Skip to content

Commit 4ebaa5a

Browse files
committed
Add a couple tests
1 parent 6c55489 commit 4ebaa5a

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

ocaml/testsuite/tests/typing-layouts-float64/unboxed_floats_alpha.ml

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,72 @@ let[@inline never] f3 n m steps () =
134134
in
135135
go 0
136136

137+
(* many args - even args are tuples, odd args are unboxed floats *)
138+
let[@inline_never] f3_manyargs x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 steps () =
139+
let (start_k, end_k) = x0 in
140+
let[@inline never] rec go k =
141+
if k = end_k
142+
then Float_u.of_float 0.
143+
else begin
144+
let (x2_1, x2_2) = x2 in
145+
let (x4_1, x4_2) = x4 in
146+
let (x6_1, x6_2) = x6 in
147+
let (x8_1, x8_2) = x8 in
148+
let sum = x2_1 + x2_2 + x4_1 + x4_2 + x6_1 + x6_2 + x8_1 + x8_2 in
149+
let acc = go (k + 1) in
150+
steps.(k) <- Float_u.to_float acc;
151+
Float_u.(acc + ((x1 + x3 + x5 + x7 + x9) * (of_float (Float.of_int sum))))
152+
end
153+
in
154+
go start_k
155+
137156
let test3 () =
157+
(* Test f3 *)
138158
let steps = Array.init 10 (fun _ -> 0.0) in
139159
let five_pi = f3 5 (Float_u.of_float 3.14) steps in
140160
print_floatu "Test 3, 5 * pi: " (five_pi ());
161+
Array.iteri (Printf.printf " Test 3, step %d: %.2f\n") steps;
162+
163+
(* Test f3_manyargs
164+
165+
(3.14 + 2.72 + 1.62 + 1.41 + 42.0) = 50.86
166+
3 * (3.14 + 2.72 + 1.62 + 1.41 + 42.0) = 152.58
167+
6 * (3.14 + 2.72 + 1.62 + 1.41 + 42.0) = 306.16
168+
9 * (3.14 + 2.72 + 1.62 + 1.41 + 42.0) = 457.74
169+
170+
( but we expect some floating point error )
171+
*)
172+
let steps = Array.init 10 (fun _ -> 0.0) in
173+
let x1 = Float_u.of_float 3.14 in
174+
let x3 = Float_u.of_float 2.72 in
175+
let x5 = Float_u.of_float 1.62 in
176+
let x7 = Float_u.of_float 1.41 in
177+
let x9 = Float_u.of_float 42.0 in
178+
179+
(* these sum to 3 *)
180+
let x2 = (7, 42) in
181+
let x4 = (-23, 109) in
182+
let x6 = (-242, 90) in
183+
let x8 = (-2, 22) in
184+
185+
let f3_manyargs = f3_manyargs (4,8) x1 x2 x3 x4 x5 x6 x7 x8 x9 steps in
186+
print_floatu "Test 3, 610.68: " (f3_manyargs ());
141187
Array.iteri (Printf.printf " Test 3, step %d: %.2f\n") steps
142188

143189
let _ = test3 ()
144190

145-
(******************************************)
146-
(* Test 4: Partial, indirect applications *)
191+
(*********************************************)
192+
(* Test 4: Partial and indirect applications *)
147193

148194
let[@inline never] test4 () =
195+
(* Simple indirect call *)
196+
let[@inline never] go f =
197+
Float_u.to_float (f (Float_u.of_float 1.) (Float_u.of_float 2.))
198+
in
199+
let (x1, x2) = (go Float_u.(+), go Float_u.(-)) in
200+
print_floatu "Test 4, 1 + 2" (Float_u.of_float x1);
201+
print_floatu "Test 4, 1 - 2" (Float_u.of_float x2);
202+
149203
(* partial application to float# *)
150204
let steps = Array.init 10 (fun _ -> 0.0) in
151205
let f = Sys.opaque_identity (f3 5 (Float_u.of_float 3.14)) in
@@ -154,6 +208,22 @@ let[@inline never] test4 () =
154208
Array.iteri (Printf.printf " Test 4, step %d: %.2f\n") steps;
155209

156210
(* partial application with float# remaining *)
211+
let steps = Array.init 10 (fun _ -> 0.0) in
212+
let f = Sys.opaque_identity (f3 6) in
213+
let five_pi = f (Float_u.of_float 3.14) steps in
214+
print_floatu "Test 4, 6 * pi: " (five_pi ());
215+
Array.iteri (Printf.printf " Test 4, step %d: %.2f\n") steps;
216+
217+
(* Those two tests again, but making f3 also opaque to prevent expansion of
218+
the partial application. *)
219+
let f3 = Sys.opaque_identity f3 in
220+
221+
let steps = Array.init 10 (fun _ -> 0.0) in
222+
let f = Sys.opaque_identity (f3 5 (Float_u.of_float 3.14)) in
223+
let five_pi = f steps in
224+
print_floatu "Test 4, 5 * pi: " (five_pi ());
225+
Array.iteri (Printf.printf " Test 4, step %d: %.2f\n") steps;
226+
157227
let steps = Array.init 10 (fun _ -> 0.0) in
158228
let f = Sys.opaque_identity (f3 6) in
159229
let five_pi = f (Float_u.of_float 3.14) steps in

ocaml/testsuite/tests/typing-layouts-float64/unboxed_floats_alpha.reference

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ Test 3, 5 * pi: : 15.70
2525
Test 3, step 7: 0.00
2626
Test 3, step 8: 0.00
2727
Test 3, step 9: 0.00
28+
Test 3, 610.68: : 610.68
29+
Test 3, step 0: 0.00
30+
Test 3, step 1: 0.00
31+
Test 3, step 2: 0.00
32+
Test 3, step 3: 0.00
33+
Test 3, step 4: 458.01
34+
Test 3, step 5: 305.34
35+
Test 3, step 6: 152.67
36+
Test 3, step 7: 0.00
37+
Test 3, step 8: 0.00
38+
Test 3, step 9: 0.00
39+
Test 4, 1 + 2: 3.00
40+
Test 4, 1 - 2: -1.00
41+
Test 4, 5 * pi: : 15.70
42+
Test 4, step 0: 12.56
43+
Test 4, step 1: 9.42
44+
Test 4, step 2: 6.28
45+
Test 4, step 3: 3.14
46+
Test 4, step 4: 0.00
47+
Test 4, step 5: 0.00
48+
Test 4, step 6: 0.00
49+
Test 4, step 7: 0.00
50+
Test 4, step 8: 0.00
51+
Test 4, step 9: 0.00
52+
Test 4, 6 * pi: : 18.84
53+
Test 4, step 0: 15.70
54+
Test 4, step 1: 12.56
55+
Test 4, step 2: 9.42
56+
Test 4, step 3: 6.28
57+
Test 4, step 4: 3.14
58+
Test 4, step 5: 0.00
59+
Test 4, step 6: 0.00
60+
Test 4, step 7: 0.00
61+
Test 4, step 8: 0.00
62+
Test 4, step 9: 0.00
2863
Test 4, 5 * pi: : 15.70
2964
Test 4, step 0: 12.56
3065
Test 4, step 1: 9.42

0 commit comments

Comments
 (0)