Skip to content

feat: [U3-C] full correctness matrix: padded shapes, over-width shift… - #29

Merged
DenkuKuro merged 1 commit into
mainfrom
u3c-full-matrix-correctness-edge-cases
Jul 22, 2026
Merged

feat: [U3-C] full correctness matrix: padded shapes, over-width shift…#29
DenkuKuro merged 1 commit into
mainfrom
u3c-full-matrix-correctness-edge-cases

Conversation

@DenkuKuro

Copy link
Copy Markdown
Collaborator

Closes: #9

Summary

Grows the differential harness from a per-op smoke test into the full
correctness matrix: every operation × width × shape, including the padded path
and the edge cases earlier updates deferred. Builds on the comparison/ashr
lowerings (#7), the SWAR sub/shift masks (U2-B), and the non-byte-multiple
padding path (U3-A), all of which are now on main.

Three areas of coverage were added, each following the existing test-suite
conventions (drop-in kernel files driven by tools/diff_runner.py, no per-op
harness logic):

  • Full padded matrixtest/pad_diff.ll grows from a handful of
    representative shapes (12 kernels) to the complete non-byte-multiple matrix
    (36 kernels): every lowered op (and/or/xor/add/sub/shl/lshr/ashr/eq/ne/ult/slt)
    at each field width i1/i2/i4 on a shape whose total bit width isn't a
    multiple of 8, exercising the zero-pad → carrier → narrow path end-to-end.
    The previously-absent comparisons and ashr are now part of the padded
    matrix, and shapes include the ticket's named cases (<5 x i1>, <12 x i1>,
    <3 x i4>).

  • At/over-width shift amounts — the concrete home for the U2-B
    amount-semantics decision (mask the amount to N, i.e. amount & (N-1)).
    tools/diff_runner.py previously clamped every shift amount into
    [0, N-1], so the over-width case was silently clamped away and never
    differentiated. Added an _ovf kernel-name marker: kernels that self-mask
    the amount in-IR (and %b, N-1) are recognized by the harness and fed the
    full unclamped amount range instead of being clamped, so counts ≥ N
    actually flow through. Because the kernel masks before the reference shift,
    the scalar reference stays defined even for raw out-of-range inputs, and the
    candidate SWAR lowering must agree with it. New test/shift_overwidth.ll
    covers shl/lshr/ashr × i2/i4, byte-multiple and padded; diff/{shl,lshr, ashr}.ll are documented as the in-range companion.

  • Explicit boundary assertions — new test/edge_values.ll pins the exact
    expected result bytes for the semantically interesting edge cases —
    all-zero and all-ones fields, and the signed high-bit boundary for slt/
    ashr sign handling — across i1/i2/i4. Unlike the differential kernels,
    this is a golden test: the module is lowered by the pass and its executed
    output is checked directly against literals (slt(-8,+7)→ff,
    ashr(-8,3)→ff sign-fill, add(15,15)→ee wrap, sub(0,1)→ff borrow, …),
    independent of any reference interpreter.

Notes / findings

  • LLVM version: this tree builds against LLVM 22 (LLVM_DIR=/usr/lib/ llvm-22/cmake), so the suite must run with the -22 tools — opt-16
    fails to load the plugin and can't parse the splat constant syntax used in
    the kernels.
  • Over-width path is genuinely exercised (not clamped away): verified with
    a negative control — a raw, non-self-masking _ovf kernel mismatches the
    poison scalar reference on the structured 0xFF/0x80 fills, while the
    self-masking kernel passes. The over-width amounts are present
    deterministically (via the structured fills), so coverage doesn't depend on
    the RNG seed.

Tests

  • Full padded matrix (pad_diff.ll, 36 kernels / 4896 trials) green, including
    comparisons and ashr; re-verified across seeds 1 / 7 / 12345.
  • shift_overwidth.ll (12 kernels / 1632 trials) green across the same seeds.
  • edge_values.ll golden assertions pass (lowered output matches all pinned
    bytes).
  • Full suite: 57/57 passing (was 55; +shift_overwidth.ll,
    +edge_values.ll), 0 XFAIL. Byte-multiple and padded matrices both green;
    no operation silently skipped (no total % 8 != 0 bypass, no trivial-pass
    no-op lowering).

@EdanStasiuk EdanStasiuk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lgtm, @angelo-yap want to review?

@DenkuKuro
DenkuKuro merged commit e9e14c7 into main Jul 22, 2026
1 check passed
@DenkuKuro
DenkuKuro deleted the u3c-full-matrix-correctness-edge-cases branch July 22, 2026 16:58
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.

[U3-C] Full-matrix correctness and edge cases

2 participants