Skip to content

add_pm probe: sub_pm as addition of the polarity-negated operand (P2) - #432

Merged
AdaWorldAPI merged 2 commits into
masterfrom
ccr-85acaff0-oszq40-sub-pm
Nov 15, 2026
Merged

AdaWorldAPI merged 2 commits into
masterfrom
ccr-85acaff0-oszq40-sub-pm

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Adds P2, subtraction, to the Codec9 P × M add probe (examples/add_pm). This is still lab code: no library or codec9 change.

The operation

  • neg_pm(b) flips the polarity bit on every lane that has a magnitude: P_¬b = P_b ⊕ (M_b ≠ 0).
  • A zero magnitude keeps its polarity. The never-touched code and +0 are therefore fixed points, and −0 is never produced.
  • sub_pm(a, b) = add_pm(a, neg_pm(b)). There is no separate subtractor, and the carry contract is the same one add_pm has.

Tests (tests/add_pm.rs, 11 tests, 5 new)

  • Negation: all 512 codewords. The value is negated; the magnitude and the touched state are kept.
  • Differences: all 512 × 512 pairs against the i32 oracle. The carry count is exact: 65,280, the opposite-polarity pairs with |a| + |b| > 255.
  • Equivalence: sub_pm is bit-identical to negate-then-add on every pair.
  • The four mandatory cases:
    • −5 + +5 = +0.
    • −0.499999 encodes to +0 (scale 1, ties to even, batch encoder) and stays touched after an add.
    • +0 − +0 = +0.
    • never touched − never touched = never touched.
  • Fold: a 2,000-block subtraction fold with the carry escape. It equals the i64 result, and it does carry, so the escape path is exercised.

Disable controls (committed first, each red):

what was disabled tests failed
polarity flipped on every lane 3
polarity never flipped 3
polarity flipped only on zero magnitudes 4

Backends

The 11 tests pass on seven tiers:

tier how it ran
AVX-512 native
AVX2 config-v3
AVX config-avx, qemu SandyBridge
x86-64-v2 (scalar backend) config-v2, qemu Nehalem
NEON aarch64 cross build, qemu
wasm32 +simd128 wasip1 under node WASI
wasm32 scalar wasip1 under node WASI
  • Before this PR, CI ran tests/add_pm.rs only in the native nextest job.
  • New scripts/add-pm-backends.sh builds the test binary for one tier and runs it, natively or under qemu.
    • It fails if zero tests execute, because the file is gated on std. A disable run confirmed this guard exits 1.
    • The SIMD-matrix rows for avx2, avx, v2 and neon now call it.
  • The wasm rows are not in CI. The criterion dev-dependency does not build for wasm32-wasip1. They were run once by hand, from a copy of the test file in a crate without dev-dependencies. The first attempt ran 0 tests because the std gate was missing, and was redone.

Cost

Measured in nanoseconds per 64 lanes, best of 50, on the same host.

tier sub_pm add_pm decode → i32 → encode
AVX-512 11.7 10.2 80.1
AVX2 (v3) 244.8 240.3 114.2

The AVX2 gap is still the array-backed U8x64 (P3).

Next

  • Promote add_pm / neg_pm / sub_pm into an experimental ndarray::hpc::abakus::pm module. Codec9 keeps the representation.
  • Then drop the lab copy in lance-graph xlog-relcomp-probe.

.claude/knowledge/add-pm-probe.md is updated with the above.


Generated by Claude Code

neg_pm flips P on lanes with a magnitude (P_neg = P xor (M != 0)), so the
never-touched code and +0 are fixed points and -0 is never produced; sub_pm
is add_pm(a, neg_pm(b)) with the same carry contract. Tests: negation of all
512 codewords, all 512 x 512 differences against the i32 oracle with the exact
carry count, sub_pm == negate-then-add, the four mandatory cases, and a
difference fold with the carry escape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF
… record P2

scripts/add-pm-backends.sh builds tests/add_pm.rs for one tier and runs it
natively or under qemu, failing when zero tests execute; the SIMD matrix rows
for avx2, avx, v2 and neon call it. The knowledge note records sub_pm, its
tests and disable controls, the seven tiers it passed on, and the Abakus
extraction as the next open item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 614cfa44-ea0d-435d-9c61-4dda0ac9e483
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review November 15, 2026 10:56
@AdaWorldAPI
AdaWorldAPI merged commit 457bce1 into master Nov 15, 2026
29 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T10:57:49.178804Z bbda7d8 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

2 participants