Reorder select's operands to put the condition last.#489
Conversation
|
Do you also want to mention something for I actually already have a v8-native branch that implements this. |
|
By "something" above, I mean, that the condition comes last (after the value) for |
|
I'm happy to submit a PR to the spec repo to reorder the inputs to |
|
I am referring to the |
|
Ah ok. Some parts of AstSemantics.md say that |
AstSemantics.md
Outdated
There was a problem hiding this comment.
it is instead of it's feels better to me given the overall formality here
|
Changed "it's" to "it is". |
|
Now I see this conversation :)... Had I known I would not have created WebAssembly/spec#200... |
|
LGTM btw |
|
Should we really do this for |
|
In v8-native, one can just use a nop for the value. As for multiple valuels: If we really have br_if and br with multiple On Thu, Dec 3, 2015 at 10:08 AM, rossberg-chromium <notifications@github.com
|
|
Is there a good reason to have the result of If supporting multiple values then the expressions will need to support this so there will still be only one result expression but it will have a multiple value type. An operator will be needed to build multiple values from multiple single value expressions. E.g. |
Generally speaking, having variable argument counts to opcodes is a big complication and we should constrain it to as few opcodes as possible. If there are two argument-counts possible for something like |
|
@titzer, my remark was more about the concrete syntax of the hypothetical textual format, which I assume would want to actually make the operand optional, while also representing the order of evaluation correctly. In practice, I think the eval order will hardly ever matter, so we should perhaps pick what reads better in text? (As for the potential case of multiple args, there is no more need to make the count explicit (in textual syntax) than for, say, function calls. Typing would be a trivial generalisation of what we already have now, see the original prototype.) @kg, separate opcodes would not be very natural in the light of an extension to multi values, where |
|
@rossberg-chromium Furthermore, we have yet to actually prove we need multiple return values or demonstrate that we can do them without significantly overhauling wasm. Compromising on file size, decode simplicity and validation simplicity right now for a questionable future feature is not something I can buy without strong justification. |
|
@kg, ah, no, arity would still be fully static, of course. As for the empty case, with multivalues it would not be special at all, it's just the N=0 case. You could make that a special opcode, if you're so inclined, but that wouldn't be any more natural than making, say, a function call with 0 arguments a special opcode. It might not even be more frequent. But all that is a bit of a tangent. My main point here is not to paint ourselves into a syntactic corner too much unless we have to. |
|
Could someone clarify why you would want to unconditionally evaluate the result expression for I understand why you would do this for |
|
I think the reason for the unconditional evaluation is to avoid having two (eval cond) On Thu, Dec 3, 2015 at 1:47 PM, JSStats notifications@github.com wrote:
|
|
@titzer Ok, thanks. So if people actually want conditional evaluation they can use |
|
@rossberg-chromium What we specifically want is for @kg I am hoping to experiment with multiple return values from statements, and to use that to approximate the potential for get_local/set_local reduction (which would be the main advantage). What happens next will depend on what we learn. @JSStats Yes, as @titzer says, making the return value unconditional avoids the need for two branches. Another way of looking at it is: |
|
@sunfishcode, I understand that both operands should always be evaluated, and I agree that a custom evaluation order would be ugly. But why does it matter that the condition operand is evaluated last? What's the use case? |
|
@rossberg-chromium: read up. It's because two branches are necessary. On Thu, Dec 3, 2015 at 5:14 PM, rossberg-chromium notifications@github.com
|
|
@titzer, as I said, I see how that motivates strictness, but not a particular choice of operand/evaluation order, no? |
|
Ah, right. We could make it strict and that fixes the problem as well. On Thu, Dec 3, 2015 at 5:26 PM, rossberg-chromium notifications@github.com
|
|
@rossberg-chromium When translating wasm to machine code, there are many situations where the condition operand can be folded with the branch, such as folding a load into a |
|
Friendly ping :-). This PR proposes reordering select's operands to put the condition last. This allows it to evaluate the condition last under the common evaluation rules, which is expected to enable more optimization opportunities. |
|
The The Was changing |
|
The changes to |
|
@sunfishcode Perhaps the point of noting that |
AstSemantics.md
Outdated
There was a problem hiding this comment.
Nit: This may be a slightly inaccurate description, given that it allows fall-through.
|
@JSStats, to be sure, a break is valid in that position, but it doesn't "yield a value" in the sense that it doesn't return one to the enclosing expression -- simply because it doesn't return to it at all. At least I think that was the intention of the wording. |
|
@rossberg-chromium Thank you for the clarification. Is there a good reason to allow |
|
@JSStats, yes, it's useful exactly for control flow forks that return a value from their "regular" branches, but want to do a break on some "exceptional" branch. A simple conditional is one example, a switch perhaps is a more interesting one. |
99fa647 to
e9eeffc
Compare
|
@rossberg-chromium Thanks for the correction; I misunderstood the intent of that wording. I've now removed that wording change, leaving the original text about br, case, and friends' return values in place. This PR now just has the operand ordering change for select and br_if/tableswitch result operands, following the discussion in #469. |
|
LGTM |
|
Merging with LGTM's above. |
Reorder select's operands to put the condition last.
This implements the select portion of WebAssembly/design#489 br_if operands are more involved, so I'll submit a separate PR for them.
This implements the select portion of WebAssembly/design#489 br_if operands are more involved, so I'll submit a separate PR for them.
This implements the second half of WebAssembly/design#489. Desugaring br_if to if+break turned out to makes this awkward; adding br_if to the kernel language was straightforward and avoided the awkwardness. This happened to expose an aspect of `br_if`'s type checking which differed from my expectations, so I've taken the liberty of fixing that too. See the deleted assert_invalid in test/labels.wast and the added $br_if1 testcase. `br_if` either sends its value to the destination label or to its own result.
This implements the second half of WebAssembly/design#489. Desugaring br_if to if+break was fairly awkward; adding br_if to the kernel language was straightforward and avoided the awkwardness. This change happened to expose an aspect of `br_if`'s type checking which differed from my expectations, so I've taken the liberty of fixing that too. See the deleted assert_invalid in test/labels.wast and the added $br_if1 testcase. `br_if` either sends its value to the destination label or to its own result.
To bring V8 into line with the proposed design changes in: WebAssembly/design#489 R=ahaas@chromium.org,bradnelson@chromium.org LOG=Y BUG=chromium:575167 BUG=v8:4735 Review URL: https://codereview.chromium.org/1624323003 Cr-Commit-Position: refs/heads/master@{#33776}
To bring V8 into line with the proposed design changes in: WebAssembly/design#489 (This CL is forked from https://codereview.chromium.org/1634673002/. That CL doesn't merge cleanly, and I can't update it.) TBR=titzer@chromium.org LOG=Y BUG=chromium:575167 Review URL: https://codereview.chromium.org/1682443002 Cr-Commit-Position: refs/heads/master@{#33828}
As discussed in #469, this PR proposes reordering select's operands to put the condition last. This allows it to evaluate the condition last under the common evaluation rules, which is expected to enable more optimization opportunities.