Skip to content

Commit 49b6156

Browse files
committed
CVS-34366 Clang format style.
1 parent 1edfb3c commit 49b6156

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3568
-3529
lines changed

.clang-format

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -4
5+
AlignAfterOpenBracket: DontAlign
6+
AlignConsecutiveAssignments: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlinesLeft: false
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
BreakConstructorInitializers: AfterColon
13+
AllowShortBlocksOnASingleLine: false
14+
AllowShortCaseLabelsOnASingleLine: false
15+
AllowShortFunctionsOnASingleLine: All
16+
AllowShortIfStatementsOnASingleLine: false
17+
AllowShortLoopsOnASingleLine: false
18+
AlwaysBreakAfterDefinitionReturnType: None
19+
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakBeforeMultilineStrings: false
21+
AlwaysBreakTemplateDeclarations: false
22+
BinPackArguments: true
23+
BinPackParameters: true
24+
BraceWrapping:
25+
AfterClass: false
26+
AfterControlStatement: false
27+
AfterEnum: false
28+
AfterFunction: false
29+
AfterNamespace: false
30+
AfterObjCDeclaration: false
31+
AfterStruct: false
32+
AfterUnion: false
33+
BeforeCatch: false
34+
BeforeElse: false
35+
IndentBraces: false
36+
BreakBeforeBinaryOperators: false
37+
BreakBeforeBraces: Attach
38+
BreakBeforeTernaryOperators: true
39+
BreakConstructorInitializersBeforeComma: false
40+
# clang-format > v3.8.0: BreakAfterJavaFieldAnnotations: false
41+
# clang-format > v3.8.0: BreakStringLiterals: true
42+
ColumnLimit: 0
43+
CommentPragmas: '^ IWYU pragma:'
44+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
45+
ConstructorInitializerIndentWidth: 4
46+
ContinuationIndentWidth: 4
47+
Cpp11BracedListStyle: true
48+
DerivePointerAlignment: false
49+
DisableFormat: false
50+
ExperimentalAutoDetectBinPacking: false
51+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
52+
IncludeBlocks: Regroup
53+
IncludeCategories:
54+
- Regex: '<([A-Za-z0-9\Q/-_\E])+>$'
55+
Priority: 1
56+
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>$'
57+
Priority: 2
58+
- Regex: '("|<).?(google|tensorflow|spdlog|aws).+("|>)'
59+
Priority: 3
60+
- Regex: '"([A-Za-z0-9\Q/-_\E])+"$'
61+
Priority: 4
62+
- Regex: '"([A-Za-z0-9\/.\Q/-_\E])+"$'
63+
Priority: 5
64+
IndentCaseLabels: false
65+
IndentWidth: 4
66+
IndentWrappedFunctionNames: false
67+
KeepEmptyLinesAtTheStartOfBlocks: true
68+
MacroBlockBegin: ''
69+
MacroBlockEnd: ''
70+
MaxEmptyLinesToKeep: 1
71+
NamespaceIndentation: None
72+
ObjCBlockIndentWidth: 2
73+
ObjCSpaceAfterProperty: false
74+
ObjCSpaceBeforeProtocolList: true
75+
PenaltyBreakBeforeFirstCallParameter: 19
76+
PenaltyBreakComment: 300
77+
PenaltyBreakFirstLessLess: 120
78+
PenaltyBreakString: 1000
79+
PenaltyExcessCharacter: 1000000
80+
PenaltyReturnTypeOnItsOwnLine: 60
81+
PointerAlignment: Left
82+
ReflowComments: true
83+
SortIncludes: true
84+
SpaceAfterCStyleCast: false
85+
SpaceBeforeAssignmentOperators: true
86+
SpaceBeforeParens: ControlStatements
87+
SpaceInEmptyParentheses: false
88+
SpacesBeforeTrailingComments: 2
89+
SpacesInAngles: false
90+
SpacesInContainerLiterals: true
91+
SpacesInCStyleCastParentheses: false
92+
SpacesInParentheses: false
93+
SpacesInSquareBrackets: false
94+
Standard: Cpp11
95+
TabWidth: 4
96+
UseTab: Never
97+
...

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ STYLE_CHECK_OPTS := --extensions=hpp,cc,cpp,h \
2121
--output=vs7 \
2222
--recursive \
2323
--linelength=120 \
24-
--filter=-build/c++11,-runtime/references,-whitespace/indent,-build/include_order,-runtime/indentation_namespace,-build/namespaces,-whitespace/line_length,-runtime/string,-readability/casting,-runtime/explicit,-readability/todo
24+
--filter=-build/c++11,-runtime/references,-whitespace/braces,-whitespace/indent,-build/include_order,-runtime/indentation_namespace,-build/namespaces,-whitespace/line_length,-runtime/string,-readability/casting,-runtime/explicit,-readability/todo
2525
STYLE_CHECK_DIRS := src
2626
HTTP_PROXY := "$(http_proxy)"
2727
HTTPS_PROXY := "$(https_proxy)"
@@ -90,6 +90,10 @@ style: venv
9090
@echo "Style-checking codebase..."
9191
@. $(ACTIVATE); echo ${PWD}; cpplint ${STYLE_CHECK_OPTS} ${STYLE_CHECK_DIRS}
9292

