feat(libc): implement the compiler-rt integer builtins #6322
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6322"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-15T11:34:07Z.
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
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T11:34:49Z.
Progress report (
fdea36b→667e8ad)📈 System libraries: 88.89% (+0.18%, +59 implemented functions)
✅ 59 implemented
__absvdi2_nid_postfix__absvsi2_nid_postfix__absvti2_nid_postfix__addvdi3_nid_postfix__addvsi3_nid_postfix__addvti3_nid_postfix__ashldi3_nid_postfix__ashlti3_nid_postfix__ashrdi3_nid_postfix__ashrti3_nid_postfix__clzdi2_nid_postfix__clzsi2_nid_postfix__clzti2_nid_postfix__cmpdi2_nid_postfix__cmpti2_nid_postfix__ctzdi2_nid_postfix__ctzsi2_nid_postfix__ctzti2_nid_postfix__divdi3_nid_postfix__divmoddi4_nid_postfix__divmodsi4_nid_postfix__divsi3_nid_postfix__ffsdi2_nid_postfix__ffsti2_nid_postfix__lshrdi3_nid_postfix__lshrti3_nid_postfix__moddi3_nid_postfix__modsi3_nid_postfix__muldi3_nid_postfix__mulodi4_nid_postfix__mulosi4_nid_postfix__muloti4_nid_postfix__multi3_nid_postfix__mulvdi3_nid_postfix__mulvsi3_nid_postfix__mulvti3_nid_postfix__negdi2_nid_postfix__negti2_nid_postfix__negvdi2_nid_postfix__negvsi2_nid_postfix__negvti2_nid_postfix__paritydi2_nid_postfix__paritysi2_nid_postfix__parityti2_nid_postfix__popcountdi2_nid_postfix__popcountsi2_nid_postfix__popcountti2_nid_postfix__subvdi3_nid_postfix__subvsi3_nid_postfix__subvti3_nid_postfix__ucmpdi2_nid_postfix__ucmpti2_nid_postfix__udivdi3_nid_postfix__udivmoddi4_nid_postfix__udivmodsi4_nid_postfix__udivmodti4_nid_postfix__udivsi3_nid_postfix__umoddi3_nid_postfix__umodsi3_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:18:43Z.
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.
main)__multi3_nid_postfixSome 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.
docs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.md