Conversation
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.
Algorithm:
upow2Modvs SymFPU'sdivideStepSymFPU computes the remainder via a
divideSteploop: one bit of long division per iteration, running for up toO(2^e)steps. This is simple but exponential in the exponent width.Our approach uses modular arithmetic: to compute
rem(x, y) = x - y * n, we only need the quotient parity (n mod 2), guard, and sticky bits. These are recovered from(x.sig * 2^k) mod (2 * D)whereD = y.sigandk = ex - ey. The key primitive isBitVec.upow2Mod, which computes2^k mod mvia repeated squaring inO(e)iterations ofO(s)-bit operations.divideStep(SymFPU)upow2Mod(ours)For IEEE double precision (e=11, s=53): ~30K vs ~108K bit operations. The gap grows exponentially with
e.Structure
BitVec.umulMod— modular multiplication (double-width)BitVec.umul2Mod— modular doubling (shift + conditional subtract)BitVec.upowMod— general modular exponentiation via repeated squaringBitVec.upow2Mod— specialized2^exp mod musingumul2Modfor the multiply-by-2 stepUnpackedFloat.mod— core remainder with rounding mode parameter (usesroundingDecisionfor integer quotient rounding, supports all SMT-LIB rounding modes)EUnpackedFloat.mod— special cases (NaN, ∞, zero)PackedFloat.mod— packed wrapper🤖 Generated with Claude Code