hn-classics/_stories/2010/12352959.md

3.8 KiB

created_at title url author points story_text comment_text num_comments story_id story_title story_url parent_id created_at_i _tags objectID year
2016-08-24T16:00:04.000Z Does a compiler use all x86 instructions? (2010) http://pepijndevos.nl/2016/08/24/x86-instruction-distribution.html pepijndevos 278 189 1472054404
story
author_pepijndevos
story_12352959
12352959 2010

Source

Does a compiler use all x86 instructions? - Wishful Coding

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 is ld. I imagine that if ld 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 output here. In total I counted 411 different mnemonics, topped by 15891451 mov instructions and a very long tail of instructions that only occur once or twice.

There are 33% mov instructions. Combined with callq, je, and lea 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 course nop is probably padding and xor is the best way to zero a register, but I have no clue why there are so many lea 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.

Pepijn de Vos

24 August 2016

assembly

Interesting Projects

[Share this page on Twitter][9]

  • [Make all the Star Wars memes][10]
  • [Generate Cities: Skylines height maps][11]
  • [The Science of Logic and the Science of Experiment][12]

Follow me with

  • [Twitter][13]
  • [Facebook][14]
  • [Github][15]
  • [Atom][16]

![Click to open menu][17]

© 2010 Pepijn de Vos ![][18]

[9]: http://twitter.com/intent/tweet?text=Does a compiler use all x86 instructions?&url=http://pepijndevos.nl/2016/08/24/x86-instruction-distribution.html&via=pepijndevos [10]: http://pepijndevos.nl/2018/01/24/make-all-the-star-wars-memes.html [11]: http://pepijndevos.nl/2018/01/13/generate-cities-skylines-height-maps.html [12]: http://pepijndevos.nl/2018/01/02/the-science-of-logic-and-the-science-of-experiment.html [13]: http://twitter.com/pepijndevos [14]: http://www.facebook.com/pepijndevos [15]: http://github.com/pepijndevos [16]: http://pepijndevos.nl/feed.xml [17]: http://pepijndevos.nl/style/chain.jpg [18]: http://pepijndevos.nl/style/wheel.gif