xbyak_aarch64 icon indicating copy to clipboard operation
xbyak_aarch64 copied to clipboard

transparent long branches

Open neumannt opened this issue 6 months ago • 6 comments

Conditional branches can only jump of to 1MB, which can be a problem for large generated code. xbyak could handle that transparently by branching to an unconditional branch instruction if needed, which can then breach 128MB.

We have a need for supporting large generated code and could contribute a patch. Would you be willing to accept such functionality? If yes, do you have any suggestions how to integrate that into the code base?

Our plan would be to patch the LabelManager to check the distances, and if a label is unreachable we would create a branch to a (pending) thunk instruction that then jumps unconditionally. These instructions would be emitted at the next convenient moment, e.g., after the next unconditional branch. In the unlikely event that there is no unconditional branch anywhere within 1MB of the original branch we would have to insert one, but that should never happen in reality.

The advantage of fixing this problem in xbyak instead of in the application is that xbyak can keep track of pending distances, which is not easily possible in the application itself.

neumannt avatar Jul 26 '24 10:07 neumannt