Skip to content

fix(gen-verilog): signed-aware ordered comparison - #1994

Merged
gHashTag merged 1 commit into
masterfrom
fix/verilog-signed-ordered-cmp
Aug 9, 2026
Merged

fix(gen-verilog): signed-aware ordered comparison#1994
gHashTag merged 1 commit into
masterfrom
fix/verilog-signed-ordered-cmp

Conversation

@gHashTag

@gHashTag gHashTag commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Problem

Verilog makes an ordered comparison (< <= > >=) unsigned if either operand is unsigned. A signed i8 (e.g. trend = -16 = 8'hF0) meeting an unsigned const reads as 240, so trend > THRESHOLD diverged from the Rust/Zig/C backends, which promote both operands to a signed int before comparing.

Fix

When at least one operand is signed, emit the comparison in the signed domain with C integer-promotion semantics:

  • signed operand → $signed(x) — Verilog sign-extends it into the wider signed comparison context
  • unsigned operand → $signed({1'b0, x}) — zero-extend one bit so the value stays non-negative

Unsigned/unsigned pairs are emitted unchanged. Example (is_degrading):

is_degrading = ((current_etx > QUALITY_POOR) && ($signed(trend) > $signed({1'b0, TREND_THRESHOLD})));

Validation

  • link_quality_monitor's degradation_detection flips to passing — the last codegen-side runtime divergence in the tri-net corpus
  • Full 105-spec icarus gate re-run against origin/main specs: 0 regressions
  • FROZEN_HASH resealed

Refs #1948

🤖 Generated with Claude Code

Verilog makes an ordered comparison (< <= > >=) UNSIGNED if either
operand is unsigned. A signed i8 (e.g. trend = -16 = 8'hF0) meeting an
unsigned const read as 240, so `trend > THRESHOLD` diverged from the
Rust/Zig/C backends, which promote both operands to a signed int before
comparing.

When at least one operand is signed, emit the comparison in the signed
domain with C integer-promotion semantics: the signed operand is wrapped
$signed(x) (Verilog sign-extends it into the wider signed comparison
context) and the unsigned operand is zero-extended one bit,
$signed({1'b0, x}), so its value stays non-negative. Unsigned/unsigned
pairs are emitted unchanged.

tri-net corpus: link_quality_monitor's degradation_detection flips to
passing -- the last codegen-side runtime divergence. Full 105-spec
icarus gate: 0 regressions.

FROZEN_HASH resealed.

Refs #1948

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

This notebook contains session context, decisions, and artifacts for this work.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-09 00:16:04 UTC

Summary

Status Count
Total Open PRs 15
PRs with Failing Checks 2
PRs with All Checks Green 13
READY 5
FAILING 2
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=274e2e4be8dd != manifest seal=87e5cbd3ad94.
    The committed NMSE numbers were certified against an older compiler.rs.
    Run scripts/reseal-check.sh locally for the two-step reseal command (advisory; not a merge gate).

@gHashTag
gHashTag merged commit 342c09b into master Aug 9, 2026
28 of 30 checks passed
@gHashTag
gHashTag deleted the fix/verilog-signed-ordered-cmp branch August 9, 2026 00:19
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.

1 participant