Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.lang.c Subject: Re: swap(x,y) Message-ID: <190@titania.warwick.ac.uk> Date: 28 Aug 89 16:35:15 GMT References: <8350@boring.cwi.nl> <8514@galbp.LBP.HARRIS.COM> <3040@solo5.cs.vu.nl> <32074@ism780c.isc.com> <184@titania.warwick.ac.uk> <11274@watcgl.waterloo.edu> Reply-To: cudcv@warwick.ac.uk (Rob McMahon) Organization: Computing Services, Warwick University, UK Lines: 22 In article <11274@watcgl.waterloo.edu> jdchrist@watcgl.waterloo.edu (Dan Christensen) writes: >In article <184@titania.warwick.ac.uk> cudcv@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@uk.ac.warwick ARPA: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England