Skip to content
Discussion options

You must be logged in to vote

No, swapping wouldn't be the proper way.

A better way is simply to make more variables, as variables are initialized to 0 by default.
Another way is XOR again (as in this example), as XOR is its own inverse.

Variable values can't be overwritten; ^= is equivalent to initialization if the variable holds value 0.

This is why in loops, arrays are used (for_32.src):

module main( in op(1),out c[4](32),inout a[4](32), inout b[4](32))
if op then
 for $i = 0 to 3 do
    c[$i] ^= (a[$i] + b[$i])
  rof
else
 for $i = 0 to 3 do
    c[$i] ^= (a[$i] - b[$i])
 rof
fi op

It doesn't have: c ^= (a[$i] + b[$i]) or c ^= (a[$i] - b[$i]), ∵ that doesn't mean "overwrite variable c with the RHS" (as it would if ^=

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TooMuchDakka
Comment options

Answer selected by Geremia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants