by ANTSANTS · 12y ago · 0 comments
>The speed hierarchy of operations is:
>
> comparisons
> (u)int add, subtract, bitops, shift
> floating point add, sub (separate unit!)
> ...
> (u)int division, remainder
This can't be right. A comparison necessitates either a branch or a cmov, and there's no way that either of those is faster than a basic ALU operation.Throughput is somewhat more reasonable, but then large parts of the hierarchy collapse entirely. A more reasonable approach is to think about resource (ALU, LSU, branch, cache, etc) pressure, but that doesn’t fit nicely into a soundbite and requires actual thought.
A branch miss on the other hand is much more expensive, about 14 cycles last time I was testing (on a core i5 desktop cpu from a few years ago).
i.e. this is why measuring the whole is so important in isolation it is slower but in more complicated code it is likely to be faster.