logoalt Hacker News

fweimeryesterday at 8:48 PM2 repliesview on HN

What language is this article talking where compilers don't optimize multiplication and division by powers of two? Even for division of signed integers, current compilers emit inline code that handles positive and negative values separately, still avoiding the division instruction (unless when optimizing for size, of course).


Replies

shakowyesterday at 9:49 PM

That's what I would have thought as well, but looks like that on x86, both clang and gcc use variations of LEA. But if they're doing it this way, I'm pretty sure it must be faster, because even if you change the ×4 for a <<2, it will still generate a LEA.

https://godbolt.org/z/EKj58dx9T

show 2 replies
cjbgkaghyesterday at 9:24 PM

It was written in assembly so goes through an assembler instead of a compiler.

show 1 reply