Skip to content

Commit 5365a1c

Browse files
committed
different implementation of parse_unsigned
1 parent 2b9ad2a commit 5365a1c

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

include/boost/json/detail/sse2.hpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,27 +317,14 @@ inline uint64_t parse_unsigned( uint64_t r, char const * p, std::size_t n ) noex
317317
{
318318
while( n >= 4 )
319319
{
320-
// faster on on clang for x86,
321-
// slower on gcc
322-
#ifdef __clang__
323-
r = r * 10 + p[0] - '0';
324-
r = r * 10 + p[1] - '0';
325-
r = r * 10 + p[2] - '0';
326-
r = r * 10 + p[3] - '0';
327-
#else
328320
uint32_t v;
329321
std::memcpy( &v, p, 4 );
330322
endian::native_to_little_inplace(v);
323+
v = (v & 0x0F0F0F0F) * 2561 >> 8;
324+
v = (v & 0x00FF00FF) * 6553601 >> 16;
331325

332-
v -= 0x30303030;
326+
r = r * 10000 + v;
333327

334-
unsigned w0 = v & 0xFF;
335-
unsigned w1 = (v >> 8) & 0xFF;
336-
unsigned w2 = (v >> 16) & 0xFF;
337-
unsigned w3 = (v >> 24);
338-
339-
r = (((r * 10 + w0) * 10 + w1) * 10 + w2) * 10 + w3;
340-
#endif
341328
p += 4;
342329
n -= 4;
343330
}
@@ -359,6 +346,7 @@ inline uint64_t parse_unsigned( uint64_t r, char const * p, std::size_t n ) noex
359346
r = r * 10 + p[2] - '0';
360347
break;
361348
}
349+
362350
return r;
363351
}
364352

0 commit comments

Comments
 (0)