Skip to content
This repository was archived by the owner on Nov 21, 2017. It is now read-only.
This repository was archived by the owner on Nov 21, 2017. It is now read-only.

Use switch tables instead of long strings of cmp/je combos #117

@faissaloo

Description

@faissaloo

Instead of doing stuff like:

os_system_config:
    cmp rdx, 0
    je os_system_config_timecounter
    cmp rdx, 1
    je os_system_config_argc
    cmp rdx, 2
    je os_system_config_argv
    cmp rdx, 3
    je os_system_config_networkcallback_get
    cmp rdx, 4
    je os_system_config_networkcallback_set
    cmp rdx, 5
    je os_system_config_clockcallback_get
    cmp rdx, 6
    je os_system_config_clockcallback_set
    cmp rdx, 20
    je os_system_config_video_base
    cmp rdx, 21
    je os_system_config_video_x
    cmp rdx, 22
    je os_system_config_video_y
    cmp rdx, 23
    je os_system_config_video_bpp
    cmp rdx, 30
    je os_system_config_mac
    ret

You could do:

os_system_functions dq   os_system_config_timecounter, os_system_config_argc, os_system_config_argv, os_system_config_networkcallback_get, os_system_config_networkcallback_set, os_system_config_clockcallback_get, os_system_config_clockcallback_get, os_system_config_clockcallback_set, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_video_x, os_system_config_video_y, os_system_config_video_bpp, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_no_function, os_system_config_mac

os_system_config:
    jmp qword [os_system_functions+rdx*4]
    os_system_config_no_function:
    ret

And I believe it would be much faster, I also believe this is what GCC does (or at least, something similar) for switch statements.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions