Skip to content

Commit

Permalink
Update to xsimd 8.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Dec 14, 2021
1 parent 52ec6f2 commit 0eb5c4e
Show file tree
Hide file tree
Showing 60 changed files with 13,297 additions and 11,215 deletions.
197 changes: 112 additions & 85 deletions third_party/xsimd/arch/generic/xsimd_generic_arithmetic.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XSIMD_GENERIC_ARITHMETIC_HPP
#define XSIMD_GENERIC_ARITHMETIC_HPP
Expand All @@ -17,85 +17,112 @@

#include "./xsimd_generic_details.hpp"

namespace xsimd {
namespace xsimd
{

namespace kernel
{

using namespace types;

// bitwise_lshift
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
inline batch<T, A> bitwise_lshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x << y; },
self, other);
}

// bitwise_rshift
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
inline batch<T, A> bitwise_rshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept
{
return detail::apply([](T x, T y) noexcept
{ return x >> y; },
self, other);
}

// div
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch<T, A> div(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept
{
return detail::apply([](T x, T y) noexcept -> T
{ return x / y; },
self, other);
}

// fma
template <class A, class T>
inline batch<T, A> fma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) noexcept
{
return x * y + z;
}

template <class A, class T>
inline batch<std::complex<T>, A> fma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) noexcept
{
auto res_r = fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}

// fms
template <class A, class T>
inline batch<T, A> fms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) noexcept
{
return x * y - z;
}

template <class A, class T>
inline batch<std::complex<T>, A> fms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) noexcept
{
auto res_r = fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}

// fnma
template <class A, class T>
inline batch<T, A> fnma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) noexcept
{
return -x * y + z;
}

template <class A, class T>
inline batch<std::complex<T>, A> fnma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) noexcept
{
auto res_r = -fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = -fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}

// fnms
template <class A, class T>
inline batch<T, A> fnms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) noexcept
{
return -x * y - z;
}

template <class A, class T>
inline batch<std::complex<T>, A> fnms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) noexcept
{
auto res_r = -fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = -fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return { res_r, res_i };
}

// mul
template <class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
inline batch<T, A> mul(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) noexcept
{
return detail::apply([](T x, T y) noexcept -> T
{ return x * y; },
self, other);
}

namespace kernel {

using namespace types;

// bitwise_lshift
template<class A, class T, class/*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
batch<T, A> bitwise_lshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) {
return detail::apply([](T x, T y) { return x << y;}, self, other);
}

// bitwise_rshift
template<class A, class T, class/*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
batch<T, A> bitwise_rshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) {
return detail::apply([](T x, T y) { return x >> y;}, self, other);
}

// div
template<class A, class T, class=typename std::enable_if<std::is_integral<T>::value, void>::type>
batch<T, A> div(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) {
return detail::apply([](T x, T y) -> T { return x / y;}, self, other);
}

// fma
template<class A, class T> batch<T, A> fma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) {
return x * y + z;
}

template<class A, class T> batch<std::complex<T>, A> fma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) {
auto res_r = fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return {res_r, res_i};
}

// fms
template<class A, class T> batch<T, A> fms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) {
return x * y - z;
}

template<class A, class T> batch<std::complex<T>, A> fms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) {
auto res_r = fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return {res_r, res_i};
}

// fnma
template<class A, class T> batch<T, A> fnma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) {
return -x * y + z;
}

template<class A, class T> batch<std::complex<T>, A> fnma(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) {
auto res_r = - fms(x.real(), y.real(), fma(x.imag(), y.imag(), z.real()));
auto res_i = - fma(x.real(), y.imag(), fms(x.imag(), y.real(), z.imag()));
return {res_r, res_i};
}

// fnms
template<class A, class T> batch<T, A> fnms(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) {
return -x * y - z;
}

template<class A, class T> batch<std::complex<T>, A> fnms(batch<std::complex<T>, A> const& x, batch<std::complex<T>, A> const& y, batch<std::complex<T>, A> const& z, requires_arch<generic>) {
auto res_r = - fms(x.real(), y.real(), fms(x.imag(), y.imag(), z.real()));
auto res_i = - fma(x.real(), y.imag(), fma(x.imag(), y.real(), z.imag()));
return {res_r, res_i};
}



// mul
template<class A, class T, class/*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
batch<T, A> mul(batch<T, A> const& self, batch<T, A> const& other, requires_arch<generic>) {
return detail::apply([](T x, T y) -> T { return x * y;}, self, other);
}

}

}

#endif

156 changes: 83 additions & 73 deletions third_party/xsimd/arch/generic/xsimd_generic_complex.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XSIMD_GENERIC_COMPLEX_HPP
#define XSIMD_GENERIC_COMPLEX_HPP
Expand All @@ -16,71 +16,81 @@

#include "./xsimd_generic_details.hpp"

namespace xsimd {

namespace kernel {

using namespace types;

// real
template <class A, class T>
batch<T, A> real(batch<T, A> const& self, requires_arch<generic>) {
return self;
}

template <class A, class T>
batch<T, A> real(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
return self.real();
}

// imag
template <class A, class T>
batch<T, A> imag(batch<T, A> const& /*self*/, requires_arch<generic>) {
return batch<T, A>(T(0));
}

