Bug 43112 - 'A' constraint's behavior not compliant with doc under x86-64
Summary: 'A' constraint's behavior not compliant with doc under x86-64
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: inline-asm (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-18 05:59 UTC by Zuxy
Modified: 2010-02-18 08:56 UTC (History)
1 user (show)

See Also:
Host: x86_64-redhat-linux
Target: x86_64-redhat-linux
Build: x86_64-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zuxy 2010-02-18 05:59:27 UTC
According to "info gcc", the 'A' constraint denotes the `a' and `d'
registers, as a pair (for instructions that return half the result in
one and half in the other). However, in reality 'A' is treated simply as
a 64-bit long integer in %rax under x86-64. For example, the following
code piece:

#include <stdint.h>

uint64_t rdtsc(void)
{
	uint64_t ret;
	asm ("rdtsc":"=A"(ret));
	return ret;
}

produces:

[zuxy@Rainbow31 bin]$ objdump -d a.o

a.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <rdtsc>:
   0:	0f 31                	rdtsc
   2:	c3                   	retq
Comment 1 Jakub Jelinek 2010-02-18 08:56:30 UTC
You just misunderstand it.  You'd need a 128-bit int __attribute__((mode (TI)))
value if you want it to mean a pair, because for -m64 registers are 64-bit.
If you use smaller precision type, "A" constraint acts just as a constraint allowing both ax and dx registers and it is up to the compiler which one it chooses.
rdtsc returns result in %eax and %edx, even for 64-bit code, so you need to use
unsigned int low, high;
"=a" (low), "=d" (high)
and then combine that into a 64-bit value.