4 ms·
We can see using ADD with EAX as dst register is 1-byte short than another, so that has higher code density and better cache-friendly. The same for INC/DEC (1
by userbinator 7y ago
We can see using ADD with EAX as dst register is 1-byte short than another, so that has higher code density and better cache-friendly.
The same for INC/DEC (1 byte!) vs ADD/SUB --- and if my years of experience writing Asm for x86 (and easily beating compilers at size, speed, often both) have any good advice to give, it's to optimise for size first and then only in specific and particular cases give up size for speed. While the size-optimised code might lose (sometimes a lot) in a microbenchmark, cache misses are extremely expensive (especially when "cache miss" actually means "swapped to disk") so unless it's a special tight loop that really needs the last few % squeezed out of it because it's a huge time-sink, trying to optimise for speed "everywhere" can actually be counterproductive overall.
- thedance 7y agoI appreciate the sentiment but compilers optimizing size (gcc -Os) often produce rather bad full-program performance. Cache and TLB pressure are important topics but in my experience it seems to have been the case that hot/cold code splitting and other layout optimizations overcome the problem, and text on hugepages helps with iTLB miss rate. The best full-system performance I've been able to get on complex C++ servers has always been with really large outputs, 100s of MB of .text.