1.) if you bothered to profile code you would see that the macro is what is called a "hot-spot"
2.) knowing something and doing something are totally different things, if you bothered to check the instruction code generated for the macro with gcc or intel compilers with -03 and visual c with opt on you will see that all 3 do a imul instead of a shift... I guess they know something you dont... Arash Partow ________________________________________________________ Be one who knows what they don't know, Instead of being one who knows not what they don't know, Thinking they know everything about all things. http://www.partow.net Neville Franks wrote:
Saturday, August 6, 2005, 5:56:00 PM, you wrote: AP> Hi all, AP> I was wondering if the getbyte macro found in misc.h is as AP> optimal as it can be... AP> I propose using a shift-left by 3 instead of an integer AP> multiply by 8. AP> original macro: AP> GETBYTE(x, y) (unsigned int)byte((x)>>(8*(y))) AP> updated macro: AP> GETBYTE(x, y) (unsigned int)byte((x)>>(y<<3)) AP> Is there anything wrong with this idea? This is something that optimizing compilers learnt how to do many years ago. To convince yourself have a look at the generated assembler code in the debugger. If you're concerned about performance then you should be using a profiler to find hot spots, and not be concerned with issues like this.
