Skip to content

Commit cf55d6a

Browse files
committed
Move ondemand implementation to include/
1 parent 1cef40c commit cf55d6a

File tree

108 files changed

+603
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+603
-557
lines changed

benchmark/bench_sax.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
66
SIMDJSON_POP_DISABLE_WARNINGS
77

88
#if SIMDJSON_IMPLEMENTATION_HASWELL
9-
#include "haswell/begin_implementation.h"
9+
#include "simdjson/haswell/begin.h"
1010
#endif // SIMDJSON_IMPLEMENTATION_HASWELL
1111

1212
#include <iostream>
@@ -31,5 +31,5 @@ SIMDJSON_POP_DISABLE_WARNINGS
3131
BENCHMARK_MAIN();
3232

3333
#if SIMDJSON_IMPLEMENTATION_HASWELL
34-
#include "haswell/end_implementation.h"
34+
#include "simdjson/haswell/end.h"
3535
#endif // SIMDJSON_IMPLEMENTATION_HASWELL

include/simdjson.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ SIMDJSON_DISABLE_UNDESIRED_WARNINGS
6969
#include "simdjson/dom/parser-inl.h"
7070
#include "simdjson/internal/tape_ref-inl.h"
7171

72+
// Implementations
73+
#include "simdjson/arm64.h"
74+
#include "simdjson/fallback.h"
75+
#include "simdjson/haswell.h"
76+
#include "simdjson/westmere.h"
77+
7278
SIMDJSON_POP_DISABLE_WARNINGS
7379

7480
#endif // SIMDJSON_H

include/simdjson/arm64.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef SIMDJSON_ARM64_H
2+
#define SIMDJSON_ARM64_H
3+
4+
#include "simdjson/portability.h"
5+
6+
#if SIMDJSON_IMPLEMENTATION_ARM64
7+
8+
#include "simdjson/arm64/implementation.h"
9+
10+
#include "simdjson/arm64/begin.h"
11+
#include "simdjson/generic/dom_parser_implementation.h"
12+
#include "simdjson/arm64/intrinsics.h"
13+
#include "simdjson/arm64/bitmanipulation.h"
14+
#include "simdjson/arm64/bitmask.h"
15+
#include "simdjson/arm64/simd.h"
16+
#include "simdjson/generic/jsoncharutils.h"
17+
#include "simdjson/generic/atomparsing.h"
18+
#include "simdjson/arm64/stringparsing.h"
19+
#include "simdjson/arm64/numberparsing.h"
20+
#include "simdjson/arm64/end.h"
21+
22+
#endif // SIMDJSON_IMPLEMENTATION_ARM64
23+
24+
#endif // SIMDJSON_ARM64_H

include/simdjson/arm64/begin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define SIMDJSON_IMPLEMENTATION arm64
File renamed without changes.

include/simdjson/arm64/end.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#undef SIMDJSON_IMPLEMENTATION

src/arm64/implementation.h renamed to include/simdjson/arm64/implementation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define SIMDJSON_ARM64_IMPLEMENTATION_H
33

44
#include "simdjson.h"
5-
#include "isadetection.h"
5+
#include "simdjson/internal/isadetection.h"
66

