Skip to content

Commit 7cf3a75

Browse files
committed
Add fallback implementation to CI
- Also add SIMDJSON_IMPLEMENTATION_HASWELL/WESTMERE/ARM64/FALLBACK=1/0 to enable/disable various implemnentations
1 parent af203aa commit 7cf3a75

Some content is hidden

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

41 files changed

+126
-188
lines changed

.drone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ steps:
511511
environment:
512512
CC: clang
513513
CXX: clang++
514-
CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_DISABLE_AVX=ON
514+
CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_IMPLEMENTATION_HASWELL=OFF
515515
commands:
516516
- apt-get update -qq
517517
- apt-get install -y clang make cmake
@@ -534,7 +534,7 @@ steps:
534534
environment:
535535
CC: gcc
536536
CXX: g++
537-
CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_DISABLE_AVX=ON
537+
CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_IMPLEMENTATION_HASWELL=OFF
538538
commands:
539539
- apt-get update -qq
540540
- apt-get install -y cmake

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ objs
7777
/get_corpus_benchmark
7878
/json2json
7979
/jsoncheck
80-
/jsoncheck_noavx
80+
/jsoncheck_westmere
81+
/jsoncheck_fallback
8182
/jsonpointer
8283
/jsonstats
8384
/integer_tests

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ set(PROJECT_VERSION_PATCH 1)
3131
set(SIMDJSON_LIB_VERSION "0.2.1" CACHE STRING "simdjson library version")
3232
set(SIMDJSON_LIB_SOVERSION "0" CACHE STRING "simdjson library soversion")
3333

34-
option(SIMDJSON_DISABLE_AVX "Forcefully disable AVX even if hardware supports it" OFF)
34+
option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON)
35+
option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON)
36+
option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON)
37+
option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON)
3538
if(NOT MSVC)
3639
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
3740
else()

Makefile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ endif # ifeq ($(MEMSANITIZE),1)
6161
SRCHEADERS_GENERIC=src/generic/atomparsing.h src/generic/numberparsing.h src/generic/stage1_find_marks.h src/generic/stage2_build_tape.h src/generic/stringparsing.h src/generic/stage2_streaming_build_tape.h src/generic/utf8_fastvalidate_algorithm.h src/generic/utf8_lookup_algorithm.h src/generic/utf8_lookup2_algorithm.h src/generic/utf8_range_algorithm.h src/generic/utf8_zwegner_algorithm.h
6262
SRCHEADERS_ARM64= src/arm64/bitmanipulation.h src/arm64/bitmask.h src/arm64/intrinsics.h src/arm64/numberparsing.h src/arm64/simd.h src/arm64/stage1_find_marks.h src/arm64/stage2_build_tape.h src/arm64/stringparsing.h
6363
SRCHEADERS_HASWELL= src/haswell/bitmanipulation.h src/haswell/bitmask.h src/haswell/intrinsics.h src/haswell/numberparsing.h src/haswell/simd.h src/haswell/stage1_find_marks.h src/haswell/stage2_build_tape.h src/haswell/stringparsing.h
64-
SRCHEADERS_FALLBACK= src/fallback/implementation.h src/fallback/stage1_find_marks.h src/fallback/stage2_build_tape.h
64+
SRCHEADERS_FALLBACK= src/fallback/bitmanipulation.h src/fallback/implementation.h src/fallback/numberparsing.h src/fallback/stage1_find_marks.h src/fallback/stage2_build_tape.h src/fallback/stringparsing.h
6565
SRCHEADERS_WESTMERE=src/westmere/bitmanipulation.h src/westmere/bitmask.h src/westmere/intrinsics.h src/westmere/numberparsing.h src/westmere/simd.h src/westmere/stage1_find_marks.h src/westmere/stage2_build_tape.h src/westmere/stringparsing.h
6666
SRCHEADERS_SRC=src/isadetection.h src/jsoncharutils.h src/simdprune_tables.h src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/document_parser_callbacks.h
6767
SRCHEADERS=$(SRCHEADERS_SRC) $(SRCHEADERS_GENERIC) $(SRCHEADERS_ARM64) $(SRCHEADERS_HASWELL) $(SRCHEADERS_WESTMERE) $(SRCHEADERS_FALLBACK)
@@ -96,7 +96,7 @@ JSON_INCLUDE:=dependencies/json/single_include/nlohmann/json.hpp
9696
EXTRAOBJECTS=ujdecode.o
9797

