Re:Does a compiler use all x86 instructions? (2010)
by Majster on Wednesday August 24, 2016 @12:38PM
(#12353261)
Could you provide some links or examples? I'd love to learn more about this.
[ Parent
| on HN ]
Re:Does a compiler use all x86 instructions? (2010)
by DSMan195276 on Wednesday August 24, 2016 @01:23PM
(#12353616)
For kernel/OS functions, there are lots of things that can only be done while in 'kernel-mode' with kernel privileges. These are things such as turning interrupts on and off, changing which page table is being used, changing the GDT/IDT, and other various things. C has no concept of these things, and they are very special purpose. The AES instructions are similar - C has no built-in AES functionality, and the compiler just can't figure-out in which situations it could use them. All of these instructions can be accesses through inline assembly, so you can still use them in C, the compiler just won't understand what you're doing besides "It takes in these inputs, does something, and then puts out these outputs".
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)
by saynsedit on Wednesday August 24, 2016 @12:52PM
(#12353380)
Just read the output of your compiler for simple functions. objdump -d, or, cc -S
Re:Does a compiler use all x86 instructions? (2010)
by zeusk on Wednesday August 24, 2016 @05:25PM
(#12355376)
objdump -S does the trick too, it even has the C code intermixed if the -g CFLAG was used.
Re:Does a compiler use all x86 instructions? (2010)
by mattgodbolt on Wednesday August 24, 2016 @10:09PM
(#12356555)
https://gcc.godbolt.org/ may help too