Skip to content

Commit 7ac7d92

Browse files
authored
Support I64x2 (WebAssembly#266)
Add i64x2.{neg,add,sub,mul}, now simd/simd_i64x2_arith.wast passes.
1 parent 225a9b2 commit 7ac7d92

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed

interpreter/exec/eval_numeric.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct
134134
| I16x8 Abs -> to_value (SXX.I16x8.abs (of_value 1 v))
135135
| I32x4 Abs -> to_value (SXX.I32x4.abs (of_value 1 v))
136136
| I32x4 Neg -> to_value (SXX.I32x4.neg (of_value 1 v))
137+
| I64x2 Neg -> to_value (SXX.I64x2.neg (of_value 1 v))
137138
| F32x4 Abs -> to_value (SXX.F32x4.abs (of_value 1 v))
138139
| F32x4 Neg -> to_value (SXX.F32x4.neg (of_value 1 v))
139140
| F32x4 Sqrt -> to_value (SXX.F32x4.sqrt (of_value 1 v))
@@ -166,6 +167,9 @@ struct
166167
| I32x4 MaxS -> SXX.I32x4.max_s
167168
| I32x4 MaxU -> SXX.I32x4.max_u
168169
| I32x4 Mul -> SXX.I32x4.mul
170+
| I64x2 Add -> SXX.I64x2.add
171+
| I64x2 Sub -> SXX.I64x2.sub
172+
| I64x2 Mul -> SXX.I64x2.mul
169173
| F32x4 Add -> SXX.F32x4.add
170174
| F32x4 Sub -> SXX.F32x4.sub
171175
| F32x4 Mul -> SXX.F32x4.mul

interpreter/exec/simd.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ sig
3030
val to_i32x4 : t -> I32.t list
3131
val of_i32x4 : I32.t list -> t
3232

33+
val to_i64x2 : t -> I64.t list
34+
val of_i64x2 : I64.t list -> t
35+
3336
val to_f32x4 : t -> F32.t list
3437
val of_f32x4 : F32.t list -> t
3538

@@ -91,6 +94,7 @@ sig
9194
module I8x16 : Int with type t = t and type lane = I8.t
9295
module I16x8 : Int with type t = t and type lane = I16.t
9396
module I32x4 : Int with type t = t and type lane = I32.t
97+
module I64x2 : Int with type t = t and type lane = I64.t
9498
module F32x4 : Float with type t = t and type lane = F32.t
9599
module F64x2 : Float with type t = t and type lane = F64.t
96100
end
@@ -169,6 +173,11 @@ struct
169173
let of_shape = Rep.of_i32x4
170174
end)
171175

176+
module I64x2 = MakeInt (I64) (struct
177+
let to_shape = Rep.to_i64x2
178+
let of_shape = Rep.of_i64x2
179+
end)
180+
172181
module F32x4 = MakeFloat (F32) (struct
173182
let to_shape = Rep.to_f32x4
174183
let of_shape = Rep.of_f32x4

interpreter/exec/v128.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ include Simd.Make
2828
List.iteri (fun i f -> Bytes.set_int32_le b (i*4) (I32.to_bits f)) fs;
2929
Bytes.to_string b
3030

31+
let to_i64x2 s =
32+
List.init 2 (fun i -> I64.of_bits (Bytes.get_int64_le (Bytes.of_string s) (i*8)))
33+
34+
let of_i64x2 fs =
35+
let b = Bytes.create bytewidth in
36+
List.iteri (fun i f -> Bytes.set_int64_le b (i*8) (I64.to_bits f)) fs;
37+
Bytes.to_string b
38+
3139
let to_f32x4 s =
3240
List.init 4 (fun i -> F32.of_bits (Bytes.get_int32_le (Bytes.of_string s) (i*4)))
3341

interpreter/script/run.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ let assert_result at got expect =
393393
List.exists2 (fun v r ->
394394
assert_num_pat at v r
395395
) [l0; l1; l2; l3] vs
396+
| I64x2, V128 v ->
397+
List.exists2
398+
(fun v r -> assert_num_pat at v r)
399+
(List.init 2 (fun i -> I64 (V128.I64x2.extract_lane i v)))
400+
vs
396401
| F32x4, V128 v ->
397402
let l0 = F32 (V128.F32x4.extract_lane 0 v) in
398403
let l1 = F32 (V128.F32x4.extract_lane 1 v) in

interpreter/syntax/operators.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ let i32x4_max_s = Binary (V128 (V128Op.I32x4 V128Op.MaxS))
249249
let i32x4_max_u = Binary (V128 (V128Op.I32x4 V128Op.MaxU))
250250
let i32x4_mul = Binary (V128 (V128Op.I32x4 V128Op.Mul))
251251

252+
let i64x2_neg = Unary (V128 (V128Op.I64x2 V128Op.Neg))
253+
let i64x2_add = Binary (V128 (V128Op.I64x2 V128Op.Add))
254+
let i64x2_sub = Binary (V128 (V128Op.I64x2 V128Op.Sub))
255+
let i64x2_mul = Binary (V128 (V128Op.I64x2 V128Op.Mul))
256+
252257
let f32x4_extract_lane imm = ExtractLane (V128Op.F32x4ExtractLane imm)
253258
let f32x4_abs = Unary (V128 (V128Op.F32x4 V128Op.Abs))
254259
let f32x4_neg = Unary (V128 (V128Op.F32x4 V128Op.Neg))

interpreter/text/lexer.mll

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,12 @@ rule token = parse
412412
| "output" { OUTPUT }
413413

414414
| (simd_shape as s)".neg"
415-
{ only ["i8x16"; "i16x8"; "i32x4"; "f32x4"; "f64x2"] s lexbuf;
416-
UNARY (simdop s i8x16_neg i16x8_neg i32x4_neg unreachable f32x4_neg f64x2_neg) }
415+
{ UNARY (simdop s i8x16_neg i16x8_neg i32x4_neg i64x2_neg f32x4_neg f64x2_neg) }
417416
| (simd_float_shape as s)".sqrt" { UNARY (simd_float_op s f32x4_sqrt f64x2_sqrt) }
418417
| (simd_shape as s)".add"
419-
{ only ["i8x16"; "i16x8"; "i32x4"; "f32x4"; "f64x2"] s lexbuf;
420-
BINARY (simdop s i8x16_add i16x8_add i32x4_add unreachable f32x4_add f64x2_add) }
418+
{ BINARY (simdop s i8x16_add i16x8_add i32x4_add i64x2_add f32x4_add f64x2_add) }
421419
| (simd_shape as s)".sub"
422-
{ only ["i8x16"; "i16x8"; "i32x4"; "f32x4"; "f64x2"] s lexbuf;
423-
BINARY (simdop s i8x16_sub i16x8_sub i32x4_sub unreachable f32x4_sub f64x2_sub) }
420+
{ BINARY (simdop s i8x16_sub i16x8_sub i32x4_sub i64x2_sub f32x4_sub f64x2_sub) }
424421
| (simd_shape as s)".min_s"
425422
{ only ["i8x16"; "i16x8"; "i32x4"] s lexbuf;
426423
BINARY (simdop s i8x16_min_s i16x8_min_s i32x4_min_s unreachable unreachable unreachable) }
@@ -434,8 +431,8 @@ rule token = parse
434431
{ only ["i8x16"; "i16x8"; "i32x4"] s lexbuf;
435432
BINARY (simdop s i8x16_max_u i16x8_max_u i32x4_max_u unreachable unreachable unreachable) }
436433
| (simd_shape as s)".mul"
437-
{ only ["i16x8"; "i32x4"; "f32x4"; "f64x2"] s lexbuf;
438-
BINARY (simdop s unreachable i16x8_mul i32x4_mul unreachable f32x4_mul f64x2_mul) }
434+
{ only ["i16x8"; "i32x4"; "i64x2"; "f32x4"; "f64x2"] s lexbuf;
435+
BINARY (simdop s unreachable i16x8_mul i32x4_mul i64x2_mul f32x4_mul f64x2_mul) }
439436
| (simd_float_shape as s)".div" { BINARY (simd_float_op s f32x4_div f64x2_div) }
440437
| (simd_float_shape as s)".min" { BINARY (simd_float_op s f32x4_min f64x2_min) }
441438
| (simd_float_shape as s)".max" { BINARY (simd_float_op s f32x4_max f64x2_max) }

interpreter/text/parser.mly

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ let simd_lane_lit shape l at =
6161
| I8x16 -> LitPat (Values.I32 (I8.of_string l) @@ at) @@ at
6262
| I16x8 -> LitPat (Values.I32 (I16.of_string l) @@ at) @@ at
6363
| I32x4 -> LitPat (Values.I32 (I32.of_string l) @@ at) @@ at
64+
| I64x2 -> LitPat (Values.I64 (I64.of_string l) @@ at) @@ at
6465
| F32x4 -> LitPat (Values.F32 (F32.of_string l) @@ at) @@ at
6566
| F64x2 -> LitPat (Values.F64 (F64.of_string l) @@ at) @@ at
66-
| _ -> error at "unimplemented simd lane lit"
6767

6868
let nanop f nan =
6969
let open Source in
@@ -933,10 +933,7 @@ result :
933933
| LPAR CONST NAN RPAR { NumResult (NanPat (nanop $2 ($3 @@ ati 3)) @@ ati 3) @@ at () }
934934
| LPAR V128_CONST SIMD_SHAPE numpat_list RPAR {
935935
if Simd.lanes $3 <> List.length $4 then error (at ()) "wrong number of lane literals";
936-
match $3 with
937-
| Simd.I8x16 | Simd.I16x8 | Simd.I32x4 | Simd.F32x4 | Simd.F64x2 ->
938-
SimdResult ($3, List.map (fun lit -> lit $3) ($4)) @@ at ()
939-
| _ -> error (ati 3) "unimplemented SIMD shape"
936+
SimdResult ($3, List.map (fun lit -> lit $3) ($4)) @@ at ()
940937
}
941938
942939
result_list :

0 commit comments

Comments
 (0)