Render signed PHIR registers as two's-complement bits instead of a sign prefix#339
Merged
Conversation
…s with matching Python and Rust interpreters
…|| handling, Path-B indexed-bit panic, and indexed Result destination sizing
…stination export, and fail-fast out-of-range bit writes
…ubit positional measurement mapping and restore unknown-block errors
…nfig.toml from build.rs when a valid LLVM 21.1 is detected
…port so PECOS works without external PATH/LD_LIBRARY_PATH setup
…ts link under rustc's bundled rust-lld
…iteral error to clear ruff RUF043 and typos
397a057 to
b70a28c
Compare
…wheels do not double-load and segfault while no-rpath source builds still resolve it
b70a28c to
0c8ddaf
Compare
…rk, useless borrow) across the workspace
…atest floating stable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
HybridEngine+ PHIR program produced a negative value in a signedregister (a sign bit that flipped), the returned bit string used Python's
sign-and-magnitude form — a leading
"-"for negatives,""for positives.So a full-width signed register printed a
"-"plus magnitude bits instead ofa fixed-width two's-complement string.
Fix
Render the raw two's-complement bit pattern in the
results()binary-stringpath: mask the value to
sizebits and format that. The sign bit now shows upas a
"1"/"0"like every other bit — never a"-"prefix — and the width isstable regardless of sign.
Applied consistently to both interpreters:
phir_classical_interpreter.py(results()) — the default Python pathclassical_interpreter.rs(results()) — the Rust interpreter twin, kept in parityWidth stays tied to the declared register
size. Negatives only occur whensize == the backing type width(e.g.i32size-32,i64size-64), so thatcase already prints the full 32/64 two's-complement bits with the sign bit as
the MSB, while a narrow signed register (e.g. an
i64size-1 measurement bit)still prints exactly one bit.
The general-purpose dtype
__format__indtypes.rsis intentionally leftalone — it mimics Python
intsign-magnitude semantics for directformat(i32(-1), 'b')calls and other callers rely on it. This change onlytouches the register result-string path.
Verification
-bug end-to-end, then confirmed fixed across i8/i32/i64/u32,narrow and full-width registers.
test_phir_64_bit.py, which had been asserting the oldsign-magnitude round-trip.