Skip to content

Commit 4bc128f

Browse files
jkeiserJohn Keiser
authored andcommitted
Move compute_quote_mask to generic bitmask library
1 parent e383b7a commit 4bc128f

17 files changed

Lines changed: 125 additions & 47 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ COMPARISONEXECUTABLES=minifiercompetition parsingcompetition parseandstatcompeti
6464
SUPPLEMENTARYEXECUTABLES=parse_noutf8validation parse_nonumberparsing parse_nostringparsing
6565

6666
# Load headers and sources
67-
LIBHEADERS=src/simdprune_tables.h src/numberparsing.h src/jsoncharutils.h src/arm64/simd.h src/arm64/stage1_find_marks.h src/arm64/stage2_build_tape.h src/arm64/stringparsing.h src/generic/stage1_find_marks.h src/generic/stage2_build_tape.h src/generic/stringparsing.h src/haswell/simd.h src/generic/simdutf8check.h src/haswell/stage1_find_marks.h src/haswell/stage2_build_tape.h src/haswell/stringparsing.h src/westmere/simd.h src/westmere/stage1_find_marks.h src/westmere/stage2_build_tape.h src/westmere/stringparsing.h
67+
LIBHEADERS=src/simdprune_tables.h src/numberparsing.h src/jsoncharutils.h src/arm64/bitmask.h src/arm64/simd.h src/arm64/stage1_find_marks.h src/arm64/stage2_build_tape.h src/arm64/stringparsing.h src/generic/stage1_find_marks.h src/generic/stage2_build_tape.h src/generic/stringparsing.h src/haswell/bitmask.h src/haswell/simd.h src/generic/simdutf8check.h src/haswell/stage1_find_marks.h src/haswell/stage2_build_tape.h src/haswell/stringparsing.h src/westmere/bitmask.h src/westmere/simd.h src/westmere/stage1_find_marks.h src/westmere/stage2_build_tape.h src/westmere/stringparsing.h
6868
PUBHEADERS=include/simdjson/common_defs.h include/simdjson/isadetection.h include/simdjson/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonminifier.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/parsedjson.h include/simdjson/parsedjsoniterator.h include/simdjson/portability.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h include/simdjson/stage1_find_marks.h include/simdjson/stage2_build_tape.h
6969
HEADERS=$(PUBHEADERS) $(LIBHEADERS)
7070

amalgamation.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ $SCRIPTPATH/src/simdjson.cpp
2020
$SCRIPTPATH/src/jsonioutil.cpp
2121
$SCRIPTPATH/src/jsonminifier.cpp
2222
$SCRIPTPATH/src/jsonparser.cpp
23+
$SCRIPTPATH/src/arm64/bitmask.h
24+
$SCRIPTPATH/src/haswell/bitmask.h
25+
$SCRIPTPATH/src/westmere/bitmask.h
2326
$SCRIPTPATH/src/arm64/simd.h
2427
$SCRIPTPATH/src/haswell/simd.h
2528
$SCRIPTPATH/src/westmere/simd.h

