1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-10 22:20:45 +01:00

NAMESPACE and formatting

This commit is contained in:
paboyle 2018-01-12 18:10:11 +00:00
parent fbc2380cb8
commit bbb657da5c

View File

@ -1,4 +1,4 @@
/*************************************************************************************
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
@ -25,15 +25,15 @@ Author: Antonin Portelli <antonin.portelli@me.com>
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 */
*************************************************************************************/
/* END LEGAL */
#include "Grid_generic_types.h"
namespace Grid {
namespace Optimization {
NAMESPACE_BEGIN(Grid);
NAMESPACE_BEGIN(Optimization);
struct Vsplat{
struct Vsplat{
// Complex
template <typename T>
inline vec<T> operator()(T a, T b){
@ -60,25 +60,25 @@ namespace Optimization {
return out;
}
};
};
struct Vstore{
struct Vstore{
// Real
template <typename T>
inline void operator()(vec<T> a, T *D){
*((vec<T> *)D) = a;
}
};
};
struct Vstream{
struct Vstream{
// Real
template <typename T>
inline void operator()(T * a, vec<T> b){
*((vec<T> *)a) = b;
}
};
};
struct Vset{
struct Vset{
// Complex
template <typename T>
inline vec<T> operator()(std::complex<T> *a){
@ -102,12 +102,12 @@ namespace Optimization {
return out;
}
};
};
/////////////////////////////////////////////////////
// Arithmetic operations
/////////////////////////////////////////////////////
struct Sum{
/////////////////////////////////////////////////////
// Arithmetic operations
/////////////////////////////////////////////////////
struct Sum{
// Complex/Real
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -120,9 +120,9 @@ namespace Optimization {
return out;
}
};
};
struct Sub{
struct Sub{
// Complex/Real
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -135,9 +135,9 @@ namespace Optimization {
return out;
}
};
};
struct Mult{
struct Mult{
// Real
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -150,13 +150,13 @@ namespace Optimization {
return out;
}
};
};
#define cmul(a, b, c, i)\
c[i] = a[i]*b[i] - a[i+1]*b[i+1];\
#define cmul(a, b, c, i) \
c[i] = a[i]*b[i] - a[i+1]*b[i+1]; \
c[i+1] = a[i]*b[i+1] + a[i+1]*b[i];
struct MultRealPart{
struct MultRealPart{
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
vec<T> out;
@ -168,9 +168,9 @@ namespace Optimization {
}
return out;
}
};
};
struct MaddRealPart{
struct MaddRealPart{
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b, vec<T> c){
vec<T> out;
@ -182,9 +182,9 @@ namespace Optimization {
}
return out;
}
};
};
struct MultComplex{
struct MultComplex{
// Complex
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -197,11 +197,11 @@ namespace Optimization {
return out;
}
};
};
#undef cmul
#undef cmul
struct Div{
struct Div{
// Real
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -214,13 +214,13 @@ namespace Optimization {
return out;
}
};
};
#define conj(a, b, i)\
b[i] = a[i];\
#define conj(a, b, i) \
b[i] = a[i]; \
b[i+1] = -a[i+1];
struct Conj{
struct Conj{
// Complex
template <typename T>
inline vec<T> operator()(vec<T> a){
@ -233,15 +233,15 @@ namespace Optimization {
return out;
}
};
};
#undef conj
#undef conj
#define timesmi(a, b, i)\
b[i] = a[i+1];\
#define timesmi(a, b, i) \
b[i] = a[i+1]; \
b[i+1] = -a[i];
struct TimesMinusI{
struct TimesMinusI{
// Complex
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -254,15 +254,15 @@ namespace Optimization {
return out;
}
};
};
#undef timesmi
#undef timesmi
#define timesi(a, b, i)\
b[i] = -a[i+1];\
#define timesi(a, b, i) \
b[i] = -a[i+1]; \
b[i+1] = a[i];
struct TimesI{
struct TimesI{
// Complex
template <typename T>
inline vec<T> operator()(vec<T> a, vec<T> b){
@ -275,11 +275,11 @@ namespace Optimization {
return out;
}
};
};
#undef timesi
#undef timesi
struct PrecisionChange {
struct PrecisionChange {
static inline vech StoH (const vecf &a,const vecf &b) {
vech ret;
#ifdef USE_FP16
@ -335,11 +335,11 @@ namespace Optimization {
StoD(sa,a,b);
StoD(sb,c,d);
}
};
};
//////////////////////////////////////////////
// Exchange support
struct Exchange{
//////////////////////////////////////////////
// Exchange support
struct Exchange{
template <typename T,int n>
static inline void ExchangeN(vec<T> &out1,vec<T> &out2,vec<T> &in1,vec<T> &in2){
@ -371,43 +371,43 @@ namespace Optimization {
static inline void Exchange3(vec<T> &out1,vec<T> &out2,vec<T> &in1,vec<T> &in2){
ExchangeN<T,3>(out1,out2,in1,in2);
};
};
};
//////////////////////////////////////////////
// Some Template specialization
#define perm(a, b, n, w)\
unsigned int _mask = w >> (n + 1);\
VECTOR_FOR(i, w, 1)\
{\
b[i] = a[i^_mask];\
//////////////////////////////////////////////
// Some Template specialization
#define perm(a, b, n, w) \
unsigned int _mask = w >> (n + 1); \
VECTOR_FOR(i, w, 1) \
{ \
b[i] = a[i^_mask]; \
}
#define DECL_PERMUTE_N(n)\
template <typename T>\
static inline vec<T> Permute##n(vec<T> in) {\
vec<T> out;\
perm(in.v, out.v, n, W<T>::r);\
return out;\
#define DECL_PERMUTE_N(n) \
template <typename T> \
static inline vec<T> Permute##n(vec<T> in) { \
vec<T> out; \
perm(in.v, out.v, n, W<T>::r); \
return out; \
}
struct Permute{
struct Permute{
DECL_PERMUTE_N(0);
DECL_PERMUTE_N(1);
DECL_PERMUTE_N(2);
DECL_PERMUTE_N(3);
};
};
#undef perm
#undef DECL_PERMUTE_N
#undef perm
#undef DECL_PERMUTE_N
#define rot(a, b, n, w)\
VECTOR_FOR(i, w, 1)\
{\
b[i] = a[(i + n)%w];\
#define rot(a, b, n, w) \
VECTOR_FOR(i, w, 1) \
{ \
b[i] = a[(i + n)%w]; \
}
struct Rotate{
struct Rotate{
template <int n, typename T> static inline vec<T> tRotate(vec<T> in){
return rotate(in, n);
@ -421,17 +421,17 @@ namespace Optimization {
return out;
}
};
};
#undef rot
#undef rot
#define acc(v, a, off, step, n)\
for (unsigned int i = off; i < n; i += step)\
{\
a += v[i];\
#define acc(v, a, off, step, n) \
for (unsigned int i = off; i < n; i += step) \
{ \
a += v[i]; \
}
template <typename Out_type, typename In_type>
template <typename Out_type, typename In_type>
struct Reduce{
//Need templated class to overload output type
//General form must generate error if compiled
@ -442,89 +442,91 @@ namespace Optimization {
}
};
//Complex float Reduce
template <>
inline Grid::ComplexF Reduce<Grid::ComplexF, vecf>::operator()(vecf in){
//Complex float Reduce
template <>
inline Grid::ComplexF Reduce<Grid::ComplexF, vecf>::operator()(vecf in){
float a = 0.f, b = 0.f;
acc(in.v, a, 0, 2, W<float>::r);
acc(in.v, b, 1, 2, W<float>::r);
return Grid::ComplexF(a, b);
}
}
//Real float Reduce
template<>
inline Grid::RealF Reduce<Grid::RealF, vecf>::operator()(vecf in){
//Real float Reduce
template<>
inline Grid::RealF Reduce<Grid::RealF, vecf>::operator()(vecf in){
float a = 0.;
acc(in.v, a, 0, 1, W<float>::r);
return a;
}
}
//Complex double Reduce
template<>
inline Grid::ComplexD Reduce<Grid::ComplexD, vecd>::operator()(vecd in){
//Complex double Reduce
template<>
inline Grid::ComplexD Reduce<Grid::ComplexD, vecd>::operator()(vecd in){
double a = 0., b = 0.;
acc(in.v, a, 0, 2, W<double>::r);
acc(in.v, b, 1, 2, W<double>::r);
return Grid::ComplexD(a, b);
}
}
//Real double Reduce
template<>
inline Grid::RealD Reduce<Grid::RealD, vecd>::operator()(vecd in){
//Real double Reduce
template<>
inline Grid::RealD Reduce<Grid::RealD, vecd>::operator()(vecd in){
double a = 0.f;
acc(in.v, a, 0, 1, W<double>::r);
return a;
}
}
//Integer Reduce
template<>
inline Integer Reduce<Integer, veci>::operator()(veci in){
//Integer Reduce
template<>
inline Integer Reduce<Integer, veci>::operator()(veci in){
Integer a = 0;
acc(in.v, a, 0, 1, W<Integer>::r);
return a;
}
#undef acc // EIGEN compatibility
}
#undef acc // EIGEN compatibility
NAMESPACE_END(Optimization)
//////////////////////////////////////////////////////////////////////////////////////
// Here assign types
typedef Optimization::vech SIMD_Htype; // Reduced precision type
typedef Optimization::vecf SIMD_Ftype; // Single precision type
typedef Optimization::vecd SIMD_Dtype; // Double precision type
typedef Optimization::veci SIMD_Itype; // Integer type
typedef Optimization::vech SIMD_Htype; // Reduced precision type
typedef Optimization::vecf SIMD_Ftype; // Single precision type
typedef Optimization::vecd SIMD_Dtype; // Double precision type
typedef Optimization::veci SIMD_Itype; // Integer type
// prefetch utilities
inline void v_prefetch0(int size, const char *ptr){};
inline void prefetch_HINT_T0(const char *ptr){};
// prefetch utilities
inline void v_prefetch0(int size, const char *ptr){};
inline void prefetch_HINT_T0(const char *ptr){};
// Function name aliases
typedef Optimization::Vsplat VsplatSIMD;
typedef Optimization::Vstore VstoreSIMD;
typedef Optimization::Vset VsetSIMD;
typedef Optimization::Vstream VstreamSIMD;
template <typename S, typename T> using ReduceSIMD = Optimization::Reduce<S,T>;
// Function name aliases
typedef Optimization::Vsplat VsplatSIMD;
typedef Optimization::Vstore VstoreSIMD;
typedef Optimization::Vset VsetSIMD;
typedef Optimization::Vstream VstreamSIMD;
template <typename S, typename T> using ReduceSIMD = Optimization::Reduce<S,T>;
// Arithmetic operations
typedef Optimization::Sum SumSIMD;
typedef Optimization::Sub SubSIMD;
typedef Optimization::Div DivSIMD;
typedef Optimization::Mult MultSIMD;
typedef Optimization::MultComplex MultComplexSIMD;
typedef Optimization::MultRealPart MultRealPartSIMD;
typedef Optimization::MaddRealPart MaddRealPartSIMD;
typedef Optimization::Conj ConjSIMD;
typedef Optimization::TimesMinusI TimesMinusISIMD;
typedef Optimization::TimesI TimesISIMD;
NAMESPACE_END(Grid)
// Arithmetic operations
typedef Optimization::Sum SumSIMD;
typedef Optimization::Sub SubSIMD;
typedef Optimization::Div DivSIMD;
typedef Optimization::Mult MultSIMD;
typedef Optimization::MultComplex MultComplexSIMD;
typedef Optimization::MultRealPart MultRealPartSIMD;
typedef Optimization::MaddRealPart MaddRealPartSIMD;
typedef Optimization::Conj ConjSIMD;
typedef Optimization::TimesMinusI TimesMinusISIMD;
typedef Optimization::TimesI TimesISIMD;
}