> but I have no clue why there are so many lea everywhere. Pointer arithmetic? Which is used for well, ... many things.
Does a compiler use all x86 instructions? (2010)
11–20 of 198 posts
Re: Does a compiler use all x86 instructions? (2010)
#12It 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…
There are also AFIAK a few "deprecated" instructions that are implemented for backward compatibility but do not perform well on modern cores or have much better modern alternatives. These would be things like old MMX instructions, cruft left over from the 16-bit DOS days, etc. X86 is crufty. Of course all old architectures are crufty, and using microcode it's probably possible to keep the cruft from taking up much si…
Re: Does a compiler use all x86 instructions? (2010)
#13Re: Does a compiler use all x86 instructions? (2010)
#14It 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…
There are also AFIAK a few "deprecated" instructions that are implemented for backward compatibility but do not perform well on modern cores or have much better modern alternatives. These would be things like old MMX instructions, cruft left over from the 16-bit DOS days, etc. X86 is crufty. Of course all old architectures are crufty, and using microcode it's probably possible to keep the cruft from taking up much si…
Re: Does a compiler use all x86 instructions? (2010)
#15Sometimes new and fancy instructions can end up being slower as opposed to using more but more standard "older" instructions to get the job done.
Re: Does a compiler use all x86 instructions? (2010)
#16> but I have no clue why there are so many lea everywhere. Pointer arithmetic? Which is used for well, ... many things.
lea is used to implement addition in OCaml: http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/e86a2...
Re: Does a compiler use all x86 instructions? (2010)
#17Earlier quoted context omitted.
There are also AFIAK a few "deprecated" instructions that are implemented for backward compatibility but do not perform well on modern cores or have much better modern alternatives. These would be things like old MMX instructions, cruft left over from the 16-bit DOS days, etc. X86 is crufty. Of course all old architectures are crufty, and using microcode it's probably possible to keep the cruft from taking up much si…
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.
Re: Does a compiler use all x86 instructions? (2010)
#18Earlier quoted context omitted.
There are also AFIAK a few "deprecated" instructions that are implemented for backward compatibility but do not perform well on modern cores or have much better modern alternatives. These would be things like old MMX instructions, cruft left over from the 16-bit DOS days, etc. X86 is crufty. Of course all old architectures are crufty, and using microcode it's probably possible to keep the cruft from taking up much si…
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.
Re: Does a compiler use all x86 instructions? (2010)
#19> but I have no clue why there are so many lea everywhere. Pointer arithmetic? Which is used for well, ... many things.
So if you write:
a = 4 * b + c + 10;
It will be optimised to a single instruction like: lea 0xa(%rsi,%rdi,4),%rax
Rather than the more naive: imul $0x4,%rdi,%rax
add %rsi,%rax
add $0xa,%raxRe: Does a compiler use all x86 instructions? (2010)
#20Earlier quoted context omitted.
lea is used to implement addition in OCaml: http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/e86a2...
Yea, I've seen compilers use lea for some integer math in C/C++, because it is handled by a different part of the CPU and so can happen in parallel with other integer math ops.