File tree 5 files changed +29
-7
lines changed
5 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 1
1
#include " atoi.h"
2
-
2
+ # include " zoo/pp/platform.h "
3
3
#include < vector>
4
4
#include < string>
5
5
#include < cstring>
@@ -119,17 +119,28 @@ struct CorpusStringLength {
119
119
}
120
120
};
121
121
122
+
123
+ #if ZOO_CONFIGURED_TO_USE_AVX()
124
+ #define AVX2_STRLEN_CORPUS_X_LIST \
125
+ X (ZOO_AVX, zoo::avx2_strlen)
126
+ #else
127
+ #define AVX2_STRLEN_CORPUS_X_LIST /* nothing */
128
+ #endif
129
+
130
+
122
131
#define STRLEN_CORPUS_X_LIST \
123
132
X (LIBC_STRLEN, strlen) \
124
133
X(ZOO_STRLEN, zoo::c_strLength) \
125
134
X(ZOO_NATURAL_STRLEN, zoo::c_strLength_natural) \
126
135
X(ZOO_MANUAL_STRLEN, zoo::c_strLength_manualComparison) \
127
- X(ZOO_AVX, zoo::avx2_strlen) \
128
- X(GENERIC_GLIBC_STRLEN, STRLEN_old)
136
+ X(GENERIC_GLIBC_STRLEN, STRLEN_old) \
137
+ AVX2_STRLEN_CORPUS_X_LIST
138
+
129
139
130
140
#define X (Typename, FunctionToCall ) \
131
141
struct Invoke ##Typename { int operator ()(const char *p) { return FunctionToCall (p); } };
132
142
133
143
PARSE8BYTES_CORPUS_X_LIST
134
144
STRLEN_CORPUS_X_LIST
145
+
135
146
#undef X
Original file line number Diff line number Diff line change 1
1
#include " zoo/swar/SWAR.h"
2
2
#include " zoo/swar/associative_iteration.h"
3
3
4
+ #if ZOO_CONFIGURED_TO_USE_AVX
4
5
#include < immintrin.h>
6
+ #endif
5
7
6
8
#include < stdint.h>
7
9
#include < string.h>
@@ -117,6 +119,7 @@ std::size_t c_strLength_manualComparison(const char *s) {
117
119
}
118
120
}
119
121
122
+ #if ZOO_CONFIGURED_TO_USE_AVX
120
123
size_t avx2_strlen (const char * str) {
121
124
const __m256i zero = _mm256_setzero_si256 (); // Vector of 32 zero bytes
122
125
size_t offset = 0 ;
@@ -140,6 +143,7 @@ size_t avx2_strlen(const char* str) {
140
143
// Unreachable, but included to avoid compiler warnings
141
144
return offset;
142
145
}
146
+ #endif
143
147
144
148
}
145
149
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ namespace zoo {
9
9
std::size_t c_strLength (const char *s);
10
10
std::size_t c_strLength_natural (const char *s);
11
11
std::size_t c_strLength_manualComparison (const char *s);
12
+
13
+ #if ZOO_CONFIGURED_TO_USE_AVX
12
14
std::size_t avx2_strlen (const char * str);
15
+ #endif
13
16
14
17
}
15
18
Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ TEST_CASE("Atoi benchmarks", "[atoi][swar]") {
36
36
REQUIRE (fromLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
37
37
REQUIRE (fromZOO_NATURAL_STRLEN == fromZOO_MANUAL_STRLEN);
38
38
REQUIRE (fromGENERIC_GLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
39
+ #if ZOO_CONFIGURED_TO_USE_AVX()
39
40
REQUIRE (fromZOO_AVX == fromZOO_STRLEN);
41
+ #endif
40
42
41
43
auto haveTheRoleOfMemoryBarrier = -1 ;
42
44
#define X (Type, Fun ) \
Original file line number Diff line number Diff line change 1
1
#ifndef ZOO_PLATFORM_MACROS_H
2
2
#define ZOO_PLATFORM_MACROS_H
3
3
4
- #ifdef _MSC_VER
4
+ #ifdef __AVX2__
5
+ #define ZOO_CONFIGURED_TO_USE_AVX () 1
6
+ #else
7
+ #define ZOO_CONFIGURED_TO_USE_AVX () 0
8
+ #endif
5
9
10
+ #ifdef _MSC_VER
6
11
#define MSVC_EMPTY_BASES __declspec(empty_bases)
7
-
8
12
#else
9
-
10
13
#define MSVC_EMPTY_BASES
11
-
12
14
#endif
13
15
14
16
#endif
You can’t perform that action at this time.
0 commit comments