/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/simd/Grid_vector_unops.h Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle Author: neo Author: paboyle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #ifndef GRID_VECTOR_UNOPS #define GRID_VECTOR_UNOPS #include namespace Grid { template struct SqrtRealFunctor { scalar operator()(const scalar &a) const { return sqrt(real(a)); } }; template struct RSqrtRealFunctor { scalar operator()(const scalar &a) const { return scalar(1.0/sqrt(real(a))); } }; template struct CosRealFunctor { scalar operator()(const scalar &a) const { return cos(real(a)); } }; template struct SinRealFunctor { scalar operator()(const scalar &a) const { return sin(real(a)); } }; 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) {}; scalar operator()(const scalar &a) const { return pow(real(a),y); } }; template struct ModIntFunctor { Integer y; ModIntFunctor(Integer _y) : y(_y) {}; scalar operator()(const scalar &a) const { return Integer(a)%y; } }; template struct DivIntFunctor { Integer y; DivIntFunctor(Integer _y) : y(_y) {}; scalar operator()(const scalar &a) const { return Integer(a)/y; } }; 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); } template < class S, class V > inline Grid_simd rsqrt(const Grid_simd &r) { return SimdApply(RSqrtRealFunctor(),r); } template < class Scalar > inline Scalar rsqrt(const Scalar &r) { return (RSqrtRealFunctor(),r); } template < class S, class V > inline Grid_simd cos(const Grid_simd &r) { return SimdApply(CosRealFunctor(),r); } template < class S, class V > inline Grid_simd sin(const Grid_simd &r) { return SimdApply(SinRealFunctor(),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); } template < class S, class V > inline Grid_simd mod(const Grid_simd &r,Integer y) { return SimdApply(ModIntFunctor(y),r); } template < class S, class V > inline Grid_simd div(const Grid_simd &r,Integer y) { return SimdApply(DivIntFunctor(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