TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN MCBRIDE
from: NIELS JONKER
date: 1997-03-28 16:49:00
subject: Re: Video

 NJ>  //Screen[x+y*320] = color;
 NJ>  Screen[x+(y<<6)+(y<<8)] = color; /* same as above but here the
 NJ>          multiplication is replaced with
 NJ>          shifts to make it faster */
 DM> Are you SURE that two shift operations followed by an addition is
 DM> really faster than the hardware-optimized integer multiplication? 
 DM> Perhaps on an 8086... but on an 80486?  Probably not...
a shift operation on a pentium takes 1 clockcycle where an integer
multiplication takes 9 for 32bit registers and 11 for 16bit
I roughly calculated the number of clockcycles for both calculations:
	x+(y 4 clockcycles
	x+y*320         => 11 (32bit), 13 (16bit)
so using shifts is still the fastest way.
I do not know if there are compilers who recognize this situation
and optimize it in the fastest(or smallest) way, but I doubt it,
so to be save I just use the shift.
Niels...
--- GEcho 1.11+
---------------
* Origin: Free sex on Softwareboard 0224-218587 {+} Reg.Only (2:280/112)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.