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 if tgt_precision = "single-precision" then
37 frac[0:23] <- frac[0:23] + inc
38 else # tgt_precision = "double-precision"
39 frac[0:52] <- frac[0:52] + inc
40 if carry_out = 1 then exp <- exp + 1
42 FPSCR[FI] <- gbit | rbit | xbit
43 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
45 def INT2FP(FR, cvt, RN):
46 if cvt = "sint2double" then
47 tgt_precision = "double-precision"
49 if cvt = "sint2single" then
50 tgt_precision <- "single-precision"
52 if cvt = "uint2double" then
53 tgt_precision <- "double-precision"
55 if cvt = "uint2single" then
56 tgt_precision <- "single-precision"
63 if frac[0:63] = 0 then
67 FPSCR[FPRF] <- "+ zero"
69 if sign = 1 then frac[0:63] <- ¬frac[0:63] + 1
70 # do the loop 0 times if FR = max negative 64-bit integer or
71 # if FR = max unsigned 64-bit integer
73 frac[0:63] <- frac[1:63] || 0b0
75 Round_Float( tgt_precision, sign, exp, frac0:63, RN )
76 if sign = 0 then FPSCR[FPRF] <- "+normal number"
77 if sign = 1 then FPSCR[FPRF] <- "-normal number"
79 result[1:11] <- exp + 1023 # exp + bias
80 result[12:63] <- frac[1:52]