Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit fdca37a

Browse files
committed
Create a functor MakeInt (similar to MakeFloat)
This does little right now, but will make it easier when we add more SIMD int ops later (similar to MakeFloat).
1 parent 710f870 commit fdca37a

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

interpreter/exec/eval_numeric.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct
151151
| F32x4ExtractLane imm ->
152152
(F32Op.to_value (SXX.F32x4.extract_lane imm (of_value 1 v)))
153153
| I32x4ExtractLane imm ->
154-
(I32Op.to_value (SXX.i32x4_extract_lane imm (of_value 1 v)))
154+
(I32Op.to_value (SXX.I32x4.extract_lane imm (of_value 1 v)))
155155
end
156156

157157
module V128Op = SimdOp (V128) (Values.V128Value)

interpreter/exec/simd.ml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1516
let f64x2_indices = [0; 8]
1617

1718
module type RepType =
@@ -25,6 +26,7 @@ sig
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
@@ -33,6 +35,15 @@ sig
3335
val of_f64x2 : F64.t list -> t
3436
end
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. *)
3748
module type Float =
3849
sig
@@ -55,10 +66,9 @@ sig
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
6474
end
@@ -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

interpreter/exec/v128.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ include Simd.Make
77
let to_i32x4 s =
88
List.map (fun i -> I32.of_bits (Bytes.get_int32_le (Bytes.of_string s) i)) Simd.f32x4_indices
99

10+
let of_i32x4 fs =
11+
let b = Bytes.create bytewidth in
12+
List.iter2 (fun i f -> Bytes.set_int32_le b i (I32.to_bits f)) Simd.i32x4_indices fs;
13+
Bytes.to_string b
14+
1015
let to_f32x4 s =
1116
List.map (fun i -> F32.of_bits (Bytes.get_int32_le (Bytes.of_string s) i)) Simd.f32x4_indices
1217

0 commit comments

Comments
 (0)