1- #include " zoo/swar/SWAR.h"
1+ #include " atoi.h"
2+
23#include " zoo/swar/associative_iteration.h"
34
4- #if ZOO_CONFIGURED_TO_USE_AVX
5+ #if ZOO_CONFIGURED_TO_USE_AVX()
56#include < immintrin.h>
67#endif
78
89#include < stdint.h>
910#include < string.h>
1011#include < stdlib.h>
12+ #include < ctype.h>
1113
1214// Copied from Daniel Lemire's GitHub at
1315// https://lemire.me/blog/2018/10/03/quickly-parsing-eight-digits/
@@ -25,7 +27,7 @@ uint32_t parse_eight_digits_swar(const char *chars) {
2527
2628// Note: eight digits can represent from 0 to (10^9) - 1, the logarithm base 2
2729// of 10^9 is slightly less than 30, thus, only 30 bits are needed.
28- auto lemire_as_zoo_swar (const char *chars) {
30+ uint32_t lemire_as_zoo_swar (const char *chars) {
2931 uint64_t bytes;
3032 memcpy (&bytes, chars, 8 );
3133 auto allCharacterZero = zoo::meta::BitmaskMaker<uint64_t , ' 0' , 8 >::value;
@@ -54,8 +56,44 @@ auto lemire_as_zoo_swar(const char *chars) {
5456 return uint32_t (by10001base2to32.value () >> 32 );
5557}
5658
59+ std::size_t spaces_glibc (const char *ptr) {
60+ auto rv = 0 ;
61+ while (isspace (ptr[rv])) { ++rv; }
62+ return rv;
63+ }
64+
5765namespace zoo {
5866
67+ // constexpr
68+ std::size_t leadingSpacesCount (swar::SWAR<8 , uint64_t > bytes) noexcept {
69+ /*
70+ space (0x20, ' ')
71+ form feed (0x0c, '\f')
72+ line feed (0x0a, '\n')
73+ carriage return (0x0d, '\r')
74+ horizontal tab (0x09, '\t')
75+ vertical tab (0x0b, '\v')*
76+ constexpr std::array<char, 6> SpaceCharacters = {
77+ 0b10'0000, //0x20 space
78+ 0b00'1101, // 0xD \r
79+ 0b00'1100, // 0xC \f
80+ 0b00'1011, // 0xB \v
81+ 0b00'1010, // 0xA \n
82+ 0b00'1001 // 9 \t
83+ },
84+ ExpressedAsEscapeCodes = { ' ', '\r', '\f', '\v', '\n', '\t' };
85+ static_assert(SpaceCharacters == ExpressedAsEscapeCodes); */
86+ using S = swar::SWAR<8 , uint64_t >;
87+ constexpr S Space{meta::BitmaskMaker<uint64_t , ' ' , 8 >::value};
88+ auto space = swar::equals (bytes, Space);
89+ auto otherWhiteSpace =
90+ swar::constantIsGreaterEqual<' \r ' >(bytes) &
91+ ~swar::constantIsGreaterEqual<' \t ' - 1 >(bytes);
92+ auto whiteSpace = space | otherWhiteSpace;
93+ auto notWhiteSpace = S{S::MostSignificantBit} ^ whiteSpace;
94+ return notWhiteSpace.lsbIndex ();
95+ }
96+
5997std::size_t c_strLength (const char *s) {
6098 using S = swar::SWAR<8 , std::size_t >;
6199 constexpr auto
@@ -119,7 +157,7 @@ std::size_t c_strLength_manualComparison(const char *s) {
119157 }
120158}
121159
122- #if ZOO_CONFIGURED_TO_USE_AVX
160+ #if ZOO_CONFIGURED_TO_USE_AVX()
123161size_t avx2_strlen (const char * str) {
124162 const __m256i zero = _mm256_setzero_si256 (); // Vector of 32 zero bytes
125163 size_t offset = 0 ;
0 commit comments