3 ms·
The text mentions that it can also do multiplication but doesn't expand on that. E.g. for x * 5 gcc issues lea eax, [rdi+rdi*4].
by stassats 10mo ago
The text mentions that it can also do multiplication but doesn't expand on that.
E.g. for x * 5 gcc issues lea eax, [rdi+rdi*4].
- xg15 10mo agoIt also says the multiplier must be one of 2, 4 or 8. So I guess this trick then only works for multiplication by 2, 3, 4, 5, 8 or 9?
- stassats 10mo agoThe tricks to avoid multiplication (and division) are probably worth a whole post. x * 6: lea eax, [rdi+rdi*2] add eax, eax x * 7: lea eax, [0+rdi*8] sub eax, edi x * 11: lea eax, [rdi+rdi*4] lea eax, [rdi+rax*2] But with -Os you get imul eax, edi, 6 And on modern CPUs multiplication might not be actually all that slow (but there may be fewer multiply units).
- mattgodbolt 10mo agoHey now; let's not get ahead too far :) I'm trying to keep each one bite-sized...I don't think you'll be (too) disappointed at the next few episodes :)