Repository navigation
Conversation
On main the C lane still evaluates these through Base's recursive definitions: Nat.pow scales with the exponent, U32.log2 keeps the Base bit search in numeric folds, and Map.msb.u walks the bits of each query. The JS lane is unchanged (it runs Base's definitions, as intr_of skips an op with no JS). C intrinsics: - U32.log2: 31 - CLZ(x | 1), so log2(0) stays 0 (no undefined CLZ). - Nat.pow: checked repeated squaring via nat_pow, using nat_mul so the 48-bit immediate wall is checked (no u64 wrap); the unused final square is skipped. - Map.msb.u: CLZ-based width, clamped by the original Nat fuel; zero input / zero fuel return zero; fuel is not narrowed to U32. Resolves bendlang#1708, bendlang#1709, bendlang#1710
Collaborator
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.
Resolves #1708, #1709, #1710
The problem
On
main, the C lane still evaluates these through Base's recursive definitions:Nat.powscales with the exponent (a multiply and runtime call per step, even for bases 0 and 1).U32.log2keeps the Base bit search in numeric folds.Map.msb.uwalks the bits of each U32 query.The JS lane is unchanged (it runs Base's definitions); only the C lane gains native paths.
The fix (
bend2/comp.ts)Three C-only intrinsics added to
OPERATIONS(JS runs Base's), plus their C implementations inNATIVE.C:u32_log2: { C: "(31 - CLZ((u32)$0 | 1))" }—log2(0)stays 0, no undefined CLZ.nat_pow: { C: "nat_pow(e, $0, $1)" }— checked repeated squaring, usingnat_mulso the 48-bit immediate wall is checked (no u64 wrap); the unused final square is skipped.map_msb_u: { C: "map_msb_u($0, $1)" }— CLZ-based width, clamped by the original Nat fuel; zero input / zero fuel return 0; fuel is not narrowed to U32.GUIDE.md updated to mention the native scalar paths. Three run-lane tests added with the exact expected outputs (boundary values, two overflow cases).
Verification
--check-onlyon all three new tests:ALL PROOFS CHECK.-std=c11 -O1):native_numeric_boundariesprints all 23 expected lines;nat_power_overflow/nat_power_wide_overflowprintbend: a Nat past the largest immediate 2^48-1and exit 1.small_num.bend(3 values) agrees with C:2187 / 31 / 31.tests/**.bend --check-onlysweep (1661 files), before vs after: byte-identical — 588 pre-existing failures both ways, 0 new, 0 changed.comp.tstoken count: 64,561 → still under the 66,000 cap (headroom 1,439).Notes
u32_powpattern (intr_ofskips an op with no JS). JS continues to use Base's recursive definitions.