File tree Expand file tree Collapse file tree 5 files changed +29
-7
lines changed Expand file tree Collapse file tree 5 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 11#include " atoi.h"
2-
2+ # include " zoo/pp/platform.h "
33#include < vector>
44#include < string>
55#include < cstring>
@@ -119,17 +119,28 @@ struct CorpusStringLength {
119119 }
120120};
121121
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+
122131#define STRLEN_CORPUS_X_LIST \
123132 X (LIBC_STRLEN, strlen) \
124133 X(ZOO_STRLEN, zoo::c_strLength) \
125134 X(ZOO_NATURAL_STRLEN, zoo::c_strLength_natural) \
126135 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+
129139
130140#define X (Typename, FunctionToCall ) \
131141 struct Invoke ##Typename { int operator ()(const char *p) { return FunctionToCall (p); } };
132142
133143PARSE8BYTES_CORPUS_X_LIST
134144STRLEN_CORPUS_X_LIST
145+
135146#undef X
Original file line number Diff line number Diff line change 11#include " zoo/swar/SWAR.h"
22#include " zoo/swar/associative_iteration.h"
33
4+ #if ZOO_CONFIGURED_TO_USE_AVX
45#include < immintrin.h>
6+ #endif
57
68#include < stdint.h>
79#include < string.h>
@@ -117,6 +119,7 @@ std::size_t c_strLength_manualComparison(const char *s) {
117119 }
118120}
119121
122+ #if ZOO_CONFIGURED_TO_USE_AVX
120123size_t avx2_strlen (const char * str) {
121124 const __m256i zero = _mm256_setzero_si256 (); // Vector of 32 zero bytes
122125 size_t offset = 0 ;
@@ -140,6 +143,7 @@ size_t avx2_strlen(const char* str) {
140143 // Unreachable, but included to avoid compiler warnings
141144 return offset;
142145}
146+ #endif
143147
144148}
145149
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ namespace zoo {
99std::size_t c_strLength (const char *s);
1010std::size_t c_strLength_natural (const char *s);
1111std::size_t c_strLength_manualComparison (const char *s);
12+
13+ #if ZOO_CONFIGURED_TO_USE_AVX
1214std::size_t avx2_strlen (const char * str);
15+ #endif
1316
1417}
1518
Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ TEST_CASE("Atoi benchmarks", "[atoi][swar]") {
3636 REQUIRE (fromLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
3737 REQUIRE (fromZOO_NATURAL_STRLEN == fromZOO_MANUAL_STRLEN);
3838 REQUIRE (fromGENERIC_GLIBC_STRLEN == fromZOO_NATURAL_STRLEN);
39+ #if ZOO_CONFIGURED_TO_USE_AVX()
3940 REQUIRE (fromZOO_AVX == fromZOO_STRLEN);
41+ #endif
4042
4143 auto haveTheRoleOfMemoryBarrier = -1 ;
4244 #define X (Type, Fun ) \
Original file line number Diff line number Diff line change 11#ifndef ZOO_PLATFORM_MACROS_H
22#define ZOO_PLATFORM_MACROS_H
33
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
59
10+ #ifdef _MSC_VER
611#define MSVC_EMPTY_BASES __declspec(empty_bases)
7-
812#else
9-
1013#define MSVC_EMPTY_BASES
11-
1214#endif
1315
1416#endif
You can’t perform that action at this time.
0 commit comments