forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1720514 - wasm: Add framework for intrinsics with basic i8vecmul.…
… r=jseward This commit implements a framework for creating 'intrinsics' which are natively implemented functions that are exposable as wasm functions that can be called or linked against. A simple 8-bit vector product for flexible vectors is implemented as a proof of concept. The basic API is: ``` let module = wasmIntrinsicI8VecMul(); // WebAssembly.Module let memory = new WebAssembly.Module({ initial: pageSize }); let instance = new WebAssembly.Instance(module, { "": { memory } }); instance.exports.i8vecmul(dest, src1, src2, len); ``` The implementation is mainly done through `CompileIntrisicModule` which manually builds a ModuleEnvironment with an imported memory, and a single exported function which is of the bytecode form: ``` (func (params ...) local.get 0 ... local.get n private_intrinsic_opcode ) ``` The private_intrinsic_opcode is implemented as an instance call. An additional heap base parameter is added which allows quick bounds checking, similar to Instance::memory32Copy. A followup will implement the intrinsic for the firefox translations project. Differential Revision: https://phabricator.services.mozilla.com/D119919
- Loading branch information
Showing
24 changed files
with
508 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|jit-test| test-also=--wasm-compiler=optimizing; include:wasm.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
let memory = new WebAssembly.Memory({initial: 1}); | ||
let bytes = new Uint8Array(memory.buffer); | ||
|
||
let module = wasmIntrinsicI8VecMul(); | ||
let instance = new WebAssembly.Instance(module, { | ||
"": {"memory": memory} | ||
}); | ||
let {i8vecmul} = instance.exports; | ||
|
||
// Test basic vector pairwise product | ||
{ | ||
// [0, 1, 2, 3] . [0, 2, 4, 6] = [0, 2, 8, 18] | ||
for (let i = 0; i < 4; i++) { | ||
bytes[i] = i; | ||
bytes[4 + i] = i * 2; | ||
} | ||
i8vecmul( | ||
/* dest */ 8, | ||
/* src1 */ 0, | ||
/* src2 */ 4, | ||
/* len */ 4); | ||
for (let i = 0; i < 4; i++) { | ||
assertEq(bytes[8 + i], i * i * 2); | ||
} | ||
} | ||
|
||
// Test bounds checking | ||
{ | ||
assertErrorMessage(() => i8vecmul(PageSizeInBytes - 1, 0, 0, 2), WebAssembly.RuntimeError, /index out of bounds/); | ||
assertErrorMessage(() => i8vecmul(0, PageSizeInBytes - 1, 0, 2), WebAssembly.RuntimeError, /index out of bounds/); | ||
assertErrorMessage(() => i8vecmul(0, 0, PageSizeInBytes - 1, 2), WebAssembly.RuntimeError, /index out of bounds/); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.