feat(libSceLibcInternal): answer _Daysto, _FXp_getw and _Isdst as firmware 13.42 does #14945

Merged
BunnyFl merged 5 commits from upstream-pr/14945 into main 2026-11-05 21:19:03 +00:00
BunnyFl commented 2026-11-02 03:05:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:05:24Z.


What

Three throwing libSceLibcInternal exports now do what firmware 13.42's module does. Each is a defined entry in its dynamic symbol table, and each is a leaf with no calls, syscalls or writable data:

  • int _Isdst() (Sb26PiOiFtE): returns -1 and reads no argument.
  • int _Daysto(int year, int month) (ZlsoRa7pcuI): Dinkumware's days-to-start-of-month helper. The leap days before year are (year - 1) / 4 for a positive year, 1 + (4 - year) / 4 for a year of -4 or less, and 0 otherwise. To those it adds the entry for month from the common table when year & 3 is nonzero or the year is 0, and from the leap table otherwise. The module computes the leap days with 32-bit unsigned sub and shr, so 4 - year wraps for the five years from INT_MIN to INT_MIN + 4; the implementation does the same in std::uint32_t (536870914 for INT_MIN, month 0). The module indexes the twelve-entry tables with any month and reads whatever follows them, so a month outside 0 to 11 throws here instead.
  • float _FXp_getw(const float* parts, int count) (e1y7KVAySrY): Dinkumware's _Xp_getw for float, which sums the parts of an extended-precision value. 0 for no parts, parts[0] when there is one part or the first or second part is zero, parts[0] + parts[1] for two parts or a zero third part. Otherwise parts[3] joins parts[2] when count >= 4, and the sum is head + tail when head - parts[0] == parts[1], else parts[0] + (parts[1] + tail).

Both month tables lie in a read-only segment and hold the usual cumulative days before each month (0, 31, 59, ... and 0, 31, 60, ...); they are written out in the code.

Source: firmware 13.42 libSceLibcInternal.sprx (sha256 a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285). Read to the return, disassembly only, not measured on a console.

0x45ab0 _Isdst
  mov eax, 0xffffffff ; ret
0x46040 _Daysto
  test edi, edi ; jle L0 ; lea ecx, [rdi-1] ; shr ecx, 2 ; jmp L2
  L0: xor ecx, ecx ; cmp edi, -4 ; jg L2 ; mov ecx, 4 ; sub ecx, edi ; shr ecx, 2 ; inc ecx
  L2: test dil, 3 ; lea rax, [common] ; lea rdx, [leap] ; cmovne rdx, rax ; test edi, edi ; cmove rdx, rax
      movsxd rax, esi ; movsx eax, word [rdx+rax*2] ; add eax, ecx ; ret
0x734b0 _FXp_getw (objdump, AT&T operand order)
  734b0: test   %esi,%esi
  734b2: je     0x734be
  734b4: cmp    $0x1,%esi
  734b7: jne    0x734c3
  734b9: vmovss (%rdi),%xmm0
  734bd: ret
  734be: vxorps %xmm0,%xmm0,%xmm0
  734c2: ret
  734c3: vmovss (%rdi),%xmm0
  734c7: vxorps %xmm2,%xmm2,%xmm2
  734cb: vucomiss %xmm2,%xmm0
  734cf: jne    0x734d4
  734d1: jp     0x734d4
  734d3: ret
  734d4: vmovss 0x4(%rdi),%xmm1
  734d9: vucomiss %xmm2,%xmm1
  734dd: jne    0x734e1
  734df: jnp    0x734d3
  734e1: cmp    $0x2,%esi
  734e4: je     0x734f7
  734e6: vmovss 0x8(%rdi),%xmm2
  734eb: vxorps %xmm3,%xmm3,%xmm3
  734ef: vucomiss %xmm3,%xmm2
  734f3: jne    0x734fc
  734f5: jp     0x734fc
  734f7: vaddss %xmm1,%xmm0,%xmm0
  734fb: ret
  734fc: vaddss %xmm1,%xmm0,%xmm3
  73500: cmp    $0x4,%esi
  73503: jl     0x7350a
  73505: vaddss 0xc(%rdi),%xmm2,%xmm2
  7350a: vsubss %xmm0,%xmm3,%xmm4
  7350e: vaddss %xmm2,%xmm3,%xmm3
  73512: vaddss %xmm2,%xmm1,%xmm2
  73516: vaddss %xmm2,%xmm0,%xmm0
  7351a: vcmpeqss %xmm1,%xmm4,%xmm1
  7351f: vblendvps %xmm1,%xmm3,%xmm0,%xmm0
  73525: ret

