Skip to content

Commit

Permalink
Update to ximd 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Oct 15, 2021
1 parent 1eab828 commit 418bd3e
Show file tree
Hide file tree
Showing 150 changed files with 16,706 additions and 35,554 deletions.
2 changes: 1 addition & 1 deletion pythran/pythonic/include/numpy/arange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace numpy
#ifdef USE_XSIMD
template <class T>
struct arange_simd_iterator {
using vector_type = xsimd::simd_type<T>;
using vector_type = xsimd::batch<T>;
vector_type curr_;
vector_type step_;
long index_;
Expand Down
10 changes: 5 additions & 5 deletions pythran/pythonic/include/numpy/conjugate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace numpy
{
return std::conj(v);
}
template <class T, std::size_t N>
xsimd::batch<std::complex<T>, N>
conjugate(xsimd::batch<std::complex<T>, N> const &v)
template <class T, class A>
xsimd::batch<std::complex<T>, A>
conjugate(xsimd::batch<std::complex<T>, A> const &v)
{
return xsimd::conj(v);
}
template <class T, std::size_t N>
xsimd::batch<T, N> conjugate(xsimd::batch<T, N> const &v)
template <class T, class A>
xsimd::batch<T, A> conjugate(xsimd::batch<T, A> const &v)
{
return v;
}
Expand Down
6 changes: 3 additions & 3 deletions pythran/pythonic/include/types/nditerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ namespace types
template <class E>
struct const_simd_nditerator
: public std::iterator<std::random_access_iterator_tag,
xsimd::simd_type<typename E::dtype>> {
xsimd::batch<typename E::dtype>> {

using vector_type = typename xsimd::simd_type<typename E::dtype>;
using vector_type = typename xsimd::batch<typename E::dtype>;
typename E::dtype const *data;
static const std::size_t vector_size = vector_type::size;

Expand All @@ -116,7 +116,7 @@ namespace types
bool operator==(const_simd_nditerator const &other) const;
bool operator<(const_simd_nditerator const &other) const;
const_simd_nditerator &operator=(const_simd_nditerator const &other);
void store(xsimd::simd_type<typename E::dtype> const &);
void store(xsimd::batch<typename E::dtype> const &);
};
template <class E>
struct const_simd_nditerator_nostep : const_simd_nditerator<E> {
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/include/types/numpy_broadcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace types
template <class dtype>
struct broadcast_base<dtype, true> {
dtype _value;
xsimd::simd_type<dtype> _splated;
xsimd::batch<dtype> _splated;
broadcast_base() = default;

template <class V>
Expand Down
10 changes: 6 additions & 4 deletions pythran/pythonic/include/types/numpy_expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ namespace types
auto _dereference(utils::index_sequence<I...>) const
-> decltype(Op{}(*std::get<I>(iters_)...))
{
return Op{}(((std::get<I>(steps_))
? (*std::get<I>(iters_))
: (xsimd::simd_type<decltype(*std::get<I>(iters_))>(
*std::get<I>(siters_))))...);
return Op{}((
(std::get<I>(steps_))
? (*std::get<I>(iters_))
: (xsimd::batch<
typename std::decay<decltype(*std::get<I>(siters_))>::type>(
*std::get<I>(siters_))))...);
}

auto operator*() const -> decltype(
Expand Down
8 changes: 4 additions & 4 deletions pythran/pythonic/numpy/argminmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace numpy
long>::type
_argminmax(E const &elts, T &minmax_elts, utils::int_<1>)
{
using vT = xsimd::simd_type<T>;
using vT = xsimd::batch<T>;
using iT = xsimd::as_integer_t<T>;
static const size_t vN = vT::size;
const long n = elts.size();
Expand All @@ -117,9 +117,9 @@ namespace numpy
iT iota[vN] = {0};
for (long i = 0; i < (long)vN; ++i)
iota[i] = i;
auto curr = xsimd::load_unaligned(iota);
xsimd::simd_type<iT> indices = curr;
xsimd::simd_type<iT> step{vN};
xsimd::batch<iT> curr = xsimd::load_unaligned(iota);
xsimd::batch<iT> indices = curr;
xsimd::batch<iT> step(vN);

for (++viter; viter != vend; ++viter) {
curr += step;
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/numpy/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace numpy
F vreduce(E e, F acc)
{
using T = typename E::dtype;
using vT = xsimd::simd_type<T>;
using vT = xsimd::batch<T>;
static const size_t vN = vT::size;
const long n = e.size();
auto viter = vectorizer::vbegin(e), vend = vectorizer::vend(e);
Expand Down
4 changes: 2 additions & 2 deletions pythran/pythonic/types/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace types
typename sliced_list<T, S>::simd_iterator
sliced_list<T, S>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {data->data() + slicing.lower +
long(size() / vector_size * vector_size)};
Expand Down Expand Up @@ -497,7 +497,7 @@ namespace types
template <class vectorizer>
typename list<T>::simd_iterator list<T>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {data->data() + long(size() / vector_size * vector_size)};
}
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/types/ndarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ namespace types
template <class vectorizer>
typename ndarray<T, pS>::simd_iterator ndarray<T, pS>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {buffer + long(std::get<0>(_shape) / vector_size * vector_size)};
}
Expand Down
4 changes: 2 additions & 2 deletions pythran/pythonic/types/nditerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ namespace types
}

template <class E>
void const_simd_nditerator<E>::store(
xsimd::simd_type<typename E::dtype> const &val)
void
const_simd_nditerator<E>::store(xsimd::batch<typename E::dtype> const &val)
{
val.store_unaligned(const_cast<typename E::dtype *>(data));
}
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/types/numpy_broadcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace types
template <class dtype>
template <class V>
broadcast_base<dtype, true>::broadcast_base(V v)
: _value(v), _splated(xsimd::simd_type<dtype>(_value))
: _value(v), _splated(xsimd::batch<dtype>(_value))
{
}

Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/types/numpy_gexpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ namespace types
typename numpy_gexpr<Arg, S...>::simd_iterator
numpy_gexpr<Arg, S...>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {buffer + long(size() / vector_size * vector_size)};
}
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/types/numpy_iexpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ namespace types
typename numpy_iexpr<Arg>::simd_iterator
numpy_iexpr<Arg>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {buffer + long(size() / vector_size * vector_size)};
}
Expand Down
2 changes: 1 addition & 1 deletion pythran/pythonic/types/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace types
typename array_base<T, N, V>::simd_iterator
array_base<T, N, V>::vend(vectorizer) const
{
using vector_type = typename xsimd::simd_type<dtype>;
using vector_type = typename xsimd::batch<dtype>;
static const std::size_t vector_size = vector_type::size;
return {&buffer[long(size() / vector_size * vector_size)]};
}
Expand Down
4 changes: 2 additions & 2 deletions pythran/pythonic/utils/broadcast_copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace utils
void vbroadcast_copy(E &&self, F const &other)
{
using T = typename F::dtype;
using vT = xsimd::simd_type<T>;
using vT = xsimd::batch<T>;

static const std::size_t vN = vT::size;

Expand Down Expand Up @@ -428,7 +428,7 @@ namespace utils
void vbroadcast_update(E &&self, F const &other)
{
using T = typename F::dtype;
using vT = typename xsimd::simd_type<T>;
using vT = typename xsimd::batch<T>;
long other_size = std::distance(other.begin(), other.end());

static const std::size_t vN = vT::size;
Expand Down
101 changes: 101 additions & 0 deletions third_party/xsimd/arch/generic/xsimd_generic_arithmetic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/***************************************************************************
* 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

#include <complex>
#include <type_traits>

#include "./xsimd_generic_details.hpp"

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*/>
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

86 changes: 86 additions & 0 deletions third_party/xsimd/arch/generic/xsimd_generic_complex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/***************************************************************************
* 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

#include <complex>

#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));
}

// 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 418bd3e

Please sign in to comment.