Skip to content

Document opcode 0x1C, typed select. #18

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions WebAssembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,10 @@ parameter is bound to the type of the global.

#### Select

| Mnemonic | Opcode | Signature | Families |
| ----------- | ------ | ------------------------------------------- | -------- |
| `select` | 0x1b | `($T[1], $T[1], $condition: i32) : ($T[1])` | |
| Mnemonic | Opcode | Immediates | Signature | Families |
| ----------- | ------ | --------------------------------------------------- | ------------------------------------------- | -------- |
| `select` | 0x1b | | `($T[1], $T[1], $condition: i32) : ($T[1])` | |
| `select` | 0x1c | `$signature`: [array] of [value types]; length is 1 | `($T[1], $T[1], $condition: i32) : ($T[1])` | |
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think "array" is correct here because "array" as defined in this document includes an encoding of the length, which the actual binary encoding for typed select doesn't have. Instead of saying it's an array with "length is 1", could we just say there's a single type? The spec does have wording leaving open the possibility of having more types, but the binary encoding doesn't reflect that.

Copy link
Author

Choose a reason for hiding this comment

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

The octets for typed select look like this: 1C 01 7F - the last one is the actual type; the second one is always 1 but I think that qualifies as array-like?

(Just guessing but I suspect it's to allow future extension for a select where the two operands have different types?)

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, you're right. I misread the spec. Could you then move the length is 1 out and add it as a Validation requirement?


The `select` instruction returns its first operand if `$condition` is [true], or
its second operand otherwise.
Expand All @@ -1767,6 +1768,9 @@ meant to have similar performance properties.
> This instruction is sometimes called "value-polymorphic" because it can
operate on values of any type.

**Validation:**
- `$signature[0]` is the [type] of the first and second operand.

TODO: Explicitly describe the binding of $T.

#### Call
Expand Down