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: float to int (kinda OT)



A compiler could certainly generate cmpwi, mfcr, rlwinm to get this value. I've never seen a compiler generate code like this in practice, however. It's possible that the branching technique is just faster than the mfcr technique on modern PowerPC hardware. (On the G5, it appears that mfcr is millicoded, so that right there is a huge strike against it.)

Personally, I've always wanted to see a compiler which would do smart things with the eight condition registers that each PowerPC has at its disposal. Right now everybody just uses cr0 for everything. (I think I've seen some rare instances where gcc will use cr7 as well.) Originally the PowerPC was going to minimize on branching by allowing you to do things like:
cmplwi cr1, something
cmplwi cr2, something
cmplwi cr3, something
cmplwi cr4, something
cror/crand something
bc something


That way you can stack a lot of comparisons together by or'ing and and'ing the condition bits. But no compiler actually generates it. (Again, it's possible that modern PowerPCs don't actually execute code like this any quicker than the usual way... chip designers, much like programmers, tend to optimize the paths that get the most use.)


On Oct 21, 2004, at 6:38 PM, Keith Bauer wrote:

I always think of (x >= y) as an int which happens to be either 0 or 1, but I guess that's not the case on the PowerPC at least, since the comparison operators don't put the results in the GPRs. Phooey :)

_______________________________________________ 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: 
 >Graphics card tricks (From: "Edward K. Chew" <email@hidden>)
 >Re: Graphics card tricks (From: Holger Bettag <email@hidden>)
 >Re: Graphics card tricks (From: Niall Dalton <email@hidden>)
 >float to int (kinda OT) (From: Ando Sonenblick <email@hidden>)
 >Re: float to int (kinda OT) (From: Brendan Younger <email@hidden>)
 >Re: float to int (kinda OT) (From: Chris Cox <email@hidden>)
 >Re: float to int (kinda OT) (From: Brendan Younger <email@hidden>)
 >Re: float to int (kinda OT) (From: Chris Cox <email@hidden>)
 >Re: float to int (kinda OT) (From: Keith Bauer <email@hidden>)
 >Re: float to int (kinda OT) (From: John Stiles <email@hidden>)
 >Re: float to int (kinda OT) (From: Keith Bauer <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.