Hello,
As far as I can tell, 30 years of tango between C compiler coders and hardware guys, must have made sure that nothing else can multiply faster in C than the * operator.

Thats just what I think ....
But maybe theres a way I havent heard of .. Is there any way to multiply two integers faster than what * using C . What about in assembly ?
If so, how fast are we talking about ?

I could find lots of "Faster XYZ with this and that" forum topics .. none of them say anything about them being faster than * .....

Thanks
Posted on 2003-11-22 21:37:31 by ashayh
Use shifts and lea to replace multiplication. Though of course, sometimes the combination of shifts and lea might be slower than mul/imul. PS: Take a look at http://www.asmcommunity.net/board/index.php?topic=12817&highlight=yodel
Posted on 2003-11-22 21:41:56 by roticv
that link was just what I was reading ! :alright:
Posted on 2003-11-22 21:43:06 by ashayh
Don't think the compiler writers are not aware of this, though :grin:

E.g. both Visual C++ and GCC generate shifts and lea instructions for '*' with constants when applicable. They also replace divisions with multiplication in cases where that is faster.
Posted on 2003-11-23 03:01:45 by Jibz
Simplest approach is to write you C/C++ code using the * multiply operator, disassemble it and see what it is doing. You reduce down to integer multiply with IMUL or if its a constant a combination of LEA and ADD. In floating point you have other options if you are doing that type of work.

I have generally seen that compilers do most maths operations reasonably well as they are not all that complex at the arithmetic level. If you want complex floating point algorithms, you will probably see some performance improvements by manually coding your own.

Regards,
http://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=2f46ed9f24413347f14439b64bdc03fd
Posted on 2003-11-23 17:43:55 by hutch--
Assembly will always be faster than C/C++. Or at least never slower. Since C is compiled into assembly.
Posted on 2003-11-23 17:51:13 by drhowarddrfine
Depends on who is doing the assembly...

Also, most compilers these day compile to some internal p-code format which is then optimized and converted to machine code, without an assembly intermediate. Hell, with the most recent compilers this is done at the link stage rather than the compile stage, so global optimizations can be applied.
Posted on 2003-11-23 17:57:45 by f0dder