Skip to content

Commit 1f4297e

Browse files
authored
Merge upstream bulk instructions proposal (WebAssembly#132)
2 parents 44b626b + 33da5b9 commit 1f4297e

File tree

10 files changed

+271
-13
lines changed

10 files changed

+271
-13
lines changed

document/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ You will also need `npm` and `yarn` for all the LaTeX goodness. `npm` might alre
8888

8989
```
9090
npm install -g yarn
91-
cd document/core
91+
cd document
9292
make -C core bikeshed
9393
```
9494

document/core/appendix/gen-index-instructions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat
319319
Instruction(r'\I32.\TRUNC\K{\_sat\_}\F64\K{\_u}', r'\hex{FC}~\hex{03}', r'[\F64] \to [\I32]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
320320
Instruction(r'\I64.\TRUNC\K{\_sat\_}\F32\K{\_s}', r'\hex{FC}~\hex{04}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
321321
Instruction(r'\I64.\TRUNC\K{\_sat\_}\F32\K{\_u}', r'\hex{FC}~\hex{05}', r'[\F32] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
322-
Instruction(r'\I64.\TRUNC\K{\_sat}\_\F64\K{\_s}', r'\hex{FC}~\hex{06}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
322+
Instruction(r'\I64.\TRUNC\K{\_sat\_}\F64\K{\_s}', r'\hex{FC}~\hex{06}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_s'),
323323
Instruction(r'\I64.\TRUNC\K{\_sat\_}\F64\K{\_u}', r'\hex{FC}~\hex{07}', r'[\F64] \to [\I64]', r'valid-cvtop', r'exec-cvtop', r'op-trunc_sat_u'),
324324
Instruction(r'\MEMORYINIT', r'\hex{FC}~\hex{08}', r'[\I32~\I32~\I32] \to []', r'valid-memory.init', r'exec-memory.init'),
325325
Instruction(r'\DATADROP', r'\hex{FC}~\hex{09}', r'[] \to []', r'valid-data.drop', r'exec-data.drop'),

document/core/appendix/index-instructions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Instruction Binary Opcode Type
267267
:math:`\I32.\TRUNC\K{\_sat\_}\F64\K{\_u}` :math:`\hex{FC}~\hex{03}` :math:`[\F64] \to [\I32]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
268268
:math:`\I64.\TRUNC\K{\_sat\_}\F32\K{\_s}` :math:`\hex{FC}~\hex{04}` :math:`[\F32] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
269269
:math:`\I64.\TRUNC\K{\_sat\_}\F32\K{\_u}` :math:`\hex{FC}~\hex{05}` :math:`[\F32] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
270-
:math:`\I64.\TRUNC\K{\_sat}\_\F64\K{\_s}` :math:`\hex{FC}~\hex{06}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
270+
:math:`\I64.\TRUNC\K{\_sat\_}\F64\K{\_s}` :math:`\hex{FC}~\hex{06}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_s>`
271271
:math:`\I64.\TRUNC\K{\_sat\_}\F64\K{\_u}` :math:`\hex{FC}~\hex{07}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-trunc_sat_u>`
272272
:math:`\MEMORYINIT` :math:`\hex{FC}~\hex{08}` :math:`[\I32~\I32~\I32] \to []` :ref:`validation <valid-memory.init>` :ref:`execution <exec-memory.init>`
273273
:math:`\DATADROP` :math:`\hex{FC}~\hex{09}` :math:`[] \to []` :ref:`validation <valid-data.drop>` :ref:`execution <exec-data.drop>`

document/web-api/index.bs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,27 @@ application/wasm
253253
<dt>Encoding Considerations:</dt>
254254
<dd>binary</dd>
255255
<dt>Security Considerations:</dt>
256-
<dd>See see WebAssembly Core Security Considerations<br/>
257-
https://www.w3.org/TR/wasm-core/#security-considerations%E2%91%A0</dd>
256+
<dd>
257+
<p>WebAssembly is a standard, a safe, portable, low-level code format. The
258+
security considerations associated with executing WebAssembly code are
259+
described in https://www.w3.org/TR/wasm-core/#security-considerations.</p>
260+
<p>The WebAssembly format includes no integrity or privacy protection. If
261+
such protection is needed it must be provided externally, e.g., through
262+
the use of HTTPS.</p>
263+
</dd>
258264
<dt>Interoperability Considerations:</dt>
259-
<dd>See see WebAssembly Core Conformance<br/>
265+
<dd>See WebAssembly Core Conformance<br/>
260266
https://www.w3.org/TR/wasm-core/#conformance</dd>
261267
<dt>Published specification:</dt>
262-
https://www.w3.org/TR/wasm-core-1/
268+
<dd>https://www.w3.org/TR/wasm-core-1/
263269
https://www.w3.org/TR/wasm-js-api-1/
264-
https://www.w3.org/TR/wasm-web-api-1/
270+
https://www.w3.org/TR/wasm-web-api-1/</dd>
265271
<dt>Application Usage:</dt>
266-
<dd>The application/wasm media type is already in use as the type used to describe WebAssembly files when sent over HTTP to be executed by browsers, which is a common scenario. Additionally, several WebAssembly runtimes that take advantage of the safety and portability while targeting efficient execution and compact representation.</dd>
272+
<dd>The application/wasm media type is intended for use as the type used to
273+
describe WebAssembly files when sent over HTTP to be executed by browsers,
274+
which is a common scenario. Additionally, the type is used by several
275+
WebAssembly runtimes that take advantage of the safety and portability
276+
while targeting efficient execution and compact representation.</dd>
267277
<dt>Fragment Identifier Considerations:</dt>
268278
<dd>None</dd>
269279
<dt>Restrictions on usage:</dt>

interpreter/exec/int.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct
199199

200200
let popcnt x =
201201
let rec loop acc i n =
202-
if n = Rep.zero then
202+
if i = 0 then
203203
acc
204204
else
205205
let acc' = if and_ n Rep.one = Rep.one then acc + 1 else acc in

test/core/binary.wast

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,23 @@
959959
"integer too large"
960960
)
961961

962+
;; Local number is unsigned 32 bit
963+
(assert_malformed
964+
(module binary
965+
"\00asm" "\01\00\00\00"
966+
"\01\04\01\60\00\00" ;; Type section
967+
"\03\02\01\00" ;; Function section
968+
"\0a\0c\01" ;; Code section
969+
970+
;; function 0
971+
"\0a\02"
972+
"\80\80\80\80\10\7f" ;; 0x100000000 i32
973+
"\02\7e" ;; 0x00000002 i64
974+
"\0b" ;; end
975+
)
976+
"integer too large"
977+
)
978+
962979
;; No more than 2^32-1 locals.
963980
(assert_malformed
964981
(module binary

test/core/data.wast

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
"\05\03\01" ;; memory section
304304
"\00\00" ;; memory 0
305305
"\0b\07\01" ;; data section
306-
"\02\01\41\00\0b" ;; data segment 0 for memory 1
306+
"\02\01\41\00\0b" ;; active data segment 0 for memory 1
307307
"\00" ;; empty vec(byte)
308308
)
309309
"unknown memory 1"
@@ -314,7 +314,7 @@
314314
(module binary
315315
"\00asm" "\01\00\00\00"
316316
"\0b\06\01" ;; data section
317-
"\00\41\00\0b" ;; data segment 0 for memory 0
317+
"\00\41\00\0b" ;; active data segment 0 for memory 0
318318
"\00" ;; empty vec(byte)
319319
)
320320
"unknown memory 0"
@@ -325,7 +325,7 @@
325325
(module binary
326326
"\00asm" "\01\00\00\00"
327327
"\0b\07\01" ;; data section
328-
"\02\01\41\00\0b" ;; data segment 0 for memory 1
328+
"\02\01\41\00\0b" ;; active data segment 0 for memory 1
329329
"\00" ;; empty vec(byte)
330330
)
331331
"unknown memory 1"
@@ -382,6 +382,40 @@
382382
"type mismatch"
383383
)
384384

385+
(assert_invalid
386+
(module
387+
(memory 1)
388+
(data (offset (;empty instruction sequence;)))
389+
)
390+
"type mismatch"
391+
)
392+
393+
(assert_invalid
394+
(module
395+
(memory 1)
396+
(data (offset (i32.const 0) (i32.const 0)))
397+
)
398+
"type mismatch"
399+
)
400+
401+
(assert_invalid
402+
(module
403+
(global (import "test" "global-i32") i32)
404+
(memory 1)
405+
(data (offset (global.get 0) (global.get 0)))
406+
)
407+
"type mismatch"
408+
)
409+
410+
(assert_invalid
411+
(module
412+
(global (import "test" "global-i32") i32)
413+
(memory 1)
414+
(data (offset (global.get 0) (i32.const 0)))
415+
)
416+
"type mismatch"
417+
)
418+
385419
(assert_invalid
386420
(module
387421
(memory 1)
@@ -419,3 +453,29 @@
419453
;; (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
420454
;; "constant expression required"
421455
;; )
456+
457+
(assert_invalid
458+
(module
459+
(memory 1)
460+
(data (global.get 0))
461+
)
462+
"unknown global 0"
463+
)
464+
465+
(assert_invalid
466+
(module
467+
(global (import "test" "global-i32") i32)
468+
(memory 1)
469+
(data (global.get 1))
470+
)
471+
"unknown global 1"
472+
)
473+
474+
(assert_invalid
475+
(module
476+
(global (import "test" "global-mut-i32") (mut i32))
477+
(memory 1)
478+
(data (global.get 0))
479+
)
480+
"constant expression required"
481+
)

test/core/elem.wast

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,41 @@
349349
"type mismatch"
350350
)
351351

352+
(assert_invalid
353+
(module
354+
(table 1 funcref)
355+
(elem (offset (;empty instruction sequence;)))
356+
)
357+
"type mismatch"
358+
)
359+
360+
(assert_invalid
361+
(module
362+
(table 1 funcref)
363+
(elem (offset (i32.const 0) (i32.const 0)))
364+
)
365+
"type mismatch"
366+
)
367+
368+
(assert_invalid
369+
(module
370+
(global (import "test" "global-i32") i32)
371+
(table 1 funcref)
372+
(elem (offset (global.get 0) (global.get 0)))
373+
)
374+
"type mismatch"
375+
)
376+
377+
(assert_invalid
378+
(module
379+
(global (import "test" "global-i32") i32)
380+
(table 1 funcref)
381+
(elem (offset (global.get 0) (i32.const 0)))
382+
)
383+
"type mismatch"
384+
)
385+
386+
352387
(assert_invalid
353388
(module
354389
(table 1 funcref)
@@ -387,6 +422,32 @@
387422
;; "constant expression required"
388423
;; )
389424

425+
(assert_invalid
426+
(module
427+
(table 1 funcref)
428+
(elem (global.get 0))
429+
)
430+
"unknown global 0"
431+
)
432+
433+
(assert_invalid
434+
(module
435+
(global (import "test" "global-i32") i32)
436+
(table 1 funcref)
437+
(elem (global.get 1))
438+
)
439+
"unknown global 1"
440+
)
441+
442+
(assert_invalid
443+
(module
444+
(global (import "test" "global-mut-i32") (mut i32))
445+
(table 1 funcref)
446+
(elem (global.get 0))
447+
)
448+
"constant expression required"
449+
)
450+
390451
;; Two elements target the same slot
391452

392453
(module

test/core/global.wast

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
"constant expression required"
285285
)
286286

287+
(assert_invalid
288+
(module (global i32 (i32.ctz (i32.const 0))))
289+
"constant expression required"
290+
)
291+
287292
(assert_invalid
288293
(module (global i32 (nop)))
289294
"constant expression required"
@@ -309,6 +314,16 @@
309314
"type mismatch"
310315
)
311316

317+
(assert_invalid
318+
(module (global (import "test" "global-i32") i32) (global i32 (global.get 0) (global.get 0)))
319+
"type mismatch"
320+
)
321+
322+
(assert_invalid
323+
(module (global (import "test" "global-i32") i32) (global i32 (i32.const 0) (global.get 0)))
324+
"type mismatch"
325+
)
326+
312327
(assert_invalid
313328
(module (global i32 (global.get 0)))
314329
"unknown global"
@@ -319,6 +334,16 @@
319334
"unknown global"
320335
)
321336

337+
(assert_invalid
338+
(module (global (import "test" "global-i32") i32) (global i32 (global.get 2)))
339+
"unknown global"
340+
)
341+
342+
(assert_invalid
343+
(module (global (import "test" "global-mut-i32") (mut i32)) (global i32 (global.get 0)))
344+
"constant expression required"
345+
)
346+
322347
(module
323348
(import "spectest" "global_i32" (global i32))
324349
)

0 commit comments

Comments
 (0)