Skip to content

Commit

Permalink
CVS-34366 Clang format style.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasapala committed Jul 14, 2020
1 parent 1edfb3c commit 49b6156
Show file tree
Hide file tree
Showing 72 changed files with 3,568 additions and 3,529 deletions.
97 changes: 97 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
BreakConstructorInitializers: AfterColon
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
# clang-format > v3.8.0: BreakAfterJavaFieldAnnotations: false
# clang-format > v3.8.0: BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '<([A-Za-z0-9\Q/-_\E])+>$'
Priority: 1
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>$'
Priority: 2
- Regex: '("|<).?(google|tensorflow|spdlog|aws).+("|>)'
Priority: 3
- Regex: '"([A-Za-z0-9\Q/-_\E])+"$'
Priority: 4
- Regex: '"([A-Za-z0-9\/.\Q/-_\E])+"$'
Priority: 5
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ STYLE_CHECK_OPTS := --extensions=hpp,cc,cpp,h \
--output=vs7 \
--recursive \
--linelength=120 \
--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
--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
STYLE_CHECK_DIRS := src
HTTP_PROXY := "$(http_proxy)"
HTTPS_PROXY := "$(https_proxy)"
Expand Down Expand Up @@ -90,6 +90,10 @@ style: venv
@echo "Style-checking codebase..."
@. $(ACTIVATE); echo ${PWD}; cpplint ${STYLE_CHECK_OPTS} ${STYLE_CHECK_DIRS}

clang-format: venv
@echo "Formating files with clang-format.."
@. $(ACTIVATE); find ${STYLE_CHECK_DIRS} -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format-6.0 -style=file -i {} \;

.PHONY: docker_build
docker_build:
@echo "Building docker image $(BASE_OS)"
Expand Down
141 changes: 72 additions & 69 deletions src/avx_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,91 +16,94 @@

namespace ovms {

#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
#pragma once
#include <immintrin.h>


int check_4th_gen_intel_core_features() {
const int the_4th_gen_features =
(_FEATURE_AVX);
// Removed _FEATURE_AVX2| _FEATURE_FMA | _FEATURE_BMI | _FEATURE_LZCNT | _FEATURE_MOVBE
return _may_i_use_cpu_feature(the_4th_gen_features);
}

#else /* non-Intel compiler */
#pragma once
#include <stdint.h>
#if defined(_MSC_VER)
# include <intrin.h>
#endif


void run_cpuid(uint32_t eax, uint32_t ecx, uint32_t* abcd) {
#if defined(_MSC_VER)
__cpuidex(abcd, eax, ecx);
#else
uint32_t ebx, edx;
# if defined( __i386__ ) && defined ( __PIC__ )
/* in case of PIC under 32-bit EBX cannot be clobbered */
__asm__ ( "movl %%ebx, %%edi \n\t cpuid \n\t xchgl %%ebx, %%edi" : "=D" (ebx),
# else
__asm__ ( "cpuid" : "+b" (ebx),
# endif
"+a" (eax), "+c" (ecx), "=d" (edx));
abcd[0] = eax; abcd[1] = ebx; abcd[2] = ecx; abcd[3] = edx;
#endif
}


int check_xcr0_ymm() {
uint32_t xcr0;
#if defined(_MSC_VER)
xcr0 = (uint32_t)_xgetbv(0);/* min VS2010 SP1 compiler is required */
#else
__asm__("xgetbv" : "=a" (xcr0) : "c" (0) : "%edx");
#endif
return ((xcr0 & 6) == 6);/* checking if xmm and ymm state are enabled in XCR0 */
}



int check_4th_gen_intel_core_features() {
uint32_t abcd[4];
uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
uint32_t avx_osxsave_mask = (1 << 27) | (1 << 28);

/* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1300)
#pragma once
#include <immintrin.h>

int check_4th_gen_intel_core_features() {
const int the_4th_gen_features =
(_FEATURE_AVX);
// Removed _FEATURE_AVX2| _FEATURE_FMA | _FEATURE_BMI | _FEATURE_LZCNT | _FEATURE_MOVBE
return _may_i_use_cpu_feature(the_4th_gen_features);
}

#else /* non-Intel compiler */
#pragma once
#include <stdint.h>
#if defined(_MSC_VER)
#include <intrin.h>
#endif

void run_cpuid(uint32_t eax, uint32_t ecx, uint32_t* abcd) {
#if defined(_MSC_VER)
__cpuidex(abcd, eax, ecx);
#else
uint32_t ebx, edx;
#if defined(__i386__) && defined(__PIC__)
/* in case of PIC under 32-bit EBX cannot be clobbered */
__asm__("movl %%ebx, %%edi \n\t cpuid \n\t xchgl %%ebx, %%edi"
: "=D"(ebx),
#else
__asm__("cpuid"
: "+b"(ebx),
#endif
"+a"(eax), "+c"(ecx), "=d"(edx));
abcd[0] = eax;
abcd[1] = ebx;
abcd[2] = ecx;
abcd[3] = edx;
#endif
}

int check_xcr0_ymm() {
uint32_t xcr0;
#if defined(_MSC_VER)
xcr0 = (uint32_t)_xgetbv(0); /* min VS2010 SP1 compiler is required */
#else
__asm__("xgetbv"
: "=a"(xcr0)
: "c"(0)
: "%edx");
#endif
return ((xcr0 & 6) == 6); /* checking if xmm and ymm state are enabled in XCR0 */
}

int check_4th_gen_intel_core_features() {
uint32_t abcd[4];
uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
uint32_t avx_osxsave_mask = (1 << 27) | (1 << 28);

/* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1 &&
CPUID.(EAX=01H, ECX=0H):ECX.MOVBE[bit 22]==1 &&
CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
/* run_cpuid(1, 0, abcd);
/* run_cpuid(1, 0, abcd);
if ((abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask)
return 0; */

/* if (!check_xcr0_ymm())
/* if (!check_xcr0_ymm())
return 0; */

/* CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 &&
/* CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 &&
CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]==1 &&
CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]==1 */
/* run_cpuid(7, 0, abcd);
/* run_cpuid(7, 0, abcd);
if ((abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask)
return 0; */

/* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
/* run_cpuid(0x80000001, 0, abcd);
/* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
/* run_cpuid(0x80000001, 0, abcd);
if ((abcd[2] & (1 << 5)) == 0)
return 0; */

// Check AVX support
run_cpuid(1, 0, abcd);
if ((abcd[2] & avx_osxsave_mask) != avx_osxsave_mask)
return 0;
// Check AVX support
run_cpuid(1, 0, abcd);
if ((abcd[2] & avx_osxsave_mask) != avx_osxsave_mask)
return 0;

return 1;
}
return 1;
}

#endif /* non-Intel compiler */
#endif /* non-Intel compiler */

} // namespace ovms
Loading

0 comments on commit 49b6156

Please sign in to comment.