Skip to content

Commit 95f4837

Browse files
Fix VSX rounding
1 parent d8c8b95 commit 95f4837

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

include/xsimd/arch/xsimd_vsx.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,18 @@ namespace xsimd
605605
}
606606

607607
// round
608-
template <class A, class T, class = std::enable_if_t<std::is_floating_point<T>::value>>
609-
XSIMD_INLINE batch<T, A> round(batch<T, A> const& self, requires_arch<vsx>) noexcept
608+
609+
// vec_round exists also for float vectors but is mapped to vrfin instruction which uses the wrong rounding mode
610+
#if defined __has_builtin && __has_builtin(__builtin_vsx_xvrspi)
611+
template <class A>
612+
XSIMD_INLINE batch<float, A> round(batch<float, A> const& self, requires_arch<vsx>) noexcept
613+
{
614+
return __builtin_vsx_xvrspi(self.data);
615+
}
616+
#endif
617+
// For double vectors vec_round uses xvrdpi which does the right thing
618+
template <class A>
619+
XSIMD_INLINE batch<double, A> round(batch<double, A> const& self, requires_arch<vsx>) noexcept
610620
{
611621
return vec_round(self.data);
612622
}

0 commit comments

Comments
 (0)