3ed1bed33fabbfc9334fed8d97b2e1b7f1182b2d
[openpower-isa.git] / openpower / isafunctions / fpfromint.mdwn
1 # A.3 FLoating-Point Convert from Integer Model
2
3 The following describes algorithmically the operation of the Floating
4 Convert From Integer instructions.
5
6 <!-- Power ISA Book I Version 3.0B Section A.3 page 782 -->
7
8 def Round_Float( tgt_precision, sign, exp, frac, round_mode ):
9 inc <- 0
10 if tgt_precision = "single-precision" then
11 lsb <- frac[23]
12 gbit <- frac[24]
13 rbit <- frac[25]
14 xbit <- frac[26:63] > 0
15 else # tgt_precision = "double-precision"
16 lsb <= frac[52]
17 gbit <= frac[53]
18 rbit <= frac[54]
19 xbit <= frac[55:63] > 0
20
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
25 end
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
30 end
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
35 end
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
41 FPSCR[FR] <- inc
42 FPSCR[FI] <- gbit | rbit | xbit
43 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
44
45 def INT2FP(FR, cvt, RN):
46 if cvt = "sint2double" then
47 tgt_precision = "double-precision"
48 sign <- FR[0]
49 if cvt = "sint2single" then
50 tgt_precision <- "single-precision"
51 sign <- FR[0]
52 if cvt = "uint2double" then
53 tgt_precision <- "double-precision"
54 sign <- 0
55 if cvt = "uint2single" then
56 tgt_precision <- "single-precision"
57 sign <- 0
58
59 result = [0] * 64
60 exp <- 63
61 frac[0:63] <- FR
62
63 if frac[0:63] = 0 then
64 # Zero Operand
65 FPSCR[FR] <- 0b00
66 FPSCR[FI] <- 0b00
67 FPSCR[FPRF] <- "+ zero"
68 else
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
72 do while frac[0] = 0
73 frac[0:63] <- frac[1:63] || 0b0
74 exp <- exp - 1
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"
78 result[0] <- sign
79 result[1:11] <- exp + 1023 # exp + bias
80 result[12:63] <- frac[1:52]
81
82 return result
83