-
Notifications
You must be signed in to change notification settings - Fork 694
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
Nop in branch values when the target is not expecting a value. #518
Comments
It seems like an inefficiency in the V8 encoding if it requires an explicit |
This used to be allowed by the spec but is no longer. I would rather view the use of the nop opcode to encode an absent optional parameter a detail of the binary encoding, not part of the AST semantics. |
Actually, I just ran into this yesterday and I was appreciating the way it is currently spec'd since, if the expected type of a |
It's really just a consequence of doing bottom-up verification in the V8 On Tue, Jan 19, 2016 at 4:28 PM, Luke Wagner notifications@github.com
|
Yes, that makes sense. I haven't really considered the ramifications of top-down (which is what's in ml-proto/spec/check.ml) vs. bottom-up. Thinking about this a bit more right now, if we want to move to a postorder serialization (which I do), then we wouldn't have parent context so we'd need a bottom-up algorithm. Assuming bottom-up, for an op as common as |
On Tue, Jan 19, 2016 at 5:23 PM, Luke Wagner notifications@github.com
|
Saving individual bytes (when most of them are 0 anyway) is way less important than ensuring the structure of the file is highly compressible. It does seem like requiring top-down validation (in order to know whether to read a child expression for the I'd prefer that we just defined separate opcodes for |
As I pointed out elsewhere, introducing separate operators on the AST level would become extremely odd in the presence of multiple values (if we ever add them), where there would more than just 0 or 1 -- in the same way that it would be odd to have a separate operator for nullary calls. I'd much prefer to consider optional operands, like lists of operands, an encoding level problem, not something that shows through in the AST semantics. As for the current V8 format, representing nullary by a pair of br opcode and nop opcode should already be perfectly compressible, I reckon? FWIW, either way I don't believe this affects top-down vs bottom-up typing considerations at all. |
Thank you for all the feedback. It's still not clear to me that this should fail. The expected type is void or empty-values, and the expression type is the same? It seems just a bug to assume that the expression returns values without checking it. @rossberg-chromium I think we see multi-value support differently as I don't see a problem with a separate convenience opcode for the case in which there is no expression @lukewagner Using the parent expected type to determine the number of expressions required by a child expression sounds very unfortunate. However it would be fine for a compressor to make coding choices based on context. Please let us know when you have some sketch of an alternative binary encoding as it might take some time to evaluate and it might be unnecessary to have all the details to form some opinions - for example we can run a bottom up compression predictor and compare it to a top down predictor. @kg It might be too early to assume that 'the case where they accept a value is going to be incredibly rare compared to the no-value case' because the emitted code is just not yet optimize to take advantage of expressions at the block level. With multiple-value support the opportunities also increase. |
@rossberg-chromium Ah, good point: this is an |
@lukewagner Yes, I see some tints that an opcode table that can specify immediate arguments could be useful. Tried a table of extended opcodes that do this, but giving each a separate name. For example: |
In the short-to-mid-term it seems unlikely that any code generator will actually use this feature. Maybe someone in the CG can correct me, but the only time I've seen break-with-value is in the .NET expression tree representation. It's not in llvm IR, the x86 or arm instruction sets, or in any language I've ever seen as a flow control primitive. I agree that it could be compelling once compilers are able to utilize the feature, but until then we'd be paying the cost for it with every file shipped. To be fair, if I remember correctly the cost of an unneeded stream of Mostly Zeroes was on the order of 3% in my tests, so maybe we don't care about the difference.
We've previously referred to this (in a more general sense) as non-nullary macros. It's a good idea to consider doing it in a more constrained fashion and just implement support for an opcode+immediate pair directly in the opcode table. It would be much easier to specify and implement. |
@kg Fwiw here are the counts and percentages for
Yes, I am developing an optimization pass that tries to better use the operations in this regard but these are also expected to reduce the use of There seems to be some support now for exploring the 'opcode+immediate pair directly in the opcode table'. Let's see how this goes. Perhaps while exploring this people can stretch this to also handle the load/store-add patterns etc. Who else has an interest in working on thIs? |
An idea discussed recently is to change branches and other instructions have an arity immediate which would indicate the number of result values. It could be initially limited to 0 or 1, but would leave room for extending to multiple results in the future. This would also eliminate the need for nop opcodes before branches, because a branch with no results would just have a 0 arity. |
@sunfishcode Thank you for looking into this issue. Depending on the goals of the post-order encoding some of the mv issues might be affected, but here are some points:
This suggests that it would only be unnecessary for
|
The V8 encoding uses a nop as filling in
br
operations see WebAssembly/wabt#20 Can the spec be modified to accept this usage?The V8 encoding used the following pattern.
The text was updated successfully, but these errors were encountered: