Repository navigation
Conversation
… -1 in div, ldiv, lldiv and imaxdiv Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Other Merge Risk:
|
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
The debt entry for
div,ldiv,lldivandimaxdiv(docs/dev/debt/libc.md:431onmainea49f32e8982) says that with a divisor of -1 the result here is the two's-complement negation of the numerator with the remainder 0, and that the console result is unmeasured. A probe on a PS5 (firmware 11.60, payload process; a title process may differ) called the four functions of the system modulelibSceLibcInternal.sprx(line 2 of the raw output in the first comment:module=1 div=1 ldiv=1 lldiv=1 imaxdiv=1) with eight pairs each. The call with the minimum value and the divisor -1 took a SIGFPE in all four:div(-2147483648, -1)(case 1.6, line 8),ldiv(-9223372036854775808, -1)(case 2.6, line 16),lldiv(case 3.6, line 24) andimaxdiv(case 4.6, line 32), each withsignal=8(the probe's handler for SIGFPE is installed atprobe.c:141; the printedquot=23130 rem=23130is the preset 0x5a5a of the result structure,probe.c:163and:176, not a result). The seven other pairs for each function returned the quotients and remainders that the arithmetic gives: 7 / 2 gave 3 remainder 1, -7 / 2 gave -3 remainder -1, 0 / -1 gave 0 remainder 0, the maximum / -1 gave its negation with remainder 0, the minimum / 2 gave half of it with remainder 0, -5 / -1 gave 5 with remainder 0 and 5 / -1 gave -5 with remainder 0 (lines 3 to 10 fordiv, 11 to 18 forldiv, 19 to 26 forlldivand 27 to 34 forimaxdiv, without the four lines named above). The run was made once (END 41, line 43).On
maina divisor of -1 returns the negated numerator and the remainder 0 without a division (core/libs/prx/libc/src/Strings.cpp:863fordiv,core/libs/prx/libc/src/Math.cpp:517to:535for the three 64-bit functions), so the minimum / -1 returns the minimum and the process does not fault, where the console takes SIGFPE.This pull request adds one entry in a new fragment (
docs/dev/debt/changes/docs-libc-div-int-min-console-1160.md,## change [div, ldiv, lldiv and imaxdiv]) that replaces the entry atlibc.md:431; the entry grows from 551 to 927 characters with its list marker. It keeps the account of the negation and the remainder 0, replaces the sentence that the console result is unmeasured by the measurement (SIGFPE for the minimum / -1, in one run, fordivwith 32 bits and for the other three with 64 bits; the seven other pairs as the arithmetic gives them), says that the console faults wheremainreturns the minimum, and keeps that a zero divisor is unchanged. No code changes.Not measured: a zero divisor, a title process, other firmware.
Tested
Measured on a PS5 with firmware 11.60 from a homebrew payload process, one run at about 13:24 UTC on 2026-11-09 (probe build 3193c5be4339,
END 41). This is a documentation change; no test was added or run.On the head merged into
mainat ea49f32 (2026-11-27 20:14 UTC) I rantools/check_conventions.py --base upstream/mainwith this title and description (All conventions checks passed, exit code 0) andtools/debt_fold.py --check(exit code 0, no message). The commit has one author,xXPBSXxwith the noreply address, and adds one new file with the mode 100644.Overlap: counted on 2026-11-27 from the 2088 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API and, for those and for the pull requests with an old base, the real diff against the merge base; the patches of the 1268 pull requests that change a file under
docs/dev/debt/,Tsd.cpp,Strings.cpporMath.cpp, or have pthread, key, div or tsd in the title or branch name, were searched forpthread_key_create,scePthreadKeyCreate,PthreadKeyCreate,ldiv,lldiv,imaxdiv,INT_MIN,INT64_MINand the two fragment names, from 18:16 to 19:57 UTC). No open pull request changes the fragmentdocs/dev/debt/changes/docs-libc-div-int-min-console-1160.mdor the entry fordiv,ldiv,lldivandimaxdivatdocs/dev/debt/libc.md:431, and no commit onmainsince13bf980d9659(the base of this branch; 124 commits, up toea49f32e8982) changed that entry, the entrylibkernel.md:435,core/libs/prx/libc/src/Strings.cpp,core/libs/prx/libc/src/Math.cppor the fragment of the first pthread entry. A search of the open pull requests forlldiv,imaxdivanddiv_nid_postfixfinds none. The patches that nameINT_MINorINT64_MINdo so in other code: boykopovar#27646, boykopovar#26796 and boykopovar#26764 (INT_MIN / 4in the complex inverse trigonometric functions) and boykopovar#27244 and boykopovar#27229 (test tables of the x87 scaling functions); none namesdiv,ldiv,lldivorimaxdivor changes the entry. The merges of this head with each of the 96 pull requests that changelibc.md,libkernel.md,Math.cpp,Strings.cpporTsd.cppor have a searched name, or have 100 or more files or an old base, were made withgit merge-treefrom 18:16 to 19:57 UTC (mainat9f12ec0e3840at the start): 57 are clean; the other 39 already conflict withmainalone, in at least as many files as with this head, so none of them conflicts because of this change. The count was repeated for the 613 pull requests that were opened or updated since 18:16 UTC (of the 2083 open pull requests, listed from 19:58 to 20:12 UTC; 394 of them were patch-scanned for the same names): no new hit beyond the ones named, and the 8 that change a searched file merge cleanly with this head. A merge of this head intomainat ea49f32 was checked the same way at 19:59 UTC and is clean, and it merges with the first head of this series (the existing fragment ofpthread_key_create) without a conflict. This pull request does not depend on any of them (Depends on: none).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)Summary by CodeRabbit
-1, including minimum-integer inputs, and recording observed behavior on PS5 firmware 11.60. Zero-divisor behavior remains unchanged.