Repository navigation
feat(libc): implement the compiler-rt integer builtins - #6322
Merged
adriadam10 merged 2 commits intoOct 18, 2026
Merged
Conversation
Shifts, bit counts, comparisons, negation, multiplication, division and remainder, __udivmodti4, the overflow-reporting __mulo* and the overflow checking __addv*/__subv*/__mulv*/__negv*/__absv* families. Where the libc.prx bundled with PPSA08427 differs from compiler-rt it is followed: __addv* and __subv* wrap, and the 32-bit unsigned division returns 0 for a zero divisor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu
Progress report (fdea36b → 667e8ad)📈 System libraries: 88.89% (+0.18%, +59 implemented functions) ✅ 59 implemented
|
… builtins The libc.prx bundled with PPSA08427 returns 32 from __clzdi2 and __ctzdi2 and 64 from __clzti2 and __ctzti2 for a zero argument; found by comparing every builtin against it on random inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu
This was referenced Oct 15, 2026
Closed
11 tasks done
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
11 tasks done
11 tasks done
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.
What
Implements the 59 compiler-rt integer builtins that the system
libc.prxexports and AnyPS5 did not have:__ashldi3,__ashrdi3,__lshrdi3,__ashlti3,__ashrti3,__lshrti3__clz{si,di,ti}2,__ctz{si,di,ti}2,__ffs{di,ti}2,__parity{si,di,ti}2,__popcount{si,di,ti}2__cmp{di,ti}2,__ucmp{di,ti}2; negation__neg{di,ti}2; multiplication__muldi3,__multi3__div{si,di}3,__mod{si,di}3,__udiv{si,di}3,__umod{si,di}3,__divmod{si,di}4,__udivmod{si,di,ti}4__mulo{si,di,ti}4and overflow checking__addv,__subv,__mulv(si3,di3,ti3),__negv,__absv(si2,di2,ti2)They live in a new
src/IntegerBuiltins.cpp. The 128-bit paths use the existingSonyCrt.hpplong division and a hand-written 128-bit multiply, so no compiler-rt is needed on Windows.Behaviour follows the
libc.prxbundled with PPSA08427 (disassembly) where it differs from upstream compiler-rt:__addv*and__subv*are plain wrapping additions/subtractions on the console (the check was optimized away), so they wrap here too.__udivsi3is a software loop there, so__udivsi3,__umodsi3and__udivmodsi4give quotient 0 and the dividend as remainder for a zero divisor.__clzdi2/__ctzdi2of 0 return 32 and__clzti2/__ctzti2of 0 return 64.__divsi3,__modsi3and the 64/128-bit divisions trap on a zero divisor (div), and__negv*,__absv*,__mulv*call an abort helper thenud2on overflow; these throwstd::runtime_error, like the existing__udivti3/__umodti3. Recorded indocs/dev/debt/libc.md.Tested
Differential test against the console: the
libc.prxof PPSA08427 was mapped into a Linux process (PT_LOAD segments, RELATIVE relocations applied, the stack-protector GOT slot pointed at a dummy guard) and every builtin here was called side by side with this implementation on 200,000 random and edge-case inputs each (inputs on which this implementation throws are skipped, since the console traps there). All 59 functions agree bit for bit. The harness is not part of this PR because it needs the console binary.Linux (CachyOS, GCC Release build, plus a clang
-Wall -Wextrasyntax check): newguest_integer_builtinstest (shifts, bit counts, comparisons, 128-bit multiply, division/remainder edge cases includingINT_MIN / -1and zero divisors,__mulo*overflow flags at the boundaries, wrapping and throwingvvariants) passes;guest_crtandguest_mathpass.tools/check_conventions.pypasses;tools/pr_overlap.py --branchreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Q8tinbP1MUpUaDsbNWnGnu