Skip to content

Commit

Permalink
Implement i64x2.bitmask (WebAssembly#368)
Browse files Browse the repository at this point in the history
This was accepted into this proposal in WebAssembly#410.
  • Loading branch information
ngzhian committed Feb 3, 2021
1 parent 98915d5 commit 8ba1f36
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ let simd_prefix s =
| 0xbal -> i32x4_dot_i16x8_s
| 0xc0l -> i64x2_eq
| 0xc1l -> i64x2_neg
| 0xc4l -> i64x2_bitmask
| 0xcbl -> i64x2_shl
| 0xccl -> i64x2_shr_s
| 0xcdl -> i64x2_shr_u
Expand Down
1 change: 1 addition & 0 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ let encode m =
| SimdBitmask Simd.I8x16 -> simd_op 0x64l
| SimdBitmask Simd.I16x8 -> simd_op 0x84l
| SimdBitmask Simd.I32x4 -> simd_op 0xa4l
| SimdBitmask Simd.I64x2 -> simd_op 0xc4l
| SimdBitmask (_) -> assert false

| _ -> assert false
Expand Down
1 change: 1 addition & 0 deletions interpreter/exec/eval_simd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ module SimdOp (SXX : Simd.S) (Value : ValueType with type t = SXX.t) = struct
| Simd.I8x16 -> SXX.I8x16.bitmask
| Simd.I16x8 -> SXX.I16x8.bitmask
| Simd.I32x4 -> SXX.I32x4.bitmask
| Simd.I64x2 -> SXX.I64x2.bitmask
| _ -> assert false
in I32 (f (of_value 1 v))

Expand Down
1 change: 1 addition & 0 deletions interpreter/syntax/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ let i64x2_mul = Binary (V128 V128Op.(I64x2 Mul))
let i64x2_shl = SimdShift V128Op.(I64x2 Shl)
let i64x2_shr_s = SimdShift V128Op.(I64x2 ShrS)
let i64x2_shr_u = SimdShift V128Op.(I64x2 ShrU)
let i64x2_bitmask = SimdBitmask Simd.I64x2

let f32x4_splat = Convert (V128 V128Op.(F32x4 Splat))
let f32x4_extract_lane imm = SimdExtract (V128Op.F32x4 (ZX, imm))
Expand Down
1 change: 1 addition & 0 deletions interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ struct
| Simd.I8x16 -> "i8x16.bitmask"
| Simd.I16x8 -> "i16x8.bitmask"
| Simd.I32x4 -> "i32x4.bitmask"
| Simd.I64x2 -> "i64x2.bitmask"
| _ -> assert false

end
Expand Down
3 changes: 1 addition & 2 deletions interpreter/text/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ rule token = parse
{ only ["i8x16"; "i16x8"; "i32x4"] s lexbuf;
UNARY (simd_int_op s i8x16_all_true i16x8_all_true i32x4_all_true unreachable) }
| (simd_int_shape as s)".bitmask"
{ only ["i8x16"; "i16x8"; "i32x4"] s lexbuf;
UNARY (simd_int_op s i8x16_bitmask i16x8_bitmask i32x4_bitmask unreachable) }
{ UNARY (simd_int_op s i8x16_bitmask i16x8_bitmask i32x4_bitmask i64x2_bitmask) }
| (simd_int_shape as s)".shl"
{ SHIFT (simd_int_op s i8x16_shl i16x8_shl i32x4_shl i64x2_shl) }
| (simd_int_shape as s)".shr_s"
Expand Down
7 changes: 7 additions & 0 deletions test/core/simd/simd_boolean.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
(func (export "i32x4.any_true") (param $0 v128) (result i32) (v128.any_true (local.get $0)))
(func (export "i32x4.all_true") (param $0 v128) (result i32) (i32x4.all_true (local.get $0)))
(func (export "i32x4.bitmask") (param $0 v128) (result i32) (i32x4.bitmask (local.get $0)))

(func (export "i64x2.bitmask") (param $0 v128) (result i32) (i64x2.bitmask (local.get $0)))
)

;; i8x16
Expand Down Expand Up @@ -156,6 +158,11 @@
(assert_return (invoke "i32x4.bitmask" (v128.const i32x4 -1 0 1 0xF))
(i32.const 0x00000001))

(assert_return (invoke "i64x2.bitmask" (v128.const i64x2 0xFFFFFFFF_FFFFFFFF 0xFFFFFFFF_FFFFFFFF))
(i32.const 0x00000003))
(assert_return (invoke "i64x2.bitmask" (v128.const i64x2 -1 0xF))
(i32.const 0x00000001))

;; Combination

(module (memory 1)
Expand Down

0 comments on commit 8ba1f36

Please sign in to comment.