move round_float to separate file
[openpower-isa.git] / openpower / isafunctions / roundfloat.mdwn
1 # A.3 Round to Float conversion
2
3 <!-- Power ISA Book I Version 3.0B Section A.3 page 782 -->
4
5 def Round_Float( tgt_precision, sign, exp, frac, round_mode ):
6 inc <- 0
7 if tgt_precision = "single-precision" then
8 lsb <- frac[23]
9 gbit <- frac[24]
10 rbit <- frac[25]
11 xbit <- frac[26:63] > 0
12 else # tgt_precision = "double-precision"
13 lsb <= frac[52]
14 gbit <= frac[53]
15 rbit <= frac[54]
16 xbit <= frac[55:63] > 0
17
18 if round_mode = 0b00 then # Round to Nearest
19 if lsb = 1 and gbit = 1 then inc <- 1
20 if lsb = 0 and gbit = 1 and rbit = 1 then inc <- 1
21 if lsb = 0 and gbit = 1 and xbit = 1 then inc <- 1
22 end
23 if round_mode = 0b10 then # Round toward + Infinity
24 if sign = 0 and gbit = 1 then inc <-1
25 if sign = 0 and rbit = 1 then inc <-1
26 if sign = 0 and xbit = 1 then inc <-1
27 end
28 if round_mode = 0b11 then # Round toward - Infinity
29 if sign = 1 and gbit = 1 then inc <-1
30 if sign = 1 and rbit = 1 then inc <-1
31 if sign = 1 and xbit = 1 then inc <-1
32 end
33 if tgt_precision = "single-precision" then
34 frac[0:23] <- frac[0:23] + inc
35 else # tgt_precision = "double-precision"
36 frac[0:52] <- frac[0:52] + inc
37 if carry_out = 1 then exp <- exp + 1
38 FPSCR[FR] <- inc
39 FPSCR[FI] <- gbit | rbit | xbit
40 FPSCR[XX] <- FPSCR[XX] | FPSCR[FI]
41