Skip to content

feat(rv32): implement i64 SIMD polyfill via register-pair calling convention #380

Description

@cschanhniem

Context

The RISC-V backend currently has an open issue (#295) about i64.div_s/rem_s sign computation being clobbered by the udiv cores fixed registers. Beyond that specific bug, the RV32 backend generally lacks i64 SIMD-level throughput because there is no polyfill path that maps WASM v128 (SIMD) operations onto the RV32P Zve32* or Zvl32* vector extensions.

Proposal

Implement a compile-time --rv32-simd=zve32x|zve32f|zvl32b option that enables v128 lowering via subregister pairing:

WASM op RV32 lowering Extension needed
v128.load / v128.store 4× i32 scalar Zve32x (base)
i8x16.add 16× byte SIMD via vadd.vv EEW=8 Zve32x
i16x8.add 8× halfword via vadd.vv EEW=16 Zve32x
i32x4.add 4× word via vadd.vv EEW=32 Zve32x
i64x2.add 2× doubleword via vadd.vv EEW=64 Zve64x (requires Zvl64b)
f32x4.add 4× float via vfadd.vv Zve32f

When the target does not advertise Zve64x (common on RV32 embedded cores like the GD32V), i64x2 ops degrade to 2× scalar i64 register pairs — the same pattern already used for scalar i64 in the rv32 backend.

Rationale

WASM SIMD is one of the most impactful proposals for embedded/edge workloads (sensor fusion, audio DSP, pixel ops). Synth targets Cortex-M and RV32 equally in its mission statement; adding RV32 SIMD lowering closes the functional gap with the ARM backend, which already has NEON-adjacent ops via VFP/ASIMD.

Existing precedent in the codebase

Minimal first step

A single PR that:

  1. Adds RiscvSimdLevel to the target configuration
  2. Lowers i8x16.splat, i8x16.extract_lane, and i8x16.replace_lane to vmv.v.x / vget.v / vset.v
  3. Wires these through the existing test harness and verifies against 5 SIMD spec tests

This is analogous to how the arm backend incrementally added f32 support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions