Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Relax verification to allow I8X16 to act as a default vector type #1236

Closed
wants to merge 1 commit into from

Conversation

abrown
Copy link
Collaborator

@abrown abrown commented Nov 16, 2019

  • This has been discussed in issue #1192.
  • A short description of what this does, why it is needed:

This change uses I8X16 as a default type to represent Wasm's V128 type. Values of Wasm's V128 type can be used in any instruction of similar width (e.g. i32x4.add). Cranelift must build signatures for Wasm functions using V128 and, lacking a special type to do so, Cranelift uses I8X16 for V128. To avoid excessive bitcasting, however, we relax the verifier to allow I8X16 to type-check as the other 128-bit types. This implies that:

  • SIMD instructions must have explicit types (e.g. iadd.i32x4) to avoid type inference deciding a wrong type and emitting the wrong instruction
  • The verifier will be unable to catch unintended errors in sequences like: v1 = iadd.i8x16 v0, v0; v2 = isub.i32x4 v1, v0 (presumably we want v0 and v1 to be I8X16 in fact and would want the verifier to tell us that we should not add them as I32X4s).

With this change, we still might choose to bitcast between SIMD instructions. Consider the Wasm snippet i64x2.add (f32x4.sub (local.get 0) (local.get 1)) for the following three options:

  • we retain all the current bitcasts between SIMD instructions when translating from Wasm; this means that the Wasm snippet is valid and compilable

  • we remove all of the current bitcasts between SIMD instructions when translating from Wasm; this makes the Wasm snippet invalid and compilation would fail with a verifier error

  • we retain the bitcasts but make this a configurable feature; in strict mode the snippet above would fail to compile but in relaxed mode it would succeed.

  • This PR contains test cases, if meaningful.

  • A reviewer from the core maintainer team has been assigned for this PR.

This change allows using I8X16 as a default type to represent Wasm's V128 type. Values of Wasm's V128 type can be used in any instruction of similar width (e.g. `i32x4.add`). Cranelift must build signatures for Wasm functions using V128 and, lacking a special type to do so, Cranelift uses I8X16 for V128. To avoid excessive bitcasting, however, we relax the verifier to allow I8X16 to type-check as the other 128-bit types. This implies that:
 - SIMD instructions must have explicit types (e.g. iadd.i32x4) to avoid type inference deciding a wrong type and emitting the wrong instruction
 - The verifier will be unable to catch unintended errors in sequences like: `v1 = iadd.i8x16 v0, v0; v2 = isub.i32x4 v1, v0` (presumably we want v0 and v1 to be I8X16 in fact and would want the verifier to tell us that we should not add them as I32X4s).
@bjorn3
Copy link
Contributor

bjorn3 commented Nov 16, 2019

Can we instead have a separate type for this? (v128?)

@abrown
Copy link
Collaborator Author

abrown commented Nov 17, 2019

Can we instead have a separate type for this? (v128?)

I considered that but as I looked into it it seemed to me that the type would be a weird one: it would have to be able to be coerced into any 128-bit wide vector AND every 128-bit wide vector would have to be able to coerce itself into such a v128. And I'm not sure I understand all the changes necessary to Type, TypeSet, ValueType, ValueTypeSet (am I forgetting some?) to do this. If you do, and it is simple, I think that would be a less hidden approach than the verifier relaxation.

@abrown
Copy link
Collaborator Author

abrown commented Dec 6, 2019

@bnjbvr, I'm going to close this in favor of #1272 and (possibly, eventually) #1251.

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.

None yet

2 participants