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)




On 22 okt 2004, at 03:57, John Stiles wrote:

compiler could certainly generate cmpwi, mfcr, rlwinm to get this value. I've never seen a compiler generate code like this in practice, however.

Ok, this is somewhat OT, but nevertheless I'm proud :) The Free Pascal Compiler (which is probably completely useless for 99% of the people on this list) does use those those instructions:


# [5] tmp := alpha * red;
mullw r3,r10,r9
# [6] remainder256 := tmp and $FF; // get alpha * red (mod 256)
rlwinm r4,r3,0,24,31
# [7] dividend := tmp >> 8; // compute alpha * red / 256
srwi r5,r3,8
# [8] remainder255 := dividend + remainder256; // compute alpha * red (mod 255)
add r6,r4,r5
# [9] inc(dividend,ord(remainder255 >= (255 + 128)) + ord(remainder255 >= 128)); // add 0, 1, 2 depending on how large the remainder (mod 255) is
cmplwi r6,383
mfcr r7
rlwinm r7,r7,1,31,31
xori r7,r7,1
cmplwi r6,128
mfcr r8
rlwinm r8,r8,1,31,31
xori r8,r8,1
add r8,r8,r7
add r5,r5,r8


Whether it's that much faster is another question though, since that stuff is mostly serialised I suppose (and we don't have an instruction scheduler yet). And that last part could be optimized by sending the result of one of the compares to cr1, so you need only one mfcr.


Jonas

_______________________________________________
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>)
 >Re: float to int (kinda OT) (From: John Stiles <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.