Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!amdcad!tim From: tim@amdcad.AMD.COM (Tim Olson) Newsgroups: comp.arch Subject: Re: AM29000 Booleans Message-ID: <16640@amdcad.AMD.COM> Date: Mon, 11-May-87 11:19:58 EDT Article-I.D.: amdcad.16640 Posted: Mon May 11 11:19:58 1987 Date-Received: Wed, 13-May-87 04:08:38 EDT References: <1270@aw.sei.cmu.edu> <8012@utzoo.UUCP> Reply-To: tim@amdcad.UUCP (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale, Ca. Lines: 57 In article <8012@utzoo.UUCP> henry@utzoo.UUCP (Henry Spencer) writes: +----- | Many multiplies (at least in non-numerical code) are by small integer | constants. For those, a sensible compiler will generate whatever small | number of steps is actually needed to do the particular multiply, as a | function of the binary representation of the constant. +----- If the multiply is by a constant known at compile time, it is usually better to perform the multiply as a series of shifts and adds, rather than a sequence of multiply-steps, since (on the average) half of the significant multiplier bits are a '1'. For example, the following code int x; main() { x = x*57; } Compiles to: const lr05,_x+(0) consth lr05,(_x+(0))>>16 load 16,lr02,lr05 sll lr04,lr02,3 add lr03,lr02,lr04 sll lr04,lr02,4 add lr03,lr03,lr04 sll lr04,lr02,5 add lr03,lr03,lr04 store 16,lr03,lr05 for a multiply time of 6 cycles. The equivalent multiply-step code would be: const lr05,_x+(0) consth lr05,(_x+(0))>>16 load 16,lr02,lr05 mtsr Q,lr02 const lr03,57 mul lr02,lr03,0 mul lr02,lr03,lr02 mul lr02,lr03,lr02 mul lr02,lr03,lr02 mul lr02,lr03,lr02 mul lr02,lr03,lr02 mull lr02,lr03,lr02 mtsrim FS,7 mfsr gr60,Q extract lr02,lr02,gr60 ; extract the result store 16,lr02,lr05 for a multiply time of 12 cycles. -- Tim Olson Advanced Micro Devices