Skip to content

Introduce optimisations to make the Z80 CPU emulation some 80% faster#11

Open
doraemoncito wants to merge 5 commits intojsanchezv:masterfrom
doraemoncito:master
Open

Introduce optimisations to make the Z80 CPU emulation some 80% faster#11
doraemoncito wants to merge 5 commits intojsanchezv:masterfrom
doraemoncito:master

Conversation

@doraemoncito
Copy link
Contributor

@doraemoncito doraemoncito commented Jan 10, 2026

This pull request adds a comprehensive performance testing suite for the z80cpp Z80 emulator library. The PR introduces three types of tests: ZEXALL instruction validation, synthetic performance benchmarks, and real-world game ROM benchmarks. Additionally, it includes performance optimizations in the core Z80 implementation and moves the example code into the tests directory with improved structure.

Changes:

  • Added three new test executables: z80_sim_test (ZEXALL), z80_benchmark_test (synthetic benchmarks), and z80_game_test (game ROM benchmarks)
  • Implemented performance optimisations in z80.cpp using branchless flag operations
  • Fixed typo in setBit3Flag function name and corrected Z80 interrupt handling behaviour for RETI and LD A,I/R instructions
  • Updated build system with CMake test integration and CI/CD workflow
  • Enhanced README with detailed benchmark results and test documentation
  • Removed old example directory in favour of new test structure

Copilot AI review requested due to automatic review settings January 10, 2026 13:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a comprehensive performance testing suite for the z80cpp Z80 emulator library. The PR introduces three types of tests: ZEXALL instruction validation, synthetic performance benchmarks, and real-world game ROM benchmarks. Additionally, it includes performance optimizations in the core Z80 implementation and moves the example code into the tests directory with improved structure.

Changes:

  • Added three new test executables: z80_sim_test (ZEXALL), z80_benchmark_test (synthetic benchmarks), and z80_game_test (game ROM benchmarks)
  • Implemented performance optimizations in z80.cpp using branchless flag operations
  • Fixed typo in setBit3Flag function name and corrected Z80 interrupt handling behavior for RETI and LD A,I/R instructions
  • Updated build system with CMake test integration and CI/CD workflow
  • Enhanced README with detailed benchmark results and test documentation
  • Removed old example directory in favor of new test structure

Reviewed changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tests/z80_sim_test.hpp Header for ZEXALL instruction exerciser test with timing
tests/z80_sim_test.cpp Implementation of ZEXALL test with per-instruction timing output
tests/benchmark_shared.hpp Shared infrastructure for benchmark tests including simulator and runner
tests/z80_benchmark_test.cpp Synthetic benchmarks for instruction mix, memory, arithmetic, and branching
tests/z80_game_test.cpp Real-world game benchmarks loading TAP files
tests/CMakeLists.txt CMake configuration for building and running all tests
tests/zexall.bin ZEXALL binary test file
tests/roms/.gitkeep Placeholder for optional game ROM files
src/z80.cpp Performance optimizations and bug fixes for flag operations and interrupt handling
include/z80.h Fixed typo in setBit3Flag function name
CMakeLists.txt Updated to integrate tests with CTest and configure verbose output
.gitignore Updated patterns for build artifacts and ROM files
README.md Added extensive documentation of test suite and benchmark results
.github/workflows/build-and-test-with-cmake.yml GitHub Actions CI workflow for automated testing
example/z80sim.h Removed - functionality moved to tests
example/z80sim.cpp Removed - functionality moved to tests
example/README.md Removed - documentation consolidated in main README

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Refactor Z80 Simulator and Add Benchmark Tests

- Removed the Z80sim class header file to streamline the codebase.
- Updated Z80 class to use static_cast for type safety in opcode fetching.
- Introduced a comprehensive CMakeLists.txt for organizing benchmark tests.
- Created benchmark_shared.hpp to encapsulate benchmarking logic and configurations.
- Implemented z80_benchmark_test.cpp for performance testing with various instruction sets.
- Developed z80_game_test.cpp to benchmark real Spectrum games from TAP files.
- Added z80_sim_test.cpp and z80_sim_test.hpp for simulating Z80 operations in tests.
- Included zexall.bin as a test ROM for CP/M program execution.
- Ensured all tests provide detailed output and performance metrics.

* Update README.md
This change set implements significant build system and performance
improvements for the z80cpp Z80 emulator core. The primary goal is to
optimise runtime performance while modernising the build infrastructure.

**Changes:**

- Refactored from virtual dispatch to CRTP (Curiously Recurring Template
Pattern) for zero-overhead polymorphism
- Introduced performance optimisation macros (`Z80_FORCE_INLINE`,
`Z80_LIKELY`, `Z80_RESTRICT`)
- Modernised CMake build system with LTO, ccache support, and parallel
builds
- Added code quality tooling (clang-format, clang-tidy, GitHub Actions
CI)
- Renamed header files from `.hpp` to `.h` for C++ consistency
- Updated benchmark tests with higher performance expectations
@doraemoncito doraemoncito changed the title Add performance tests Introduce optimisations to make the Z80 CPU emulation some 80% faster Jan 17, 2026
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