@@ -168,6 +168,22 @@ module Type = struct
168168 ]
169169 })
170170
171+ let float32_type =
172+ register_type " float32" (fun () ->
173+ let * custom_operations = custom_operations_type in
174+ let * custom = custom_type in
175+ return
176+ { supertype = Some custom
177+ ; final = true
178+ ; typ =
179+ W. Struct
180+ [ { mut = false
181+ ; typ = Value (Ref { nullable = false ; typ = Type custom_operations })
182+ }
183+ ; { mut = false ; typ = Value F32 }
184+ ]
185+ })
186+
171187 let int32_type =
172188 register_type " int32" (fun () ->
173189 let * custom_operations = custom_operations_type in
@@ -884,6 +900,24 @@ module Memory = struct
884900 in
885901 if_mismatch
886902
903+ let make_float32 e =
904+ let * custom_operations = Type. custom_operations_type in
905+ let * float32_ops =
906+ register_import
907+ ~name: " float32_ops"
908+ (Global
909+ { mut = false ; typ = Ref { nullable = false ; typ = Type custom_operations } })
910+ in
911+ let * ty = Type. float32_type in
912+ let * e = e in
913+ return (W. StructNew (ty, [ GlobalGet float32_ops; e ]))
914+
915+ let box_float32 = make_float32
916+
917+ let unbox_float32 e =
918+ let * ty = Type. float32_type in
919+ wasm_struct_get ty (wasm_cast ty e) 1
920+
887921 let make_int32 ~kind e =
888922 let * custom_operations = Type. custom_operations_type in
889923 let * int32_ops =
@@ -1043,6 +1077,9 @@ module Constant = struct
10431077 | Float f ->
10441078 let * ty = Type. float_type in
10451079 return (Const , W. StructNew (ty, [ Const (F64 (Int64. float_of_bits f)) ]))
1080+ | Float32 f ->
1081+ let * e = Memory. make_float32 (return (W. Const (F32 (Int64. float_of_bits f)))) in
1082+ return (Const , e)
10461083 | Float_array l ->
10471084 let l = Array. to_list l in
10481085 let * ty = Type. float_array_type in
@@ -1070,6 +1107,8 @@ module Constant = struct
10701107 match c with
10711108 | Code. Int i -> return (W. Const (I32 (Targetint. to_int32 i)))
10721109 | Float f when unboxed -> return (W. Const (F64 (Int64. float_of_bits f)))
1110+ | ((Float32 f ) [@if oxcaml ]) when unboxed ->
1111+ return (W. Const (F32 (Int64. float_of_bits f)))
10731112 | Int64 i when unboxed -> return (W. Const (I64 i))
10741113 | (Int32 i | NativeInt i ) when unboxed -> return (W. Const (I32 i))
10751114 | _ -> (
@@ -1423,6 +1462,7 @@ module Bigarray = struct
14231462 , fun x ->
14241463 let * x = x in
14251464 return (W. F64PromoteF32 x) )
1465+ | Float32_t -> " dv_get_f32" , F32 , 2 , Fun. id
14261466 | Float64 -> " dv_get_f64" , F64 , 3 , Fun. id
14271467 | Int8_signed -> " dv_get_i8" , I32 , 0 , Fun. id
14281468 | Int8_unsigned -> " dv_get_ui8" , I32 , 0 , Fun. id
@@ -1476,6 +1516,7 @@ module Bigarray = struct
14761516 let * ofs = Arith. (i lsl const (Int32. of_int size)) in
14771517 match kind with
14781518 | Float32
1519+ | Float32_t
14791520 | Float64
14801521 | Int8_signed
14811522 | Int8_unsigned
@@ -1508,6 +1549,7 @@ module Bigarray = struct
15081549 , fun x ->
15091550 let * x = x in
15101551 return (W. F32DemoteF64 x) )
1552+ | Float32_t -> " dv_set_f32" , F32 , 2 , Fun. id
15111553 | Float64 -> " dv_set_f64" , F64 , 3 , Fun. id
15121554 | Int8_signed | Int8_unsigned -> " dv_set_i8" , I32 , 0 , Fun. id
15131555 | Int16_signed | Int16_unsigned -> " dv_set_i16" , I32 , 1 , Fun. id
@@ -1560,6 +1602,7 @@ module Bigarray = struct
15601602 in
15611603 match kind with
15621604 | Float32
1605+ | Float32_t
15631606 | Float64
15641607 | Int8_signed
15651608 | Int8_unsigned
0 commit comments