diff --git a/.drone.yml b/.drone.yml index f5eca687..9e551d85 100644 --- a/.drone.yml +++ b/.drone.yml @@ -511,7 +511,7 @@ steps: environment: CC: clang CXX: clang++ - CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_DISABLE_AVX=ON + CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_IMPLEMENTATION_HASWELL=OFF commands: - apt-get update -qq - apt-get install -y clang make cmake @@ -534,7 +534,7 @@ steps: environment: CC: gcc CXX: g++ - CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_DISABLE_AVX=ON + CMAKE_FLAGS: -DSIMDJSON_SANITIZE=ON -DSIMDJSON_IMPLEMENTATION_HASWELL=OFF commands: - apt-get update -qq - apt-get install -y cmake diff --git a/.gitignore b/.gitignore index 634adf3d..162fa78f 100644 --- a/.gitignore +++ b/.gitignore @@ -77,7 +77,8 @@ objs /get_corpus_benchmark /json2json /jsoncheck -/jsoncheck_noavx +/jsoncheck_westmere +/jsoncheck_fallback /jsonpointer /jsonstats /integer_tests diff --git a/CMakeLists.txt b/CMakeLists.txt index de0d1980..c5c7e92f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,10 @@ set(PROJECT_VERSION_PATCH 1) set(SIMDJSON_LIB_VERSION "0.2.1" CACHE STRING "simdjson library version") set(SIMDJSON_LIB_SOVERSION "0" CACHE STRING "simdjson library soversion") -option(SIMDJSON_DISABLE_AVX "Forcefully disable AVX even if hardware supports it" OFF) +option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON) +option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON) +option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON) +option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON) if(NOT MSVC) option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library else() diff --git a/Makefile b/Makefile index 020f1ce2..810a74cf 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ endif # ifeq ($(MEMSANITIZE),1) 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 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 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 -SRCHEADERS_FALLBACK= src/fallback/implementation.h src/fallback/stage1_find_marks.h src/fallback/stage2_build_tape.h +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 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 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 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 EXTRAOBJECTS=ujdecode.o MAINEXECUTABLES=parse minify json2json jsonstats statisticalmodel jsonpointer get_corpus_benchmark -TESTEXECUTABLES=jsoncheck jsoncheck_noavx integer_tests numberparsingcheck stringparsingcheck pointercheck parse_many_test basictests errortests readme_examples +TESTEXECUTABLES=jsoncheck jsoncheck_westmere jsoncheck_fallback integer_tests numberparsingcheck stringparsingcheck pointercheck parse_many_test basictests errortests readme_examples COMPARISONEXECUTABLES=minifiercompetition parsingcompetition parseandstatcompetition distinctuseridcompetition allparserscheckfile allparsingcompetition SUPPLEMENTARYEXECUTABLES=parse_noutf8validation parse_nonumberparsing parse_nostringparsing @@ -134,8 +134,11 @@ run_jsoncheck: jsoncheck run_parse_many_test: parse_many_test ./parse_many_test -run_jsoncheck_noavx: jsoncheck_noavx - ./jsoncheck_noavx +run_jsoncheck_westmere: jsoncheck_westmere + ./jsoncheck_westmere + +run_jsoncheck_fallback: jsoncheck_fallback + ./jsoncheck_fallback run_pointercheck: pointercheck ./pointercheck @@ -152,12 +155,12 @@ $(FEATURE_JSON_FILES): benchmark/genfeaturejson.rb run_benchfeatures: benchfeatures $(FEATURE_JSON_FILES) ./benchfeatures -n 1000 -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 +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 @echo "It looks like the code is good!" -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 +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 -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 +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 slowtests: run_testjson2json_sh run_issue150_sh @@ -215,8 +218,11 @@ parse_many_test:tests/parse_many_test.cpp $(HEADERS) $(LIBFILES) $(CXX) $(CXXFLAGS) -o parse_many_test tests/parse_many_test.cpp -I. $(LIBFILES) $(LIBFLAGS) -jsoncheck_noavx:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES) - $(CXX) $(CXXFLAGS) -o jsoncheck_noavx tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_DISABLE_AVX2_DETECTION +jsoncheck_westmere:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES) + $(CXX) $(CXXFLAGS) -o jsoncheck_westmere tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_IMPLEMENTATION_HASWELL=0 + +jsoncheck_fallback:tests/jsoncheck.cpp $(HEADERS) $(LIBFILES) + $(CXX) $(CXXFLAGS) -o jsoncheck_fallback tests/jsoncheck.cpp -I. $(LIBFILES) $(LIBFLAGS) -DSIMDJSON_IMPLEMENTATION_HASWELL=0 -DSIMDJSON_IMPLEMENTATION_WESTMERE=0 -DSIMDJSON_IMPLEMENTATION_ARM64=0 basictests:tests/basictests.cpp $(HEADERS) $(LIBFILES) $(CXX) $(CXXFLAGS) -o basictests tests/basictests.cpp -I. $(LIBFILES) $(LIBFLAGS) diff --git a/fuzz/build_fuzzer_variants.sh b/fuzz/build_fuzzer_variants.sh index 6fc1afb6..75bc39fb 100755 --- a/fuzz/build_fuzzer_variants.sh +++ b/fuzz/build_fuzzer_variants.sh @@ -25,7 +25,7 @@ if [ ! -d build-$variant ] ; then -DSIMDJSON_BUILD_STATIC=On \ -DENABLE_FUZZING=On \ -DSIMDJSON_FUZZ_LINKMAIN=On \ - -DSIMDJSON_DISABLE_AVX=On + -DSIMDJSON_IMPLEMENTATION_HASWELL=0 ninja cd .. @@ -69,7 +69,7 @@ if [ ! -d build-$variant ] ; then -DENABLE_FUZZING=On \ -DSIMDJSON_FUZZ_LINKMAIN=Off \ -DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE \ - -DSIMDJSON_DISABLE_AVX=On + -DSIMDJSON_IMPLEMENTATION_HASWELL=0 ninja cd .. @@ -97,7 +97,7 @@ if which clang++-8 >/dev/null 2>&1 ; then -DENABLE_FUZZING=On \ -DSIMDJSON_FUZZ_LINKMAIN=Off \ -DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE \ - -DSIMDJSON_DISABLE_AVX=On + -DSIMDJSON_IMPLEMENTATION_HASWELL=0 ninja cd .. diff --git a/include/simdjson/portability.h b/include/simdjson/portability.h index c4dac8be..2f8072b2 100644 --- a/include/simdjson/portability.h +++ b/include/simdjson/portability.h @@ -21,6 +21,28 @@ #define STRINGIFY_IMPLEMENTATION_(a) #a #define STRINGIFY(a) STRINGIFY_IMPLEMENTATION_(a) +#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK +#define SIMDJSON_IMPLEMENTATION_FALLBACK 1 +#endif + +#if IS_ARM64 +#ifndef SIMDJSON_IMPLEMENTATION_ARM64 +#define SIMDJSON_IMPLEMENTATION_ARM64 1 +#endif +#define SIMDJSON_IMPLEMENTATION_HASWELL 0 +#define SIMDJSON_IMPLEMENTATION_WESTMERE 0 +#endif // IS_ARM64 + +#if IS_X86_64 +#ifndef SIMDJSON_IMPLEMENTATION_HASWELL +#define SIMDJSON_IMPLEMENTATION_HASWELL 1 +#endif +#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE +#define SIMDJSON_IMPLEMENTATION_WESTMERE 1 +#endif +#define SIMDJSON_IMPLEMENTATION_ARM64 0 +#endif // IS_X86_64 + // we are going to use runtime dispatch #ifdef IS_X86_64 #ifdef __clang__ diff --git a/singleheader/simdjson.cpp b/singleheader/simdjson.cpp index 9ad1fdd4..ba25e97a 100644 --- a/singleheader/simdjson.cpp +++ b/singleheader/simdjson.cpp @@ -191,11 +191,9 @@ static inline uint32_t detect_supported_architectures() { eax = 0x7; ecx = 0x0; cpuid(&eax, &ebx, &ecx, &edx); -#ifndef SIMDJSON_DISABLE_AVX2_DETECTION if (ebx & cpuid_avx2_bit) { host_isa |= instruction_set::AVX2; } -#endif if (ebx & cpuid_bmi1_bit) { host_isa |= instruction_set::BMI1; } diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index cdc6278c..da00e7db 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_BITMANIPULATION_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "arm64/intrinsics.h" namespace simdjson::arm64 { @@ -83,6 +80,4 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu } // namespace simdjson::arm64 -#endif // IS_ARM64 - #endif // SIMDJSON_ARM64_BITMANIPULATION_H diff --git a/src/arm64/bitmask.h b/src/arm64/bitmask.h index 81a69c64..11f39a4d 100644 --- a/src/arm64/bitmask.h +++ b/src/arm64/bitmask.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#ifdef IS_ARM64 - #include "arm64/intrinsics.h" namespace simdjson::arm64 { @@ -40,5 +38,4 @@ really_inline uint64_t prefix_xor(uint64_t bitmask) { } // namespace simdjson::arm64 UNTARGET_REGION -#endif // IS_ARM64 #endif diff --git a/src/arm64/implementation.h b/src/arm64/implementation.h index 56650509..4766cb4e 100644 --- a/src/arm64/implementation.h +++ b/src/arm64/implementation.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_IMPLEMENTATION_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "isadetection.h" namespace simdjson::arm64 { @@ -20,6 +17,4 @@ public: } // namespace simdjson::arm64 -#endif // IS_ARM64 - #endif // SIMDJSON_ARM64_IMPLEMENTATION_H diff --git a/src/arm64/intrinsics.h b/src/arm64/intrinsics.h index 71813c5a..ceebaf24 100644 --- a/src/arm64/intrinsics.h +++ b/src/arm64/intrinsics.h @@ -3,11 +3,8 @@ #include "simdjson.h" -#ifdef IS_ARM64 - // This should be the correct header whether // you use visual studio or other compilers. #include -#endif // IS_ARM64 #endif // SIMDJSON_ARM64_INTRINSICS_H diff --git a/src/arm64/numberparsing.h b/src/arm64/numberparsing.h index 4c8c54a4..03523a42 100644 --- a/src/arm64/numberparsing.h +++ b/src/arm64/numberparsing.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_NUMBERPARSING_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "jsoncharutils.h" #include "arm64/intrinsics.h" #include "arm64/bitmanipulation.h" @@ -35,9 +32,6 @@ static inline uint32_t parse_eight_digits_unrolled(const char *chars) { #include "generic/numberparsing.h" +} // namespace simdjson::arm64 -}// namespace simdjson::arm64 - - -#endif // IS_ARM64 -#endif // SIMDJSON_ARM64_NUMBERPARSING_H +#endif // SIMDJSON_ARM64_NUMBERPARSING_H diff --git a/src/arm64/simd.h b/src/arm64/simd.h index 0c13dfb4..bb21b273 100644 --- a/src/arm64/simd.h +++ b/src/arm64/simd.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_SIMD_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "arm64/intrinsics.h" namespace simdjson::arm64::simd { @@ -347,5 +344,4 @@ namespace simdjson::arm64::simd { } // namespace simdjson::arm64::simd -#endif // IS_ARM64 #endif // SIMDJSON_ARM64_SIMD_H diff --git a/src/arm64/stage1_find_marks.h b/src/arm64/stage1_find_marks.h index 62665b78..7a15921b 100644 --- a/src/arm64/stage1_find_marks.h +++ b/src/arm64/stage1_find_marks.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_STAGE1_FIND_MARKS_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "arm64/bitmask.h" #include "arm64/simd.h" #include "arm64/bitmanipulation.h" @@ -56,6 +53,4 @@ WARN_UNUSED error_code implementation::stage1(const uint8_t *buf, size_t len, do } // namespace simdjson::arm64 -#endif // IS_ARM64 - #endif // SIMDJSON_ARM64_STAGE1_FIND_MARKS_H diff --git a/src/arm64/stage2_build_tape.h b/src/arm64/stage2_build_tape.h index 7179e2c4..2b711157 100644 --- a/src/arm64/stage2_build_tape.h +++ b/src/arm64/stage2_build_tape.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_STAGE2_BUILD_TAPE_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "arm64/implementation.h" #include "arm64/stringparsing.h" #include "arm64/numberparsing.h" @@ -17,6 +14,4 @@ namespace simdjson::arm64 { } // namespace simdjson::arm64 -#endif // IS_ARM64 - #endif // SIMDJSON_ARM64_STAGE2_BUILD_TAPE_H diff --git a/src/arm64/stringparsing.h b/src/arm64/stringparsing.h index 3cd78dee..7dd9db68 100644 --- a/src/arm64/stringparsing.h +++ b/src/arm64/stringparsing.h @@ -2,9 +2,6 @@ #define SIMDJSON_ARM64_STRINGPARSING_H #include "simdjson.h" - -#ifdef IS_ARM64 - #include "jsoncharutils.h" #include "arm64/simd.h" #include "arm64/intrinsics.h" @@ -52,6 +49,4 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 } // namespace simdjson::amd64 -#endif // IS_ARM64 - #endif // SIMDJSON_ARM64_STRINGPARSING_H diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index 31397155..6ef91a97 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#ifdef IS_X86_64 - #include "haswell/intrinsics.h" TARGET_HASWELL @@ -76,6 +74,4 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, }// namespace simdjson::haswell UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_BITMANIPULATION_H diff --git a/src/haswell/bitmask.h b/src/haswell/bitmask.h index 3ef707a8..f97272e6 100644 --- a/src/haswell/bitmask.h +++ b/src/haswell/bitmask.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#ifdef IS_X86_64 - #include "haswell/intrinsics.h" TARGET_HASWELL @@ -26,6 +24,4 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { } // namespace simdjson::haswell UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_BITMASK_H diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index 5dec34d5..d9f50514 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -2,9 +2,6 @@ #define SIMDJSON_HASWELL_IMPLEMENTATION_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "isadetection.h" namespace simdjson::haswell { @@ -24,6 +21,4 @@ public: } // namespace simdjson::haswell -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/haswell/intrinsics.h b/src/haswell/intrinsics.h index b426de90..bc978822 100644 --- a/src/haswell/intrinsics.h +++ b/src/haswell/intrinsics.h @@ -3,14 +3,10 @@ #include "simdjson.h" -#ifdef IS_X86_64 - #ifdef _MSC_VER #include // visual studio #else #include // elsewhere #endif // _MSC_VER -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_INTRINSICS_H diff --git a/src/haswell/numberparsing.h b/src/haswell/numberparsing.h index 7307ee41..41ad4246 100644 --- a/src/haswell/numberparsing.h +++ b/src/haswell/numberparsing.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#ifdef IS_X86_64 - #include "jsoncharutils.h" #include "haswell/intrinsics.h" #include "haswell/bitmanipulation.h" @@ -45,6 +43,4 @@ static inline uint32_t parse_eight_digits_unrolled(const char *chars) { } // namespace simdjson::haswell UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_NUMBERPARSING_H diff --git a/src/haswell/simd.h b/src/haswell/simd.h index 396376ec..4850dabb 100644 --- a/src/haswell/simd.h +++ b/src/haswell/simd.h @@ -2,9 +2,6 @@ #define SIMDJSON_HASWELL_SIMD_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "haswell/intrinsics.h" TARGET_HASWELL @@ -311,6 +308,4 @@ namespace simdjson::haswell::simd { } // namespace simdjson::haswell::simd UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_SIMD_H diff --git a/src/haswell/stage1_find_marks.h b/src/haswell/stage1_find_marks.h index 97dab6a8..4c19e930 100644 --- a/src/haswell/stage1_find_marks.h +++ b/src/haswell/stage1_find_marks.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#ifdef IS_X86_64 - #include "haswell/bitmask.h" #include "haswell/simd.h" #include "haswell/bitmanipulation.h" @@ -55,6 +53,4 @@ WARN_UNUSED error_code implementation::stage1(const uint8_t *buf, size_t len, do } // namespace simdjson::haswell UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_STAGE1_FIND_MARKS_H diff --git a/src/haswell/stage2_build_tape.h b/src/haswell/stage2_build_tape.h index 8f22d54e..34560779 100644 --- a/src/haswell/stage2_build_tape.h +++ b/src/haswell/stage2_build_tape.h @@ -2,9 +2,6 @@ #define SIMDJSON_HASWELL_STAGE2_BUILD_TAPE_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "haswell/implementation.h" #include "haswell/stringparsing.h" #include "haswell/numberparsing.h" @@ -19,6 +16,4 @@ namespace simdjson::haswell { } // namespace simdjson UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_STAGE2_BUILD_TAPE_H diff --git a/src/haswell/stringparsing.h b/src/haswell/stringparsing.h index 78cfae62..6e6a633c 100644 --- a/src/haswell/stringparsing.h +++ b/src/haswell/stringparsing.h @@ -2,9 +2,6 @@ #define SIMDJSON_HASWELL_STRINGPARSING_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "jsoncharutils.h" #include "haswell/simd.h" #include "haswell/intrinsics.h" @@ -48,6 +45,4 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 } // namespace simdjson::haswell UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_HASWELL_STRINGPARSING_H diff --git a/src/implementation.cpp b/src/implementation.cpp index b1c446bc..5d40df29 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -1,39 +1,46 @@ #include "simdjson.h" +#include "isadetection.h" #include // Static array of known implementations. We're hoping these get baked into the executable // without requiring a static initializer. -#ifdef IS_X86_64 - +#if SIMDJSON_IMPLEMENTATION_HASWELL #include "haswell/implementation.h" +namespace simdjson::internal { const haswell::implementation haswell_singleton{}; } +#endif // SIMDJSON_IMPLEMENTATION_HASWELL + +#if SIMDJSON_IMPLEMENTATION_WESTMERE #include "westmere/implementation.h" -#include "fallback/implementation.h" - -namespace simdjson::internal { -const fallback::implementation fallback_singleton{}; -const haswell::implementation haswell_singleton{}; -const westmere::implementation westmere_singleton{}; -constexpr const std::initializer_list available_implementation_pointers { &haswell_singleton, &westmere_singleton, &fallback_singleton }; -} - -#endif - -#ifdef IS_ARM64 +namespace simdjson::internal { const westmere::implementation westmere_singleton{}; } +#endif // SIMDJSON_IMPLEMENTATION_WESTMERE +#if SIMDJSON_IMPLEMENTATION_ARM64 #include "arm64/implementation.h" +namespace simdjson::internal { const arm64::implementation arm64_singleton{}; } +#endif // SIMDJSON_IMPLEMENTATION_ARM64 + +#if SIMDJSON_IMPLEMENTATION_FALLBACK #include "fallback/implementation.h" +namespace simdjson::internal { const fallback::implementation fallback_singleton{}; } +#endif // SIMDJSON_IMPLEMENTATION_FALLBACK namespace simdjson::internal { -const fallback::implementation fallback_singleton{}; -const arm64::implementation arm64_singleton{}; -constexpr const std::initializer_list available_implementation_pointers { &arm64_singleton, &fallback_singleton }; -} +constexpr const std::initializer_list available_implementation_pointers { +#if SIMDJSON_IMPLEMENTATION_HASWELL + &haswell_singleton, #endif - - -namespace simdjson::internal { +#if SIMDJSON_IMPLEMENTATION_WESTMERE + &westmere_singleton, +#endif +#if SIMDJSON_IMPLEMENTATION_ARM64 + &arm64_singleton, +#endif +#if SIMDJSON_IMPLEMENTATION_FALLBACK + &fallback_singleton, +#endif +}; // available_implementation_pointers // So we can return UNSUPPORTED_ARCHITECTURE from the parser when there is no support class unsupported_implementation final : public implementation { @@ -79,4 +86,4 @@ const implementation *detect_best_supported_implementation_on_first_use::set_bes return active_implementation = available_implementations.detect_best_supported(); } -} // namespace simdjson +} // namespace simdjson::internal diff --git a/src/isadetection.h b/src/isadetection.h index c881c85f..b7047598 100644 --- a/src/isadetection.h +++ b/src/isadetection.h @@ -120,11 +120,9 @@ static inline uint32_t detect_supported_architectures() { eax = 0x7; ecx = 0x0; cpuid(&eax, &ebx, &ecx, &edx); -#ifndef SIMDJSON_DISABLE_AVX2_DETECTION if (ebx & cpuid_avx2_bit) { host_isa |= instruction_set::AVX2; } -#endif if (ebx & cpuid_bmi1_bit) { host_isa |= instruction_set::BMI1; } diff --git a/src/stage1_find_marks.cpp b/src/stage1_find_marks.cpp index 5ea28617..338b954a 100644 --- a/src/stage1_find_marks.cpp +++ b/src/stage1_find_marks.cpp @@ -1,4 +1,12 @@ +#if SIMDJSON_IMPLEMENTATION_ARM64 #include "arm64/stage1_find_marks.h" +#endif +#if SIMDJSON_IMPLEMENTATION_FALLBACK #include "fallback/stage1_find_marks.h" +#endif +#if SIMDJSON_IMPLEMENTATION_HASWELL #include "haswell/stage1_find_marks.h" +#endif +#if SIMDJSON_IMPLEMENTATION_WESTMERE #include "westmere/stage1_find_marks.h" +#endif diff --git a/src/stage2_build_tape.cpp b/src/stage2_build_tape.cpp index c0d1919d..2a525ceb 100644 --- a/src/stage2_build_tape.cpp +++ b/src/stage2_build_tape.cpp @@ -12,7 +12,15 @@ void found_string(const uint8_t *buf, const uint8_t *parsed_begin, void found_bad_string(const uint8_t *buf); #endif +#if SIMDJSON_IMPLEMENTATION_ARM64 #include "arm64/stage2_build_tape.h" +#endif +#if SIMDJSON_IMPLEMENTATION_FALLBACK #include "fallback/stage2_build_tape.h" +#endif +#if SIMDJSON_IMPLEMENTATION_HASWELL #include "haswell/stage2_build_tape.h" +#endif +#if SIMDJSON_IMPLEMENTATION_WESTMERE #include "westmere/stage2_build_tape.h" +#endif diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index 81b68180..e6c7e45b 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_BITMANIPULATION_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "westmere/intrinsics.h" TARGET_WESTMERE @@ -84,9 +81,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } -}// namespace simdjson::westmere +} // namespace simdjson::westmere UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_WESTMERE_BITMANIPULATION_H diff --git a/src/westmere/bitmask.h b/src/westmere/bitmask.h index 95ef3802..58eacca3 100644 --- a/src/westmere/bitmask.h +++ b/src/westmere/bitmask.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_BITMASK_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "westmere/intrinsics.h" TARGET_WESTMERE @@ -26,6 +23,4 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { } // namespace simdjson::westmere UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_WESTMERE_BITMASK_H diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index 029743d6..4675867e 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_IMPLEMENTATION_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "simdjson/implementation.h" #include "isadetection.h" @@ -21,6 +18,4 @@ public: } // namespace simdjson::westmere -#endif // IS_X86_64 - #endif // SIMDJSON_WESTMERE_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/westmere/intrinsics.h b/src/westmere/intrinsics.h index 129bbd1b..127dce96 100644 --- a/src/westmere/intrinsics.h +++ b/src/westmere/intrinsics.h @@ -1,12 +1,10 @@ #ifndef SIMDJSON_WESTMERE_INTRINSICS_H #define SIMDJSON_WESTMERE_INTRINSICS_H -#ifdef IS_X86_64 #ifdef _MSC_VER #include // visual studio #else #include // elsewhere #endif // _MSC_VER -#endif // IS_X86_64 #endif // SIMDJSON_WESTMERE_INTRINSICS_H diff --git a/src/westmere/numberparsing.h b/src/westmere/numberparsing.h index f12d38b5..cf039498 100644 --- a/src/westmere/numberparsing.h +++ b/src/westmere/numberparsing.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_NUMBERPARSING_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "jsoncharutils.h" #include "westmere/intrinsics.h" #include "westmere/bitmanipulation.h" @@ -47,7 +44,4 @@ static inline uint32_t parse_eight_digits_unrolled(const char *chars) { } // namespace simdjson::westmere UNTARGET_REGION - - -#endif // IS_X86_64 #endif // SIMDJSON_WESTMERE_NUMBERPARSING_H diff --git a/src/westmere/simd.h b/src/westmere/simd.h index b97f9bd2..c399a7a4 100644 --- a/src/westmere/simd.h +++ b/src/westmere/simd.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_SIMD_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "westmere/intrinsics.h" TARGET_WESTMERE @@ -311,5 +308,4 @@ namespace simdjson::westmere::simd { } // namespace simdjson::westmere::simd UNTARGET_REGION -#endif // IS_X86_64 #endif // SIMDJSON_WESTMERE_SIMD_INPUT_H diff --git a/src/westmere/stage1_find_marks.h b/src/westmere/stage1_find_marks.h index b3e2ad1e..c229a232 100644 --- a/src/westmere/stage1_find_marks.h +++ b/src/westmere/stage1_find_marks.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_STAGE1_FIND_MARKS_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "westmere/bitmask.h" #include "westmere/simd.h" #include "westmere/bitmanipulation.h" @@ -57,5 +54,4 @@ WARN_UNUSED error_code implementation::stage1(const uint8_t *buf, size_t len, do } // namespace simdjson::westmere UNTARGET_REGION -#endif // IS_X86_64 #endif // SIMDJSON_WESTMERE_STAGE1_FIND_MARKS_H diff --git a/src/westmere/stage2_build_tape.h b/src/westmere/stage2_build_tape.h index 7d41c4b4..d8c86347 100644 --- a/src/westmere/stage2_build_tape.h +++ b/src/westmere/stage2_build_tape.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_STAGE2_BUILD_TAPE_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "westmere/implementation.h" #include "westmere/stringparsing.h" #include "westmere/numberparsing.h" @@ -18,7 +15,4 @@ namespace simdjson::westmere { } // namespace simdjson::westmere UNTARGET_REGION - -#endif // IS_X86_64 - #endif // SIMDJSON_WESTMERE_STAGE2_BUILD_TAPE_H diff --git a/src/westmere/stringparsing.h b/src/westmere/stringparsing.h index 44d382f3..1c3a52a3 100644 --- a/src/westmere/stringparsing.h +++ b/src/westmere/stringparsing.h @@ -2,9 +2,6 @@ #define SIMDJSON_WESTMERE_STRINGPARSING_H #include "simdjson.h" - -#ifdef IS_X86_64 - #include "jsoncharutils.h" #include "westmere/simd.h" #include "westmere/intrinsics.h" @@ -50,6 +47,4 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 } // namespace simdjson::westmere UNTARGET_REGION -#endif // IS_X86_64 - #endif // SIMDJSON_WESTMERE_STRINGPARSING_H diff --git a/tests/basictests.cpp b/tests/basictests.cpp index 6d5599f6..f0083c52 100644 --- a/tests/basictests.cpp +++ b/tests/basictests.cpp @@ -10,7 +10,9 @@ #include #include #include +#ifndef _MSC_VER #include +#endif #include "simdjson.h" @@ -1459,7 +1461,8 @@ bool lots_of_brackets() { int main(int argc, char *argv[]) { std::cout << std::unitbuf; - char c; +#ifndef _MSC_VER + int c; while ((c = getopt(argc, argv, "a:")) != -1) { switch (c) { case 'a': { @@ -1476,6 +1479,9 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } } +#else + int optind = 1; +#endif // this is put here deliberately to check that the documentation is correct (README), // should this fail to compile, you should update the documentation: diff --git a/tests/jsoncheck.cpp b/tests/jsoncheck.cpp index b8a80b28..32f57b10 100644 --- a/tests/jsoncheck.cpp +++ b/tests/jsoncheck.cpp @@ -112,7 +112,28 @@ bool validate(const char *dirname) { } int main(int argc, char *argv[]) { - if (argc != 2) { +#ifndef _MSC_VER + int c; + while ((c = getopt(argc, argv, "a:")) != -1) { + switch (c) { + case 'a': { + const simdjson::implementation *impl = simdjson::available_implementations[optarg]; + if (!impl) { + fprintf(stderr, "Unsupported architecture value -a %s\n", optarg); + return EXIT_FAILURE; + } + simdjson::active_implementation = impl; + break; + } + default: + fprintf(stderr, "Unexpected argument %c\n", c); + return EXIT_FAILURE; + } + } +#else + int optind = 1; +#endif + if ((argc - optind) != 1) { std::cerr << "Usage: " << argv[0] << " " << std::endl; #ifndef SIMDJSON_TEST_DATA_DIR @@ -126,5 +147,5 @@ int main(int argc, char *argv[]) { return validate(SIMDJSON_TEST_DATA_DIR) ? EXIT_SUCCESS : EXIT_FAILURE; #endif } - return validate(argv[1]) ? EXIT_SUCCESS : EXIT_FAILURE; + return validate(argv[optind]) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tools/cmake/FindOptions.cmake b/tools/cmake/FindOptions.cmake index 81030a9a..2c665a38 100644 --- a/tools/cmake/FindOptions.cmake +++ b/tools/cmake/FindOptions.cmake @@ -18,23 +18,6 @@ else () set (X64 FALSE) endif () -if(X64) - message(STATUS "Detected x64 processor: ${CMAKE_SYSTEM_PROCESSOR}") - if(SIMDJSON_DISABLE_AVX) - message(STATUS "Disabling AVX. No runtime dispatch.") - if(NOT MSVC) - set (OPT_FLAGS "${OPT_FLAGS} -mno-avx -mno-bmi -mpclmul -msse4.2") #westmere - else() - set (OPT_FLAGS "${OPT_FLAGS}") - endif() - else() - if(NOT MSVC) - message(STATUS "Assuming Westmere or better") - set (OPT_FLAGS "${OPT_FLAGS} -mpclmul -msse4.2") - endif() - endif() -endif() - if(SIMDJSON_EXCEPTIONS) set(OPT_FLAGS "${OPT_FLAGS} -DSIMDJSON_EXCEPTIONS=1") else()