move round_float to separate file
[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 INT2FP(FR, cvt, RN):
9 if cvt = "sint2double" then
10 tgt_precision = "double-precision"
11 sign <- FR[0]
12 if cvt = "sint2single" then
13 tgt_precision <- "single-precision"
14 sign <- FR[0]
15 if cvt = "uint2double" then
16 tgt_precision <- "double-precision"
17 sign <- 0
18 if cvt = "uint2single" then
19 tgt_precision <- "single-precision"
20 sign <- 0
21
22 result = [0] * 64
23 exp <- 63
24 frac[0:63] <- FR
25
26 if frac[0:63] = 0 then
27 # Zero Operand
28 FPSCR[FR] <- 0b00
29 FPSCR[FI] <- 0b00
30 FPSCR[FPRF] <- "+ zero"
31 else
32 if sign = 1 then frac[0:63] <- ¬frac[0:63] + 1
33 # do the loop 0 times if FR = max negative 64-bit integer or
34 # if FR = max unsigned 64-bit integer
35 do while frac[0] = 0
36 frac[0:63] <- frac[1:63] || 0b0
37 exp <- exp - 1
38 Round_Float( tgt_precision, sign, exp, frac0:63, RN )
39 if sign = 0 then FPSCR[FPRF] <- "+normal number"
40 if sign = 1 then FPSCR[FPRF] <- "-normal number"
41 result[0] <- sign
42 result[1:11] <- exp + 1023 # exp + bias
43 result[12:63] <- frac[1:52]
44
45 return result
46