Skip to content

fix(cpu_reference): avoid debug-build overflow in mask isolation#116

Merged
robtaylor merged 1 commit into
mainfrom
fix/cpu-ref-mask-debug-overflow
Jun 7, 2026
Merged

fix(cpu_reference): avoid debug-build overflow in mask isolation#116
robtaylor merged 1 commit into
mainfrom
fix/cpu-ref-mask-debug-overflow

Conversation

@robtaylor

@robtaylor robtaylor commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

What

cpu_reference::simulate_block_v1 (and _xprop) isolate the lowest set
bit of mask via mask & (-(mask as i32)) as u32. When mask has bit
31 set, -(i32::MIN) overflows and panics in debug builds
("negate with overflow"); release builds wrap silently, masking the bug.

Fix

Use mask & mask.wrapping_neg() — same two's-complement lowest-set-bit
isolation, but defined for all inputs. Behaviour is identical in release;
debug builds no longer panic, so cosim --check-with-cpu is now runnable
under debug builds.

Carry-forward item flagged in #115 / the backend-alignment handoff.

robtaylor added a commit that referenced this pull request Jun 7, 2026
Second session update: #115 merged; debug-mask fix (#116) and
batch-utilisation telemetry + findings (#117) open. Captures the
batch-capable-trait refinement and the paused-for-review status of
Phase 0b/0c.

Co-developed-by: Claude Code v2.1.168 (claude-opus-4-8)
`mask & (-(mask as i32)) as u32` panics with "negate with overflow"
in debug builds when `mask` has bit 31 set (negating i32::MIN). Release
builds wrap silently. Use `mask.wrapping_neg()` so the lowest-set-bit
isolation works identically in debug and release, making
`cosim --check-with-cpu` runnable under debug builds.

Co-developed-by: Claude Code v2.1.168 (claude-opus-4-8)
@robtaylor robtaylor force-pushed the fix/cpu-ref-mask-debug-overflow branch from baa3b30 to 07203de Compare June 7, 2026 10:52
@robtaylor robtaylor merged commit 5668db0 into main Jun 7, 2026
16 checks passed
@robtaylor robtaylor deleted the fix/cpu-ref-mask-debug-overflow branch June 7, 2026 11:19
robtaylor added a commit that referenced this pull request Jun 7, 2026
Both PRs merged. Sync handoff to final state: backend-owned schedule
(edge_ops_mut), P2/P3 merged in the plan, JTAG on xlarge + 40/45min
timeout (validated 32.0min), amendment date refs.

Co-developed-by: Claude Code v2.1.168 (claude-opus-4-8)
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