wasm_validate_simd (wasm v0.1.0)

View Source

Operand types for the 0xFD vector opcode space. Add a vector instruction's types here, alongside its decoding.

Four tables, one per immediate shape, matching wasm_decode_simd:

  • type_of/1 for the plain lane-wise instructions, which is nearly all of them and where the type is a function of the opcode alone;
  • lane_op/1 for extract_lane and replace_lane, which also need the lane count so the immediate can be bounds-checked;
  • mem_op/1 for the vector loads and stores, whose natural alignment is the width of the access rather than 16: v128.load32_splat reads four bytes;
  • lane_mem_op/1 for the lane-indexed loads and stores, which need both.

Kept apart from wasm_validate_code for the same reason the decoder is: this opcode space is larger than every other prefix combined, and inlining it would bury the rules that are actually interesting.

Summary

Functions

Direction, natural alignment and lane count of a lane-indexed access.

Lane count and types for extract_lane and replace_lane.

Direction and natural alignment (as log2 bytes) of a vector load or store.

Operand and result types, or false if this is not a plain vector op.

Functions

lane_mem_op/1

-spec lane_mem_op(atom()) -> {load | store, 0..3, pos_integer()} | false.

Direction, natural alignment and lane count of a lane-indexed access.

lane_op/1

-spec lane_op(atom()) -> {pos_integer(), [atom()], [atom()]} | false.

Lane count and types for extract_lane and replace_lane.

The lane count is returned so the caller can reject an out-of-range immediate, which is a validation error rather than a decoding one: the byte is well-formed, it just names a lane the shape does not have.

mem_op/1

-spec mem_op(atom()) -> {load | store, 0..4} | false.

Direction and natural alignment (as log2 bytes) of a vector load or store.

The alignment hint is checked against the bytes the instruction actually touches, not against the 16 bytes of the result: v128.load8_splat reads one byte and may declare align=0.

type_of/1

-spec type_of(atom()) -> {[atom()], [atom()]} | false.

Operand and result types, or false if this is not a plain vector op.