1 # A.3 Floating-Point Convert from Integer Model
3 The following describes algorithmically the operation of the Floating
4 Convert From Integer instructions.
6 <!-- Power ISA Book I Version 3.0B Section A.3 page 782 -->
8 def Round_Float( tgt_precision, sign, exp, frac, round_mode ):
10 if tgt_precision = 'single-precision' then
14 xbit <- frac[26:63] > 0
15 else # tgt_precision = 'double-precision'
19 xbit <- frac[55:63] > 0
21 if round_mode = 0b00 then # Round to Nearest
22 if (lsb = 1) & (gbit = 1) then inc <- 1
23 if (lsb = 0) & (gbit = 1) & (rbit = 1) then inc <- 1
24 if (lsb = 0) & (gbit = 1) & (xbit = 1) then inc <- 1
25 if round_mode = 0b10 then # Round toward + Infinity
26 if (sign = 0) & (gbit = 1) then inc <-1
27 if (sign = 0) & (rbit = 1) then inc <-1
28 if (sign = 0) & (xbit = 1) then inc <-1
29 if round_mode = 0b11 then # Round toward - Infinity
30 if (sign = 1) & (gbit = 1) then inc <-1
31 if (sign = 1) & (rbit = 1) then inc <-1
32 if (sign = 1) & (xbit = 1) then inc <-1
34 # increase fraction, record the top bit as a 'carry out'
35 if tgt_precision = 'single-precision' then
37 tmp[1:24] <- frac[0:23]
38 tmp[0:24] <- tmp[0:24] + inc
40 frac[0:23] <- tmp[1:24]
41 else # tgt_precision = 'double-precision'
43 tmp[1:53] <- frac[0:52]
44 tmp[0:53] <- tmp[0:53] + inc
46 frac[0:52] <- tmp[1:53]
47 if carry_out = 1 then exp <- exp + 1
50 # FPSCR[FI] <- gbit | rbit | xbit
51 # FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
54 if cvt = 'sint2double' then
55 tgt_precision = 'double-precision'
57 if cvt = 'sint2single' then
58 tgt_precision <- 'single-precision'
60 if cvt = 'uint2double' then
61 tgt_precision <- 'double-precision'
63 if cvt = 'uint2single' then
64 tgt_precision <- 'single-precision'
72 if frac[0:63] = 0 then
77 #FPSCR[FPRF] <- '+ zero'
80 if sign = 1 then frac[0:63] <- ¬frac[0:63] + 1
81 # do the loop 0 times if FR = max negative 64-bit integer or
82 # if FR = max unsigned 64-bit integer
84 frac[0:63] <- frac[1:63] || 0b0
87 RN <- 0b00 # TODO, FPSCR[RN]
88 Round_Float( tgt_precision, sign, exp, frac, RN )
90 #if sign = 0 then FPSCR[FPRF] <- '+normal number'
91 #if sign = 1 then FPSCR[FPRF] <- '-normal number'
93 result[1:11] <- exp + 1023 # exp + bias
94 result[12:63] <- frac[1:52]