Skip to content

Require C++26 and optimize invalidation bitfields with regression coverage - #2

Merged
gajae1 merged 4 commits into
masterfrom
modernize/cpp26-bitfield
Sep 9, 2026
Merged

gajae1 merged 4 commits into
masterfrom
modernize/cpp26-bitfield

Conversation

@gajae1

@gajae1 gajae1 commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Scope

This branch builds on 986e8e0 and includes the still-unmerged fixes from #1. New work: e8dbcc9 (C++26/bitfields) and 7044cf1 (UTF-8 migration fix). Neither master nor the upstream repository has been merged or modified.

  • Require C++26 mode and CMake 3.30+ for project-owned C++ code; remove the nested core C++17 override and export cxx_std_26 to consumers. Unsupported compilers fail instead of silently falling back.
  • Retain C11 and vendored projects' own standards (notably Teakra's C++17). No language rewrite, fast-math or forced ISA change.
  • Modernize invalidation bitfields with standard <bit> operations and clear the lowest set bit using x &= x - 1.
  • Fix empty-range shifts by 64 and iteration into padding in a partial final word.
  • Preserve UTF-8 bytes at the three FATStorage boundaries affected by filesystem::path::u8string() returning std::u8string since C++20. Do not disable char8_t or use native-code-page .string() as a workaround.
  • Add direct-header bitfield and UTF-8 regression tests, a C++26 dialect guard, and an optional reproducible microbenchmark.
  • Update Linux CI to GCC 14 / Clang 18 and CMake 3.31.6; add full-core JIT-on/off compilation. Ubuntu application jobs no longer hide failures with job-level continue-on-error.
  • Document hardware-oracle and performance acceptance criteria in docs/Cpp26.md.

Verification at commit 7044cf1

GitHub Actions run: https://github.com/gajae1/melonDS/actions/runs/34088504727

Check Observed result
GCC 14 regression build/tests Success
Clang 18.1.3 ASan + UBSan regression build/tests 10/10 CTest entries passed; log inspected
Complete core, JIT ON Compile success
Complete core, JIT OFF Compile success

Core builds use BUILD_QT_SDL=OFF and ENABLE_OGLRENDERER=OFF; a successful static core build is not a full frontend link or native JIT execution test. Application/package workflows are checked separately and must not be inferred successful from this table.

The first C++26 full-core CI attempt correctly failed at the FATStorage char8_t boundary. Commit 7044cf1 addresses that actual failure and the new run above passed both core configurations.

Local source-fixture verification (not a full checkout): original bitfield valid nonempty ranges pass, padding test fails, and UBSan reports the empty-range shift. Patched bitfield and UTF-8 tests pass with GCC 14.2 and Clang 17 ASan/UBSan. A local CMake probe for language mode, bitfield and UTF-8 passes 3/3 on each compiler; the C++23 dialect guard is rejected as intended. Git blob hashes were checked for the original headers and FATStorage source. ASCII, Korean, Japanese, non-BMP, long, empty and embedded-NUL byte cases are covered; filesystem mutation and complete FAT synchronization are not.

Isolated performance result, NOT emulator FPS

Identical flags for before/after: -std=c++2c -O3 -fwrapv, no -march=native, added AVX or LTO. Same deterministic harness, one logical CPU on an AMD EPYC 9V74 virtual host, nine randomized-order paired samples after warmup. All 72 paired checksums agree.

Initial pattern GCC 14.2 routine-time reduction Clang 17 routine-time reduction
empty (input subsequently mutates) 14.65% -1.17%
sparse 26.06% 14.19%
mixed 39.23% 16.04%
dense 41.98% 16.71%

These are bitfield-iteration microbenchmarks, not whole-emulator speedups or proof that C++26 alone is faster. Results vary by compiler, workload and host. No fixed wall-clock CI thresholds are added.

Accuracy and compatibility boundaries

No guest timing constants, ARM semantics, DMA/IRQ model, native JIT emitter, renderer interfaces, storage layout or save format were changed. Real DS/DSi comparisons, game playback and real GPU output were not executed here. This is not yet a measured hardware-accuracy milestone.

