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

---
[Source](http://pepijndevos.nl/2016/08/24/x86-instruction-distribution.html "Permalink to Does a compiler use all x86 instructions? - Wishful Coding")

# Does a compiler use all x86 instructions? - Wishful Coding

# [Wishful Coding][1]

Didn't you ever wish your computer understood you?

## [Does a compiler use all x86 instructions?][2]

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][3]. 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][4]

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][5], but I have no clue why there are so many `lea` everywhere.

[Nobody really seems to know how many x86 instructions there are][6], 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][7]

#### [Interesting Projects][8]

#### [Share this page on Twitter][9]

#### Remotely related posts

* [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]

[1]: http://pepijndevos.nl/
[2]: http://pepijndevos.nl/2016/08/24/x86-instruction-distribution.html
[3]: https://gist.github.com/pepijndevos/c9ea860acb9cc41d6ed6bd1df7ca0605
[4]: http://pepijndevos.nl/images/opcodepie.png
[5]: http://stackoverflow.com/questions/33666617/what-is-the-best-way-to-set-a-register-to-zero-in-x86-assembly-xor-mov-or-and
[6]: http://stackoverflow.com/questions/15922708/how-many-instructions-on-x86-today
[7]: http://pepijndevos.nl/tags.html#assembly
[8]: http://pepijndevos.nl/projects.html
[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

