Skip to content

Commit 84bcdfe

Browse files
authored
flambda-backend: Consistently use type t in unboxed libs (#2562)
* type t * promote test output
1 parent bb0dabd commit 84bcdfe

File tree

19 files changed

+451
-484
lines changed

19 files changed

+451
-484
lines changed

otherlibs/beta/float32.ml

Lines changed: 70 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -18,99 +18,86 @@
1818

1919
type t = float32
2020

21-
external float32_of_bits : int32 -> float32
21+
external float32_of_bits : int32 -> t
2222
= "caml_float32_of_bits_bytecode" "caml_float32_of_bits"
2323
[@@unboxed] [@@noalloc]
2424

25-
external neg : (float32[@local_opt]) -> (float32[@local_opt]) = "%negfloat32"
25+
external neg : (t[@local_opt]) -> (t[@local_opt]) = "%negfloat32"
2626

27-
external add :
28-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
27+
external add : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
2928
= "%addfloat32"
3029

31-
external sub :
32-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
30+
external sub : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
3331
= "%subfloat32"
3432

35-
external mul :
36-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
33+
external mul : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
3734
= "%mulfloat32"
3835

39-
external div :
40-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
36+
external div : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
4137
= "%divfloat32"
4238

43-
external pow : float32 -> float32 -> float32
44-
= "caml_power_float32_bytecode" "powf"
39+
external pow : t -> t -> t = "caml_power_float32_bytecode" "powf"
4540
[@@unboxed] [@@noalloc]
4641

4742
module Operators = struct
48-
external ( ~-. ) : (float32[@local_opt]) -> (float32[@local_opt])
49-
= "%negfloat32"
43+
external ( ~-. ) : (t[@local_opt]) -> (t[@local_opt]) = "%negfloat32"
5044

51-
external ( +. ) :
52-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
45+
external ( +. ) : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
5346
= "%addfloat32"
5447

55-
external ( -. ) :
56-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
48+
external ( -. ) : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
5749
= "%subfloat32"
5850

59-
external ( *. ) :
60-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
51+
external ( *. ) : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
6152
= "%mulfloat32"
6253

63-
external ( /. ) :
64-
(float32[@local_opt]) -> (float32[@local_opt]) -> (float32[@local_opt])
54+
external ( /. ) : (t[@local_opt]) -> (t[@local_opt]) -> (t[@local_opt])
6555
= "%divfloat32"
6656

67-
external ( ** ) : float32 -> float32 -> float32
68-
= "caml_power_float32_bytecode" "powf"
57+
external ( ** ) : t -> t -> t = "caml_power_float32_bytecode" "powf"
6958
[@@unboxed] [@@noalloc]
7059
end
7160

72-
external fma : float32 -> float32 -> float32 -> float32
73-
= "caml_fma_float32_bytecode" "fmaf"
61+
external fma : t -> t -> t -> t = "caml_fma_float32_bytecode" "fmaf"
7462
[@@unboxed] [@@noalloc]
7563

76-
external rem : float32 -> float32 -> float32
77-
= "caml_fmod_float32_bytecode" "fmodf"
64+
external rem : t -> t -> t = "caml_fmod_float32_bytecode" "fmodf"
7865
[@@unboxed] [@@noalloc]
7966

80-
external abs : (float32[@local_opt]) -> (float32[@local_opt]) = "%absfloat32"
67+
external abs : (t[@local_opt]) -> (t[@local_opt]) = "%absfloat32"
8168

8269
let zero = 0.s
8370
let one = 1.s
8471
let minus_one = -1.s
8572
let infinity = float32_of_bits 0x7f800000l
8673
let neg_infinity = float32_of_bits 0xff800000l
8774
let nan = float32_of_bits 0x7f800001l
88-
let is_finite (x : float32) = sub x x = 0.s
89-
let is_infinite (x : float32) = div 1.s x = 0.s
90-
let is_nan (x : float32) = x <> x
75+
let is_finite (x : t) = sub x x = 0.s
76+
let is_infinite (x : t) = div 1.s x = 0.s
77+
let is_nan (x : t) = x <> x
9178
let pi = 0x1.921fb6p+1s
9279
let max_float = float32_of_bits 0x7f7fffffl
9380
let min_float = float32_of_bits 0x00800000l
9481
let epsilon = float32_of_bits 0x34000000l
9582

96-
external of_int : int -> float32 = "%float32ofint"
97-
external to_int : (float32[@local_opt]) -> int = "%intoffloat32"
98-
external of_float : (float[@local_opt]) -> float32 = "%float32offloat"
99-
external to_float : (float32[@local_opt]) -> float = "%floatoffloat32"
83+
external of_int : int -> t = "%float32ofint"
84+
external to_int : (t[@local_opt]) -> int = "%intoffloat32"
85+
external of_float : (float[@local_opt]) -> t = "%float32offloat"
86+
external to_float : (t[@local_opt]) -> float = "%floatoffloat32"
10087

101-
external of_bits : (int32[@local_opt]) -> float32
88+
external of_bits : (int32[@local_opt]) -> t
10289
= "caml_float32_of_bits_bytecode" "caml_float32_of_bits"
10390
[@@unboxed] [@@noalloc] [@@builtin]
10491

105-
external to_bits : (float32[@local_opt]) -> int32
92+
external to_bits : (t[@local_opt]) -> int32
10693
= "caml_float32_to_bits_bytecode" "caml_float32_to_bits"
10794
[@@unboxed] [@@noalloc] [@@builtin]
10895

109-
external of_string : string -> float32 = "caml_float32_of_string"
96+
external of_string : string -> t = "caml_float32_of_string"
11097

11198
let of_string_opt s = try Some (of_string s) with Failure _ -> None
11299

113-
external format : string -> float32 -> string = "caml_format_float32"
100+
external format : string -> t -> string = "caml_format_float32"
114101

115102
let to_string f = Stdlib.valid_float_lexem (format "%.9g" f)
116103

@@ -121,153 +108,150 @@ type fpclass = Stdlib.fpclass =
121108
| FP_infinite
122109
| FP_nan
123110

124-
external classify_float : (float32[@unboxed]) -> fpclass
111+
external classify_float : (t[@unboxed]) -> fpclass
125112
= "caml_classify_float32_bytecode" "caml_classify_float32"
126113
[@@noalloc]
127114

128-
external sqrt : float32 -> float32 = "caml_sqrt_float32_bytecode" "sqrtf"
115+
external sqrt : t -> t = "caml_sqrt_float32_bytecode" "sqrtf"
129116
[@@unboxed] [@@noalloc] [@@builtin]
130117

131-
external cbrt : float32 -> float32 = "caml_cbrt_float32_bytecode" "cbrtf"
118+
external cbrt : t -> t = "caml_cbrt_float32_bytecode" "cbrtf"
132119
[@@unboxed] [@@noalloc]
133120

134-
external exp : float32 -> float32 = "caml_exp_float32_bytecode" "expf"
121+
external exp : t -> t = "caml_exp_float32_bytecode" "expf"
135122
[@@unboxed] [@@noalloc]
136123

137-
external exp2 : float32 -> float32 = "caml_exp2_float32_bytecode" "exp2f"
124+
external exp2 : t -> t = "caml_exp2_float32_bytecode" "exp2f"
138125
[@@unboxed] [@@noalloc]
139126

140-
external log : float32 -> float32 = "caml_log_float32_bytecode" "logf"
127+
external log : t -> t = "caml_log_float32_bytecode" "logf"
141128
[@@unboxed] [@@noalloc]
142129

143-
external log10 : float32 -> float32 = "caml_log10_float32_bytecode" "log10f"
130+
external log10 : t -> t = "caml_log10_float32_bytecode" "log10f"
144131
[@@unboxed] [@@noalloc]
145132

146-
external log2 : float32 -> float32 = "caml_log2_float32_bytecode" "log2f"
133+
external log2 : t -> t = "caml_log2_float32_bytecode" "log2f"
147134
[@@unboxed] [@@noalloc]
148135

149-
external expm1 : float32 -> float32 = "caml_expm1_float32_bytecode" "expm1f"
136+
external expm1 : t -> t = "caml_expm1_float32_bytecode" "expm1f"
150137
[@@unboxed] [@@noalloc]
151138

152-
external log1p : float32 -> float32 = "caml_log1p_float32_bytecode" "log1pf"
139+
external log1p : t -> t = "caml_log1p_float32_bytecode" "log1pf"
153140
[@@unboxed] [@@noalloc]
154141

155-
external cos : float32 -> float32 = "caml_cos_float32_bytecode" "cosf"
142+
external cos : t -> t = "caml_cos_float32_bytecode" "cosf"
156143
[@@unboxed] [@@noalloc]
157144

158-
external sin : float32 -> float32 = "caml_sin_float32_bytecode" "sinf"
145+
external sin : t -> t = "caml_sin_float32_bytecode" "sinf"
159146
[@@unboxed] [@@noalloc]
160147

161-
external tan : float32 -> float32 = "caml_tan_float32_bytecode" "tanf"
148+
external tan : t -> t = "caml_tan_float32_bytecode" "tanf"
162149
[@@unboxed] [@@noalloc]
163150

164-
external acos : float32 -> float32 = "caml_acos_float32_bytecode" "acosf"
151+
external acos : t -> t = "caml_acos_float32_bytecode" "acosf"
165152
[@@unboxed] [@@noalloc]
166153

167-
external asin : float32 -> float32 = "caml_asin_float32_bytecode" "asinf"
154+
external asin : t -> t = "caml_asin_float32_bytecode" "asinf"
168155
[@@unboxed] [@@noalloc]
169156

170-
external atan : float32 -> float32 = "caml_atan_float32_bytecode" "atanf"
157+
external atan : t -> t = "caml_atan_float32_bytecode" "atanf"
171158
[@@unboxed] [@@noalloc]
172159

173-
external atan2 : float32 -> float32 -> float32
174-
= "caml_atan2_float32_bytecode" "atan2f"
160+
external atan2 : t -> t -> t = "caml_atan2_float32_bytecode" "atan2f"
175161
[@@unboxed] [@@noalloc]
176162

177-
external hypot : float32 -> float32 -> float32
178-
= "caml_hypot_float32_bytecode" "hypotf"
163+
external hypot : t -> t -> t = "caml_hypot_float32_bytecode" "hypotf"
179164
[@@unboxed] [@@noalloc]
180165

181-
external cosh : float32 -> float32 = "caml_cosh_float32_bytecode" "coshf"
166+
external cosh : t -> t = "caml_cosh_float32_bytecode" "coshf"
182167
[@@unboxed] [@@noalloc]
183168

184-
external sinh : float32 -> float32 = "caml_sinh_float32_bytecode" "sinhf"
169+
external sinh : t -> t = "caml_sinh_float32_bytecode" "sinhf"
185170
[@@unboxed] [@@noalloc]
186171

187-
external tanh : float32 -> float32 = "caml_tanh_float32_bytecode" "tanhf"
172+
external tanh : t -> t = "caml_tanh_float32_bytecode" "tanhf"
188173
[@@unboxed] [@@noalloc]
189174

190-
external acosh : float32 -> float32 = "caml_acosh_float32_bytecode" "acoshf"
175+
external acosh : t -> t = "caml_acosh_float32_bytecode" "acoshf"
191176
[@@unboxed] [@@noalloc]
192177

193-
external asinh : float32 -> float32 = "caml_asinh_float32_bytecode" "asinhf"
178+
external asinh : t -> t = "caml_asinh_float32_bytecode" "asinhf"
194179
[@@unboxed] [@@noalloc]
195180

196-
external atanh : float32 -> float32 = "caml_atanh_float32_bytecode" "atanhf"
181+
external atanh : t -> t = "caml_atanh_float32_bytecode" "atanhf"
197182
[@@unboxed] [@@noalloc]
198183

199-
external erf : float32 -> float32 = "caml_erf_float32_bytecode" "erff"
184+
external erf : t -> t = "caml_erf_float32_bytecode" "erff"
200185
[@@unboxed] [@@noalloc]
201186

202-
external erfc : float32 -> float32 = "caml_erfc_float32_bytecode" "erfcf"
187+
external erfc : t -> t = "caml_erfc_float32_bytecode" "erfcf"
203188
[@@unboxed] [@@noalloc]
204189

205-
external trunc : float32 -> float32 = "caml_trunc_float32_bytecode" "truncf"
190+
external trunc : t -> t = "caml_trunc_float32_bytecode" "truncf"
206191
[@@unboxed] [@@noalloc]
207192

208-
external round : float32 -> float32 = "caml_round_float32_bytecode" "roundf"
193+
external round : t -> t = "caml_round_float32_bytecode" "roundf"
209194
[@@unboxed] [@@noalloc]
210195

211-
external ceil : float32 -> float32 = "caml_ceil_float32_bytecode" "ceilf"
196+
external ceil : t -> t = "caml_ceil_float32_bytecode" "ceilf"
212197
[@@unboxed] [@@noalloc]
213198

214-
external floor : float32 -> float32 = "caml_floor_float32_bytecode" "floorf"
199+
external floor : t -> t = "caml_floor_float32_bytecode" "floorf"
215200
[@@unboxed] [@@noalloc]
216201

217202
let is_integer x = x = trunc x && is_finite x
218203

219-
external next_after : float32 -> float32 -> float32
204+
external next_after : t -> t -> t
220205
= "caml_nextafter_float32_bytecode" "nextafterf"
221206
[@@unboxed] [@@noalloc]
222207

223208
let succ x = next_after x infinity
224209
let pred x = next_after x neg_infinity
225210

226-
external copy_sign : float32 -> float32 -> float32
227-
= "caml_copysign_float32_bytecode" "copysignf"
211+
external copy_sign : t -> t -> t = "caml_copysign_float32_bytecode" "copysignf"
228212
[@@unboxed] [@@noalloc]
229213

230-
external sign_bit : (float32[@unboxed]) -> bool
214+
external sign_bit : (t[@unboxed]) -> bool
231215
= "caml_signbit_float32_bytecode" "caml_signbit_float32"
232216
[@@noalloc]
233217

234-
external frexp : float32 -> float32 * int = "caml_frexp_float32"
218+
external frexp : t -> t * int = "caml_frexp_float32"
235219

236-
external ldexp : (float32[@unboxed]) -> (int[@untagged]) -> (float32[@unboxed])
220+
external ldexp : (t[@unboxed]) -> (int[@untagged]) -> (t[@unboxed])
237221
= "caml_ldexp_float32_bytecode" "caml_ldexp_float32"
238222
[@@noalloc]
239223

240-
external modf : float32 -> float32 * float32 = "caml_modf_float32"
241-
external compare : float32 -> float32 -> int = "%compare"
224+
external modf : t -> t * t = "caml_modf_float32"
225+
external compare : t -> t -> int = "%compare"
242226

243227
let equal x y = compare x y = 0
244228

245-
let[@inline] min (x : float32) (y : float32) =
229+
let[@inline] min (x : t) (y : t) =
246230
if y > x || ((not (sign_bit y)) && sign_bit x) then if is_nan y then y else x
247231
else if is_nan x then x
248232
else y
249233

250-
let[@inline] max (x : float32) (y : float32) =
234+
let[@inline] max (x : t) (y : t) =
251235
if y > x || ((not (sign_bit y)) && sign_bit x) then if is_nan x then x else y
252236
else if is_nan y then y
253237
else x
254238

255-
let[@inline] min_max (x : float32) (y : float32) =
239+
let[@inline] min_max (x : t) (y : t) =
256240
if is_nan x || is_nan y then (nan, nan)
257241
else if y > x || ((not (sign_bit y)) && sign_bit x) then (x, y)
258242
else (y, x)
259243

260-
let[@inline] min_num (x : float32) (y : float32) =
244+
let[@inline] min_num (x : t) (y : t) =
261245
if y > x || ((not (sign_bit y)) && sign_bit x) then if is_nan x then y else x
262246
else if is_nan y then x
263247
else y
264248

265-
let[@inline] max_num (x : float32) (y : float32) =
249+
let[@inline] max_num (x : t) (y : t) =
266250
if y > x || ((not (sign_bit y)) && sign_bit x) then if is_nan y then x else y
267251
else if is_nan x then y
268252
else x
269253

270-
let[@inline] min_max_num (x : float32) (y : float32) =
254+
let[@inline] min_max_num (x : t) (y : t) =
271255
if is_nan x then (y, y)
272256
else if is_nan y then (x, x)
273257
else if y > x || ((not (sign_bit y)) && sign_bit x) then (x, y)

0 commit comments

Comments
 (0)