Skip to content

fix(libc): preserve Dinkumware zero signs when no conversion occurs - #14595

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Danigamer05:fix/libc-no-conversion-zero-20261101
Nov 14, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Danigamer05:fix/libc-no-conversion-zero-20261101

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

When the host parser consumes no characters, ScaledFloat now obtains the zero sign from _Stopfx. For example, _Stodx("-z", ...) and _WStod(u"-z", ...) return negative zero while keeping the end pointer at the original input. Incomplete -i and -n prefixes retain positive zero. This changes the shared _Stodx / _Stofx / _Stoldx path and the wide wrappers added by #11733, without changing strtod or adding exports.

The contract was read and executed from PPSA03671 v01.001.005's bundled libc.prx (SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6). No original binary or extracted bytes are committed. The debt edit removes only the corrected zero-sign gap and retains the other parser qualifications.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main f2d874c1fdccf781c0fa5d86619bb5dd8894b958.

  • Compiled libc and the affected test executables. All 12 selected CTests pass: guest_dinkumware_internals, guest_wide_conversion, guest_math, guest_math_exact, guest_wide_strings, guest_strtod_subnormal, all four guest_floating_prefix_* cases, public_headers and libc_floating_point_contraction.
  • Negative control: the same regression tests with main's production source fail guest_dinkumware_internals and guest_wide_conversion; the other nine selected baseline tests pass.
  • Direct native comparison of the original module and the patched production library: 2,073,600 comparisons, zero differences after the change versus 506,880 differences before it. Six narrow/wide exports, 120 no-conversion texts, five scales including both int64 limits, three initial errno values, optional end/error pointers, four rounding modes, four DAZ/FTZ combinations and four initial floating-exception states. Compared result bits, final pointers, errno, error output, x87 exception flags/control and MXCSR. Original initializers are not run; unknown imports stop the comparison. This qualifies no-conversion behavior on this SDK module, not all numeric inputs or the console system libc.
  • Executable code was tested at 6af78ee89c; the final 5f320fed14 changes only documentation, with byte-identical C++ sources. Conventions were rerun on the final head: all checks pass. git diff --check passes.
  • Refreshed official overlap check: 1,796 open PRs, no confirmed overlap. It retains exit 2 for 31 branches already conflicting with main, sharing only the debt file. Their debt diffs were checked against every merge base; none changes the _WStod / _WStof / _WStold entry. This does not claim those branches merge cleanly. fix(libc): set ERANGE for decimal subnormals in wcstod as strtod does #11892 changes wcstod's subnormal-errno path and does not contain this correction.

Not tested: Linux, macOS, unmasked floating exceptions, non-C locales, another SDK, a title or a console. This is not a complete qualification of the wide floating conversions.

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

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 7447 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 11172 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 12682 docs/dev/debt/libc.md
PR 12688 docs/dev/debt/libc.md
PR 12700 docs/dev/debt/libc.md
PR 12849 docs/dev/debt/libc.md
PR 12965 docs/dev/debt/libc.md
PR 15973 docs/dev/debt/libc.md
PR 16791 docs/dev/debt/libc.md
PR 17557 docs/dev/debt/libc.md
PR 17558 docs/dev/debt/libc.md
PR 19602 docs/dev/debt/libc.md

@CnRJay CnRJay left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

When a Dinkumware strtod-family conversion consumes nothing, the change returns a zero whose sign follows the leading - that _Stopfx reports (bit 8). I traced ParsePrefix (FloatingPrefix.cpp lines 29-71) for each row of the test's no-conversion table: -z, - 5, -. and --1 give a negative zero; -i and -n reset the result and give a positive zero; +z and an empty string give a positive zero. The hosted Windows run passed guest_wide_conversion. The debt entry's measurement claims for the wide functions were not verified here.

