[FIX][VM] gcc 3.3 'float bug' cured

Ned Konz ned at bike-nomad.com
Wed Nov 12 20:10:45 UTC 2003


On Monday 28 July 2003 2:23 pm, Andreas Raab wrote:
> Hm ... I wonder if that might be a GCC optimization issue? IIRC, then we
> had problems with GCC 3+ in some areas and trying to optimize some of this
> C code _might_ get you in trouble if the optimizations aren't rock-solid.

I think I figured out the problems with this. I was having 3D problems with a 
3.6g-2 VM compiled with gcc 3.3.2 and -O2; I did a bit of research, and 
figured out what was happening.

Ian had some time ago narrowed down the problem to the fetchFloatAtinto() (and 
maybe the storeFloatAtfrom()) macros that looked like this:

#   define storeFloatAtfrom(i, floatVarName) \
	*((int *) (i) + 0) = *((int *) &(floatVarName) + 1); \
	*((int *) (i) + 1) = *((int *) &(floatVarName) + 0);
#   define fetchFloatAtinto(i, floatVarName) \
	*((int *) &(floatVarName) + 0) = *((int *) (i) + 1); \
	*((int *) &(floatVarName) + 1) = *((int *) (i) + 0);

If you compile the VM with enough warnings turned on, you'll see warnings 
about strict-aliasing on these macro invocations.

So I changed only the CFLAGS to add --no-strict-aliasing and the problems went 
away.

A small change to the definition of these macros removes the warning and the 
problems, and works with -O2 or -O3:

typedef union { double d; int i[sizeof(double) / sizeof(int)]; } _swapper;

#   define storeFloatAtfrom(intPointerToFloat, floatVarName) \
	*((int *)(intPointerToFloat) + 0) = ((_swapper *)(&floatVarName))->i[1]; \
	*((int *)(intPointerToFloat) + 1) = ((_swapper *)(&floatVarName))->i[0];
#   define fetchFloatAtinto(intPointerToFloat, floatVarName) \
	((_swapper *)(&floatVarName))->i[1] = *((int *)(intPointerToFloat) + 0); \
	((_swapper *)(&floatVarName))->i[0] = *((int *)(intPointerToFloat) + 1);

Patch is enclosed.
-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: floatbug.patch
Type: text/x-diff
Size: 2937 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20031112/ddfe6e08/floatbug.bin


More information about the Squeak-dev mailing list