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

Commit a09a028

Browse files
authored
Merge pull request #7 from WebAssembly/tweaks
A few tweaks
2 parents 8ba81a2 + 6423534 commit a09a028

File tree

12 files changed

+50
-63
lines changed

12 files changed

+50
-63
lines changed

document/core/appendix/index-instructions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ Instruction Binary Opcode Type
199199
:math:`\I64.\REINTERPRET\K{\_}\F64` :math:`\hex{BD}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
200200
:math:`\F32.\REINTERPRET\K{\_}\I32` :math:`\hex{BE}` :math:`[\I32] \to [\F32]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
201201
:math:`\F64.\REINTERPRET\K{\_}\I64` :math:`\hex{BF}` :math:`[\I64] \to [\F64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
202-
: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>`
203-
: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>`
204-
: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>`
205-
: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>`
206-
: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>`
202+
: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>`
203+
: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>`
204+
: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>`
205+
: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>`
206+
: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>`
207207

208208
====================================== ================ ========================================== ======================================== ===============================================================

interpreter/binary/encode.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ let encode m =
130130
open Source
131131
open Ast
132132
open Values
133-
open Memory
134133

135134
let op n = u8 n
136135
let end_ () = op 0x0b
@@ -260,16 +259,16 @@ let encode m =
260259
| Unary (I32 I32Op.Clz) -> op 0x67
261260
| Unary (I32 I32Op.Ctz) -> op 0x68
262261
| Unary (I32 I32Op.Popcnt) -> op 0x69
263-
| Unary (I32 I32Op.Extend8S) -> op 0xc0
264-
| Unary (I32 I32Op.Extend16S) -> op 0xc1
265-
| Unary (I32 I32Op.Extend32S) -> assert false
262+
| Unary (I32 (I32Op.ExtendS Pack8)) -> op 0xc0
263+
| Unary (I32 (I32Op.ExtendS Pack16)) -> op 0xc1
264+
| Unary (I32 (I32Op.ExtendS Pack32)) -> assert false
266265

267266
| Unary (I64 I64Op.Clz) -> op 0x79
268267
| Unary (I64 I64Op.Ctz) -> op 0x7a
269268
| Unary (I64 I64Op.Popcnt) -> op 0x7b
270-
| Unary (I64 I64Op.Extend8S) -> op 0xc2
271-
| Unary (I64 I64Op.Extend16S) -> op 0xc3
272-
| Unary (I64 I64Op.Extend32S) -> op 0xc4
269+
| Unary (I64 (I64Op.ExtendS Pack8)) -> op 0xc2
270+
| Unary (I64 (I64Op.ExtendS Pack16)) -> op 0xc3
271+
| Unary (I64 (I64Op.ExtendS Pack32)) -> op 0xc4
273272

274273
| Unary (F32 F32Op.Abs) -> op 0x8b
275274
| Unary (F32 F32Op.Neg) -> op 0x8c

interpreter/exec/eval_numeric.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ struct
2424
| Clz -> IXX.clz
2525
| Ctz -> IXX.ctz
2626
| Popcnt -> IXX.popcnt
27-
| Extend8S -> IXX.extend8_s
28-
| Extend16S -> IXX.extend16_s
29-
| Extend32S -> IXX.extend32_s
27+
| ExtendS sz -> IXX.extend_s (8 * packed_size sz)
3028
in fun v -> to_value (f (of_value 1 v))
3129

3230
let binop op =

interpreter/exec/int.ml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ sig
5858
val clz : t -> t
5959
val ctz : t -> t
6060
val popcnt : t -> t
61-
val extend8_s : t -> t
62-
val extend16_s : t -> t
63-
val extend32_s : t -> t
61+
val extend_s : int -> t -> t
6462
val eqz : t -> bool
6563
val eq : t -> t -> bool
6664
val ne : t -> t -> bool
@@ -204,14 +202,10 @@ struct
204202
loop acc' (i - 1) (Rep.shift_right_logical n 1)
205203
in Rep.of_int (loop 0 Rep.bitwidth x)
206204

207-
let extendn_s n x =
205+
let extend_s n x =
208206
let shift = Rep.bitwidth - n in
209207
Rep.shift_right (Rep.shift_left x shift) shift
210208

211-
let extend8_s x = extendn_s 8 x
212-
let extend16_s x = extendn_s 16 x
213-
let extend32_s x = extendn_s 32 x
214-
215209
let eqz x = x = Rep.zero
216210

217211
let eq x y = x = y

interpreter/runtime/memory.ml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ type size = int32 (* number of pages *)
77
type address = int64
88
type offset = int32
99

10-
type pack_size = Pack8 | Pack16 | Pack32
11-
type extension = SX | ZX
12-
1310
type memory' = (int, int8_unsigned_elt, c_layout) Array1.t
1411
type memory = {mutable content : memory'; max : size option}
1512
type t = memory
@@ -22,11 +19,6 @@ exception OutOfMemory
2219

2320
let page_size = 0x10000L (* 64 KiB *)
2421

25-
let packed_size = function
26-
| Pack8 -> 1
27-
| Pack16 -> 2
28-
| Pack32 -> 4
29-
3022
let within_limits n = function
3123
| None -> true
3224
| Some max -> I32.le_u n max

interpreter/runtime/memory.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ type size = int32 (* number of pages *)
88
type address = int64
99
type offset = int32
1010

11-
type pack_size = Pack8 | Pack16 | Pack32
12-
type extension = SX | ZX
13-
1411
exception Type
1512
exception Bounds
1613
exception SizeOverflow
1714
exception SizeLimit
1815
exception OutOfMemory
1916

2017
val page_size : int64
21-
val packed_size : pack_size -> int
2218

2319
val alloc : memory_type -> memory (* raises SizeOverflow, OutOfMemory *)
2420
val type_of : memory -> memory_type

interpreter/syntax/ast.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open Types
2323

2424
module IntOp =
2525
struct
26-
type unop = Clz | Ctz | Popcnt | Extend8S | Extend16S | Extend32S
26+
type unop = Clz | Ctz | Popcnt | ExtendS of pack_size
2727
type binop = Add | Sub | Mul | DivS | DivU | RemS | RemU
2828
| And | Or | Xor | Shl | ShrS | ShrU | Rotl | Rotr
2929
type testop = Eqz
@@ -57,8 +57,8 @@ type cvtop = (I32Op.cvtop, I64Op.cvtop, F32Op.cvtop, F64Op.cvtop) Values.op
5757

5858
type 'a memop =
5959
{ty : value_type; align : int; offset : Memory.offset; sz : 'a option}
60-
type loadop = (Memory.pack_size * Memory.extension) memop
61-
type storeop = Memory.pack_size memop
60+
type loadop = (pack_size * extension) memop
61+
type storeop = pack_size memop
6262

6363

6464
(* Expressions *)

interpreter/syntax/operators.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
open Source
22
open Types
33
open Values
4-
open Memory
54
open Ast
65

76

@@ -199,11 +198,11 @@ let i64_reinterpret_f64 = Convert (I64 I64Op.ReinterpretFloat)
199198
let f32_reinterpret_i32 = Convert (F32 F32Op.ReinterpretInt)
200199
let f64_reinterpret_i64 = Convert (F64 F64Op.ReinterpretInt)
201200

202-
let i32_extend8_s = Unary (I32 I32Op.Extend8S)
203-
let i32_extend16_s = Unary (I32 I32Op.Extend16S)
204-
let i64_extend8_s = Unary (I64 I64Op.Extend8S)
205-
let i64_extend16_s = Unary (I64 I64Op.Extend16S)
206-
let i64_extend32_s = Unary (I64 I64Op.Extend32S)
201+
let i32_extend8_s = Unary (I32 (I32Op.ExtendS Pack8))
202+
let i32_extend16_s = Unary (I32 (I32Op.ExtendS Pack16))
203+
let i64_extend8_s = Unary (I64 (I64Op.ExtendS Pack8))
204+
let i64_extend16_s = Unary (I64 (I64Op.ExtendS Pack16))
205+
let i64_extend32_s = Unary (I64 (I64Op.ExtendS Pack32))
207206

208207
let memory_size = MemorySize
209208
let memory_grow = MemoryGrow

interpreter/syntax/types.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ type extern_type =
1616
| ExternMemoryType of memory_type
1717
| ExternGlobalType of global_type
1818

19+
type pack_size = Pack8 | Pack16 | Pack32
20+
type extension = SX | ZX
21+
1922

2023
(* Attributes *)
2124

2225
let size = function
2326
| I32Type | F32Type -> 4
2427
| I64Type | F64Type -> 8
2528

29+
let packed_size = function
30+
| Pack8 -> 1
31+
| Pack16 -> 2
32+
| Pack32 -> 4
33+
2634

2735
(* Subtyping *)
2836

interpreter/text/arrange.ml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ let global_type = function
7575
| GlobalType (t, Immutable) -> atom string_of_value_type t
7676
| GlobalType (t, Mutable) -> Node ("mut", [atom string_of_value_type t])
7777

78+
let pack_size = function
79+
| Pack8 -> "8"
80+
| Pack16 -> "16"
81+
| Pack32 -> "32"
82+
83+
let extension = function
84+
| SX -> "_s"
85+
| ZX -> "_u"
86+
7887

7988
(* Operators *)
8089

@@ -101,9 +110,7 @@ struct
101110
| Clz -> "clz"
102111
| Ctz -> "ctz"
103112
| Popcnt -> "popcnt"
104-
| Extend8S -> "extend8_s"
105-
| Extend16S -> "extend16_s"
106-
| Extend32S -> "extend32_s"
113+
| ExtendS sz -> "extend" ^ pack_size sz ^ "_s"
107114

108115
let binop xx = function
109116
| Add -> "add"
@@ -190,15 +197,6 @@ let testop = oper (IntOp.testop, FloatOp.testop)
190197
let relop = oper (IntOp.relop, FloatOp.relop)
191198
let cvtop = oper (IntOp.cvtop, FloatOp.cvtop)
192199

193-
let pack_size = function
194-
| Memory.Pack8 -> "8"
195-
| Memory.Pack16 -> "16"
196-
| Memory.Pack32 -> "32"
197-
198-
let extension = function
199-
| Memory.SX -> "_s"
200-
| Memory.ZX -> "_u"
201-
202200
let memop name {ty; align; offset; _} sz =
203201
value_type ty ^ "." ^ name ^
204202
(if offset = 0l then "" else " offset=" ^ nat32 offset) ^
@@ -208,12 +206,12 @@ let loadop op =
208206
match op.sz with
209207
| None -> memop "load" op (size op.ty)
210208
| Some (sz, ext) ->
211-
memop ("load" ^ pack_size sz ^ extension ext) op (Memory.packed_size sz)
209+
memop ("load" ^ pack_size sz ^ extension ext) op (packed_size sz)
212210

213211
let storeop op =
214212
match op.sz with
215213
| None -> memop "store" op (size op.ty)
216-
| Some sz -> memop ("store" ^ pack_size sz) op (Memory.packed_size sz)
214+
| Some sz -> memop ("store" ^ pack_size sz) op (packed_size sz)
217215

218216

219217
(* Expressions *)

0 commit comments

Comments
 (0)