93+
clang-format: venv
94+
@echo "Formating files with clang-format.."
95+
@. $(ACTIVATE); find ${STYLE_CHECK_DIRS} -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format-6.0 -style=file -i {} \;
96+
9397
.PHONY: docker_build
9498
docker_build:
9599
@echo "Building docker image $(BASE_OS)"

src/avx_check.hpp

+72-69
Original file line numberDiff line numberDiff line change
@@ -16,91 +16,94 @@
1616

1717
namespace ovms {
1818

19-
#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
20-
#pragma once
21-
#include <immintrin.h>
22-
23-
24-
int check_4th_gen_intel_core_features() {
25-
const int the_4th_gen_features =
26-
(_FEATURE_AVX);
27-
// Removed _FEATURE_AVX2| _FEATURE_FMA | _FEATURE_BMI | _FEATURE_LZCNT | _FEATURE_MOVBE
28-
return _may_i_use_cpu_feature(the_4th_gen_features);
29-
}
30-
31-
#else /* non-Intel compiler */
32-
#pragma once
33-
#include <stdint.h>
34-
#if defined(_MSC_VER)
35-
# include <intrin.h>
36-
#endif
37-
38-
39-
void run_cpuid(uint32_t eax, uint32_t ecx, uint32_t* abcd) {
40-
#if defined(_MSC_VER)
41-
__cpuidex(abcd, eax, ecx);
42-
#else
43-
uint32_t ebx, edx;
44-
# if defined( __i386__ ) && defined ( __PIC__ )
45-
/* in case of PIC under 32-bit EBX cannot be clobbered */
46-
__asm__ ( "movl %%ebx, %%edi \n\t cpuid \n\t xchgl %%ebx, %%edi" : "=D" (ebx),
47-
# else
48-
__asm__ ( "cpuid" : "+b" (ebx),
49-
# endif
50-
"+a" (eax), "+c" (ecx), "=d" (edx));
51-
abcd[0] = eax; abcd[1] = ebx; abcd[2] = ecx; abcd[3] = edx;
52-
#endif
53-
}
54-
55-
56-
int check_xcr0_ymm() {
57-
uint32_t xcr0;
58-
#if defined(_MSC_VER)
59-
xcr0 = (uint32_t)_xgetbv(0);/* min VS2010 SP1 compiler is required */
60-
#else
61-
__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "%edx");
62-
#endif
63-
return ((xcr0 & 6) == 6);/* checking if xmm and ymm state are enabled in XCR0 */
64-
}
65-
66-
67-
68-
int check_4th_gen_intel_core_features() {
69-
uint32_t abcd[4];
70-
uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
71-
uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
72-
uint32_t avx_osxsave_mask = (1 << 27) | (1 << 28);
73-
74-
/* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
19+
#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
20+
#pragma once
21+
#include <immintrin.h>
22+
23+
int check_4th_gen_intel_core_features() {
24+
const int the_4th_gen_features =
25+
(_FEATURE_AVX);
26+
// Removed _FEATURE_AVX2| _FEATURE_FMA | _FEATURE_BMI | _FEATURE_LZCNT | _FEATURE_MOVBE
27+
return _may_i_use_cpu_feature(the_4th_gen_features);
28+
}
29+
30+
#else /* non-Intel compiler */
31+
#pragma once
32+
#include <stdint.h>
33+
#if defined(_MSC_VER)
34+
#include <intrin.h>
35+
#endif
36+
37+
void run_cpuid(uint32_t eax, uint32_t ecx, uint32_t* abcd) {
38+
#if defined(_MSC_VER)
39+
__cpuidex(abcd, eax, ecx);
40+
#else
41+
uint32_t ebx, edx;
42+
#if defined(__i386__) && defined(__PIC__)
43+
/* in case of PIC under 32-bit EBX cannot be clobbered */
44+
__asm__("movl %%ebx, %%edi \n\t cpuid \n\t xchgl %%ebx, %%edi"
45+
: "=D"(ebx),
46+
#else
47+
__asm__("cpuid"
48+
: "+b"(ebx),
49+
#endif
50+
"+a"(eax), "+c"(ecx), "=d"(edx));
51+
abcd[0] = eax;
52+
abcd[1] = ebx;
53+
abcd[2] = ecx;
54+
abcd[3] = edx;
55+
#endif
56+
}
57+
58+
int check_xcr0_ymm() {
59+
uint32_t xcr0;
60+
#if defined(_MSC_VER)
61+
xcr0 = (uint32_t)_xgetbv(0); /* min VS2010 SP1 compiler is required */
62+
#else
63+
__asm__("xgetbv"
64+
: "=a"(xcr0)
65+
: "c"(0)
66+
: "%edx");
67+
#endif
68+
return ((xcr0 & 6) == 6); /* checking if xmm and ymm state are enabled in XCR0 */
69+
}
70+
71+
int check_4th_gen_intel_core_features() {
72+
uint32_t abcd[4];
73+
uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
74+
uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
75+
uint32_t avx_osxsave_mask = (1 << 27) | (1 << 28);
76+
77+
/* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
7578
CPUID.(EAX=01H, ECX=0H):ECX.MOVBE[bit 22]==1 &&
7679
CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
77-
/* run_cpuid(1, 0, abcd);
80+
/* run_cpuid(1, 0, abcd);
7881
if ((abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask)
7982
return 0; */
8083

81-
/* if (!check_xcr0_ymm())
84+
/* if (!check_xcr0_ymm())
8285
return 0; */
8386

84-
/* CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 &&
87+
/* CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 &&
8588
CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]==1 &&
8689
CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]==1 */
87-
/* run_cpuid(7, 0, abcd);
90+
/* run_cpuid(7, 0, abcd);
8891
if ((abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask)
8992
return 0; */
9093

91-
/* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
92-
/* run_cpuid(0x80000001, 0, abcd);
94+
/* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
95+
/* run_cpuid(0x80000001, 0, abcd);
9396
if ((abcd[2] & (1 << 5)) == 0)
9497
return 0; */
9598

96-
// Check AVX support
97-
run_cpuid(1, 0, abcd);
98-
if ((abcd[2] & avx_osxsave_mask) != avx_osxsave_mask)
99-
return 0;
99+
// Check AVX support
100+
run_cpuid(1, 0, abcd);
101+
if ((abcd[2] & avx_osxsave_mask) != avx_osxsave_mask)
102+
return 0;
100103

101-
return 1;
102-
}
104+
return 1;
105+
}
103106

104-
#endif /* non-Intel compiler */
107+
#endif /* non-Intel compiler */
105108

106109
} // namespace ovms

0 commit comments

Comments
 (0)