Skip to content

Commit f24de99

Browse files
authored
Numerous build and optimisation changes to speedup runtime performance
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
1 parent b6f0596 commit f24de99

19 files changed

Lines changed: 6442 additions & 6272 deletions

.clang-format

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
Language: Cpp
3+
Standard: c++17
4+
BasedOnStyle: LLVM
5+
6+
# Line length
7+
ColumnLimit: 120
8+
9+
# Indentation
10+
IndentWidth: 4
11+
UseTab: Never
12+
IndentCaseLabels: true
13+
IndentPPDirectives: AfterHash
14+
15+
# Spacing
16+
SpaceBeforeParens: ControlStatements
17+
SpaceAfterCStyleCast: false
18+
SpacesInAngles: false
19+
SpaceInEmptyParentheses: false
20+
SpaceBeforeAssignmentOperators: true
21+
22+
# Pointers and references
23+
PointerAlignment: Left
24+
25+
# Braces
26+
BraceWrapping:
27+
AfterCaseLabel: false
28+
AfterClass: false
29+
AfterControlStatement: Never
30+
AfterEnum: false
31+
AfterFunction: false
32+
AfterNamespace: false
33+
AfterStruct: false
34+
AfterUnion: false
35+
AfterExternBlock: false
36+
BeforeCatch: false
37+
BeforeElse: false
38+
BeforeLambdaBody: false
39+
BeforeWhile: false
40+
IndentBraces: false
41+
SplitEmptyFunction: false
42+
SplitEmptyRecord: false
43+
SplitEmptyNamespace: false
44+
45+
# Function definitions
46+
AllowShortFunctionsOnASingleLine: None
47+
SeparateDefinitionBlocks: Always
48+
AllowShortBlocksOnASingleLine: Empty
49+
AllowShortIfStatementsOnASingleLine: Never
50+
AllowShortLoopsOnASingleLine: false
51+
AllowAllArgumentsOnNextLine: true
52+
AllowAllParametersOfDeclarationOnNextLine: true
53+
54+
# Constructor/Destructor
55+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
56+
ConstructorInitializerIndentWidth: 4
57+
Cpp11BracedListStyle: true
58+
59+
# Operators
60+
BreakBeforeBinaryOperators: NonAssignment
61+
BreakBeforeTernaryOperators: true
62+
63+
# Includes
64+
SortIncludes: true
65+
IncludeBlocks: Preserve
66+
67+
# Comments
68+
ReflowComments: true
69+
70+
# Other
71+
AlignAfterOpenBracket: Align
72+
AlignConsecutiveAssignments: None
73+
AlignConsecutiveDeclarations: None
74+
AlignConsecutiveMacros: true
75+
AlignEscapedNewlines: Left
76+
AlignTrailingComments: true
77+
78+
AccessModifierOffset: -2
79+
CompactNamespaces: false
80+
FixNamespaceComments: true
81+
MaxEmptyLinesToKeep: 1
82+
NamespaceIndentation: None

.clang-tidy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
# Clang-tidy configuration for Z80 emulator project
3+
Checks: |
4+
-*,
5+
readability-*,
6+
performance-*,
7+
modernize-*,
8+
bugprone-*,
9+
clang-diagnostic-*,
10+
cppcoreguidelines-*,
11+
google-*,
12+
-readability-magic-numbers,
13+
-readability-uppercase-literal-suffix,
14+
-cppcoreguidelines-avoid-magic-numbers,
15+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
16+
-cppcoreguidelines-pro-type-cstyle-cast,
17+
-cppcoreguidelines-pro-type-reinterpret-cast,
18+
-google-readability-function-size,
19+
-google-runtime-references,
20+
-modernize-use-trailing-return-type,
21+
-cppcoreguidelines-pro-bounds-constant-array-index,
22+
-readability-function-cognitive-complexity,
23+
-readability-function-size
24+
25+
WarningsAsErrors: ''
26+
27+
# Configure individual checks
28+
CheckOptions:
29+
- key: 'readability-function-cognitive-complexity.Threshold'
30+
value: '25'
31+
- key: 'readability-function-size.StatementThreshold'
32+
value: '800'
33+
- key: 'readability-identifier-length.MinimumVariableNameLength'
34+
value: '2'
35+
- key: 'readability-identifier-length.MinimumParameterNameLength'
36+
value: '2'
37+
- key: 'readability-identifier-length.MinimumLoopCounterNameLength'
38+
value: '1'
39+
- key: 'readability-line-length.LineLength'
40+
value: '120'
41+
- key: 'bugprone-easily-swappable-parameters.MinimumLength'
42+
value: '3'
43+
44+
HeaderFilterRegex: '.*'
45+
InheritParentConfig: true

.github/workflows/code-quality.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Code Quality
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
formatting:
7+
name: Check Code Formatting
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Install clang-format
13+
run: sudo apt-get install -y clang-format
14+
15+
- name: Check formatting
16+
run: |
17+
files=$(find include tests -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.tpp" \))
18+
for file in $files; do
19+
clang-format --dry-run -Werror "$file" || exit 1
20+
done
21+
echo "All files are properly formatted!"
22+
23+
static-analysis:
24+
name: Static Analysis with clang-tidy
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Install dependencies
30+
run: |
31+
sudo apt-get update
32+
sudo apt-get install -y clang-tidy cmake build-essential
33+
34+
- name: Build with compile_commands.json
35+
run: |
36+
mkdir -p build
37+
cd build
38+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
39+
make
40+
41+
- name: Run clang-tidy
42+
run: |
43+
cd build
44+
files=$(find ../tests -type f -name "*.cpp")
45+
clang-tidy -p . $files
46+
47+
build:
48+
name: Build Project
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Install dependencies
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install -y cmake build-essential
57+
58+
- name: Build
59+
run: |
60+
mkdir -p build
61+
cd build
62+
cmake ..
63+
make -j4
64+
65+
- name: Run tests
66+
run: |
67+
cd build
68+
ctest --output-on-failure

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
# Editor and OS files
12
.cache/
23
.idea/
34
.vscode/
5+
.DS_Store
6+
7+
# Build directories
48
build*/
9+
10+
# Test ROMs
11+
tests/roms/*
512
tests/roms/*.tap

0 commit comments

Comments
 (0)