Skip to content

Commit

Permalink
Test nearbyint_as_int using xsimd's scalar version instead of lround
Browse files Browse the repository at this point in the history
Fix #948
  • Loading branch information
serge-sans-paille committed Oct 16, 2023
1 parent 4a5ee2e commit e036691
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
4 changes: 2 additions & 2 deletions include/xsimd/arch/generic/xsimd_generic_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ namespace xsimd
{
using U = as_integer_t<float>;
return kernel::detail::apply_transform<U>([](float x) noexcept -> U
{ return std::lroundf(x); },
{ return std::nearbyintf(x); },
self);
}

Expand All @@ -1865,7 +1865,7 @@ namespace xsimd
{
using U = as_integer_t<double>;
return kernel::detail::apply_transform<U>([](double x) noexcept -> U
{ return std::llround(x); },
{ return std::nearbyint(x); },
self);
}

Expand Down
4 changes: 2 additions & 2 deletions include/xsimd/arch/xsimd_sve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,14 +1124,14 @@ namespace xsimd
template <class A>
inline batch<int32_t, A> nearbyint_as_int(batch<float, A> const& arg, requires_arch<sve>) noexcept
{
const auto nearest = svrinta_x(detail::sve_ptrue<float>(), arg);
const auto nearest = svrintx_x(detail::sve_ptrue<float>(), arg);
return svcvt_s32_x(detail::sve_ptrue<float>(), nearest);
}

template <class A>
inline batch<int64_t, A> nearbyint_as_int(batch<double, A> const& arg, requires_arch<sve>) noexcept
{
const auto nearest = svrinta_x(detail::sve_ptrue<double>(), arg);
const auto nearest = svrintx_x(detail::sve_ptrue<double>(), arg);
return svcvt_s64_x(detail::sve_ptrue<double>(), nearest);
}

Expand Down
17 changes: 2 additions & 15 deletions test/test_rounding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@

#include "test_utils.hpp"

namespace detail
{
inline xsimd::as_integer_t<float> nearbyint_as_int(float a)
{
return std::lroundf(a);
}

inline xsimd::as_integer_t<double> nearbyint_as_int(double a)
{
return std::llround(a);
}
}

template <class B>
struct rounding_test
{
Expand Down Expand Up @@ -163,7 +150,7 @@ struct rounding_test
std::array<int_value_type, nb_input> res;
std::transform(input.cbegin(), input.cend(), expected.begin(),
[](const value_type& v)
{ return detail::nearbyint_as_int(v); });
{ return xsimd::nearbyint_as_int(v); });
batch_type in;
int_batch_type out;
for (size_t i = 0; i < nb_batches; i += size)
Expand All @@ -174,7 +161,7 @@ struct rounding_test
}
for (size_t i = nb_batches; i < nb_input; ++i)
{
res[i] = detail::nearbyint_as_int(input[i]);
res[i] = xsimd::nearbyint_as_int(input[i]);
}
size_t diff = detail::get_nb_diff(res, expected);
INFO("nearbyint_as_int");
Expand Down

0 comments on commit e036691

Please sign in to comment.