lightning
[Top][All Lists]
Advanced

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

[Lightning] Register arguments


From: Marc Nieper-Wißkirchen
Subject: [Lightning] Register arguments
Date: Mon, 04 Sep 2017 07:46:46 +0000

The lightning documentation states: "Note that arguments in registers are very cheap, but will be overwritten at any moment, including on some operations, for example division, that on several ports is implemented as a function call."

For writing portable code, it is important to know, which instructions actually overwrite (register) arguments, or rather, which instructions preserve them. Obviously, function calls do not preserve the arguments, and the above quote says that using division also does not guarantee that arguments are preserved.

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?

Marc


reply via email to

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