Repository navigation
Nat.div and Nat.mod are one native division each: Base drops the other half as a Nat - #2173
Merged
Merged
Conversation
Base spells them Pair.fst and Pair.snd of Nat.divmod. Nat.divmod was already native, but the generic Pair.fst / Pair.snd then dropped the unused half, and a drop of a word of unknown type is a test (term_sink) that clang cannot remove when it cannot bound the word: a remainder computed for nothing, two compares and a branch per division. Both names are now C operations, the two halves of Nat.divmod's own text. The JS lane and the interpreter still run Base's defs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…, not as C operations Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Nat.divandNat.modwere Base'sPair.fstandPair.sndofNat.divmod. A generic def doesn't know the half it drops is aNat, so in C the drop was aterm_sinktest on that half. EveryNat.divtherefore also computed the remainder, and everyNat.modthe quotient.They now go through two Base helpers,
Nat.div.goandNat.mod.go, typedNat & Nat -> Nat. Dropping aNatcosts nothing, so clang deletes the unused half and leaves one division. The first version of this PR made both names C operations incomp.ts(+31 tokens). That no longer fits under the 66k cap, and this version adds 0 tokens tocomp.ts.Results
One M4, one thread,
korulang/koru-benchmarksosprey-compute-kernels. Each figure is the least of 7 runs, as instructions / cycles.All 17
bench/runtimeprograms emit byte-identical C and JS.Checks
tests/run/nat_div_native.bendcoversb = 0,a < b,a = b, the largestNaton either side, both names as function values and partly applied, anda = b * (a / b) + a % bover a countdown.clang failed to build main.🤖 Generated with Claude Code