What I ran

  • Head 5f320fed149ec62183fba3263bafe94c08754e0a; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 4 files, +54/-1: core/libs/prx/libc/src/DinkumwareInternals.cpp (+5), core/libs/tests/GuestDinkumwareInternals.cpp (+24), core/libs/tests/GuestWideConversion.cpp (+24) and docs/dev/debt/libc.md.
  • Read the changed function (DinkumwareInternals.cpp lines 216-223 at head), ParsePrefix (FloatingPrefix.cpp lines 29-71 at base), and the no-conversion table in the test.
  • Registration: guest_dinkumware_internals_tests (libc/CMakeLists.txt line 795) and guest_wide_conversion_tests (line 452).
  • Read-only checks from the trusted main checkout (precheck not run: this session does not run code from PR heads): diff check, conventions and the stack check passed; the ABI audit reported 25 symbols with no findings.
  • Hosted: the windows CTest run has two cases, guest_wide_conversion (Passed) and a tool check; guest_dinkumware_internals was compiled and was not in the run.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Sign of zero for -z, - 5, -., --1 passed ParsePrefix sets bit 8 from the leading - (line 35), and the result keeps it
Sign of zero for -i and -n passed the word test fails and resets the result to 0 (lines 52-57 and 40-45)
+z and the empty string passed no sign bit
guest_wide_conversion (hosted) passed in the Windows CTest run
guest_dinkumware_internals (hosted) not run compiled, not in the Windows CTest run
Debt-entry measurement claims (wide functions) not verified based on SDK 7.00 libc.prx comparisons not repeated here
ABI audit (main-checkout tool) passed 25 symbols, no findings
Build and runtime tests not run no local build
Negative controls not run no local build
Hosted CI passed windows passed (two CTest cases); linux and relinkers skipped
Read-only check output

Precheck was not run: this session does not run code from PR heads. The two "possible-unregistered" heuristic flags are false positives: both test files are registered (see Results notes). Hosted: gh api repos/boykopovar/AnyPS5/commits/5f320fed149ec62183fba3263bafe94c08754e0a/check-runs.

Negative control

Not run here. A negative control needs a build, and code from this head is not run here.

Findings

Blocking

None.

Non-blocking

None.

