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 and gbit = 1 then inc <- 1
23 if lsb = 0 and gbit = 1 and rbit = 1 then inc <- 1
24 if lsb = 0 and gbit = 1 and xbit = 1 then inc <- 1
26 if round_mode = 0b10 then # Round toward + Infinity
27 if sign = 0 and gbit = 1 then inc <-1
28 if sign = 0 and rbit = 1 then inc <-1
29 if sign = 0 and xbit = 1 then inc <-1
31 if round_mode = 0b11 then # Round toward - Infinity
32 if sign = 1 and gbit = 1 then inc <-1
33 if sign = 1 and rbit = 1 then inc <-1
34 if sign = 1 and xbit = 1 then inc <-1
36 # increase fraction, record the top bit as a "carry out"
37 if tgt_precision = "single-precision" then
39 tmp[1:24] = frac[0:23]
40 tmp[0:24] <- tmp[0:24] + inc
42 frac[0:23] = tmp[1:24]
43 else # tgt_precision = "double-precision"
45 tmp[1:53] = frac[0:52]
46 tmp[0:53] <- tmp[0:53] + inc
48 frac[0:52] = tmp[1:54]
49 if carry_out = 1 then exp <- exp + 1
52 # FPSCR[FI] <- gbit | rbit | xbit
53 # FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
55 def INT2FP(FR, cvt, RN):
56 if cvt = "sint2double" then
57 tgt_precision = "double-precision"
59 if cvt = "sint2single" then
60 tgt_precision <- "single-precision"
62 if cvt = "uint2double" then
63 tgt_precision <- "double-precision"
65 if cvt = "uint2single" then
66 tgt_precision <- "single-precision"
73 if frac[0:63] = 0 then
78 #FPSCR[FPRF] <- "+ zero"
81 if sign = 1 then frac[0:63] <- ¬frac[0:63] + 1
82 # do the loop 0 times if FR = max negative 64-bit integer or
83 # if FR = max unsigned 64-bit integer
85 frac[0:63] <- frac[1:63] || 0b0
88 Round_Float( tgt_precision, sign, exp, frac, 0b00 )
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]