Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

[spec/interpreter/test] Avoid lubs and glbs #43

Merged
merged 6 commits into from
May 11, 2019
Merged

[spec/interpreter/test] Avoid lubs and glbs #43

merged 6 commits into from
May 11, 2019

Conversation

rossberg
Copy link
Member

@rossberg rossberg commented May 8, 2019

This addresses #42 by:

  • adding a type-annotated variant of the select instruction (opcode 1C, one after plain select),
  • adding a bottom type.

Question: given the explicitly typed select, it would be possible to extend it to multiple values under the multi-value proposal. If we want to keep this option open then its type immediate should be a type vector, not a single type. Opinions?

@titzer
Copy link

titzer commented May 8, 2019

For multi-value select, I don't see a reason not to allow it. Without pick, it would require the use of an auxiliary local to chain multiple selects on the same condition.

@@ -92,7 +92,7 @@ Reference Instructions
Parametric Instructions
~~~~~~~~~~~~~~~~~~~~~~~

:ref:`Parametric instructions <syntax-instr-parametric>` are represented by single byte codes.
:ref:`Parametric instructions <syntax-instr-parametric>` are represented by single byte codes, possibly followd by a type annotation.
Copy link
Member

Choose a reason for hiding this comment

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

sp: followed

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

\end{array}

The |DROP| operator simply throws away a single operand.

The |SELECT| operator selects one of its first two operands based on whether its third operand is zero or not.
It may be include by a :ref:`value type <syntax-valtype>` determining the type of these operands. If missing, the operands must be of :ref:`numeric type <syntax-numtype>`.
Copy link
Member

Choose a reason for hiding this comment

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

s/may be include by/may include/ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@rossberg
Copy link
Member Author

rossberg commented May 8, 2019

@titzer, okay changed to enable multi-value select in the future.

Copy link
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

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

Glad you spotted this now.

@binji
Copy link
Member

binji commented May 9, 2019

Do we want the encoding of select to be a vector of types? We could reuse the blocktype encoding instead to save 1 byte in most cases. Though we'd have to also check that the type has 0 results.

@rossberg
Copy link
Member Author

rossberg commented May 10, 2019

@binji, good point. My reasoning for using a vector: (1) the most relevant cases where a blocktype would save a byte (numeric types) are already covered by the plain select instruction, which is even shorter; (2) deferring to a function type is odd here, because it would not match the actual instruction type (unlike with blocks) and only half of it is used; (3) it's going to be a rare instruction anyway, making conceptual simplicity more attractive.

@lukewagner
Copy link
Member

I'm having a hard time imagining the use case for multi-reference-value select, much less the need to optimize this case. Also, the need to reuse a condition multiple times seems like a reason for us to go ahead and add dup/pick, not work around their absence.

@rossberg
Copy link
Member Author

@lukewagner, it's not just multi-reference, it would work for all multi-values. The use case for this is the same as for multi-values in general, e.g., imagine a select on two complex numbers. An argument against this would be that there is no native hardware support for this, though I suppose a compiler could make use of vector types in common cases?

@lukewagner
Copy link
Member

Oh hah, sorry, not sure why I was thinking that the new select was only for ref types; commenting too early in the morning...

@binji
Copy link
Member

binji commented May 10, 2019

@rossberg Yep, those seem like good reasons to me. Having written a few decoders now, I've found it a bit nicer when instruction+immediate has a (more or less) fixed length, but we've already ruined that with br_table so I suppose I don't mind adding another.

@rossberg rossberg merged commit 29540ac into master May 11, 2019
@rossberg rossberg deleted the no-lub branch May 11, 2019 12:26
rossberg pushed a commit that referenced this pull request Nov 20, 2019
yurydelendik pushed a commit to bytecodealliance/wasmparser that referenced this pull request Jan 9, 2020
* Add nullref as an externally specifiable type

Spec commit: WebAssembly/reference-types@d4bc208

* Add typed select operator for reference types proposal

The reftypes proposal adds a typed select operator to simplify type checking
for reference types. The existing select operator is henceforth limited to
operate on the original MVP types only.

Spec change: WebAssembly/reference-types#43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants