Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bit manipulation instructions #344

Draft
wants to merge 515 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
515 commits
Select commit Hold shift + click to select a range
8ad3667
bug test for lwsp
Jun 17, 2024
2a4374f
changes to make tests run correctly
leekillough Jun 18, 2024
5878cf6
fix for #289
Jun 18, 2024
6d957c5
added bug test to regression list
Jun 18, 2024
75a9e00
cleaned up test files
Jun 18, 2024
93071b7
Merge pull request #290 from tactcomplabs/lwsp
kpgriesser Jun 18, 2024
20fe41c
comment out new test until issue with Jenkins is resolved
kpgriesser Jun 18, 2024
2a23b3b
put back lwsp test
Jun 18, 2024
9b8d8f7
simplified makefile for testing
Jun 18, 2024
0b91d89
Pass RVCXX to tests; use ${RVCXX} instead of hard-coded compiler; fix…
leekillough Jun 18, 2024
0fb9e35
update docs
leekillough Jun 19, 2024
05c8987
Merge pull request #291 from tactcomplabs/fix_rvcxx
leekillough Jun 19, 2024
261ac93
Merge remote-tracking branch 'tcl/devel' into fenv
leekillough Jun 19, 2024
bcc105c
fix exception handling
leekillough Jun 19, 2024
2e0f3b2
fix compilation errors
leekillough Jun 20, 2024
d45b52f
formatting
leekillough Jun 20, 2024
8fffff0
add execute permission to scripts
leekillough Jun 20, 2024
1efbb2e
change variable to static
leekillough Jun 20, 2024
191575d
change how printing results is done
leekillough Jun 20, 2024
6376c22
remove suspected cause of segfault
leekillough Jun 20, 2024
f63127e
fix reading of frm; format text
leekillough Jun 20, 2024
bc4c584
Add comment
leekillough Jun 20, 2024
6a63565
Tune maxmimum number of tests per executable; increase timeout
leekillough Jun 20, 2024
8f5d26b
change timeouts
leekillough Jun 20, 2024
1bfaac5
Fix fsrm instruction; reformat templates; reduce the number of combin…
leekillough Jun 20, 2024
be24abb
add rdcycle test
leekillough Jun 20, 2024
dc34a33
Decrease timeout
leekillough Jun 20, 2024
b97782a
parallelize fenv tests
leekillough Jun 20, 2024
24cf7dd
parallelize tests; fix bug in test CMakeLists.txt
leekillough Jun 21, 2024
a39cdca
Add CSR instruction tests
leekillough Jun 21, 2024
d071f26
comment out code which might be causing crashes
leekillough Jun 21, 2024
254ebe4
reduce timeout of CSR test
leekillough Jun 21, 2024
ef58ea4
Test conversions from {float, double} to {int32_t, uint32_t, int64_t,…
leekillough Jun 21, 2024
5dabc7e
fix fp -> integer conversion tests
leekillough Jun 21, 2024
f98a37b
Fix CSR test values; tweak FP->Integer rounding operands
leekillough Jun 21, 2024
866a5e4
fix syntax error
leekillough Jun 21, 2024
4f5a6ba
fix FMA test to use fmadd instruction directly
leekillough Jun 22, 2024
f0792df
remove extra space
leekillough Jun 22, 2024
becce21
Add more values to test FP->INT conversion
leekillough Jun 24, 2024
501f249
Add TEST_LEVEL variable to control which tests are run
leekillough Jun 24, 2024
a484f7f
Merge branch 'test_level' into fenv
leekillough Jun 24, 2024
97d47cc
remove "all" label
leekillough Jun 24, 2024
61ead35
Merge pull request #294 from tactcomplabs/test_level
leekillough Jun 24, 2024
7129bc8
Merge remote-tracking branch 'tcl/devel' into fenv
leekillough Jun 24, 2024
f388afd
decrease test timeout
leekillough Jun 24, 2024
829ff60
fix test_level
leekillough Jun 24, 2024
dd21599
Support non-canonical forms of rdcycle[h], rdtime[h], rdinstret[h]
leekillough Jun 24, 2024
e6d7b86
change comparison syntax
leekillough Jun 24, 2024
8cdadb2
remove unused variable, change docs
leekillough Jun 24, 2024
faf2b52
Merge branch 'test_level' into fenv
leekillough Jun 24, 2024
ca644cb
fix comment
leekillough Jun 24, 2024
3047175
Handle read-only CSRs
leekillough Jun 24, 2024
aa36b3a
Merge branch 'test_level' into devel
leekillough Jun 24, 2024
2f531e5
Merge remote-tracking branch 'tcl/devel' into fenv
leekillough Jun 24, 2024
25b40da
fix typo
leekillough Jun 24, 2024
ba92c11
change order of operations
leekillough Jun 24, 2024
c463d96
Add non-canonical reads of performance counters
leekillough Jun 24, 2024
8726cf4
change order of operations in CSR modification
leekillough Jun 24, 2024
363379c
simplify CSR function
leekillough Jun 24, 2024
7ddce64
Simplify fclass, using names for number classes
leekillough Jun 24, 2024
beda7f5
Merge pull request #238 from tactcomplabs/fenv
leekillough Jun 25, 2024
37f0382
Remove "all" tag
leekillough Jun 25, 2024
45cbad0
Fix stack to always be aligned on 16 bytes
leekillough Jun 25, 2024
5f80fff
Merge pull request #296 from tactcomplabs/fix_stack_alignment
leekillough Jun 25, 2024
4b71c79
Refactor the performance counters code so that the operation of
leekillough Jun 25, 2024
5511c14
Merge pull request #295 from tactcomplabs/remove_all_label
leekillough Jun 25, 2024
1590af2
Merge pull request #297 from tactcomplabs/refactor_perf_counters
leekillough Jun 25, 2024
b604229
Fix stack and thread local storage allocation
leekillough Jun 25, 2024
51ff62c
Merge pull request #298 from tactcomplabs/fix_stack_thread_allocation
leekillough Jun 25, 2024
416b31a
Add support for extension versions
leekillough Jun 26, 2024
b7904b7
change default versions to be per-extension
leekillough Jun 27, 2024
93c8eaa
fix order, temporarily disable Zfa
leekillough Jun 29, 2024
5a32dc8
Merge pull request #300 from tactcomplabs/extension_versions
leekillough Jul 2, 2024
c68b3c1
Zfa functionality
leekillough Jul 6, 2024
2ea65d9
Disable Zfa tests if Zfa is not supported in the toolchain
leekillough Jul 7, 2024
508872f
Disable RV32 tests if RV32 is not supported in the toolchain
leekillough Jul 8, 2024
17f4c6e
Merge pull request #301 from tactcomplabs/Zfa
leekillough Jul 8, 2024
a45c362
misc fixes
leekillough Jul 9, 2024
1b49fc9
change tests to be disabled instead of left out
leekillough Jul 9, 2024
d37e24a
get rid of warnings in some toolchains
leekillough Jul 10, 2024
8d28838
Fix comment
leekillough Jul 11, 2024
648680c
increase timeouts
leekillough Jul 11, 2024
fced652
temporarily increase timeout
leekillough Jul 11, 2024
65f8fbb
set timeouts
leekillough Jul 11, 2024
501dc4f
change syntax to avoid warnings
leekillough Jul 11, 2024
1c9f355
Merge pull request #302 from leekillough/misc_fixes
leekillough Jul 11, 2024
ccf1044
Addd csrs pseudoinstruction
leekillough Jul 17, 2024
1484539
Merge pull request #303 from tactcomplabs/csrs_pseudoinstruction
leekillough Jul 17, 2024
8f56671
Zmmul extension
leekillough Jul 17, 2024
9af3bd4
Merge pull request #305 from tactcomplabs/Zmmul
leekillough Jul 18, 2024
6e36520
fully templatize floating-point helper fundtions
leekillough Jul 18, 2024
d883ffc
Merge remote-tracking branch 'tcl/devel' into templatize_helpers
leekillough Jul 18, 2024
1c0ddb0
Merge pull request #306 from tactcomplabs/templatize_helpers
leekillough Jul 18, 2024
deee736
Revert "Fully templatize floating-point helper functions"
leekillough Jul 18, 2024
c178e1e
Merge pull request #307 from tactcomplabs/revert-306-templatize_helpers
leekillough Jul 18, 2024
adb783d
fully templatize floating-point helper fundtions
leekillough Jul 18, 2024
f813fa0
remove float16
leekillough Jul 18, 2024
0169016
Increase timeout
leekillough Jul 19, 2024
964066f
Merge pull request #308 from tactcomplabs/templatize_helpers2
leekillough Jul 19, 2024
56fa725
list CSR registers by name
leekillough Jul 31, 2024
b2f29ef
Fix LR/SC and split A into Zaamo and Zalrsc
leekillough Aug 24, 2024
28e53cc
fix swap
leekillough Aug 30, 2024
16e65f1
Merge pull request #310 from tactcomplabs/CSRReg
leekillough Aug 30, 2024
18a7c54
Merge remote-tracking branch 'tcl/devel' into Zaamo_Zalrsc
leekillough Aug 30, 2024
c3dee3c
Merge pull request #313 from tactcomplabs/Zaamo_Zalrsc
leekillough Aug 30, 2024
db35996
Make feature pointers pointers to const RevFeature
leekillough Sep 5, 2024
c77ffd1
change spacing to be more consistent
leekillough Sep 5, 2024
f1f3978
add const
leekillough Sep 6, 2024
ba8902d
Make RevFeature* const in more places; consolidate RevFeature initial…
leekillough Sep 6, 2024
158a520
Use enum instead of macros; fix bug where cbo.clean and cbo.flush wer…
leekillough Sep 6, 2024
0f3b15f
Make RevImmFunc an enum class for better correctness
leekillough Sep 7, 2024
b0af064
Merge pull request #317 from tactcomplabs/constFeature
leekillough Sep 7, 2024
fba5745
Merge remote-tracking branch 'tcl/devel' into fixZicbom
leekillough Sep 8, 2024
140039e
Merge remote-tracking branch 'tcl/devel' into spacing
leekillough Sep 8, 2024
cc7170e
redo changes, this time with Python reindent tool
leekillough Sep 9, 2024
5930731
change names to be consistent
leekillough Sep 9, 2024
3244471
Merge pull request #318 from tactcomplabs/spacing
leekillough Sep 9, 2024
dbe5033
Merge remote-tracking branch 'tcl/devel' into consistent_naming
leekillough Sep 9, 2024
8fa9a57
Merge remote-tracking branch 'tcl/devel' into fixZicbom
leekillough Sep 9, 2024
6273c34
Merge pull request #320 from tactcomplabs/fixZicbom
leekillough Sep 13, 2024
5a92980
Add flake8 and shellcheck checks for pre-commit
leekillough Sep 13, 2024
b24085a
Merge remote-tracking branch 'tcl/devel' into consistent_naming
leekillough Sep 13, 2024
c0a2718
change warnings
leekillough Sep 13, 2024
7d73867
Merge pull request #316 from tactcomplabs/consistent_naming
leekillough Sep 13, 2024
1281896
fast printf implementation
leekillough Sep 17, 2024
18ccf04
remove asprintf; use REV_SYSCALL macro
leekillough Sep 17, 2024
35eb6ba
Merge pull request #322 from leekillough/fastprint
leekillough Sep 17, 2024
012bc4a
Fix rev_fast_printf
leekillough Sep 18, 2024
5f88d76
Print warnings about C++ filename extensions
leekillough Sep 18, 2024
1d0740c
simplify code
leekillough Sep 18, 2024
d52e4f7
Add pre-commit to shell files checked
leekillough Sep 18, 2024
24bbb4e
Merge pull request #324 from tactcomplabs/fix_fast_printf
leekillough Sep 18, 2024
9a92ec4
Merge pull request #325 from tactcomplabs/cpp_warning
leekillough Sep 18, 2024
7ad4c91
rev-fast-printf post-processing script and test
Sep 19, 2024
b5b85c3
Overhaul of CSR functionality
leekillough Sep 20, 2024
d68c417
remove unnecessary template
leekillough Sep 20, 2024
e348c9e
simplify CSR with GetCore() pure virtual
leekillough Sep 20, 2024
8011c27
fix RevZicntr member access
leekillough Sep 20, 2024
a2e138c
force initialization of pointer member
leekillough Sep 20, 2024
aa14475
add #include
leekillough Sep 20, 2024
113201b
increase timeout
leekillough Sep 20, 2024
8a2ed82
Remove unnecessary path to RevCommon.h
leekillough Sep 20, 2024
3df73c8
Merge pull request #327 from tactcomplabs/modular_csr
leekillough Sep 20, 2024
e3c4a8d
Clean up shellcheck warnings
leekillough Sep 20, 2024
40f3812
improve instructions on how to install flake8 and shellcheck
leekillough Sep 20, 2024
c5af147
Move test of read-only CSR to SetCSR()
leekillough Sep 23, 2024
6ca3a9f
Merge pull request #329 from tactcomplabs/SetCSR
leekillough Sep 23, 2024
5fc14d1
Merge remote-tracking branch 'tcl/devel' into cleanup_shellcheck_errors
leekillough Sep 23, 2024
365fbe4
make missing flake8 / shellcheck fatal error
leekillough Sep 23, 2024
4464d37
remove unbound variable error
leekillough Sep 23, 2024
eaf1fe4
Merge pull request #328 from tactcomplabs/cleanup_shellcheck_errors
leekillough Sep 23, 2024
1f42af3
remove --color option from flake8
leekillough Sep 24, 2024
83414a2
Merge pull request #330 from tactcomplabs/flake8_colors
leekillough Sep 25, 2024
eb477ad
fix brace nesting in if statement; simplify code to use memcpy()
leekillough Oct 4, 2024
d37c4ef
Merge pull request #332 from tactcomplabs/handleFlagResp
leekillough Oct 4, 2024
2d91a43
Refactor read/write functions
leekillough Oct 4, 2024
46ef557
adding sst 14.1.0 buold scripts
jleidel Oct 18, 2024
d820d3d
Merge pull request #333 from tactcomplabs/MemH_paging
leekillough Oct 21, 2024
b1f4f67
zicntr updates for tracer testing
Oct 21, 2024
563b73f
added checks for sign extending LW in RV64 mode
Oct 22, 2024
ee6b586
Add function to do safe casts from enum->int and int->int
leekillough Oct 25, 2024
3508bc2
Merge pull request #335 from tactcomplabs/safe_enum_int_cast
leekillough Oct 25, 2024
5e86220
Merge branch 'devel' into tracer
Nov 4, 2024
fe40402
Testing updates. Added trace testing for ld/st sign extension. Added …
Nov 4, 2024
1236828
tracer memory sign extension test
Nov 4, 2024
a4851a7
use local branch mnemonics for assembly
Nov 4, 2024
a23294a
Make pre-commit script handle missing or old version of shellcheck be…
leekillough Nov 4, 2024
4f3b402
Fix casting in SetX
leekillough Nov 4, 2024
d393598
Merge pull request #339 from tactcomplabs/SetX_type_bug
jleidel Nov 4, 2024
e1da5af
Merge pull request #338 from tactcomplabs/smart_shellcheck
leekillough Nov 5, 2024
eb457be
updates from tracer PR#336 feedback
Nov 6, 2024
b465ded
Merge pull request #336 from tactcomplabs/tracer
kpgriesser Nov 6, 2024
0a5245d
Add warnings suggesting format and noreturn attributes
leekillough Nov 10, 2024
22cc141
Add functions for optionally setting CSR Getters/Setters; reword and …
leekillough Nov 26, 2024
43c6eab
Change API for CSR Getters/Setters; add RevCore CSR Getters/Setters
leekillough Nov 27, 2024
cdb75a0
add comments
leekillough Nov 27, 2024
d7ce6c7
handle nullified getter/setter entries the same as missing entries
leekillough Nov 27, 2024
1f33fb5
Add make_dependent<>() utility function; simplify code
leekillough Nov 29, 2024
12be53a
Erase CSR Getter/Setter entries when set to nullptr
leekillough Dec 1, 2024
45bf5eb
Improve wording and formatting of comments
leekillough Dec 1, 2024
42aeb20
simplify code, move get Getter/Setter functions to be public
leekillough Dec 1, 2024
a0db981
Macroize fli instruction table generation
leekillough Dec 2, 2024
0135523
Handle iconv errors more gracefully
leekillough Dec 3, 2024
9e25a52
Merge pull request #343 from tactcomplabs/iconv_error
leekillough Dec 3, 2024
ff48be4
undefine macros at end of Zfa.h
leekillough Dec 3, 2024
5fa8d53
Merge pull request #341 from tactcomplabs/CSR_handlers
leekillough Dec 3, 2024
6754598
Merge remote-tracking branch 'rev/devel' into macroize_fli
leekillough Dec 4, 2024
a13e636
Merge remote-tracking branch 'rev/devel' into suggest_override_final
leekillough Dec 4, 2024
f730d3d
fix warnings
leekillough Dec 4, 2024
1309732
remove -DBUILD_ASM_TESTING=ON
leekillough Dec 4, 2024
cd5fa0a
Add -Wno-mismatched-tags
leekillough Dec 4, 2024
9b3323d
fix spelling of -Wno-mismatched-tags
leekillough Dec 4, 2024
3c54f06
change warning options
leekillough Dec 4, 2024
749672c
remove more warnings
leekillough Dec 4, 2024
a9893c9
Remove Clang warnings
leekillough Dec 4, 2024
7d65d3a
remove more warnings
leekillough Dec 4, 2024
0cd27cc
Revert "Add -Wno-mismatched-tags"
leekillough Dec 4, 2024
b975338
Merge pull request #342 from tactcomplabs/macroize_fli
leekillough Dec 4, 2024
9f7eacb
Merge pull request #340 from tactcomplabs/suggest_override_final
leekillough Dec 4, 2024
ea27d8d
Add bit functions BitExtract(), BitDeposit() and BitShift()
leekillough Dec 5, 2024
55ff155
Suppress warnings about promoting 16-bit compressed instructions to 3…
leekillough Dec 5, 2024
a1d263e
Enable -Werror; git rid of one warning
leekillough Dec 5, 2024
1986a9c
Make sure file extensions and shebangs are as expected; check for com…
leekillough Dec 5, 2024
9a33fb0
remove unnecessary integer suffixes
leekillough Dec 5, 2024
f3bd01f
disable some warnings
leekillough Dec 6, 2024
a6f3136
use -Wno-macro-redefined
leekillough Dec 6, 2024
7a595dd
fix printf formats; use uint32_t or uint64_t instead of unsigned
leekillough Dec 6, 2024
3680a8f
change unsigned to uint32_t
leekillough Dec 6, 2024
6905165
Merge pull request #345 from tactcomplabs/SafeSignedNess
leekillough Dec 6, 2024
de9c843
change permissions
leekillough Dec 6, 2024
9e41bae
change shebang to /usr/bin/env python3
leekillough Dec 6, 2024
bf4d1f8
Merge remote-tracking branch 'rev/devel' into Warnings
leekillough Dec 6, 2024
ac807d7
minor fixes
leekillough Dec 7, 2024
9506e4d
Remove redundant parentheses; use BitExtract() in more places; shorte…
leekillough Dec 7, 2024
078c92e
Merge pull request #346 from tactcomplabs/Warnings
leekillough Dec 8, 2024
8bf6deb
Merge pull request #347 from tactcomplabs/Small_fixes
leekillough Dec 9, 2024
d4a4e70
Move common file changes out of RVV to minimize conflicts
leekillough Dec 10, 2024
3071b4f
Merge pull request #348 from tactcomplabs/vector_subtree
leekillough Dec 11, 2024
41293c1
fix shebang warning to include python3 instead of python
leekillough Dec 14, 2024
26bba90
change pre-commit handling of itself
leekillough Dec 15, 2024
2435756
Merge pull request #349 from tactcomplabs/shebang
leekillough Dec 16, 2024
b9085a8
Merge pull request #350 from tactcomplabs/pre-commit
leekillough Dec 16, 2024
99cf400
Fix double-precision FLI instructions which were mixing single- and d…
leekillough Dec 19, 2024
7d15916
Remove duplicate code in RevOpts
leekillough Dec 23, 2024
b428f48
Merge pull request #351 from tactcomplabs/zfa
leekillough Dec 23, 2024
6b7a3af
Remove duplicate code in RevOpts
leekillough Dec 23, 2024
3a7f890
Merge remote-tracking branch 'rev/devel' into SimplifyRevOpts
leekillough Dec 23, 2024
4eb3057
Simplify API since the CORES:* logic is always followed by the genera…
leekillough Dec 24, 2024
d208318
add space delimiters; clean up new templates
leekillough Dec 24, 2024
278c9c9
Add header
leekillough Dec 27, 2024
7312fae
change loop iter type to size_t
leekillough Dec 27, 2024
a89f14d
add const to getters; delete copy/assignment
leekillough Dec 27, 2024
884fdd4
optimize string moves to vector and map
leekillough Dec 28, 2024
ceacdb2
Add make_dependent<> to cause lazy evaluation in if-constexpr blocks
leekillough Dec 28, 2024
04f4db7
Add more types to make_dependent<> for more lazy evaluation
leekillough Dec 28, 2024
cb7cacc
simplify make_dependent
leekillough Dec 28, 2024
e2e3116
minor optimizations
leekillough Dec 28, 2024
df1584f
fix comment
leekillough Dec 28, 2024
b6f1a9c
Add const to avoid accidentally modifying reference
leekillough Jan 1, 2025
b614da2
Compress RevFlag so that atomic operations take fewer bits
leekillough Jan 6, 2025
5a33f44
Merge pull request #353 from tactcomplabs/compress_revflags
leekillough Jan 6, 2025
fddeb8a
Merge remote-tracking branch 'rev/devel' into SimplifyRevOpts
leekillough Jan 6, 2025
55f8d37
Merge pull request #352 from tactcomplabs/SimplifyRevOpts
leekillough Jan 7, 2025
f4a1a7f
use regular expressions to match MIME types
leekillough Jan 7, 2025
a1dfa7f
Merge pull request #354 from tactcomplabs/python_mime
leekillough Jan 7, 2025
afc9eab
Add sanity checks for assumptions about instruction tables
leekillough Jan 9, 2025
df83e82
Merge pull request #356 from tactcomplabs/sanity_checking
leekillough Jan 9, 2025
724f4bd
Enable -Wconversion warnings to avoid inadvertent lowering conversions
leekillough Jan 10, 2025
e20036f
fix type mismatch in regRead() and regWrite(); simplify emplace_back(…
leekillough Jan 10, 2025
a6efaaf
Merge pull request #358 from tactcomplabs/conversions
leekillough Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
74 changes: 74 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
BasedOnStyle: LLVM
Standard: c++17
ColumnLimit: 132
UseTab: Never
UseCRLF: false
AlignEscapedNewlines: Left
AllowShortFunctionsOnASingleLine: Inline
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
BinPackArguments: false
AllowAllArgumentsOnNextLine: true
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: true
BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
ConstructorInitializerIndentWidth: 2
BreakConstructorInitializers: BeforeColon
ContinuationIndentWidth: 2
FixNamespaceComments: true
IndentWrappedFunctionNames: true
SortIncludes: true
SpaceBeforeParens: Never
SpacesInAngles: Never
SpacesInParentheses: true
SpacesInSquareBrackets: false
SpacesInConditionalStatement: true
SpacesInCStyleCastParentheses: false
SpaceInEmptyParentheses: false
SpaceAfterTemplateKeyword: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCaseColon: false
SpaceBeforeAssignmentOperators: true
SpaceAfterLogicalNot: false
SpaceAfterCStyleCast: true
SpaceAroundPointerQualifiers: Default
PointerAlignment: Left
DerivePointerAlignment: false
ReferenceAlignment: Pointer
InsertTrailingCommas: Wrapped
MaxEmptyLinesToKeep: 1
AlignTrailingComments: true
SpacesBeforeTrailingComments: 2
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: AcrossEmptyLinesAndComments
AlignConsecutiveDeclarations: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
AlignAfterOpenBracket: BlockIndent
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
AlignOperands: Align
ReflowComments: false
SeparateDefinitionBlocks: Always
EmptyLineBeforeAccessModifier: LogicalBlock
313 changes: 313 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
#!/bin/bash
#
# This pre-commit hook reformats text files to meet coding guidelines.
#
# Based on https://github.com/rocm/rocBLAS
#
# shellcheck enable=all
# shellcheck disable=2034,2059,2064,2250,2310,2312

set_shell_options() {
set -eEu -o pipefail
shopt -s nocasematch
export PATH=$PATH:/usr/bin:/bin
exec >&2
}

# Terminal colors
set_colors() {
if [[ -z ${NO_COLOR+x} ]] && tty -s <&2; then
RED="\033[91m"
YELLOW="\033[93m"
GREEN="\033[92m"
END="\033[0m"
else
RED=
YELLOW=
GREEN=
END=
fi
}

usage() {
cat<<EOF
Usage: pre-commit [ --reformat] [ --nostage ] [ file1 ] [ file2 ] [ file3 ] ...

Format files prior to commit so that they match style guidelines

Normally called before commit, but if files are explicitly specified, reformats
them in-place without respect to commits.

Options:
--reformat Reformat all files in the source tree, rather than staged files
--nostage Do not add files modified by pre-commit to the staging area
EOF
exit 1
}

# Parse command-line options
parse_options() {
FILES=()
REFORMAT=
NOSTAGE=
EXPLICIT_FILES=
local endopts=
for opt in "$@"; do
if [[ -n $endopts ]]; then
FILES+=("$opt")
else
case $opt in
--) endopts=1 ;;
--reformat) REFORMAT=1 ;;
--nostage) NOSTAGE=1 ;;
-*) usage ;;
*) FILES+=("$opt")
esac
fi
done
if [[ ${#FILES[@]} -ne 0 ]]; then
EXPLICIT_FILES=1
NOSTAGE=1
fi
}

# How to install a package
howto_install() {
package=$1

INSTALL=
if [[ $OSTYPE = darwin* ]]; then
if command -v brew >/dev/null; then
INSTALL="brew install $package"
fi
elif [[ $OSTYPE = linux* ]]; then
if [[ -f /etc/redhat-release ]]; then
if command -v dnf >/dev/null; then
INSTALL="sudo dnf install $package"
elif command -v yum >/dev/null; then
if [[ $package = shellcheck ]]; then
package=ShellCheck
fi
INSTALL="sudo yum install $package"
fi
elif [[ -f /etc/debian_version ]] && command -v apt-get >/dev/null; then
INSTALL="sudo apt-get install $package"
fi
fi
if [[ -n $INSTALL ]]; then
printf "${YELLOW}\nTo install $package, run:\n\n%s\n\n${END}" "$INSTALL"
else
printf "${YELLOW}\nInstall $package and make sure it is in PATH.\n\n${END}"
fi
}

# Check for existence of clang-format or print error message on how to install
check_clang_format() {
if ! command -v clang-format >/dev/null; then
printf "${RED}\nError: clang-format not found\n${END}"
howto_install clang-format
exit 1
fi
}

# Test a file for changes and add them to the Git commit if changed
detect_change() {
if ! cmp -s "$1" "$2"; then
printf "${YELLOW}$3${END}\n" "$1"
cp -f "$2" "$1"
if [[ -z $EXPLICIT_FILES && -z $NOSTAGE ]]; then
git add -u "$1"
fi
fi
}

# Generate list of modified files
# If --reformat is used, all files are reformatted
get_files() {
if [[ -n $EXPLICIT_FILES ]]; then
# cd to this script's directory before running clang-format
# so that the .clang-format from this script's repo is used
REPO=$(dirname "$0")
else
# Do everything from top level
REPO=$(git rev-parse --show-toplevel)
cd "$REPO"
if [[ -n $REFORMAT ]]; then
while IFS= read -r -d $'\0' FILE; do
FILES+=("$FILE")
done < <(git ls-files -z --exclude-standard)
else
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against initial commit
against=$(git log --reverse --pretty=format:%H | head -1)
fi
while IFS= read -r -d $'\0' FILE; do
FILES+=("$FILE")
done < <(git diff-index -z --cached --name-only "$against")
fi
fi
}

# Test if argument is a text file
# git grep tests whether Git considers it a text file
# If files were explicitly specified, they are assumed to be text files
is_text_file() {
[[ -n $EXPLICIT_FILES ]] || git grep -Iqe . -- "$1"
}

# Test if argument is a C/C++ file
is_cxx_file() {
local file=$1
trap "$(shopt -p nocasematch)" RETURN
shopt -u nocasematch
case $file in
*.c|*.h|*.cc) true ;;
*.hpp) printf "${RED}${file}: Error: C++ header files should have .h extension instead of .hpp${END}\n\n"
errors=true ;;
*.cxx) printf "${RED}${file}: Error: C++ source files should have .cc extension instead of .cxx${END}\n\n"
errors=true ;;
*.cpp) printf "${RED}${file}: Error: C++ source files should have .cc extension instead of .cpp${END}\n\n"
errors=true ;;
*.C) printf "${RED}${file}: Error: C++ source files should have .cc extension instead of .C${END}\n\n"
errors=true ;;
*) false
esac
}


# Check for redundant C++ directives
check_override_final() {
local file=$1 err
if err=$(grep -Hno "^[^/].*\bvirtual\b.*\boverride\b" "$file"); then
printf "${err}\n${RED}Error: virtual keyword is redundant with override directive${END}\n\n"
errors=true
elif err=$(grep -Hno "^[^/].*\bvirtual\b.*\bfinal\b" "$file"); then
printf "${err}\n${RED}Error: If final directive is used, virtual should not be specified${END}\n\n"
errors=true
elif err=$(grep -Hno "^[^/].*\boverride\b.*\bfinal\b" "$file") || err=$(grep -Hno "\bfinal\b.*\boverride\b" "$file"); then
printf "${err}\n${RED}Error: If final directive is used, override is redundant${END}\n\n"
errors=true
fi
}

# Check for correct magic and filename extensions
# filename extension mime-type shebang
check_extension() {
local file=$1 ext=$2 mimetype=$3 shebang=$4 instead
trap "$(shopt -p nocasematch)" RETURN
shopt -u nocasematch
if [[ ! $(file -Lb --mime-type "$1") =~ ${mimetype} ]]; then
if [[ $file = *$ext ]]; then
printf "\n${RED}${file}: Error: Not recognized as ${mimetype}.\n${shebang:+Make sure that shebang ${shebang} is at the top of ${file}.\n}${END}"
errors=true
fi
elif [[ $file != *$ext ]]; then
instead=$( if [[ $file = *.* ]]; then echo "instead of .${file##*.}"; fi )
printf "\n${RED}${file}: Error: ${mimetype} filenames should have $ext extension ${instead}${END}\n"
errors=true
fi
}

reformat_files() {
# Temporary file for reformatting
temp=$(mktemp)
trap 'rm -f "$temp"' EXIT

# Get the list of files into FILES
get_files

# Fix formatting on text files
if [[ ${#FILES[@]} -eq 0 ]]; then
return 0
fi

errors=false
shellcheck_warning=

# Fix formatting on text files
for file in "${FILES[@]}"; do
if [[ -f $file ]] && is_text_file "$file"; then
# Replace non-ASCII characters with ASCII equivalents
if ! iconv -s -f utf-8 -t ascii//TRANSLIT "$file" > "$temp"; then
cat <<EOF
${YELLOW}iconv -f utf-8 -t ascii//TRANSLIT "$file" > "$temp"${END}
EOF
iconv -f utf-8 -t ascii//TRANSLIT "$file" > "$temp" || true
fold -s -w79 <<EOF
${RED}Some non-ASCII characters in $file could not be converted into equivalent
ASCII characters. Please replace non-ASCII characters in $file and try again.${END}
EOF
exit 1
fi

detect_change "$file" "$temp" "%s: Converting non-ASCII characters to ASCII equivalents"

# Change the copyright date at the top of any text files
perl -e ''
if perl -pe 'INIT { exit 1 if !-f $ARGV[0] || -B $ARGV[0]; $year = (localtime)[5] + 1900 } s/^([*\/#\/"*[:space:]]*)Copyright\s+(?:\(C\)\s*)?(\d+)(?:\s*-\s*\d+)?(?=\s+Tactical Computing)/qq($1Copyright (C) $2@{[$year != $2 ? "-$year" : ""]})/ie if $. < 10' "$file" > "$temp"; then
detect_change "$file" "$temp" "%s: Changing copyright date"
fi

# Run clang-format on C/C++ files
if is_cxx_file "$file"; then
check_clang_format
(cd "$REPO" && clang-format) < "$file" > "$temp"
detect_change "$file" "$temp" "%s: Reformatting with clang-format according to coding guidelines"
check_override_final "$file"
fi

# Remove trailing whitespace at end of lines
sed -e 's/[[:space:]]*$//' < "$file" > "$temp"
detect_change "$file" "$temp" "%s: Removing trailing whitespace at line endings"

# Add missing newline at EOF
awk 1 < "$file" > "$temp"
detect_change "$file" "$temp" "%s: Adding missing newline at end of file"

# check filename extensions and magic
if [[ $file != **/pre-commit ]]; then
check_extension "$file" ".sh" "^text/x-shellscript$" "#!/bin/bash"
check_extension "$file" ".py" "^text/x-script\.python|text/x-python$" "#!/usr/bin/env python3"
check_extension "$file" ".pl" "^text/x-perl$" "#!/usr/bin/perl"
fi

# Python files
if [[ $file = *.py ]]; then
if command -v flake8 >/dev/null 2>&1; then
flake8 --max-line-length 131 "$file" || errors=true
else
printf "${RED}Error: flake8 utility not found. %s not checked with flake8.${END}\n" "$file"
printf "${YELLOW}\nTo Install flake8, type:\n\npip install flake8\n\n${END}"
exit 1
fi
fi

# Shell scripts
if [[ $file = *.sh || $file = **/pre-commit ]]; then
if command -v shellcheck >/dev/null 2>&1 && shellcheck -o all -e2148 /dev/null >/dev/null 2>&1; then
shellcheck -o all -e 1091,2059,2154,2248,2250,2312 "$file" || errors=true
else
printf "${YELLOW}Warning: %s not checked with shellcheck.${END}\n" "$file"
shellcheck_warning=1
fi
fi
fi
done

if [[ -n $shellcheck_warning ]]; then
printf "${YELLOW}\nWarning: shellcheck utility not found or not recent enough version.\n${END}"
howto_install shellcheck
fi

if [[ $errors = true ]]; then
exit 1
fi
}

# Main Program
set_shell_options
set_colors
parse_options "$@"
reformat_files
Loading