9898
MAINEXECUTABLES=parse minify json2json jsonstats statisticalmodel jsonpointer get_corpus_benchmark
99-
TESTEXECUTABLES=jsoncheck jsoncheck_noavx integer_tests numberparsingcheck stringparsingcheck pointercheck parse_many_test basictests errortests readme_examples
99+
TESTEXECUTABLES=jsoncheck jsoncheck_westmere jsoncheck_fallback integer_tests numberparsingcheck stringparsingcheck pointercheck parse_many_test basictests errortests readme_examples
100100
COMPARISONEXECUTABLES=minifiercompetition parsingcompetition parseandstatcompetition distinctuseridcompetition allparserscheckfile allparsingcompetition
101101
SUPPLEMENTARYEXECUTABLES=parse_noutf8validation parse_nonumberparsing parse_nostringparsing
102102

@@ -134,8 +134,11 @@ run_jsoncheck: jsoncheck
134134
run_parse_many_test: parse_many_test
135135
./parse_many_test
136136

137-
run_jsoncheck_noavx: jsoncheck_noavx
138-
./jsoncheck_noavx
137+
run_jsoncheck_westmere: jsoncheck_westmere
138+
./jsoncheck_westmere
139+
140+
run_jsoncheck_fallback: jsoncheck_fallback
141+
./jsoncheck_fallback
139142

140143
run_pointercheck: pointercheck
141144
./pointercheck
@@ -152,12 +155,12 @@ $(FEATURE_JSON_FILES): benchmark/genfeaturejson.rb
152155
run_benchfeatures: benchfeatures $(FEATURE_JSON_FILES)
153156
./benchfeatures -n 1000
154157

155-
test: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_parse_many_test run_pointercheck run_testjson2json_sh run_issue150_sh run_jsoncheck_noavx
158+
test: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_parse_many_test run_pointercheck run_testjson2json_sh run_issue150_sh run_jsoncheck_westmere run_jsoncheck_fallback
156159
@echo "It looks like the code is good!"
157160

158-
quiettest: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_jsoncheck run_parse_many_test run_pointercheck run_testjson2json_sh run_issue150_sh run_jsoncheck_noavx
161+
quiettest: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_jsoncheck run_parse_many_test run_pointercheck run_testjson2json_sh run_issue150_sh run_jsoncheck_westmere run_jsoncheck_fallback
159162

160-
quicktests: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_jsoncheck run_parse_many_test run_pointercheck run_jsoncheck_noavx
163+
quicktests: run_basictests run_readme_examples run_jsoncheck run_numberparsingcheck run_integer_tests run_stringparsingcheck run_jsoncheck run_parse_many_test run_pointercheck run_jsoncheck_westmere run_jsoncheck_fallback
161164

162165
slowtests: run_testjson2json_sh run_issue150_sh
163166

@@ -215,8 +218,11 @@ parse_many_test:tests/parse_many_test.cpp $(HEADERS) $(LIBFILES)
215218
$(CXX) $(CXXFLAGS) -o parse_many_test tests/parse_many_test.cpp -I. $(LIBFILES) $(LIBFLAGS)
216219

217220

218-
jsoncheck_noavx:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES)
219-
$(CXX) $(CXXFLAGS) -o jsoncheck_noavx tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_DISABLE_AVX2_DETECTION
221+
jsoncheck_westmere:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES)
222+
$(CXX) $(CXXFLAGS) -o jsoncheck_westmere tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_IMPLEMENTATION_HASWELL=0
223+
224+
jsoncheck_fallback:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES)
225+
$(CXX) $(CXXFLAGS) -o jsoncheck_fallback tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_IMPLEMENTATION_HASWELL=0 -DSIMDJSON_IMPLEMENTATION_WESTMERE=0 -DSIMDJSON_IMPLEMENTATION_ARM64=0
220226

221227
basictests:tests/basictests.cpp $(HEADERS) $(LIBFILES)
222228
$(CXX) $(CXXFLAGS) -o basictests tests/basictests.cpp -I. $(LIBFILES) $(LIBFLAGS)

fuzz/build_fuzzer_variants.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ ! -d build-$variant ] ; then
2525
-DSIMDJSON_BUILD_STATIC=On \
2626
-DENABLE_FUZZING=On \
2727
-DSIMDJSON_FUZZ_LINKMAIN=On \
28-
-DSIMDJSON_DISABLE_AVX=On
28+
-DSIMDJSON_IMPLEMENTATION_HASWELL=0
2929

