diff --git a/specification/wasm-1.0/1-syntax.spectec b/specification/wasm-1.0/1-syntax.spectec index 5566658277..fb74afe757 100644 --- a/specification/wasm-1.0/1-syntax.spectec +++ b/specification/wasm-1.0/1-syntax.spectec @@ -178,8 +178,19 @@ syntax relop_(Inn) = syntax relop_(Fnn) = | EQ | NE | LT | GT | LE | GE -syntax cvtop = - | EXTEND sx | WRAP | CONVERT sx | TRUNC sx | PROMOTE | DEMOTE | REINTERPRET +syntax cvtop__(valtype_1, valtype_2) +syntax cvtop__(Inn_1, Inn_2) = + | EXTEND sx -- if $size(Inn_1) < $size(Inn_2) + | WRAP -- if $size(Inn_1) > $size(Inn_2) +syntax cvtop__(Inn_1, Fnn_2) = + | CONVERT sx + | REINTERPRET -- if $size(Inn_1) = $size(Fnn_2) +syntax cvtop__(Fnn_1, Inn_2) = + | TRUNC sx + | REINTERPRET -- if $size(Fnn_1) = $size(Inn_2) +syntax cvtop__(Fnn_1, Fnn_2) = + | PROMOTE -- if $size(Fnn_1) < $size(Fnn_2) + | DEMOTE -- if $size(Fnn_1) > $size(Fnn_2) ;; Memory operators @@ -229,7 +240,7 @@ syntax instr/num hint(desc "numeric instruction") = ... | BINOP valtype binop_(valtype) hint(show %.%) | TESTOP valtype testop_(valtype) hint(show %.%) | RELOP valtype relop_(valtype) hint(show %.%) - | CVTOP valtype_1 valtype_2 cvtop hint(show %1.%3#_#%2) + | CVTOP valtype_1 valtype_2 cvtop__(valtype_2, valtype_1) hint(show %1.##%3#_#%2) -- if valtype_1 =/= valtype_2 | ... diff --git a/specification/wasm-1.0/3-numerics.spectec b/specification/wasm-1.0/3-numerics.spectec index aac9c98749..e3095cfef3 100644 --- a/specification/wasm-1.0/3-numerics.spectec +++ b/specification/wasm-1.0/3-numerics.spectec @@ -33,7 +33,7 @@ def $testop_(valtype, testop_(valtype), val_(valtype)) : val_(I32) hint(show %2#$_(%1)#((%3))) def $relop_(valtype, relop_(valtype), val_(valtype), val_(valtype)) : val_(I32) hint(show %2#$_(%1)#(%3, %4)) -def $cvtop__(valtype_1, valtype_2, cvtop, val_(valtype_1)) : val_(valtype_2)* +def $cvtop__(valtype_1, valtype_2, cvtop__(valtype_1, valtype_2), val_(valtype_1)) : val_(valtype_2)* hint(show %3#$__(%1,%2)#((%4))) def $wrap__(M, N, iN(M)) : iN(N) @@ -79,8 +79,8 @@ def $inot_(N, iN(N)) : iN(N) def $iand_(N, iN(N), iN(N)) : iN(N) def $ior_(N, iN(N), iN(N)) : iN(N) def $ixor_(N, iN(N), iN(N)) : iN(N) -def $ishl_(N, iN(N), u32) : iN(N) -def $ishr_(N, sx, iN(N), u32) : iN(N) hint(show $ishr_(%)^(%)#((%,%))) +def $ishl_(N, iN(N), iN(N)) : iN(N) +def $ishr_(N, sx, iN(N), iN(N)) : iN(N) hint(show $ishr_(%)^(%)#((%,%))) def $irotl_(N, iN(N), iN(N)) : iN(N) def $irotr_(N, iN(N), iN(N)) : iN(N) def $iclz_(N, iN(N)) : iN(N) diff --git a/specification/wasm-1.0/6-typing.spectec b/specification/wasm-1.0/6-typing.spectec index ba19eb0ce9..faae809568 100644 --- a/specification/wasm-1.0/6-typing.spectec +++ b/specification/wasm-1.0/6-typing.spectec @@ -233,13 +233,7 @@ rule Instr_ok/testop: rule Instr_ok/relop: C |- RELOP t relop_t : t t -> I32 - -;; TODO: move side conditions to syntax -rule Instr_ok/cvtop-reinterpret: - C |- CVTOP nt_1 nt_2 REINTERPRET : nt_2 -> nt_1 - -- if $size(nt_1) = $size(nt_2) - -rule Instr_ok/cvtop-convert: +rule Instr_ok/cvtop: C |- CVTOP nt_1 nt_2 cvtop : nt_2 -> nt_1 diff --git a/specification/wasm-1.0/8-reduction.spectec b/specification/wasm-1.0/8-reduction.spectec index 6b160730aa..799f6630be 100644 --- a/specification/wasm-1.0/8-reduction.spectec +++ b/specification/wasm-1.0/8-reduction.spectec @@ -84,10 +84,10 @@ rule Step_pure/label-vals: ;; TODO: may want a label context instead of bubbling up rule Step_pure/br-zero: - (LABEL_ n `{instr'*} val'* val^n (BR 0) instr*) ~> val^n instr'* + (LABEL_ n `{instr'*} val'* val^n (BR 0) admininstr*) ~> val^n instr'* rule Step_pure/br-succ: - (LABEL_ n `{instr'*} val* (BR $(l+1)) instr*) ~> val* (BR l) + (LABEL_ n `{instr'*} val* (BR $(l+1)) admininstr*) ~> val* (BR l) rule Step_pure/br_if-true: @@ -133,17 +133,17 @@ rule Step_pure/frame-vals: (FRAME_ n `{f} val^n) ~> val^n rule Step_pure/return-frame: - (FRAME_ n `{f} val'* val^n RETURN instr*) ~> val^n + (FRAME_ n `{f} val'* val^n RETURN admininstr*) ~> val^n rule Step_pure/return-label: - (LABEL_ n `{instr'*} val* RETURN instr*) ~> val* RETURN + (LABEL_ n `{instr'*} val* RETURN admininstr*) ~> val* RETURN ;; Traps rule Step_pure/trap-vals: - val* TRAP instr* ~> TRAP - -- if val* =/= eps \/ instr* =/= eps + val* TRAP admininstr* ~> TRAP + -- if val* =/= eps \/ admininstr* =/= eps rule Step_pure/trap-label: (LABEL_ n `{instr'*} TRAP) ~> TRAP diff --git a/specification/wasm-1.0/B-soundness.spectec b/specification/wasm-1.0/B-soundness.spectec new file mode 100644 index 0000000000..7a30d9ecd0 --- /dev/null +++ b/specification/wasm-1.0/B-soundness.spectec @@ -0,0 +1,229 @@ +;; Contexts + +relation Context_ok: |- context : OK hint(macro "%context") + +rule Context_ok: + |- C : OK + -- if C = + { TYPES ft*, + FUNCS ft_2*, + GLOBALS gt*, + MEMS mt*, + TABLES tt*, + LOCALS lct*, + LABELS rt*, + RETURN rt'?, + } + -- (Functype_ok: |- ft : OK)* + -- (Globaltype_ok: |- gt : OK)* + -- (Memtype_ok: |- mt : OK)* + -- (Tabletype_ok: |- tt : OK)* + -- (Functype_ok: |- ft_2 : OK)* + + +;; Value types + +relation Val_ok: |- val : valtype + +rule Val_ok: + |- CONST t c_t : t + + +;; Result types + +relation Result_ok: |- result : valtype* + +rule Result_ok/result: + |- _VALS v* : t* + -- (Val_ok: |- v : t)* + +rule Result_ok/trap: + |- TRAP : t* + + +;; Administrative instructions + +syntax adminexpr = admininstr* + +relation Instr_ok2: store; context |- admininstr : functype + hint(prose "%3 is valid with %4") +relation Instrs_ok2: store; context |- admininstr* : functype + hint(prose "%3 is valid with %4") +relation Expr_ok2: store; context |- adminexpr : resulttype + hint(prose "%3 is valid with %4") + +rule Instr_ok2/plain: + s; C |- instr : t_1* -> t_2* + -- Instr_ok: C |- instr : t_1* -> t_2* + +rule Instr_ok2/label: + s; C |- LABEL_ n `{instr'*} admininstr* : eps -> t? + -- if |t'?| = n + -- Instrs_ok2: s; C |- instr'* : t'? -> t? + -- Instrs_ok2: s; {LABELS (t'?)} ++ C |- admininstr* : eps -> t? + +rule Instr_ok2/frame: + s; C |- FRAME_ n `{f} admininstr* : eps -> t? + -- if |t?| = n + -- Frame_ok: s |- f : C' + -- Expr_ok2: s; C' ++ {RETURN t?} |- admininstr* : t? + +rule Instr_ok2/call_addr: + s; C |- CALL_ADDR funcaddr : t_1* -> t_2* + -- Externaddr_ok: s |- FUNC funcaddr: FUNC (t_1* -> t_2*) + +rule Instr_ok2/trap: + s; C |- TRAP : t_1* -> t_2* + + +rule Instrs_ok2/empty: + s; C |- eps : eps -> eps + +rule Instrs_ok2/instr: + s; C |- admininstr : t_1* -> t_2* + -- Instr_ok2: s; C |- admininstr : t_1* -> t_2* + +rule Instrs_ok2/seq: + s; C |- admininstr_1* admininstr_2* : t_1* -> t_3* + -- Instrs_ok2: s; C |- admininstr_1* : t_1* -> t_2* + -- Instrs_ok2: s; C |- admininstr_2* : t_2* -> t_3* + +rule Instrs_ok2/frame: + s; C |- admininstr* : t* t_1* -> t* t_2* + -- Instrs_ok2: s; C |- admininstr* : t_1* -> t_2* + +rule Expr_ok2: + s; C |- admininstr* : t? + -- Instrs_ok2: s; C |- admininstr* : eps -> t? + + +;; Instances + +relation Globalinst_ok: store |- globalinst : globaltype +relation Meminst_ok: store |- meminst : memtype +relation Tableinst_ok: store |- tableinst : tabletype +relation Funcinst_ok: store |- funcinst : functype +relation Exportinst_ok: store |- exportinst : OK + +rule Globalinst_ok: + s |- {TYPE mut t, VALUE val} : mut t + -- Globaltype_ok: |- mut t : OK + -- Val_ok: |- val : t + +rule Meminst_ok: + s |- {TYPE `[n..m?], BYTES b*} : `[n..m?] + -- Memtype_ok: |- `[n..m?] : OK + -- if |b*| = $(n * $($(64 * $Ki))) + +rule Tableinst_ok: + s |- {TYPE `[n..m?] , REFS (fa?)*} : `[n..m?] + -- Tabletype_ok: |- `[n..m?] : OK + -- ((Externaddr_ok: s |- FUNC fa : FUNC ft)?)* + -- if |(fa?)*| = n + +rule Funcinst_ok: + s |- {TYPE ft, MODULE moduleinst, CODE func} : ft + -- Functype_ok: |- ft : OK + -- Moduleinst_ok: s |- moduleinst : C + -- Func_ok: C |- func : ft + +rule Exportinst_ok: + s |- {NAME nm, ADDR xa} : OK + -- Externaddr_ok: s |- xa : xt + + +;; Modules + +relation Moduleinst_ok: store |- moduleinst : context + +rule Moduleinst_ok: + s |- { TYPES functype*, + GLOBALS globaladdr*, + MEMS memaddr*, + TABLES tableaddr*, + FUNCS funcaddr*, + EXPORTS exportinst* } : + { TYPES functype*, + GLOBALS globaltype*, + MEMS memtype*, + TABLES tabletype*, + FUNCS functype_F*, + } + -- (Functype_ok: |- functype : OK)* + -- (Externaddr_ok: s |- GLOBAL globaladdr : GLOBAL globaltype)* + -- (Externaddr_ok: s |- FUNC funcaddr : FUNC functype_F)* + -- (Externaddr_ok: s |- MEM memaddr : MEM memtype)* + -- (Externaddr_ok: s |- TABLE tableaddr : TABLE tabletype)* + -- (Exportinst_ok: s |- exportinst : OK)* + ---- + -- if $disjoint_(name, (exportinst.NAME)*) + -- (if exportinst.ADDR <- (GLOBAL globaladdr)* (MEM memaddr)* (TABLE tableaddr)* (FUNC funcaddr)*)* + + +;; Stores + +relation Store_ok: |- store : OK + +rule Store_ok: + |- s : OK + -- (Globalinst_ok: s |- globalinst : globaltype)* + -- (Meminst_ok: s |- meminst : memtype)* + -- (Tableinst_ok: s |- tableinst : tabletype)* + -- (Funcinst_ok: s |- funcinst : functype)* + ---- + -- if s = {GLOBALS globalinst*, MEMS meminst*, TABLES tableinst*, FUNCS funcinst*} + + +;; Store extension + +relation Extend_globalinst: globalinst `<= globalinst +relation Extend_meminst: meminst `<= meminst +relation Extend_tableinst: tableinst `<= tableinst +relation Extend_funcinst: funcinst `<= funcinst +relation Extend_store: store `<= store + +rule Extend_globalinst: + {TYPE mut t, VALUE val} `<= {TYPE mut t, VALUE val'} + -- if mut = MUT \/ val = val' + +rule Extend_meminst: + {TYPE `[n..m?], BYTES b*} `<= {TYPE `[n'..m?], BYTES b'*} + -- if n <= n' + -- if |b*| <= |b'*| + +rule Extend_tableinst: + {TYPE `[n..m?], REFS ref*} `<= {TYPE `[n'..m?], REFS ref'*} + -- if n <= n' + -- if |ref*| <= |ref'*| + +rule Extend_funcinst: + {TYPE ft, MODULE mm, CODE fc} `<= {TYPE ft, MODULE mm, CODE fc} + +rule Extend_store: + s `<= s' + -- (Extend_globalinst: s.GLOBALS[a] `<= s'.GLOBALS[a] )^(a<|s.GLOBALS|) + -- (Extend_meminst: s.MEMS[a] `<= s'.MEMS[a] )^(a<|s.MEMS|) + -- (Extend_tableinst: s.TABLES[a] `<= s'.TABLES[a] )^(a<|s.TABLES|) + -- (Extend_funcinst: s.FUNCS[a] `<= s'.FUNCS[a] )^(a<|s.FUNCS|) + + +;; Configurations + +relation Frame_ok: store |- frame : context +relation State_ok: |- state : context +relation Config_ok: |- config : resulttype + +rule Frame_ok: + s |- {LOCALS val*, MODULE moduleinst} : C ++ {LOCALS t*} + -- Moduleinst_ok: s |- moduleinst : C + -- (Val_ok: |- val : t)* + +rule State_ok: + |- s; f : C + -- Store_ok: |- s : OK + -- Frame_ok: s |- f : C + +rule Config_ok: + |- s; f; admininstr* : t? + -- State_ok: |- s; f : C + -- Expr_ok2: s; C |- admininstr* : t? diff --git a/specification/wasm-2.0/1-syntax.spectec b/specification/wasm-2.0/1-syntax.spectec index aaeafc60ea..3f3a6f9e27 100644 --- a/specification/wasm-2.0/1-syntax.spectec +++ b/specification/wasm-2.0/1-syntax.spectec @@ -209,6 +209,7 @@ def $lanetype(shape) : lanetype def $unpack(lanetype) : numtype def $size(valtype) : nat hint(show |%|) hint(partial) +def $vsize(vectype) : nat hint(show |%|) def $psize(packtype) : nat hint(show |%|) def $lsize(lanetype) : nat hint(show |%|) def $isize(Inn) : nat hint(show |%|) hint(inverse $inv_isize) @@ -221,6 +222,8 @@ def $size(F32) = 32 def $size(F64) = 64 def $size(V128) = 128 +def $vsize(V128) = 128 + def $psize(I8) = 8 def $psize(I16) = 16 @@ -265,10 +268,16 @@ syntax num_(Fnn) = fN($sizenn(Fnn)) syntax pack_(Pnn) = iN($psize(Pnn)) +;; TODO: HACK! lane_ should reuse num_ and pack_. +;; Original definition: +;; syntax lane_(lanetype) +;; syntax lane_(numtype) = num_(numtype) +;; syntax lane_(packtype) = pack_(packtype) +;; syntax lane_(Jnn) = iN($lsize(Jnn)) ;; HACK + syntax lane_(lanetype) -syntax lane_(numtype) = num_(numtype) -syntax lane_(packtype) = pack_(packtype) -syntax lane_(Jnn) = iN($lsize(Jnn)) ;; HACK +syntax lane_(Jnn) = iN($lsize(Jnn)) +syntax lane_(Fnn) = fN($sizenn(Fnn)) syntax vec_(Vnn) = vN($size(Vnn)) @@ -305,24 +314,33 @@ syntax relop_(Inn) = syntax relop_(Fnn) = | EQ | NE | LT | GT | LE | GE -syntax cvtop = - | EXTEND sx - | WRAP +syntax cvtop__(numtype_1, numtype_2) +syntax cvtop__(Inn_1, Inn_2) = + | EXTEND sx -- if $sizenn1(Inn_1) < $sizenn2(Inn_2) + | WRAP -- if $sizenn1(Inn_1) > $sizenn2(Inn_2) +syntax cvtop__(Inn_1, Fnn_2) = | CONVERT sx + | REINTERPRET -- if $sizenn1(Inn_1) = $sizenn2(Fnn_2) +syntax cvtop__(Fnn_1, Inn_2) = | TRUNC sx | TRUNC_SAT sx - | PROMOTE - | DEMOTE - | REINTERPRET + | REINTERPRET -- if $sizenn1(Fnn_1) = $sizenn2(Inn_2) +syntax cvtop__(Fnn_1, Fnn_2) = + | PROMOTE -- if $sizenn1(Fnn_1) < $sizenn2(Fnn_2) + | DEMOTE -- if $sizenn1(Fnn_1) > $sizenn2(Fnn_2) ;; Vector operators syntax dim hint(desc "dimension") = `1 | `2 | `4 | `8 | `16 syntax shape hint(desc "shape") = lanetype X dim hint(show %0#X#%2) -syntax ishape hint(desc "shape") = Jnn X dim hint(show %0#X#%2) -syntax fshape hint(desc "shape") = Fnn X dim hint(show %0#X#%2) -syntax pshape hint(desc "shape") = Pnn X dim hint(show %0#X#%2) + -- if $($lsize(lanetype) * dim = 128) +syntax ishape hint(desc "shape") = shape hint(show %0#X#%2) + -- if $lanetype(shape) = Jnn +syntax fshape hint(desc "shape") = shape hint(show %0#X#%2) + -- if $lanetype(shape) = Fnn +syntax pshape hint(desc "shape") = shape hint(show %0#X#%2) + -- if $lanetype(shape) = Pnn syntax M = dim @@ -367,18 +385,37 @@ syntax vrelop_(Fnn X M) = EQ | NE | LT | GT | LE | GE syntax half hint(desc "lane part") = LOW | HIGH syntax zero = ZERO -syntax vcvtop = EXTEND half sx | TRUNC_SAT sx zero? | CONVERT half? sx | DEMOTE zero | PROMOTE LOW +syntax vcvtop__(shape_1, shape_2) hint(macro "%" "V%") +syntax vcvtop__(Jnn_1 X M_1, Jnn_2 X M_2) = + | EXTEND half sx hint(show EXTEND#_#%#_#%) + -- if $lsizenn2(Jnn_2) = $(2 * $lsizenn1(Jnn_1)) +syntax vcvtop__(Jnn_1 X M_1, Fnn_2 X M_2) = + | CONVERT half? sx hint(show CONVERT#_#%) hint(show CONVERT#_#%#_#%) + -- if $sizenn2(Fnn_2) = $lsizenn1(Jnn_1) = `32 /\ half? = eps + \/ $sizenn2(Fnn_2) = $(2 * $lsizenn1(Jnn_1)) /\ half? = LOW +syntax vcvtop__(Fnn_1 X M_1, Inn_2 X M_2) = + | TRUNC_SAT sx zero? hint(show TRUNC_SAT#_#%) hint(show TRUNC_SAT#_#%#_#%) + -- if $sizenn1(Fnn_1) = $lsizenn2(Inn_2) = `32 /\ zero? = eps + \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Inn_2)) /\ zero? = ZERO +syntax vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2) = + | DEMOTE zero hint(show DEMOTE#_#ZERO) + -- if $sizenn1(Fnn_1) = $(2 * $sizenn2(Fnn_2)) + | PROMOTE LOW hint(show PROMOTE#_#LOW) + -- if $(2 * $sizenn1(Fnn_1)) = $sizenn2(Fnn_2) syntax vshiftop_(ishape) syntax vshiftop_(Jnn X M) = SHL | SHR sx -syntax vextunop_(ishape) -syntax vextunop_(Jnn X M) = - | EXTADD_PAIRWISE sx -- if `16 <= $lsizenn(Jnn) <= `32 -syntax vextbinop_(ishape) -syntax vextbinop_(Jnn X M) = - | EXTMUL half sx hint(show EXTMUL#_#%#_#%) - | DOT S -- if $lsizenn(Jnn) = `32 +syntax vextunop__(ishape_1, ishape_2) hint(macro "%" "V%") +syntax vextunop__(Jnn_1 X M_1, Jnn_2 X M_2) = + | EXTADD_PAIRWISE sx hint(show EXTADD_PAIRWISE#_#%) + -- if 16 <= $(2 * $lsizenn1(Jnn_1)) = $lsizenn2(Jnn_2) <= `32 +syntax vextbinop__(ishape_1, ishape_2) hint(macro "%" "V%") +syntax vextbinop__(Jnn_1 X M_1, Jnn_2 X M_2) = + | EXTMUL half sx hint(show EXTMUL#_#%#_#%) + -- if $(2 * $lsizenn1(Jnn_1)) = $lsizenn2(Jnn_2) >= `16 + | DOT S hint(show DOT#_#%) + -- if $(2 * $lsizenn1(Jnn_1)) = $lsizenn2(Jnn_2) = `32 ;; Memory operators @@ -390,10 +427,10 @@ var ao : memarg syntax loadop_(numtype) syntax loadop_(Inn) = sz _ sx hint(show %0#_#%2) -- if sz < $sizenn(Inn) -syntax vloadop = - | SHAPE nat X nat _ sx hint(show %1#X#%3#_#%5) - | SPLAT nat hint(show %#_#SPLAT) - | ZERO nat hint(show %#_#ZERO) +syntax vloadop_(vectype) = + | SHAPE sz X M _ sx hint(show %1#X#%3#_#%5) -- if $(sz * M = $vsize(vectype)/2) /\ M > `1 + | SPLAT sz hint(show %#_#SPLAT) + | ZERO sz hint(show %#_#ZERO) -- if sz >= `32 ;; @@ -437,7 +474,7 @@ syntax instr/num hint(desc "numeric instruction") = ... | BINOP numtype binop_(numtype) hint(show %.%) | TESTOP numtype testop_(numtype) hint(show %.%) | RELOP numtype relop_(numtype) hint(show %.%) - | CVTOP numtype_1 numtype_2 cvtop hint(show %1.%3#_#%2) + | CVTOP numtype_1 numtype_2 cvtop__(numtype_2, numtype_1) hint(show %1.##%3#_#%2) -- if numtype_1 =/= numtype_2 | ... @@ -459,17 +496,13 @@ syntax instr/vec hint(desc "vector instruction") = ... -- if ishape = I8 X `16 /\ |laneidx*| = 16 | VSPLAT shape hint(show %.SPLAT) | VEXTRACT_LANE shape sx? laneidx hint(show %.EXTRACT_LANE_#% %) - -- if sx? =/= eps <=> $lanetype(shape) =/= $unpack($lanetype(shape)) + -- if $lanetype(shape) <- I32 I64 F32 F64 <=> sx? = eps | VREPLACE_LANE shape laneidx hint(show %.REPLACE_LANE %) - | VEXTUNOP ishape_1 ishape_2 vextunop_(ishape_1) - hint(show %1.%3#_#%2#_#%4) - -- if $($lsize($lanetype(ishape_1)) = 2*$lsize($lanetype(ishape_2))) - | VEXTBINOP ishape_1 ishape_2 vextbinop_(ishape_1) - hint(show %1.%3#_#%2#_#%4) - -- if $($lsize($lanetype(ishape_1)) = 2*$lsize($lanetype(ishape_2))) + | VEXTUNOP ishape_1 ishape_2 vextunop__(ishape_2, ishape_1) hint(show %1.%3#_#%2#_#%4) + | VEXTBINOP ishape_1 ishape_2 vextbinop__(ishape_2, ishape_1) hint(show %1.%3#_#%2#_#%4) | VNARROW ishape_1 ishape_2 sx hint(show %.NARROW#_#%#_#%) -- if $($lsize($lanetype(ishape_2)) = 2*$lsize($lanetype(ishape_1)) <= 32) - | VCVTOP shape shape vcvtop + | VCVTOP shape_1 shape_2 vcvtop__(shape_2, shape_1) hint(show %1.%3#_#%2) ;; TODO: missing constraints | ... @@ -509,7 +542,7 @@ syntax instr/memory hint(desc "memory instruction") = ... | LOAD numtype loadop_(numtype)? memarg hint(show %.LOAD %) hint(show %.LOAD# ##% %) | STORE numtype sz? memarg hint(show %.STORE %) hint(show %.STORE#% %) -- (if numtype = Inn /\ sz < $sizenn(Inn))? - | VLOAD vectype vloadop? memarg hint(show %.LOAD %) hint(show %.LOAD#% %) + | VLOAD vectype vloadop_(vectype)? memarg hint(show %.LOAD %) hint(show %.LOAD#% %) | VLOAD_LANE vectype sz memarg laneidx hint(show %.LOAD#%#_#LANE % %) | VSTORE vectype memarg hint(show %.STORE %) | VSTORE_LANE vectype sz memarg laneidx hint(show %.STORE#%#_#LANE % %) diff --git a/specification/wasm-2.0/3-numerics.spectec b/specification/wasm-2.0/3-numerics.spectec index 4960e5d274..8934ee1517 100644 --- a/specification/wasm-2.0/3-numerics.spectec +++ b/specification/wasm-2.0/3-numerics.spectec @@ -49,7 +49,7 @@ def $testop_(numtype, testop_(numtype), num_(numtype)) : num_(I32) hint(show %2#$_(%1)#((%3))) def $relop_(numtype, relop_(numtype), num_(numtype), num_(numtype)) : num_(I32) hint(show %2#$_(%1)#(%3, %4)) -def $cvtop__(numtype_1, numtype_2, cvtop, num_(numtype_1)) : num_(numtype_2)* +def $cvtop__(numtype_1, numtype_2, cvtop__(numtype_1, numtype_2), num_(numtype_1)) : num_(numtype_2)* hint(show %3#$__(%1,%2)#((%4))) def $wrap__(N, N', iN(N)) : iN(N') @@ -113,8 +113,8 @@ def $iand_(N, iN(N), iN(N)) : iN(N) def $iandnot_(N, iN(N), iN(N)) : iN(N) def $ior_(N, iN(N), iN(N)) : iN(N) def $ixor_(N, iN(N), iN(N)) : iN(N) -def $ishl_(N, iN(N), u32) : iN(N) -def $ishr_(N, sx, iN(N), u32) : iN(N) hint(show $ishr_(%)^(%)#((%,%))) +def $ishl_(N, iN(N), iN(N)) : iN(N) +def $ishr_(N, sx, iN(N), iN(N)) : iN(N) hint(show $ishr_(%)^(%)#((%,%))) def $irotl_(N, iN(N), iN(N)) : iN(N) def $irotr_(N, iN(N), iN(N)) : iN(N) def $iclz_(N, iN(N)) : iN(N) @@ -322,12 +322,14 @@ def $cvtop__(Fnn_1, Inn_2, REINTERPRET, fN_1) = $reinterpret__(Fnn_1, Inn_2, fN_ def $packnum_(lanetype, num_($unpack(lanetype))) : lane_(lanetype) hint(show $pack_(%,%)) -def $packnum_(numtype, c) = c +def $packnum_(Inn, c) = c +def $packnum_(Fnn, c) = c def $packnum_(packtype, c) = $wrap__($size($unpack(packtype)), $psize(packtype), c) def $unpacknum_(lanetype, lane_(lanetype)) : num_($unpack(lanetype)) hint(show $unpack_(%,%)) -def $unpacknum_(numtype, c) = c +def $unpacknum_(Inn, c) = c +def $unpacknum_(Fnn, c) = c def $unpacknum_(packtype, c) = $extend__($psize(packtype), $size($unpack(packtype)), U, c) @@ -340,19 +342,19 @@ def $inv_lanes_(shape, lane_($lanetype(shape))*) : vec_(V128) hint(show $lanes^(-1)#_%#(%,%)) def $inv_lanes_ hint(builtin) -def $zeroop(vcvtop) : zero? -def $zeroop(EXTEND half sx) = eps -def $zeroop(CONVERT half? sx) = eps -def $zeroop(TRUNC_SAT sx zero?) = zero? -def $zeroop(DEMOTE zero) = zero -def $zeroop(PROMOTE LOW) = eps +def $zeroop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : zero? +def $zeroop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = eps +def $zeroop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = eps +def $zeroop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = zero? +def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = zero +def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = eps -def $halfop(vcvtop) : half? -def $halfop(EXTEND half sx) = half -def $halfop(CONVERT half? sx) = half? -def $halfop(TRUNC_SAT sx zero?) = eps -def $halfop(DEMOTE zero) = eps -def $halfop(PROMOTE LOW) = LOW +def $halfop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : half? +def $halfop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = half +def $halfop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = half? +def $halfop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = eps +def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = eps +def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = LOW def $half(half, nat, nat) : nat def $half(LOW, i, j) = i @@ -380,7 +382,9 @@ def $vbinop_(shape, vbinop_(shape), vec_(V128), vec_(V128)) : vec_(V128)* hint(show %2#$_(%1)#(%3, %4)) def $vrelop_(shape, vrelop_(shape), vec_(V128), vec_(V128)) : vec_(V128) hint(show %2#$_(%1)#(%3, %4)) -def $vcvtop__(shape_1, shape_2, vcvtop, lane_($lanetype(shape_1))) : lane_($lanetype(shape_2))* +def $lcvtop__(shape_1, shape_2, vcvtop__(shape_1, shape_2), lane_($lanetype(shape_1))) : lane_($lanetype(shape_2))* + hint(show %3#$__(%1,%2)^(%4)#((%5))) +def $vcvtop__(shape_1, shape_2, vcvtop__(shape_1, shape_2), vec_(V128)) : vec_(V128) hint(show %3#$__(%1,%2)^(%4)#((%5))) def $vunop_(Jnn X M, ABS, v128_1) = v128 @@ -568,45 +572,61 @@ def $vrelop_(Fnn X M, GE, v128_1, v128_2) = v128 -- if $isize(Inn) = $size(Fnn) -- if v128 = $inv_lanes_(Inn X M, lane_3*) -def $vcvtop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx, iN_1) = iN_2 +def $lcvtop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx, iN_1) = iN_2 -- if iN_2 = $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), sx, iN_1) -def $vcvtop__(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx, iN_1) = fN_2 +def $lcvtop__(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx, iN_1) = fN_2 -- if fN_2 = $convert__($lsizenn1(Jnn_1), $lsizenn2(Fnn_2), sx, iN_1) -def $vcvtop__(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?, fN_1) = $list_(lane_(Inn_2), iN_2?) +def $lcvtop__(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?, fN_1) = $list_(lane_(Inn_2), iN_2?) -- if iN_2? = $trunc_sat__($lsizenn1(Fnn_1), $lsizenn2(Inn_2), sx, fN_1) -def $vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE ZERO, fN_1) = fN_2* +def $lcvtop__(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE ZERO, fN_1) = fN_2* -- if fN_2* = $demote__($lsizenn1(Fnn_1), $lsizenn2(Fnn_2), fN_1) -def $vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW, fN_1) = fN_2* +def $lcvtop__(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW, fN_1) = fN_2* -- if fN_2* = $promote__($lsizenn1(Fnn_1), $lsizenn2(Fnn_2), fN_1) - -def $vextunop__(ishape_1, ishape_2, vextunop_(ishape_1), vec_(V128)) : vec_(V128) +def $vcvtop__(Lnn_1 X M, Lnn_2 X M, vcvtop, v128_1) = v128 + -- if $halfop(Lnn_1 X M, Lnn_2 X M, vcvtop) = eps /\ $zeroop(Lnn_1 X M, Lnn_2 X M, vcvtop) = eps + -- if c_1* = $lanes_(Lnn_1 X M, v128_1) + -- if c** = $setproduct_(lane_(Lnn_2), $lcvtop__(Lnn_1 X M, Lnn_2 X M, vcvtop, c_1)*) + -- if v128 <- $inv_lanes_(Lnn_2 X M, c*)* +def $vcvtop__(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop, v128_1) = v128 + -- if $halfop(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop) = half + -- if c_1* = $lanes_(Lnn_1 X M_1, v128_1)[$half(half, 0, M_2) : M_2] + -- if c** = $setproduct_(lane_(Lnn_2), $lcvtop__(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop, c_1)*) + -- if v128 <- $inv_lanes_(Lnn_2 X M_2, c*)* +def $vcvtop__(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop, v128_1) = v128 + -- if $zeroop(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop) = ZERO + -- if c_1* = $lanes_(Lnn_1 X M_1, v128_1) + -- if c** = $setproduct_(lane_(Lnn_2), ($lcvtop__(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop, c_1)* ++ [$packnum_(Lnn_2, $zero($unpack(Lnn_2)))]^M_1)) + -- if v128 <- $inv_lanes_(Lnn_2 X M_2, c*)* + + +def $vextunop__(ishape_1, ishape_2, vextunop__(ishape_1, ishape_2), vec_(V128)) : vec_(V128) hint(show %3#$_((%1,%2))^(%5)#((%6))) -def $vextbinop__(ishape_1, ishape_2, vextbinop_(ishape_1), vec_(V128), vec_(V128)) : vec_(V128) +def $vextbinop__(ishape_1, ishape_2, vextbinop__(ishape_1, ishape_2), vec_(V128), vec_(V128)) : vec_(V128) hint(show %3#$_((%1,%2))^(%5)#((%6,%7))) -def $vextunop__(Inn_1 X M_1, Inn_2 X M_2, EXTADD_PAIRWISE sx, c_1) = c - -- var cj_1 : iN($lsize(Inn_1)) - -- var cj_2 : iN($lsize(Inn_1)) - -- if ci* = $lanes_(Inn_2 X M_2, c_1) - -- if $concat_(iN($lsizenn1(Inn_1)), (cj_1 cj_2)*) = $extend__($lsizenn2(Inn_2), $lsizenn1(Inn_1), sx, ci)* - -- if c = $inv_lanes_(Inn_1 X M_1, $iadd_($lsizenn1(Inn_1), cj_1, cj_2)*) - -def $vextbinop__(Inn_1 X M_1, Inn_2 X M_2, EXTMUL half sx, c_1, c_2) = c - -- if ci_1* = $lanes_(Inn_2 X M_2, c_1)[$half(half, 0, M_1) : M_1] - -- if ci_2* = $lanes_(Inn_2 X M_2, c_2)[$half(half, 0, M_1) : M_1] - -- if c = $inv_lanes_(Inn_1 X M_1, $imul_($lsizenn1(Inn_1), $extend__($lsizenn2(Inn_2), $lsizenn1(Inn_1), sx, ci_1), $extend__($lsizenn2(Inn_2), $lsizenn1(Inn_1), sx, ci_2))*) - -def $vextbinop__(Inn_1 X M_1, Inn_2 X M_2, DOT S, c_1, c_2) = c - -- var cj_1 : iN($lsize(Inn_1)) - -- var cj_2 : iN($lsize(Inn_1)) - -- if ci_1* = $lanes_(Inn_2 X M_2, c_1) - -- if ci_2* = $lanes_(Inn_2 X M_2, c_2) - -- if $concat_(iN($lsizenn1(Inn_1)), (cj_1 cj_2)*) = $imul_($lsizenn1(Inn_1), $extend__($lsizenn2(Inn_2), $lsizenn1(Inn_1), S, ci_1), $extend__($lsizenn2(Inn_2), $lsizenn1(Inn_1), S, ci_2))* - -- if c = $inv_lanes_(Inn_1 X M_1, $iadd_($lsizenn1(Inn_1), cj_1, cj_2)*) +def $vextunop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTADD_PAIRWISE sx, c_1) = c + -- var cj_1 : iN($lsize(Jnn_2)) + -- var cj_2 : iN($lsize(Jnn_2)) + -- if ci* = $lanes_(Jnn_1 X M_1, c_1) + -- if $concat_(iN($lsizenn1(Jnn_2)), (cj_1 cj_2)*) = $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), sx, ci)* + -- if c = $inv_lanes_(Jnn_2 X M_2, $iadd_($lsizenn2(Jnn_2), cj_1, cj_2)*) + +def $vextbinop__(Jnn_1 X M_1, Jnn_2 X M_2, EXTMUL half sx, c_1, c_2) = c + -- if ci_1* = $lanes_(Jnn_1 X M_1, c_1)[$half(half, 0, M_2) : M_2] + -- if ci_2* = $lanes_(Jnn_1 X M_1, c_2)[$half(half, 0, M_2) : M_2] + -- if c = $inv_lanes_(Jnn_2 X M_2, $imul_($lsizenn2(Jnn_2), $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), sx, ci_1), $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), sx, ci_2))*) + +def $vextbinop__(Jnn_1 X M_1, Jnn_2 X M_2, DOT S, c_1, c_2) = c + -- var cj_1 : iN($lsize(Jnn_2)) + -- var cj_2 : iN($lsize(Jnn_2)) + -- if ci_1* = $lanes_(Jnn_1 X M_1, c_1) + -- if ci_2* = $lanes_(Jnn_1 X M_1, c_2) + -- if $concat_(iN($lsizenn2(Jnn_2)), (cj_1 cj_2)*) = $imul_($lsizenn2(Jnn_2), $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), S, ci_1), $extend__($lsizenn1(Jnn_1), $lsizenn2(Jnn_2), S, ci_2))* + -- if c = $inv_lanes_(Jnn_2 X M_2, $iadd_($lsizenn2(Jnn_2), cj_1, cj_2)*) def $vshiftop_(ishape, vshiftop_(ishape), lane_($lanetype(ishape)), u32) : lane_($lanetype(ishape)) hint(show %2#_%1#(%3, %4)) -def $vshiftop_(Jnn X M, SHL, lane, n) = $ishl_($lsizenn(Jnn), lane, n) -def $vshiftop_(Jnn X M, SHR sx, lane, n) = $ishr_($lsizenn(Jnn), sx, lane, n) +def $vshiftop_(Jnn X M, SHL, lane, n) = $ishl_($lsizenn(Jnn), lane, $(n \ $lsizenn(Jnn))) +def $vshiftop_(Jnn X M, SHR sx, lane, n) = $ishr_($lsizenn(Jnn), sx, lane, $(n \ $lsizenn(Jnn))) diff --git a/specification/wasm-2.0/6-typing.spectec b/specification/wasm-2.0/6-typing.spectec index e49a37987c..c8a1aa7f06 100644 --- a/specification/wasm-2.0/6-typing.spectec +++ b/specification/wasm-2.0/6-typing.spectec @@ -101,7 +101,6 @@ rule Limits_sub/eps: |- `[n_1 .. eps] <: `[n_2 .. eps] -- if n_1 >= n_2 - rule Functype_sub: |- ft <: ft @@ -276,13 +275,7 @@ rule Instr_ok/testop: rule Instr_ok/relop: C |- RELOP nt relop_nt : nt nt -> I32 - -;; TODO: move side conditions to syntax -rule Instr_ok/cvtop-reinterpret: - C |- CVTOP nt_1 nt_2 REINTERPRET : nt_2 -> nt_1 - -- if $size(nt_1) = $size(nt_2) - -rule Instr_ok/cvtop-convert: +rule Instr_ok/cvtop: C |- CVTOP nt_1 nt_2 cvtop : nt_2 -> nt_1 diff --git a/specification/wasm-2.0/8-reduction.spectec b/specification/wasm-2.0/8-reduction.spectec index 19ec11340a..5e4d91acc2 100644 --- a/specification/wasm-2.0/8-reduction.spectec +++ b/specification/wasm-2.0/8-reduction.spectec @@ -90,10 +90,10 @@ rule Step_pure/label-vals: ;; TODO: may want a label context instead of bubbling up rule Step_pure/br-zero: - (LABEL_ n `{instr'*} val'* val^n (BR 0) instr*) ~> val^n instr'* + (LABEL_ n `{instr'*} val'* val^n (BR 0) admininstr*) ~> val^n instr'* rule Step_pure/br-succ: - (LABEL_ n `{instr'*} val* (BR $(l+1)) instr*) ~> val* (BR l) + (LABEL_ n `{instr'*} val* (BR $(l+1)) admininstr*) ~> val* (BR l) rule Step_pure/br_if-true: @@ -139,17 +139,17 @@ rule Step_pure/frame-vals: (FRAME_ n `{f} val^n) ~> val^n rule Step_pure/return-frame: - (FRAME_ n `{f} val'* val^n RETURN instr*) ~> val^n + (FRAME_ n `{f} val'* val^n RETURN admininstr*) ~> val^n rule Step_pure/return-label: - (LABEL_ n `{instr'*} val* RETURN instr*) ~> val* RETURN + (LABEL_ n `{instr'*} val* RETURN admininstr*) ~> val* RETURN ;; Traps rule Step_pure/trap-vals: - val* TRAP instr* ~> TRAP - -- if val* =/= eps \/ instr* =/= eps + val* TRAP admininstr* ~> TRAP + -- if val* =/= eps \/ admininstr* =/= eps rule Step_pure/trap-label: (LABEL_ n `{instr'*} TRAP) ~> TRAP @@ -323,7 +323,7 @@ rule Step_pure/vsplat: rule Step_pure/vextract_lane-num: (VCONST V128 c_1) (VEXTRACT_LANE (nt X N) i) ~> (CONST nt c_2) - -- if c_2 = $lanes_(nt X N, c_1)[i] + -- if c_2 = $unpacknum_(nt, $lanes_(nt X N, c_1)[i]) ;; TODO : fshape rule Step_pure/vextract_lane-pack: @@ -337,12 +337,12 @@ rule Step_pure/vreplace_lane: rule Step_pure/vextunop: - (VCONST V128 c_1) (VEXTUNOP sh_1 sh_2 vextunop) ~> (VCONST V128 c) + (VCONST V128 c_1) (VEXTUNOP sh_2 sh_1 vextunop) ~> (VCONST V128 c) -- if $vextunop__(sh_1, sh_2, vextunop, c_1) = c rule Step_pure/vextbinop: - (VCONST V128 c_1) (VCONST V128 c_2) (VEXTBINOP sh_1 sh_2 vextbinop) ~> (VCONST V128 c) + (VCONST V128 c_1) (VCONST V128 c_2) (VEXTBINOP sh_2 sh_1 vextbinop) ~> (VCONST V128 c) -- if $vextbinop__(sh_1, sh_2, vextbinop, c_1, c_2) = c @@ -355,26 +355,9 @@ rule Step_pure/vnarrow: -- if c = $inv_lanes_(Jnn_2 X N_2, cj_1* cj_2*) -rule Step_pure/vcvtop-full: - (VCONST V128 c_1) (VCVTOP (Lnn_2 X M) (Lnn_1 X M) vcvtop) ~> (VCONST V128 c) - -- if $halfop(vcvtop) = eps /\ $zeroop(vcvtop) = eps - -- if ci* = $lanes_(Lnn_1 X M, c_1) - -- if cj** = $setproduct_(lane_(Lnn_2), $vcvtop__(Lnn_1 X M, Lnn_2 X M, vcvtop, ci)*) - -- if c <- $inv_lanes_(Lnn_2 X M, cj*)* - -rule Step_pure/vcvtop-half: - (VCONST V128 c_1) (VCVTOP (Lnn_2 X M_2) (Lnn_1 X M_1) vcvtop) ~> (VCONST V128 c) - -- if $halfop(vcvtop) = half - -- if ci* = $lanes_(Lnn_1 X M_1, c_1)[$half(half, 0, M_2) : M_2] - -- if cj** = $setproduct_(lane_(Lnn_2), $vcvtop__(Lnn_1 X M_1, Lnn_2 X M_2, vcvtop, ci)*) - -- if c <- $inv_lanes_(Lnn_2 X M_2, cj*)* - -rule Step_pure/vcvtop-zero: - (VCONST V128 c_1) (VCVTOP (nt_2 X M_2) (nt_1 X M_1) vcvtop) ~> (VCONST V128 c) - -- if $zeroop(vcvtop) = ZERO - -- if ci* = $lanes_(nt_1 X M_1, c_1) - -- if cj** = $setproduct_(lane_(nt_2), ($vcvtop__(nt_1 X M_1, nt_2 X M_2, vcvtop, ci)* ++ [$zero(nt_2)]^M_1)) - -- if c <- $inv_lanes_(nt_2 X M_2, cj*)* +rule Step_pure/vcvtop: + (VCONST V128 c_1) (VCVTOP sh_2 sh_1 vcvtop) ~> (VCONST V128 c) + -- if c = $vcvtop__(sh_1, sh_2, vcvtop, c_1) ;; Local instructions @@ -622,7 +605,7 @@ rule Step_read/memory.fill-zero: rule Step_read/memory.fill-succ: z; (CONST I32 i) val (CONST I32 n) (MEMORY.FILL) ~> (CONST I32 i) val (STORE I32 8 $memarg0) - (CONST I32 $(i+1)) val (CONST I32 $(n-1)) (MEMORY.FILL) + (CONST I32 $iadd_(32, i, 1)) val (CONST I32 $(n-1)) (MEMORY.FILL) -- otherwise @@ -638,7 +621,7 @@ rule Step_read/memory.copy-zero: rule Step_read/memory.copy-le: z; (CONST I32 j) (CONST I32 i) (CONST I32 n) (MEMORY.COPY) ~> (CONST I32 j) (CONST I32 i) (LOAD I32 (8 _ U) $memarg0) (STORE I32 8 $memarg0) - (CONST I32 $(j+1)) (CONST I32 $(i+1)) (CONST I32 $(n-1)) (MEMORY.COPY) + (CONST I32 $iadd_(32, j, 1)) (CONST I32 $iadd_(32, i, 1)) (CONST I32 $(n-1)) (MEMORY.COPY) -- otherwise -- if j <= i @@ -661,7 +644,7 @@ rule Step_read/memory.init-zero: rule Step_read/memory.init-succ: z; (CONST I32 j) (CONST I32 i) (CONST I32 n) (MEMORY.INIT x) ~> (CONST I32 j) (CONST I32 $data(z,x).BYTES[i]) (STORE I32 8 $memarg0) - (CONST I32 $(j+1)) (CONST I32 $(i+1)) (CONST I32 $(n-1)) (MEMORY.INIT x) + (CONST I32 $iadd_(32, j, 1)) (CONST I32 $iadd_(32, i, 1)) (CONST I32 $(n-1)) (MEMORY.INIT x) -- otherwise diff --git a/specification/wasm-2.0/9-module.spectec b/specification/wasm-2.0/9-module.spectec index f05cf7e177..8aaac79425 100644 --- a/specification/wasm-2.0/9-module.spectec +++ b/specification/wasm-2.0/9-module.spectec @@ -187,7 +187,7 @@ def $runelem(ELEM reftype expr* (ACTIVE x instr*), i) = instr* (CONST I32 0) (CONST I32 n) (TABLE.INIT x i) (ELEM.DROP i) -- if n = |expr*| -def $rundata(data, idx) : instr* +def $rundata(data, idx) : instr* hint(partial) def $rundata(DATA byte* (PASSIVE), i) = eps def $rundata(DATA byte* (ACTIVE 0 instr*), i) = instr* (CONST I32 0) (CONST I32 n) (MEMORY.INIT i) (DATA.DROP i) diff --git a/specification/wasm-2.0/B-soundness.spectec b/specification/wasm-2.0/B-soundness.spectec new file mode 100644 index 0000000000..f66388e53f --- /dev/null +++ b/specification/wasm-2.0/B-soundness.spectec @@ -0,0 +1,294 @@ +;; Contexts + +relation Context_ok: |- context : OK hint(macro "%context") + +rule Context_ok: + |- C : OK + -- if C = + { TYPES ft*, + FUNCS ft_2*, + GLOBALS gt*, + MEMS mt*, + TABLES tt*, + LOCALS lct*, + DATAS ok*, + ELEMS et*, + LABELS rt*, + RETURN rt'?, + } + -- (Functype_ok: |- ft : OK)* + -- (Globaltype_ok: |- gt : OK)* + -- (Memtype_ok: |- mt : OK)* + -- (Tabletype_ok: |- tt : OK)* + -- (Functype_ok: |- ft_2 : OK)* + + +;; Reference types + +relation Ref_ok: store |- ref : reftype + +rule Ref_ok/null: + s |- REF.NULL rt : rt + +rule Ref_ok/func: + s |- REF.FUNC_ADDR a : FUNCREF + -- Externaddr_ok: s |- FUNC a : FUNC ext + +rule Ref_ok/extern: + s |- REF.HOST_ADDR a : EXTERNREF + + +;; Value types + +relation Val_ok: store |- val : valtype + +rule Val_ok/numtype: + s |- CONST nt c_t : nt + +rule Val_ok/vectype: + s |- VCONST vt c_t : vt + +rule Val_ok/reftype: + s |- r : rt + -- Ref_ok : s |- r : rt + + +;; Result types + +relation Result_ok: store |- result : valtype* + +rule Result_ok/result: + s |- _VALS v* : t* + -- (Val_ok: s |- v : t)* + +rule Result_ok/trap: + s |- TRAP : t* + + +;; Administrative instructions + +syntax adminexpr = admininstr* + +relation Instr_ok2: store; context |- admininstr : functype + hint(prose "%3 is valid with %4") +relation Instrs_ok2: store; context |- admininstr* : functype + hint(prose "%3 is valid with %4") +relation Expr_ok2: store; context |- adminexpr : resulttype + hint(prose "%3 is valid with %4") + +rule Instr_ok2/plain: + s; C |- instr : t_1* -> t_2* + -- Instr_ok: C |- instr : t_1* -> t_2* + +rule Instr_ok2/label: + s; C |- LABEL_ n `{instr'*} admininstr* : eps -> t* + -- Instrs_ok2: s; C |- instr'* : t'^n -> t* + -- Instrs_ok2: s; {LABELS (t')^n} ++ C |- admininstr* : eps -> t* + +rule Instr_ok2/frame: + s; C |- FRAME_ n `{f} admininstr* : eps -> t^n + -- Frame_ok: s |- f : C' + -- Expr_ok2: s; C' ++ {RETURN t^n} |- admininstr* : t^n + +rule Instr_ok2/call_addr: + s; C |- CALL_ADDR funcaddr : t_1* -> t_2* + -- Externaddr_ok: s |- FUNC funcaddr: FUNC (t_1* -> t_2*) + +rule Instr_ok2/ref: + s; C |- ref : eps -> rt + -- Ref_ok: s |- ref : rt + +rule Instr_ok2/trap: + s; C |- TRAP : t_1* -> t_2* + + +rule Instrs_ok2/empty: + s; C |- eps : eps -> eps + +rule Instrs_ok2/instr: + s; C |- admininstr : t_1* -> t_2* + -- Instr_ok2: s; C |- admininstr : t_1* -> t_2* + +rule Instrs_ok2/seq: + s; C |- admininstr_1* admininstr_2* : t_1* -> t_3* + -- Instrs_ok2: s; C |- admininstr_1* : t_1* -> t_2* + -- Instrs_ok2: s; C |- admininstr_2* : t_2* -> t_3* + +rule Instrs_ok2/sub: + s; C |- admininstr* : t'_1* -> t'_2* + -- Instrs_ok2: s; C |- admininstr* : t_1* -> t_2* + -- Resulttype_sub: |- t'_1* <: t_1* + -- Resulttype_sub: |- t_2* <: t'_2* + +rule Instrs_ok2/frame: + s; C |- admininstr* : t* t_1* -> t* t_2* + -- Instrs_ok2: s; C |- admininstr* : t_1* -> t_2* + +rule Expr_ok2: + s; C |- admininstr* : t* + -- Instrs_ok2: s; C |- admininstr* : eps -> t* + + +;; Instances + +relation Globalinst_ok: store |- globalinst : globaltype +relation Meminst_ok: store |- meminst : memtype +relation Tableinst_ok: store |- tableinst : tabletype +relation Funcinst_ok: store |- funcinst : functype +relation Datainst_ok: store |- datainst : datatype +relation Eleminst_ok: store |- eleminst : elemtype +relation Exportinst_ok: store |- exportinst : OK + +rule Globalinst_ok: + s |- {TYPE mut t, VALUE val} : mut t + -- Globaltype_ok: |- mut t : OK + -- Val_ok: s |- val : t + +rule Meminst_ok: + s |- {TYPE `[n..m?] PAGE, BYTES b*} : `[n..m?] PAGE + -- Memtype_ok: |- `[n..m?] PAGE : OK + -- if |b*| = $(n * $($(64 * $Ki))) + +rule Tableinst_ok: + s |- {TYPE `[n..m?] rt , REFS ref*} : `[n..m?] rt + -- Tabletype_ok: |- `[n..m?] rt : OK + -- (Ref_ok : s |- ref : rt)* + -- if |ref*| = n + +rule Funcinst_ok: + s |- {TYPE ft, MODULE moduleinst, CODE func} : ft + -- Functype_ok: |- ft : OK + -- Moduleinst_ok: s |- moduleinst : C + -- Func_ok: C |- func : ft + +rule Datainst_ok: + s |- {BYTES b*} : OK + -- if |b*| < $(2^32) + +rule Eleminst_ok: + s |- {TYPE rt, REFS ref*} : rt + -- (Ref_ok: s |- ref : rt)* + -- if |ref*| < $(2^32) + +rule Exportinst_ok: + s |- {NAME nm, ADDR xa} : OK + -- Externaddr_ok: s |- xa : xt + + +;; Modules + +relation Moduleinst_ok: store |- moduleinst : context + +rule Moduleinst_ok: + s |- { TYPES functype*, + GLOBALS globaladdr*, + MEMS memaddr*, + TABLES tableaddr*, + FUNCS funcaddr*, + DATAS dataaddr*, + ELEMS elemaddr*, + EXPORTS exportinst* } : + { TYPES functype*, + GLOBALS globaltype*, + MEMS memtype*, + TABLES tabletype*, + FUNCS functype_F*, + DATAS datatype*, + ELEMS elemtype*, + } + -- (Functype_ok: |- functype : OK)* + -- (Externaddr_ok: s |- GLOBAL globaladdr : GLOBAL globaltype)* + -- (Externaddr_ok: s |- FUNC funcaddr : FUNC functype_F)* + -- (Externaddr_ok: s |- MEM memaddr : MEM memtype)* + -- (Externaddr_ok: s |- TABLE tableaddr : TABLE tabletype)* + -- (Exportinst_ok: s |- exportinst : OK)* + ---- + -- (Datainst_ok: s |- s.DATAS[dataaddr] : datatype)* + -- (Eleminst_ok: s |- s.ELEMS[elemaddr] : elemtype)* + ---- + -- if $disjoint_(name, (exportinst.NAME)*) + -- (if exportinst.ADDR <- (GLOBAL globaladdr)* (MEM memaddr)* (TABLE tableaddr)* (FUNC funcaddr)*)* + + +;; Stores + +relation Store_ok: |- store : OK + +rule Store_ok: + |- s : OK + -- (Globalinst_ok: s |- globalinst : globaltype)* + -- (Meminst_ok: s |- meminst : memtype)* + -- (Tableinst_ok: s |- tableinst : tabletype)* + -- (Funcinst_ok: s |- funcinst : functype)* + -- (Datainst_ok: s |- datainst : datatype)* + -- (Eleminst_ok: s |- eleminst : elemtype)* + ---- + -- if s = {GLOBALS globalinst*, MEMS meminst*, TABLES tableinst*, + FUNCS funcinst*, DATAS datainst*, ELEMS eleminst*} + + +;; Store extension + +relation Extend_globalinst: globalinst `<= globalinst +relation Extend_meminst: meminst `<= meminst +relation Extend_tableinst: tableinst `<= tableinst +relation Extend_funcinst: funcinst `<= funcinst +relation Extend_datainst: datainst `<= datainst +relation Extend_eleminst: eleminst `<= eleminst +relation Extend_store: store `<= store + +rule Extend_globalinst: + {TYPE mut t, VALUE val} `<= {TYPE mut t, VALUE val'} + -- if mut = MUT \/ val = val' + +rule Extend_meminst: + {TYPE `[n..m?] PAGE, BYTES b*} `<= {TYPE `[n'..m?] PAGE, BYTES b'*} + -- if n <= n' + -- if |b*| <= |b'*| + +rule Extend_tableinst: + {TYPE `[n..m?] rt, REFS ref*} `<= {TYPE `[n'..m?] rt, REFS ref'*} + -- if n <= n' + -- if |ref*| <= |ref'*| + +rule Extend_funcinst: + {TYPE ft, MODULE mm, CODE fc} `<= {TYPE ft, MODULE mm, CODE fc} + +rule Extend_datainst: + {BYTES b*} `<= {BYTES b'*} + -- if b* = b'* \/ b'* = eps + +rule Extend_eleminst: + {TYPE rt, REFS ref*} `<= {TYPE rt, REFS ref'*} + -- if ref* = ref'* \/ ref'* = eps + +rule Extend_store: + s `<= s' + -- (Extend_globalinst: s.GLOBALS[a] `<= s'.GLOBALS[a] )^(a<|s.GLOBALS|) + -- (Extend_meminst: s.MEMS[a] `<= s'.MEMS[a] )^(a<|s.MEMS|) + -- (Extend_tableinst: s.TABLES[a] `<= s'.TABLES[a] )^(a<|s.TABLES|) + -- (Extend_funcinst: s.FUNCS[a] `<= s'.FUNCS[a] )^(a<|s.FUNCS|) + -- (Extend_datainst: s.DATAS[a] `<= s'.DATAS[a] )^(a<|s.DATAS|) + -- (Extend_eleminst: s.ELEMS[a] `<= s'.ELEMS[a] )^(a<|s.ELEMS|) + + +;; Configurations + +relation Frame_ok: store |- frame : context +relation State_ok: |- state : context +relation Config_ok: |- config : resulttype + +rule Frame_ok: + s |- {LOCALS val*, MODULE moduleinst} : C ++ {LOCALS t*} + -- Moduleinst_ok: s |- moduleinst : C + -- (Val_ok: s |- val : t)* + +rule State_ok: + |- s; f : C + -- Store_ok: |- s : OK + -- Frame_ok: s |- f : C + +rule Config_ok: + |- s; f; admininstr* : t* + -- State_ok: |- s; f : C + -- Expr_ok2: s; C |- admininstr* : t* diff --git a/specification/wasm-3.0/1.2-syntax.types.spectec b/specification/wasm-3.0/1.2-syntax.types.spectec index 682d15f6b0..d996a0c0f7 100644 --- a/specification/wasm-3.0/1.2-syntax.types.spectec +++ b/specification/wasm-3.0/1.2-syntax.types.spectec @@ -398,7 +398,7 @@ def $subst_comptype((FUNC t_1* -> t_2*), tv*, tu*) = FUNC $subst_valtype(t_1, tv def $subst_subtype((SUB final? tu'* ct), tv*, tu*) = SUB final? $subst_typeuse(tu', tv*, tu*)* $subst_comptype(ct, tv*, tu*) -def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*) +def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*) hint(partial) def $minus_recs(eps, eps) = (eps, eps) def $minus_recs((REC n) tv*, tu_1 tu*) = $minus_recs(tv*, tu*) def $minus_recs((_IDX x) tv*, tu_1 tu*) = ((_IDX x) tv'*, tu_1 tu'*) diff --git a/specification/wasm-3.0/1.3-syntax.instructions.spectec b/specification/wasm-3.0/1.3-syntax.instructions.spectec index 356c930915..2a29f01eb2 100644 --- a/specification/wasm-3.0/1.3-syntax.instructions.spectec +++ b/specification/wasm-3.0/1.3-syntax.instructions.spectec @@ -10,10 +10,16 @@ syntax num_(Fnn) = fN($sizenn(Fnn)) syntax pack_(Pnn) = iN($psizenn(Pnn)) +;; TODO: HACK! lane_ should reuse num_ and pack_. +;; Original definition: +;; syntax lane_(lanetype) +;; syntax lane_(numtype) = num_(numtype) +;; syntax lane_(packtype) = pack_(packtype) +;; syntax lane_(Jnn) = iN($lsizenn(Jnn)) ;; HACK + syntax lane_(lanetype) -syntax lane_(numtype) = num_(numtype) -syntax lane_(packtype) = pack_(packtype) -syntax lane_(Jnn) = iN($lsizenn(Jnn)) ;; HACK +syntax lane_(Jnn) = iN($lsizenn(Jnn)) +syntax lane_(Fnn) = fN($sizenn(Fnn)) syntax vec_(Vnn) = vN($vsizenn(Vnn)) @@ -171,13 +177,13 @@ syntax vcvtop__(Jnn_1 X M_1, Fnn_2 X M_2) = | CONVERT half? sx hint(show CONVERT#_#%) hint(show CONVERT#_#%#_#%) -- if $sizenn2(Fnn_2) = $lsizenn1(Jnn_1) = `32 /\ half? = eps \/ $sizenn2(Fnn_2) = $(2 * $lsizenn1(Jnn_1)) /\ half? = LOW -syntax vcvtop__(Fnn_1 X M_1, Jnn_2 X M_2) = +syntax vcvtop__(Fnn_1 X M_1, Inn_2 X M_2) = | TRUNC_SAT sx zero? hint(show TRUNC_SAT#_#%) hint(show TRUNC_SAT#_#%#_#%) - -- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps - \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO + -- if $sizenn1(Fnn_1) = $lsizenn2(Inn_2) = `32 /\ zero? = eps + \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Inn_2)) /\ zero? = ZERO | RELAXED_TRUNC sx zero? hint(show RELAXED_TRUNC#_#%) hint(show RELAXED_TRUNC#_#%#_#%) - -- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps - \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO + -- if $sizenn1(Fnn_1) = $lsizenn2(Inn_2) = `32 /\ zero? = eps + \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Inn_2)) /\ zero? = ZERO syntax vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2) = | DEMOTE zero hint(show DEMOTE#_#ZERO) -- if $sizenn1(Fnn_1) = $(2 * $sizenn2(Fnn_2)) @@ -198,7 +204,7 @@ syntax storeop_(numtype) syntax storeop_(Inn) = sz -- if sz < $sizenn(Inn) syntax vloadop_(vectype) hint(macro "%" "L%") = - | SHAPE sz X M _ sx hint(show %1#X#%3#_#%5) hint(macro "%shape") -- if $(sz * M = $vsize(vectype)/2) + | SHAPE sz X M _ sx hint(show %1#X#%3#_#%5) hint(macro "%shape") -- if $(sz * M = $vsize(vectype)/2) /\ M > `1 | SPLAT sz hint(show %#_#SPLAT) | ZERO sz hint(show %#_#ZERO) -- if sz >= `32 diff --git a/specification/wasm-3.0/3.1-numerics.scalar.spectec b/specification/wasm-3.0/3.1-numerics.scalar.spectec index 3c66c4625e..d695feafd1 100644 --- a/specification/wasm-3.0/3.1-numerics.scalar.spectec +++ b/specification/wasm-3.0/3.1-numerics.scalar.spectec @@ -340,7 +340,8 @@ def $lpacknum_(lanetype, num_($lunpack(lanetype))) : lane_(lanetype) def $cpacknum_(storagetype, lit_($cunpack(storagetype))) : lit_(storagetype) hint(show $pack_(%,%)) hint(macro "packnum") -def $lpacknum_(numtype, c) = c +def $lpacknum_(Inn, c) = c +def $lpacknum_(Fnn, c) = c def $lpacknum_(packtype, c) = $wrap__($size($lunpack(packtype)), $psize(packtype), c) def $cpacknum_(consttype, c) = c @@ -352,7 +353,8 @@ def $lunpacknum_(lanetype, lane_(lanetype)) : num_($lunpack(lanetype)) def $cunpacknum_(storagetype, lit_(storagetype)) : lit_($cunpack(storagetype)) hint(show $unpack_(%,%)) hint(macro "unpacknum") -def $lunpacknum_(numtype, c) = c +def $lunpacknum_(Inn, c) = c +def $lunpacknum_(Fnn, c) = c def $lunpacknum_(packtype, c) = $extend__($psize(packtype), $size($lunpack(packtype)), U, c) def $cunpacknum_(consttype, c) = c diff --git a/specification/wasm-3.0/3.2-numerics.vector.spectec b/specification/wasm-3.0/3.2-numerics.vector.spectec index 451369fc10..56d717ddc4 100644 --- a/specification/wasm-3.0/3.2-numerics.vector.spectec +++ b/specification/wasm-3.0/3.2-numerics.vector.spectec @@ -19,16 +19,16 @@ def $inv_lanes_ hint(builtin) def $zeroop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : zero? def $zeroop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = eps def $zeroop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = eps -def $zeroop(Fnn_1 X M_1, Jnn_2 X M_2, TRUNC_SAT sx zero?) = zero? -def $zeroop(Fnn_1 X M_1, Jnn_2 X M_2, RELAXED_TRUNC sx zero?) = zero? +def $zeroop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = zero? +def $zeroop(Fnn_1 X M_1, Inn_2 X M_2, RELAXED_TRUNC sx zero?) = zero? def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = zero def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = eps def $halfop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : half? def $halfop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = half def $halfop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = half? -def $halfop(Fnn_1 X M_1, Jnn_2 X M_2, TRUNC_SAT sx zero?) = eps -def $halfop(Fnn_1 X M_1, Jnn_2 X M_2, RELAXED_TRUNC sx zero?) = eps +def $halfop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = eps +def $halfop(Fnn_1 X M_1, Inn_2 X M_2, RELAXED_TRUNC sx zero?) = eps def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = eps def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = LOW @@ -51,11 +51,11 @@ def $irelaxed_swizzle_lane_(N, c*, i) = $relaxed2($R_swizzle, iN(N), 0, c*[i \ | ;; Lanewise operations -def $ivunop_(shape, def $f_(N, iN(N)) : iN(N), vec_(V128)) : vec_(V128)* +def $ivunop_(shape, def $f_(N, iN(N)) : iN(N), vec_(V128)) : vec_(V128)* hint(partial) def $fvunop_(shape, def $f_(N, fN(N)) : fN(N)*, vec_(V128)) : vec_(V128)* -def $ivbinop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128)* -def $ivbinopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), vec_(V128)) : vec_(V128)* +def $ivbinop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128)* hint(partial) +def $ivbinopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), vec_(V128)) : vec_(V128)* hint(partial) def $ivbinopsxnd_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N)*, sx, vec_(V128), vec_(V128)) : vec_(V128)* def $fvbinop_(shape, def $f_(N, fN(N), fN(N)) : fN(N)*, vec_(V128), vec_(V128)) : vec_(V128)* @@ -66,12 +66,12 @@ def $ivrelop_(shape, def $f_(N, iN(N), iN(N)) : u32, vec_(V128), vec_(V128)) : v def $ivrelopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : u32, sx, vec_(V128), vec_(V128)) : vec_(V128) def $fvrelop_(shape, def $f_(N, fN(N), fN(N)) : u32, vec_(V128), vec_(V128)) : vec_(V128) -def $ivshiftop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), u32) : vec_(V128) -def $ivshiftopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), u32) : vec_(V128) +def $ivshiftop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), u32) : vec_(V128) hint(partial) +def $ivshiftopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), u32) : vec_(V128) hint(partial) def $ivbitmaskop_(shape, vec_(V128)) : u32 -def $ivswizzlop_(shape, def $f_(N, iN(N)*, iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128) -def $ivshufflop_(shape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) +def $ivswizzlop_(shape, def $f_(N, iN(N)*, iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128) hint(partial) +def $ivshufflop_(shape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) hint(partial) def $ivunop_(Jnn X M, def $f_, v_1) = $inv_lanes_(Jnn X M, c*) @@ -189,7 +189,7 @@ def $vbitmaskop_(ishape, vec_(V128)) : u32 hint(show VBITMASK#$_(%1,%2)) def $vswizzlop_(bshape, vswizzlop_(bshape), vec_(V128), vec_(V128)) : vec_(V128) hint(show %2#$_(%1,%3,%4)) -def $vshufflop_(bshape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) +def $vshufflop_(bshape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) hint(partial) hint(show VSHUFFLE#$_(%1,%2,%3,%4)) def $vnarrowop__(shape_1, shape_2, sx, vec_(V128), vec_(V128)) : vec_(V128) diff --git a/specification/wasm-3.0/4.3-execution.instructions.spectec b/specification/wasm-3.0/4.3-execution.instructions.spectec index 949f6b44e9..ac69f528ca 100644 --- a/specification/wasm-3.0/4.3-execution.instructions.spectec +++ b/specification/wasm-3.0/4.3-execution.instructions.spectec @@ -582,7 +582,7 @@ rule Step_read/memory.fill-zero: rule Step_read/memory.fill-succ: z; (CONST at i) val (CONST at n) (MEMORY.FILL x) ~> (CONST at i) val (STORE I32 `8 x $memarg0) - (CONST at $(i+1)) val (CONST at $(n-1)) (MEMORY.FILL x) + (CONST at $iadd_($size(at), i, 1)) val (CONST at $(n-1)) (MEMORY.FILL x) -- otherwise @@ -599,7 +599,7 @@ rule Step_read/memory.copy-zero: rule Step_read/memory.copy-le: z; (CONST at_1 i_1) (CONST at_2 i_2) (CONST at' n) (MEMORY.COPY x_1 x_2) ~> (CONST at_1 i_1) (CONST at_2 i_2) (LOAD I32 (`8 _ U) x_2 $memarg0) (STORE I32 `8 x_1 $memarg0) - (CONST at_1 $(i_1 + 1)) (CONST at_2 $(i_2 + 1)) (CONST at' $(n - 1)) (MEMORY.COPY x_1 x_2) + (CONST at_1 $iadd_($size(at_1), i_1, 1)) (CONST at_2 $iadd_($size(at_2), i_2, 1)) (CONST at' $(n - 1)) (MEMORY.COPY x_1 x_2) -- otherwise -- if i_1 <= i_2 @@ -623,7 +623,7 @@ rule Step_read/memory.init-zero: rule Step_read/memory.init-succ: z; (CONST at i) (CONST I32 j) (CONST I32 n) (MEMORY.INIT x y) ~> (CONST at i) (CONST I32 $data(z,y).BYTES[j]) (STORE I32 `8 x $memarg0) - (CONST at $(i+1)) (CONST I32 $(j+1)) (CONST I32 $(n-1)) (MEMORY.INIT x y) + (CONST at $iadd_($size(at), i, 1)) (CONST I32 $iadd_(32, j, 1)) (CONST I32 $(n-1)) (MEMORY.INIT x y) -- otherwise @@ -1071,7 +1071,7 @@ rule Step_pure/vsplat: rule Step_pure/vextract_lane-num: (VCONST V128 c_1) (VEXTRACT_LANE (nt X M) i) ~> (CONST nt c_2) - -- if c_2 = $lanes_(nt X M, c_1)[i] + -- if c_2 = $lunpacknum_(nt, $lanes_(nt X M, c_1)[i]) rule Step_pure/vextract_lane-pack: (VCONST V128 c_1) (VEXTRACT_LANE (pt X M) sx i) ~> (CONST I32 c_2) diff --git a/specification/wasm-3.0/7.1-soundness.configurations.spectec b/specification/wasm-3.0/7.1-soundness.configurations.spectec index c6d2bddf19..0f1384ec76 100644 --- a/specification/wasm-3.0/7.1-soundness.configurations.spectec +++ b/specification/wasm-3.0/7.1-soundness.configurations.spectec @@ -37,8 +37,7 @@ rule Instr_ok2/label: rule Instr_ok2/frame: s; C |- FRAME_ n `{f} instr* : eps -> t^n -- Frame_ok: s |- f : C' - -- if C'.RETURN = t^n - -- Expr_ok2: s; C' |- instr* : t^n + -- Expr_ok2: s; C' ++ {RETURN t^n} |- instr* : t^n -- Resulttype_ok: {} |- t^n : OK rule Instr_ok2/handler: @@ -126,11 +125,13 @@ rule Funcinst_ok: rule Datainst_ok: s |- {BYTES b*} : OK + -- if |b*| < $(2^32) rule Eleminst_ok: s |- {TYPE rt, REFS ref*} : rt -- Reftype_ok: {} |- rt : OK -- (Ref_ok: s |- ref : rt)* + -- if |ref*| < $(2^32) rule Exportinst_ok: s |- {NAME nm, ADDR xa} : OK diff --git a/specification/wasm-latest/1.2-syntax.types.spectec b/specification/wasm-latest/1.2-syntax.types.spectec index 682d15f6b0..d996a0c0f7 100644 --- a/specification/wasm-latest/1.2-syntax.types.spectec +++ b/specification/wasm-latest/1.2-syntax.types.spectec @@ -398,7 +398,7 @@ def $subst_comptype((FUNC t_1* -> t_2*), tv*, tu*) = FUNC $subst_valtype(t_1, tv def $subst_subtype((SUB final? tu'* ct), tv*, tu*) = SUB final? $subst_typeuse(tu', tv*, tu*)* $subst_comptype(ct, tv*, tu*) -def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*) +def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*) hint(partial) def $minus_recs(eps, eps) = (eps, eps) def $minus_recs((REC n) tv*, tu_1 tu*) = $minus_recs(tv*, tu*) def $minus_recs((_IDX x) tv*, tu_1 tu*) = ((_IDX x) tv'*, tu_1 tu'*) diff --git a/specification/wasm-latest/1.3-syntax.instructions.spectec b/specification/wasm-latest/1.3-syntax.instructions.spectec index 356c930915..2a29f01eb2 100644 --- a/specification/wasm-latest/1.3-syntax.instructions.spectec +++ b/specification/wasm-latest/1.3-syntax.instructions.spectec @@ -10,10 +10,16 @@ syntax num_(Fnn) = fN($sizenn(Fnn)) syntax pack_(Pnn) = iN($psizenn(Pnn)) +;; TODO: HACK! lane_ should reuse num_ and pack_. +;; Original definition: +;; syntax lane_(lanetype) +;; syntax lane_(numtype) = num_(numtype) +;; syntax lane_(packtype) = pack_(packtype) +;; syntax lane_(Jnn) = iN($lsizenn(Jnn)) ;; HACK + syntax lane_(lanetype) -syntax lane_(numtype) = num_(numtype) -syntax lane_(packtype) = pack_(packtype) -syntax lane_(Jnn) = iN($lsizenn(Jnn)) ;; HACK +syntax lane_(Jnn) = iN($lsizenn(Jnn)) +syntax lane_(Fnn) = fN($sizenn(Fnn)) syntax vec_(Vnn) = vN($vsizenn(Vnn)) @@ -171,13 +177,13 @@ syntax vcvtop__(Jnn_1 X M_1, Fnn_2 X M_2) = | CONVERT half? sx hint(show CONVERT#_#%) hint(show CONVERT#_#%#_#%) -- if $sizenn2(Fnn_2) = $lsizenn1(Jnn_1) = `32 /\ half? = eps \/ $sizenn2(Fnn_2) = $(2 * $lsizenn1(Jnn_1)) /\ half? = LOW -syntax vcvtop__(Fnn_1 X M_1, Jnn_2 X M_2) = +syntax vcvtop__(Fnn_1 X M_1, Inn_2 X M_2) = | TRUNC_SAT sx zero? hint(show TRUNC_SAT#_#%) hint(show TRUNC_SAT#_#%#_#%) - -- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps - \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO + -- if $sizenn1(Fnn_1) = $lsizenn2(Inn_2) = `32 /\ zero? = eps + \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Inn_2)) /\ zero? = ZERO | RELAXED_TRUNC sx zero? hint(show RELAXED_TRUNC#_#%) hint(show RELAXED_TRUNC#_#%#_#%) - -- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps - \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO + -- if $sizenn1(Fnn_1) = $lsizenn2(Inn_2) = `32 /\ zero? = eps + \/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Inn_2)) /\ zero? = ZERO syntax vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2) = | DEMOTE zero hint(show DEMOTE#_#ZERO) -- if $sizenn1(Fnn_1) = $(2 * $sizenn2(Fnn_2)) @@ -198,7 +204,7 @@ syntax storeop_(numtype) syntax storeop_(Inn) = sz -- if sz < $sizenn(Inn) syntax vloadop_(vectype) hint(macro "%" "L%") = - | SHAPE sz X M _ sx hint(show %1#X#%3#_#%5) hint(macro "%shape") -- if $(sz * M = $vsize(vectype)/2) + | SHAPE sz X M _ sx hint(show %1#X#%3#_#%5) hint(macro "%shape") -- if $(sz * M = $vsize(vectype)/2) /\ M > `1 | SPLAT sz hint(show %#_#SPLAT) | ZERO sz hint(show %#_#ZERO) -- if sz >= `32 diff --git a/specification/wasm-latest/3.1-numerics.scalar.spectec b/specification/wasm-latest/3.1-numerics.scalar.spectec index 3c66c4625e..d695feafd1 100644 --- a/specification/wasm-latest/3.1-numerics.scalar.spectec +++ b/specification/wasm-latest/3.1-numerics.scalar.spectec @@ -340,7 +340,8 @@ def $lpacknum_(lanetype, num_($lunpack(lanetype))) : lane_(lanetype) def $cpacknum_(storagetype, lit_($cunpack(storagetype))) : lit_(storagetype) hint(show $pack_(%,%)) hint(macro "packnum") -def $lpacknum_(numtype, c) = c +def $lpacknum_(Inn, c) = c +def $lpacknum_(Fnn, c) = c def $lpacknum_(packtype, c) = $wrap__($size($lunpack(packtype)), $psize(packtype), c) def $cpacknum_(consttype, c) = c @@ -352,7 +353,8 @@ def $lunpacknum_(lanetype, lane_(lanetype)) : num_($lunpack(lanetype)) def $cunpacknum_(storagetype, lit_(storagetype)) : lit_($cunpack(storagetype)) hint(show $unpack_(%,%)) hint(macro "unpacknum") -def $lunpacknum_(numtype, c) = c +def $lunpacknum_(Inn, c) = c +def $lunpacknum_(Fnn, c) = c def $lunpacknum_(packtype, c) = $extend__($psize(packtype), $size($lunpack(packtype)), U, c) def $cunpacknum_(consttype, c) = c diff --git a/specification/wasm-latest/3.2-numerics.vector.spectec b/specification/wasm-latest/3.2-numerics.vector.spectec index 451369fc10..56d717ddc4 100644 --- a/specification/wasm-latest/3.2-numerics.vector.spectec +++ b/specification/wasm-latest/3.2-numerics.vector.spectec @@ -19,16 +19,16 @@ def $inv_lanes_ hint(builtin) def $zeroop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : zero? def $zeroop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = eps def $zeroop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = eps -def $zeroop(Fnn_1 X M_1, Jnn_2 X M_2, TRUNC_SAT sx zero?) = zero? -def $zeroop(Fnn_1 X M_1, Jnn_2 X M_2, RELAXED_TRUNC sx zero?) = zero? +def $zeroop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = zero? +def $zeroop(Fnn_1 X M_1, Inn_2 X M_2, RELAXED_TRUNC sx zero?) = zero? def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = zero def $zeroop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = eps def $halfop(shape_1, shape_2, vcvtop__(shape_1, shape_2)) : half? def $halfop(Jnn_1 X M_1, Jnn_2 X M_2, EXTEND half sx) = half def $halfop(Jnn_1 X M_1, Fnn_2 X M_2, CONVERT half? sx) = half? -def $halfop(Fnn_1 X M_1, Jnn_2 X M_2, TRUNC_SAT sx zero?) = eps -def $halfop(Fnn_1 X M_1, Jnn_2 X M_2, RELAXED_TRUNC sx zero?) = eps +def $halfop(Fnn_1 X M_1, Inn_2 X M_2, TRUNC_SAT sx zero?) = eps +def $halfop(Fnn_1 X M_1, Inn_2 X M_2, RELAXED_TRUNC sx zero?) = eps def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, DEMOTE zero) = eps def $halfop(Fnn_1 X M_1, Fnn_2 X M_2, PROMOTE LOW) = LOW @@ -51,11 +51,11 @@ def $irelaxed_swizzle_lane_(N, c*, i) = $relaxed2($R_swizzle, iN(N), 0, c*[i \ | ;; Lanewise operations -def $ivunop_(shape, def $f_(N, iN(N)) : iN(N), vec_(V128)) : vec_(V128)* +def $ivunop_(shape, def $f_(N, iN(N)) : iN(N), vec_(V128)) : vec_(V128)* hint(partial) def $fvunop_(shape, def $f_(N, fN(N)) : fN(N)*, vec_(V128)) : vec_(V128)* -def $ivbinop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128)* -def $ivbinopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), vec_(V128)) : vec_(V128)* +def $ivbinop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128)* hint(partial) +def $ivbinopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), vec_(V128)) : vec_(V128)* hint(partial) def $ivbinopsxnd_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N)*, sx, vec_(V128), vec_(V128)) : vec_(V128)* def $fvbinop_(shape, def $f_(N, fN(N), fN(N)) : fN(N)*, vec_(V128), vec_(V128)) : vec_(V128)* @@ -66,12 +66,12 @@ def $ivrelop_(shape, def $f_(N, iN(N), iN(N)) : u32, vec_(V128), vec_(V128)) : v def $ivrelopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : u32, sx, vec_(V128), vec_(V128)) : vec_(V128) def $fvrelop_(shape, def $f_(N, fN(N), fN(N)) : u32, vec_(V128), vec_(V128)) : vec_(V128) -def $ivshiftop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), u32) : vec_(V128) -def $ivshiftopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), u32) : vec_(V128) +def $ivshiftop_(shape, def $f_(N, iN(N), iN(N)) : iN(N), vec_(V128), u32) : vec_(V128) hint(partial) +def $ivshiftopsx_(shape, def $f_(N, sx, iN(N), iN(N)) : iN(N), sx, vec_(V128), u32) : vec_(V128) hint(partial) def $ivbitmaskop_(shape, vec_(V128)) : u32 -def $ivswizzlop_(shape, def $f_(N, iN(N)*, iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128) -def $ivshufflop_(shape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) +def $ivswizzlop_(shape, def $f_(N, iN(N)*, iN(N)) : iN(N), vec_(V128), vec_(V128)) : vec_(V128) hint(partial) +def $ivshufflop_(shape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) hint(partial) def $ivunop_(Jnn X M, def $f_, v_1) = $inv_lanes_(Jnn X M, c*) @@ -189,7 +189,7 @@ def $vbitmaskop_(ishape, vec_(V128)) : u32 hint(show VBITMASK#$_(%1,%2)) def $vswizzlop_(bshape, vswizzlop_(bshape), vec_(V128), vec_(V128)) : vec_(V128) hint(show %2#$_(%1,%3,%4)) -def $vshufflop_(bshape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) +def $vshufflop_(bshape, laneidx*, vec_(V128), vec_(V128)) : vec_(V128) hint(partial) hint(show VSHUFFLE#$_(%1,%2,%3,%4)) def $vnarrowop__(shape_1, shape_2, sx, vec_(V128), vec_(V128)) : vec_(V128) diff --git a/specification/wasm-latest/4.3-execution.instructions.spectec b/specification/wasm-latest/4.3-execution.instructions.spectec index 949f6b44e9..ac69f528ca 100644 --- a/specification/wasm-latest/4.3-execution.instructions.spectec +++ b/specification/wasm-latest/4.3-execution.instructions.spectec @@ -582,7 +582,7 @@ rule Step_read/memory.fill-zero: rule Step_read/memory.fill-succ: z; (CONST at i) val (CONST at n) (MEMORY.FILL x) ~> (CONST at i) val (STORE I32 `8 x $memarg0) - (CONST at $(i+1)) val (CONST at $(n-1)) (MEMORY.FILL x) + (CONST at $iadd_($size(at), i, 1)) val (CONST at $(n-1)) (MEMORY.FILL x) -- otherwise @@ -599,7 +599,7 @@ rule Step_read/memory.copy-zero: rule Step_read/memory.copy-le: z; (CONST at_1 i_1) (CONST at_2 i_2) (CONST at' n) (MEMORY.COPY x_1 x_2) ~> (CONST at_1 i_1) (CONST at_2 i_2) (LOAD I32 (`8 _ U) x_2 $memarg0) (STORE I32 `8 x_1 $memarg0) - (CONST at_1 $(i_1 + 1)) (CONST at_2 $(i_2 + 1)) (CONST at' $(n - 1)) (MEMORY.COPY x_1 x_2) + (CONST at_1 $iadd_($size(at_1), i_1, 1)) (CONST at_2 $iadd_($size(at_2), i_2, 1)) (CONST at' $(n - 1)) (MEMORY.COPY x_1 x_2) -- otherwise -- if i_1 <= i_2 @@ -623,7 +623,7 @@ rule Step_read/memory.init-zero: rule Step_read/memory.init-succ: z; (CONST at i) (CONST I32 j) (CONST I32 n) (MEMORY.INIT x y) ~> (CONST at i) (CONST I32 $data(z,y).BYTES[j]) (STORE I32 `8 x $memarg0) - (CONST at $(i+1)) (CONST I32 $(j+1)) (CONST I32 $(n-1)) (MEMORY.INIT x y) + (CONST at $iadd_($size(at), i, 1)) (CONST I32 $iadd_(32, j, 1)) (CONST I32 $(n-1)) (MEMORY.INIT x y) -- otherwise @@ -1071,7 +1071,7 @@ rule Step_pure/vsplat: rule Step_pure/vextract_lane-num: (VCONST V128 c_1) (VEXTRACT_LANE (nt X M) i) ~> (CONST nt c_2) - -- if c_2 = $lanes_(nt X M, c_1)[i] + -- if c_2 = $lunpacknum_(nt, $lanes_(nt X M, c_1)[i]) rule Step_pure/vextract_lane-pack: (VCONST V128 c_1) (VEXTRACT_LANE (pt X M) sx i) ~> (CONST I32 c_2) diff --git a/specification/wasm-latest/7.1-soundness.configurations.spectec b/specification/wasm-latest/7.1-soundness.configurations.spectec index c6d2bddf19..0f1384ec76 100644 --- a/specification/wasm-latest/7.1-soundness.configurations.spectec +++ b/specification/wasm-latest/7.1-soundness.configurations.spectec @@ -37,8 +37,7 @@ rule Instr_ok2/label: rule Instr_ok2/frame: s; C |- FRAME_ n `{f} instr* : eps -> t^n -- Frame_ok: s |- f : C' - -- if C'.RETURN = t^n - -- Expr_ok2: s; C' |- instr* : t^n + -- Expr_ok2: s; C' ++ {RETURN t^n} |- instr* : t^n -- Resulttype_ok: {} |- t^n : OK rule Instr_ok2/handler: @@ -126,11 +125,13 @@ rule Funcinst_ok: rule Datainst_ok: s |- {BYTES b*} : OK + -- if |b*| < $(2^32) rule Eleminst_ok: s |- {TYPE rt, REFS ref*} : rt -- Reftype_ok: {} |- rt : OK -- (Ref_ok: s |- ref : rt)* + -- if |ref*| < $(2^32) rule Exportinst_ok: s |- {NAME nm, ADDR xa} : OK