Skip to content

D-ADD-PM: Codec9 P × M lanes added in place (lab example) - #430

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

AdaWorldAPI merged 5 commits into
masterfrom
ccr-85acaff0-oszq40-add-pm

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Lab-only: an example and a test file. Nothing changes in codec9, the SIMD facade or any backend.

What

examples/add_pm/pm.rs provides add_pm(a, b) -> (lanes, carry). It adds two blocks of 64 DR512 lanes (a U8x64 of magnitudes plus a u64 presence word) directly in sign-magnitude form, without decoding to a signed integer:

  • Same polarity: M = sat(M_a + M_b) and P = P_a. The carry mask marks the lanes where M_a > 255 − M_b. It is the exact-escape signal that Codec9's encoder lacks, since the encoder saturates silently.
  • Opposite polarity: M = max − min, and P comes from the larger magnitude.
  • A zero result is +0 when either input was touched. Two never-touched inputs stay never touched.

Finding: no identity blend is needed. The never-touched code is a zero magnitude, so untouched ⊕ x = x falls out of the addition itself. A disable run that removed the first version's identity step stayed green, because the step was dead, so it's gone. Presence matters in only one place: the zero-to-+0 rule.

Tests (tests/add_pm.rs, all green)

  • All 512 × 512 codeword pairs match an i32 oracle. There are 65,280 carry pairs, exactly the touched same-polarity pairs with |a| + |b| > 255.
  • add_pm is bit-identical to the decode → i32 → encode path.
  • Never-touched appears in the output only where both inputs were never touched, and a touched zero is +0.
  • Associativity holds off the carry lanes (20,000 random triple blocks).
  • A 5,000-block fold that escapes its carry lanes into a wide tally equals the i64 sum.

Each of four disable controls turns at least three tests red: no +0 normalization, normalization not gated on presence, carry forced to 0, and opposite polarity taking the smaller magnitude's sign.

Cost (ns per 64 lanes, best of 50, same host)

tier add_pm decode path
AVX-512 (native, built avx512bw=true) 11.8 – 11.9 89.7
AVX2 (--config .cargo/config-v3.toml) 284.7 – 285.3 133.5 – 134.7

On AVX2, add_pm is slower than the decode path because the AVX2 U8x64 is array-backed: its mask_blend, saturating_add and saturating_sub are per-byte scalar loops, already on the facet-stride burn-down list. The AVX2 row is a v3 build running on an AVX-512 machine, not AVX2 silicon.

Doc: .claude/knowledge/add-pm-probe.md. Blackboard entry added.

cargo test --release --test add_pm --features std
cargo run --release --example add_pm --features std

Generated by Claude Code

…e (D-ADD-PM lab)

Sign-magnitude addition of Codec9 / DR512 lanes 64 at a time on the U8x64
facade, with no decode to a signed integer: untouched is the identity, a
touched zero is +0, and the same-polarity lanes whose sum passes 255 come
back as a carry mask instead of saturating silently. Tests: every 512 x 512
codeword pair against an i32 oracle, equality with the decode path,
associativity off the carry lanes, and a fold that escapes carry lanes into
a wide tally and stays exact.

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

The never-touched code is a zero magnitude, so untouched + x = x is the
sign-magnitude addition itself (a disable run removing the identity step
stayed green, because the step was dead). Only the zero-to-+0 rule needs
presence: two never-touched inputs must stay never touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF
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: d214bc75-f17a-4fb9-b51b-c814ee5621af
  • 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 04:48
@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-15T04:49:41.693121Z 4209a04 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.

@AdaWorldAPI
AdaWorldAPI merged commit acaa120 into master Nov 15, 2026
31 checks passed
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