@@ -11,7 +11,8 @@ let lanes shape =
1111 | F32x4 -> 4
1212 | F64x2 -> 2
1313
14- let f32x4_indices = [0 ; 4 ; 8 ; 12 ]
14+ let i32x4_indices = [0 ; 4 ; 8 ; 12 ]
15+ let f32x4_indices = i32x4_indices
1516let f64x2_indices = [0 ; 8 ]
1617
1718module type RepType =
2526 val of_strings : shape -> string list -> t
2627
2728 val to_i32x4 : t -> I32 .t list
29+ val of_i32x4 : I32 .t list -> t
2830
2931 val to_f32x4 : t -> F32 .t list
3032 val of_f32x4 : F32 .t list -> t
3335 val of_f64x2 : F64 .t list -> t
3436end
3537
38+ (* This signature defines the types and operations SIMD ints can expose. *)
39+ module type Int =
40+ sig
41+ type t
42+ type lane
43+
44+ val extract_lane : int -> t -> lane
45+ end
46+
3647(* This signature defines the types and operations SIMD floats can expose. *)
3748module type Float =
3849sig
5566 val to_bits : t -> bits
5667 val of_strings : shape -> string list -> t
5768
58- val i32x4_extract_lane : int -> t -> I32 .t
59-
6069 (* We need type t = t to ensure that all submodule types are S.t,
6170 * then callers don't have to change *)
71+ module I32x4 : Int with type t = t and type lane = I32. t
6272 module F32x4 : Float with type t = t and type lane = F32. t
6373 module F64x2 : Float with type t = t and type lane = F64. t
6474end
@@ -74,10 +84,6 @@ struct
7484 let to_bits x = x
7585 let of_strings = Rep. of_strings
7686
77- let to_i32x4 = Rep. to_i32x4
78-
79- let i32x4_extract_lane i x = List. nth (to_i32x4 x) i
80-
8187 module MakeFloat (Float : Float.S ) (Convert : sig
8288 val to_shape : Rep .t -> Float .t list
8389 val of_shape : Float .t list -> Rep .t
@@ -93,6 +99,19 @@ struct
9399 let extract_lane i s = List. nth (Convert. to_shape s) i
94100 end
95101
102+ module MakeInt (Int : Int.S ) (Convert : sig
103+ val to_shape : Rep .t -> Int .t list
104+ end ) : Int with type t = Rep. t and type lane = Int. t =
105+ struct
106+ type t = Rep .t
107+ type lane = Int .t
108+ let extract_lane i s = List. nth (Convert. to_shape s) i
109+ end
110+
111+ module I32x4 = MakeInt (I32 ) (struct
112+ let to_shape = Rep. to_i32x4
113+ end )
114+
96115 module F32x4 = MakeFloat (F32 ) (struct
97116 let to_shape = Rep. to_f32x4
98117 let of_shape = Rep. of_f32x4
0 commit comments