-
Notifications
You must be signed in to change notification settings - Fork 786
wasm2js: Avoid 64-bit scratch memory helpers in wasm-intrinsics #2926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm wondering is it also could fix #2925 issue? |
@MaxGraey I doubt it's related. These intrinsics are used to do i64 division, remainder, etc., which I don't think is the case there. But you can test locally to verify if you want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this looks like a good improvement. I wonder why we didn't do this in the first place?
src/passes/wasm-intrinsics.wat
Outdated
@@ -11,6 +11,8 @@ | |||
;; special scratch space, wasm2js_scratch_load_i32 etc. | |||
;; * Fix function type of __wasm_ctz_i64, which was wrong somehow, | |||
;; i32, i32 => i32 instead of i64 => i64 | |||
;; * Add $wasm-intrinsics-temp-i64 global to avoid a 64-bit import | |||
;; wasm2js_scratch_load_i64/store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this name won't exist in the codebase after this change, so it would probably be good to avoid using it in this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated.
I kind of saw the lines here as a "history", but yeah, maybe that's confusing.
This was disabled due to some bugs with legalization, but those have been fixed meanwhile (in WebAssembly/binaryen#2926) so we can do this. This helps nicely, e.g. 6% shrinking of hello_webgl2_wasm2js in the minimal runtime size test. In addition to CI, verified with wasm2js3 locally.
That code originally used memory location 0 to save 64 bits of
data (as that is what rust does apparently). We refactored it
manually to instead use a scratch memory helper, which is safer.
However, that 64-bit function ends up legalized, which actually
changes the interface between the module and the outside,
which is confusing and causes problems with optimizations
that can remove the getTempRet0 imports, see
emscripten-core/emscripten#11456
Instead, just use a global i64 to stash those bits. This requires
adding support for copying globals from the intrinsics module,
but otherwise seems simpler overall.
(tested on emscripten locally too)