Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!kth!sunic!liuida!prosys!ath From: ath@helios.prosys.se (Anders Thulin) Newsgroups: comp.lang.c Subject: Re: iAPX86 code for ABS (using Microsoft C?) Message-ID: <429@helios.prosys.se> Date: 28 Jun 89 17:09:53 GMT References: <1202@draken.nada.kth.se> <7416@xyzzy.UUCP> Organization: Programsystem AB, Linkoping, SWEDEN Lines: 34 In article <1202@draken.nada.kth.se> d88-eli@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@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