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 30, 2004, at 2:56 AM, Jonas Maebe wrote:


On 30 Oct 2004, at 04:00, Chris Cox wrote:

There are no vectors there.
There are lots of single precision floats (lfs, stfs, fmuls), and lots of results being rounded to single precision (frsp).


Several of the frsp instructions look pointless since you just loaded the value as single precision.

You're right several are pointless, but at least the ones like this may not be (although they seem so at first sight):


frsp     f1,f2
stfs     f2,20(r28)

The reason is that some PPC's have a bug, whereby they throw an exception if you try to store an fpu value as a single without first explicitly rounding it to a single. I have to admit I'm not sure whether it can also pop up if the value in question has only been "touched" by single precision fpu ops though.



I recall something like this from way back... The question was whether 'stfs' can obviate the need for 'frsp' entirely. The Programming Environments Manual seems to indicate so, stating:


"The contents of register frS are converted to single-precision and stored into the word in memory."

However, there's a gotcha, buried in the appendices:

"Notice that if the value to be stored by a single-precision store floating-point instruction is larger in magnitude than [MAX_FLOAT], the result stored in WORD is then a well-defined value, but is not numerically equal to the value in the source register."

In other words, 'stfs' doesn't correctly handle values greater than MAX_FLOAT, so the 'frsp' is required to ensure that 'stfs' will always do the right thing. (Pity; I can't imagine it would have taken much silicon to avoid this.) Maybe the gcc compiler has a flag to bypass the 'frsp' anyway? I never heard of the exception throwing bug, but perhaps this is why CodeWarrior always generates a 'frsp' after 'fabs', even when the input is single-precision. E.g.

	static float foo(float x) { return __fabs(x); }

generates:

	fabs       fp1,fp1
	frsp       fp1,fp1
	blr

Very silly. Would be nice if the newer processors can detect this pattern and optimize the 'frsp' away. (Or is there a case I'm unaware of where 'fabs' on a single-precision value can produce a double-precision result?)

Ben

_______________________________________________
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>)



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.