Skip to content

Commit b3ea8c4

Browse files
committed
Add simdjson.cpp for unified use (simdjson#515)
1 parent 99667f7 commit b3ea8c4

15 files changed

+1625
-292
lines changed

.drone.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,48 @@ steps:
9999
commands: [ make slowtests ]
100100
---
101101
kind: pipeline
102+
name: x64-amalgamated-build
103+
104+
platform:
105+
os: linux
106+
arch: amd64
107+
108+
steps:
109+
- name: build
110+
image: gcc:8
111+
environment:
112+
SIMDJSON_TEST_AMALGAMATED_HEADERS: 1
113+
commands: [ make, make amalgamate ]
114+
---
115+
kind: pipeline
116+
name: x64-amalgamated-quicktests
117+
118+
platform:
119+
os: linux
120+
arch: amd64
121+
122+
steps:
123+
- name: quicktests
124+
image: gcc:8
125+
environment:
126+
SIMDJSON_TEST_AMALGAMATED_HEADERS: 1
127+
commands: [ make quicktests ]
128+
---
129+
kind: pipeline
130+
name: x64-amalgamated-slowtests
131+
132+
platform:
133+
os: linux
134+
arch: amd64
135+
136+
steps:
137+
- name: slowtests
138+
image: gcc:8
139+
environment:
140+
SIMDJSON_TEST_AMALGAMATED_HEADERS: 1
141+
commands: [ make slowtests ]
142+
---
143+
kind: pipeline
102144
name: stylecheck
103145

104146
platform:

Makefile

Lines changed: 65 additions & 53 deletions
Large diffs are not rendered by default.

amalgamation.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ INCLUDEPATH="$SCRIPTPATH/include"
1616

1717
# this list excludes the "src/generic headers"
1818
ALLCFILES="
19-
document.cpp
20-
error.cpp
21-
implementation.cpp
22-
jsonioutil.cpp
23-
jsonminifier.cpp
24-
stage1_find_marks.cpp
25-
stage2_build_tape.cpp
19+
simdjson.cpp
2620
"
2721

2822
# order matters

benchmark/benchmarker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#ifdef __linux__
3232
#include <libgen.h>
3333
#endif
34-
//#define DEBUG
3534
#include "simdjson.h"
3635

3736
#include <functional>

doc/JsonStream.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Here is a simple example, using single header simdjson:
184184
```cpp
185185
#include "simdjson.h"
186186
#include "simdjson.cpp"
187+
#include "simdjson.cpp"
187188
188189
int parse_file(const char *filename) {
189190
simdjson::padded_string p = simdjson::get_corpus(filename);

fuzz/fuzz_minify.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "simdjson.h"
2-
#include "simdjson.h"
32
#include <cstddef>
43
#include <cstdint>
54
#include <string>

include/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
set(SIMDJSON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
22
set(SIMDJSON_INCLUDE
3+
${SIMDJSON_INCLUDE_DIR}/simdjson.h
4+
${SIMDJSON_INCLUDE_DIR}/simdjson/compiler_check.h
35
${SIMDJSON_INCLUDE_DIR}/simdjson/common_defs.h
46
${SIMDJSON_INCLUDE_DIR}/simdjson/document.h
5-
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h
67
${SIMDJSON_INCLUDE_DIR}/simdjson/document_iterator.h
7-
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h
88
${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h
9+
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h
10+
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h
911
${SIMDJSON_INCLUDE_DIR}/simdjson/isadetection.h
1012
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonformatutils.h
1113
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h

singleheader/amalgamation_demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Mon Mar 2 14:10:52 PST 2020. Do not edit! */
1+
/* auto-generated on Mon Mar 2 15:35:47 PST 2020. Do not edit! */
22

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

singleheader/simdjson.cpp

100755100644
Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/* auto-generated on Mon Mar 2 14:10:52 PST 2020. Do not edit! */
1+
/* auto-generated on Mon Mar 2 15:35:47 PST 2020. Do not edit! */
22
#include "simdjson.h"
33

44
/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */
55
#ifdef DMALLOC
66
#include "dmalloc.h"
77
#endif
88

9+
/* begin file src/simdjson.cpp */
910
/* begin file src/document.cpp */
1011

1112
namespace simdjson {
@@ -31,8 +32,7 @@ bool document::set_capacity(size_t capacity) {
3132
return string_buf && tape;
3233
}
3334

34-
WARN_UNUSED
35-
bool document::print_json(std::ostream &os, size_t max_depth) const {
35+
bool document::print_json(std::ostream &os, size_t max_depth) const noexcept {
3636
uint32_t string_length;
3737
size_t tape_idx = 0;
3838
uint64_t tape_val = tape[tape_idx];
@@ -138,8 +138,7 @@ bool document::print_json(std::ostream &os, size_t max_depth) const {
138138
return true;
139139
}
140140

141-
WARN_UNUSED
142-
bool document::dump_raw_tape(std::ostream &os) const {
141+
bool document::dump_raw_tape(std::ostream &os) const noexcept {
143142
uint32_t string_length;
144143
size_t tape_idx = 0;
145144
uint64_t tape_val = tape[tape_idx];
@@ -325,6 +324,9 @@ const std::map<int, const std::string> error_strings = {
325324
{UNSUPPORTED_ARCHITECTURE, "simdjson does not have an implementation"
326325
" supported by this CPU architecture (perhaps"
327326
" it's a non-SIMD CPU?)."},
327+
{INCORRECT_TYPE, "The JSON element does not have the requested type."},
328+
{NUMBER_OUT_OF_RANGE, "The JSON number is too large or too small to fit within the requested type."},
329+
{NO_SUCH_FIELD, "The JSON field referenced does not exist in this object."},
328330
{UNEXPECTED_ERROR, "Unexpected error, consider reporting this problem as"
329331
" you may have found a bug in simdjson"},
330332
};
@@ -2330,7 +2332,7 @@ really_inline uint64_t follows(const uint64_t match, uint64_t &overflow) {
23302332
really_inline uint64_t follows(const uint64_t match, const uint64_t filler, uint64_t &overflow) {
23312333
uint64_t follows_match = follows(match, overflow);
23322334
uint64_t result;
2333-
overflow |= add_overflow(follows_match, filler, &result);
2335+
overflow |= uint64_t(add_overflow(follows_match, filler, &result));
23342336
return result;
23352337
}
23362338

@@ -2639,7 +2641,6 @@ namespace simdjson::haswell::simd {
26392641
really_inline Child operator&(const Child other) const { return _mm256_and_si256(*this, other); }
26402642
really_inline Child operator^(const Child other) const { return _mm256_xor_si256(*this, other); }
26412643
really_inline Child bit_andnot(const Child other) const { return _mm256_andnot_si256(other, *this); }
2642-
really_inline Child operator~() const { return *this ^ 0xFFu; }
26432644
really_inline Child& operator|=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast | other; return *this_cast; }
26442645
really_inline Child& operator&=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast & other; return *this_cast; }
26452646
really_inline Child& operator^=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast ^ other; return *this_cast; }
@@ -2679,6 +2680,7 @@ namespace simdjson::haswell::simd {
26792680

26802681
really_inline int to_bitmask() const { return _mm256_movemask_epi8(*this); }
26812682
really_inline bool any() const { return !_mm256_testz_si256(*this, *this); }
2683+
really_inline simd8<bool> operator~() const { return *this ^ true; }
26822684
};
26832685

26842686
template<typename T>
@@ -2713,6 +2715,9 @@ namespace simdjson::haswell::simd {
27132715
really_inline simd8<T>& operator+=(const simd8<T> other) { *this = *this + other; return *(simd8<T>*)this; }
27142716
really_inline simd8<T>& operator-=(const simd8<T> other) { *this = *this - other; return *(simd8<T>*)this; }
27152717

2718+
// Override to distinguish from bool version
2719+
really_inline simd8<T> operator~() const { return *this ^ 0xFFu; }
2720+
27162721
// Perform a lookup assuming the value is between 0 and 16 (undefined behavior for out of range values)
27172722
template<typename L>
27182723
really_inline simd8<L> lookup_16(simd8<L> lookup_table) const {
@@ -3675,7 +3680,7 @@ really_inline uint64_t follows(const uint64_t match, uint64_t &overflow) {
36753680
really_inline uint64_t follows(const uint64_t match, const uint64_t filler, uint64_t &overflow) {
36763681
uint64_t follows_match = follows(match, overflow);
36773682
uint64_t result;
3678-
overflow |= add_overflow(follows_match, filler, &result);
3683+
overflow |= uint64_t(add_overflow(follows_match, filler, &result));
36793684
return result;
36803685
}
36813686

@@ -3982,7 +3987,6 @@ namespace simdjson::westmere::simd {
39823987
really_inline Child operator&(const Child other) const { return _mm_and_si128(*this, other); }
39833988
really_inline Child operator^(const Child other) const { return _mm_xor_si128(*this, other); }
39843989
really_inline Child bit_andnot(const Child other) const { return _mm_andnot_si128(other, *this); }
3985-
really_inline Child operator~() const { return *this ^ 0xFFu; }
39863990
really_inline Child& operator|=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast | other; return *this_cast; }
39873991
really_inline Child& operator&=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast & other; return *this_cast; }
39883992
really_inline Child& operator^=(const Child other) { auto this_cast = (Child*)this; *this_cast = *this_cast ^ other; return *this_cast; }
@@ -4022,6 +4026,7 @@ namespace simdjson::westmere::simd {
40224026

40234027
really_inline int to_bitmask() const { return _mm_movemask_epi8(*this); }
40244028
really_inline bool any() const { return !_mm_testz_si128(*this, *this); }
4029+
really_inline simd8<bool> operator~() const { return *this ^ true; }
40254030
};
40264031

40274032
template<typename T>
@@ -4048,6 +4053,9 @@ namespace simdjson::westmere::simd {
40484053
// Store to array
40494054
really_inline void store(T dst[16]) const { return _mm_storeu_si128(reinterpret_cast<__m128i *>(dst), *this); }
40504055

4056+
// Override to distinguish from bool version
4057+
really_inline simd8<T> operator~() const { return *this ^ 0xFFu; }
4058+
40514059
// Addition/subtraction are the same for signed and unsigned
40524060
really_inline simd8<T> operator+(const simd8<T> other) const { return _mm_add_epi8(*this, other); }
40534061
really_inline simd8<T> operator-(const simd8<T> other) const { return _mm_sub_epi8(*this, other); }
@@ -5032,7 +5040,7 @@ really_inline uint64_t follows(const uint64_t match, uint64_t &overflow) {
50325040
really_inline uint64_t follows(const uint64_t match, const uint64_t filler, uint64_t &overflow) {
50335041
uint64_t follows_match = follows(match, overflow);
50345042
uint64_t result;
5035-
overflow |= add_overflow(follows_match, filler, &result);
5043+
overflow |= uint64_t(add_overflow(follows_match, filler, &result));
50365044
return result;
50375045
}
50385046

@@ -5914,9 +5922,9 @@ never_inline bool parse_large_integer(const uint8_t *const buf,
59145922
// content and append a space before calling this function.
59155923
//
59165924
// Our objective is accurate parsing (ULP of 0 or 1) at high speed.
5917-
really_inline bool parse_number(const uint8_t *const buf,
5918-
const uint32_t offset,
5919-
bool found_minus,
5925+
really_inline bool parse_number(UNUSED const uint8_t *const buf,
5926+
UNUSED const uint32_t offset,
5927+
UNUSED bool found_minus,
59205928
document::parser &parser) {
59215929
#ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes
59225930
// useful to skip parsing
@@ -7281,9 +7289,9 @@ never_inline bool parse_large_integer(const uint8_t *const buf,
72817289
// content and append a space before calling this function.
72827290
//
72837291
// Our objective is accurate parsing (ULP of 0 or 1) at high speed.
7284-
really_inline bool parse_number(const uint8_t *const buf,
7285-
const uint32_t offset,
7286-
bool found_minus,
7292+
really_inline bool parse_number(UNUSED const uint8_t *const buf,
7293+
UNUSED const uint32_t offset,
7294+
UNUSED bool found_minus,
72877295
document::parser &parser) {
72887296
#ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes
72897297
// useful to skip parsing
@@ -8658,9 +8666,9 @@ never_inline bool parse_large_integer(const uint8_t *const buf,
86588666
// content and append a space before calling this function.
86598667
//
86608668
// Our objective is accurate parsing (ULP of 0 or 1) at high speed.
8661-
really_inline bool parse_number(const uint8_t *const buf,
8662-
const uint32_t offset,
8663-
bool found_minus,
8669+
really_inline bool parse_number(UNUSED const uint8_t *const buf,
8670+
UNUSED const uint32_t offset,
8671+
UNUSED bool found_minus,
86648672
document::parser &parser) {
86658673
#ifdef SIMDJSON_SKIPNUMBERPARSING // for performance analysis, it is sometimes
86668674
// useful to skip parsing
@@ -9429,3 +9437,4 @@ UNTARGET_REGION
94299437
#endif // SIMDJSON_WESTMERE_STAGE2_BUILD_TAPE_H
94309438
/* end file src/generic/stage2_streaming_build_tape.h */
94319439
/* end file src/generic/stage2_streaming_build_tape.h */
9440+
/* end file src/generic/stage2_streaming_build_tape.h */

0 commit comments

Comments
 (0)