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: Development vs Deployment




On Jan 13, 2005, at 11:32 AM, Charles PARNOT wrote:



Sorry, just a newbie question.

Is it normal that you get slightly different numeric results in deployment vs developement build in Xcode? (which translates in different -o flag values in gcc)


Yes, the development build usually doesn't use fused multiply add instructions. These return different results from ordinary multiply plus an ordinary add, because there is no rounding step inbetween. (In a fused multiply add, the multiply produces infinitely precise results, the addition is done, then the result is rounded down to single or double precision as appropriate.) Because the fused multiply add operations are in general more accurate, because of no intermediate rounding, results will be different.


There are other reasons too, if you are passing stuff like the fast math flag.

Please note that fused multiply adds can do unpleasant things in certain cases, especially with complex numbers. The problem is due asymmetrical rounding:

    C1 = Round( Ar * Br )
    C2 = Round( Ai * Bi )
    result = Round( C1 - C2 )

vs

    C1 = Round( Ar * Br )
    result = Round( C1 - Ai * Bi )

Note that in the second case, the real product is rounded before the subtraction while the imaginary product is infinitely precise. If these are supposed to all cancel out and return a zero result (which they do in the top case), you'll likely get a small non-zero result in the second case. Edge case behavior is also different between FMA and multiply + add, if you need your signed zeros, Infs and NaNs to all come out right.

However, most of the time the fused multiply add is the right thing to do for performance and accuracy.

Ian
_______________________________________________
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: 
 >Development vs Deployment (From: Charles PARNOT <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.