News for hackers. Stuff that matters.
Re:Learning to Read X86 Assembly Language by JoshTriplett on Sunday November 27, 2016 @09:48PM (#13053064)
One great example to try: add -O3 to the compiler options, then write a function returning its argument multiplied by 2, 3, 4, ...

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.

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.