Re:Learning to Read X86 Assembly Language
by boterock on Sunday November 27, 2016 @11:39PM
(#13053446)
Interesting example, I came up with clang 3.9 producing an imul with 11 though.
Re:Learning to Read X86 Assembly Language
by JoshTriplett on Sunday November 27, 2016 @11:50PM
(#13053482)
With optimization turned on?
GCC produces an lea that multiplies by 5 into %rax for the return value, then another lea that multiplies that by 2 and adds the original.
You'll see the various ways the compiler avoids emitting an actual multiplication instruction. The smallest multiplier I found that actually produced an imul: 46.