Skip to content

Commit 14c595e

Browse files
committed
Updating the single-header
1 parent 5e78fa5 commit 14c595e

3 files changed

Lines changed: 56 additions & 35 deletions

File tree

‎singleheader/amalgamate_demo.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue Jul 7 13:32:36 EDT 2020. Do not edit! */
1+
/* auto-generated on Tue Jul 7 15:13:17 EDT 2020. Do not edit! */
22

33
#include <iostream>
44
#include "simdjson.h"

‎singleheader/simdjson.cpp‎

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue Jul 7 13:32:36 EDT 2020. Do not edit! */
1+
/* auto-generated on Tue Jul 7 15:13:17 EDT 2020. Do not edit! */
22
/* begin file src/simdjson.cpp */
33
#include "simdjson.h"
44

@@ -2808,7 +2808,7 @@ really_inline json_character_block json_character_block::classify(const simd::si
28082808
}
28092809

28102810
really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
2811-
simd8<uint8_t> bits = (input.chunks[0] | input.chunks[1]) | (input.chunks[2] | input.chunks[3]);
2811+
simd8<uint8_t> bits = input.reduce_or();
28122812
return bits.max() < 0b10000000u;
28132813
}
28142814

@@ -3552,18 +3552,25 @@ namespace utf8_validation {
35523552
}
35533553

35543554
really_inline void check_next_input(const simd8x64<uint8_t>& input) {
3555-
if (likely(is_ascii(input))) {
3555+
if (unlikely(!is_ascii(input))) {
3556+
// you might think that a for-loop would work, but under Visual Studio, it is not good enough.
3557+
static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) || (simd8x64<uint8_t>::NUM_CHUNKS == 4));
3558+
if(simd8x64<uint8_t>::NUM_CHUNKS == 2) {
3559+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
3560+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
3561+
} else if(simd8x64<uint8_t>::NUM_CHUNKS == 4) {
3562+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
3563+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
3564+
this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
3565+
this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
3566+
}
3567+
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
3568+
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
3569+
} else {
35563570
// If the previous block had incomplete UTF-8 characters at the end, an ASCII block can't
35573571
// possibly finish them.
35583572
this->error |= this->prev_incomplete;
3559-
} else {
3560-
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
3561-
for (int i=1; i<simd8x64<uint8_t>::NUM_CHUNKS; i++) {
3562-
this->check_utf8_bytes(input.chunks[i], input.chunks[i-1]);
3563-
}
3564-
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
3565-
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
3566-
}
3573+
}
35673574
}
35683575

35693576
really_inline error_code errors() {
@@ -7997,6 +8004,7 @@ namespace simd {
79978004
really_inline simd8<bool> bits_not_set(simd8<uint8_t> bits) const { return (*this & bits).bits_not_set(); }
79988005
really_inline simd8<bool> any_bits_set() const { return ~this->bits_not_set(); }
79998006
really_inline simd8<bool> any_bits_set(simd8<uint8_t> bits) const { return ~this->bits_not_set(bits); }
8007+
really_inline bool is_ascii() const { return _mm256_movemask_epi8(*this) == 0; }
80008008
really_inline bool bits_not_set_anywhere() const { return _mm256_testz_si256(*this, *this); }
80018009
really_inline bool any_bits_set_anywhere() const { return !bits_not_set_anywhere(); }
80028010
really_inline bool bits_not_set_anywhere(simd8<uint8_t> bits) const { return _mm256_testz_si256(*this, bits); }
@@ -8122,8 +8130,7 @@ really_inline json_character_block json_character_block::classify(const simd::si
81228130
}
81238131

81248132
really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
8125-
simd8<uint8_t> bits = input.reduce_or();;
8126-
return !bits.any_bits_set_anywhere(0b10000000u);
8133+
return input.reduce_or().is_ascii();
81278134
}
81288135

81298136
really_inline simd8<bool> must_be_continuation(const simd8<uint8_t>& prev1, const simd8<uint8_t>& prev2, const simd8<uint8_t>& prev3) {
@@ -8862,18 +8869,25 @@ namespace utf8_validation {
88628869
}
88638870

88648871
really_inline void check_next_input(const simd8x64<uint8_t>& input) {
8865-
if (likely(is_ascii(input))) {
8872+
if (unlikely(!is_ascii(input))) {
8873+
// you might think that a for-loop would work, but under Visual Studio, it is not good enough.
8874+
static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) || (simd8x64<uint8_t>::NUM_CHUNKS == 4));
8875+
if(simd8x64<uint8_t>::NUM_CHUNKS == 2) {
8876+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
8877+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
8878+
} else if(simd8x64<uint8_t>::NUM_CHUNKS == 4) {
8879+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
8880+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
8881+
this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
8882+
this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
8883+
}
8884+
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
8885+
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
8886+
} else {
88668887
// If the previous block had incomplete UTF-8 characters at the end, an ASCII block can't
88678888
// possibly finish them.
88688889
this->error |= this->prev_incomplete;
8869-
} else {
8870-
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
8871-
for (int i=1; i<simd8x64<uint8_t>::NUM_CHUNKS; i++) {
8872-
this->check_utf8_bytes(input.chunks[i], input.chunks[i-1]);
8873-
}
8874-
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
8875-
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
8876-
}
8890+
}
88778891
}
88788892

