lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] Feature Request: Allow patching of st(x)i and ld(x)i


From: Marc Nieper-Wißkirchen
Subject: Re: [Lightning] Feature Request: Allow patching of st(x)i and ld(x)i
Date: Tue, 3 Sep 2019 19:11:37 +0200

Hi Paulo,

Am Di., 3. Sept. 2019 um 19:01 Uhr schrieb Paulo César Pereira de
Andrade <address@hidden>:
>
> Em ter, 3 de set de 2019 às 12:32, Marc Nieper-Wißkirchen
> <address@hidden> escreveu:
>
>  Hi Marc,
>
> > > > >   Patches for ldi* and sti* are mostly pointless, because it would 
> > > > > mean the
> > > > > address is not known while generating jit, but before calling 
> > > > > jit_emit().
> > > >
> > > > This is exactly the case here. My code generator, which calls GNU
> > > > lightning, handles literals (of the source language) by storing their
> > > > addresses in a table, which is malloc'd. The size of the table is not
> > > > known until all code has been generated (that is, just before the call
> > > > to jit_emit). Therefore, the table cannot be malloc'd before and its
> > > > absolute address is not known before. However, needs to reference
> > > > entries in the table, so I have to patch it when the table has been
> > > > malloc'd.
> > > >
> > > > Currently, I do something like:
> > > >
> > > > lbl = jit_movi (JIT_R0, 0);
> > > > jit_ldr (JIT_R1, JIT_R0);
> > > > ...
> > > > jit_patch_abs (lbl, table_pointer + offset);
> > > > jit_emit ();
> > > >
> > > > What I want to do is:
> > > >
> > > > lbl = jit_ldi (JIT_R1, 0);
> > > > ...
> > > > jit_patch_abs (lbl, table_pointer + offset);
> > > > jit_emit ();
> > >
> > >   Ok. This is a trivial patch. Still untested, but very unlikely to
> > > have issues. Please give some feedback on the attached patch.
> >
> > I have tried the patch and it works here (x86_64).
>
>   Ok. I will commit it. The patch is good to have as it allows semantic
> use the same way as patching movi.

Thank you!

>   Note that it will still internally become a movi(..), ldr(...) pair on
>  a very large amount of inputs.
>   For x86_64 it will be a direct load from memory only if the address can
> be 32 bit signed extended to a 64 bit address.
>   For several other ports the value will be far smaller, for example, could
> need to be the first 16k bytes or similar value.
>   Usually the best approach would be to have a base register, and then use
> ldxi with a constant offset. But that could mean keeping a register
> exclusively for the base pointer of global the data.

Apart from the fact that I am short on the register side, I currently
have no control where the malloc'd area lies in memory, so it is
unclear where a base pointer should point at.

It would be a nice addition to GNU lightning if user data could be
stored along the code, for which GNU lightning could use IP-relative
addressing if available on the target architecture.

If we had this, I wouldn't have to resort to jit_patch_abs. (By the
way, jit_patch_abs is not yet documented in the manual, I think.)

--

Marc

>
> > Thanks a lot!
> >
> > Marc
>
> Thanks,
> Paulo



reply via email to

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