/************************************************************************************* 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_BEGIN(Grid); template struct SqrtRealFunctor { accelerator scalar operator()(const scalar &a) const { return sqrt(real(a)); } }; template struct RSqrtRealFunctor { accelerator scalar operator()(const scalar &a) const { return scalar(1.0 / sqrt(real(a))); } }; template struct CosRealFunctor { accelerator scalar operator()(const scalar &a) const { return cos(real(a)); } }; template struct SinRealFunctor { accelerator scalar operator()(const scalar &a) const { return sin(real(a)); } }; template struct AcosRealFunctor { accelerator scalar operator()(const scalar &a) const { return acos(real(a)); } }; template struct AsinRealFunctor { accelerator scalar operator()(const scalar &a) const { return asin(real(a)); } }; template struct LogRealFunctor { accelerator scalar operator()(const scalar &a) const { return log(real(a)); } }; template struct ExpFunctor { accelerator scalar operator()(const scalar &a) const { return exp(a); } }; template struct NotFunctor { accelerator scalar operator()(const scalar &a) const { return (!a); } }; template struct AbsRealFunctor { accelerator scalar operator()(const scalar &a) const { return std::abs(real(a)); } }; template struct PowRealFunctor { double y; accelerator PowRealFunctor(double _y) : y(_y){}; accelerator scalar operator()(const scalar &a) const { return pow(real(a), y); } }; template struct ModIntFunctor { Integer y; accelerator ModIntFunctor(Integer _y) : y(_y){}; accelerator scalar operator()(const scalar &a) const { return Integer(a) % y; } }; template struct DivIntFunctor { Integer y; accelerator DivIntFunctor(Integer _y) : y(_y){}; accelerator scalar operator()(const scalar &a) const { return Integer(a) / y; } }; template struct RealFunctor { accelerator scalar operator()(const scalar &a) const { return real(a); } }; template struct ImagFunctor { accelerator scalar operator()(const scalar &a) const { return imag(a); } }; template accelerator_inline Grid_simd real(const Grid_simd &r) { return SimdApply(RealFunctor(), r); } template accelerator_inline Grid_simd imag(const Grid_simd &r) { return SimdApply(ImagFunctor(), r); } template accelerator_inline Grid_simd sqrt(const Grid_simd &r) { return SimdApply(SqrtRealFunctor(), r); } template accelerator_inline Grid_simd rsqrt(const Grid_simd &r) { return SimdApply(RSqrtRealFunctor(), r); } template accelerator_inline Scalar rsqrt(const Scalar &r) { return (RSqrtRealFunctor(), r); } template accelerator_inline Grid_simd cos(const Grid_simd &r) { return SimdApply(CosRealFunctor(), r); } template accelerator_inline Grid_simd sin(const Grid_simd &r) { return SimdApply(SinRealFunctor(), r); } template accelerator_inline Grid_simd acos(const Grid_simd &r) { return SimdApply(AcosRealFunctor(), r); } template accelerator_inline Grid_simd asin(const Grid_simd &r) { return SimdApply(AsinRealFunctor(), r); } template accelerator_inline Grid_simd log(const Grid_simd &r) { return SimdApply(LogRealFunctor(), r); } template accelerator_inline Grid_simd abs(const Grid_simd &r) { return SimdApply(AbsRealFunctor(), r); } template accelerator_inline Grid_simd exp(const Grid_simd &r) { return SimdApply(ExpFunctor(), r); } template accelerator_inline Grid_simd Not(const Grid_simd &r) { return SimdApply(NotFunctor(), r); } template accelerator_inline Grid_simd pow(const Grid_simd &r, double y) { return SimdApply(PowRealFunctor(y), r); } template accelerator_inline Grid_simd mod(const Grid_simd &r, Integer y) { return SimdApply(ModIntFunctor(y), r); } template accelerator_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 struct AndFunctor { accelerator scalar operator()(const scalar &x, const scalar &y) const { return x & y; } }; template struct OrFunctor { accelerator scalar operator()(const scalar &x, const scalar &y) const { return x | y; } }; template struct AndAndFunctor { accelerator scalar operator()(const scalar &x, const scalar &y) const { return x && y; } }; template struct OrOrFunctor { accelerator scalar operator()(const scalar &x, const scalar &y) const { return x || y; } }; //////////////////////////////// // Calls to simd binop functors //////////////////////////////// template accelerator_inline Grid_simd operator&(const Grid_simd &x, const Grid_simd &y) { return SimdApplyBinop(AndFunctor(), x, y); } template accelerator_inline Grid_simd operator&&(const Grid_simd &x, const Grid_simd &y) { return SimdApplyBinop(AndAndFunctor(), x, y); } template accelerator_inline Grid_simd operator|(const Grid_simd &x, const Grid_simd &y) { return SimdApplyBinop(OrFunctor(), x, y); } template accelerator_inline Grid_simd operator||(const Grid_simd &x, const Grid_simd &y) { return SimdApplyBinop(OrOrFunctor(), x, y); } NAMESPACE_END(Grid); #endif