Skip to content

Commit 9c25f2f

Browse files
Fix -Wshorten-64-to-32 warnings
1 parent 5e8a090 commit 9c25f2f

13 files changed

+33
-22
lines changed

include/xsimd/arch/generic/xsimd_generic_logical.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace xsimd
4949
// popcount instruction depending on the arch...
5050
XSIMD_IF_CONSTEXPR(batch_bool<T, A>::size <= 32)
5151
{
52-
uint32_t m32 = m;
52+
uint32_t m32 = static_cast<uint32_t>(m);
5353
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
5454
m32 = m32 - ((m32 >> 1) & 0x55555555); // reuse input as temporary
5555
m32 = (m32 & 0x33333333) + ((m32 >> 2) & 0x33333333); // temp

include/xsimd/arch/xsimd_sse2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ namespace xsimd
10211021
*/
10221022
namespace detail
10231023
{
1024-
XSIMD_INLINE int mask_lut(int mask)
1024+
XSIMD_INLINE int mask_lut(uint64_t mask)
10251025
{
10261026
// clang-format off
10271027
static const int mask_lut[256] = {

test/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ set(TARGET_ARCH "native" CACHE STRING "Target architecture arguments")
4848
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
4949
if (NOT WIN32 AND NOT ANDROID)
5050
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder")
51+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
52+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32")
53+
endif()
5154
# Users may override the c++ standard:
5255
if(NOT DEFINED CMAKE_CXX_STANDARD OR "${CMAKE_CXX_STANDARD}" STREQUAL "")
5356
if (ENABLE_XTL_COMPLEX)

test/test_api.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ struct xsimd_api_test
166166
template <class T>
167167
void test_set_impl(const std::string& name)
168168
{
169+
#ifdef __clang__
170+
#pragma clang diagnostic push
171+
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
172+
#endif
169173
T v = T(1);
170174
batch_type expected(v);
171175
batch_type res = xsimd::broadcast<value_type>(v);
176+
#ifdef __clang__
177+
#pragma clang diagnostic pop
178+
#endif
172179
INFO(name);
173180
CHECK_BATCH_EQ(res, expected);
174181
}
@@ -187,8 +194,8 @@ struct xsimd_api_test
187194
{
188195
vec.resize(size);
189196

190-
value_type min = value_type(0);
191-
value_type max = value_type(100);
197+
int min = 0;
198+
int max = 100;
192199

193200
std::default_random_engine generator;
194201
std::uniform_int_distribution<int> distribution(min, max);

test/test_basic_math.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct basic_math_test
6969
{
7070
lhs[i] = value_type(i) / 4 + value_type(1.2) * std::sqrt(value_type(i + 0.25)) + value_type(1.);
7171
rhs[i] = value_type(10.2) / (i + 2) + value_type(0.25) + value_type(1.);
72-
clip_input[i] = i * value_type(0.25);
72+
clip_input[i] = static_cast<value_type>(i) * value_type(0.25);
7373
from_input[i] = rhs[i] - value_type(1);
7474
}
7575
}

test/test_batch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ struct batch_test
746746
{
747747
if (std::is_integral<value_type>::value)
748748
{
749-
return ((long long)l + r) / 2;
749+
return static_cast<value_type>(((long long)l + r) / 2);
750750
}
751751
else
752752
{
@@ -764,7 +764,7 @@ struct batch_test
764764
{
765765
if (std::is_integral<value_type>::value)
766766
{
767-
return ((long long)l + r) / 2 + ((long long)(l + r) & 1);
767+
return static_cast<value_type>(((long long)l + r) / 2 + ((long long)(l + r) & 1));
768768
}
769769
else
770770
{

test/test_batch_constant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct constant_batch_test
5858
{
5959
static constexpr value_type get(size_t index, size_t /*size*/)
6060
{
61-
return index;
61+
return static_cast<value_type>(index);
6262
}
6363
};
6464

test/test_batch_int.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ struct batch_int_test
294294
lhs = batch_type(std::numeric_limits<value_type>::max());
295295
for (int32_t i = 0; i < s; ++i)
296296
{
297-
res = lhs >> value_type(i);
297+
res = lhs >> i;
298298
value_type expected = std::numeric_limits<value_type>::max() >> i;
299299
for (std::size_t j = 0; j < size; ++j)
300300
{

test/test_batch_manip.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace xsimd
3030
/* Generate input data */
3131
for (std::size_t i = 0; i < N; ++i)
3232
{
33-
lhs_in[i] = 2 * i + 1;
33+
lhs_in[i] = static_cast<T>(2 * i + 1);
3434
}
3535
vects.push_back(std::move(lhs_in));
3636

test/test_fp_manipulation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct fp_manipulation_test
4545
array_type expected;
4646
std::transform(input.cbegin(), input.cend(), expected.begin(),
4747
[this](const value_type& v)
48-
{ return std::ldexp(v, exponent); });
48+
{ return std::ldexp(v, static_cast<int>(exponent)); });
4949
batch_type res = xsimd::ldexp(batch_input(), bexp);
5050
INFO("ldexp");
5151
CHECK_BATCH_EQ(res, expected);

test/test_load_store.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ struct load_store_test
269269
{
270270
vec.resize(size);
271271

272-
value_type min = value_type(0);
273-
value_type max = value_type(100);
272+
int min = 0;
273+
int max = 100;
274274

275275
std::default_random_engine generator;
276276
std::uniform_int_distribution<int> distribution(min, max);

test/test_shuffle.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace
3232
/* Generate input data: lhs, rhs */
3333
for (size_t i = 0; i < N; ++i)
3434
{
35-
lhs_in[i] = 'A' + 2 * i + 1;
36-
rhs_in[i] = 'A' + 2 * i;
35+
lhs_in[i] = static_cast<T>('A' + 2 * i + 1);
36+
rhs_in[i] = static_cast<T>('A' + 2 * i);
3737
}
3838
vects.push_back(std::move(lhs_in));
3939
vects.push_back(std::move(rhs_in));
@@ -288,7 +288,7 @@ struct compress_test
288288
{
289289
for (size_t i = 0; i < size; ++i)
290290
{
291-
input[i] = i;
291+
input[i] = static_cast<value_type>(i);
292292
}
293293
}
294294

@@ -360,11 +360,11 @@ TEST_CASE_TEMPLATE("[compress]", B, BATCH_FLOAT_TYPES, xsimd::batch<uint32_t>, x
360360
}
361361
// SUBCASE("interleave")
362362
//{
363-
// Test.interleave();
363+
// Test.interleave();
364364
// }
365365
// SUBCASE("generic")
366366
//{
367-
// Test.generic();
367+
// Test.generic();
368368
// }
369369
}
370370

@@ -384,7 +384,7 @@ struct expand_test
384384
{
385385
for (size_t i = 0; i < size; ++i)
386386
{
387-
input[i] = i;
387+
input[i] = static_cast<value_type>(i);
388388
}
389389
}
390390

@@ -479,8 +479,8 @@ struct shuffle_test
479479
{
480480
for (size_t i = 0; i < size; ++i)
481481
{
482-
lhs[i] = i;
483-
rhs[i] = i + size;
482+
lhs[i] = static_cast<value_type>(i);
483+
rhs[i] = static_cast<value_type>(i + size);
484484
}
485485
}
486486

test/test_xsimd_api.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ struct xsimd_api_float_types_functions
623623
{
624624
value_type val0(4);
625625
xsimd::as_integer_t<value_type> val1(2);
626-
CHECK_EQ(extract(xsimd::ldexp(T(val0), xsimd::as_integer_t<T>(val1))), std::ldexp(val0, val1));
626+
using exponent_type = typename std::conditional<std::is_scalar<T>::value, int, xsimd::as_integer_t<T>>::type;
627+
CHECK_EQ(extract(xsimd::ldexp(T(val0), exponent_type(val1))), std::ldexp(val0, static_cast<int>(val1)));
627628
}
628629
void test_lgamma()
629630
{

0 commit comments

Comments
 (0)