Skip to content

Commit 739a71c

Browse files
committed
Update basic_csv_parser_simd.hpp
1 parent d85b4b0 commit 739a71c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

include/internal/basic_csv_parser_simd.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818

1919
#if (defined(__AVX2__) || defined(__SSE2__)) && !defined(CSV_NO_SIMD)
2020
#include <immintrin.h>
21+
// _tzcnt_u32 in GCC/Clang headers is __attribute__(__target__("bmi")), which
22+
// requires -mbmi at the call site. __builtin_ctz has no such restriction and
23+
// emits BSF/TZCNT as the optimizer sees fit. MSVC's _tzcnt_u32 has no
24+
// equivalent restriction, so keep it there.
25+
# ifdef _MSC_VER
26+
# define CSV_TZCNT32(x) _tzcnt_u32(x)
27+
# else
28+
# define CSV_TZCNT32(x) static_cast<unsigned>(__builtin_ctz(x))
29+
# endif
2130
#endif
2231

2332
namespace csv {
@@ -84,7 +93,7 @@ namespace csv {
8493
int mask = _mm256_movemask_epi8(special);
8594

8695
if (mask != 0)
87-
return pos + _tzcnt_u32(mask);
96+
return pos + CSV_TZCNT32(static_cast<unsigned>(mask));
8897
pos += 32;
8998
}
9099
#elif defined(__SSE2__) && !defined(CSV_NO_SIMD)
@@ -97,7 +106,7 @@ namespace csv {
97106
int mask = _mm_movemask_epi8(special);
98107

99108
if (mask != 0)
100-
return pos + _tzcnt_u32(mask);
109+
return pos + CSV_TZCNT32(static_cast<unsigned>(mask));
101110
pos += 16;
102111
}
103112
#else

0 commit comments

Comments
 (0)