lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] RFC: conditional move


From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] RFC: conditional move
Date: Mon, 7 Oct 2019 14:03:16 -0300

Em seg, 7 de out de 2019 às 06:58, Paul Cercueil
<address@hidden> escreveu:
>
> Hi,

  Hi,

> I was thinking that we could have a conditional move operation,
> something like:
>
> movs    01 = (04 != 0) ? 02 : 03
> movc    01 = (04 == 0) ? 02 : 03
>
> (of course 'movc' is just a 'movs' with inverted 02/03 operands, so
> there could be only one operation)
>
> That would be easy to implement on MIPS with MOVZ/MOVN, ARM with
> TST/MOVS, AArch64 with TST/CSEL. The other platforms could resolve to
> emitting branches.
>
> That's something that would be very useful to me.
>
> Thoughts?

  The fallback way of doing it would be something like this:
# define jit_movsr(r0, r1, r2, r3) \
    do { \
        jit_node_t *n; \
        jit_movr(r0, r1): \
        n = beqi(r3, 0); \
        jit_movr(r0, r2); \
        jit_patch(n); \
    } while (0)
and then customized if 'r3 == 0' or 'r3 != 0' has a cheaper variant.
Also customized if there is some kind of short jump.
  On most backends would be 3 instructions, on some backends it would
be 4 instructions (two for compare and branch), and when there is
conditional move 2 instructions (or 3 if need to set flags).
  I will leave this in my todo for a next lightning release.

> Thanks,
> -Paul

Thanks,
Paulo



reply via email to

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