Sources

  • Changed function:
    char* stop = nullptr;
    TFloat value = parse(text, &stop);
    if (end != nullptr) *end = stop;
    if (stop == text) {
    const char* subject = text;
    const bool negative = (_Stopfx_nid_postfix(&subject, nullptr) & 8) != 0;
    value = std::copysign(TFloat{0}, negative ? TFloat{-1} : TFloat{1});
    }
  • ParsePrefix:
    template<typename TChar>
    int ParsePrefix(const TChar** cursor, TChar** end) {
    const TChar* const original = *cursor;
    const TChar* current = original;
    while (CharacterRules<TChar>::Space(*current)) ++current;
    const int negative = *current == '-' ? 8 : 0;
    if (*current == '-' || *current == '+') ++current;
    int result = negative | 1;
    if (*current == 'n' || *current == 'N') {
    if (Matches(current, "nan")) {
    current += 3;
    result = 4;
    if (*current == '(') {
    const TChar* payload = current + 1;
    while (CharacterRules<TChar>::Payload(*payload)) ++payload;
    if (*payload == ')') current = payload + 1;
    }
    } else {
    current = original;
    result = 0;
    }
    if (end) *end = const_cast<TChar*>(current);
    } else if (*current == 'i' || *current == 'I') {
    if (Matches(current, "inf")) {
    current += 3;
    if (Matches(current, "inity")) current += 5;
    result = negative | 3;
    } else {
    current = original;
    result = 0;
    }
    if (end) *end = const_cast<TChar*>(current);
    } else if (*current == '0' && (current[1] == 'x' || current[1] == 'X')) {
    const TChar* digit = current + 2;
    if (*digit == '.') ++digit;
    if (CharacterRules<TChar>::Hex(*digit)) {
    current += 2;
    result = negative | 2;
    }
    }
    *cursor = current;
    return result;
  • Registration:
    add_test_executable(guest_wide_conversion_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideConversion.cpp)
    and #L795

Not verified

  • The debt entry's measurements for the wide functions (SDK 7.00 comparisons) were not repeated.
  • guest_dinkumware_internals did not run hosted.

To get this to a good state

  • Nothing blocking. A run of guest_dinkumware_internals on Windows, or a note of how it was run, would close the hosted gap.

@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head 5f320fe merged onto main 4639eff · tested 2026-11-05 09:55 UTC · 21 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 3,825 passed · 19 failed (0 new, 11 also fail on main, 8 unstable on main) · 69 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 3,913 of 3,962 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (1399 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 121.9 s, ⚠️ agc_driver_graphics_maps_fallback 120.4 s, ⚠️ agc_driver_graphics 120.2 s, ⚠️ agc_driver_bda_device 69.3 s, ⚠️ agc_driver_stream_copy 53.3 s
Unstable on main (8, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_alpha_to_coverage_sample_mask_export: failed in 6 of the last 10 main runs
agc_driver_array_layer_target_cpu: failed in 2 of the last 10 main runs
agc_driver_dithered_alpha_to_coverage: failed in 1 of the last 10 main runs
agc_driver_graphics: failed in 3 of the last 10 main runs
agc_driver_graphics_maps_fallback: failed in 2 of the last 10 main runs
agc_driver_job_manager_compute_capacity: failed in 8 of the last 10 main runs
agc_driver_pipeline_journal: failed in 9 of the last 10 main runs
agc_driver_two_sample_alpha_to_coverage_sample_mask_export: failed in 4 of the last 10 main runs
Failing on main too (11, not counted against this PR)
agc_driver_guest_memory_lifetime_direct
agc_driver_image_table
agc_driver_native_depth_bda_clear
agc_driver_native_depth_buffer_clear
agc_driver_native_depth_clears
agc_driver_native_multisample_depth
agc_driver_submit_progress
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Passed on retry (2, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)
agc_driver_emulated_color_compare_srgb_decode: Timeout in the parallel run; also passed only on retry in 38 other runs in the last 7 days
agc_driver_recorder: Timeout in the parallel run; also passed only on retry in 30 other runs in the last 7 days
Validation IDs already present on main (4 IDs in 808 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (808 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_draw_space_reuse, agc_driver_address_draw_space_reuse_held, agc_driver_address_draw_space_reuse_off, agc_driver_address_draw_space_reuse_transitions, agc_driver_address_draw_space_reuse_verify, agc_driver_address_passes, and 800 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store_image_copy, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_partially_unmapped_plane, agc_driver_depth_plane_unmapped_plane, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store_image_copy, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_partially_unmapped_plane, agc_driver_depth_plane_unmapped_plane, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (69)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_copied_writer_label_order_drain: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_float16_unused_nan_payloads: skipped, the device has no native f16 conversions with RTE rounding and kept f16 denormals
agc_driver_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
agc_driver_image_table_vouched_lookups: skipped, the device reports 4 of 4 host-imported pages written after a GPU read, so a watched imported table cannot be vouched for
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_recorded_draw_staging: skipped, the device does not keep host imports write-watched, so the target is never resident
agc_driver_scattered_runs: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_unit_shadow: skipped, the device does not import watched host memory for unit shadows
agc_driver_unit_shadow_budget: skipped, the device does not import watched host memory for unit shadows
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_idle_publish_wait: skipped, the device reports 4 of 4 host-imported pages written after a GPU read, so a forced watch of the import reads its submissions as CPU stores
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_shadowed_key_stores: skipped, the device imports no watched host memory under a unit shadow
agc_small_tiled_shadow_label: skipped, host imports are unavailable: the test block is not imported and watched
agc_storage_clear_hand_over: skipped, the device imports no watched host memory for the clear-key hand-over
agc_unit_shadow: skipped, the device does not import watched host memory for unit shadows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_net_ctl_disconnected: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_disabled: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_four_k: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_height_only: skipped, n
Reproduce
git fetch origin 5f320fed149ec62183fba3263bafe94c08754e0a 4639eff7f4c23325a916875a0e37f1e312fa18f4
git checkout 4639eff7f4c23325a916875a0e37f1e312fa18f4 && git merge --no-ff 5f320fed149ec62183fba3263bafe94c08754e0a
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 5f320fed14, merged onto main bed95ca442 (02990e5735, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_dinkumware_internals, guest_wide_conversion pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit 46df0ee into boykopovar:main Nov 14, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants