diff options
author | Alon Zakai <alonzakai@gmail.com> | 2019-04-22 09:28:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-22 09:28:23 -0700 |
commit | b99d668ead5c6a6a4891ec58b5a53e80ea9f5705 (patch) | |
tree | cd6ae2d7dfa5164a1b71f5445f5882a48c053a90 /test/wasm2js/f32.2asm.js | |
parent | db14d0477f2715e3071687f42b77d8712477d83e (diff) | |
download | binaryen-b99d668ead5c6a6a4891ec58b5a53e80ea9f5705.tar.gz binaryen-b99d668ead5c6a6a4891ec58b5a53e80ea9f5705.tar.bz2 binaryen-b99d668ead5c6a6a4891ec58b5a53e80ea9f5705.zip |
wasm2js: use scratch memory properly (#2033)
This replaces all uses of __tempMemory__, the old scratch space location, with calls to function imports for scratch memory access. This lets us then implement those in a way that does not use the same heap as main memory. This avoids possible bugs with scratch memory overwriting something, or just in general that it has observable side effects, which can confuse fuzzing etc.
The intrinsics are currently implemented in the glue. We could perhaps emit them inline instead (but that might limit asm.js optimizations, so I wanted to keep our options open for now - easy to change later).
Also fixes some places where we used 0 as the scratch space address.
Diffstat (limited to 'test/wasm2js/f32.2asm.js')
-rw-r--r-- | test/wasm2js/f32.2asm.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test/wasm2js/f32.2asm.js b/test/wasm2js/f32.2asm.js index 96d10e660..cd53439c3 100644 --- a/test/wasm2js/f32.2asm.js +++ b/test/wasm2js/f32.2asm.js @@ -1,4 +1,26 @@ + + var scratchBuffer = new ArrayBuffer(8); + var i32ScratchView = new Int32Array(scratchBuffer); + var f32ScratchView = new Float32Array(scratchBuffer); + var f64ScratchView = new Float64Array(scratchBuffer); + + function wasm2js_scratch_store_i32(index, value) { + i32ScratchView[index] = value; + } + + function wasm2js_scratch_load_f32() { + return f32ScratchView[0]; + } + + function wasm2js_scratch_store_f32(value) { + f32ScratchView[0] = value; + } + + function wasm2js_scratch_load_i32(index) { + return i32ScratchView[index]; + } + function asmFunc(global, env, buffer) { "almost asm"; var HEAP8 = new global.Int8Array(buffer); @@ -95,7 +117,7 @@ function asmFunc(global, env, buffer) { function $13(x, y) { x = Math_fround(x); y = Math_fround(y); - return Math_fround((HEAP32[0] = (HEAPF32[0] = x, HEAP32[0] | 0) & 2147483647 | 0 | ((HEAPF32[0] = y, HEAP32[0] | 0) & 2147483648 | 0) | 0, HEAPF32[0])); + return Math_fround((wasm2js_scratch_store_i32(0, (wasm2js_scratch_store_f32(x), wasm2js_scratch_load_i32(0)) & 2147483647 | 0 | ((wasm2js_scratch_store_f32(y), wasm2js_scratch_load_i32(0)) & 2147483648 | 0) | 0), wasm2js_scratch_load_f32())); } function legalstub$0($0_1, $1_1) { |