lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Lightning] How to get call address / instruction pointer without a


From: Bruno Loff
Subject: Re: [Lightning] How to get call address / instruction pointer without a hack?
Date: Mon, 10 Mar 2014 17:22:39 +0000

Actually, I can satisfy my requirements with lightning as it stands without hacks. My generated code _would_ become a bit faster if lightning had the following possibility:

ref = jit_movi(REGISTER, 0)
jit_relative_patch_at(ref, label1, label2, const)

this would cause the movi instruction to be patched to jit_address(label2) - jit_address(label 1) + const. This would effectively allow me put in the register the address of label 2 relative to the address of label 1, and add a constant on top of that. Even without the constant that would already improve my code.

Currently I am simulating the above by doing the following:
ref = jit_movi(REGISTER, 0)
jit_subr(REGISTER, REGISTER, V1)
jit_patch_at(ref, label2)

And the main function that is emitted accepts an argument which it immediately puts in V1. Then I call this function with that argument set to jit_address(label1) + const. This works because label1 is always the same on every instance where I want to apply the trick above (actually label1 = jit_address(first_line_of_code)).

alternatively, some instruction like
ref = jit_movi(REGISTER, 0)
...
jit_emit()
jit_repatch_abs(ref, abs_value)

which would be called *after* jit_emit and would change the code of the movi instruction to have some absolute value instead of 0. I really do not know how the immediate of the movi instruction is stored (you told me it was in the code, not in the data buffer), but maybe this is not hard to change even after the code emission?

It seems a bit over the top to implement all of the things you mentioned just to fix this small problem. I would suggest that you don't do that unless someone else also asks for it.

   jit_emit. As a side note, it is worth mentioning that jit_patch_abs exists,
   and is usable for jit_movi and jit_jmpi, but only use cases I can imagine
   are when using multiple jit_context_t and using addresses after one of
   the contexts has been emitted, as all other addresses are expected to
   be constant at runtime or can be resolved before actual jit emit, e.g.
   dlopen+dlsym.


  If you, Bruno, or anybody else have suggestions, please let me know.

Thanks,
Paulo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]