88798893
really_inline error_code errors() {
@@ -11176,6 +11190,7 @@ namespace simd {
1117611190
really_inline simd8<bool> bits_not_set(simd8<uint8_t> bits) const { return (*this & bits).bits_not_set(); }
1117711191
really_inline simd8<bool> any_bits_set() const { return ~this->bits_not_set(); }
1117811192
really_inline simd8<bool> any_bits_set(simd8<uint8_t> bits) const { return ~this->bits_not_set(bits); }
11193+
really_inline bool is_ascii() const { return _mm_movemask_epi8(*this) == 0; }
1117911194
really_inline bool bits_not_set_anywhere() const { return _mm_testz_si128(*this, *this); }
1118011195
really_inline bool any_bits_set_anywhere() const { return !bits_not_set_anywhere(); }
1118111196
really_inline bool bits_not_set_anywhere(simd8<uint8_t> bits) const { return _mm_testz_si128(*this, bits); }
@@ -11317,8 +11332,7 @@ really_inline json_character_block json_character_block::classify(const simd::si
1131711332
}
1131811333

1131911334
really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
11320-
simd8<uint8_t> bits = input.reduce_or();
11321-
return !bits.any_bits_set_anywhere(0b10000000u);
11335+
return input.reduce_or().is_ascii();
1132211336
}
1132311337

1132411338
really_inline simd8<bool> must_be_continuation(const simd8<uint8_t>& prev1, const simd8<uint8_t>& prev2, const simd8<uint8_t>& prev3) {
@@ -12057,18 +12071,25 @@ namespace utf8_validation {
1205712071
}
1205812072

1205912073
really_inline void check_next_input(const simd8x64<uint8_t>& input) {
12060-
if (likely(is_ascii(input))) {
12074+
if (unlikely(!is_ascii(input))) {
12075+
// you might think that a for-loop would work, but under Visual Studio, it is not good enough.
12076+
static_assert((simd8x64<uint8_t>::NUM_CHUNKS == 2) || (simd8x64<uint8_t>::NUM_CHUNKS == 4));
12077+
if(simd8x64<uint8_t>::NUM_CHUNKS == 2) {
12078+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
12079+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
12080+
} else if(simd8x64<uint8_t>::NUM_CHUNKS == 4) {
12081+
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
12082+
this->check_utf8_bytes(input.chunks[1], input.chunks[0]);
12083+
this->check_utf8_bytes(input.chunks[2], input.chunks[1]);
12084+
this->check_utf8_bytes(input.chunks[3], input.chunks[2]);
12085+
}
12086+
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
12087+
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
12088+
} else {
1206112089
// If the previous block had incomplete UTF-8 characters at the end, an ASCII block can't
1206212090
// possibly finish them.
1206312091
this->error |= this->prev_incomplete;
12064-
} else {
12065-
this->check_utf8_bytes(input.chunks[0], this->prev_input_block);
12066-
for (int i=1; i<simd8x64<uint8_t>::NUM_CHUNKS; i++) {
12067-
this->check_utf8_bytes(input.chunks[i], input.chunks[i-1]);
12068-
}
12069-
this->prev_incomplete = is_incomplete(input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1]);
12070-
this->prev_input_block = input.chunks[simd8x64<uint8_t>::NUM_CHUNKS-1];
12071-
}
12092+
}
1207212093
}
1207312094

1207412095
really_inline error_code errors() {

‎singleheader/simdjson.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Tue Jul 7 13:32:36 EDT 2020. Do not edit! */
1+
/* auto-generated on Tue Jul 7 15:13:17 EDT 2020. Do not edit! */
22
/* begin file include/simdjson.h */
33
#ifndef SIMDJSON_H
44
#define SIMDJSON_H

0 commit comments

Comments
 (0)