Skip to content

Add support for sign-extension operators from threading proposal#1167

Merged
dschuff merged 2 commits intomasterfrom
sext
Sep 6, 2017
Merged

Add support for sign-extension operators from threading proposal#1167
dschuff merged 2 commits intomasterfrom
sext

Conversation

@dschuff
Copy link
Member

@dschuff dschuff commented Sep 6, 2017

These are not atomic operations, but are added with the atomic operations to keep from having to define atomic versions of all the sign-extending loads (an atomic zero-extending load + signext operation can be used instead).

}
case ExtendSInt32: shouldBeEqual(curr->value->type, i32, curr, "extend type must be correct"); break;
case ExtendUInt32: shouldBeEqual(curr->value->type, i32, curr, "extend type must be correct"); break;
case ExtendSInt32:
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the original extend instructions should be renamed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe. Actually a lot of instructions probably should be renamed, and probably along with the binary format opcodes, it's kind of a mess (a lot of the opcode names predate the current spec scheme). I almost renamed the extension instructions here but decided that's not a great idea to mix it in with a functionality PR.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, probably better for a cleanup PR.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, let's do a bulk renaming eventually to the spec names, but not here.

Copy link
Member

@binji binji left a comment

Choose a reason for hiding this comment

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

lgtm, but did you want to implement in interpreter as well?

@dschuff
Copy link
Member Author

dschuff commented Sep 6, 2017

but did you want to implement in interpreter as well?

Not in this PR. I actually haven't implemented any of them in the interpreter yet, because my focus has been plumbing things through so we can test in engines. Although this one would be much simpler than the ones requiring shared memory.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Please add a TODO in passes/OptimizeInstructions.cpp that we can use these new instructions for code shrinking purposes. We have a bunch of code there to detect sign extends as well as create them etc., and this would be more compact (one instruction instead of one plus a constant).

src/wasm.h Outdated
DemoteFloat64, // f64 to f32
ReinterpretInt32, ReinterpretInt64, // reinterpret bits to float
// The following sign-extention operators go along with wasm atomics support.
// Extend signed subword-sized integer. This differs from e.g. ExtendSInt64
Copy link
Member

Choose a reason for hiding this comment

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

typo in comment, should be 32?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

// The following sign-extention operators go along with wasm atomics support.
// Extend signed subword-sized integer. This differs from e.g. ExtendSInt64
// because the input integer is in an i64 value insetad of an i32 value.
ExtendS8Int32, ExtendS16Int32, ExtendS8Int64, ExtendS16Int64, ExtendS32Int64,
Copy link
Member

Choose a reason for hiding this comment

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

maybe names should be ToInt32 etc., to match the trunc and converts? but maybe not since there are others too...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the Trunc* and Convert* opcode names use ToType but Promote, Demote, Reinterpret, and Extend don't. So... ¯\_(ツ)_/¯

}
case ExtendSInt32: shouldBeEqual(curr->value->type, i32, curr, "extend type must be correct"); break;
case ExtendUInt32: shouldBeEqual(curr->value->type, i32, curr, "extend type must be correct"); break;
case ExtendSInt32:
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, let's do a bulk renaming eventually to the spec names, but not here.

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