From 4cf04c8583440da2682c40db770ab7c770229fb6 Mon Sep 17 00:00:00 2001 From: Azusa Yamaguchi Date: Sun, 14 Jun 2015 00:58:14 +0100 Subject: [PATCH] More functions broken out into element by element --- lib/simd/Grid_vector_unops.h | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/lib/simd/Grid_vector_unops.h b/lib/simd/Grid_vector_unops.h index 8e2b6956..3ba77d82 100644 --- a/lib/simd/Grid_vector_unops.h +++ b/lib/simd/Grid_vector_unops.h @@ -1,6 +1,8 @@ #ifndef GRID_VECTOR_UNOPS #define GRID_VECTOR_UNOPS +#include + namespace Grid { template struct SqrtRealFunctor { @@ -27,6 +29,28 @@ namespace Grid { } }; + template struct LogRealFunctor { + scalar operator()(const scalar &a) const { + return log(real(a)); + } + }; + + template struct ExpRealFunctor { + scalar operator()(const scalar &a) const { + return exp(real(a)); + } + }; + template struct NotFunctor { + scalar operator()(const scalar &a) const { + return (!a); + } + }; + template struct AbsRealFunctor { + scalar operator()(const scalar &a) const { + return std::abs(real(a)); + } + }; + template struct PowRealFunctor { double y; PowRealFunctor(double _y) : y(_y) {}; @@ -43,6 +67,25 @@ namespace Grid { } }; + template struct RealFunctor { + scalar operator()(const scalar &a) const { + return real(a); + } + }; + template struct ImagFunctor { + scalar operator()(const scalar &a) const { + return imag(a); + } + }; + template < class S, class V > + inline Grid_simd real(const Grid_simd &r) { + return SimdApply(RealFunctor(),r); + } + template < class S, class V > + inline Grid_simd imag(const Grid_simd &r) { + return SimdApply(ImagFunctor(),r); + } + template < class S, class V > inline Grid_simd sqrt(const Grid_simd &r) { return SimdApply(SqrtRealFunctor(),r); @@ -60,6 +103,22 @@ namespace Grid { return SimdApply(CosRealFunctor(),r); } template < class S, class V > + inline Grid_simd log(const Grid_simd &r) { + return SimdApply(LogRealFunctor(),r); + } + template < class S, class V > + inline Grid_simd abs(const Grid_simd &r) { + return SimdApply(AbsRealFunctor(),r); + } + template < class S, class V > + inline Grid_simd exp(const Grid_simd &r) { + return SimdApply(ExpRealFunctor(),r); + } + template < class S, class V > + inline Grid_simd Not(const Grid_simd &r) { + return SimdApply(NotFunctor(),r); + } + template < class S, class V > inline Grid_simd pow(const Grid_simd &r,double y) { return SimdApply(PowRealFunctor(y),r); } @@ -67,6 +126,55 @@ namespace Grid { inline Grid_simd mod(const Grid_simd &r,Integer y) { return SimdApply(ModIntFunctor(y),r); } + //////////////////////////////////////////////////////////////////////////// + // Allows us to assign into **conformable** real vectors from complex + //////////////////////////////////////////////////////////////////////////// + // template < class S, class V > + // inline auto ComplexRemove(const Grid_simd &c) -> Grid_simd::Real,V> { + // Grid_simd::Real,V> ret; + // ret.v = c.v; + // return ret; + // } + template struct AndFunctor { + scalar operator()(const scalar &x, const scalar &y) const { + return x & y; + } + }; + template struct OrFunctor { + scalar operator()(const scalar &x, const scalar &y) const { + return x | y; + } + }; + template struct AndAndFunctor { + scalar operator()(const scalar &x, const scalar &y) const { + return x && y; + } + }; + template struct OrOrFunctor { + scalar operator()(const scalar &x, const scalar &y) const { + return x || y; + } + }; + + //////////////////////////////// + // Calls to simd binop functors + //////////////////////////////// + template < class S, class V > + inline Grid_simd operator &(const Grid_simd &x,const Grid_simd &y) { + return SimdApplyBinop(AndFunctor(),x,y); + } + template < class S, class V > + inline Grid_simd operator &&(const Grid_simd &x,const Grid_simd &y) { + return SimdApplyBinop(AndAndFunctor(),x,y); + } + template < class S, class V > + inline Grid_simd operator |(const Grid_simd &x,const Grid_simd &y) { + return SimdApplyBinop(OrFunctor(),x,y); + } + template < class S, class V > + inline Grid_simd operator ||(const Grid_simd &x,const Grid_simd &y) { + return SimdApplyBinop(OrOrFunctor(),x,y); + } } #endif