Module Wax_wasm.SimdSource

Shared registry mapping wax SIMD intrinsic names to WebAssembly Vec* instructions and back. Single source of truth for to_wasm (forward), from_wasm (reverse) and Wax_lang.Typing (signatures).

Surface convention: vector ops are method intrinsics with the lane shape in the name (a.add_i32x4(b), v.extract_lane_s_i8x16(0)); the wax name is the WAT mnemonic A.B rewritten as B_A. Constants and bitselect are free functions; loads/stores are methods on a memory object.

Sourcemodule Text = Ast.Text
Sourcetype ty =
  1. | TV128
  2. | TI32
  3. | TI64
  4. | TF32
  5. | TF64

Operand / result valtype of an intrinsic, abstract from the wax/wasm valtype representations.

Sourceval lane_count : Ast.vec_shape -> int

Number of lanes in a shape (e.g. I32x4 -> 4); also the exclusive upper bound for a lane index of that shape.

Sourceval lane_scalar : Ast.vec_shape -> ty

Scalar type of one lane (splat operand, extract result, replace value).

Reverse direction: op -> wax name

Sourceval unop_name : Ast.vec_un_op -> string
Sourceval binop_name : Ast.vec_bin_op -> string
Sourceval ternop_name : Ast.vec_tern_op -> string
Sourceval shift_name : Ast.vec_shift_op -> string
Sourceval test_name : Ast.vec_test_op -> string
Sourceval bitmask_name : Ast.vec_bitmask_op -> string
Sourceval splat_name : Ast.vec_shape -> string
Sourceval extract_name : Ast.vec_shape -> Ast.signage option -> string
Sourceval replace_name : Ast.vec_shape -> string
Sourceval shuffle_name : string
Sourceval bitselect_name : string
Sourceval const_name : Wax_utils.V128.shape -> string
Sourceval free_namespace : string

The namespace of the free-function intrinsics, spelled v128::<member>.

Sourceval free_full : string -> string

free_full member is the registry key v128_<member> for a v128::member path (the inverse of free_member).

Sourceval free_member : string -> string

free_member "v128_bitselect" = "bitselect": the v128:: member name for a full registry key (the inverse of free_full).

Sourceval free_member_names : string list

Every v128:: free-function member: bitselect and one const constructor per shape (i8x16f64x2). For completion after v128::.

Sourceval vec_load_name : Ast.vec_load_op -> string
Sourceval load_lane_name : [ `I8 | `I16 | `I32 | `I64 ] -> string
Sourceval store_lane_name : [ `I8 | `I16 | `I32 | `I64 ] -> string
Sourceval load_splat_name : [ `I8 | `I16 | `I32 | `I64 ] -> string
Sourceval store_name : string
Sourceval vec_load_nat_align : Ast.vec_load_op -> int
Sourceval lane_nat_align : [ `I8 | `I16 | `I32 | `I64 ] -> int

Forward direction: wax name -> op

Sourcetype imm =
  1. | No_imm
  2. | Lane of Ast.vec_shape
    (*

    one index, 0 <= n < lane_count shape

    *)
  3. | Shuffle
    (*

    exactly 16 indices, each 0 <= n < 32

    *)

Trailing constant lane immediates (memory ops handled by mem_method).

Sourcetype intrinsic = {
  1. operands : ty list;
    (*

    receiver-first stack operand types

    *)
  2. result : ty option;
  3. imm : imm;
  4. free : bool;
    (*

    true: free function; false: method on the receiver

    *)
  5. build : int list -> Ast.location Text.instr_desc;
    (*

    lane immediates (source order) -> instruction

    *)
}
Sourceval classify : string -> intrinsic option

Recognise a method or free-function SIMD intrinsic by name.

Sourceval method_names : ty -> string list

The names of every SIMD *method* intrinsic (not a free function) whose receiver — its first stack operand — is ty, sorted. method_names TV128 is the vector ops written v.add_i32x4(w); the scalar-receiver splats live under their lane type (e.g. TI32 for splat_i32x4). For member completion after . on a value of that type.

Sourceval is_free_intrinsic : string -> bool

A reserved free-function name (a v128_<shape> constant, v128_bitselect); these shadow a user function of the same name only when it is unbound.

Sourceval const_shape_of_name : string -> Wax_utils.V128.shape option
Sourceval const_arity : Wax_utils.V128.shape -> int

Number of lane literals in a v128_<shape> const call.

Sourceval const_is_float : Wax_utils.V128.shape -> bool

Memory loads/stores (mem.loadv128, mem.load8_lane, …)

Sourcetype mem_intrinsic = {
  1. m_operands : ty list;
    (*

    address first, then the vector for store/lane ops

    *)
  2. m_result : ty option;
  3. m_lane : bool;
    (*

    a trailing constant lane immediate is present

    *)
  4. m_nat_align : int;
  5. m_make : Text.idx -> Ast.memarg -> int -> Ast.location Text.instr_desc;
    (*

    memory index, memarg, lane (0 when not m_lane) -> instruction

    *)
}
Sourceval mem_method : string -> mem_intrinsic option
Sourceval is_mem_method : string -> bool
Sourceval mem_method_names : string list

Every SIMD memory-access method name (loadv128store64_lane), for completion after mem.. The names mem_method recognises.

WAT mnemonics for plain vector instructions

The plain vector instructions are those the WAT lexer emits as a single INSTR token (splat, unop, binop, shift, test, bitmask); the single source of their WAT mnemonics, shared by output.ml and the WAT lexer.

Sourceval wat_mnemonic : _ Ast.Text.instr_desc -> string option

The WAT mnemonic of a plain vector instruction; None for anything else.

Sourceval plain_vec_instrs : Ast.location Ast.Text.instr_desc list

Every plain vector instruction, for the WAT lexer's keyword table.