Merge pull request #2806 from google:dependabot/github_actions/step-security/harden-runner-2.13.3 PiperOrigin-RevId: 839244210
diff --git a/CMakeLists.txt b/CMakeLists.txt index 65139b7..3f5e7c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -97,21 +97,15 @@ if ("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES) set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_17) else() - if ("cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES) - set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_14) - else() - set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_11) - endif() + message(WARNING "cxx_std_17 not found in CMAKE_CXX_COMPILE_FEATURES but vqsort requires C++17") + set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_14) endif() else() - if (CMAKE_CXX_STANDARD GREATER_EQUAL 14 AND CMAKE_CXX_STANDARD LESS 98) - if (CMAKE_CXX_STANDARD GREATER_EQUAL 17) - set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_17) - else() - set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_14) - endif() + if (CMAKE_CXX_STANDARD GREATER_EQUAL 17 AND CMAKE_CXX_STANDARD LESS 98) + set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_17) else() - set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_11) + message(WARNING "CMAKE_CXX_STANDARD < 17 but vqsort requires C++17") + set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_14) endif() endif() @@ -445,7 +439,7 @@ endif() # Suppress STL iterator warnings. Supported by GCC 4.4.7 and newer, which - # predates the C++11 we require. + # predates the C++14 (and C++17 for VQSort) we require. if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") list(APPEND HWY_FLAGS -Wno-psabi) endif()
diff --git a/README.md b/README.md index d6cc1f5..07b74e8 100644 --- a/README.md +++ b/README.md
@@ -31,9 +31,9 @@ **Works on widely-used platforms**: Highway supports seven architectures; the same application code can target various instruction sets, including those with -'scalable' vectors (size unknown at compile time). Highway only requires C++11 -and supports four families of compilers. If you would like to use Highway on -other platforms, please raise an issue. +'scalable' vectors (size unknown at compile time). Highway only requires C++17 +(language features, not necessarily the library) and supports four families of +compilers. If you want to use Highway on other platforms, please raise an issue. **Flexible to deploy**: Applications using Highway can run on heterogeneous clouds or client devices, choosing the best available instruction set at
diff --git a/hwy/base.h b/hwy/base.h index ef920cf..ddb9e04 100644 --- a/hwy/base.h +++ b/hwy/base.h
@@ -1118,11 +1118,8 @@ #define HWY_BITCASTSCALAR_CONSTEXPR #endif -#if __cpp_constexpr >= 201304L +// C++14 is now required. #define HWY_BITCASTSCALAR_CXX14_CONSTEXPR HWY_BITCASTSCALAR_CONSTEXPR -#else -#define HWY_BITCASTSCALAR_CXX14_CONSTEXPR -#endif #if HWY_HAS_BUILTIN(__builtin_bit_cast) || HWY_COMPILER_MSVC >= 1926 namespace detail {
diff --git a/hwy/contrib/algo/copy_test.cc b/hwy/contrib/algo/copy_test.cc index 1158405..1a7b788 100644 --- a/hwy/contrib/algo/copy_test.cc +++ b/hwy/contrib/algo/copy_test.cc
@@ -26,14 +26,6 @@ #include "hwy/tests/test_util-inl.h" // clang-format on -// If your project requires C++14 or later, you can ignore this and pass lambdas -// directly to Transform, without requiring an lvalue as we do here for C++11. -#if __cplusplus < 201402L -#define HWY_GENERIC_LAMBDA 0 -#else -#define HWY_GENERIC_LAMBDA 1 -#endif - HWY_BEFORE_NAMESPACE(); namespace hwy { namespace HWY_NAMESPACE { @@ -45,19 +37,6 @@ return ConvertScalarTo<T>(Random32(&rng) & 127); } -// In C++14, we can instead define these as generic lambdas next to where they -// are invoked. -#if !HWY_GENERIC_LAMBDA - -struct IsOdd { - template <class D, class V> - Mask<D> operator()(D d, V v) const { - return TestBit(v, Set(d, TFromD<D>{1})); - } -}; - -#endif // !HWY_GENERIC_LAMBDA - // Invokes Test (e.g. TestCopyIf) with all arg combinations. T comes from // ForFloatTypes. template <class Test> @@ -168,13 +147,9 @@ } } -#if HWY_GENERIC_LAMBDA const auto is_odd = [](const auto d2, const auto v) HWY_ATTR { return TestBit(v, Set(d2, TFromD<decltype(d2)>{1})); }; -#else - const IsOdd is_odd; -#endif T* end = CopyIf(d, a, count, b, is_odd); const size_t num_written = static_cast<size_t>(end - b); HWY_ASSERT_EQ(num_odd, num_written);
diff --git a/hwy/contrib/algo/find_test.cc b/hwy/contrib/algo/find_test.cc index c525f25..7c772d1 100644 --- a/hwy/contrib/algo/find_test.cc +++ b/hwy/contrib/algo/find_test.cc
@@ -31,14 +31,6 @@ #include "hwy/tests/test_util-inl.h" // clang-format on -// If your project requires C++14 or later, you can ignore this and pass lambdas -// directly to FindIf, without requiring an lvalue as we do here for C++11. -#if __cplusplus < 201402L -#define HWY_GENERIC_LAMBDA 0 -#else -#define HWY_GENERIC_LAMBDA 1 -#endif - HWY_BEFORE_NAMESPACE(); namespace hwy { namespace HWY_NAMESPACE { @@ -57,24 +49,6 @@ return ConvertScalarTo<T>(val); } -// In C++14, we can instead define these as generic lambdas next to where they -// are invoked. -#if !HWY_GENERIC_LAMBDA - -class GreaterThan { - public: - GreaterThan(int val) : val_(val) {} - template <class D, class V> - Mask<D> operator()(D d, V v) const { - return Gt(v, Set(d, ConvertScalarTo<TFromD<D>>(val_))); - } - - private: - int val_; -}; - -#endif // !HWY_GENERIC_LAMBDA - // Invokes Test (e.g. TestFind) with all arg combinations. template <class Test> struct ForeachCountAndMisalign { @@ -172,13 +146,9 @@ const int min_val = IsSigned<T>() ? -9 : 0; // Includes out-of-range value 9 to test the not-found path. for (int val = min_val; val <= 9; ++val) { -#if HWY_GENERIC_LAMBDA const auto greater = [val](const auto d2, const auto v) HWY_ATTR { return Gt(v, Set(d2, ConvertScalarTo<T>(val))); }; -#else - const GreaterThan greater(val); -#endif const size_t actual = FindIf(d, in, count, greater); found_any |= actual < count; not_found_any |= actual == count;
diff --git a/hwy/contrib/algo/transform_test.cc b/hwy/contrib/algo/transform_test.cc index cc489c9..f367e4e 100644 --- a/hwy/contrib/algo/transform_test.cc +++ b/hwy/contrib/algo/transform_test.cc
@@ -29,14 +29,6 @@ #include "hwy/tests/test_util-inl.h" // clang-format on -// If your project requires C++14 or later, you can ignore this and pass lambdas -// directly to Transform, without requiring an lvalue as we do here for C++11. -#if __cplusplus < 201402L -#define HWY_GENERIC_LAMBDA 0 -#else -#define HWY_GENERIC_LAMBDA 1 -#endif - HWY_BEFORE_NAMESPACE(); namespace hwy { namespace HWY_NAMESPACE { @@ -79,43 +71,6 @@ } } -// In C++14, we can instead define these as generic lambdas next to where they -// are invoked. -#if !HWY_GENERIC_LAMBDA - -// Generator that returns even numbers by doubling the output indices. -struct Gen2 { - template <class D, class VU> - Vec<D> operator()(D d, VU vidx) const { - return BitCast(d, Add(vidx, vidx)); - } -}; - -struct SCAL { - template <class D, class V> - Vec<D> operator()(D d, V v) const { - using T = TFromD<D>; - return Mul(Set(d, ConvertScalarTo<T>(kAlpha)), v); - } -}; - -struct AXPY { - template <class D, class V> - Vec<D> operator()(D d, V v, V v1) const { - using T = TFromD<D>; - return MulAdd(Set(d, ConvertScalarTo<T>(kAlpha)), v, v1); - } -}; - -struct FMA4 { - template <class D, class V> - Vec<D> operator()(D /*d*/, V v, V v1, V v2) const { - return MulAdd(v, v1, v2); - } -}; - -#endif // !HWY_GENERIC_LAMBDA - // Invokes Test (e.g. TestTransform1) with all arg combinations. T comes from // ForFloatTypes. template <class Test> @@ -172,12 +127,8 @@ // TODO(janwas): can we update the apply_to in HWY_PUSH_ATTRIBUTES so that // the attribute also applies to lambdas? If so, remove HWY_ATTR. -#if HWY_GENERIC_LAMBDA const auto gen2 = [](const auto d2, const auto vidx) HWY_ATTR { return BitCast(d2, Add(vidx, vidx)); }; -#else - const Gen2 gen2; -#endif actual[count] = ConvertScalarTo<T>(0); // sentinel Generate(d, actual, count, gen2); HWY_ASSERT_EQ(ConvertScalarTo<T>(0), actual[count]); // no write past end @@ -244,13 +195,9 @@ // TODO(janwas): can we update the apply_to in HWY_PUSH_ATTRIBUTES so that // the attribute also applies to lambdas? If so, remove HWY_ATTR. -#if HWY_GENERIC_LAMBDA const auto scal = [](const auto d2, const auto v) HWY_ATTR { return Mul(Set(d2, ConvertScalarTo<T>(kAlpha)), v); }; -#else - const SCAL scal; -#endif Transform(d, a, count, scal); const auto info = hwy::detail::MakeTypeInfo<T>(); @@ -289,13 +236,9 @@ SimpleAXPY(a, b, expected.get(), count); -#if HWY_GENERIC_LAMBDA const auto axpy = [](const auto d2, const auto v, const auto v1) HWY_ATTR { return MulAdd(Set(d2, ConvertScalarTo<T>(kAlpha)), v, v1); }; -#else - const AXPY axpy; -#endif Transform1(d, a, count, b, axpy); AssertArraySimilar(expected.get(), a, count, hwy::TargetName(HWY_TARGET), @@ -335,12 +278,8 @@ SimpleFMA4(a, b, c, expected.get(), count); -#if HWY_GENERIC_LAMBDA const auto fma4 = [](auto /*d*/, auto v, auto v1, auto v2) HWY_ATTR { return MulAdd(v, v1, v2); }; -#else - const FMA4 fma4; -#endif Transform2(d, a, count, b, c, fma4); AssertArraySimilar(expected.get(), a, count, hwy::TargetName(HWY_TARGET),
diff --git a/hwy/contrib/bit_pack/bit_pack-inl.h b/hwy/contrib/bit_pack/bit_pack-inl.h index 09d37ac..c041c13 100644 --- a/hwy/contrib/bit_pack/bit_pack-inl.h +++ b/hwy/contrib/bit_pack/bit_pack-inl.h
@@ -2623,7 +2623,7 @@ T* HWY_RESTRICT packed_out, const V& mask, const V& frame_of_reference, V& in, V& out) { // Avoid compilation errors and unnecessary template instantiation if - // compiling in C++11 or C++14 mode + // compiling in C++14 mode using NextUnroller = BitPackUnroller< T, kBits, ((S <= B) ? (S + ((S < B) ? kBits : 0)) : (S % B)), kLoadPos + static_cast<size_t>(S < B), @@ -2669,7 +2669,7 @@ T* HWY_RESTRICT raw, const V& mask, const V& frame_of_reference, V& in, V& out) { // Avoid compilation errors and unnecessary template instantiation if - // compiling in C++11 or C++14 mode + // compiling in C++14 mode using NextUnroller = BitPackUnroller< T, kBits, ((S <= B) ? (S + ((S < B) ? kBits : 0)) : (S % B)), kLoadPos + static_cast<size_t>(S > B),
diff --git a/hwy/contrib/sort/sorting_networks-inl.h b/hwy/contrib/sort/sorting_networks-inl.h index 50f8428..7eabc37 100644 --- a/hwy/contrib/sort/sorting_networks-inl.h +++ b/hwy/contrib/sort/sorting_networks-inl.h
@@ -197,6 +197,7 @@ // st.SortPairsDistance1 to compile. `if constexpr` in the caller would also // work, but is not available in C++11. We write out the (unused) argument types // rather than `...` because GCC 9 (but not 10) fails to compile with `...`. +// TODO: use C++17. template <size_t kKeysPerVector, class D, class Traits, class V, HWY_IF_LANES_LE(kKeysPerVector, 1)>
diff --git a/hwy/detect_compiler_arch.h b/hwy/detect_compiler_arch.h index 08d8b3a..f4ccf2d 100644 --- a/hwy/detect_compiler_arch.h +++ b/hwy/detect_compiler_arch.h
@@ -198,11 +198,8 @@ #define HWY_CXX17_CONSTEXPR #endif -#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L +// C++14 is now required. #define HWY_CXX14_CONSTEXPR constexpr -#else -#define HWY_CXX14_CONSTEXPR -#endif #if HWY_CXX_LANG >= 201703L #define HWY_IF_CONSTEXPR if constexpr
diff --git a/hwy/tests/in_range_float_to_int_conv_test.cc b/hwy/tests/in_range_float_to_int_conv_test.cc index bd76696..565dd80 100644 --- a/hwy/tests/in_range_float_to_int_conv_test.cc +++ b/hwy/tests/in_range_float_to_int_conv_test.cc
@@ -28,14 +28,9 @@ namespace { // HWY_IN_RANGE_F2I_CONV_TEST_CONST_ASSERT(condition, msg) checks that condition -// is true using static_assert if constexpr BitCastScalar is available and -// Highway is being compiled in C++11 mode. -// -// Otherwise, if constexpr BitCastScalar is not available or Highway is being -// compiled in C++11 mode, HWY_IN_RANGE_F2I_CONV_TEST_CONST_ASSERT(condition, -// msg) checks that condition is true using a run-time assertion. -#if (HWY_HAS_BUILTIN(__builtin_bit_cast) || HWY_COMPILER_MSVC >= 1926) && \ - __cpp_constexpr >= 201304L +// is true using static_assert if constexpr BitCastScalar is available, and +// otherwise uses a run-time assertion. +#if (HWY_HAS_BUILTIN(__builtin_bit_cast) || HWY_COMPILER_MSVC >= 1926) #define HWY_IN_RANGE_F2I_CONV_TEST_CONST_ASSERT(condition, msg) \ static_assert((condition), msg) #else