From 4021d511c8273f74bb0375fea36c29fe653fe84b Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 24 Mar 2025 23:48:31 +0100 Subject: [PATCH] Fix -Wshorten-64-to-32 warnings --- .../xsimd/arch/generic/xsimd_generic_logical.hpp | 2 +- include/xsimd/arch/xsimd_sse2.hpp | 2 +- test/CMakeLists.txt | 3 +++ test/test_api.cpp | 11 +++++++++-- test/test_basic_math.cpp | 2 +- test/test_batch.cpp | 4 ++-- test/test_batch_constant.cpp | 2 +- test/test_batch_int.cpp | 2 +- test/test_batch_manip.cpp | 2 +- test/test_fp_manipulation.cpp | 2 +- test/test_load_store.cpp | 4 ++-- test/test_shuffle.cpp | 16 ++++++++-------- test/test_xsimd_api.cpp | 3 ++- 13 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/xsimd/arch/generic/xsimd_generic_logical.hpp b/include/xsimd/arch/generic/xsimd_generic_logical.hpp index bc25b1155..4f5dd8e4b 100644 --- a/include/xsimd/arch/generic/xsimd_generic_logical.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_logical.hpp @@ -49,7 +49,7 @@ namespace xsimd // popcount instruction depending on the arch... XSIMD_IF_CONSTEXPR(batch_bool::size <= 32) { - uint32_t m32 = m; + uint32_t m32 = static_cast(m); // https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel m32 = m32 - ((m32 >> 1) & 0x55555555); // reuse input as temporary m32 = (m32 & 0x33333333) + ((m32 >> 2) & 0x33333333); // temp diff --git a/include/xsimd/arch/xsimd_sse2.hpp b/include/xsimd/arch/xsimd_sse2.hpp index 280abaa0f..fed786576 100644 --- a/include/xsimd/arch/xsimd_sse2.hpp +++ b/include/xsimd/arch/xsimd_sse2.hpp @@ -1021,7 +1021,7 @@ namespace xsimd */ namespace detail { - XSIMD_INLINE int mask_lut(int mask) + XSIMD_INLINE int mask_lut(uint64_t mask) { // clang-format off static const int mask_lut[256] = { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1e01ce9d7..8fffeed1d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,6 +48,9 @@ set(TARGET_ARCH "native" CACHE STRING "Target architecture arguments") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") if (NOT WIN32 AND NOT ANDROID) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder") + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32") + endif() # Users may override the c++ standard: if(NOT DEFINED CMAKE_CXX_STANDARD OR "${CMAKE_CXX_STANDARD}" STREQUAL "") if (ENABLE_XTL_COMPLEX) diff --git a/test/test_api.cpp b/test/test_api.cpp index a5e933f4a..73f74619a 100644 --- a/test/test_api.cpp +++ b/test/test_api.cpp @@ -166,9 +166,16 @@ struct xsimd_api_test template void test_set_impl(const std::string& name) { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wshorten-64-to-32" +#endif T v = T(1); batch_type expected(v); batch_type res = xsimd::broadcast(v); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif INFO(name); CHECK_BATCH_EQ(res, expected); } @@ -187,8 +194,8 @@ struct xsimd_api_test { vec.resize(size); - value_type min = value_type(0); - value_type max = value_type(100); + int min = 0; + int max = 100; std::default_random_engine generator; std::uniform_int_distribution distribution(min, max); diff --git a/test/test_basic_math.cpp b/test/test_basic_math.cpp index 87bf25b87..5f34db720 100644 --- a/test/test_basic_math.cpp +++ b/test/test_basic_math.cpp @@ -69,7 +69,7 @@ struct basic_math_test { lhs[i] = value_type(i) / 4 + value_type(1.2) * std::sqrt(value_type(i + 0.25)) + value_type(1.); rhs[i] = value_type(10.2) / (i + 2) + value_type(0.25) + value_type(1.); - clip_input[i] = i * value_type(0.25); + clip_input[i] = static_cast(i) * value_type(0.25); from_input[i] = rhs[i] - value_type(1); } } diff --git a/test/test_batch.cpp b/test/test_batch.cpp index d5b567660..49559b25d 100644 --- a/test/test_batch.cpp +++ b/test/test_batch.cpp @@ -746,7 +746,7 @@ struct batch_test { if (std::is_integral::value) { - return ((long long)l + r) / 2; + return static_cast(((long long)l + r) / 2); } else { @@ -764,7 +764,7 @@ struct batch_test { if (std::is_integral::value) { - return ((long long)l + r) / 2 + ((long long)(l + r) & 1); + return static_cast(((long long)l + r) / 2 + ((long long)(l + r) & 1)); } else { diff --git a/test/test_batch_constant.cpp b/test/test_batch_constant.cpp index 2839d35cf..3989280a7 100644 --- a/test/test_batch_constant.cpp +++ b/test/test_batch_constant.cpp @@ -58,7 +58,7 @@ struct constant_batch_test { static constexpr value_type get(size_t index, size_t /*size*/) { - return index; + return static_cast(index); } }; diff --git a/test/test_batch_int.cpp b/test/test_batch_int.cpp index 00f38c92c..e63d120ed 100644 --- a/test/test_batch_int.cpp +++ b/test/test_batch_int.cpp @@ -294,7 +294,7 @@ struct batch_int_test lhs = batch_type(std::numeric_limits::max()); for (int32_t i = 0; i < s; ++i) { - res = lhs >> value_type(i); + res = lhs >> i; value_type expected = std::numeric_limits::max() >> i; for (std::size_t j = 0; j < size; ++j) { diff --git a/test/test_batch_manip.cpp b/test/test_batch_manip.cpp index 10fc16d13..d7b220e1a 100644 --- a/test/test_batch_manip.cpp +++ b/test/test_batch_manip.cpp @@ -30,7 +30,7 @@ namespace xsimd /* Generate input data */ for (std::size_t i = 0; i < N; ++i) { - lhs_in[i] = 2 * i + 1; + lhs_in[i] = static_cast(2 * i + 1); } vects.push_back(std::move(lhs_in)); diff --git a/test/test_fp_manipulation.cpp b/test/test_fp_manipulation.cpp index caf06c650..454e75600 100644 --- a/test/test_fp_manipulation.cpp +++ b/test/test_fp_manipulation.cpp @@ -45,7 +45,7 @@ struct fp_manipulation_test array_type expected; std::transform(input.cbegin(), input.cend(), expected.begin(), [this](const value_type& v) - { return std::ldexp(v, exponent); }); + { return std::ldexp(v, static_cast(exponent)); }); batch_type res = xsimd::ldexp(batch_input(), bexp); INFO("ldexp"); CHECK_BATCH_EQ(res, expected); diff --git a/test/test_load_store.cpp b/test/test_load_store.cpp index 76d30179a..7a4d80932 100644 --- a/test/test_load_store.cpp +++ b/test/test_load_store.cpp @@ -269,8 +269,8 @@ struct load_store_test { vec.resize(size); - value_type min = value_type(0); - value_type max = value_type(100); + int min = 0; + int max = 100; std::default_random_engine generator; std::uniform_int_distribution distribution(min, max); diff --git a/test/test_shuffle.cpp b/test/test_shuffle.cpp index 0fc678d98..4b698a138 100644 --- a/test/test_shuffle.cpp +++ b/test/test_shuffle.cpp @@ -32,8 +32,8 @@ namespace /* Generate input data: lhs, rhs */ for (size_t i = 0; i < N; ++i) { - lhs_in[i] = 'A' + 2 * i + 1; - rhs_in[i] = 'A' + 2 * i; + lhs_in[i] = static_cast('A' + 2 * i + 1); + rhs_in[i] = static_cast('A' + 2 * i); } vects.push_back(std::move(lhs_in)); vects.push_back(std::move(rhs_in)); @@ -288,7 +288,7 @@ struct compress_test { for (size_t i = 0; i < size; ++i) { - input[i] = i; + input[i] = static_cast(i); } } @@ -360,11 +360,11 @@ TEST_CASE_TEMPLATE("[compress]", B, BATCH_FLOAT_TYPES, xsimd::batch, x } // SUBCASE("interleave") //{ - // Test.interleave(); + // Test.interleave(); // } // SUBCASE("generic") //{ - // Test.generic(); + // Test.generic(); // } } @@ -384,7 +384,7 @@ struct expand_test { for (size_t i = 0; i < size; ++i) { - input[i] = i; + input[i] = static_cast(i); } } @@ -479,8 +479,8 @@ struct shuffle_test { for (size_t i = 0; i < size; ++i) { - lhs[i] = i; - rhs[i] = i + size; + lhs[i] = static_cast(i); + rhs[i] = static_cast(i + size); } } diff --git a/test/test_xsimd_api.cpp b/test/test_xsimd_api.cpp index f416ae9b3..ef41c709b 100644 --- a/test/test_xsimd_api.cpp +++ b/test/test_xsimd_api.cpp @@ -623,7 +623,8 @@ struct xsimd_api_float_types_functions { value_type val0(4); xsimd::as_integer_t val1(2); - CHECK_EQ(extract(xsimd::ldexp(T(val0), xsimd::as_integer_t(val1))), std::ldexp(val0, val1)); + using exponent_type = typename std::conditional::value, int, xsimd::as_integer_t>::type; + CHECK_EQ(extract(xsimd::ldexp(T(val0), exponent_type(val1))), std::ldexp(val0, static_cast(val1))); } void test_lgamma() {