Hacker News new | ask | show | jobs
by ww520 2756 days ago
I'm surprised it's not doing a left shift for the x2.
1 comments

It is in the first example (the sal instruction)
However, if you look at the second, you won't see any left shifts, which is also interesting
I find it weird that he doesn't mention this difference as part of the performance difference. A left shift should be considerably faster than a mul operation?
I believe this is far less true than it used to be, but it’s a good example of why these decisions really need to be data driven as compilers and processors change faster than most people can afford to optimize code. I don’t know that this would be the case for something that simple but I’ve seen a fair amount of heavily-tuned C/ASM code which was replaced with the now-faster “reference” code when someone noticed that the old assumptions weren’t true.
I don't think this is generally true on modern processors.