Skip to content

Select 128 can only be select_t#1901

Closed
andreaTP wants to merge 1 commit intoWebAssembly:mainfrom
andreaTP:fix-select-128
Closed

Select 128 can only be select_t#1901
andreaTP wants to merge 1 commit intoWebAssembly:mainfrom
andreaTP:fix-select-128

Conversation

@andreaTP
Copy link

@andreaTP andreaTP commented May 9, 2025

This is a fix on top of the recently merged #1899 .

From the spec:
Screenshot from 2025-05-09 11-06-24

If missing, the operands must be of numeric type.

With numtype:
Screenshot from 2025-05-09 11-10-01

Vector Types are not Number Types, hence the select type should be explicitly defined.

@andreaTP
Copy link
Author

andreaTP commented May 9, 2025

cc. @Zzzabiyaka

@rossberg
Copy link
Member

rossberg commented May 9, 2025

Note that this is just non-normative text describing the purpose of the instruction. It apparently wasn't updated by the SIMD proposal.

The normative specification of validation for select is here and allows vector types to be omitted as well.

I updated the informal description.

@andreaTP
Copy link
Author

andreaTP commented May 9, 2025

@rossberg thanks for the explanation.

How do you know if SELECT(without explicitly defined type) should operate on Numbers or on Vector Types?

We have the same question for other opcodes like LOCAL_GET/LOCAL_SET but in that case the type is stored in the function signature.

From an initial look, the only way to infer the correct type of SELECT is to do it in the validation algorithm or keeping the information around at runtime, but this is the first time we have to do something like this.

Just to explicitly state the problem, in the Chicory interpreter we use a fully untyped long array as Stack and we store Vector types using 2 slots.

In this situation we don't know how many values to pop and this is the only opcode where it is, non-decidable(if I understand it correctly) without an additional type inference step.

@rossberg
Copy link
Member

rossberg commented May 9, 2025

@andreaTP, well, semantically, it does not matter. And a jit will know the type. An interpreter using heterogeneous representations, however, may have to do some extra work, like storing type information from validation in a side table.

That's certainly annoying, but that problem is neither specific to vector types (i32 and i64 may already be of different size), nor to the select instruction (e.g., consider the drop instruction). So while I was never in favour of expanding the legacy form to vector types personally, I don't think it introduced any novel problems.

@andreaTP
Copy link
Author

andreaTP commented May 9, 2025

Thanks again for the prompt answer.

I don't think it introduced any novel problems.

Agreed, I'm going to close this one.

@andreaTP andreaTP closed this May 9, 2025
@titzer
Copy link
Contributor

titzer commented May 10, 2025

From an initial look, the only way to infer the correct type of SELECT is to do it in the validation algorithm or keeping the information around at runtime, but this is the first time we have to do something like this.

FWIW drop is also polymorphic in the same way.

@andreaTP
Copy link
Author

Thanks 👍

andreaTP added a commit to dylibso/chicory that referenced this pull request May 16, 2025
Opening in draft waiting for
WebAssembly/spec#1901 to be resolved.

---------

Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
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