Figure 3-50. Convert Floating-Point to 32-Bit Unsigned Integer Code Sequence
|
|
# FR0 = 0.0
|
|
|
# FR1 = value to be converted
|
|
|
# FR3 = 232 - 1
|
|
|
# FR4 = 231
|
|
|
# R3 = returned result
|
|
|
# disp = displacement from R1
|
|
|
|
|
|
|
|
32-Bit Implementation
|
|
|
fsel
|
FR2,FR1,FR1,FR0
|
# use 0 if < 0
|
|
|
fsub
|
FR5,FR3,FR1
|
# use 232-1 if >= 232
|
|
|
fsel
|
FR2,FR5,FR2,FR3
|
|
|
|
fsub
|
FR5,FR2,FR4
|
# subtract 2**31
|
|
|
fcmpu
|
cr2,FR2,FR4
|
|
|
|
fsel
|
FR2,FR5,FR5,FR2
|
# use diff if >= 231
|
|
|
|
|
# next part same as conversion to
|
|
|
|
|
# signed integer word
|
|
|
fctiw[z]
|
FR2,FR2
|
# convert to integer
|
|
|
stfd
|
FR2,disp(R1)
|
# copy unmodified to memory
|
|
|
lwz
|
R3,disp+4(R1)
|
# load low-order word
|
|
|
|
|
|
|
|
blt
|
cr2,$+8
|
# add 231 if input
|
|
|
xoris
|
R3,R3,0x8000
|
# was >= 231
|
|
|
|
|
|
|
|
64-Bit Implementation
|
|
|
fsel
|
FR2,FR1,FR1,FR0
|
# use 0 if < 0
|
|
|
fsub
|
FR4,FR3,FR1
|
# use 232-1 if >= 232
|
|
|
fsel
|
FR2,FR4,FR2,FR3
|
|
|
|
|
|
# next part same as conversion to
|
|
|
|
|
# signed integer word except
|
|
|
|
|
# convert to double
|
|
|
fctid[z]
|
FR2,FR2
|
# convert to doubleword integer
|
|
|
stfd
|
FR2,disp(R1)
|
# copy unmodified to memory
|
|
|
lwz
|
R3,disp+4(R1)
|
# load low-order word, zero extend
|