Skip to content

Commit

Permalink
Revert sign-extension changes
Browse files Browse the repository at this point in the history
Revert "Check for invalid extend operation (WebAssembly#64)"

This reverts commit eb056c8.

Revert "Implement extend instructions in interpreter (WebAssembly#60)"

This reverts commit 2f7592b.

Revert "Fix naming of `iextend` macro in math.def (WebAssembly#56)"

This reverts commit ae08b5e.

Revert "Add spec text for extend operators (WebAssembly#54)"

This reverts commit a4cb852.
  • Loading branch information
binji committed Feb 2, 2018
1 parent da0f5b0 commit 2bc8b74
Show file tree
Hide file tree
Showing 17 changed files with 3 additions and 141 deletions.
5 changes: 0 additions & 5 deletions document/core/appendix/index-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ Instruction Binary Opcode
:math:`\I64.\REINTERPRET\K{/}\F64` :math:`\hex{BD}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F32.\REINTERPRET\K{/}\I32` :math:`\hex{BE}` :math:`[\I32] \to [\F32]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F64.\REINTERPRET\K{/}\I64` :math:`\hex{BF}` :math:`[\I64] \to [\F64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\I32.\EXTEND\K{8\_s}` :math:`\hex{C0}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-unop>` :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`
:math:`\I32.\EXTEND\K{16\_s}` :math:`\hex{C1}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-unop>` :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`
:math:`\I64.\EXTEND\K{8\_s}` :math:`\hex{C2}` :math:`[\I64] \to [\I64]` :ref:`validation <valid-unop>` :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`
:math:`\I64.\EXTEND\K{16\_s}` :math:`\hex{C3}` :math:`[\I64] \to [\I64]` :ref:`validation <valid-unop>` :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`
:math:`\I64.\EXTEND\K{32\_s}` :math:`\hex{C4}` :math:`[\I64] \to [\I64]` :ref:`validation <valid-unop>` :ref:`execution <exec-unop>`, :ref:`operator <op-iextendn_s>`
:math:`\ATOMICWAKE~\memarg` :math:`\hex{FE}~\hex{00}` :math:`[\I32~\I64] \to [\I64]` :ref:`validation <valid-atomic-wake>`
:math:`\I32.\ATOMICWAIT~\memarg` :math:`\hex{FE}~\hex{01}` :math:`[\I32~\I32~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
:math:`\I64.\ATOMICWAIT~\memarg` :math:`\hex{FE}~\hex{02}` :math:`[\I32~\I64~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
Expand Down
11 changes: 0 additions & 11 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,6 @@ All other numeric instructions are plain opcodes without any immediates.
\end{array}
.. math::
\begin{array}{llclll}
\phantom{\production{instruction}} & \phantom{\Binstr} &\phantom{::=}& \phantom{\dots} && \phantom{thisshouldbeenough} \\[-2ex] &&|&
\hex{C0} &\Rightarrow& \I32.\EXTEND\K{8\_s} \\ &&|&
\hex{C1} &\Rightarrow& \I32.\EXTEND\K{16\_s} \\ &&|&
\hex{C2} &\Rightarrow& \I64.\EXTEND\K{8\_s} \\ &&|&
\hex{C3} &\Rightarrow& \I64.\EXTEND\K{16\_s} \\ &&|&
\hex{C4} &\Rightarrow& \I64.\EXTEND\K{32\_s} \\
\end{array}
.. index:: expression
pair: binary format; expression
single: expression; constant
Expand Down
13 changes: 0 additions & 13 deletions document/core/exec/numerics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -611,19 +611,6 @@ The integer result of predicates -- i.e., :ref:`tests <syntax-testop>` and :ref:
\end{array}
.. _op-iextendn_s:

:math:`\iextendns_N(i)`
.......................

* Return :math:`\extends_{M,N}(i)`.

.. math::
\begin{array}{lll@{\qquad}l}
\iextendns_N(i) &=& \extends_{M,N}(i) \\
\end{array}
.. _op-ixchg:

:math:`\ixchg_N(i_1, i_2)`
Expand Down
10 changes: 2 additions & 8 deletions document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ These operations closely match respective operations available in hardware.
\K{f}\X{nn}\K{.}\fbinop \\&&|&
\K{i}\X{nn}\K{.}\itestop \\&&|&
\K{i}\X{nn}\K{.}\irelop ~|~
\K{f}\X{nn}\K{.}\frelop ~|~ \\&&|&
\K{i}\X{nn}\K{.}\EXTEND\K{8\_s} ~|~
\K{i}\X{nn}\K{.}\EXTEND\K{16\_s} ~|~
\K{i64.}\EXTEND\K{32\_s} ~|~ \\&&|&
\K{f}\X{nn}\K{.}\frelop \\&&|&
\K{i32.}\WRAP\K{/i64} ~|~
\K{i64.}\EXTEND\K{\_}\sx/\K{i32} ~|~
\K{i}\X{nn}\K{.}\TRUNC\K{\_}\sx/\K{f}\X{mm} \\&&|&
Expand Down Expand Up @@ -154,10 +151,7 @@ Occasionally, it is convenient to group operators together according to the foll

.. math::
\begin{array}{llll}
\production{unary operator} & \unop &::=&
\iunop ~|~
\funop ~|~
\EXTEND{N}\K{\_s} \\
\production{unary operator} & \unop &::=& \iunop ~|~ \funop \\
\production{binary operator} & \binop &::=& \ibinop ~|~ \fbinop \\
\production{test operator} & \testop &::=& \itestop \\
\production{relational operator} & \relop &::=& \irelop ~|~ \frelop \\
Expand Down
10 changes: 0 additions & 10 deletions document/core/text/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -549,16 +549,6 @@ Numeric Instructions
\text{f64.reinterpret/i64} &\Rightarrow& \F64.\REINTERPRET\K{/}\I64 \\
\end{array}
.. math::
\begin{array}{llclll}
\phantom{\production{instruction}} & \phantom{\Tplaininstr_I} &\phantom{::=}& \phantom{thisisenough} && \phantom{thisshouldbeenough} \\[-2ex] &&|&
\text{i32.extend8\_s} &\Rightarrow& \I32.\EXTEND\K{8\_s} \\ &&|&
\text{i32.extend16\_s} &\Rightarrow& \I32.\EXTEND\K{16\_s} \\ &&|&
\text{i64.extend8\_s} &\Rightarrow& \I64.\EXTEND\K{8\_s} \\ &&|&
\text{i64.extend16\_s} &\Rightarrow& \I64.\EXTEND\K{16\_s} \\ &&|&
\text{i64.extend32\_s} &\Rightarrow& \I64.\EXTEND\K{32\_s} \\
\end{array}
.. index:: ! folded instruction, S-expression
.. _text-foldedinstr:
Expand Down
1 change: 0 additions & 1 deletion document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,6 @@
.. |iles| mathdef:: \xref{exec/numerics}{op-ile_s}{\F{ile\_s}}
.. |igeu| mathdef:: \xref{exec/numerics}{op-ige_u}{\F{ige\_u}}
.. |iges| mathdef:: \xref{exec/numerics}{op-ige_s}{\F{ige\_s}}
.. |iextendns| mathdef:: \xref{exec/numerics}{op-iextendn_s}{\F{iextend}M\F{\_s}}
.. |ixchg| mathdef:: \xref{exec/numerics}{op-ixchg}{\F{ixchg}}

.. |fadd| mathdef:: \xref{exec/numerics}{op-fadd}{\F{fadd}}
Expand Down
6 changes: 0 additions & 6 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,6 @@ let rec instr s =
| 0xbe -> f32_reinterpret_i32
| 0xbf -> f64_reinterpret_i64

| 0xc0 -> i32_extend8_s
| 0xc1 -> i32_extend16_s
| 0xc2 -> i64_extend8_s
| 0xc3 -> i64_extend16_s
| 0xc4 -> i64_extend32_s

| 0xfe -> atomic_instr s

| b -> illegal s pos b
Expand Down
6 changes: 0 additions & 6 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,10 @@ let encode m =
| Unary (I32 I32Op.Clz) -> op 0x67
| Unary (I32 I32Op.Ctz) -> op 0x68
| Unary (I32 I32Op.Popcnt) -> op 0x69
| Unary (I32 I32Op.Extend8S) -> op 0xc0
| Unary (I32 I32Op.Extend16S) -> op 0xc1
| Unary (I32 I32Op.Extend32S) -> assert false

| Unary (I64 I64Op.Clz) -> op 0x79
| Unary (I64 I64Op.Ctz) -> op 0x7a
| Unary (I64 I64Op.Popcnt) -> op 0x7b
| Unary (I64 I64Op.Extend8S) -> op 0xc2
| Unary (I64 I64Op.Extend16S) -> op 0xc3
| Unary (I64 I64Op.Extend32S) -> op 0xc4

| Unary (F32 F32Op.Abs) -> op 0x8b
| Unary (F32 F32Op.Neg) -> op 0x8c
Expand Down
3 changes: 0 additions & 3 deletions interpreter/exec/eval_numeric.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ struct
| Clz -> IXX.clz
| Ctz -> IXX.ctz
| Popcnt -> IXX.popcnt
| Extend8S -> IXX.extend8_s
| Extend16S -> IXX.extend16_s
| Extend32S -> IXX.extend32_s
in fun v -> to_value (f (of_value 1 v))

let binop op =
Expand Down
11 changes: 0 additions & 11 deletions interpreter/exec/int.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ sig
val clz : t -> t
val ctz : t -> t
val popcnt : t -> t
val extend8_s : t -> t
val extend16_s : t -> t
val extend32_s : t -> t
val eqz : t -> bool
val eq : t -> t -> bool
val ne : t -> t -> bool
Expand Down Expand Up @@ -204,14 +201,6 @@ struct
loop acc' (i - 1) (Rep.shift_right_logical n 1)
in Rep.of_int (loop 0 Rep.bitwidth x)

let extendn_s n x =
let shift = Rep.bitwidth - n in
Rep.shift_right (Rep.shift_left x shift) shift

let extend8_s x = extendn_s 8 x
let extend16_s x = extendn_s 16 x
let extend32_s x = extendn_s 32 x

let eqz x = x = Rep.zero

let eq x y = x = y
Expand Down
2 changes: 1 addition & 1 deletion interpreter/syntax/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open Types

module IntOp =
struct
type unop = Clz | Ctz | Popcnt | Extend8S | Extend16S | Extend32S
type unop = Clz | Ctz | Popcnt
type binop = Add | Sub | Mul | DivS | DivU | RemS | RemU
| And | Or | Xor | Shl | ShrS | ShrU | Rotl | Rotr
type testop = Eqz
Expand Down
6 changes: 0 additions & 6 deletions interpreter/syntax/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ let i64_reinterpret_f64 = Convert (I64 I64Op.ReinterpretFloat)
let f32_reinterpret_i32 = Convert (F32 F32Op.ReinterpretInt)
let f64_reinterpret_i64 = Convert (F64 F64Op.ReinterpretInt)

let i32_extend8_s = Unary (I32 I32Op.Extend8S)
let i32_extend16_s = Unary (I32 I32Op.Extend16S)
let i64_extend8_s = Unary (I64 I64Op.Extend8S)
let i64_extend16_s = Unary (I64 I64Op.Extend16S)
let i64_extend32_s = Unary (I64 I64Op.Extend32S)

let current_memory = CurrentMemory
let grow_memory = GrowMemory

3 changes: 0 additions & 3 deletions interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ struct
| Clz -> "clz"
| Ctz -> "ctz"
| Popcnt -> "popcnt"
| Extend8S -> "extend8_s"
| Extend16S -> "extend16_s"
| Extend32S -> "extend32_s"

let binop xx = function
| Add -> "add"
Expand Down
3 changes: 0 additions & 3 deletions interpreter/text/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ rule token = parse
| (ixx as t)".clz" { UNARY (intop t i32_clz i64_clz) }
| (ixx as t)".ctz" { UNARY (intop t i32_ctz i64_ctz) }
| (ixx as t)".popcnt" { UNARY (intop t i32_popcnt i64_popcnt) }
| (ixx as t)".extend8_s" { UNARY (intop t i32_extend8_s i64_extend8_s) }
| (ixx as t)".extend16_s" { UNARY (intop t i32_extend16_s i64_extend16_s) }
| "i64.extend32_s" { UNARY i64_extend32_s }
| (fxx as t)".neg" { UNARY (floatop t f32_neg f64_neg) }
| (fxx as t)".abs" { UNARY (floatop t f32_abs f64_abs) }
| (fxx as t)".sqrt" { UNARY (floatop t f32_sqrt f64_sqrt) }
Expand Down
6 changes: 0 additions & 6 deletions interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ let type_cvtop at = function

(* Expressions *)

let check_unop unop at =
match unop with
| Values.I32 I32Op.Extend32S -> error at "invalid unary operator"
| _ -> ()

let check_memop (c : context) (memop : 'a memop) (sh: sharability option)
get_sz at =
let MemoryType (_, shared) = memory c (0l @@ at) in
Expand Down Expand Up @@ -283,7 +278,6 @@ let rec check_instr (c : context) (e : instr) (s : infer_stack_type) : op_type =
[t; t] --> [I32Type]

| Unary unop ->
check_unop unop e.at;
let t = type_unop unop in
[t] --> [t]

Expand Down
18 changes: 0 additions & 18 deletions test/core/i32.wast
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
(func (export "clz") (param $x i32) (result i32) (i32.clz (get_local $x)))
(func (export "ctz") (param $x i32) (result i32) (i32.ctz (get_local $x)))
(func (export "popcnt") (param $x i32) (result i32) (i32.popcnt (get_local $x)))
(func (export "extend8_s") (param $x i32) (result i32) (i32.extend8_s (get_local $x)))
(func (export "extend16_s") (param $x i32) (result i32) (i32.extend16_s (get_local $x)))
(func (export "eqz") (param $x i32) (result i32) (i32.eqz (get_local $x)))
(func (export "eq") (param $x i32) (param $y i32) (result i32) (i32.eq (get_local $x) (get_local $y)))
(func (export "ne") (param $x i32) (param $y i32) (result i32) (i32.ne (get_local $x) (get_local $y)))
Expand Down Expand Up @@ -266,22 +264,6 @@
(assert_return (invoke "popcnt" (i32.const 0x55555555)) (i32.const 16))
(assert_return (invoke "popcnt" (i32.const 0xDEADBEEF)) (i32.const 24))

(assert_return (invoke "extend8_s" (i32.const 0)) (i32.const 0))
(assert_return (invoke "extend8_s" (i32.const 0x7f)) (i32.const 127))
(assert_return (invoke "extend8_s" (i32.const 0x80)) (i32.const -128))
(assert_return (invoke "extend8_s" (i32.const 0xff)) (i32.const -1))
(assert_return (invoke "extend8_s" (i32.const 0x012345_00)) (i32.const 0))
(assert_return (invoke "extend8_s" (i32.const 0xfedcba_80)) (i32.const -0x80))
(assert_return (invoke "extend8_s" (i32.const -1)) (i32.const -1))

(assert_return (invoke "extend16_s" (i32.const 0)) (i32.const 0))
(assert_return (invoke "extend16_s" (i32.const 0x7fff)) (i32.const 32767))
(assert_return (invoke "extend16_s" (i32.const 0x8000)) (i32.const -32768))
(assert_return (invoke "extend16_s" (i32.const 0xffff)) (i32.const -1))
(assert_return (invoke "extend16_s" (i32.const 0x0123_0000)) (i32.const 0))
(assert_return (invoke "extend16_s" (i32.const 0xfedc_8000)) (i32.const -0x8000))
(assert_return (invoke "extend16_s" (i32.const -1)) (i32.const -1))

(assert_return (invoke "eqz" (i32.const 0)) (i32.const 1))
(assert_return (invoke "eqz" (i32.const 1)) (i32.const 0))
(assert_return (invoke "eqz" (i32.const 0x80000000)) (i32.const 0))
Expand Down
30 changes: 0 additions & 30 deletions test/core/i64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
(func (export "clz") (param $x i64) (result i64) (i64.clz (get_local $x)))
(func (export "ctz") (param $x i64) (result i64) (i64.ctz (get_local $x)))
(func (export "popcnt") (param $x i64) (result i64) (i64.popcnt (get_local $x)))
(func (export "extend8_s") (param $x i64) (result i64) (i64.extend8_s (get_local $x)))
(func (export "extend16_s") (param $x i64) (result i64) (i64.extend16_s (get_local $x)))
(func (export "extend32_s") (param $x i64) (result i64) (i64.extend32_s (get_local $x)))
(func (export "eqz") (param $x i64) (result i32) (i64.eqz (get_local $x)))
(func (export "eq") (param $x i64) (param $y i64) (result i32) (i64.eq (get_local $x) (get_local $y)))
(func (export "ne") (param $x i64) (param $y i64) (result i32) (i64.ne (get_local $x) (get_local $y)))
Expand Down Expand Up @@ -267,33 +264,6 @@
(assert_return (invoke "popcnt" (i64.const 0x99999999AAAAAAAA)) (i64.const 32))
(assert_return (invoke "popcnt" (i64.const 0xDEADBEEFDEADBEEF)) (i64.const 48))

(assert_return (invoke "extend8_s" (i64.const 0)) (i64.const 0))
(assert_return (invoke "extend8_s" (i64.const 0x7f)) (i64.const 127))
(assert_return (invoke "extend8_s" (i64.const 0x80)) (i64.const -128))
(assert_return (invoke "extend8_s" (i64.const 0xff)) (i64.const -1))
(assert_return (invoke "extend8_s" (i64.const 0x01234567_89abcd_00)) (i64.const 0))
(assert_return (invoke "extend8_s" (i64.const 0xfedcba98_765432_80)) (i64.const -0x80))
(assert_return (invoke "extend8_s" (i64.const -1)) (i64.const -1))

(assert_return (invoke "extend16_s" (i64.const 0)) (i64.const 0))
(assert_return (invoke "extend16_s" (i64.const 0x7fff)) (i64.const 32767))
(assert_return (invoke "extend16_s" (i64.const 0x8000)) (i64.const -32768))
(assert_return (invoke "extend16_s" (i64.const 0xffff)) (i64.const -1))
(assert_return (invoke "extend16_s" (i64.const 0x12345678_9abc_0000)) (i64.const 0))
(assert_return (invoke "extend16_s" (i64.const 0xfedcba98_7654_8000)) (i64.const -0x8000))
(assert_return (invoke "extend16_s" (i64.const -1)) (i64.const -1))

(assert_return (invoke "extend32_s" (i64.const 0)) (i64.const 0))
(assert_return (invoke "extend32_s" (i64.const 0x7fff)) (i64.const 32767))
(assert_return (invoke "extend32_s" (i64.const 0x8000)) (i64.const 32768))
(assert_return (invoke "extend32_s" (i64.const 0xffff)) (i64.const 65535))
(assert_return (invoke "extend32_s" (i64.const 0x7fffffff)) (i64.const 0x7fffffff))
(assert_return (invoke "extend32_s" (i64.const 0x80000000)) (i64.const -0x80000000))
(assert_return (invoke "extend32_s" (i64.const 0xffffffff)) (i64.const -1))
(assert_return (invoke "extend32_s" (i64.const 0x01234567_00000000)) (i64.const 0))
(assert_return (invoke "extend32_s" (i64.const 0xfedcba98_80000000)) (i64.const -0x80000000))
(assert_return (invoke "extend32_s" (i64.const -1)) (i64.const -1))

(assert_return (invoke "eqz" (i64.const 0)) (i32.const 1))
(assert_return (invoke "eqz" (i64.const 1)) (i32.const 0))
(assert_return (invoke "eqz" (i64.const 0x8000000000000000)) (i32.const 0))
Expand Down

0 comments on commit 2bc8b74

Please # to comment.