Skip to content

Commit 1910b1a

Browse files
committed
SIMDDetect: Use tesseract namespace and format code
Signed-off-by: Stefan Weil <[email protected]>
1 parent b6057f5 commit 1910b1a

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/api/tesseractmain.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ static void PrintVersionInfo() {
108108
}
109109
}
110110
}
111-
}
111+
}
112112
#endif
113-
if (SIMDDetect::IsAVX512BWAvailable()) printf(" Found AVX512BW\n");
114-
if (SIMDDetect::IsAVX512FAvailable()) printf(" Found AVX512F\n");
115-
if (SIMDDetect::IsAVX2Available()) printf(" Found AVX2\n");
116-
if (SIMDDetect::IsAVXAvailable()) printf(" Found AVX\n");
117-
if (SIMDDetect::IsSSEAvailable()) printf(" Found SSE\n");
113+
if (tesseract::SIMDDetect::IsAVX512BWAvailable()) printf(" Found AVX512BW\n");
114+
if (tesseract::SIMDDetect::IsAVX512FAvailable()) printf(" Found AVX512F\n");
115+
if (tesseract::SIMDDetect::IsAVX2Available()) printf(" Found AVX2\n");
116+
if (tesseract::SIMDDetect::IsAVXAvailable()) printf(" Found AVX\n");
117+
if (tesseract::SIMDDetect::IsSSEAvailable()) printf(" Found SSE\n");
118118
}
119119

120120
static void PrintHelpForPSM() {
@@ -706,4 +706,3 @@ int main(int argc, char** argv) {
706706

707707
return EXIT_SUCCESS;
708708
}
709-

src/arch/simddetect.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@
1919

2020
#undef X86_BUILD
2121
#if defined(__x86_64__) || defined(__i386__) || defined(_WIN32)
22-
#if !defined(ANDROID_BUILD)
23-
#define X86_BUILD 1
24-
#endif // !ANDROID_BUILD
25-
#endif // x86 target
22+
# if !defined(ANDROID_BUILD)
23+
# define X86_BUILD 1
24+
# endif // !ANDROID_BUILD
25+
#endif // x86 target
2626

2727
#if defined(X86_BUILD)
28-
#if defined(__GNUC__)
29-
#include <cpuid.h>
30-
#elif defined(_WIN32)
31-
#include <intrin.h>
32-
#endif
28+
# if defined(__GNUC__)
29+
# include <cpuid.h>
30+
# elif defined(_WIN32)
31+
# include <intrin.h>
32+
# endif
3333
#endif
3434

35+
namespace tesseract {
36+
3537
SIMDDetect SIMDDetect::detector;
3638

3739
// If true, then AVX has been detected.
@@ -49,7 +51,7 @@ bool SIMDDetect::sse_available_;
4951
// clang.
5052
SIMDDetect::SIMDDetect() {
5153
#if defined(X86_BUILD)
52-
#if defined(__GNUC__)
54+
# if defined(__GNUC__)
5355
unsigned int eax, ebx, ecx, edx;
5456
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) != 0) {
5557
// Note that these tests all use hex because the older compilers don't have
@@ -66,16 +68,18 @@ SIMDDetect::SIMDDetect() {
6668
avx512BW_available_ = (ebx & 0x40000000) != 0;
6769
}
6870
}
69-
#elif defined(_WIN32)
71+
# elif defined(_WIN32)
7072
int cpuInfo[4];
7173
__cpuid(cpuInfo, 0);
7274
if (cpuInfo[0] >= 1) {
7375
__cpuid(cpuInfo, 1);
7476
sse_available_ = (cpuInfo[2] & 0x00080000) != 0;
7577
avx_available_ = (cpuInfo[2] & 0x10000000) != 0;
7678
}
77-
#else
78-
#error "I don't know how to test for SIMD with this compiler"
79-
#endif
79+
# else
80+
# error "I don't know how to test for SIMD with this compiler"
81+
# endif
8082
#endif // X86_BUILD
8183
}
84+
85+
} // namespace tesseract

src/arch/simddetect.h

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "platform.h"
2121

22+
namespace tesseract {
23+
2224
// Architecture detector. Add code here to detect any other architectures for
2325
// SIMD-based faster dot product functions. Intended to be a single static
2426
// object, but it does no real harm to have more than one.
@@ -55,4 +57,6 @@ class SIMDDetect {
5557
static TESS_API bool sse_available_;
5658
};
5759

60+
} // namespace tesseract
61+
5862
#endif // TESSERACT_ARCH_SIMDDETECT_H_

0 commit comments

Comments
 (0)