-
Notifications
You must be signed in to change notification settings - Fork 715
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
wasm2c: implement the bulk memory operations proposal #1877
Conversation
dae6e37
to
7c8b9a5
Compare
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.
lgtm! Since I'm not maintaining this anymore you may want to wait for further review, but I wanted to give you some feedback
@binji Thank you muchly for the reviews! I wish GitHub had a way for us to mark the stacked PRs more clearly -- if possible, could we take these in order (so #1814 [module instancing] would be next, before we get to this one [bulk memory], reference types [#1887], and tolerating partly invalid modules [#1888])? Some of your comments here are things we'll need to fix in #1814 where the relevant commits originate, and then our plan was to rebase the later PRs on top of whatever ultimately lands. |
fdec286
to
f5d4deb
Compare
Sorry about reviewing out of order, I should have looked more closely at the description! |
85e60d0
to
f36fb7c
Compare
Does this change really depend on instancing ( #1814)? I wonder if it can land first? |
It's possible, but it would be a bit of work to backport this to a pre-instanced implementation. I guess I thought we had coalesced on this ordering when we talked at #1853 (comment). The major "instance-related" design decisions/consequences here are:
|
No problem. If its not a simple rebase we can keep the sequence as is |
The upgrade broke the Firefox build. wasm2c can't handle bulk memory ops yet. https://bugzilla.mozilla.org/show_bug.cgi?id=1773200 WebAssembly/wabt#1877 git-svn-id: file:///srv/repos/svn-community/svn@1230052 9fca08f4-af9d-4005-b8df-a31f2cc04f65
The upgrade broke the Firefox build. wasm2c can't handle bulk memory ops yet. https://bugzilla.mozilla.org/show_bug.cgi?id=1773200 WebAssembly/wabt#1877 git-svn-id: file:///srv/repos/svn-community/svn@1230052 9fca08f4-af9d-4005-b8df-a31f2cc04f65
e160874
to
13642fc
Compare
de1e4dd
to
1793a5d
Compare
@sbc100 Do you want to take a look at this one? (It will be helpful for updating the testsuite as more of the spec tests have started to require bulk-memory.) |
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!
lgtm with comments
@@ -1,4 +1,5 @@ | |||
# https://stackoverflow.com/a/47801116 | |||
file(READ ${in} content) | |||
set(content "const char* ${symbol} = R\"w2c_template(${content})w2c_template\";") | |||
string(REGEX REPLACE "(.[^\n]*\n)" "R\"w2c_template(\\1)w2c_template\"\n" content "${content}") | |||
set(content "const char* ${symbol} = ${content};") |
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.
Why this change?
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.
MSVC has a limit on the length of string literals that was getting exceeded (I think because wasm2c.declarations.c is now longer than 16KiB). This switches it to being one string literal per line of source.
@@ -444,4 +444,85 @@ static float wasm_sqrtf(float x) { | |||
return sqrtf(x); | |||
} | |||
|
|||
static inline void memory_fill(wasm_rt_memory_t* mem, u32 d, u32 val, u32 n) { |
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.
Would it make sense to somehow only emit this code when bulk memory is enabled? Perhaps we could define _WASM2C_HAS_BULK_MEMORY
and make this conditional? I guess it doesn't make much difference? Maybe tiny modules would compile marginally faster?
Maybe not worth it?
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.
We can do this if you want, but given that bulk memory is enabled by default (and has been for almost a year), it seems like a niche case... and it's not like these are particularly complicated functions to compile. (Some of the math functions are arguably more complicated and we emit those unconditionally...)
} | ||
|
||
static void init_elem_instances(Z_fac_instance_t *instance) { | ||
} |
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.
It it worth eliding all these function when they are empty (to make the output more readable?)
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.
Sounds good, done in #1999 which hopefully we can do as a follow-on to this one.
Write("bool ", "data_segment_dropped_", GetGlobalName(data_segment->name), | ||
" : 1;", Newline()); | ||
} | ||
} |
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.
I wonder if we should have some more examples of wasm2c output actual checked in so that when reviewing these changes we can see the effect they have on the output? Not sure what the best way to do that is.
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.
I also like this idea but not sure how far to take it... some options are probably:
- check in rot13.c like we do fac.c?
- check in a few representative outputs of running wasm2c on the spec testsuite?
- check in every single output of running wasm2c on the spec testsuite?
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.
How about a few hand-crafted tests under test/wasm2c
that include the input wat and the output c code in the same same file.
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.
Did a first stab at this in #2006.
Co-authored-by: Yuhan Deng <yhdeng@stanford.edu>
Co-authored-by: Yuhan Deng <yhdeng@stanford.edu>
(This PR is sequenced behind #1875 and #1814.)Support bulk memory operations in wasm2c (the next step in the checklist at #1853 (comment)).
This PR also adds test coverage:
elem.wast
test (we had previously been using a pre-bulk-memory version in old-spec. These "old" tests are tracked at wasm2c no longer passes many spec tests #1737.)bulk.wast
,memory_copy.wast
,memory_fill.wast
, andmemory_init.wast
(these were added in the bulk-memory proposal)load.wast
andstore.wast
tests (we had previously been omitting these because they require bulk-memory support, discussed at wasm2c: run multi-memory tests #1834. Another multi-memory tests requires reference-types support, and the final multi-memory test requires SIMD.)imports.wast
,linking.wast
,table_copy.wast
, andtable_init.wast
tests. (The current versions of these are waiting on reference-types support.)