22
22
#include " params.h" // for STRING_VAR
23
23
#include " tprintf.h" // for tprintf
24
24
25
- #undef X86_BUILD
26
- #if defined(__x86_64__) || defined(__i386__) || defined(_WIN32)
27
- # if !defined(ANDROID_BUILD)
28
- # define X86_BUILD 1
29
- # endif // !ANDROID_BUILD
30
- #endif // x86 target
31
-
32
- #if defined(X86_BUILD)
33
- # if defined(__GNUC__)
34
- # include < cpuid.h>
35
- # elif defined(_WIN32)
36
- # include < intrin.h>
37
- # endif
25
+ #if defined(__GNUC__)
26
+ # include < cpuid.h>
27
+ #elif defined(_WIN32)
28
+ # include < intrin.h>
38
29
#endif
39
30
40
31
namespace tesseract {
@@ -84,13 +75,15 @@ SIMDDetect::SIMDDetect() {
84
75
// The fallback is a generic dot product calculation.
85
76
SetDotProduct (DotProductGeneric);
86
77
87
- #if defined(X86_BUILD)
88
- # if defined(__GNUC__)
78
+ #if defined(__GNUC__)
89
79
unsigned int eax, ebx, ecx, edx;
90
80
if (__get_cpuid (1 , &eax, &ebx, &ecx, &edx) != 0 ) {
91
81
// Note that these tests all use hex because the older compilers don't have
92
82
// the newer flags.
83
+ #if defined(SSE4_1)
93
84
sse_available_ = (ecx & 0x00080000 ) != 0 ;
85
+ #endif
86
+ #if defined(AVX)
94
87
avx_available_ = (ecx & 0x10000000 ) != 0 ;
95
88
if (avx_available_) {
96
89
// There is supposed to be a __get_cpuid_count function, but this is all
@@ -101,30 +94,38 @@ SIMDDetect::SIMDDetect() {
101
94
avx512F_available_ = (ebx & 0x00010000 ) != 0 ;
102
95
avx512BW_available_ = (ebx & 0x40000000 ) != 0 ;
103
96
}
97
+ #endif
104
98
}
105
99
# elif defined(_WIN32)
106
100
int cpuInfo[4 ];
107
101
__cpuid (cpuInfo, 0 );
108
102
if (cpuInfo[0 ] >= 1 ) {
109
103
__cpuid (cpuInfo, 1 );
104
+ #if defined(SSE4_1)
110
105
sse_available_ = (cpuInfo[2 ] & 0x00080000 ) != 0 ;
106
+ #endif
107
+ #if defined(AVX)
111
108
avx_available_ = (cpuInfo[2 ] & 0x10000000 ) != 0 ;
109
+ #endif
112
110
}
113
- # else
114
- # error "I don't know how to test for SIMD with this compiler"
115
- # endif
116
- #endif // X86_BUILD
111
+ #else
112
+ #error "I don't know how to test for SIMD with this compiler"
113
+ #endif
117
114
118
- #if defined(X86_BUILD)
119
115
// Select code for calculation of dot product based on autodetection.
120
- if (avx_available_) {
116
+ if (false ) {
117
+ // This is a dummy to support conditional compilation.
118
+ #if defined(AVX)
119
+ } else if (avx_available_) {
121
120
// AVX detected.
122
121
SetDotProduct (DotProductAVX);
122
+ #endif
123
+ #if defined(SSE4_1)
123
124
} else if (sse_available_) {
124
125
// SSE detected.
125
126
SetDotProduct (DotProductSSE);
127
+ #endif
126
128
}
127
- #endif // X86_BUILD
128
129
}
129
130
130
131
void SIMDDetect::Update () {
@@ -141,26 +142,29 @@ void SIMDDetect::Update() {
141
142
// Native optimized code selected by config variable.
142
143
SetDotProduct (DotProductNative);
143
144
dotproduct_method = " native" ;
144
- }
145
- #if defined(X86_BUILD)
146
- else if (!strcmp (dotproduct.string (), " avx" )) {
145
+ #if defined(AVX)
146
+ } else if (!strcmp (dotproduct.string (), " avx" )) {
147
147
// AVX selected by config variable.
148
148
SetDotProduct (DotProductAVX);
149
149
dotproduct_method = " avx" ;
150
+ #endif
151
+ #if defined(SSE4_1)
150
152
} else if (!strcmp (dotproduct.string (), " sse" )) {
151
153
// SSE selected by config variable.
152
154
SetDotProduct (DotProductSSE);
153
155
dotproduct_method = " sse" ;
154
- }
155
- #endif // X86_BUILD
156
- else {
156
+ #endif
157
+ } else {
157
158
// Unsupported value of config variable.
158
159
tprintf (" Warning, ignoring unsupported config variable value: dotproduct=%s\n " ,
159
160
dotproduct.string ());
160
161
tprintf (" Support values for dotproduct: auto generic native"
161
- #if defined(X86_BUILD)
162
- " avx sse"
163
- #endif // X86_BUILD
162
+ #if defined(AVX)
163
+ " avx"
164
+ #endif
165
+ #if defined(SSE4_1)
166
+ " sse"
167
+ #endif
164
168
" .\n " );
165
169
}
166
170
0 commit comments