template <class A, class T>
batch<T, A> imag(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
return self.imag();
}

// arg
template<class A, class T>
real_batch_type_t<batch<T, A>> arg(batch<T, A> const& self, requires_arch<generic>) {
return atan2(imag(self), real(self));
namespace xsimd
{

namespace kernel
{

using namespace types;

// real
template <class A, class T>
inline batch<T, A> real(batch<T, A> const& self, requires_arch<generic>) noexcept
{
return self;
}

template <class A, class T>
inline batch<T, A> real(batch<std::complex<T>, A> const& self, requires_arch<generic>) noexcept
{
return self.real();
}

// imag
template <class A, class T>
inline batch<T, A> imag(batch<T, A> const& /*self*/, requires_arch<generic>) noexcept
{
return batch<T, A>(T(0));
}

template <class A, class T>
inline batch<T, A> imag(batch<std::complex<T>, A> const& self, requires_arch<generic>) noexcept
{
return self.imag();
}

// arg
template <class A, class T>
inline real_batch_type_t<batch<T, A>> arg(batch<T, A> const& self, requires_arch<generic>) noexcept
{
return atan2(imag(self), real(self));
}

// conj
template <class A, class T>
inline complex_batch_type_t<batch<T, A>> conj(batch<T, A> const& self, requires_arch<generic>) noexcept
{
return { real(self), -imag(self) };
}

// norm
template <class A, class T>
inline real_batch_type_t<batch<T, A>> norm(batch<T, A> const& self, requires_arch<generic>) noexcept
{
return { fma(real(self), real(self), imag(self) * imag(self)) };
}

// proj
template <class A, class T>
inline complex_batch_type_t<batch<T, A>> proj(batch<T, A> const& self, requires_arch<generic>) noexcept
{
using batch_type = complex_batch_type_t<batch<T, A>>;
using real_batch = typename batch_type::real_batch;
using real_value_type = typename real_batch::value_type;
auto cond = xsimd::isinf(real(self)) || xsimd::isinf(imag(self));
return select(cond,
batch_type(constants::infinity<real_batch>(),
copysign(real_batch(real_value_type(0)), imag(self))),
batch_type(self));
}

template <class A, class T>
inline batch_bool<T, A> isnan(batch<std::complex<T>, A> const& self, requires_arch<generic>) noexcept
{
return batch_bool<T, A>(isnan(self.real()) || isnan(self.imag()));
}
}

// conj
template<class A, class T>
complex_batch_type_t<batch<T, A>> conj(batch<T, A> const& self, requires_arch<generic>) {
return {real(self), - imag(self)};
}

// norm
template<class A, class T>
real_batch_type_t<batch<T, A>> norm(batch<T, A> const& self, requires_arch<generic>) {
return {fma(real(self), real(self), imag(self) * imag(self))};
}

// proj
template<class A, class T>
complex_batch_type_t<batch<T, A>> proj(batch<T, A> const& self, requires_arch<generic>) {
using batch_type = complex_batch_type_t<batch<T, A>>;
using real_batch = typename batch_type::real_batch;
using real_value_type = typename real_batch::value_type;
auto cond = xsimd::isinf(real(self)) || xsimd::isinf(imag(self));
return select(cond,
batch_type(constants::infinity<real_batch>(),
copysign(real_batch(real_value_type(0)), imag(self))),
batch_type(self));
}

template <class A, class T>
batch_bool<T, A> isnan(batch<std::complex<T>, A> const& self, requires_arch<generic>) {
return batch_bool<T, A>(isnan(self.real()) || isnan(self.imag()));
}
}
}

#endif

Loading

0 comments on commit 0eb5c4e

Please sign in to comment.