lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] Register arguments


From: Marc Nieper-Wißkirchen
Subject: Re: [Lightning] Register arguments
Date: Mon, 04 Sep 2017 20:35:23 +0000

Hi Paulo,

  If the code does jit_getarg* after a temporary was used, and the argument
was in a register, it can be clobbered in a temporary.

I did some experiments, and the code generated by GNU lightning actually spills and reloads register arguments when it thinks they are live. (I tried with %rdx on x64, which is used by qdiv and is a register argument.)

Which is great because with it, one can generate more performant code with lightning.
 
  It is a good practice to read arguments at the function prolog.

This would make the (ABI) optimization of passing arguments in registers a bit moot, wouldn't it?
 

> On the other hand, this example from the documentation
>
> fact_entry:                  ! This is the tail call entry point
> ac = arg                     ! The accumulator is the first argument
> in = arg                     ! The factorial argument
>      getarg R0, ac           ! Move the accumulator to R0
>      getarg R1, in           ! Move the argument to R1
>      blei fact_out, R1, 1    ! Done if argument is one or less
>      mulr R0, R0, R1         ! accumulator *= argument
>      putargr R0, ac          ! Update the accumulator
>      subi R1, R1, 1          ! argument -= 1
>      putargr R1, in          ! Update the argument
>      jmpi fact_entry         ! Tail Call Optimize it!
> fact_out:
>      retr R0                 ! Return the accumulator
>
> makes it clear, that simple operations like subtraction actually do preserve
> arguments.
>
> Could the set of safe instructions (that is those instructions not modifying
> arguments) be documented? Is it safe to assume that all ALU operations
> (except for division and multiplication (?)), the compare and transfer
> operations, the network, load and store operations, and the branch
> instructions do not modify (register) arguments?

  jit_getarg* should be called at the function prolog, otherwise the argument
will be considered dead from the prolog to the jit_getarg* call, what may be
too late if it was used as a temporary. But as the example you quote tells,
one can restore (or change) an argument, with jit_putarg*.

My point was that between the two putargr instructions in the above code, there is a subi instruction. The subi instruction obviously has to respect the value in the "ac" argument and not clobber it.
 

> Marc

Thanks,
Paulo

And thank you very much!

Marc
 

reply via email to

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