Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "FP precision conv" with no floats in sight




On Oct 31, 2004, at 3:35 AM, Ben Weiss wrote:


> What other annoying processor bugs are lurking out there?

Is this really just a processor bug, or are we looking at a IEEE-754 conformance issue? Stfs doesn't appear to do rounding, and correct rounding is required for IEEE-754 compliance.

Take the below program as an example. When run without frsp, 0x3FFFFFFFFFFFFFFF (1.99999....) is truncated to 0x3FFFFFFF (1.999999...f) as a result of stfs. Whereas if you put a frsp in there, then it is correctly rounded to nearest (assuming that is the rounding mode) and you get 0x40000000 (2.0f, exactly), which is correct. While this may seem like one bit to you, to certain people, this is the difference between correct operation and garbage. As it is also required by the standard, so it is highly likely to be viewed by a compiler writer as the difference between correct operation and garbage.

The particular example mentioned at the start of this thread surprised me. I've seen GCC insert a lot of frsp's where I didn't particularly want them (right after frsqrte is the most common example), but I haven't actually seen a case where it was completely unjustified -- frsqrte is a double precision instruction after all, even if it is only accurate to 5 bits. However, right after a fmadds is completely unjustified in my opinion. It should probably be reported as a compiler bug.

Ian

#include <stdint.h>
#include <stdio.h>
int main( void )
{
        union
        {
                uint64_t        u;
                double          d;
        }a;
        union
        {
                uint32_t        u;
                float           f;
        }b;
        register double d;
        register double *dp = &a.d;
        register float *fp = &b.f;
        register int zero = 0;

        a.u = 0x3FFFFFFFFFFFFFFFULL;            /* almost 2 */

asm volatile( "lfd %0, 0(%1)" : "=f" (d) : "b" (dp) );
// asm volatile( "frsp %0, %1" : "=f" (d) : "f" (d) );
asm volatile( "stfs %0, 0(%1)" : : "f" (d), "b" (fp) : "memory" );


        printf( "0x%8.8x (%17.21g)\n", b.u, b.f );

        return 0;
}


_______________________________________________ Do not post admin requests to the list. They will be ignored. PerfOptimization-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden

This email sent to email@hidden
References: 
 >"FP precision conv" with no floats in sight (From: "James W. Walker" <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: John Stiles <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: "James W. Walker" <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Chris Cox <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Jonas Maebe <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Ben Weiss <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Holger Bettag <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Ben Weiss <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Jonas Maebe <email@hidden>)
 >Re: "FP precision conv" with no floats in sight (From: Ben Weiss <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.