Repository navigation
Expand file tree
/
Copy pathi32_convert.ml
More file actions
93 lines (83 loc) · 2.07 KB
/
Copy pathi32_convert.ml
File metadata and controls
93 lines (83 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(* WebAssembly-compatible type conversions to i32 implementation *)
let wrap_i64 x = Int64.to_int32 x
let trunc_f32_s x =
if F32.ne x x then
raise Ixx.InvalidConversion
else
let xf = F32.to_float x in
if xf >= -.Int32.(to_float min_int) || xf < Int32.(to_float min_int) then
raise Ixx.Overflow
else
Int32.of_float xf
let trunc_f32_u x =
if F32.ne x x then
raise Ixx.InvalidConversion
else
let xf = F32.to_float x in
if xf >= -.Int32.(to_float min_int) *. 2.0 || xf <= -1.0 then
raise Ixx.Overflow
else
Int64.(to_int32 (of_float xf))
let trunc_f64_s x =
if F64.ne x x then
raise Ixx.InvalidConversion
else
let xf = F64.to_float x in
if xf >= -.Int32.(to_float min_int) || xf <= Int32.(to_float min_int) -. 1.0 then
raise Ixx.Overflow
else
Int32.of_float xf
let trunc_f64_u x =
if F64.ne x x then
raise Ixx.InvalidConversion
else
let xf = F64.to_float x in
if xf >= -.Int32.(to_float min_int) *. 2.0 || xf <= -1.0 then
raise Ixx.Overflow
else
Int64.(to_int32 (of_float xf))
let trunc_sat_f32_s x =
if F32.ne x x then
0l
else
let xf = F32.to_float x in
if xf < Int32.(to_float min_int) then
Int32.min_int
else if xf >= -.Int32.(to_float min_int) then
Int32.max_int
else
Int32.of_float xf
let trunc_sat_f32_u x =
if F32.ne x x then
0l
else
let xf = F32.to_float x in
if xf <= -1.0 then
0l
else if xf >= -.Int32.(to_float min_int) *. 2.0 then
-1l
else
Int64.(to_int32 (of_float xf))
let trunc_sat_f64_s x =
if F64.ne x x then
0l
else
let xf = F64.to_float x in
if xf < Int32.(to_float min_int) then
Int32.min_int
else if xf >= -.Int32.(to_float min_int) then
Int32.max_int
else
Int32.of_float xf
let trunc_sat_f64_u x =
if F64.ne x x then
0l
else
let xf = F64.to_float x in
if xf <= -1.0 then
0l
else if xf >= -.Int32.(to_float min_int) *. 2.0 then
-1l
else
Int64.(to_int32 (of_float xf))
let reinterpret_f32 = F32.to_bits