Debian Codegraph @

js/src/jit-test/tests/wasm/builtin-modules/i8vecmul.js

raw
1 let memory = new WebAssembly.Memory({initial: 1});
2 let bytes = new Uint8Array(memory.buffer);
3
4 let module = wasmBuiltinI8VecMul();
5 let instance = new WebAssembly.Instance(module, {
6 "": {"memory": memory}
7 });
8 let {i8vecmul} = instance.exports;
9
10 // Test basic vector pairwise product
11 {
12 // [0, 1, 2, 3] . [0, 2, 4, 6] = [0, 2, 8, 18]
13 for (let i = 0; i < 4; i++) {
14 bytes[i] = i;
15 bytes[4 + i] = i * 2;
16 }
17 i8vecmul(
18 /* dest */ 8,
19 /* src1 */ 0,
20 /* src2 */ 4,
21 /* len */ 4);
22 for (let i = 0; i < 4; i++) {
23 assertEq(bytes[8 + i], i * i * 2);
24 }
25 }
26
27 // Test bounds checking
28 {
29 assertErrorMessage(() => i8vecmul(PageSizeInBytes - 1, 0, 0, 2), WebAssembly.RuntimeError, /index out of bounds/);
30 assertErrorMessage(() => i8vecmul(0, PageSizeInBytes - 1, 0, 2), WebAssembly.RuntimeError, /index out of bounds/);
31 assertErrorMessage(() => i8vecmul(0, 0, PageSizeInBytes - 1, 2), WebAssembly.RuntimeError, /index out of bounds/);
32 }
33
34 // Test linking of intrinsics
35 {
36 let linkInstance = wasmEvalText(`(module
37 (import "" "i8vecmul" (func (param i32 i32 i32 i32)))
38 )`, {"": instance.exports});
39 }