Brantley Coile <[email protected]> wrote:
> Which plan 9 assembler uses right to left argument assignments,
> or compare argument order?

The CMP order is different (at least) between power and arm64. This
inconsistency is impossible to fix; I know because I tried to fix
it in the SPARC64 Go port.

The problem is that different architectures treat immediate constants
either as the first, or the second argument. For non-commutative
operations like subtractions, this matters.

However, in Plan 9, for three-argument instructions, we want to
have a two argument variant that works like this:

    OP      one, two -> OP    one, two, two

That is, the last argument is doubled, and serves as the (Plan 9)
second operand.

However, this means immediates must come first, because

    OP      $imm, R -> OP   $imm, R, R

makes sense, but

    OP      R, $imm, $imm

doesn't; $imm can't serve as destination.

So this forces immediates in Plan 9 assembly to be the first operands,
even though the machine might treat them as the first, or second
operands.

One might be tempted to allow immediates as second operands, and
simply forbit an instruction of the form "OP   R, $imm", mandating
one should always use the three-operand form "OP Rs, $imm, Rd".
Indeed this was what I did with the SPARC64 Go port. However, this
makes the compiler significantly more complex, and different, so
it's not a good idea.

As for instructions with different data flow order, atomic instructions
on ARM64 come to mind. Note that printing is still in "from, reg,
from3, to" order, so printing these instructions (7a -S) will print
something different than the input. This has been fixed in Go.

-- 
Aram Hăvărneanu

Reply via email to