add fpcvt.mdwn pseudocode which calls new auto-generated function
[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) & (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
33
34 # increase fraction, record the top bit as a 'carry out'
35 if tgt_precision = 'single-precision' then
36 tmp <- [0]*25
37 tmp[1:24] <- frac[0:23]
38 tmp[0:24] <- tmp[0:24] + inc
39 carry_out <- tmp[24]
40 frac[0:23] <- tmp[1:24]
41 else # tgt_precision = 'double-precision'
42 tmp <- [0]*54
43 tmp[1:53] <- frac[0:52]
44 tmp[0:53] <- tmp[0:53] + inc
45 carry_out <- tmp[53]
46 frac[0:52] <- tmp[1:54]
47 if carry_out = 1 then exp <- exp + 1
48 # TODO, later
49 # FPSCR[FR] <- inc
50 # FPSCR[FI] <- gbit | rbit | xbit
51 # FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
52
53 def INT2FP(FR, cvt):
54 if cvt = 'sint2double' then
55 tgt_precision = 'double-precision'
56 sign <- FR[0]
57 if cvt = 'sint2single' then
58 tgt_precision <- 'single-precision'
59 sign <- FR[0]
60 if cvt = 'uint2double' then
61 tgt_precision <- 'double-precision'
62 sign <- 0
63 if cvt = 'uint2single' then
64 tgt_precision <- 'single-precision'
65 sign <- 0
66
67 frac <- [0] * 64
68 result <- [0] * 64
69 exp <- 63
70 frac <- FR[0:63]
71
72 if frac[0:63] = 0 then
73 # Zero Operand
74 # TODO, FPSCR
75 #FPSCR[FR] <- 0b00
76 #FPSCR[FI] <- 0b00
77 #FPSCR[FPRF] <- '+ zero'
78 result <- [0] * 64
79 else
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
83 do while frac[0] = 0
84 frac[0:63] <- frac[1:63] || 0b0
85 exp <- exp - 1
86 # round to nearest
87 Round_Float( tgt_precision, sign, exp, frac, 0b00 )
88 # TODO, FPSCR
89 #if sign = 0 then FPSCR[FPRF] <- '+normal number'
90 #if sign = 1 then FPSCR[FPRF] <- '-normal number'
91 result[0] <- sign
92 result[1:11] <- exp + 1023 # exp + bias
93 result[12:63] <- frac[1:52]
94
95 return result
96