C++26 implementations remain partial/experimental. This pass uses established C++20 bit facilities under the requested newer dialect. Linux CI now targets Ubuntu 24.04; do not assume its artifacts run on Ubuntu 22.04. Older BSD/Nix/toolchain configurations may need updates. The PR remains draft pending platform build review and game regression evidence.

cmake -S tests -B build-regression -DCMAKE_BUILD_TYPE=Debug
cmake --build build-regression
ctest --test-dir build-regression --output-on-failure

… validation

Limit wrapped capture readback to the remaining blocks. Validate section headers and lengths before both returning a matching section and skipping one.

Reuse the one-line ARMJIT fix authored by Ogato in melonDS-emu#2654; its base ARMJIT.cpp blob matches this fork. The savestate work is informed by melonDS-emu#2712 but also validates matching sections before returning. FIFO validation from that PR is not included.

Add focused standalone C++ regression tests and a GCC/Clang sanitizer workflow. Document measurement-first performance direction without introducing a language rewrite or unmeasured SIMD requirements.

Locally verified: 7/7 CTest entries with GCC 14.2 and Clang 17 ASan/UBSan. These are dependency-isolated tests, not a complete emulator build, real OpenGL execution, or game/performance validation.
Raise project-owned C++ targets and the regression suite to C++26 mode with CMake 3.30+, remove the core's C++17 override, and export cxx_std_26 to consumers. Keep vendored project settings and C11 sources unchanged.

Replace bit-count builtins with standard <bit> operations and clear the lowest set bit with x & (x - 1). Fix zero-length range shifts and iterator padding bounds. Add direct-header regression tests, a language-mode guard, an optional reproducible microbenchmark, and JIT-on/off core build jobs. Update the Ubuntu CI toolchain and document the runtime compatibility change.

Local verification: baseline padding test fails and UBSan reports the empty-range shift; patched tests pass with GCC 14.2 and Clang 17 ASan/UBSan. CMake C++26 probe passes, C++23 guard fails as intended. Paired same-flags microbenchmarks show a compiler/workload-dependent improvement, not emulator FPS or hardware-accuracy proof. Full repository builds and the combined regression suite are delegated to this commit's CI; no result is claimed before execution.
Full-core CI exposed the C++20+ change from std::string to std::u8string in filesystem::path::u8string. Adapt the three FATStorage call sites explicitly without disabling char8_t or converting paths through the native code page.

Add a small byte-preserving conversion and direct-header tests for ASCII, Korean, Japanese, non-BMP, long, empty and embedded-NUL strings. Local GCC 14.2 and Clang 17 ASan/UBSan runs pass; the original boundary conversion fails compilation as expected. Full core and application results are checked separately in CI.
Documentation-only follow-up: update the previous C++17/CMake 3.16 instructions and describe the ten-test suite. Production code and build configurations are unchanged from 7044cf1.

gajae1 commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

Verified HEAD: 5be8f74

The final documentation follow-up changes only tests/README.md; production code is identical to 7044cf1.

The new HEAD's Core regressions run has passed all four jobs:
https://github.com/gajae1/melonDS/actions/runs/34088845520

  • GCC 14: configure, build, tests successful.
  • Clang 18 ASan/UBSan: configure, build, tests successful.
  • Full core JIT ON: compilation successful.
  • Full core JIT OFF: compilation successful.

The suite contains 10 CTest entries. The inspected Clang log on the identical code commit 7044cf1 explicitly reports 10/10 passing:
https://github.com/gajae1/melonDS/actions/runs/34088504727/job/101637080780

For 7044cf1, the Ubuntu x86_64 full application and AppImage job completed successfully, and the Ubuntu aarch64 full-application Build step also passed:
https://github.com/gajae1/melonDS/actions/runs/34088504784

The documentation-only HEAD's application workflows were still rebuilding at this check; Windows/macOS/BSD are not declared passed. Do not conflate core-only compilation, complete application compilation, actual native JIT execution, real GPU output, game compatibility, or real DS/DSi agreement.

The PR remains draft and unmerged. No end-to-end FPS or new hardware-accuracy result is claimed. Bitfield timings in the PR body remain isolated, same-flags microbenchmarks; the initially-empty Clang case shows no improvement.

@gajae1
gajae1 merged commit 5be8f74 into master Sep 9, 2026
11 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant