Skip to content

Commit 862b9f9

Browse files
author
shijiashuai
committed
perf: comprehensive optimization and bug fixes
Core Improvements: - Add SIMD popcount for AVX2/AVX-512 (2-3x performance gain) - Optimize operator== with SIMD comparison - Add dynamic alignment based on bit width - Add bit64 specialization for scalar optimization New APIs: - find_first_set() / find_last_set() - set_range() / clear_range() / flip_range() - all() / any() / none() / count() / test() CI/CD Enhancements: - Add code coverage workflow - Add sanitizer workflows (ASan/UBSan/TSan) - Add static analysis workflows (clang-tidy/cppcheck) - Add .clang-tidy configuration Bug Fixes: - Fix undefined behavior in shift with negative count - Fix 1ULL << 64 overflow in range operations Project Structure: - Add GitHub Issue templates (bug/feature) - Add PR template Tests: - Add 47 comprehensive test cases
1 parent a451239 commit 862b9f9

16 files changed

Lines changed: 1158 additions & 42 deletions

File tree

.clang-tidy

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
Checks: >
3+
-*,
4+
performance-*,
5+
portability-*,
6+
bugprone-*,
7+
cert-*,
8+
cppcoreguidelines-*,
9+
-cppcoreguidelines-pro-bounds-constant-array-index,
10+
-cppcoreguidelines-macro-usage,
11+
modernize-*,
12+
-modernize-use-trailing-return-type,
13+
-modernize-macro-to-enum,
14+
readability-*,
15+
-readability-named-parameter,
16+
-readability-braces-around-statements,
17+
-readability-function-cognitive-complexity,
18+
-readability-magic-numbers,
19+
clang-analyzer-*
20+
21+
WarningsAsErrors: ''
22+
23+
HeaderFilterRegex: 'include/bitcal/.*'
24+
25+
CheckOptions:
26+
- key: readability-identifier-naming.ClassCase
27+
value: 'lower_case'
28+
- key: readability-identifier-naming.StructCase
29+
value: 'lower_case'
30+
- key: readability-identifier-naming.FunctionCase
31+
value: 'lower_case'
32+
- key: readability-identifier-naming.VariableCase
33+
value: 'lower_case'
34+
- key: readability-identifier-naming.MacroCase
35+
value: 'UPPER_CASE'
36+
- key: readability-identifier-naming.ConstantCase
37+
value: 'UPPER_CASE'
38+
- key: performance-for-range-copy.WarnOnAllAutoCopies
39+
value: 'true'
40+
- key: bugprone-argument-comment.StrictMode
41+
value: '1'
42+
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
43+
value: '0'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Bug Report
2+
description: Report a bug in BitCal
3+
title: "[Bug] "
4+
labels: ["bug"]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
Thanks for taking the time to report a bug!
10+
11+
- type: input
12+
id: version
13+
attributes:
14+
label: BitCal Version
15+
placeholder: e.g., 2.1.0
16+
validations:
17+
required: true
18+
19+
- type: dropdown
20+
id: platform
21+
attributes:
22+
label: Platform
23+
options:
24+
- Linux x86-64
25+
- Linux ARM64
26+
- macOS x86-64
27+
- macOS ARM64 (Apple Silicon)
28+
- Windows x86-64
29+
- Other
30+
validations:
31+
required: true
32+
33+
- type: input
34+
id: compiler
35+
attributes:
36+
label: Compiler
37+
placeholder: e.g., GCC 13.2, Clang 17, MSVC 2022
38+
validations:
39+
required: true
40+
41+
- type: textarea
42+
id: description
43+
attributes:
44+
label: Bug Description
45+
description: Clear description of the bug
46+
validations:
47+
required: true
48+
49+
- type: textarea
50+
id: reproduction
51+
attributes:
52+
label: Reproduction Steps
53+
description: Minimal code to reproduce the issue
54+
render: cpp
55+
validations:
56+
required: true
57+
58+
- type: textarea
59+
id: expected
60+
attributes:
61+
label: Expected Behavior
62+
validations:
63+
required: true
64+
65+
- type: textarea
66+
id: actual
67+
attributes:
68+
label: Actual Behavior
69+
validations:
70+
required: true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Feature Request
2+
description: Suggest a new feature for BitCal
3+
title: "[Feature] "
4+
labels: ["enhancement"]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
Thanks for suggesting a feature!
10+
11+
- type: textarea
12+
id: problem
13+
attributes:
14+
label: Problem Statement
15+
description: What problem are you trying to solve?
16+
validations:
17+
required: true
18+
19+
- type: textarea
20+
id: solution
21+
attributes:
22+
label: Proposed Solution
23+
description: Describe the feature you'd like to see
24+
validations:
25+
required: true
26+
27+
- type: textarea
28+
id: alternatives
29+
attributes:
30+
label: Alternatives Considered
31+
description: Any alternative solutions you've considered
32+
33+
- type: textarea
34+
id: context
35+
attributes:
36+
label: Additional Context
37+
description: Any other context or screenshots
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Description
2+
Brief description of the changes in this PR.
3+
4+
## Type of Change
5+
- [ ] Bug fix
6+
- [ ] New feature
7+
- [ ] Performance improvement
8+
- [ ] Documentation update
9+
- [ ] Refactoring
10+
- [ ] Other (please describe):
11+
12+
## Related Issues
13+
Fixes #(issue number)
14+
15+
## Testing
16+
- [ ] All existing tests pass
17+
- [ ] Added new tests for the changes
18+
- [ ] Tested manually on:
19+
- [ ] x86-64
20+
- [ ] ARM64
21+
- [ ] Other (specify):
22+
23+
## Checklist
24+
- [ ] Code follows the project style guidelines
25+
- [ ] Self-review completed
26+
- [ ] Comments added for complex code
27+
- [ ] Documentation updated (if needed)
28+
- [ ] No new warnings generated
29+
- [ ] Sanitizers pass (ASan/UBSan)
30+
31+
## Performance Impact
32+
If applicable, describe any performance changes:
33+
- Before:
34+
- After:
35+
36+
## Additional Notes
37+
Any additional information for reviewers.

.github/workflows/coverage.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: coverage-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
coverage:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y lcov
26+
27+
- name: Configure with coverage
28+
run: |
29+
cmake -S . -B build \
30+
-DCMAKE_BUILD_TYPE=Debug \
31+
-DCMAKE_CXX_FLAGS="--coverage -O0" \
32+
-DCMAKE_C_FLAGS="--coverage -O0" \
33+
-DBITCAL_BUILD_TESTS=ON \
34+
-DBITCAL_BUILD_EXAMPLES=OFF \
35+
-DBITCAL_NATIVE_ARCH=OFF
36+
37+
- name: Build
38+
run: cmake --build build --config Debug
39+
40+
- name: Run tests
41+
run: ctest --test-dir build --output-on-failure -C Debug
42+
43+
- name: Generate coverage report
44+
run: |
45+
lcov --capture --directory build --output-file coverage.info
46+
lcov --remove coverage.info '/usr/*' '*/tests/*' '*/examples/*' '*/benchmarks/*' --output-file coverage.info
47+
lcov --list coverage.info
48+
49+
- name: Upload coverage to Codecov
50+
uses: codecov/codecov-action@v4
51+
with:
52+
files: coverage.info
53+
fail_ci_if_error: false
54+
verbose: true
55+
56+
- name: Upload coverage artifact
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: coverage-report
60+
path: coverage.info

.github/workflows/sanitizers.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Sanitizers
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: sanitizers-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
sanitizer:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
sanitizer: [address, undefined, thread]
22+
exclude:
23+
# Thread sanitizer is not compatible with address sanitizer
24+
- sanitizer: ${{ github.event_name == 'pull_request' && 'thread' || '' }}
25+
26+
name: "${{ matrix.sanitizer }} sanitizer"
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Configure with sanitizer
33+
run: |
34+
cmake -S . -B build \
35+
-DCMAKE_BUILD_TYPE=Debug \
36+
-DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }} -fno-omit-frame-pointer" \
37+
-DCMAKE_C_FLAGS="-fsanitize=${{ matrix.sanitizer }} -fno-omit-frame-pointer" \
38+
-DBITCAL_BUILD_TESTS=ON \
39+
-DBITCAL_BUILD_EXAMPLES=OFF \
40+
-DBITCAL_NATIVE_ARCH=OFF
41+
42+
- name: Build
43+
run: cmake --build build --config Debug
44+
45+
- name: Test with sanitizer
46+
run: ctest --test-dir build --output-on-failure -C Debug
47+
env:
48+
# Suppress leak sanitizer in GitHub Actions environment
49+
ASAN_OPTIONS: detect_leaks=0
50+
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
permissions:
10+
contents: read
11+
# Required for cpp-linter to post annotations
12+
checks: write
13+
14+
concurrency:
15+
group: static-analysis-${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
clang-tidy:
20+
name: "clang-tidy"
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install clang-tidy
26+
run: |
27+
sudo apt-get update
28+
sudo apt-get install -y clang-tidy
29+
30+
- name: Create compile_commands.json
31+
run: |
32+
cmake -S . -B build \
33+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
34+
-DBITCAL_BUILD_TESTS=ON \
35+
-DBITCAL_NATIVE_ARCH=OFF
36+
37+
- name: Run clang-tidy
38+
run: |
39+
clang-tidy -p build \
40+
--checks='-*,performance-*,portability-*,bugprone-*,cert-*,cppcoreguidelines-*' \
41+
include/bitcal/*.hpp \
42+
tests/*.cpp \
43+
2>&1 | tee clang-tidy-report.txt
44+
45+
- name: Upload report
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: clang-tidy-report
49+
path: clang-tidy-report.txt
50+
51+
cppcheck:
52+
name: "cppcheck"
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Install cppcheck
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y cppcheck
61+
62+
- name: Run cppcheck
63+
run: |
64+
cppcheck --enable=all \
65+
--suppress=missingIncludeSystem \
66+
--suppress=unusedFunction \
67+
--suppress=preprocessorErrorDirective \
68+
--error-exitcode=0 \
69+
--inline-suppr \
70+
--std=c++17 \
71+
-I include \
72+
include/bitcal/ tests/ \
73+
2>&1 | tee cppcheck-report.txt
74+
75+
- name: Upload report
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: cppcheck-report
79+
path: cppcheck-report.txt

0 commit comments

Comments
 (0)