swap(x,y)
Anton Rang
rang at cs.wisc.edu
Fri Sep 22 01:49:57 AEST 1989
In article <433 at crdos1.crd.ge.COM> davidsen at crdos1.crd.ge.COM (Wm E Davidsen Jr) writes:
> I would be willing to bet that there are more uses of swap than shift
>in applications programs, and yet we have shift.
Shift can't be portably represented in a language without it; there
is no (simple) sequence of statements which will do a shift. The
simple sequence:
t = x;
x = y;
y = t;
will do a swap. A reasonable compiler (on a reasonable machine) ought
to discover that T is only used in these three statements, and put it
in a register. At this point, a peephole optimizer ought to discover
that there is a swap instruction applicable.
MOVE X, R0
MOVE Y, X
MOVE R0, Y
can be transformed into
SWAP X, Y
if the value in R0 is not used past this point.
Anton
+----------------------------------+------------------+
| Anton Rang (grad student) | rang at cs.wisc.edu |
| University of Wisconsin--Madison | |
+----------------------------------+------------------+
"You are in a twisty little maze of Unix versions, all different."
More information about the Comp.lang.c
mailing list