Path: utzoo!attcan!uunet!husc6!ukma!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Efficient coding considered harmful? Message-ID: <14444@mimsy.UUCP> Date: 9 Nov 88 19:15:49 GMT References: <3105@hubcap.UUCP> <34112@XAIT.XEROX.COM> <1700@dataio.Data-IO.COM> <23459@amdcad.AMD.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 In article <23459@amdcad.AMD.COM> tim@crackle.amd.com (Tim Olson) writes: >A good compiler can also recognize a signed integer divided by a power >of 2, and use the following trick: [copy and add sign bit] It is worth noting that Sun's PCC-based compiler does something similar: f() { register i, j; ... i = j / 2; ... i = (unsigned)j / 2; ... } compiles (using the SunOS 3.5 compiler running under SunOS 3.2) to movl d6,d0 tstl d0 jge L2000000 addql #1,d0 L2000000: asrl #1,d0 movl d0,d7 (clearly not the best code in the world) and movl d6,d0 lsrl #0x1,d0 movl d0,d7 (why some constants in hex and others decimal we may never know :-) ). The optimiser transforms the latter to the more appropriate movl d6,d7 lsrl #1,d7 (yes, the 0x disappears). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris