[Discuss] gcc 128 bits and all that!

John Blomfield jabfield at shaw.ca
Sat Mar 1 10:38:33 PST 2008


Hi Alan,

I thought I had better start a new thread as the original had gone a 
little off topic.

I note that my current 32 bit AMD CPU has gcc 4.1.2 installed as the 
default and accordingly these sets double and long double (in standard C 
and C++) both to 8 byte words (memory) which I assumed are handled in 
the CPU's ALU with software to fit 4 bytes.  I am awaiting next week a 
new desktop box with an AMD 64 CPU so I was interested to know how if 
that would change anything (not that I need more precision these days).  
I found the following in the gcc 4.1.2 manual on gcc switches:

|"-m128bit-long-double|
    These switches control the size of |long double| type. The i386
    application binary interface specifies the size to be 96 bits, so
    -m96bit-long-double is the default in 32 bit mode.

    Modern architectures (Pentium and newer) would prefer |long double|
    to be aligned to an 8 or 16 byte boundary. In arrays or structures
    conforming to the ABI, this would not be possible. So specifying a
    -m128bit-long-double will align |long double| to a 16 byte boundary
    by padding the |long double| with an additional 32 bit zero.

    In the x86-64 compiler, -m128bit-long-double is the default choice
    as its ABI specifies that |long double| is to be aligned on 16 byte
    boundary.

    Notice that neither of these options enable any extra precision over
    the x87 standard of 80 bits for a |long double|.

    *Warning:* if you override the default value for your target ABI,
    the structures and arrays containing |long double| variables will
    change their size as well as function calling convention for
    function taking |long double| will be modified. Hence they will not
    be binary compatible with arrays or structures in code compiled
    without that switch." (end quote)

My understanding is that though gcc can handle 80 bit long doubles, the 
implementation of C may not.  I have not waded through all the ANSI C 
documentation but did come across the following from Intel.

*"C Standard Conformance*
The Intel® C++ Compilers conforms to the ANSI/ISO standard ISO/IEC 
9899:1999 for C language with one limitation:

    * long double (128-bit representations) is not supported." (end quote)

This suggests that C can now handle 128 bit long doubles.  I did a test 
on my current box and sizeof( long double) returned 8 bytes.  I shall be 
interested to see what happens on my new box.

This all begs the question as to what happens with the gcc Fortran 
compiler.  I haven't used Fortran for a long time so I haven't run a 
test on it ( I would need to hit the books to do that ).

John Blomfield




More information about the Discuss mailing list