Discussion:
sizeof(long double)
Pascal Stumpf
2012-08-11 13:53:40 UTC
Permalink
Hi,
pcc trunk fails to compile since the addition of -Wall -Werror to the
default CFLAGS. This is because -Wbounded (an OpenBSD addition)
complains about a memcpy:

gcc -g -O2 -Wall -Werror -Wmissing-prototypes -Wstrict-prototypes
-Wshadow -Wsign-compare -Wno-error=uninitialized -DGCC_COMPAT
-DPCC_DEBUG -D_ISOC99_SOURCE -Dos_openbsd -Dmach_amd64 -I. -I. -I../..
-I../../mip -I../../arch/amd64 -I../../os/openbsd -c -o builtins.o
./builtins.c
cc1: warnings being treated as errors
./builtins.c: In function 'builtin_nanx':
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
./builtins.c:599: warning: array size (12) smaller than bound length
(16)


This is because PCC assumes a size of 12 bytes for a "long double" by
default, whereas sizeof() returns the true size (16). This is
apparently never checked, and LDBL_128 is never defined. It should be
easy to add an autoconf test for this though ...
Anders Magnusson
2012-08-11 15:45:28 UTC
Permalink
Hi,
Post by Pascal Stumpf
Hi,
pcc trunk fails to compile since the addition of -Wall -Werror to the
default CFLAGS. This is because -Wbounded (an OpenBSD addition)
gcc -g -O2 -Wall -Werror -Wmissing-prototypes -Wstrict-prototypes
-Wshadow -Wsign-compare -Wno-error=uninitialized -DGCC_COMPAT
-DPCC_DEBUG -D_ISOC99_SOURCE -Dos_openbsd -Dmach_amd64 -I. -I. -I../..
-I../../mip -I../../arch/amd64 -I../../os/openbsd -c -o builtins.o
./builtins.c
cc1: warnings being treated as errors
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
This is because PCC assumes a size of 12 bytes for a "long double" by
default, whereas sizeof() returns the true size (16). This is
apparently never checked, and LDBL_128 is never defined. It should be
easy to add an autoconf test for this though ...
Hm. Well, a "long double" is handled by the x87 math coprocessor
on amd64, so it is in fact 10. But this is an ABI thingie, and when looking
at the current code I did some changes so that it will work on both
x86 and x64 targets (that uses the x87 for long double).

Thanks for the bug report!

-- Ragge
ольга крыжановская
2012-08-11 15:51:31 UTC
Permalink
Anders, have a look at gcc(1):
--------------------
-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.
--------------------

So if I interpret this correctly, then x86-32 (32bit i386) uses 96bits
to store the 80bit long double and x86-64 (64bit AMD64) uses 128bit
for storing a 80bit long double.

Olga
Post by Anders Magnusson
Hi,
Post by Pascal Stumpf
Hi,
pcc trunk fails to compile since the addition of -Wall -Werror to the
default CFLAGS. This is because -Wbounded (an OpenBSD addition)
gcc -g -O2 -Wall -Werror -Wmissing-prototypes -Wstrict-prototypes
-Wshadow -Wsign-compare -Wno-error=uninitialized -DGCC_COMPAT
-DPCC_DEBUG -D_ISOC99_SOURCE -Dos_openbsd -Dmach_amd64 -I. -I. -I../..
-I../../mip -I../../arch/amd64 -I../../os/openbsd -c -o builtins.o
./builtins.c
cc1: warnings being treated as errors
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
This is because PCC assumes a size of 12 bytes for a "long double" by
default, whereas sizeof() returns the true size (16). This is
apparently never checked, and LDBL_128 is never defined. It should be
easy to add an autoconf test for this though ...
Hm. Well, a "long double" is handled by the x87 math coprocessor
on amd64, so it is in fact 10. But this is an ABI thingie, and when looking
at the current code I did some changes so that it will work on both
x86 and x64 targets (that uses the x87 for long double).
Thanks for the bug report!
-- Ragge
--
, _ _ ,
{ \/`o;====- Olga Kryzhanovska -====;o`\/ }
.----'-/`-/ ***@gmail.com \-`\-'----.
`'-..-| / http://twitter.com/fleyta \ |-..-'`
/\/\ Solaris/BSD//C/C++ programmer /\/\
`--` `--`
Anders Magnusson
2012-08-18 15:52:38 UTC
Permalink
Yep, correct. The change I did was to have the constant big enough for
both of them :-)

-- Ragge
Post by ольга крыжановская
--------------------
-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.
--------------------
So if I interpret this correctly, then x86-32 (32bit i386) uses 96bits
to store the 80bit long double and x86-64 (64bit AMD64) uses 128bit
for storing a 80bit long double.
Olga
Post by Anders Magnusson
Hi,
Post by Pascal Stumpf
Hi,
pcc trunk fails to compile since the addition of -Wall -Werror to the
default CFLAGS. This is because -Wbounded (an OpenBSD addition)
gcc -g -O2 -Wall -Werror -Wmissing-prototypes -Wstrict-prototypes
-Wshadow -Wsign-compare -Wno-error=uninitialized -DGCC_COMPAT
-DPCC_DEBUG -D_ISOC99_SOURCE -Dos_openbsd -Dmach_amd64 -I. -I. -I../..
-I../../mip -I../../arch/amd64 -I../../os/openbsd -c -o builtins.o
./builtins.c
cc1: warnings being treated as errors
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
./builtins.c:599: warning: array size (12) smaller than bound length
(16)
This is because PCC assumes a size of 12 bytes for a "long double" by
default, whereas sizeof() returns the true size (16). This is
apparently never checked, and LDBL_128 is never defined. It should be
easy to add an autoconf test for this though ...
Hm. Well, a "long double" is handled by the x87 math coprocessor
on amd64, so it is in fact 10. But this is an ABI thingie, and when looking
at the current code I did some changes so that it will work on both
x86 and x64 targets (that uses the x87 for long double).
Thanks for the bug report!
-- Ragge
Loading...