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
//Compile the .WAT (WebAssembly text) file to a .WASM binary, put it alongside this .js file, and you're A for Away. | |
// | |
//Goodbye to problems working with Javascript's Number, and to the indeterminism of division, remainder and rounding ops across platforms. | |
//No more need for hefty libraries like BigNumber.js, decimal.js, big.js etc. Great libraries... before WebAssembly came along :) | |
// | |
//There is some overhead to crossing the WASM/JS barrier of course. But simplicity and native performance make this more than worthwhile. | |
//At worst, you can move all your hot logic to WebAssembly to eliminate repeated call-out costs, and in that way you can also avoid | |
//any further implicit conversions to JavaScript's Number class... at least until you are ready to render the results of your computation. | |
//Just be careful how you store the values you get back, or conversion back to JS Number is on the cards. I use Int32Array to store them. |
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
const systemWordSize = 8; //bytes | |
const strideLength = 1; //bytes | |
//...these functions can be optimised to take advantage of 4 or 8 byte reads / writes, depending on system word size. | |
//Utility functions | |
function padAndCalcMemberOffsets(type) | |
{ | |
let structSize = 0; | |
for (let memberName in type) |
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
//Ensure we have reproducible read / write sequence via pseudo-random index sequence. | |
export const MAX_RAND_INT = 4294967296; | |
export function splitmixUInt32(seed) | |
{ | |
return function() { | |
seed |= 0; | |
seed = seed + 0x9e3779b9 | 0; | |
let t = seed ^ seed >>> 16; | |
t = Math.imul(t, 0x21f0aaad); |
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
//Ensure we have reproducible read / write sequence via pseudo-random index sequence. | |
export const MAX_RAND_INT = 4294967296; | |
export function splitmixUInt32(seed) | |
{ | |
return function() { | |
seed |= 0; | |
seed = seed + 0x9e3779b9 | 0; | |
let t = seed ^ seed >>> 16; | |
t = Math.imul(t, 0x21f0aaad); |