Skip to content

A signed right shift needs three angle brackets - #2868

Merged
gHashTag merged 1 commit into
masterfrom
w723
Aug 29, 2026
Merged

A signed right shift needs three angle brackets#2868
gHashTag merged 1 commit into
masterfrom
w723

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

>> was mapped to Verilog's >> unconditionally. Verilog's >> is a logical shift — it fills with zeros however the operand is declared — and the arithmetic shift is >>>. The signedness repair this backend already has (W565) fires only on ordered relations < <= > >=, so no shift was ever fixed up.

spec      specs/igla/race/cordic_fixed.t27:42
          return x - (y >> shift);

emitted   input signed [15:0] y;
          ...
          cordic_x_next = (x - (y >> shift));

Simulated on the actual generated module

Not a reduced example — t27c gen-verilog output with a $display block appended, compiled with iverilog -g2012:

x_next(100, −64, shift=2)
before −16268
after 116
spec / C / Zig 116

y = −64 is 16'hFFC0 = 65472; 65472 >> 2 = 16368; 100 − 16368 = −16268.

An eight-iteration CORDIC whose rotations fill with zeros does not converge at all. This is a wrong gate, not a wrong number — Verilog is the backend that reaches silicon.

The project already knew the right operator

Its own hand-written golden CORDIC RTL writes y0 >>> 1 for the identical rotation. The expression path emitted >>> zero times across 559 generated modules; the only two occurrences in the whole corpus were inside string literals.

before after
>>> in generated Verilog 2 369, across 48 specs
iverilog accepts 373 / 559 373 / 559
suite 2455 / 0 2455 / 0

Acceptance is unchanged because the wrong shift was always legal Verilog. No gate could have caught this, and none did.

Tempered

The audit that found this said so first, and it holds: 42 of the 45 affected specs shift values that happen to be non-negative today, so they are latent rather than currently wrong. The three igla/race CORDIC specs are value-corrupting now.

bootstrap/stage0/FROZEN_HASH resealed.

Refs #2860

`>>` was mapped to Verilog's `>>` unconditionally. Verilog's `>>` is a
LOGICAL shift -- it fills with zeros however the operand is declared --
and the arithmetic shift is `>>>`. The signedness repair this backend
already has (W565) fires only on ordered relations, so no shift was ever
fixed up.

`specs/igla/race/cordic_fixed.t27:42`

    return x - (y >> shift);

emits, with `input signed [15:0] y;` two lines above,

    cordic_x_next = (x - (y >> shift));

Simulated on the actual generated module with iverilog:

    before   x_next(100, -64, shift=2) = -16268
    after    x_next(100, -64, shift=2) =    116

The spec, the C backend and the Zig backend all say 116. y = -64 is
16'hFFC0 = 65472; 65472 >> 2 = 16368; 100 - 16368 = -16268. An
eight-iteration CORDIC whose rotations fill with zeros does not converge
at all: this is a wrong gate, not a wrong number.

This project's own hand-written golden CORDIC RTL writes `y0 >>> 1` for
the identical rotation. The right operator was known; the expression path
emitted it zero times across 559 generated modules.

    `>>>` in generated Verilog    2 -> 369, across 48 specs
    iverilog accepts        373 / 559 -> 373 / 559
    suite                    2455 / 0 -> 2455 / 0

Both of the old two were inside string literals. Acceptance is unchanged
because the wrong shift was always legal Verilog -- no gate could have
caught this, and none did.

Tempered, and the audit that found it said so first: 42 of the 45
affected specs shift values that happen to be non-negative today, so
they are latent rather than currently wrong. The three igla/race CORDIC
specs are value-corrupting now.

FROZEN_HASH resealed.

Refs #2860
@github-actions

Copy link
Copy Markdown
Contributor

📓 NotebookLM Notebook linked to this PR

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

@github-actions

Copy link
Copy Markdown
Contributor

PR Dashboard

Generated at: 2026-08-29 19:02:43 UTC

Summary

Status Count
Total Open PRs 9
PRs with Failing Checks 7
PRs with All Checks Green 2
READY 1
FAILING 7
PENDING 0

Seal Status

  • ⚠️ STALE -- sha256(compiler.rs)=b109d745f014 != 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 enabled auto-merge (squash) August 29, 2026 19:02
@gHashTag
gHashTag merged commit d325b20 into master Aug 29, 2026
26 of 27 checks passed
gHashTag added a commit that referenced this pull request Aug 29, 2026
…ot see it (#2870)

310: `gen-verilog` mapped `>>` to Verilog's logical `>>` on signed
operands, and the decisive evidence was not in the compiler. All 559
generated modules held two `>>>`, both inside string literals -- and
those literals are this project's own hand-written golden CORDIC RTL,
which writes `y0 >>> 1` for the identical rotation. The project knew the
right operator and the backend emitted it zero times. A hand-written
reference in the repository is an oracle the generator can be measured
against, and it costs one grep.

311: four defects fixed this pass and not one moved an acceptance
number -- the step becoming the loop body, the dropped width suffix, the
logical shift, the truncated test that reported OK. Every one produced
output the target compiler was happy with, so a gate asking "does it
compile" cannot see the whole interesting class. What saw them: a second
backend to disagree with, a hand-written artefact to compare against,
and simulating the emitted module instead of reading it.

Refs #2868
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