iAPX86 code for ABS (using Microsof

Dik T. Winter dik at cwi.nl
Tue Jun 20 09:52:47 AEST 1989


In article <225800188 at uxe.cso.uiuc.edu> mcdonald at uxe.cso.uiuc.edu writes:
 > ; b = abs(a)
...
 > 	cwd	
 > 	xor	ax,dx
 > 	sub	ax,dx
...
 > So your review was correct!  I assume that they do this odd thing in
 > order to not empty instruction prefetch queues????????????????
 > 
No, it is faster; just count clock cycles and compare to:
	jns	lab
	neg	ax
lab:

On many machines jumps are not cheap, so it may be better to avoid them.
(There are machines where
	if(a >= 0 && b >= 0)
is cheaper if && is not short-circuited.)
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik at cwi.nl
BITNET/EARN: dik at mcvax



More information about the Comp.lang.c mailing list