[Speex-dev] [patch] Mac Universal Binaries

Erik de Castro Lopo mle+la at mega-nerd.com
Thu May 3 20:05:48 PDT 2007


Peter Grayson wrote:

> Can you elaborate on what kind of CPU vagaries come into play besides
> endianess?

One issue I found was the cpu behaviour when converting from 
float/double to int32 when the source float is outside the range
 of values that can be represented by the int32.

For instance:

      float           int32_ppc      in32_x86
      2147483649.0    2147483647   -2147483648
      2147483648.0    2147483647   -2147483648
      2147483647.0    2147483647    2147483647  (0x7fffffff)
        ....
     -2147483648.0   -2147483648   -2147483648
     -2147483649.0   -2147483648   -2147483648  (0x80000000)
     -2147483650.0   -2147483648   -2147483648

As you can see out of range floats are correctly clipped on PPC,
but only correctly clipped for negative floats on x86.

libsndfile has code a bit like this:

    if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= 1.0 * 0x7FFFFFFF)
        int_value = 0x7fffffff ;

    if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
        int_value = 0x80000000 ;

On PPC, the above two lines get optimised out. On Intel x86, only 
the second gets optimised out.

> Do they affect all code or just highly-optimized code?

The float -> int issue affects all code where the source float
is greater than 0x7fffffff. Yes it is a rather obscure corner
case.

> have built several open source projects as universal binaries and they
> basically function. If you know of specific risks to look out for,
> your experiences would help a lot of people.

AFAIAC, all code should have a test suite. For universal binary
builds (and any cross compile builds), the test suite must be run 
on both platforms.

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
Saying Python is easier than C++ is like saying that turning a 
light  switch on or off is easier than operating a nuclear reactor.


More information about the Speex-dev mailing list