src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,21 @@ set(SIMDJSON_SRC_HEADERS
3737
jsoncharutils.h
3838
numberparsing.h
3939
simdprune_tables.h
40+
arm64/bitmask.h
4041
arm64/simd.h
4142
arm64/stage1_find_marks.h
4243
arm64/stage2_build_tape.h
4344
arm64/stringparsing.h
4445
generic/stage1_find_marks.h
4546
generic/stage2_build_tape.h
4647
generic/stringparsing.h
47-
haswell/simd.h
4848
generic/simdutf8check.h
49+
haswell/bitmask.h
50+
haswell/simd.h
4951
haswell/stage1_find_marks.h
5052
haswell/stage2_build_tape.h
5153
haswell/stringparsing.h
54+
westmere/bitmask.h
5255
westmere/simd.h
5356
westmere/stage1_find_marks.h
5457
westmere/stage2_build_tape.h

src/arm64/bitmask.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef SIMDJSON_ARM64_BITMASK_H
2+
#define SIMDJSON_ARM64_BITMASK_H
3+
4+
#include "simdjson/portability.h"
5+
6+
#ifdef IS_ARM64
7+
8+
#include "haswell/bitmask.h"
9+
#include "simdjson/common_defs.h"
10+
11+
namespace simdjson::arm64 {
12+
13+
//
14+
// Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered.
15+
//
16+
// For example, prefix_xor(00100100) == 00011100
17+
//
18+
really_inline uint64_t prefix_xor(uint64_t bitmask) {
19+
20+
#ifdef __ARM_FEATURE_CRYPTO // some ARM processors lack this extension
21+
return vmull_p64(-1ULL, bitmask);
22+
#else
23+
bitmask ^= bitmask << 1;
24+
bitmask ^= bitmask << 2;
25+
bitmask ^= bitmask << 4;
26+
bitmask ^= bitmask << 8;
27+
bitmask ^= bitmask << 16;
28+
bitmask ^= bitmask << 32;
29+
return bitmask;
30+
#endif
31+
32+
}
33+
34+
} // namespace simdjson::arm64
35+
UNTARGET_REGION
36+
37+
#endif // IS_ARM64
38+
#endif

src/arm64/simd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#ifndef SIMDJSON_ARM64_SIMD_H
22
#define SIMDJSON_ARM64_SIMD_H
33

4-
#include "simdjson/common_defs.h"
54
#include "simdjson/portability.h"
6-
#include "simdjson/simdjson.h"
75

86
#ifdef IS_ARM64
97

8+
#include "simdjson/common_defs.h"
9+
#include "simdjson/simdjson.h"
10+
1011
namespace simdjson::arm64::simd {
1112

1213
template<typename T>

src/arm64/stage1_find_marks.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55

66
#ifdef IS_ARM64
77

8+
#include "arm64/bitmask.h"
89
#include "arm64/simd.h"
910
#include "simdjson/stage1_find_marks.h"
1011

1112
namespace simdjson::arm64 {
1213

1314
using namespace simd;
1415

15-
really_inline uint64_t compute_quote_mask(const uint64_t quote_bits) {
16-
17-
#ifdef __ARM_FEATURE_CRYPTO // some ARM processors lack this extension
18-
return vmull_p64(-1ULL, quote_bits);
19-
#else
20-
return portable_compute_quote_mask(quote_bits);
21-
#endif
22-
}
23-
2416
really_inline void find_whitespace_and_operators(
2517
const simd::simd8x64<uint8_t> in,
2618
uint64_t &whitespace, uint64_t &op) {

src/arm64/stringparsing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef SIMDJSON_ARM64_STRINGPARSING_H
22
#define SIMDJSON_ARM64_STRINGPARSING_H
33

4+
#include "simdjson/portability.h"
5+
46
#ifdef IS_ARM64
57

68
#include "simdjson/common_defs.h"

src/generic/stage1_find_marks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class json_structural_scanner {
162162
const uint64_t backslash = in.eq('\\');
163163
const uint64_t escaped = follows_odd_sequence_of(backslash, prev_escaped);
164164
const uint64_t quote = in.eq('"') & ~escaped;
165-
// compute_quote_mask returns start quote plus string contents.
166-
const uint64_t in_string = compute_quote_mask(quote) ^ prev_in_string;
165+
// prefix_xor flips on bits inside the string (and flips off the end quote).
166+
const uint64_t in_string = prefix_xor(quote) ^ prev_in_string;
167167
/* right shift of a signed value expected to be well-defined and standard
168168
* compliant as of C++20,
169169
* John Regher from Utah U. says this is fine code */

src/haswell/bitmask.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef SIMDJSON_HASWELL_BITMASK_H
2+
#define SIMDJSON_HASWELL_BITMASK_H
3+
4+
#include "simdjson/portability.h"
5+
6+
#ifdef IS_X86_64
7+
8+
#include "simdjson/common_defs.h"
9+
10+
TARGET_HASWELL
11+
namespace simdjson::haswell {
12+
13+
//
14+
// Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered.
15+
//
16+
// For example, prefix_xor(00100100) == 00011100
17+
//
18+
really_inline uint64_t prefix_xor(const uint64_t bitmask) {
19+
// There should be no such thing with a processing supporting avx2
20+
// but not clmul.
21+
__m128i all_ones = _mm_set1_epi8('\xFF');
22+
__m128i result = _mm_clmulepi64_si128(_mm_set_epi64x(0ULL, bitmask), all_ones, 0);
23+
return _mm_cvtsi128_si64(result);
24+
}
25+
26+
} // namespace simdjson::haswell
27+
UNTARGET_REGION
28+
29+
#endif // IS_X86_64
30+
#endif

src/haswell/simd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef SIMDJSON_HASWELL_SIMD_H
22
#define SIMDJSON_HASWELL_SIMD_H
33

4-
#include "simdjson/common_defs.h"
54
#include "simdjson/portability.h"
65

76
#ifdef IS_X86_64
87

8+
#include "simdjson/common_defs.h"
9+
910
TARGET_HASWELL
1011
namespace simdjson::haswell::simd {
1112

0 commit comments

Comments
 (0)