3030
ninja
3131
cd ..
@@ -69,7 +69,7 @@ if [ ! -d build-$variant ] ; then
6969
-DENABLE_FUZZING=On \
7070
-DSIMDJSON_FUZZ_LINKMAIN=Off \
7171
-DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE \
72-
-DSIMDJSON_DISABLE_AVX=On
72+
-DSIMDJSON_IMPLEMENTATION_HASWELL=0
7373

7474
ninja
7575
cd ..
@@ -97,7 +97,7 @@ if which clang++-8 >/dev/null 2>&1 ; then
9797
-DENABLE_FUZZING=On \
9898
-DSIMDJSON_FUZZ_LINKMAIN=Off \
9999
-DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE \
100-
-DSIMDJSON_DISABLE_AVX=On
100+
-DSIMDJSON_IMPLEMENTATION_HASWELL=0
101101

102102
ninja
103103
cd ..

include/simdjson/portability.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
#define STRINGIFY_IMPLEMENTATION_(a) #a
2222
#define STRINGIFY(a) STRINGIFY_IMPLEMENTATION_(a)
2323

24+
#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK
25+
#define SIMDJSON_IMPLEMENTATION_FALLBACK 1
26+
#endif
27+
28+
#if IS_ARM64
29+
#ifndef SIMDJSON_IMPLEMENTATION_ARM64
30+
#define SIMDJSON_IMPLEMENTATION_ARM64 1
31+
#endif
32+
#define SIMDJSON_IMPLEMENTATION_HASWELL 0
33+
#define SIMDJSON_IMPLEMENTATION_WESTMERE 0
34+
#endif // IS_ARM64
35+
36+
#if IS_X86_64
37+
#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
38+
#define SIMDJSON_IMPLEMENTATION_HASWELL 1
39+
#endif
40+
#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE
41+
#define SIMDJSON_IMPLEMENTATION_WESTMERE 1
42+
#endif
43+
#define SIMDJSON_IMPLEMENTATION_ARM64 0
44+
#endif // IS_X86_64
45+
2446
// we are going to use runtime dispatch
2547
#ifdef IS_X86_64
2648
#ifdef __clang__

singleheader/simdjson.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,9 @@ static inline uint32_t detect_supported_architectures() {
191191
eax = 0x7;
192192
ecx = 0x0;
193193
cpuid(&eax, &ebx, &ecx, &edx);
194-
#ifndef SIMDJSON_DISABLE_AVX2_DETECTION
195194
if (ebx & cpuid_avx2_bit) {
196195
host_isa |= instruction_set::AVX2;
197196
}
198-
#endif
199197
if (ebx & cpuid_bmi1_bit) {
200198
host_isa |= instruction_set::BMI1;
201199
}

src/arm64/bitmanipulation.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#define SIMDJSON_ARM64_BITMANIPULATION_H
33

44
#include "simdjson.h"
5-
6-
#ifdef IS_ARM64
7-
85
#include "arm64/intrinsics.h"
96

107
namespace simdjson::arm64 {
@@ -83,6 +80,4 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu
8380

8481
} // namespace simdjson::arm64
8582

86-
#endif // IS_ARM64
87-
8883
#endif // SIMDJSON_ARM64_BITMANIPULATION_H

src/arm64/bitmask.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include "simdjson.h"
55

6-
#ifdef IS_ARM64
7-
86
#include "arm64/intrinsics.h"
97

108
namespace simdjson::arm64 {
@@ -40,5 +38,4 @@ really_inline uint64_t prefix_xor(uint64_t bitmask) {
4038
} // namespace simdjson::arm64
4139
UNTARGET_REGION
4240

43-
#endif // IS_ARM64
4441
#endif

src/arm64/implementation.h

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

44
#include "simdjson.h"
5-
6-
#ifdef IS_ARM64
7-
85
#include "isadetection.h"
96

107
namespace simdjson::arm64 {
@@ -20,6 +17,4 @@ class implementation final : public simdjson::implementation {
2017

2118
} // namespace simdjson::arm64
2219

23-
#endif // IS_ARM64
24-
2520
#endif // SIMDJSON_ARM64_IMPLEMENTATION_H

0 commit comments

Comments
 (0)