Skip to content

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

Merged
merged 8 commits into from
Jun 23, 2020
Merged

Conversation

kripken
Copy link
Member

@kripken kripken commented Jun 23, 2020

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)

@MaxGraey
Copy link
Contributor

I'm wondering is it also could fix #2925 issue?

@kripken
Copy link
Member Author

kripken commented Jun 23, 2020

@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.

Copy link
Member

@tlively tlively left a 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?

@@ -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
Copy link
Member

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.

Copy link
Member Author

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.

@kripken kripken merged commit 8540db8 into master Jun 23, 2020
@kripken kripken deleted the fix branch June 23, 2020 23:37
kripken added a commit to emscripten-core/emscripten that referenced this pull request Jul 16, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants