Messages in this thread | | | Date | Mon, 09 Jul 2018 02:47:10 -0600 | From | "Jan Beulich" <> | Subject | Re: [PATCH v2] x86-64: use 32-bit XOR to zero registers |
| |
>>> On 09.07.18 at 10:33, <pavel@ucw.cz> wrote: > Anyway, normally assembler is the one who chooses instruction > encoding.
There are different possible views here, and I personally think that while it is a compiler's job to chose optimal encodings, assemblers shouldn't by default alter what the programmer (or compiler) has specified, unless there are multiple encodings that are _entirely_ identical in effect, but which are _truly_ different encodings (and presence/absence of instruction prefixes to me doesn't count as "truly different"). This view is particularly on the basis that assembly programmers often imply a certain encoding to be chosen, be it just to imply size, or to go as far as meaning to run-time patch code.
> xor %rax, %rax is equivalent to xor %eax, %eax; first variant is > slower on some CPUs, second variant will take one extra byte due to > operand size prefix IIRC...
The second variant is actually shorter by one byte.
> Should the assembler generate right > variant according to the CPU type?
An "optimization" mode has recently been added to gas, but in general as well as for the sake of older gas I don't think we should rely on this new behavior (which is also off by default) except in cases where the impact on the source code would be undesirable (as can e.g. be the case when macro-izing things).
Jan
| |