diff --git a/Grid/lattice/Lattice_ET.h b/Grid/lattice/Lattice_ET.h index 0bcad224f..735f6f4e1 100644 --- a/Grid/lattice/Lattice_ET.h +++ b/Grid/lattice/Lattice_ET.h @@ -74,7 +74,7 @@ accelerator_inline vobj predicatedWhere(const iobj &predicate, extract(iftrue, truevals); extract(iffalse, falsevals); - extract(TensorRemove(predicate), mask); + extract(TensorRemove(predicate), mask); for (int s = 0; s < Nsimd; s++) { if (mask[s]) falsevals[s] = truevals[s]; diff --git a/Grid/lattice/Lattice_comparison.h b/Grid/lattice/Lattice_comparison.h index b99126399..91d683da8 100644 --- a/Grid/lattice/Lattice_comparison.h +++ b/Grid/lattice/Lattice_comparison.h @@ -40,16 +40,16 @@ NAMESPACE_BEGIN(Grid); //Query supporting logical &&, ||, ////////////////////////////////////////////////////////////////////////// -typedef iScalar vPredicate ; +template using vPredicate = iScalar > ; ////////////////////////////////////////////////////////////////////////// // compare lattice to lattice ////////////////////////////////////////////////////////////////////////// template -inline Lattice LLComparison(vfunctor op,const Lattice &lhs,const Lattice &rhs) +inline Lattice > LLComparison(vfunctor op,const Lattice &lhs,const Lattice &rhs) { - Lattice ret(rhs.Grid()); + Lattice > ret(rhs.Grid()); autoView( lhs_v, lhs, CpuRead); autoView( rhs_v, rhs, CpuRead); autoView( ret_v, ret, CpuWrite); @@ -62,9 +62,9 @@ inline Lattice LLComparison(vfunctor op,const Lattice &lhs,con // compare lattice to scalar ////////////////////////////////////////////////////////////////////////// template -inline Lattice LSComparison(vfunctor op,const Lattice &lhs,const robj &rhs) +inline Lattice > LSComparison(vfunctor op,const Lattice &lhs,const robj &rhs) { - Lattice ret(lhs.Grid()); + Lattice > ret(lhs.Grid()); autoView( lhs_v, lhs, CpuRead); autoView( ret_v, ret, CpuWrite); thread_for( ss, lhs_v.size(), { @@ -76,9 +76,9 @@ inline Lattice LSComparison(vfunctor op,const Lattice &lhs,con // compare scalar to lattice ////////////////////////////////////////////////////////////////////////// template -inline Lattice SLComparison(vfunctor op,const lobj &lhs,const Lattice &rhs) +inline Lattice > SLComparison(vfunctor op,const lobj &lhs,const Lattice &rhs) { - Lattice ret(rhs.Grid()); + Lattice > ret(rhs.Grid()); autoView( rhs_v, rhs, CpuRead); autoView( ret_v, ret, CpuWrite); thread_for( ss, rhs_v.size(), { @@ -92,87 +92,87 @@ inline Lattice SLComparison(vfunctor op,const lobj &lhs,const Lattic ////////////////////////////////////////////////////////////////////////// // Less than template -inline Lattice operator < (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator < (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vlt(),lhs,rhs); } template -inline Lattice operator < (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator < (const Lattice & lhs, const robj & rhs) { return LSComparison(vlt(),lhs,rhs); } template -inline Lattice operator < (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator < (const lobj & lhs, const Lattice & rhs) { return SLComparison(vlt(),lhs,rhs); } // Less than equal template -inline Lattice operator <= (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator <= (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vle(),lhs,rhs); } template -inline Lattice operator <= (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator <= (const Lattice & lhs, const robj & rhs) { return LSComparison(vle(),lhs,rhs); } template -inline Lattice operator <= (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator <= (const lobj & lhs, const Lattice & rhs) { return SLComparison(vle(),lhs,rhs); } // Greater than template -inline Lattice operator > (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator > (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vgt(),lhs,rhs); } template -inline Lattice operator > (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator > (const Lattice & lhs, const robj & rhs) { return LSComparison(vgt(),lhs,rhs); } template -inline Lattice operator > (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator > (const lobj & lhs, const Lattice & rhs) { return SLComparison(vgt(),lhs,rhs); } // Greater than equal template -inline Lattice operator >= (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator >= (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vge(),lhs,rhs); } template -inline Lattice operator >= (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator >= (const Lattice & lhs, const robj & rhs) { return LSComparison(vge(),lhs,rhs); } template -inline Lattice operator >= (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator >= (const lobj & lhs, const Lattice & rhs) { return SLComparison(vge(),lhs,rhs); } // equal template -inline Lattice operator == (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator == (const Lattice & lhs, const Lattice & rhs) { return LLComparison(veq(),lhs,rhs); } template -inline Lattice operator == (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator == (const Lattice & lhs, const robj & rhs) { return LSComparison(veq(),lhs,rhs); } template -inline Lattice operator == (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator == (const lobj & lhs, const Lattice & rhs) { return SLComparison(veq(),lhs,rhs); } // not equal template -inline Lattice operator != (const Lattice & lhs, const Lattice & rhs) { +inline Lattice > operator != (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vne(),lhs,rhs); } template -inline Lattice operator != (const Lattice & lhs, const robj & rhs) { +inline Lattice > operator != (const Lattice & lhs, const robj & rhs) { return LSComparison(vne(),lhs,rhs); } template -inline Lattice operator != (const lobj & lhs, const Lattice & rhs) { +inline Lattice > operator != (const lobj & lhs, const Lattice & rhs) { return SLComparison(vne(),lhs,rhs); } NAMESPACE_END(Grid); diff --git a/Grid/lattice/Lattice_comparison_utils.h b/Grid/lattice/Lattice_comparison_utils.h index 431aa9e1f..7c1f78829 100644 --- a/Grid/lattice/Lattice_comparison_utils.h +++ b/Grid/lattice/Lattice_comparison_utils.h @@ -39,47 +39,53 @@ NAMESPACE_BEGIN(Grid); // // Should guard this with isGridTensor<> enable if? ///////////////////////////////////////// + // + // Predicate type matching the operand's vectorisation + // + template using IntegerPredicate = + typename GridTypeMapper::vector_type>::Integerified; + // // Generic list of functors // template class veq { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) == (rhs); } }; template class vne { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) != (rhs); } }; template class vlt { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) < (rhs); } }; template class vle { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) <= (rhs); } }; template class vgt { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) > (rhs); } }; template class vge { public: - accelerator vInteger operator()(const lobj &lhs, const robj &rhs) + accelerator IntegerPredicate operator()(const lobj &lhs, const robj &rhs) { return (lhs) >= (rhs); } @@ -133,78 +139,78 @@ NAMESPACE_BEGIN(Grid); // Integer and real get extra relational functions. ////////////////////////////////////////////////////////////////////////////////////////////////////// template = 0> - accelerator_inline vInteger Comparison(sfunctor sop,const vsimd & lhs, const vsimd & rhs) + accelerator_inline IntegerPredicate Comparison(sfunctor sop,const vsimd & lhs, const vsimd & rhs) { typedef typename vsimd::scalar_type scalar; ExtractBuffer vlhs(vsimd::Nsimd()); // Use functors to reduce this to single implementation ExtractBuffer vrhs(vsimd::Nsimd()); ExtractBuffer vpred(vsimd::Nsimd()); - vInteger ret; + IntegerPredicate ret; extract(lhs,vlhs); extract(rhs,vrhs); for(int s=0;s(ret,vpred); + merge,Integer>(ret,vpred); return ret; } template = 0> - accelerator_inline vInteger Comparison(sfunctor sop,const vsimd & lhs, const typename vsimd::scalar_type & rhs) + accelerator_inline IntegerPredicate Comparison(sfunctor sop,const vsimd & lhs, const typename vsimd::scalar_type & rhs) { typedef typename vsimd::scalar_type scalar; ExtractBuffer vlhs(vsimd::Nsimd()); // Use functors to reduce this to single implementation ExtractBuffer vpred(vsimd::Nsimd()); - vInteger ret; + IntegerPredicate ret; extract(lhs,vlhs); for(int s=0;s(ret,vpred); + merge,Integer>(ret,vpred); return ret; } template = 0> - accelerator_inline vInteger Comparison(sfunctor sop,const typename vsimd::scalar_type & lhs, const vsimd & rhs) + accelerator_inline IntegerPredicate Comparison(sfunctor sop,const typename vsimd::scalar_type & lhs, const vsimd & rhs) { typedef typename vsimd::scalar_type scalar; ExtractBuffer vrhs(vsimd::Nsimd()); // Use functors to reduce this to single implementation ExtractBuffer vpred(vsimd::Nsimd()); - vInteger ret; + IntegerPredicate ret; extract(rhs,vrhs); for(int s=0;s(ret,vpred); + merge,Integer>(ret,vpred); return ret; } #define DECLARE_RELATIONAL_EQ(op,functor) \ template = 0>\ - accelerator_inline vInteger operator op (const vsimd & lhs, const vsimd & rhs)\ + accelerator_inline IntegerPredicate operator op (const vsimd & lhs, const vsimd & rhs)\ {\ typedef typename vsimd::scalar_type scalar;\ return Comparison(functor(),lhs,rhs);\ }\ template = 0>\ - accelerator_inline vInteger operator op (const vsimd & lhs, const typename vsimd::scalar_type & rhs) \ + accelerator_inline IntegerPredicate operator op (const vsimd & lhs, const typename vsimd::scalar_type & rhs) \ {\ typedef typename vsimd::scalar_type scalar;\ return Comparison(functor(),lhs,rhs);\ }\ template = 0>\ - accelerator_inline vInteger operator op (const typename vsimd::scalar_type & lhs, const vsimd & rhs) \ + accelerator_inline IntegerPredicate operator op (const typename vsimd::scalar_type & lhs, const vsimd & rhs) \ {\ typedef typename vsimd::scalar_type scalar;\ return Comparison(functor(),lhs,rhs);\ }\ template\ - accelerator_inline vInteger operator op(const iScalar &lhs,const typename vsimd::scalar_type &rhs) \ + accelerator_inline IntegerPredicate operator op(const iScalar &lhs,const typename vsimd::scalar_type &rhs) \ { \ return lhs._internal op rhs; \ } \ template\ - accelerator_inline vInteger operator op(const typename vsimd::scalar_type &lhs,const iScalar &rhs) \ + accelerator_inline IntegerPredicate operator op(const typename vsimd::scalar_type &lhs,const iScalar &rhs) \ { \ return lhs op rhs._internal; \ } \ @@ -212,7 +218,7 @@ NAMESPACE_BEGIN(Grid); #define DECLARE_RELATIONAL(op,functor) \ DECLARE_RELATIONAL_EQ(op,functor) \ template\ - accelerator_inline vInteger operator op(const iScalar &lhs,const iScalar &rhs)\ + accelerator_inline IntegerPredicate operator op(const iScalar &lhs,const iScalar &rhs)\ { \ return lhs._internal op rhs._internal; \ }