[spectec] wasm-2.0: $vextunop__/$vextbinop__ are defined only for Inn, so I8/I16-lane extadd_pairwise, extmul, and dot have no result

Open Beginner friendly
#2,321 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
wasm
Domain
compilers

Research direction

Read the $vextunop__ and $vextbinop__ clauses in specification/wasm-2.0/3-numerics.spectec, then compare the corresponding clauses in 3.2-numerics.vector.spectec from wasm-3.0 and check $vunop_ in the wasm-2.0 file. Update the operand shapes to cover the Jnn cases described in the issue, then run the five named SIMD test files through the Spec2Maude validation workflow; done means all five pass.

Written by the indexing model from the issue text.

Description

In specification/wasm-2.0/3-numerics.spectec (checked on main, e7a9df7c), the clauses of $vextunop__ and $vextbinop__ (lines 588, 595, 600) match only Inn shapes:

def $vextunop__(Inn_1 X M_1, Inn_2 X M_2, EXTADD_PAIRWISE sx, c_1) = c
def $vextbinop__(Inn_1 X M_1, Inn_2 X M_2, EXTMUL half sx, c_1, c_2) = c
def $vextbinop__(Inn_1 X M_1, Inn_2 X M_2, DOT S, c_1, c_2) = c

Inn is I32 | I64 (1-syntax.spectec:141), but the syntax admits Jnn shapes (syntax vextunop_(Jnn X M), 1-syntax.spectec:376-381), and the binary format produces them, e.g. (A-binary.spectec:623):

| 0xFD 124:Bu32 => VEXTUNOP (I16 X 8) (I8 X 16) (EXTADD_PAIRWISE S)

So no clause applies to i16x8.extadd_pairwise_i8x16_s/u, i32x4.extadd_pairwise_i16x8_s/u, i16x8.extmul_*_i8x16_*, i32x4.extmul_*_i16x8_*, and i32x4.dot_i16x8_s. The premise of Step_pure/vextunop / Step_pure/vextbinop has no solution, and execution gets stuck. Only i64x2.extmul_*_i32x4_* is covered. Example (test/core/simd/simd_i16x8_extadd_pairwise_i8x16.wast:13 in wg-2.0):

(assert_return (invoke "i16x8.extadd_pairwise_i8x16_s" (v128.const i8x16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
                                                       (v128.const i16x8 2 2 2 2 2 2 2 2))

We found this with Spec2Maude, a tool that translates the SpecTec IL of the Wasm spec into Maude, a rewriting-logic framework, so that the spec semantics can be formally analyzed (e.g., model checking of Wasm programs). To validate the translation, we run the official test suite of each Wasm version (here, the wg-2.0 tag) on the translated semantics. Five files fail on the wasm-2.0 spec as is: simd_i16x8_extadd_pairwise_i8x16, simd_i32x4_extadd_pairwise_i16x8, simd_i16x8_extmul_i8x16, simd_i32x4_extmul_i16x8, and simd_i32x4_dot_i16x8.

Possible fix: use Jnn in these clauses, as wasm-3.0 does (3.2-numerics.vector.spectec:316-325) and as $vunop_ already does in the same wasm-2.0 file:

def $vextunop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTADD_PAIRWISE sx, c_1) = c
def $vextbinop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTMUL half sx, c_1, c_2) = c
def $vextbinop__(Jnn_1 X M_1, Jnn_2 X M_2, DOT S, c_1, c_2) = c

(with Inn_1/Inn_2 replaced by Jnn_1/Jnn_2 in the premises as well). With this change, all five files pass with the Maude translation.

Dominant language
WebAssembly
Stars
3.5k
Forks
545
Avg merge
1d 4h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/spec

All issues in WebAssembly/spec

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.