@@ -139,7 +139,7 @@ let nativeint_shiftop (l : constant list) (f : int32 -> int -> int32) : constant
139139 | [ NativeInt i; Int j ] -> Some (NativeInt (f i (Targetint. to_int_exn j)))
140140 | _ -> None
141141
142- let eval_prim x =
142+ let eval_prim ~ target x =
143143 match x with
144144 | Not , [ Int i ] -> bool (Targetint. is_zero i)
145145 | Lt , [ Int i; Int j ] -> bool Targetint. (i < j)
@@ -231,7 +231,13 @@ let eval_prim x =
231231 (* int32 *)
232232 | "caml_int32_bits_of_float" , [ Float f ] ->
233233 int32 (Int32. bits_of_float (Int64. float_of_bits f))
234- | "caml_int32_float_of_bits" , [ Int32 i ] -> Some (float (Int32. float_of_bits i))
234+ | " caml_int32_float_of_bits" , [ Int32 i ]
235+ when match target with
236+ | `JavaScript ->
237+ let f = Int32. float_of_bits i in
238+ (not (Float. is_nan f))
239+ || Int64. equal (Int64. bits_of_float f) (Int64. bits_of_float nan)
240+ | `Wasm -> true -> Some (float (Int32. float_of_bits i))
235241 | "caml_int32_of_float" , [ Float f ] ->
236242 int32 (Int32. of_float (Int64. float_of_bits f))
237243 | "caml_int32_to_float" , [ Int32 i ] -> Some (float (Int32. to_float i))
@@ -258,8 +264,13 @@ let eval_prim x =
258264 (* nativeint *)
259265 | "caml_nativeint_bits_of_float" , [ Float f ] ->
260266 nativeint (Int32. bits_of_float (Int64. float_of_bits f))
261- | "caml_nativeint_float_of_bits" , [ NativeInt i ] ->
262- Some (float (Int32. float_of_bits i))
267+ | " caml_nativeint_float_of_bits" , [ NativeInt i ]
268+ when match target with
269+ | `JavaScript ->
270+ let f = Int32. float_of_bits i in
271+ (not (Float. is_nan f))
272+ || Int64. equal (Int64. bits_of_float f) (Int64. bits_of_float nan)
273+ | `Wasm -> true -> Some (float (Int32. float_of_bits i))
263274 | "caml_nativeint_of_float" , [ Float f ] ->
264275 nativeint (Int32. of_float (Int64. float_of_bits f))
265276 | "caml_nativeint_to_float" , [ NativeInt i ] -> Some (float (Int32. to_float i))
@@ -284,7 +295,12 @@ let eval_prim x =
284295 | "caml_nativeint_of_int" , [ Int i ] -> nativeint (Targetint. to_int32 i)
285296 (* int64 *)
286297 | "caml_int64_bits_of_float" , [ Float f ] -> int64 f
287- | "caml_int64_float_of_bits" , [ Int64 i ] -> Some (Float i)
298+ | " caml_int64_float_of_bits" , [ Int64 i ]
299+ when match target with
300+ | `JavaScript ->
301+ (not (Float. is_nan (Int64. float_of_bits i)))
302+ || Int64. equal i (Int64. bits_of_float nan)
303+ | `Wasm -> true -> Some (Float i)
288304 | "caml_int64_of_float" , [ Float f ] ->
289305 int64 (Int64. of_float (Int64. float_of_bits f))
290306 | "caml_int64_to_float" , [ Int64 i ] -> Some (float (Int64. to_float i))
@@ -632,6 +648,7 @@ let eval_instr update_count inline_constant ~target info i =
632648 | _ -> false )
633649 then
634650 eval_prim
651+ ~target
635652 ( prim
636653 , List. map prim_args' ~f: (function
637654 | Some c -> c
0 commit comments