[Vm-dev] Removing UB to make SmallFloat handling gcc 4.9.2 -O2
compatible [WAS: first 64 bits windows VM Running]
avalloud at smalltalk.comcastbiz.net
Thu Jul 21 00:41:53 UTC 2016
> Or better: eliminate Undefined Behavior which is most probably the
> cause of problems
This is a good start for a default debugging procedure.
> Note: i've successfully compiled Squeak stack spur 64 bits with gcc
> 4.9.2 -02 and restored the correct behavior for SmallFloat:
> 2.0*3.0 correctly answer 6.0 instead of 4.0...
> Why is memcpy less evil than pointer aliasing?
> With pointer aliasing any other write into a long integer could modify
> This completely defeat optimization - the holy grail of C people, they
> can't bother that FORTRAN compilers are faster than theirs ;). With
> great wisdom they declared this construct as undefined behavior, giving
> priority to optimization rather than backward compatibility or
> programmers' intentions...
> memcpy is less evil because it's localized (one shot).
The GCC manual warns of potential issues with memcpy(), and recommends
using unions instead. The union method worked on every HPS compilation
environment, across multiple optimization levels. Whenever I checked,
the resulting assembly code was optimal.
More information about the Vm-dev