How to multiply a register by 37 using only 2 consecutive leal instructions in x86?
At -O3, gcc will emit (Godbolt compiler explorer): int mul37(int a) { return a*37; } leal (%rdi,%rdi,8), %eax # eax = a * 9 leal (%rdi,%rax,4), %eax # eax = a + 4*(a*9) ret That’s using 37 = 9*4 + 1, not destroying the original a value with the first lea so it can use … Read more