4 ms·
Could you provide some links or examples? I'd love to learn more about this.
by Majster 10y ago
Could you provide some links or examples? I'd love to learn more about this.
- saynsedit 10y agoJust read the output of your compiler for simple functions. objdump -d, or, cc -S
- zeusk 10y agoobjdump -S does the trick too, it even has the C code intermixed if the -g CFLAG was used.
- mattgodbolt 10y agohttps://gcc.godbolt.org/ https://gcc.godbolt.org/ may help too
- deleted 10y ago[deleted]
- DSMan195276 10y agoFor 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.