This patch adds a low-cost, conditional execution mechanism based on hot-patching.
Its main goal is to provide a way of optimize infrequently used if-statements in performance-sensitive code.
Instead of repeatedly evaluating an if statement, a single branch
direction is "baked in" at compile time. This is achieved by an unconditional
jump or nop using the using 'asm goto' feature. When the branch direction needs
to be changed, the appropriate instruction is patched at runtime.
Previous code blocks of form:
bool flag = false; if(flag) { action1(); } if(!flag) { action2(); }
would be migrated to the new interface as:
DEFINE_ZCOND_FALSE(flag); if(zcond_true(flag)) { action1(); } if(zcond_false(flag)) { action2(); }
This revision also modifies SDT to use this mechanism, both as a proof of concept and example of use.
This revision introduces support for the amd64 architecture only.
Support for all other architectures will be added if the overall approach is deemed acceptable.
This work was sponsored by the GSoC '24 program.