I am developing a program that has to be very very fast.
I will make it in C++, and because it has to do a lot of logical operations like XOR, AND or even count the number of 1s in a binary number, I thought it would be a good idea to use _asm{} in some parts of the code to do those operations faster. They will be executed millions of times sometimes.
But I don’t know if it will really make the difference and worth the effort.
Please if someone tryed it before I will really appreciate your knowledge on the subject.
Thanks a lot.
A million ops when the processor clock is a few billion per second is not often a big deal.
So code it in simple C/C++. Test it. Profile it. If it’s really too slow and the profile shows a hot spot, turn up optimizations to maximum for that spot and test again. If it’s still too slow, disassemble the optimized code and see if you think you can do better than the compiler. If you think so, go ahead and insert your
_asm {}. Be prepared for this carefully handcrafted code to run slower. It happens a lot. If you do achieve the needed speedup, put the assembler in#ifdefs so that you can chuck it when the next processor rev is issued. Read: Assembly code is so expensive to write and maintain that it’s almost always a bad idea.