ASM Optimization: Fast Multiplication @WhatsACreel
ASM Optimization: Fast Multiplication  @WhatsACreel
Uploaded November 2013 | Updated November 2026, 3 hours ago
In this video we're going to explore an x86 Assembly optimization, using LEA to speed up multiplications of registers by various constants. LEA is useful in conjunction with other fast operations to get a good speed ups for many common multiplications.

The techniques we'll look at are not always going to be faster than using IMUL or MUL. Any gains in speed have a lot to do with what is being multiplied, which registers are used, which numbers are multiplied and how the surrounding instructions use the results. In general, if the IMUL is completely independent from surrounding instructions, it is very fast.

I've not mentioned it in the tute but the C++ compiler knows some pretty clever tricks. If you multiply some variable by some constant millions of times in a loop (as we're doing in the tute), the compiler notes that it can halve the loop count and multiply by the square of the value. We could obviously use this technique in ASM as well. Actually, we could do a lot better. We're calculating X to the power of Y multiplied by some value, and taking the low 64 bits as the result (if we are using 64 bit registers). We could easily use a very fast MOD POW algorithm and take virtually no clock cycles at all. That's not really the point of the tute.

My music channel:
youtube.com/channel/UC2nWRGqPL6O-Lm8mexWhISQ

Michael Abrash's Black Book of Graphics Programming (Chapter 6 has a great introduction to using LEA for several multiplications):
drdobbs.com/parallel/graphics-programming-black-book/184404919
ASM Optimization: Fast Multiplicationx64 Assembly MultiThreading 1: Intro and Calling CreateThreadNeural Net Structure (Architecture)AES Encryption 2: AddRoundKey, SubBytes and ShiftRowsx64 Assembly Self Modifying CodeLinux x64 Assembly Tutorial 7: Jump and Branch InstructionsNVIDIA CUDA Tutorial 3: Display Driver has Stopped Working and has RecoveredAssembly Language MisconceptionsC++ Function Templatesx64 Assembly Tutorial 47: Intro to SSEC++ 11: Range Based For LoopsDirect3D 11 3: Create Device and Swap Chain
Creel |

ASM Optimization: Fast Multiplication

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER