Skip to content

Wasm2.0#72

Open
Terricide wants to merge 14 commits intoRyanLamansky:mainfrom
Terricide:Wasm2.0
Open

Wasm2.0#72
Terricide wants to merge 14 commits intoRyanLamansky:mainfrom
Terricide:Wasm2.0

Conversation

@Terricide
Copy link
Copy Markdown

Used AI to upgrade library to support Wasm 2.0

MR-Absolute and others added 7 commits April 19, 2026 08:47
Adds v128 bitwise (not/and/andnot/or/xor) and integer arithmetic
instructions across all four integer lane widths. Uses Vector128<T>
on .NET 5+ and scalar V128Polyfill fallback on older targets.
Adds System.Runtime.CompilerServices.Unsafe package for netstandard2.0
polyfill path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds 30 JIT-compilable WASM SIMD float instructions: Float32x4 and Float64x2 variants
of Abs, Neg, Sqrt, Ceil, Floor, Trunc, Nearest (unary) and Add, Sub, Mul, Div, Min,
Max, Pmin, Pmax (binary). Uses Vector128<T> on .NET 5+ and V128Polyfill scalar fallback
on netstandard2.0 (using Math.* instead of MathF.* for compatibility).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ions

Adds 25 new JIT-compilable WASM SIMD instructions:
- Int8x16Shuffle (16-byte immediate), Int8x16Swizzle (binary v128→v128)
- 6 splat instructions (scalar→v128): i8x16, i16x8, i32x4, i64x2, f32x4, f64x2
- 8 extract-lane instructions (v128+lane_imm→scalar) for all integer/float types
- 6 replace-lane instructions (v128,scalar,lane_imm→v128) for all types

New abstract bases: SimdSplatInstruction, SimdExtractLaneInstruction,
SimdReplaceLaneInstruction (all with private protected constructors per API quality test).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds ~95 new SIMD instructions covering:
- Comparisons: i8x16/i16x8/i32x4/i64x2/f32x4/f64x2 equal/ne/lt/gt/le/ge
- Shifts: i8x16/i16x8/i32x4/i64x2 shl/shr_s/shr_u
- AllTrue/Bitmask/AnyTrue for all integer lane types
- i8x16 popcnt, avgr_u; i16x8 avgr_u
- Narrow: i8x16.narrow_i16x8_s/u, i16x8.narrow_i32x4_s/u
- Extend: i16x8/i32x4/i64x2 extend_low/high_*_s/u
- Extmul: i16x8/i32x4/i64x2 extmul_low/high_*_s/u
- Extadd pairwise: i16x8/i32x4 extadd_pairwise_*_s/u
- i16x8.q15mulr_sat_s, i32x4.dot_i16x8_s
- v128.bitselect
- TruncSat, Convert, Demote, Promote conversions

New base classes: SimdShiftInstruction, SimdV128ToI32Instruction
Both NET5+ (Vector128<T>) and netstandard2.0 polyfill implementations included.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements v128.load8x8_s, v128.load8x8_u, v128.load16x4_s, v128.load16x4_u,
v128.load32x2_s, v128.load32x2_u, v128.load8_splat, v128.load16_splat,
v128.load32_splat, and v128.load64_splat — all 10 memory-widening and splat
SIMD instructions. Also fixes a pre-existing netstandard2.0 build error
(BitConverter.Int32BitsToSingle unavailable in that TFM).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements v128.load8_lane, v128.load16_lane, v128.load32_lane, v128.load64_lane,
v128.store8_lane, v128.store16_lane, v128.store32_lane, v128.store64_lane,
v128.load32_zero, and v128.load64_zero — all remaining SIMD memory instructions
needed for WASM 2.0 (SIMD) compliance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implemented WebAssembly 2.0 features: multi-value returns (using ValueTuple), reference types (funcref/externref), bulk memory/table operations, and initial SIMD (v128) support. Added MultiValueHelper for ValueTuple handling. Updated instruction parsing, segment handling, and test coverage for new features. Added build/test scripts and improved code style.
@RyanLamansky
Copy link
Copy Markdown
Owner

The PR is too big to review, and it needs to be reviewed carefully: uncritically accepting public code is how supply-chain vulnerabilities happen.

