Movatterモバイル変換


[0]ホーム

URL:


Wishful Coding

Didn't you ever wish your
computer understood you?

Does a compiler use all x86 instructions?

On the Z80 CPU there are so few registers and instructions that you can easily know and use them all and wish there were more of them. However, half of the time it feels like the only on you really use isld.I imagine that ifld took half the number of clock cycles, average code would run twice as fast.

In modern x86(_64) there are so many that I even wonder if my compiler knows and uses them all, and how often. To get an impression, I ran this one-liner:

objdump -d /usr/bin/* | cut -f3 | grep -oE "^[a-z]+" | sort | uniq -c

Full outputhere. In total I counted 411 different mnemonics, topped by 15891451mov instructions and a very long tail of instructions that only occur once or twice.

There are 33%mov instructions. Combined withcallq,je, andlea making up over half of all code.

Opcode pie chart

Between the expected compare and jump instructions, “Load Effective Address”, “eXclusive OR” and “No OPeration” surprised me. Of coursenop is probably padding andxor is thebest way to zero a register, but I have no clue why there are so manylea everywhere.

Nobody really seems to know how many x86 instructions there are, but someone counted 678, meaning there are over 200 instructions that do not occur even once in all the code in my/usr/bin.

It would be interesting to break it down further in “normal” instructions, SIMD instructions, other optimizations, and special purpose instructions… if anyone can be bothered categorizing 600+ instructions.

Published on

Elsewhere

Remotely related posts

Share this page on Twitter!
Click to open menu
[8]ページ先頭

©2009-2025 Movatter.jp