You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the output of asm2wasm, I find it just simply delete the imported variables statements, such as "var i = env.STACKTOP | 0; ". Without the support of imported variables, can this tool support all asm.js?
This is an issue that happens because WebAssembly does not have global variables. The idea is that people use locations in memory to replace them, but that requires interaction with the compiler, so it knows where it can place them.
For emscripten, we just reserve 8-1000 for such "mapped globals" as we call them, and we know that will be enough room.
I see. So before running WASM code, load_mapped_globals() should be called to copy imported variables to the correct locations and inside WASM, global variable access is interpreted to load/store of linear memory.
No, I also convert asm.js generated by EmScripten to v8-native binary format. Since v8-native still supports Global variable, I need to consider how to initialize the imported variables to the global variables. My current solution is to import variables by FFI function call, like
Module.asmLibraryArg.getSTACKTOP = function getSTACKTOP() { return STACKTOP; };
Then modify the asm.js code to call this initialization before running _main function.
Activity
kripken commentedon Nov 24, 2015
This is an issue that happens because WebAssembly does not have global variables. The idea is that people use locations in memory to replace them, but that requires interaction with the compiler, so it knows where it can place them.
For emscripten, we just reserve 8-1000 for such "mapped globals" as we call them, and we know that will be enough room.
We could make this work for other asm.js code too. The mapping shows up in
mappedGlobals, see https://github.com/WebAssembly/binaryen/blob/master/src/wasm-js.cpp#L199 for how it is used. But asm2wasm needs to be told where it can place them, with nextGlobal and maxGlobal https://github.com/WebAssembly/binaryen/blob/master/src/asm2wasm.h#L275 which by default have the 8-1000 range that works for emscripten.weilianglin commentedon Nov 24, 2015
I see. So before running WASM code, load_mapped_globals() should be called to copy imported variables to the correct locations and inside WASM, global variable access is interpreted to load/store of linear memory.
kripken commentedon Nov 24, 2015
Yes, exactly.
Out of curiosity, are you trying to convert asm.js from a non-emscripten source?
weilianglin commentedon Nov 24, 2015
No, I also convert asm.js generated by EmScripten to v8-native binary format. Since v8-native still supports Global variable, I need to consider how to initialize the imported variables to the global variables. My current solution is to import variables by FFI function call, like
Module.asmLibraryArg.getSTACKTOP = function getSTACKTOP() { return STACKTOP; };
Then modify the asm.js code to call this initialization before running _main function.
kripken commentedon Nov 24, 2015
I see. Yes, something like that could work too.
tlively commentedon Dec 13, 2024
Closing because asm2wasm no longer exists!
[Plat 9771] Add wasm-opt pass to instrument functions (WebAssembly#6)