twoc: two's-complement jets (scalar + Lagoon %int2 arrays)#66
Merged
Conversation
Jet-hint /lib/twoc ++twid (12 hot-path arms: add sub neg mul div rem pow abs gth lth lte gte). All logic lives in the width-keyed ++twid door; the bloq-keyed ++twoc facade re-exports its gates, so a single %twid registration fires for both twid-direct (/lib/fixed) and facade (/lib/unum, Lagoon) callers. Master C jet twoc.c dispatches on width: native c3 types (c3_d <=64, __int128 <=128) for the bloq widths, GNU MP (already vendored) for arbitrary precision >128; declines to Hoon on out-of-width operands and zero divisors. Shared kernels factored into twoc.h. Lagoon %int2 element-wise array jets (add/sub/mul/div/mod) added to lagoon.c, dispatched on ray kind like %i754 and reusing the twoc.h kernels -- one linear C pass per array op instead of the super-linear Hoon bit-packing loop. Validated standalone (libmath/tools/twoc, 8280 native + 5692 GMP checks) and bit-exact on a hoon-135 fakezod; %int2 array add ~25,600x (20k lanes) to ~310,000x (200k) over interpreted. Vere reference: libmath/vere/README-twoc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
Runtime counterpart: urbit/vere#1047 |
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.
Jets for the
/lib/twoctwo's-complement integer library — scalar ops plus Lagoon%int2element-wise array ops. The runtime counterpart is urbit/vere (companion PR, linked below).What's here
/lib/twoc++twid(12 hot-path arms:add sub neg mul div rem pow abs gth lth lte gte). All logic lives in the width-keyed++twiddoor; the bloq-keyed++twocfacade re-exports its gates, so a single%twidregistration fires for bothtwid-direct (/lib/fixed) and facade (/lib/unum, Lagoon) callers.twoc.cdispatches on width — nativec3(c3_d≤64,__int128≤128) for the bloq widths, GNU MP (already vendored) for arbitrary precision >128; declines to Hoon on out-of-width operands and zero divisors. Shared kernels intwoc.h.%int2array jets (add/sub/mul/div/mod) inlagoon.c, dispatched on ray kind exactly like%i754, reusing thetwoc.hkernels — one linear C pass per array op instead of the super-linear Hoon bit-packing loop.libmath/tools/twoc) and a vere reference (libmath/vere/README-twoc.md).Design notes
%int2array lanes are always machine widths (8/16/32/64/128), so the array path is entirely native (no GMP).Validation
libmath/tools/twoc).%int2array ops verified jet == Hoon for all five ops; ~25,600× (20k lanes) to ~310,000× (200k) over interpreted (the Hoon array path is super-linear, the jet is O(N)).🤖 Generated with Claude Code