Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA
Path: utzoo!watmath!clyde!cbosgd!cbdkc1!desoto!cord!bentley!hoxna!houxm!vax135!cornell!uw-beaver!tektronix!decvax!genrad!panda!talcott!harvard!seismo!brl-tgr!tgr!cottrell@nbs-vms.ARPA
From: cottrell@nbs-vms.ARPA
Newsgroups: net.lang.c
Subject: swapping vars
Message-ID: <8047@brl-tgr.ARPA>
Date: Tue, 5-Feb-85 15:31:24 EST
Article-I.D.: brl-tgr.8047
Posted: Tue Feb  5 15:31:24 1985
Date-Received: Sun, 10-Feb-85 03:37:15 EST
Sender: news@brl-tgr.ARPA
Organization: Ballistic Research Lab
Lines: 38

/*
> > > How often have you written:
> > > 
> > > 	{	register type	t;
> > > 
> > > 		t = a;
> > > 		a = b;
> > > 		b = t;
> > > 	}
> > Rarely. I use:	`a ^= b; b ^= a; a ^= b;' Only worx for integer types.
> 
> Also takez more cycles on most machines.
> 
> An example: on the 68000, case 1 is
> 
> 	move.l	a,t		# 32-bit ints
> 	move.l	b,a
> 	move.l	t,a
> 
> case 2 is
> 
> 	move.l	b,d0
> 	eor.l	d0,a
> 	move.l	a,d0
> 	eor.l	d0,b
> 	move.l	b,d0
> 	eor.l	d0,a
> 
> Cute, but not worth it.
> 
> 	Guy Harris
> 	{seismo,ihnp4,allegra}!rlgvax!guy

If a & b are in registers it only takes 3 eor's. I don't know if eor
is slower than move. If all regs are being used, the var `t' may
have to be a memory location. Why did Motorola choose `eor' instead
of `xor'? Are they Winnie the Pooh freaks :-?
*/