swap(x,y)

Rob McMahon cudcv at warwick.ac.uk
Tue Aug 29 02:35:15 AEST 1989


In article <11274 at watcgl.waterloo.edu> jdchrist at watcgl.waterloo.edu (Dan Christensen) writes:
>In article <184 at titania.warwick.ac.uk> cudcv at warwick.ac.uk (Rob McMahon) writes:
>>On our Gould PN6000 with GCC 1.34
>>	{ int tmp; tmp = x; x = y; y = tmp; }
>>compiles to
>>	xchg	r5,r4
>
>Just out of curiousity, is space allocated for tmp?

It does get a register allocated for it, although of course it is immediately
reusable since tmp goes out of scope straight away.  It is done as a simple
peephole optimisation after register allocation, a better job could probably
be done by spotting the case earlier in the compiler.  My point is that if the
compiler does do anything like this, all you're doing by using deviosities
like `{ x ^= y; y ^= x; x ^= y; }' is confusing the compiler so that it will
miss these optimisations.

Rob
-- 
UUCP:   ...!mcvax!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv at uk.ac.warwick             ARPA:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.lang.c mailing list