1 # A.1 Floating-Point Round to Single-Precision Model
3 The following describes algorithmically the operation of the Floating
4 Round to Single-Precision instruction.
6 <!-- OPF_PowerISA_v3.1B.pdf Book I Section A.1 page 1005-1008(1031-1034) -->
9 if ((FRB)[1:11] <u 897) & ((FRB)[1:63] >u 0) then
11 return FRSP_Disabled_Exponent_Underflow(FRB)
13 return FRSP_Enabled_Exponent_Underflow(FRB)
15 if ((FRB)[1:11] >u 1150) & ((FRB)[1:11] <u 2047) then
17 return FRSP_Disabled_Exponent_Overflow(FRB)
19 return FRSP_Enabled_Exponent_Overflow(FRB)
21 if ((FRB)[1:11] >u 896) & ((FRB)[1:11] <u 1151) then
22 return FRSP_Normal_Operand(FRB)
24 if (FRB)[1:63] = 0 then
25 return FRSP_Zero_Operand(FRB)
27 if (FRB)[1:11] = 2047 then
28 if (FRB)[12:63] = 0 then
29 return FRSP_Infinity_Operand(FRB)
31 return FRSP_QNaN_Operand(FRB)
32 if ((FRB)[12] = 0) & ((FRB)[13:63] >u 0) then
33 return FRSP_SNaN_Operand(FRB)
35 def FRSP_Disabled_Exponent_Underflow(FRB):
39 if (FRB)[1:11] = 0 then
41 frac[0:52] <- 0b0 || (FRB)[12:63]
42 if (FRB)[1:11] >u 0 then
43 exp <- (FRB)[1:11] - 1023
44 frac[0:52] <- 0b1 || (FRB)[12:63]
46 # Denormalize operand:
55 frac[0:52] <- 0b0 || frac[0:51]
57 FPSCR[UX] <- (frac[24:52] || G || R || X) >u 0
58 exp, frac <- Round_Single(sign, exp, frac[0:52], G, R, X)
59 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
61 if frac[0:52] = 0 then
64 if sign = 0 then FPSCR[FPRF] <- '+ zero'
65 if sign = 1 then FPSCR[FPRF] <- '- zero'
66 if frac[0:52] >u 0 then
68 if sign = 0 then FPSCR[FPRF] <- '+ normal number'
69 if sign = 1 then FPSCR[FPRF] <- '- normal number'
71 if sign = 0 then FPSCR[FPRF] <- '+ denormalized number'
72 if sign = 1 then FPSCR[FPRF] <- '- denormalized number'
77 frac[0:52] <- frac[1:52] || 0b0
80 FRT[1:11] <- exp + 1023
81 FRT[12:63] <- frac[1:52]
84 def FRSP_Enabled_Exponent_Underflow(FRB):
89 if (FRB)[1:11] = 0 then
91 frac[0:52] <- 0b0 || (FRB)[12:63]
92 if (FRB)[1:11] >u 0 then
93 exp <- (FRB)[1:11] - 1023
94 frac[0:52] <- 0b1 || (FRB)[12:63]
99 frac[0:52] <- frac[1:52] || 0b0
101 exp, frac <- Round_Single(sign, exp, frac[0:52], 0b0, 0b0, 0b0)
102 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
106 FRT[1:11] <- exp + 1023
107 FRT[12:63] <- frac[1:52]
108 if sign = 0 then FPSCR[FPRF] <- '+ normal number'
109 if sign = 1 then FPSCR[FPRF] <- '- normal number'
112 def FRSP_Disabled_Exponent_Overflow(FRB):
115 if FPSCR[RN] = 0b00 then # Round to Nearest
116 if (FRB)[0] = 0 then FRT <- 0x7FF0_0000_0000_0000
117 if (FRB)[0] = 1 then FRT <- 0xFFF0_0000_0000_0000
118 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ infinity'
119 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- infinity'
120 if FPSCR[RN] = 0b01 then # Round toward Zero
121 if (FRB)[0] = 0 then FRT <- 0x47EF_FFFF_E000_0000
122 if (FRB)[0] = 1 then FRT <- 0xC7EF_FFFF_E000_0000
123 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ normal number'
124 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- normal number'
125 if FPSCR[RN] = 0b10 then # Round toward +Infinity
126 if (FRB)[0] = 0 then FRT <- 0x7FF0_0000_0000_0000
127 if (FRB)[0] = 1 then FRT <- 0xC7EF_FFFF_E000_0000
128 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ infinity'
129 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- normal number'
130 if FPSCR[RN] = 0b11 then # Round toward -Infinity
131 if (FRB)[0] = 0 then FRT <- 0x47EF_FFFF_E000_0000
132 if (FRB)[0] = 1 then FRT <- 0xFFF0_0000_0000_0000
133 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ normal number'
134 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- infinity'
135 FPSCR[FR] <- undefined(0) # FIXME: figure out what values POWER9 uses
140 def FRSP_Enabled_Exponent_Overflow(FRB):
142 exp <- (FRB)[1:11] - 1023
144 frac[0:52] <- 0b1 || (FRB)[12:63]
145 exp, frac <- Round_Single(sign, exp, frac[0:52], 0b0, 0b0, 0b0)
146 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
152 FRT[1:11] <- exp + 1023
153 FRT[12:63] <- frac[1:52]
154 if sign = 0 then FPSCR[FPRF] <- '+ normal number'
155 if sign = 1 then FPSCR[FPRF] <- '- normal number'
158 def FRSP_Zero_Operand(FRB):
160 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ zero'
161 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- zero'
165 def FRSP_Infinity_Operand(FRB):
167 if (FRB)[0] = 0 then FPSCR[FPRF] <- '+ infinity'
168 if (FRB)[0] = 1 then FPSCR[FPRF] <- '- infinity'
172 def FRSP_QNaN_Operand(FRB):
173 FRT <- (FRB)[0:34] || [0b0] * 29
174 FPSCR[FPRF] <- 'QNaN'
179 def FRSP_SNaN_Operand(FRB):
182 if FPSCR[VE] = 0 then
183 FRT[0:11] <- (FRB)[0:11]
185 FRT[13:63] <- (FRB)[13:34] || [0b0] * 29
186 FPSCR[FPRF] <- 'QNaN'
191 def FRSP_Normal_Operand(FRB):
193 exp <- (FRB)[1:11] - 1023
195 frac[0:52] <- 0b1 || (FRB)[12:63]
196 exp, frac <- Round_Single(sign, exp, frac[0:52], 0b0, 0b0, 0b0)
197 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
198 if (exp > 127) & (FPSCR[OE] = 0) then
199 return FRSP_Disabled_Exponent_Overflow(FRB)
200 if (exp > 127) & (FPSCR[OE] = 1) then
201 return FRSP_Enabled_Overflow(FRB)
204 FRT[1:11] <- exp + 1023
205 FRT[12:63] <- frac[1:52]
206 if sign = 0 then FPSCR[FPRF] <- '+ normal number'
207 if sign = 1 then FPSCR[FPRF] <- '- normal number'
210 def Round_Single(sign, exp, frac, G, R, X):
215 xbit <- (frac[26:52]||G||R||X) != 0
216 if FPSCR[RN] = 0b00 then # Round to Nearest
217 # comparisons ignore u bits
218 if (lsb || gbit) = 0b11 then inc <- 1
219 if (lsb || gbit || rbit) = 0b011 then inc <- 1
220 if (lsb || gbit || xbit) = 0b011 then inc <- 1
221 if FPSCR[RN] = 0b10 then # Round toward + Infinity
222 # comparisons ignore u bits
223 if (sign || gbit) = 0b01 then inc <- 1
224 if (sign || rbit) = 0b01 then inc <- 1
225 if (sign || xbit) = 0b01 then inc <- 1
226 if FPSCR[RN] = 0b11 then # Round toward - Infinity
227 # comparisons ignore u bits
228 if (sign || gbit) = 0b11 then inc <- 1
229 if (sign || rbit) = 0b11 then inc <- 1
230 if (sign || xbit) = 0b11 then inc <- 1
231 frac[0:23] <- frac[0:23] + inc
232 if (inc = 1) & (frac[0:23] = 0) then
233 frac[0:23] <- 0b1 || frac[0:22]
235 frac[24:52] <- [0b0] * 29
237 FPSCR[FI] <- gbit | rbit | xbit
240 <!-- Power ISA v3.0B p140 section 4.6.2 -->
248 if (WORD[1:8] >u 0) & (WORD[1:8] <u 255) then
249 FRT[0:1] <- WORD[0:1]
253 FRT[5:63] <- WORD[2:31] || [0]*29
254 # Denormalized Operand
255 if (WORD[1:8] = 0) & (WORD[9:31] != 0) then
258 frac[0:52] <- 0b0 || WORD[9:31] || [0]*29
259 #normalize the operand
261 frac[0:52] <- frac[1:52] || 0b0
264 FRT[1:11] <- exp + 1023
265 FRT[12:63] <- frac[1:52]
266 # Zero / Infinity / NaN
267 if (WORD[1:8] = 255) | (WORD[1:31] = 0) then
268 FRT[0:1] <- WORD[0:1]
272 FRT[5:63] <- WORD[2:31] || [0]*29