Skip to content
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

Implement table.copy #6078

Merged
merged 14 commits into from
Nov 6, 2023
Merged

Implement table.copy #6078

merged 14 commits into from
Nov 6, 2023

Conversation

kripken
Copy link
Member

@kripken kripken commented Nov 2, 2023

With this, the cool Scheme game in https://davexunit.itch.io/strigoform can be optimized by wasm-opt. We reduce code size by 20% and improve the quality pretty substantially (e.g. we remove most of the casts).

Helps #5951

@@ -446,6 +446,10 @@ struct Unsubtyping
void visitTableFill(TableFill* curr) {
noteSubtype(curr->value->type, getModule()->getTable(curr->table)->type);
}
void visitTableCopy(TableCopy* curr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a test case for this in test/lit/passes/unsubtyping.wast.

if (sourceVal + sizeVal > sourceTableSize ||
destVal + sizeVal > destTableSize ||
// FIXME: better/cheaper way to detect wrapping?
sourceVal + sizeVal < sourceVal || sourceVal + sizeVal < sizeVal ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to check for wrapping against both sourceVal and sizeVal. Even the most wrapping possible cannot wrap around to greater than the minimum of the two, so just one of them will serve to detect the wrapping.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from the parallel logic in MemoryCopy. I agree that it looks unoptimal. I think the TODO covers improving them.

@@ -2706,6 +2706,24 @@ Expression* SExpressionWasmBuilder::makeTableFill(Element& s) {
return Builder(wasm).makeTableFill(tableName, dest, value, size);
}

Expression* SExpressionWasmBuilder::makeTableCopy(Element& s) {
auto destTableName = s[1]->str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support raw indices as well, or do we not support those in other places? The new wat parser will support them in either case (eventually).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we do in other places, as this is based on TableFill right above us. That actually might explain why some spec tests didn't pass...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is copied from upstream? I saw the TODO at the end, but did anything here require modifications? Are the failures mentioned in the TODO due to the fact that we re-evaluate table initializers whenever the table is accessed (IIRC)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No modifications. Just the TODO at the end, for tests that don't pass yet. I didn't investigate those in detail, but at least one factor was a failure to parse, which might be what you mentioned above.

@kripken kripken merged commit e3d2716 into main Nov 6, 2023
14 checks passed
@kripken kripken deleted the table.copy branch November 6, 2023 20:29
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
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.

2 participants