From 3b8b7e89e4b1d148a4fd2bd3d5eda1ff8caf5e46 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 11 May 2022 18:17:25 -0400 Subject: [PATCH] Further guard the use of AVX-512. We require a compiler which we know supports VBMI2. --- .github/workflows/ubuntu22.yml | 33 ++++++++++++++++++++++++++++++ cmake/developer-options.cmake | 4 ++-- include/simdjson/implementations.h | 10 +++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ubuntu22.yml diff --git a/.github/workflows/ubuntu22.yml b/.github/workflows/ubuntu22.yml new file mode 100644 index 000000000..d7677f67d --- /dev/null +++ b/.github/workflows/ubuntu22.yml @@ -0,0 +1,33 @@ +name: Ubuntu 22.04 CI (GCC 11) + +on: [push, pull_request] + +jobs: + ubuntu-build: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: dependencies/.cache + key: ${{ hashFiles('dependencies/CMakeLists.txt') }} + - name: Use cmake + run: | + mkdir builddebug && + cd builddebug && + cmake -DCMAKE_BUILD_TYPE=Debug -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_DEVELOPER_MODE=ON -DBUILD_SHARED_LIBS=OFF .. && + cmake --build . && + ctest -j --output-on-failure -LE explicitonly && + cd .. && + mkdir build && + cd build && + cmake -DSIMDJSON_GOOGLE_BENCHMARKS=ON -DSIMDJSON_DEVELOPER_MODE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX:PATH=destination .. && + cmake --build . && + ctest -j --output-on-failure -LE explicitonly && + cmake --install . && + echo -e '#include \nint main(int argc,char**argv) {simdjson::dom::parser parser;simdjson::dom::element tweets = parser.load(argv[1]); }' > tmp.cpp && c++ -Idestination/include -Ldestination/lib -std=c++17 -Wl,-rpath,destination/lib -o linkandrun tmp.cpp -lsimdjson && ./linkandrun jsonexamples/twitter.json && + cd ../tests/installation_tests/find && + mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=../../../build/destination .. && cmake --build . diff --git a/cmake/developer-options.cmake b/cmake/developer-options.cmake index 38bcfd658..a0511704e 100644 --- a/cmake/developer-options.cmake +++ b/cmake/developer-options.cmake @@ -179,12 +179,12 @@ endif() option( SIMDJSON_AVX512_ALLOWED - "Enable AVX-512 instructions (only affects processors with AVX-512 support)." + "Enable AVX-512 instructions (only affects processors and compilers with AVX-512 support)." ON ) if(SIMDJSON_AVX512_ALLOWED) add_compile_definitions(SIMDJSON_AVX512_ALLOWED=1) - message(STATUS "AVX-512 instructions allowed if the CPU supports it.") + message(STATUS "AVX-512 instructions allowed if the CPU and compiler support it.") endif() include(CheckSymbolExists) diff --git a/include/simdjson/implementations.h b/include/simdjson/implementations.h index 8cf8fe53e..90615526c 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -13,14 +13,20 @@ #endif #define SIMDJSON_CAN_ALWAYS_RUN_ARM64 SIMDJSON_IMPLEMENTATION_ARM64 && SIMDJSON_IS_ARM64 +#ifdef __has_include +// How do we detect that a compiler supports vbmi2? +// For sure if the following header is found, we are ok? +#if __has_include() +#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 +#endif +#endif // Default Icelake to on if this is x86-64. Even if we're not compiled for it, it could be selected // at runtime. #ifndef SIMDJSON_IMPLEMENTATION_ICELAKE -#define SIMDJSON_IMPLEMENTATION_ICELAKE ((SIMDJSON_IS_X86_64) && (SIMDJSON_AVX512_ALLOWED)) +#define SIMDJSON_IMPLEMENTATION_ICELAKE ((SIMDJSON_IS_X86_64) && (SIMDJSON_AVX512_ALLOWED) && (SIMDJSON_COMPILER_SUPPORTS_VBMI2)) #endif - #ifdef _MSC_VER // To see why (__BMI__) && (__PCLMUL__) && (__LZCNT__) are not part of this next line, see // https://github.com/simdjson/simdjson/issues/1247