Some things are due to an algorithmical trick, while others are a translation trick. Some are both.
Assembly Gems
11–14 of 14 posts
Re: Assembly Gems
#12Earlier quoted context omitted.
Now almost every code to be run is cache-bound for performance, not cycle-bound. So this gems, while may still work, may not be the best means to achieve optimal performance. Optimizing cache access is what brings the biggest speedups today -- see for example NumExpr[1]. [1] https://github.com/pydata/numexpr
Cache is extremely important, but most of these operate strictly on values in registers. So, losing cycles due to cache misses, latency, contention, etc... isn't a bottleneck. A lot of these are crucial enough that they've been codified in transistors now, and generally can execute in a cycle without consuming extra registers. There are still some very valid bit tricks though.
Re: Assembly Gems
#13Secrets of Assembly Programming Gurus!
Re: Assembly Gems
#14This one has a serious flaw: http://dflund.se/~john_e/gems/gem0032.html The neg (two's complement) of 0x80000000 is 0x80000000. Thus his trick results in an infinite loop for the most negative value.
For what it's worth, my copy of the C11 spec says
The abs, labs, and llabs functions compute the absolute value of an integer j. If the result cannot be represented, the behavior is undefined. 304)
304) The absolute value of the most negative number cannot be represented in two’s complement.