[Top][All Lists]

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

Re: [Lightning] Calling jit_patch after jit_emit and jit_clear_state

From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] Calling jit_patch after jit_emit and jit_clear_state
Date: Wed, 9 Aug 2017 15:03:31 -0400

2017-08-09 14:04 GMT-04:00 Marc Nieper-Wißkirchen <address@hidden>:
> Is it safe to change immediate operands by calling jit_patch after the code
> has already been emitted by jit_emit? If so, would it still be safe after
> jit_clear_state has been called?

  It does not work, because jit_patch, and jit_patch_at works on the
intermediate representation. Once jit_emit is called, it is converted
to machine code, and may become a (possibly conditional) relative
short jump or an absolute jump. The only non branch instruction that
can be patched is jit_movi, and it can become some special instruction
depending on the constant.

  If the value must be changed, I suggest using a heap pointer, or a
stack pointer allocated with jit_allocai, to load/store the value.

> And a related question: Can I reuse the jit state to generate new code after
> jit_clear_state has been called, or do I have to jit_destroy_state and
> jit_new_state?

  It would require some minor patching, but is not currently supported.
It is assumed that jit_new_state is called before starting to emit code,
and jit_destroy_state is called after done. Basically, it would need to
reset some offset variables and zero some memory (zero the memory
because by default it always starts with zeroed memory), but that can
be changed with jit_set_memory_functions.

> Thanks!
> Marc


reply via email to

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