mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-11 14:40:46 +01:00
Format
This commit is contained in:
parent
ec89714cce
commit
00c49d4c17
@ -25,14 +25,14 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
******************************************************************************/
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef GEN_SIMD_WIDTH
|
||||
#define GEN_SIMD_WIDTH 32u
|
||||
#endif
|
||||
#include "Grid_generic_types.h" // Definitions for simulated integer SIMD.
|
||||
|
||||
namespace Grid {
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
#ifdef QPX
|
||||
#include <spi/include/kernel/location.h>
|
||||
@ -41,25 +41,26 @@ namespace Grid {
|
||||
#include <hwi/include/bqc/A2_inlines.h>
|
||||
#endif
|
||||
|
||||
namespace Optimization {
|
||||
typedef struct
|
||||
{
|
||||
float v0,v1,v2,v3;
|
||||
} vector4float;
|
||||
NAMESPACE_BEGIN(Optimization);
|
||||
|
||||
inline std::ostream & operator<<(std::ostream& stream, const vector4double a)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
float v0,v1,v2,v3;
|
||||
} vector4float;
|
||||
|
||||
inline std::ostream & operator<<(std::ostream& stream, const vector4double a)
|
||||
{
|
||||
stream << "{"<<vec_extract(a,0)<<","<<vec_extract(a,1)<<","<<vec_extract(a,2)<<","<<vec_extract(a,3)<<"}";
|
||||
return stream;
|
||||
};
|
||||
};
|
||||
|
||||
inline std::ostream & operator<<(std::ostream& stream, const vector4float a)
|
||||
{
|
||||
inline std::ostream & operator<<(std::ostream& stream, const vector4float a)
|
||||
{
|
||||
stream << "{"<< a.v0 <<","<< a.v1 <<","<< a.v2 <<","<< a.v3 <<"}";
|
||||
return stream;
|
||||
};
|
||||
};
|
||||
|
||||
struct Vsplat{
|
||||
struct Vsplat{
|
||||
//Complex float
|
||||
inline vector4float operator()(float a, float b){
|
||||
return (vector4float){a, b, a, b};
|
||||
@ -87,9 +88,9 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Vstore{
|
||||
struct Vstore{
|
||||
//Float
|
||||
inline void operator()(vector4double a, float *f){
|
||||
vec_st(a, 0, f);
|
||||
@ -115,9 +116,9 @@ namespace Optimization {
|
||||
inline void operator()(veci a, Integer *i){
|
||||
*((veci *)i) = a;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Vstream{
|
||||
struct Vstream{
|
||||
//Float
|
||||
inline void operator()(float *f, vector4double a){
|
||||
vec_st(a, 0, f);
|
||||
@ -138,9 +139,9 @@ namespace Optimization {
|
||||
vec_st(a, 0, d);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
struct Vset{
|
||||
struct Vset{
|
||||
// Complex float
|
||||
inline vector4float operator()(Grid::ComplexF *a){
|
||||
return (vector4float){a[0].real(), a[0].imag(), a[1].real(), a[1].imag()};
|
||||
@ -171,9 +172,9 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
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
|
||||
@ -184,53 +185,53 @@ namespace Optimization {
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Arithmetic operations
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
// Arithmetic operations
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
#define FLOAT_WRAP_3(fn, pref)\
|
||||
#define FLOAT_WRAP_3(fn, pref) \
|
||||
pref vector4float fn(vector4float a, vector4float b, vector4float c) \
|
||||
{\
|
||||
{ \
|
||||
vector4double ad, bd, rd, cd; \
|
||||
vector4float r;\
|
||||
vector4float r; \
|
||||
\
|
||||
ad = Vset()(a);\
|
||||
bd = Vset()(b);\
|
||||
cd = Vset()(c);\
|
||||
ad = Vset()(a); \
|
||||
bd = Vset()(b); \
|
||||
cd = Vset()(c); \
|
||||
rd = fn(ad, bd, cd); \
|
||||
Vstore()(rd, r);\
|
||||
Vstore()(rd, r); \
|
||||
\
|
||||
return r;\
|
||||
return r; \
|
||||
}
|
||||
|
||||
#define FLOAT_WRAP_2(fn, pref)\
|
||||
pref vector4float fn(vector4float a, vector4float b)\
|
||||
{\
|
||||
vector4double ad, bd, rd;\
|
||||
vector4float r;\
|
||||
#define FLOAT_WRAP_2(fn, pref) \
|
||||
pref vector4float fn(vector4float a, vector4float b) \
|
||||
{ \
|
||||
vector4double ad, bd, rd; \
|
||||
vector4float r; \
|
||||
\
|
||||
ad = Vset()(a);\
|
||||
bd = Vset()(b);\
|
||||
rd = fn(ad, bd);\
|
||||
Vstore()(rd, r);\
|
||||
ad = Vset()(a); \
|
||||
bd = Vset()(b); \
|
||||
rd = fn(ad, bd); \
|
||||
Vstore()(rd, r); \
|
||||
\
|
||||
return r;\
|
||||
return r; \
|
||||
}
|
||||
|
||||
#define FLOAT_WRAP_1(fn, pref)\
|
||||
pref vector4float fn(vector4float a)\
|
||||
{\
|
||||
vector4double ad, rd;\
|
||||
vector4float r;\
|
||||
#define FLOAT_WRAP_1(fn, pref) \
|
||||
pref vector4float fn(vector4float a) \
|
||||
{ \
|
||||
vector4double ad, rd; \
|
||||
vector4float r; \
|
||||
\
|
||||
ad = Vset()(a);\
|
||||
rd = fn(ad);\
|
||||
Vstore()(rd, r);\
|
||||
ad = Vset()(a); \
|
||||
rd = fn(ad); \
|
||||
Vstore()(rd, r); \
|
||||
\
|
||||
return r;\
|
||||
return r; \
|
||||
}
|
||||
|
||||
struct Sum{
|
||||
struct Sum{
|
||||
//Complex/Real double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
return vec_add(a, b);
|
||||
@ -250,9 +251,9 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Sub{
|
||||
struct Sub{
|
||||
//Complex/Real double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
return vec_sub(a, b);
|
||||
@ -272,24 +273,24 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct MultRealPart{
|
||||
struct MultRealPart{
|
||||
// Complex double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
// return vec_xmul(b, a);
|
||||
return vec_xmul(a, b);
|
||||
}
|
||||
FLOAT_WRAP_2(operator(), inline)
|
||||
};
|
||||
struct MaddRealPart{
|
||||
};
|
||||
struct MaddRealPart{
|
||||
// Complex double
|
||||
inline vector4double operator()(vector4double a, vector4double b,vector4double c){
|
||||
return vec_xmadd(a, b, c);
|
||||
}
|
||||
FLOAT_WRAP_3(operator(), inline)
|
||||
};
|
||||
struct MultComplex{
|
||||
};
|
||||
struct MultComplex{
|
||||
// Complex double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
return vec_xxnpmadd(a, b, vec_xmul(b, a));
|
||||
@ -297,9 +298,9 @@ namespace Optimization {
|
||||
|
||||
// Complex float
|
||||
FLOAT_WRAP_2(operator(), inline)
|
||||
};
|
||||
};
|
||||
|
||||
struct Mult{
|
||||
struct Mult{
|
||||
// Real double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
return vec_mul(a, b);
|
||||
@ -319,9 +320,9 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Div{
|
||||
struct Div{
|
||||
// Real double
|
||||
inline vector4double operator()(vector4double a, vector4double b){
|
||||
return vec_swdiv(a, b);
|
||||
@ -341,9 +342,9 @@ namespace Optimization {
|
||||
|
||||
return out;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Conj{
|
||||
struct Conj{
|
||||
// Complex double
|
||||
inline vector4double operator()(vector4double v){
|
||||
return vec_mul(v, (vector4double){1., -1., 1., -1.});
|
||||
@ -351,9 +352,9 @@ namespace Optimization {
|
||||
|
||||
// Complex float
|
||||
FLOAT_WRAP_1(operator(), inline)
|
||||
};
|
||||
};
|
||||
|
||||
struct TimesMinusI{
|
||||
struct TimesMinusI{
|
||||
//Complex double
|
||||
inline vector4double operator()(vector4double v, vector4double ret){
|
||||
return vec_xxcpnmadd(v, (vector4double){1., 1., 1., 1.},
|
||||
@ -362,9 +363,9 @@ namespace Optimization {
|
||||
|
||||
// Complex float
|
||||
FLOAT_WRAP_2(operator(), inline)
|
||||
};
|
||||
};
|
||||
|
||||
struct TimesI{
|
||||
struct TimesI{
|
||||
//Complex double
|
||||
inline vector4double operator()(vector4double v, vector4double ret){
|
||||
return vec_xxcpnmadd(v, (vector4double){-1., -1., -1., -1.},
|
||||
@ -373,9 +374,9 @@ namespace Optimization {
|
||||
|
||||
// Complex float
|
||||
FLOAT_WRAP_2(operator(), inline)
|
||||
};
|
||||
};
|
||||
#define USE_FP16
|
||||
struct PrecisionChange {
|
||||
struct PrecisionChange {
|
||||
static inline vech StoH (const vector4float &a, const vector4float &b) {
|
||||
vech ret;
|
||||
std::cout << GridLogError << "QPX single to half precision conversion not yet supported." << std::endl;
|
||||
@ -408,10 +409,10 @@ namespace Optimization {
|
||||
std::cout << GridLogError << "QPX half to double precision conversion not yet supported." << std::endl;
|
||||
assert(0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Exchange support
|
||||
//////////////////////////////////////////////
|
||||
// Exchange support
|
||||
#define FLOAT_WRAP_EXCHANGE(fn) \
|
||||
static inline void fn(vector4float &out1, vector4float &out2, \
|
||||
vector4float in1, vector4float in2) \
|
||||
@ -424,7 +425,7 @@ namespace Optimization {
|
||||
Vstore()(out2d, out2); \
|
||||
}
|
||||
|
||||
struct Exchange{
|
||||
struct Exchange{
|
||||
|
||||
// double precision
|
||||
static inline void Exchange0(vector4double &out1, vector4double &out2,
|
||||
@ -451,9 +452,9 @@ namespace Optimization {
|
||||
FLOAT_WRAP_EXCHANGE(Exchange1);
|
||||
FLOAT_WRAP_EXCHANGE(Exchange2);
|
||||
FLOAT_WRAP_EXCHANGE(Exchange3);
|
||||
};
|
||||
};
|
||||
|
||||
struct Permute{
|
||||
struct Permute{
|
||||
//Complex double
|
||||
static inline vector4double Permute0(vector4double v){ //0123 -> 2301
|
||||
return vec_perm(v, v, vec_gpci(02301));
|
||||
@ -473,9 +474,9 @@ namespace Optimization {
|
||||
FLOAT_WRAP_1(Permute1, static inline)
|
||||
FLOAT_WRAP_1(Permute2, static inline)
|
||||
FLOAT_WRAP_1(Permute3, static inline)
|
||||
};
|
||||
};
|
||||
|
||||
struct Rotate{
|
||||
struct Rotate{
|
||||
|
||||
template<int n> static inline vector4double tRotate(vector4double v){
|
||||
if ( n==1 ) return vec_perm(v, v, vec_gpci(01230));
|
||||
@ -519,23 +520,23 @@ namespace Optimization {
|
||||
Vstore()(rd, r);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//Complex float Reduce
|
||||
template<>
|
||||
inline Grid::ComplexF
|
||||
Reduce<Grid::ComplexF, vector4float>::operator()(vector4float v) { //2 complex
|
||||
//Complex float Reduce
|
||||
template<>
|
||||
inline Grid::ComplexF
|
||||
Reduce<Grid::ComplexF, vector4float>::operator()(vector4float v) { //2 complex
|
||||
vector4float v1,v2;
|
||||
|
||||
v1 = Optimization::Permute::Permute0(v);
|
||||
v1 = Optimization::Sum()(v1, v);
|
||||
|
||||
return Grid::ComplexF(v1.v0, v1.v1);
|
||||
}
|
||||
//Real float Reduce
|
||||
template<>
|
||||
inline Grid::RealF
|
||||
Reduce<Grid::RealF, vector4float>::operator()(vector4float v){ //4 floats
|
||||
}
|
||||
//Real float Reduce
|
||||
template<>
|
||||
inline Grid::RealF
|
||||
Reduce<Grid::RealF, vector4float>::operator()(vector4float v){ //4 floats
|
||||
vector4float v1,v2;
|
||||
|
||||
v1 = Optimization::Permute::Permute0(v);
|
||||
@ -544,25 +545,25 @@ namespace Optimization {
|
||||
v1 = Optimization::Sum()(v1, v2);
|
||||
|
||||
return v1.v0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Complex double Reduce
|
||||
template<>
|
||||
inline Grid::ComplexD
|
||||
Reduce<Grid::ComplexD, vector4double>::operator()(vector4double v){ //2 complex
|
||||
//Complex double Reduce
|
||||
template<>
|
||||
inline Grid::ComplexD
|
||||
Reduce<Grid::ComplexD, vector4double>::operator()(vector4double v){ //2 complex
|
||||
vector4double v1;
|
||||
|
||||
v1 = Optimization::Permute::Permute0(v);
|
||||
v1 = vec_add(v1, v);
|
||||
|
||||
return Grid::ComplexD(vec_extract(v1, 0), vec_extract(v1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
//Real double Reduce
|
||||
template<>
|
||||
inline Grid::RealD
|
||||
Reduce<Grid::RealD, vector4double>::operator()(vector4double v){ //4 doubles
|
||||
//Real double Reduce
|
||||
template<>
|
||||
inline Grid::RealD
|
||||
Reduce<Grid::RealD, vector4double>::operator()(vector4double v){ //4 doubles
|
||||
vector4double v1,v2;
|
||||
|
||||
v1 = Optimization::Permute::Permute0(v);
|
||||
@ -571,20 +572,21 @@ namespace Optimization {
|
||||
v1 = vec_add(v1, v2);
|
||||
|
||||
return vec_extract(v1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//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;
|
||||
for (unsigned int i = 0; i < W<Integer>::r; ++i)
|
||||
{
|
||||
a += in.v[i];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
NAMESPACE_END(Optimization);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Here assign types
|
||||
typedef Optimization::vech SIMD_Htype; // Half precision type
|
||||
@ -596,7 +598,6 @@ typedef Optimization::veci SIMD_Itype; // Integer type
|
||||
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;
|
||||
@ -616,4 +617,4 @@ typedef Optimization::Conj ConjSIMD;
|
||||
typedef Optimization::TimesMinusI TimesMinusISIMD;
|
||||
typedef Optimization::TimesI TimesISIMD;
|
||||
|
||||
}
|
||||
NAMESPACE_END(Grid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user