Does a compiler use all x86 instructions? (2010)
41–50 of 198 posts
Re: Does a compiler use all x86 instructions? (2010)
#42For example, if Intel decided today that CPUs need a new "fast" hashing opcode (I don't know if they actually do), a compiler can't compiles to it, as programs won't work on older computers.
Is it like the API cruft in Android, where "new" Lollipop APIs are introduced for 10 years from now, when no one uses any phones from before 2014?
Re: Does a compiler use all x86 instructions? (2010)
#43Earlier quoted context omitted.
And the counterpoint is that some instructions that are commonly believed to be slow (eg. the string instructions like rep movs, lods, stos), are in fact fast on modern processors.
Now I'm curious - do you have performance numbers somewhere for this? The rep instructions can actually be shorter than a call to str*, so if rep is actually fast enough then it might make a nice optimization.
Some code I just compiled with GCC 6.1.1 had several snippets like this emitted for zeroing with memset:
xor eax,eax
...
rep stos QWORD PTR es:[rdi],rax
and some rep movs for memcpy/memmove.Re: Does a compiler use all x86 instructions? (2010)
#44Of course what really matters is which instructions are dynamically used the most. Can Intel performance counters collect that data? You could modify QEMU TCG mode to collect it fairly easily.
Performance counters by themselves aren't granular enough for an exact histogram. But you can use them (especially the LBR[1] and the fancy new PT[2]) to reconstruct an approximate control-flow graph, and with a bit of post-processing it's easy to get per-instruction call frequencies.
A long time ago, I wrote a paper on x86 trace compression that needed a dynamic histogram like the one you mentioned. As expected, the CDF rises very very fast [3, Fig. 5] -- you can cover a very large fraction of execution with a very small number of instructions.
[1] http://lwn.net/Articles/680996/ [2] http://www.halobates.de/pt-tracing-summit15.pdf [3] http://skanev.org/papers/ispass11zcompr.pdf
Re: Does a compiler use all x86 instructions? (2010)
#45Earlier quoted context omitted.
Source?
Here is a paper and a mov only compiler. http://www.cl.cam.ac.uk/~sd601/papers/mov.pdf , https://github.com/xoreaxeaxeax/movfuscator PS: Found these links on hn.algolia.com, the HN threads are: https://news.ycombinator.com/item?id=6309631 https://news.ycombinator.com/item?id=9751312
Re: Does a compiler use all x86 instructions? (2010)
#46My question is if compilers use "new" x86 instructions, as then the program won't work at all on old systems. For example, if Intel decided today that CPUs need a new "fast" hashing opcode (I don't know if they actually do), a compiler can't compiles to it, as programs won't work on older computers. Is it like the API cruft in Android, where "new" Lollipop APIs are introduced for 10 years from now, when no one uses a…
This is the main reason why Apple is now pushing for LLVM bitcode, Android still uses dex even when AOT compiling and WP uses MDIL with AOT compilation at the store.
So regardless of what an OEM decides for their mobile device, in theory, it is possible to make the best use of the chosen CPU.
This is actually quite common in the mainframes, with AS/400 (now IBM i) being one of the most well known ones.
Re: Does a compiler use all x86 instructions? (2010)
#47Re: Does a compiler use all x86 instructions? (2010)
#48It doesn't, because there are lots of special-purpose x86 instructions that would be more trouble than they're worth to teach a compiler about. For example, instructions for accessing particular CPU features that the C and C++ languages have no concept of (cryptographic acceleration and instructions used for OS kernel code spring to mind). Some of these the compiler might know about via intrinsic functions, but won't…
Could you provide some links or examples? I'd love to learn more about this.
As for `lea`, there's nothing particularly special about it. x86 allows you to do some 'funny' addressing within instructions that take memory addresses - where you can do several calculations on the address within the instruction itself, without having to use a temporary to hold the address. `lea` just lets you 'load' the result of that calculation back into a register, presumably to let you avoid making the CPU do the calculation a bunch of times in a row. But there's nothing about `lea` that requires you to actually use addresses, rather then just plain numbers you want to shift and add. It is used a lot because `lea` is a single instruction and will generally run faster then doing a shift and some additions over multiple instructions.
Re: Does a compiler use all x86 instructions? (2010)
#49My question is if compilers use "new" x86 instructions, as then the program won't work at all on old systems. For example, if Intel decided today that CPUs need a new "fast" hashing opcode (I don't know if they actually do), a compiler can't compiles to it, as programs won't work on older computers. Is it like the API cruft in Android, where "new" Lollipop APIs are introduced for 10 years from now, when no one uses a…