Next steps:

  • Slice & dice it into a smaller PRs, ideally not more than 2000 lines. This will obviously take many PRs, but they'll be small enough that I can handle the reviews.
  • Find the WASM official spec tests and make sure they're here, just as the WASM 1.0 ones are. These are the authority to confirm that the implementation is correct. Be sure to tell me how you found / integrated them so I can manually verify authenticity.
  • Remove Claude leftovers. So, CLAUDE.md, .claude directory, the .py files, the inprogress folder, maybe other things I didn't notice. I don't want to show affinity for any particular coding agent in the repo. .gitignore is an acceptable option.
  • If you want to keep this PR open, squash the commits + force push so the earlier state isn't included in history if it's merged.

@Terricide
Copy link
Copy Markdown
Author

I'll see what I can do, I just prompted Claude to add support for Wasm 2.0 and then pretty much let it create the unit tests and code and told it to continue every so often for a couple of days,

MR-Absolute and others added 7 commits April 20, 2026 10:26
- Fix V128Value NaN handling: change value[] from ulong[] to string[] so
  nan:canonical/nan:arithmetic patterns are accepted; add IsMatch() for
  NaN-aware lane-by-lane comparison in assert_return
- Allow v128.const in global initializer expressions (ParseInitializerExpression)
- Add SelectV128 helper method for select instruction with v128 operands
- Add lane index bounds validation to all extract/replace lane instructions,
  load/store lane instructions, and i8x16.shuffle
- Fix data segment range check: use (address + length - 1) as last-byte
  address for RangeCheck8, so segments ending exactly at memory boundary pass
- Fix active element segment validation: check for table existence before
  the zero-elements early-continue, so modules with zero-element active
  segments but no table correctly fail with ModuleLoadException
- Update tests to reflect new correct behavior (CompilerException instead of
  ModuleLoadException for TableCopy/TableInit, MemoryAccessOutOfRangeException
  instead of InvalidOperationException for memory.init after data.drop)

All 713 tests pass on net8, net9, and net10.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduce comprehensive test artifacts and JSON manifests for WebAssembly SIMD store, splat, select, and zero-load instructions. The new files cover v128.store, v128.store8/16/32/64_lane, v128.splat, v128.select, and v128.load32/64_zero, including tests for all lane types, offsets, alignments, and error conditions (malformed/invalid modules, out-of-bounds, type mismatches). These additions significantly expand test coverage for the SIMD proposal, ensuring correctness and robust error handling.
- Major overhaul of br/br_if/br_table/if/else/end compilation for spec-compliant stack/result handling
- Data/element segment initialization is now atomic; all bounds checks before writes
- Validate table/memory limits and global mutability on import
- Table initial size is always ≥1; relax delegate type checks
- Enforce memory alignment for load/store instructions
- Enable more spec tests; document CLR NaN limitations
- Fix unsigned float-to-int conversions and .NET SIMD test handling
- Various code cleanups and improved error reporting
Implement bit-exact float/double handling using new FloatHelper methods and IL changes to bypass CLR NaN canonicalization. Update memory read/write and constant instructions to use integer bit reinterpretation, ensuring spec-compliant NaN propagation and storage. Remove related test skips and update documentation for WASM 2.0 and known gaps.
Implement WASM spec-compliant NaN canonicalization for all float32/float64 arithmetic and conversions. Replace CIL Rem with helpers for signed int remainder to return 0 for INT_MIN % -1. Provide scalar-per-lane SIMD min/max for f32x4/f64x2 on .NET < 9 to match WASM NaN and ±0 rules. Remove test skips for these cases; update docs and test logic to reflect full spec compliance except for permanent CLR limitations.
Refactored SpecTestRunner to detect stack exhaustion by running tests on a background thread with a limited stack and timeout, ensuring both stack overflows and infinite recursion are handled per WASM spec. Removed test skips in SpecTests for call and call_indirect, as all cases are now reliably detected.
Updated documentation to explain the new approach for handling WASM spec stack exhaustion tests. Instead of permanently skipping `assert_exhaustion` tests affected by CLR JIT tail-call optimization, these are now run on a background thread with a timeout to detect exhaustion per the WASM spec. Only the `skip-stack-guard-page` test remains permanently skipped due to CLR limitations. Updated the skipped tests summary table accordingly.
@Terricide
Copy link
Copy Markdown
Author

I had Claude pull down all the spec wasm/wast files and go work on getting spec tests to pass, they all pass except one which crashes the clr, this is on purpose I believe and would require process isolation to not crash the test suite.

Now that the spec is hopefully all there, I'll try and see if I can get it broken up into new smaller commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants