Live data from Hacker News

Assembly Gems

dflund.se

11–14 of 14 posts

Re: Assembly Gems

#12
post #9

Earlier 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.

Well I read some and had the impression they were going for speed or low cycle count. Indeed, most surely still work (there doesn't seem to be anything that is processor-specific). Unfortunately my asm is rustier than I thought and I find it quite demanding to read and fully understand them.

Re: Assembly Gems

#13
post #3

Secrets of Assembly Programming Gurus!

I wouldn't go so far to call them secrets, as in my personal experience gurus tend not to keep secrets; they're just neat hacks that not many people know about nowadays.

Re: Assembly Gems

#14

This 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.

Indeed. The x86 equivalent gem (http://dflund.se/~john_e/gems/gem0001.html) makes a point to note that. Odd that it's not mentioned on the m68k page.

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.
Post reply on HN