swap(x,y)

Larry Breed lmb at ghoti.uucp
Sat Sep 16 17:59:09 AEST 1989


A good compiler will produce better code for the naive algorithm than
can be produced for any xor technique.  Here's the code generated by
the Metaware compiler on AOS (IBM's 4.3 for the rt pc).  

#void swap(int* i, int* j)
_.swap:
#{
#   int t;
#   t=*i;
        ls      r0,0(r3)
#   *i=*j;
        ls      r4,0(r2)
        sts     r0,0(r2)
#   *j=t;
        brx     r15		# branch with execute of following instruction
#}
        sts     r4,0(r3)


Disclaimer: Don't blame my employer, blame:
Larry Breed			(415) 855-4460
uucp: uunet!ibmsupt!lmb		inet: ibmsupt!lmb at uunet.uu.net



More information about the Comp.lang.c mailing list