Skip to content

Commit

Permalink
SIMDDetect: Use tesseract namespace and format code
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Nov 30, 2018
1 parent b6057f5 commit 1910b1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/api/tesseractmain.cpp
Expand Up @@ -108,13 +108,13 @@ static void PrintVersionInfo() {
}
}
}
}
}
#endif
if (SIMDDetect::IsAVX512BWAvailable()) printf(" Found AVX512BW\n");
if (SIMDDetect::IsAVX512FAvailable()) printf(" Found AVX512F\n");
if (SIMDDetect::IsAVX2Available()) printf(" Found AVX2\n");
if (SIMDDetect::IsAVXAvailable()) printf(" Found AVX\n");
if (SIMDDetect::IsSSEAvailable()) printf(" Found SSE\n");
if (tesseract::SIMDDetect::IsAVX512BWAvailable()) printf(" Found AVX512BW\n");
if (tesseract::SIMDDetect::IsAVX512FAvailable()) printf(" Found AVX512F\n");
if (tesseract::SIMDDetect::IsAVX2Available()) printf(" Found AVX2\n");
if (tesseract::SIMDDetect::IsAVXAvailable()) printf(" Found AVX\n");
if (tesseract::SIMDDetect::IsSSEAvailable()) printf(" Found SSE\n");
}

static void PrintHelpForPSM() {
Expand Down Expand Up @@ -706,4 +706,3 @@ int main(int argc, char** argv) {

return EXIT_SUCCESS;
}

32 changes: 18 additions & 14 deletions src/arch/simddetect.cpp
Expand Up @@ -19,19 +19,21 @@

#undef X86_BUILD
#if defined(__x86_64__) || defined(__i386__) || defined(_WIN32)
#if !defined(ANDROID_BUILD)
#define X86_BUILD 1
#endif // !ANDROID_BUILD
#endif // x86 target
# if !defined(ANDROID_BUILD)
# define X86_BUILD 1
# endif // !ANDROID_BUILD
#endif // x86 target

#if defined(X86_BUILD)
#if defined(__GNUC__)
#include <cpuid.h>
#elif defined(_WIN32)
#include <intrin.h>
#endif
# if defined(__GNUC__)
# include <cpuid.h>
# elif defined(_WIN32)
# include <intrin.h>
# endif
#endif

namespace tesseract {

SIMDDetect SIMDDetect::detector;

// If true, then AVX has been detected.
Expand All @@ -49,7 +51,7 @@ bool SIMDDetect::sse_available_;
// clang.
SIMDDetect::SIMDDetect() {
#if defined(X86_BUILD)
#if defined(__GNUC__)
# if defined(__GNUC__)
unsigned int eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) != 0) {
// Note that these tests all use hex because the older compilers don't have
Expand All @@ -66,16 +68,18 @@ SIMDDetect::SIMDDetect() {
avx512BW_available_ = (ebx & 0x40000000) != 0;
}
}
#elif defined(_WIN32)
# elif defined(_WIN32)
int cpuInfo[4];
__cpuid(cpuInfo, 0);
if (cpuInfo[0] >= 1) {
__cpuid(cpuInfo, 1);
sse_available_ = (cpuInfo[2] & 0x00080000) != 0;
avx_available_ = (cpuInfo[2] & 0x10000000) != 0;
}
#else
#error "I don't know how to test for SIMD with this compiler"
#endif
# else
# error "I don't know how to test for SIMD with this compiler"
# endif
#endif // X86_BUILD
}

} // namespace tesseract
4 changes: 4 additions & 0 deletions src/arch/simddetect.h
Expand Up @@ -19,6 +19,8 @@

#include "platform.h"

namespace tesseract {

// Architecture detector. Add code here to detect any other architectures for
// SIMD-based faster dot product functions. Intended to be a single static
// object, but it does no real harm to have more than one.
Expand Down Expand Up @@ -55,4 +57,6 @@ class SIMDDetect {
static TESS_API bool sse_available_;
};

} // namespace tesseract

#endif // TESSERACT_ARCH_SIMDDETECT_H_

0 comments on commit 1910b1a

Please sign in to comment.