[xproto: PATCH] Xmd.h: amd64-x32 ABI defines sizeof(long) == sizeof (void*) == 4

Sergei Trofimovich slyich at gmail.com
Fri Dec 30 12:07:36 PST 2011


On Wed, 28 Dec 2011 12:45:03 -0800
Alan Coopersmith <alan.coopersmith at oracle.com> wrote:

> On 12/28/11 12:29, Lu, Hongjiu wrote:
> >>
> >>> From: "Lu, Hongjiu"<hongjiu.lu at intel.com>
> >>> Date: Wed, 28 Dec 2011 14:34:09 +0000
> >>>
> >>> __AMD64__ is defined when 64bit x86 instruction set is used,
> >>> which is true for x32. The difference is x32 doesn't define
> >>> __LP64__.
> >>
> >> Chapter 7, "Development Environment", of the AMD64 ABI (the non-x32
> >> version) does not list __LP64__ as a predefined pre-processor symbol.
> >> As far as I'm aware, it's just a GCC convention to define __LP64__ for
> >> platforms that use the LP64 programming model, and even GCC didn't do
> >> so very consistently in the past.
> >
> > __LP64__ isn't the part of x86-64 psABI while GCC always define __LP64__
> > for 64bit long on x86.  I can check if other compilers do the same.
> >
> > In most cases, __amd64__ is checked for 64bit instructions and we have
> > ported those we have found so far to x32 so that we can use one __amd64__
> > block to support both x32 and x86-64.
> 
> C code checking __amd64__ mostly does so to find out the size of long & 
> pointers.  Instructions are usually at the assembly level, not the C code level.

It's a very generic tet. Such software is already broken for very popular MSVC
compiler (or mingw64-gcc).

Looking for __amd64__ in /usr/include things like endianness test and inline gcc
assembly pop up most of the time.

Aside: Portable software already lives with it (or solves problems the other way).
          If one needs reliable storage for void* one uses [u]intptr_t.
          For guaranteed 64bit value one uses [u]int64_t.
          They are POSIXish, but are easy to reimplement for weird systems.

> It would make far more sense for x32 to declare it's __i386__ with additional
> instructions available (much like MMX, SSE, etc.) than to declare that it's
> __amd64__ with incompatible types.

amd64 instruction set is not a superset of i386, otherwise __amd64__ would not exist at all.
- amd64 can't address certain "small" register forms (like %bh)
- can't encode many legacy instructions (decimal ones for example: DAA, DAS, etc.)
- can't encode many prefixes (ES, SS overrides, etc.).

-- 

  Sergei
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20111230/83e82a11/attachment.pgp>


More information about the xorg-devel mailing list