i8vecmul.js (1468B)
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 let test = () => { 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 test(); 27 28 if (WasmHelpers.isSingleStepProfilingEnabled) { 29 const { 30 assertEqImpreciseStacks, 31 startProfiling, 32 endProfiling 33 } = WasmHelpers; 34 35 enableGeckoProfiling(); 36 startProfiling(); 37 test(); 38 assertEqImpreciseStacks(endProfiling(), ["", ">", "0,>", "", "0,>", ">", ""]); 39 disableGeckoProfiling(); 40 } 41 42 43 // Test bounds checking 44 { 45 assertErrorMessage(() => i8vecmul(PageSizeInBytes - 1, 0, 0, 2), WebAssembly.RuntimeError, /index out of bounds/); 46 assertErrorMessage(() => i8vecmul(0, PageSizeInBytes - 1, 0, 2), WebAssembly.RuntimeError, /index out of bounds/); 47 assertErrorMessage(() => i8vecmul(0, 0, PageSizeInBytes - 1, 2), WebAssembly.RuntimeError, /index out of bounds/); 48 } 49 50 51 // Test linking of intrinsics 52 { 53 let linkInstance = wasmEvalText(`(module 54 (import "" "i8vecmul" (func (param i32 i32 i32 i32))) 55 )`, {"": instance.exports}); 56 }