77
namespace simdjson {
88
namespace arm64 {
@@ -12,7 +12,7 @@ using namespace simdjson::dom;
1212

1313
class implementation final : public simdjson::implementation {
1414
public:
15-
simdjson_really_inline implementation() : simdjson::implementation("arm64", "ARM NEON", instruction_set::NEON) {}
15+
simdjson_really_inline implementation() : simdjson::implementation("arm64", "ARM NEON", internal::instruction_set::NEON) {}
1616
SIMDJSON_WARN_UNUSED error_code create_dom_parser_implementation(
1717
size_t capacity,
1818
size_t max_length,
File renamed without changes.

src/arm64/numberparsing.h renamed to include/simdjson/arm64/numberparsing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const uint8_t
2121

2222
#define SWAR_NUMBER_PARSING
2323

24-
#include "generic/stage2/numberparsing.h"
24+
#include "simdjson/generic/numberparsing.h"
2525

2626
#endif // SIMDJSON_ARM64_NUMBERPARSING_H

src/arm64/simd.h renamed to include/simdjson/arm64/simd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define SIMDJSON_ARM64_SIMD_H
33

44
#include "simdjson.h"
5-
#include "simdprune_tables.h"
6-
#include "arm64/bitmanipulation.h"
5+
#include "simdjson/internal/simdprune_tables.h"
6+
#include "simdjson/arm64/bitmanipulation.h"
77
#include <type_traits>
88

99

src/arm64/stringparsing.h renamed to include/simdjson/arm64/stringparsing.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define SIMDJSON_ARM64_STRINGPARSING_H
33

44
#include "simdjson.h"
5-
#include "arm64/simd.h"
6-
#include "arm64/bitmanipulation.h"
5+
#include "simdjson/arm64/simd.h"
6+
#include "simdjson/arm64/bitmanipulation.h"
77

88
namespace simdjson {
99
namespace SIMDJSON_IMPLEMENTATION {
@@ -48,6 +48,6 @@ simdjson_really_inline backslash_and_quote backslash_and_quote::copy_and_find(co
4848
} // namespace SIMDJSON_IMPLEMENTATION
4949
} // namespace simdjson
5050

51-
#include "generic/stage2/stringparsing.h"
51+
#include "simdjson/generic/stringparsing.h"
5252

5353
#endif // SIMDJSON_ARM64_STRINGPARSING_H

include/simdjson/common_defs.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ namespace std {
196196
#endif // SIMDJSON_HAS_STRING_VIEW
197197
#undef SIMDJSON_HAS_STRING_VIEW // We are not going to need this macro anymore.
198198

199-
200-
199+
/// If EXPR is an error, returns it.
200+
#define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
201201

202202

203203
/**
@@ -244,5 +244,4 @@ namespace std {
244244
* End of the crazy locale headers.
245245
*/
246246

247-
248247
#endif // SIMDJSON_COMMON_DEFS_H

include/simdjson/fallback.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef SIMDJSON_FALLBACK_H
2+
#define SIMDJSON_FALLBACK_H
3+
4+
#include "simdjson/portability.h"
5+
6+
#if SIMDJSON_IMPLEMENTATION_FALLBACK
7+
8+
#include "simdjson/fallback/implementation.h"
9+
10+
#include "simdjson/fallback/begin.h"
11+
#include "simdjson/generic/dom_parser_implementation.h"
12+
#include "simdjson/fallback/bitmanipulation.h"
13+
#include "simdjson/generic/jsoncharutils.h"
14+
#include "simdjson/generic/atomparsing.h"
15+
#include "simdjson/fallback/stringparsing.h"
16+
#include "simdjson/fallback/numberparsing.h"
17+
#include "simdjson/fallback/end.h"
18+
19+
#endif // SIMDJSON_IMPLEMENTATION_FALLBACK
20+
#endif // SIMDJSON_FALLBACK_H

include/simdjson/fallback/begin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define SIMDJSON_IMPLEMENTATION fallback

include/simdjson/fallback/end.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#undef SIMDJSON_IMPLEMENTATION

src/fallback/implementation.h renamed to include/simdjson/fallback/implementation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#ifndef SIMDJSON_FALLBACK_IMPLEMENTATION_H
22
#define SIMDJSON_FALLBACK_IMPLEMENTATION_H
33

4-
#include "simdjson.h"
5-
#include "isadetection.h"
4+
#include "simdjson/implementation.h"
65

76
namespace simdjson {
87
namespace fallback {

src/fallback/numberparsing.h renamed to include/simdjson/fallback/numberparsing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ static simdjson_really_inline uint32_t parse_eight_digits_unrolled(const uint8_t
2727
} // namespace simdjson
2828

2929
#define SWAR_NUMBER_PARSING
30-
#include "generic/stage2/numberparsing.h"
30+
#include "simdjson/generic/numberparsing.h"
3131

3232
#endif // SIMDJSON_FALLBACK_NUMBERPARSING_H

src/fallback/stringparsing.h renamed to include/simdjson/fallback/stringparsing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ simdjson_really_inline backslash_and_quote backslash_and_quote::copy_and_find(co
3131
} // namespace SIMDJSON_IMPLEMENTATION
3232
} // namespace simdjson
3333

34-
#include "generic/stage2/stringparsing.h"
34+
#include "simdjson/generic/stringparsing.h"
3535

3636
#endif // SIMDJSON_FALLBACK_STRINGPARSING_H

src/generic/stage2/atomparsing.h renamed to include/simdjson/generic/atomparsing.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace simdjson {
22
namespace SIMDJSON_IMPLEMENTATION {
33
namespace {
4-
namespace stage2 {
54
namespace atomparsing {
65

76
// The string_to_uint32 is exclusively used to map literal strings to 32-bit values.
@@ -25,7 +24,7 @@ simdjson_really_inline uint32_t str4ncmp(const uint8_t *src, const char* atom) {
2524

2625
SIMDJSON_WARN_UNUSED
2726
simdjson_really_inline bool is_valid_true_atom(const uint8_t *src) {
28-
return (str4ncmp(src, "true") | is_not_structural_or_whitespace(src[4])) == 0;
27+
return (str4ncmp(src, "true") | jsoncharutils::is_not_structural_or_whitespace(src[4])) == 0;
2928
}
3029

3130
SIMDJSON_WARN_UNUSED
@@ -37,7 +36,7 @@ simdjson_really_inline bool is_valid_true_atom(const uint8_t *src, size_t len) {
3736

3837
SIMDJSON_WARN_UNUSED
3938
simdjson_really_inline bool is_valid_false_atom(const uint8_t *src) {
40-
return (str4ncmp(src+1, "alse") | is_not_structural_or_whitespace(src[5])) == 0;
39+
return (str4ncmp(src+1, "alse") | jsoncharutils::is_not_structural_or_whitespace(src[5])) == 0;
4140
}
4241

4342
SIMDJSON_WARN_UNUSED
@@ -49,7 +48,7 @@ simdjson_really_inline bool is_valid_false_atom(const uint8_t *src, size_t len)
4948

5049
SIMDJSON_WARN_UNUSED
5150
simdjson_really_inline bool is_valid_null_atom(const uint8_t *src) {
52-
return (str4ncmp(src, "null") | is_not_structural_or_whitespace(src[4])) == 0;
51+
return (str4ncmp(src, "null") | jsoncharutils::is_not_structural_or_whitespace(src[4])) == 0;
5352
}
5453

5554
SIMDJSON_WARN_UNUSED
@@ -60,7 +59,6 @@ simdjson_really_inline bool is_valid_null_atom(const uint8_t *src, size_t len) {
6059
}
6160

6261
} // namespace atomparsing
63-
} // namespace stage2
6462
} // unnamed namespace
6563
} // namespace SIMDJSON_IMPLEMENTATION
6664
} // namespace simdjson

src/generic/dom_parser_implementation.h renamed to include/simdjson/generic/dom_parser_implementation.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "simdjson.h"
2-
#include "isadetection.h"
2+
#include "simdjson/internal/isadetection.h"
33

44
namespace simdjson {
55
namespace SIMDJSON_IMPLEMENTATION {
@@ -36,16 +36,16 @@ class dom_parser_implementation final : public internal::dom_parser_implementati
3636
SIMDJSON_WARN_UNUSED error_code check_for_unclosed_array() noexcept;
3737
SIMDJSON_WARN_UNUSED error_code stage2(dom::document &doc) noexcept final;
3838
SIMDJSON_WARN_UNUSED error_code stage2_next(dom::document &doc) noexcept final;
39-
SIMDJSON_WARN_UNUSED error_code set_capacity(size_t capacity) noexcept final;
40-
SIMDJSON_WARN_UNUSED error_code set_max_depth(size_t max_depth) noexcept final;
39+
inline SIMDJSON_WARN_UNUSED error_code set_capacity(size_t capacity) noexcept final;
40+
inline SIMDJSON_WARN_UNUSED error_code set_max_depth(size_t max_depth) noexcept final;
41+
private:
42+
simdjson_really_inline SIMDJSON_WARN_UNUSED error_code set_capacity_stage1(size_t capacity);
43+
4144
};
4245

4346
} // namespace SIMDJSON_IMPLEMENTATION
4447
} // namespace simdjson
4548

46-
#include "generic/stage1/allocate.h"
47-
#include "generic/stage2/allocate.h"
48-
4949
namespace simdjson {
5050
namespace SIMDJSON_IMPLEMENTATION {
5151

@@ -54,16 +54,24 @@ inline dom_parser_implementation::dom_parser_implementation(dom_parser_implement
5454
inline dom_parser_implementation &dom_parser_implementation::operator=(dom_parser_implementation &&other) noexcept = default;
5555

5656
// Leaving these here so they can be inlined if so desired
57-
SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
58-
error_code err = stage1::allocate::set_capacity(*this, capacity);
59-
if (err) { _capacity = 0; return err; }
57+
inline SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::set_capacity(size_t capacity) noexcept {
58+
// Stage 1 index output
59+
size_t max_structures = SIMDJSON_ROUNDUP_N(capacity, 64) + 2 + 7;
60+
structural_indexes.reset( new (std::nothrow) uint32_t[max_structures] );
61+
if (!structural_indexes) { _capacity = 0; return MEMALLOC; }
62+
structural_indexes[0] = 0;
63+
n_structural_indexes = 0;
64+
6065
_capacity = capacity;
6166
return SUCCESS;
6267
}
6368

64-
SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
65-
error_code err = stage2::allocate::set_max_depth(*this, max_depth);
66-
if (err) { _max_depth = 0; return err; }
69+
inline SIMDJSON_WARN_UNUSED error_code dom_parser_implementation::set_max_depth(size_t max_depth) noexcept {
70+
// Stage 2 stacks
71+
open_containers.reset(new (std::nothrow) open_container[max_depth]);
72+
is_array.reset(new (std::nothrow) bool[max_depth]);
73+
if (!is_array || !open_containers) { _max_depth = 0; return MEMALLOC; }
74+
6775
_max_depth = max_depth;
6876
return SUCCESS;
6977
}

src/generic/stage2/jsoncharutils.h renamed to include/simdjson/generic/jsoncharutils.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
#include "simdjson/internal/jsoncharutils_tables.h"
2+
#include "simdjson/internal/numberparsing_tables.h"
3+
14
namespace simdjson {
25
namespace SIMDJSON_IMPLEMENTATION {
36
namespace {
4-
namespace stage2 {
7+
namespace jsoncharutils {
58

69
// return non-zero if not a structural or whitespace char
710
// zero otherwise
811
simdjson_really_inline uint32_t is_not_structural_or_whitespace(uint8_t c) {
9-
return structural_or_whitespace_negated[c];
12+
return internal::structural_or_whitespace_negated[c];
1013
}
1114

1215
simdjson_really_inline uint32_t is_structural_or_whitespace(uint8_t c) {
13-
return structural_or_whitespace[c];
16+
return internal::structural_or_whitespace[c];
1417
}
1518

1619
// returns a value with the high 16 bits set if not valid
@@ -21,10 +24,10 @@ simdjson_really_inline uint32_t is_structural_or_whitespace(uint8_t c) {
2124
// https://lemire.me/blog/2019/04/17/parsing-short-hexadecimal-strings-efficiently/
2225
static inline uint32_t hex_to_u32_nocheck(
2326
const uint8_t *src) { // strictly speaking, static inline is a C-ism
24-
uint32_t v1 = digit_to_val32[630 + src[0]];
25-
uint32_t v2 = digit_to_val32[420 + src[1]];
26-
uint32_t v3 = digit_to_val32[210 + src[2]];
27-
uint32_t v4 = digit_to_val32[0 + src[3]];
27+
uint32_t v1 = internal::digit_to_val32[630 + src[0]];
28+
uint32_t v2 = internal::digit_to_val32[420 + src[1]];
29+
uint32_t v3 = internal::digit_to_val32[210 + src[2]];
30+
uint32_t v4 = internal::digit_to_val32[0 + src[3]];
2831
return v1 | v2 | v3 | v4;
2932
}
3033

@@ -87,6 +90,8 @@ static simdjson_really_inline uint64_t _umul128(uint64_t ab, uint64_t cd, uint64
8790
}
8891
#endif
8992

93+
using internal::value128;
94+
9095
simdjson_really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
9196
value128 answer;
9297
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
@@ -105,7 +110,7 @@ simdjson_really_inline value128 full_multiplication(uint64_t value1, uint64_t va
105110
return answer;
106111
}
107112

108-
} // namespace stage2
113+
} // namespace jsoncharutils
109114
} // unnamed namespace
110115
} // namespace SIMDJSON_IMPLEMENTATION
111116
} // namespace simdjson

0 commit comments

Comments
 (0)