Skip to content

Use checked native paths for Nat powers and bit widths - #1713

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:perf/c-base-numeric-20261018c
Oct 19, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:perf/c-base-numeric-20261018c

Conversation

@oxura

@oxura oxura commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

This adds C paths for Map.msb.u and U32.log2. Base, the checker and the JS backend are unchanged: a JS file runs Base's defs, as intr_of skips an op with no JS.

Map.msb.u computes the U32 width with CLZ, capped by the Nat fuel; zero fuel or zero input return 0. U32.log2 is 31 - CLZ(x | 1), so log2(0) stays 0. Map.msb.u sits on Map.diff.chr, the per-character step of string key comparison.

Native workload Before After
Map.msb.u fold 31.207 ms 2.371 ms
U32.log2 fold 2.825 ms 1.579 ms

(Linux x64, nine-pair medians; fixture in #1708.)

tests/run/native_numeric_boundaries.bend checks zero, bit boundaries and fuel 0/1/31/32/99 on every lane.

The Nat.pow native was dropped in review: any base >= 2 hits the 48-bit Nat wall by exponent 47, so Base's linear def already takes at most 48 steps, and nothing outside tests calls it.

Fixes #1709
Fixes #1710

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Lorenzobattistela
Lorenzobattistela merged commit d0d0c21 into bendlang:main Oct 19, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 20, 2026
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.

Native U32.log2 retains the Base bit search in numeric folds Native Map.msb.u walks the bits of each U32 query

2 participants