Skip to content

[Wasm RyuJIT] Codegen for Const Vector Create and Basic Packed SIMD operations#129703

Open
adamperlin wants to merge 18 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-basic-simd
Open

[Wasm RyuJIT] Codegen for Const Vector Create and Basic Packed SIMD operations#129703
adamperlin wants to merge 18 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-basic-simd

Conversation

@adamperlin

Copy link
Copy Markdown
Contributor

This PR implements support for Vector128.Create on Wasm with known constant args, as well as table-driven expansion and codegen for a large set of PackedSimd opcodes that operate on v128, (v128, v128) and (v128, v128, v128) type operands.

Notably absent from this PR: Vector128.Create with non-constants (requires additional lowering work), and SIMD compares (need special codegen for ulong since i64_u compare is not natively supported on Wasm).

Copilot AI review requested due to automatic review settings June 22, 2026 18:02
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends CoreCLR’s Wasm (RyuJIT) pipeline to recognize Wasm SIMD instruction-set support and begin emitting v128 SIMD code, including constant Vector128.Create lowering to v128.const and table-driven codegen for many PackedSimd operations.

Changes:

  • Enable Wasm ISA flags (WasmBase, PackedSimd, Vector128) and wire up instruction-set support for Wasm32 (base, simd128).
  • Add GT_CNS_VEC emission via v128.const, plus v128 load/store selection for TYP_SIMD16.
  • Introduce initial importer/list/codegen plumbing for PackedSimd and Vector128.Create constants.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems Enables SupportsWasmIntrinsics for CoreCLR Wasm builds.
src/coreclr/tools/Common/InstructionSetHelpers.cs Adds Wasm32 baseline instruction sets (base, simd128).
src/coreclr/jit/lowerwasm.cpp Starts allowing SIMD-category GT_HWINTRINSIC through lowering.
src/coreclr/jit/lower.cpp Relaxes TYP_SIMD12 assert for Wasm during lowering checks.
src/coreclr/jit/instr.cpp Adds Wasm v128_load/v128_store mapping for TYP_SIMD16.
src/coreclr/jit/hwintrinsicwasm.cpp Implements constant Vector128.Create import to GT_CNS_VEC.
src/coreclr/jit/hwintrinsiclistwasm.h Adds PackedSimd intrinsic definitions and updates some Vector128 entries.
src/coreclr/jit/hwintrinsiccodegenwasm.cpp Adds initial table-driven Wasm HW intrinsic emission.
src/coreclr/jit/hwintrinsic.h Adds a Wasm HWIntrinsic helper wrapper (but currently has a preprocessor issue).
src/coreclr/jit/hwintrinsic.cpp Adds Wasm PackedSimd ISA range and simdSize validation for Wasm.
src/coreclr/jit/compiler.cpp Forces Wasm baseline ISAs into JIT supported set, adds Vector128.
src/coreclr/jit/codegenwasm.cpp Adds GT_HWINTRINSIC dispatch and GT_CNS_VEC emission (v128.const).
src/coreclr/jit/codegen.h Declares Wasm vector-constant codegen helper.

Comment thread src/coreclr/jit/hwintrinsic.h Outdated
Comment thread src/coreclr/jit/lowerwasm.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsic.cpp Outdated
Copilot AI review requested due to automatic review settings June 22, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Comment thread src/coreclr/jit/hwintrinsiccodegenwasm.cpp
Comment thread src/coreclr/jit/codegenwasm.cpp
Comment thread src/coreclr/jit/instr.cpp Outdated
Comment thread src/coreclr/jit/instr.cpp Outdated
Comment thread src/coreclr/jit/hwintrinsic.cpp Outdated
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsiclistwasm.h Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Comment thread src/coreclr/jit/hwintrinsic.cpp Outdated
…case in SPMI (can happen if NYI_WASM_SIMD fires during import)
Comment thread src/coreclr/jit/instr.cpp
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Copilot AI review requested due to automatic review settings June 23, 2026 00:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Comment on lines 18 to 20
<SupportsWasmIntrinsics Condition="'$(Platform)' == 'wasm' and '$(FeatureMono)' == 'true'">true</SupportsWasmIntrinsics>
<SupportsWasmIntrinsics Condition="'$(Platform)' == 'wasm' and '$(FeatureCoreCLR)' == 'true'">true</SupportsWasmIntrinsics>
<SupportsWasmIntrinsics Condition="'$(SupportsWasmIntrinsics)' == ''">false</SupportsWasmIntrinsics>
Comment thread src/coreclr/scripts/superpmi.py Outdated
Comment thread src/coreclr/jit/hwintrinsiclistwasm.h Outdated
Comment on lines +68 to +72
#define FIRST_NI_PackedSimd NI_PackedSimd_Abs
HARDWARE_INTRINSIC(PackedSimd, Abs, 16, 1, {INS_i8x16_abs, INS_invalid, INS_i16x8_abs, INS_invalid, INS_i32x4_abs, INS_invalid, INS_i64x2_abs, INS_invalid, INS_f32x4_abs, INS_f64x2_abs}, HW_Category_SIMD, HW_Flag_BaseTypeFromFirstArg)
HARDWARE_INTRINSIC(PackedSimd, Add, 16, 2, {INS_i8x16_add, INS_i8x16_add, INS_i16x8_add, INS_i16x8_add, INS_i32x4_add, INS_i32x4_add, INS_i64x2_add, INS_i64x2_add, INS_f32x4_add, INS_f64x2_add}, HW_Category_SIMD, HW_Flag_BaseTypeFromFirstArg|HW_Flag_Commutative)
HARDWARE_INTRINSIC(PackedSimd, AddPairwiseWidening, 16, 1, {INS_i16x8_extadd_pairwise_s_i8x16, INS_i16x8_extadd_pairwise_u_i8x16, INS_i32x4_extadd_pairwise_s_i16x8, INS_i32x4_extadd_pairwise_u_i16x8, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_BaseTypeFromFirstArg)
HARDWARE_INTRINSIC(PackedSimd, AddSaturate, 16, 2, {INS_i8x16_add_sat_s, INS_i8x16_add_sat_u, INS_i16x8_add_sat_s, INS_i16x8_add_sat_u, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SIMD, HW_Flag_BaseTypeFromFirstArg|HW_Flag_Commutative)

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have anything to add over what copilot has pointed out.

I'll take another look when you've sorted through that; ping me.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 23, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Comment thread src/coreclr/jit/hwintrinsiclistwasm.h Outdated
Comment thread src/coreclr/jit/hwintrinsiclistwasm.h Outdated
Comment thread src/coreclr/scripts/superpmi.py Outdated
Comment thread src/coreclr/jit/hwintrinsicwasm.cpp
Copilot AI review requested due to automatic review settings June 23, 2026 20:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comment on lines +1819 to +1828
void CodeGen::genCodeForVectorConstant(GenTree* treeNode)
{
assert(treeNode->IsCnsVec());
GenTreeVecCon* vecCon = treeNode->AsVecCon();

// There is only one type variant for v128.const, v128.const <byte[16]>
// and the bytes are reinterpreted according to whichever operation consumes the value.
GetEmitter()->emitIns_V128Imm(INS_v128_const, vecCon->gtSimd16Val.u8);
WasmProduceReg(treeNode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants