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

Commit d154084

Browse files
authored
Implement i32x4.dot_i16x8_s (#393)
It multiplies respective lanes from the 2 input operands, then adds adjacent lanes. This was merged into the proposal in #127.
1 parent 599b20d commit d154084

File tree

12 files changed

+189
-0
lines changed

12 files changed

+189
-0
lines changed

interpreter/binary/decode.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ let simd_prefix s =
370370
| 0xb7l -> i32x4_min_u
371371
| 0xb8l -> i32x4_max_s
372372
| 0xb9l -> i32x4_max_u
373+
| 0xbal -> i32x4_dot_i16x8_s
373374
| 0xc1l -> i64x2_neg
374375
| 0xcbl -> i64x2_shl
375376
| 0xccl -> i64x2_shr_s

interpreter/binary/encode.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ let encode m =
466466
| Binary (V128 V128Op.(I32x4 MinU)) -> simd_op 0xb7l
467467
| Binary (V128 V128Op.(I32x4 MaxS)) -> simd_op 0xb8l
468468
| Binary (V128 V128Op.(I32x4 MaxU)) -> simd_op 0xb9l
469+
| Binary (V128 V128Op.(I32x4 DotI16x8S)) -> simd_op 0xbal
469470
| Binary (V128 V128Op.(I32x4 Mul)) -> simd_op 0xb5l
470471
| Binary (V128 V128Op.(I32x4 Eq)) -> simd_op 0x37l
471472
| Binary (V128 V128Op.(I32x4 Ne)) -> simd_op 0x38l

interpreter/exec/eval_simd.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ module SimdOp (SXX : Simd.S) (Value : ValueType with type t = SXX.t) = struct
118118
| I32x4 GtU -> SXX.I32x4.gt_u
119119
| I32x4 GeS -> SXX.I32x4.ge_s
120120
| I32x4 GeU -> SXX.I32x4.ge_u
121+
| I32x4 DotI16x8S -> SXX.I32x4_convert.dot_i16x8_s
121122
| I64x2 Add -> SXX.I64x2.add
122123
| I64x2 Sub -> SXX.I64x2.sub
123124
| I64x2 Mul -> SXX.I64x2.mul

interpreter/exec/simd.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ sig
185185
val widen_high_s : t -> t
186186
val widen_low_u : t -> t
187187
val widen_high_u : t -> t
188+
val dot_i16x8_s : t -> t -> t
188189
end
189190
module I64x2_convert : sig
190191
val widen_low_s : t -> t
@@ -429,6 +430,17 @@ struct
429430
let widen_high_s = widen Lib.List.drop 0xffffffffl
430431
let widen_low_u = widen Lib.List.take 0xffffl
431432
let widen_high_u = widen Lib.List.drop 0xffffl
433+
434+
let dot_i16x8_s x y =
435+
let xs = Rep.to_i16x8 x in
436+
let ys = Rep.to_i16x8 y in
437+
let rec dot xs ys =
438+
match xs, ys with
439+
| x1::x2::xss, y1::y2::yss ->
440+
Int32.(add (mul x1 y1) (mul x2 y2)) :: dot xss yss
441+
| [], [] -> []
442+
| _, _ -> assert false
443+
in Rep.of_i32x4 (dot xs ys)
432444
end
433445

434446
module I64x2_convert = struct

interpreter/syntax/ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct
5454
| Eq | Ne | LtS | LtU | LeS | LeU | GtS | GtU | GeS | GeU
5555
| Swizzle | Shuffle of int list | NarrowS | NarrowU
5656
| AddSatS | AddSatU | SubSatS | SubSatU
57+
| DotI16x8S
5758
type funop = Abs | Neg | Sqrt
5859
| Ceil | Floor | Trunc | Nearest
5960
| ConvertI32x4S | ConvertI32x4U

interpreter/syntax/operators.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ let i32x4_max_u = Binary (V128 V128Op.(I32x4 MaxU))
367367
let i32x4_mul = Binary (V128 V128Op.(I32x4 Mul))
368368
let i32x4_trunc_sat_f32x4_s = Unary (V128 V128Op.(I32x4 TruncSatF32x4S))
369369
let i32x4_trunc_sat_f32x4_u = Unary (V128 V128Op.(I32x4 TruncSatF32x4U))
370+
let i32x4_dot_i16x8_s = Binary (V128 V128Op.(I32x4 DotI16x8S))
370371

371372
let i64x2_splat = Convert (V128 V128Op.(I64x2 Splat))
372373
let i64x2_extract_lane imm = SimdExtract (V128Op.I64x2 (ZX, imm))

interpreter/text/arrange.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ struct
305305
| I32x4 MinU -> "i32x4.min_u"
306306
| I32x4 MaxS -> "i32x4.max_s"
307307
| I32x4 MaxU -> "i32x4.max_u"
308+
| I32x4 DotI16x8S -> "i32x4.dot_i16x8_s"
308309
| I64x2 Add -> "i64x2.add"
309310
| I64x2 Sub -> "i64x2.sub"
310311
| I64x2 Mul -> "i64x2.mul"

interpreter/text/lexer.mll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,9 @@ rule token = parse
569569
| "i16x8.sub_sat_"(sign as s)
570570
{ BINARY (ext s i16x8_sub_sat_s i16x8_sub_sat_u) }
571571

572+
| "i32x4.dot_i16x8_s"
573+
{ BINARY i32x4_dot_i16x8_s }
574+
572575
| (simd_shape as s) { SIMD_SHAPE (simd_shape s) }
573576

574577
| name as s { VAR s }

test/core/simd/meta/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Currently it only support following simd test files generation.
2626
- 'simd_f64x2_rounding'
2727
- 'simd_f32x4_pmin_pmax'
2828
- 'simd_f64x2_pmin_pmax'
29+
- 'simd_i32x4_dot_i16x8'
2930

3031

3132
Usage:

test/core/simd/meta/gen_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'simd_f64x2_rounding',
3131
'simd_f32x4_pmin_pmax',
3232
'simd_f64x2_pmin_pmax',
33+
'simd_i32x4_dot_i16x8',
3334
)
3435

3536

0 commit comments

Comments
 (0)