This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: recent change to binutils' include/opcode/i386.h
- From: Zack Weinberg <zack at codesourcery dot com>
- To: "H. J. Lu" <hjl at lucon dot org>
- Cc: Jan Beulich <JBeulich at novell dot com>, binutils at sources dot redhat dot com
- Date: Fri, 23 Jul 2004 10:41:52 -0700
- Subject: Re: recent change to binutils' include/opcode/i386.h
- References: <s100c3d9.002@emea1-mh.id2.novell.com><20040723140035.GA31423@lucon.org>
"H. J. Lu" <hjl@lucon.org> writes:
> On Fri, Jul 23, 2004 at 08:53:36AM +0200, Jan Beulich wrote:
>> it would seem to me that the change to again allow cs/ds prefixes in
>> 64-bit mode should be undone. If you want branch prediction hints, use
>> the ,ht and ,hn instruction suffixes. Using segment overrides in their
>> place is counter intuitive, and generally allowing them in 64-bit mode
>> is an error in any case (if you absolutely wanted to allow them for this
>> specific purpose, then you'd have to add checks in other places
>> preventing incorrect uses).
>
> All the current gccs in CVS and released versions use "cs/ds ;" as
> branch hints for EM64T. You can see that by passing -march=nocona to
> gcc 3.3, 3.4 and 3.5 for x86-64. Assembler has to support it. As far
> as I know, all x86-64 chips can handle segment prefixes. Whether they
> do anyhing useful is entirely a different question.
The hardware must support this - at least as a NOP - because
"cs; je .L1" and "je,pn .L1" assemble to exactly the same thing
(except for the assembler miscalculating the branch offset).
See for yourself:
$ cat test.s
.text
ds ; je .+2 # offset miscalculated
cs ; je .+2 # offset miscalculated
je,pt .+3
je,pn .+3
$ as test.s
$ objdump -d a.out
a.out: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: 3e 74 00 je,pt 0x3
3: 2e 74 00 je,pn 0x6
6: 3e 74 00 je,pt 0x9
9: 2e 74 00 je,pn 0xc
I assume that the offset miscalculation is due to the problem HJ is
trying to solve, i.e. the x86-64 assembler rejecting explicit ds/cs
prefixes on branch instructions.
HJ is correct - all released versions of GCC that support x86-64 emit
explicit segment prefixes for hinted branch instructions, for both 32-
and 64-bit i386. Therefore the assembler does have to support this
idiom. Sorry, ideological purity has no place in a discussion of
compatibility between two programs.
zw