1
1
(* TEST
2
- flags = "-extension layouts_beta";
2
+ flags = "-extension layouts_beta -extension small_numbers";
3
+ include beta;
3
4
flambda2;
4
5
{
5
6
native;
11
12
(* ****************************************)
12
13
(* Prelude: Functions on unboxed numbers *)
13
14
15
+ module Float32_u = Beta. Float32_u
14
16
module Float_u = Stdlib__Float_u
15
17
module Int32_u = Stdlib__Int32_u
16
18
module Int64_u = Stdlib__Int64_u
@@ -34,6 +36,9 @@ type t =
34
36
| Mixed6 of float * int32 # * float #
35
37
| Mixed7 of float * int64 # * float # * nativeint #
36
38
| Mixed8 of float * int32 # * float # * int64 # * float #
39
+ | Mixed9 of float * float # * float32 #
40
+ | Mixed10 of float * float32 # * float # * int64 # * float #
41
+ | Mixed11 of float * int32 # * float32 # * float # * int64 # * nativeint #
37
42
| Uniform2 of float * float
38
43
39
44
type t_ext = ..
@@ -47,6 +52,9 @@ type t_ext +=
47
52
| Ext_mixed6 of float * int32 # * float #
48
53
| Ext_mixed7 of float * int64 # * float # * nativeint #
49
54
| Ext_mixed8 of float * int32 # * float # * int64 # * float #
55
+ | Ext_mixed9 of float * float # * float32 #
56
+ | Ext_mixed10 of float * float32 # * float # * int64 # * float #
57
+ | Ext_mixed11 of float * int32 # * float32 # * float # * int64 # * nativeint #
50
58
51
59
let sprintf = Printf. sprintf
52
60
@@ -75,6 +83,17 @@ let to_string = function
75
83
sprintf " Mixed8 (%f, %i, %f, %i, %f)"
76
84
x1 (Int32_u. to_int x2) (Float_u. to_float x3) (Int64_u. to_int x4)
77
85
(Float_u. to_float x5)
86
+ | Mixed9 (x1 , x2 , x3 ) ->
87
+ sprintf " Mixed9 (%f, %f, %f)" x1 (Float_u. to_float x2)
88
+ (Float_u. to_float (Float32_u. to_float x3))
89
+ | Mixed10 (x1 , x2 , x3 , x4 , x5 ) ->
90
+ sprintf " Mixed10 (%f, %f, %f, %i, %f)"
91
+ x1 (Float_u. to_float (Float32_u. to_float x2)) (Float_u. to_float x3)
92
+ (Int64_u. to_int x4) (Float_u. to_float x5)
93
+ | Mixed11 (x1 , x2 , x3 , x4 , x5 , x6 ) ->
94
+ sprintf " Mixed11 (%f, %i, %f, %f, %i, %i)"
95
+ x1 (Int32_u. to_int x2) (Float_u. to_float (Float32_u. to_float x3))
96
+ (Float_u. to_float x4) (Int64_u. to_int x5) (Nativeint_u. to_int x6)
78
97
| Uniform2 (x1 , x2 ) -> sprintf " Uniform2 (%f, %f)" x1 x2
79
98
80
99
let ext_to_string = function
@@ -100,6 +119,17 @@ let ext_to_string = function
100
119
sprintf " Ext_mixed8 (%f, %i, %f, %i, %f)"
101
120
x1 (Int32_u. to_int x2) (Float_u. to_float x3) (Int64_u. to_int x4)
102
121
(Float_u. to_float x5)
122
+ | Ext_mixed9 (x1 , x2 , x3 ) ->
123
+ sprintf " Ext_mixed9 (%f, %f, %f)" x1 (Float_u. to_float x2)
124
+ (Float_u. to_float (Float32_u. to_float x3))
125
+ | Ext_mixed10 (x1 , x2 , x3 , x4 , x5 ) ->
126
+ sprintf " Ext_mixed10 (%f, %f, %f, %i, %f)"
127
+ x1 (Float_u. to_float (Float32_u. to_float x2)) (Float_u. to_float x3)
128
+ (Int64_u. to_int x4) (Float_u. to_float x5)
129
+ | Ext_mixed11 (x1 , x2 , x3 , x4 , x5 , x6 ) ->
130
+ sprintf " Ext_mixed11 (%f, %i, %f, %f, %i, %i)"
131
+ x1 (Int32_u. to_int x2) (Float_u. to_float (Float32_u. to_float x3))
132
+ (Float_u. to_float x4) (Int64_u. to_int x5) (Nativeint_u. to_int x6)
103
133
| _ -> " <ext>"
104
134
105
135
let print t = print_endline (" " ^ to_string t)
@@ -128,12 +158,12 @@ let () = run #17.0
128
158
exercise an optimization code path.
129
159
*)
130
160
131
- let sum uf uf' f f' i i32 i64 i_n =
161
+ let sum uf uf' f f' i i32 i64 i_n f32 =
132
162
Float_u. to_float uf +. Float_u. to_float uf' +. f +. f' +.
133
163
Int32_u. to_float i32 +. Int64_u. to_float i64 +. Nativeint_u. to_float i_n
134
- +. float_of_int i
164
+ +. float_of_int i +. ( Float_u. to_float ( Float32_u. to_float f32))
135
165
136
- let construct_and_destruct uf uf' f f' i i32 i64 i_n =
166
+ let construct_and_destruct uf uf' f f' i i32 i64 i_n f32 =
137
167
let Constant = Constant in
138
168
let Uniform1 f = Uniform1 f in
139
169
let Mixed1 uf = Mixed1 uf in
@@ -144,6 +174,9 @@ let construct_and_destruct uf uf' f f' i i32 i64 i_n =
144
174
let Mixed6 (f, i32, uf) = Mixed6 (f, i32, uf) in
145
175
let Mixed7 (f, i64, uf, i_n) = Mixed7 (f, i64, uf, i_n) in
146
176
let Mixed8 (f, i32, uf, i64, uf') = Mixed8 (f, i32, uf, i64, uf') in
177
+ let Mixed9 (f, uf, f32) = Mixed9 (f, uf, f32) in
178
+ let Mixed10 (f, f32, uf, i64, uf') = Mixed10 (f, f32, uf, i64, uf') in
179
+ let Mixed11 (f, i32, f32, uf, i64, i_n) = Mixed11 (f, i32, f32, uf, i64, i_n) in
147
180
let Ext_mixed1 uf = Ext_mixed1 uf in
148
181
let Ext_mixed2 (f, uf) = Ext_mixed2 (f, uf) in
149
182
let Ext_mixed3 (f, uf, uf') = Ext_mixed3 (f, uf, uf') in
@@ -152,8 +185,11 @@ let construct_and_destruct uf uf' f f' i i32 i64 i_n =
152
185
let Ext_mixed6 (f, i32, uf) = Ext_mixed6 (f, i32, uf) in
153
186
let Ext_mixed7 (f, i64, uf, i_n) = Ext_mixed7 (f, i64, uf, i_n) in
154
187
let Ext_mixed8 (f, i32, uf, i64, uf') = Ext_mixed8 (f, i32, uf, i64, uf') in
188
+ let Ext_mixed9 (f, uf, f32) = Ext_mixed9 (f, uf, f32) in
189
+ let Ext_mixed10 (f, f32, uf, i64, uf') = Ext_mixed10 (f, f32, uf, i64, uf') in
190
+ let Ext_mixed11 (f, i32, f32, uf, i64, i_n) = Ext_mixed11 (f, i32, f32, uf, i64, i_n) in
155
191
let Uniform2 (f, f') = Uniform2 (f, f') in
156
- sum uf uf' f f' i i32 i64 i_n
192
+ sum uf uf' f f' i i32 i64 i_n f32
157
193
[@@ ocaml.warning " -partial-match" ]
158
194
159
195
let () =
@@ -165,10 +201,11 @@ let () =
165
201
and i32 = #12l
166
202
and i64 = #42L
167
203
and i_n = #56n
204
+ and f32 = #1.2 s
168
205
in
169
206
let () =
170
- let sum1 = sum uf uf' f f' i i32 i64 i_n in
171
- let sum2 = construct_and_destruct uf uf' f f' i i32 i64 i_n in
207
+ let sum1 = sum uf uf' f f' i i32 i64 i_n f32 in
208
+ let sum2 = construct_and_destruct uf uf' f f' i i32 i64 i_n f32 in
172
209
Printf. printf
173
210
" Test (construct and destruct): %f = %f (%s)\n "
174
211
sum1
@@ -218,7 +255,7 @@ let _ =
218
255
let go x y z =
219
256
let f =
220
257
match x with
221
- | Mixed5 (f1 , uf1 , i , i32_1 , i_n , i64 ) ->
258
+ | Mixed11 (f1 , i32_1 , f32 , uf1 , i64 , i_n ) ->
222
259
(* Close over the fields we projected out *)
223
260
(fun () ->
224
261
match y, z with
@@ -228,7 +265,6 @@ let go x y z =
228
265
Mixed3 (f2, uf2, uf3) ->
229
266
[ f1;
230
267
Float_u. to_float uf1;
231
- float_of_int i;
232
268
Int32_u. to_float i32_1;
233
269
Nativeint_u. to_float i_n;
234
270
Int64_u. to_float i64;
@@ -238,6 +274,7 @@ let go x y z =
238
274
f3;
239
275
Float_u. to_float uf4;
240
276
Int32_u. to_float i32_2;
277
+ Float32. to_float (Float32_u. to_float32 f32);
241
278
]
242
279
| _ -> assert false
243
280
)
@@ -249,7 +286,6 @@ let test () =
249
286
let f1 = 4.0
250
287
and f2 = 42.0
251
288
and f3 = 36.0
252
- and i = 3
253
289
and i32_1 = #3l
254
290
and i32_2 = - #10l
255
291
and i64 = - #20L
@@ -258,8 +294,9 @@ let test () =
258
294
and uf2 = #32.0
259
295
and uf3 = #47.5
260
296
and uf4 = #47.8
297
+ and f32 = #1.2 s
261
298
in
262
- let x = Mixed5 (f1, uf1, i, i32_1, i_n, i64 ) in
299
+ let x = Mixed11 (f1, i32_1, f32, uf1, i64, i_n ) in
263
300
let y = Mixed3 (f2, uf2, uf3) in
264
301
let z = Mixed4 (f3, uf4, i32_2) in
265
302
(* These results should match as [go] is symmetric in
@@ -292,11 +329,10 @@ let go_recursive x y z =
292
329
let rec f_odd n =
293
330
if n < 7 then f_even (n+ 1 )
294
331
else match x with
295
- | Mixed5 (f1 , uf1 , i , i32_1 , i_n , i64 ) ->
332
+ | Mixed11 (f1 , i32_1 , f32 , uf1 , i64 , i_n ) ->
296
333
[ float_of_int n;
297
334
f1;
298
335
Float_u. to_float uf1;
299
- float_of_int i;
300
336
Int32_u. to_float i32_1;
301
337
Nativeint_u. to_float i_n;
302
338
Int64_u. to_float i64;
@@ -306,6 +342,7 @@ let go_recursive x y z =
306
342
f3;
307
343
Float_u. to_float uf4;
308
344
Int32_u. to_float i32_2;
345
+ Float32. to_float (Float32_u. to_float32 f32);
309
346
]
310
347
| _ -> assert false
311
348
and f_even n = f_odd (n+ 1 ) in
@@ -318,7 +355,6 @@ let test_recursive () =
318
355
let f1 = 4.0
319
356
and f2 = 42.0
320
357
and f3 = 36.0
321
- and i = 3
322
358
and i32_1 = #3l
323
359
and i32_2 = - #10l
324
360
and i64 = - #20L
@@ -327,8 +363,9 @@ let test_recursive () =
327
363
and uf2 = #32.0
328
364
and uf3 = #47.5
329
365
and uf4 = #47.8
366
+ and f32 = #1.2 s
330
367
in
331
- let x = Mixed5 (f1, uf1, i, i32_1, i_n, i64 ) in
368
+ let x = Mixed11 (f1, i32_1, f32, uf1, i64, i_n ) in
332
369
let y = Mixed3 (f2, uf2, uf3) in
333
370
let z = Mixed4 (f3, uf4, i32_2) in
334
371
(* These results should match as [go_recursive] is symmetric in
0 commit comments