iAPX86 code for ABS (using Microsoft C?)

Anders Thulin ath at helios.prosys.se
Thu Jun 29 03:09:53 AEST 1989


In article <1202 at draken.nada.kth.se> d88-eli at nada.kth.se (Erik Liljencrantz) writes:
| I remember a review of Microsoft's C compiler for MS-DOS that stated it
| produced no-conditional-jump-abs-code. The function to convert an integer
| to a positive integer was performed without a conditional jump (i.e. JS or
| something). I'm very interested in this piece of code, so if someone
| who does have a Microsoft C-compiler could try something like
|   main()
|   { int a,b;
|     a=-10;
|     b=abs(a);
|   }

I expect it would look something like:

	(x in d0)
	move.l	d0,d1
	add.l	d1,d1
	subx.l	d1,d1
	eor.l	d1,d0
	sub.l	d1,d0
	(abs(x) in d0)

This is very likely the optimal sequence of instructions for 8086.
Whether it is faster than the traditional test-jump if positive-negate
I cannot judge.

Copied from the article 'Superoptimizer -- A Look at the Smallest
Program' by Henry Massalin, in 2nd Int. Conf. Arch. Support for Prog.
Lang. and Operating Sys. (ASPLOS II)
-- 
Anders Thulin			INET : ath at prosys.se
Programsystem AB		UUCP : ...!{uunet,mcvax}!sunic!prosys!ath
Teknikringen 2A			PHONE: +46 (0)13 21 40 40
S-583 30 Linkoping, Sweden	FAX  : +46 (0)13 21 36 35



More information about the Comp.lang.c mailing list