The pending lists in docs/dev/debt/libSceLibcInternal.md drop the three names, and a new entry records what stays unverified.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, on upstream/main 93dbd0f82a:

  • New guest_libc_internal_firmware_answers passes. It covers:
    • _Isdst;
    • _Daysto for years 1, 4, 5, 0, -1, -3, -4, -5, 100, 2023, 2024, INT_MIN to INT_MIN + 5 and INT_MAX. The limit values come from the firmware's 32-bit arithmetic, computed independently. Built alone with -ftrapv, the first version's 4 - year traps at INT_MIN (exit 3) and the current one returns 536870914;
    • every _FXp_getw path, including two cases where parts[1] is lost in the first sum, so the two final branches give different results ({2^24, 1, 1} gives 16777218, not 16777216), and a NaN first part.
  • Mutation check: with _FXp_getw always returning head + tail, the test fails (a second part lost in the first sum is folded with the third first).
  • public_headers passes.
  • python3 tools/check_conventions.py --base upstream/main: all checks pass.
  • python3 tools/pr_overlap.py --branch feat/libcinternal-fw1342-daysto: no shared exports. The test registration sits in its own block at the end of CMakeLists.txt, so this branch merges cleanly with #14401, which inserts at line 10. #5021 (the ARM64 compiler) and #14212 (debt-file reformatting) conflict with main and could not be compared. #14212 shows these names only as context lines in the debt lists.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5114309470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14945). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T03:05:24Z. --- ### What Three throwing libSceLibcInternal exports now do what firmware 13.42's module does. Each is a defined entry in its dynamic symbol table, and each is a leaf with no calls, syscalls or writable data: - `int _Isdst()` (`Sb26PiOiFtE`): returns -1 and reads no argument. - `int _Daysto(int year, int month)` (`ZlsoRa7pcuI`): Dinkumware's days-to-start-of-month helper. The leap days before `year` are `(year - 1) / 4` for a positive year, `1 + (4 - year) / 4` for a year of -4 or less, and 0 otherwise. To those it adds the entry for `month` from the common table when `year & 3` is nonzero or the year is 0, and from the leap table otherwise. The module computes the leap days with 32-bit unsigned `sub` and `shr`, so `4 - year` wraps for the five years from `INT_MIN` to `INT_MIN + 4`; the implementation does the same in `std::uint32_t` (536870914 for `INT_MIN`, month 0). The module indexes the twelve-entry tables with any `month` and reads whatever follows them, so a month outside 0 to 11 throws here instead. - `float _FXp_getw(const float* parts, int count)` (`e1y7KVAySrY`): Dinkumware's `_Xp_getw` for `float`, which sums the parts of an extended-precision value. 0 for no parts, `parts[0]` when there is one part or the first or second part is zero, `parts[0] + parts[1]` for two parts or a zero third part. Otherwise `parts[3]` joins `parts[2]` when `count >= 4`, and the sum is `head + tail` when `head - parts[0] == parts[1]`, else `parts[0] + (parts[1] + tail)`. Both month tables lie in a read-only segment and hold the usual cumulative days before each month (0, 31, 59, ... and 0, 31, 60, ...); they are written out in the code. Source: firmware 13.42 `libSceLibcInternal.sprx` (sha256 `a01795ab49df639dd40abd6194956ada062244826824ce486c9acab227bf5285`). Read to the return, disassembly only, not measured on a console. ``` 0x45ab0 _Isdst mov eax, 0xffffffff ; ret 0x46040 _Daysto test edi, edi ; jle L0 ; lea ecx, [rdi-1] ; shr ecx, 2 ; jmp L2 L0: xor ecx, ecx ; cmp edi, -4 ; jg L2 ; mov ecx, 4 ; sub ecx, edi ; shr ecx, 2 ; inc ecx L2: test dil, 3 ; lea rax, [common] ; lea rdx, [leap] ; cmovne rdx, rax ; test edi, edi ; cmove rdx, rax movsxd rax, esi ; movsx eax, word [rdx+rax*2] ; add eax, ecx ; ret 0x734b0 _FXp_getw (objdump, AT&T operand order) 734b0: test %esi,%esi 734b2: je 0x734be 734b4: cmp $0x1,%esi 734b7: jne 0x734c3 734b9: vmovss (%rdi),%xmm0 734bd: ret 734be: vxorps %xmm0,%xmm0,%xmm0 734c2: ret 734c3: vmovss (%rdi),%xmm0 734c7: vxorps %xmm2,%xmm2,%xmm2 734cb: vucomiss %xmm2,%xmm0 734cf: jne 0x734d4 734d1: jp 0x734d4 734d3: ret 734d4: vmovss 0x4(%rdi),%xmm1 734d9: vucomiss %xmm2,%xmm1 734dd: jne 0x734e1 734df: jnp 0x734d3 734e1: cmp $0x2,%esi 734e4: je 0x734f7 734e6: vmovss 0x8(%rdi),%xmm2 734eb: vxorps %xmm3,%xmm3,%xmm3 734ef: vucomiss %xmm3,%xmm2 734f3: jne 0x734fc 734f5: jp 0x734fc 734f7: vaddss %xmm1,%xmm0,%xmm0 734fb: ret 734fc: vaddss %xmm1,%xmm0,%xmm3 73500: cmp $0x4,%esi 73503: jl 0x7350a 73505: vaddss 0xc(%rdi),%xmm2,%xmm2 7350a: vsubss %xmm0,%xmm3,%xmm4 7350e: vaddss %xmm2,%xmm3,%xmm3 73512: vaddss %xmm2,%xmm1,%xmm2 73516: vaddss %xmm2,%xmm0,%xmm0 7351a: vcmpeqss %xmm1,%xmm4,%xmm1 7351f: vblendvps %xmm1,%xmm3,%xmm0,%xmm0 73525: ret ``` The pending lists in `docs/dev/debt/libSceLibcInternal.md` drop the three names, and a new entry records what stays unverified. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, on upstream/main 93dbd0f82a: - New `guest_libc_internal_firmware_answers` passes. It covers: - `_Isdst`; - `_Daysto` for years 1, 4, 5, 0, -1, -3, -4, -5, 100, 2023, 2024, `INT_MIN` to `INT_MIN + 5` and `INT_MAX`. The limit values come from the firmware's 32-bit arithmetic, computed independently. Built alone with `-ftrapv`, the first version's `4 - year` traps at `INT_MIN` (exit 3) and the current one returns 536870914; - every `_FXp_getw` path, including two cases where `parts[1]` is lost in the first sum, so the two final branches give different results (`{2^24, 1, 1}` gives 16777218, not 16777216), and a NaN first part. - Mutation check: with `_FXp_getw` always returning `head + tail`, the test fails (`a second part lost in the first sum is folded with the third first`). - `public_headers` passes. - `python3 tools/check_conventions.py --base upstream/main`: all checks pass. - `python3 tools/pr_overlap.py --branch feat/libcinternal-fw1342-daysto`: no shared exports. The test registration sits in its own block at the end of `CMakeLists.txt`, so this branch merges cleanly with #14401, which inserts at line 10. #5021 (the ARM64 compiler) and #14212 (debt-file reformatting) conflict with main and could not be compared. #14212 shows these names only as context lines in the debt lists. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14945
No description provided.