Introduce optimisations to make the Z80 CPU emulation some 80% faster#11
Open
doraemoncito wants to merge 5 commits intojsanchezv:masterfrom
Open
Introduce optimisations to make the Z80 CPU emulation some 80% faster#11doraemoncito wants to merge 5 commits intojsanchezv:masterfrom
doraemoncito wants to merge 5 commits intojsanchezv:masterfrom
Conversation
There was a problem hiding this comment.
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
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.
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: