FairRoot/PandaRoot
PSEUDO_F32vec4.h
Go to the documentation of this file.
1 #ifndef L1Algo_PSEUDO_F32vec4_H
2 #define L1Algo_PSEUDO_F32vec4_H
3 
4 #include <iostream>
5 #include <cmath>
6 #include "vec_arithmetic.h"
7 
8 /**********************************
9  *
10  * Vector of four floats
11  *
12  **********************************/
13 
14 
15 
16 float min( float x, float y );
17 float max( float x, float y );
18 float asgnb( float x, float y );
19 float rsqrt( float x );
20 float rcp( float x );
21 float sgn( float x );
22 
23 class F32vec4
24 {
25 
26 
27  public:
28 
29  float v[4];
30 
31  float & operator[]( int i ){ return ((float*)&v)[i]; }
32  float operator[]( int i ) const { return ((float*)&v)[i]; }
33 
34  F32vec4( ){}
35  F32vec4( const F32vec4 &a ) {
36  v[0] = a.v[0];
37  v[1] = a.v[1];
38  v[2] = a.v[2];
39  v[3] = a.v[3];
40  }
41  F32vec4( const float &a ) {
42  v[0] = a;
43  v[1] = a;
44  v[2] = a;
45  v[3] = a;
46  }
47 
48  F32vec4( const float &f0, const float &f1, const float &f2, const float &f3 ){
49  v[0] = f0;
50  v[1] = f1;
51  v[2] = f2;
52  v[3] = f3;
53  }
54 
55 
56 #define _f2(A,B,F) F32vec4 z; z.v[0] = F(A.v[0],B.v[0]); z.v[1] = F(A.v[1],B.v[1]); \
57  z.v[2] = F(A.v[2],B.v[2]); z.v[3] = F(A.v[3],B.v[3]); return z;
58 #define _f1(A,F) F32vec4 z; z.v[0] = F(A.v[0]); z.v[1] = F(A.v[1]); \
59  z.v[2] = F(A.v[2]); z.v[3] = F(A.v[3]); return z;
60 #define _op(A,B,O) F32vec4 z; z.v[0] = A.v[0] O B.v[0]; z.v[1] = A.v[1] O B.v[1]; \
61  z.v[2] = A.v[2] O B.v[2]; z.v[3] = A.v[3] O B.v[3]; return z;
62 
63  /* Arithmetic Operators */
64  friend F32vec4 operator +(const F32vec4 &a, const F32vec4 &b){ _op(a,b,+) }
65  friend F32vec4 operator -(const F32vec4 &a, const F32vec4 &b){ _op(a,b,-) }
66  friend F32vec4 operator *(const F32vec4 &a, const F32vec4 &b){ _op(a,b,*) }
67  friend F32vec4 operator /(const F32vec4 &a, const F32vec4 &b){ _op(a,b,/) }
68 
69  /* Comparison */
70  friend F32vec4 operator <(const F32vec4 &a, const F32vec4 &b){ _op(a,b,<) }
71  friend F32vec4 operator <=(const F32vec4 &a, const F32vec4 &b){ _op(a,b,<=) }
72  friend F32vec4 operator >(const F32vec4 &a, const F32vec4 &b){ _op(a,b,>) }
73  friend F32vec4 operator >=(const F32vec4 &a, const F32vec4 &b){ _op(a,b,>=) }
74 
75  /* Logic */
76  friend F32vec4 operator &(const F32vec4 &a, const F32vec4 &b){ _op(a,b,&&) }
77  friend F32vec4 operator |(const F32vec4 &a, const F32vec4 &b){ _op(a,b,||) }
78  friend F32vec4 operator ||(const F32vec4 &a, const F32vec4 &b){ _op(a,b,||) }
79 
80  friend F32vec4 operator !(const F32vec4 &a) {
81  F32vec4 z;
82  z[0] = !a[0];
83  z[1] = !a[1];
84  z[2] = !a[2];
85  z[3] = !a[3];
86 
87  return z;
88  }
89 
90  friend F32vec4 if3(const F32vec4 &a, const F32vec4 &b, const F32vec4 &c) {
91  F32vec4 z;
92  z[0] = (a[0]) ? b[0] : c[0];
93  z[1] = (a[1]) ? b[1] : c[1];
94  z[2] = (a[2]) ? b[2] : c[2];
95  z[3] = (a[3]) ? b[3] : c[3];
96 
97  return z;
98  }
99 
100 #define NotEmpty(a) bool((a)[0])|bool((a)[1])|bool((a)[2])|bool((a)[3])
101 #define Empty(a) !(bool((a)[0])|bool((a)[1])|bool((a)[2])|bool((a)[3]))
102  // bool NotEmpty(const F32vec4 &a) { return a[0]||a[1]||a[2]||a[3]; }
103  // bool Empty(const F32vec4 &a) { return !(a[0]||a[1]||a[2]||a[3]); } // optimize
104  friend F32vec4 bool2int( const F32vec4 &a){ // mask returned
105  return if3(a,1,0);
106  }
107 
108 
109 
110  /* Functions */
111  friend float min( float x, float y ){ return x<y ?x :y; }
112  friend float max( float x, float y ){ return x<y ?y :x; }
113  friend float asgnb( float x, float y ){ return y>=0 ?fabs(x) :-fabs(x); }
114  friend float rsqrt( float x ){ return 1./sqrt(x); }
115  friend float rcp( float x ){ return 1./x; }
116  friend float sgn( float x ){ return x>=0 ?1 :-1; }
117 
118  friend F32vec4 min( const F32vec4 &a, const F32vec4 &b ){ _f2(a,b,min) }
119  friend F32vec4 max( const F32vec4 &a, const F32vec4 &b ){ _f2(a,b,max) }
120  friend F32vec4 asgnb( const F32vec4 &a, const F32vec4 &b ){ _f2(a,b,asgnb) }
121  friend F32vec4 sqrt ( const F32vec4 &a ){ _f1(a,sqrt) }
122  friend F32vec4 rsqrt( const F32vec4 &a ){ _f1(a,rsqrt) }
123  friend F32vec4 rcp ( const F32vec4 &a ){ _f1(a,rcp) }
124  friend F32vec4 fabs ( const F32vec4 &a ) { _f1(a,fabs) }
125  friend F32vec4 sgn ( const F32vec4 &a ){ _f1(a,sgn) }
126  friend F32vec4 exp( const F32vec4 &a ){ _f1(a,exp) }
127  friend F32vec4 log( const F32vec4 &a ){ _f1(a,log) }
128  friend F32vec4 sin( const F32vec4 &a ){ _f1(a,sin) }
129  friend F32vec4 cos( const F32vec4 &a ){ _f1(a,cos) }
130 #undef _f1
131 #undef _f2
132 #undef _op
133 
134  /* Define all operators for consistensy */
135 
136  vec_arithmetic(F32vec4,float);
137 
138  friend ostream & operator<<(ostream &strm, const F32vec4 &a ){
139  strm<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3];
140  return strm;
141  }
142 
143  friend istream & operator>>(istream &strm, F32vec4 &a ){
144  float tmp;
145  strm>>tmp;
146  a = tmp;
147  return strm;
148  }
149 
150 } __attribute__ ((aligned(16)));;
151 
152 typedef F32vec4 fvec;
153 typedef float fscal;
154 const int fvecLen = 4;
155 //#define fvec_true _f32vec4_true
156 //#define fvec_false _f32vec4_false
157 #define _fvecalignment
158 
159 namespace nsL1
160 {
161  template<typename T>
162  struct vector
163  {
164  typedef std::vector<T> TStd;
165  typedef std::vector<T> TSimd;
166  };
167 
169 }; // namespace nsL1
170 
171 template<typename T>
172 struct nsL1vector: public nsL1::vector<T> // just for use std::vector simultaniosly
173 {
174 };
175 
176 #endif
friend F32vec4 operator!(const F32vec4 &a)
Definition: P4_F32vec4.h:110
friend F32vec4 log(const F32vec4 &a)
Int_t i
Definition: run_full.C:25
TTree * b
#define _op(A, B, O)
F32vec4(const float &a)
TF1 * f1
Definition: reco_analys2.C:50
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:70
friend F32vec4 rsqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:76
F32vec4(const float &f0, const float &f1, const float &f2, const float &f3)
nsL1::vector< fvec >::TSimd vector_fvec
#define _f2(A, B, F)
friend F32vec4 operator&(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:101
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
friend F32vec4 asgnb(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:51
vec_arithmetic(F32vec4, float)
friend F32vec4 operator>(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:125
friend F32vec4 operator+(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:63
T rcp(T val)
Definition: PndFTSCADef.h:52
friend F32vec4 exp(const F32vec4 &a)
Definition: P4_F32vec4.h:153
friend F32vec4 operator||(const F32vec4 &a, const F32vec4 &b)
Int_t a
Definition: anaLmdDigi.C:126
friend F32vec4 rcp(const F32vec4 &a)
Definition: P4_F32vec4.h:84
std::vector< T > TSimd
friend F32vec4 operator/(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:66
TFile * f3
friend F32vec4 asgnb(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:95
friend F32vec4 operator|(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:104
basic_ostream< char, char_traits< char > > ostream
friend F32vec4 sgn(const F32vec4 &a)
Definition: P4_F32vec4.h:50
friend F32vec4 if3(const F32vec4 &a, const F32vec4 &b, const F32vec4 &c)
friend F32vec4 rsqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:32
friend F32vec4 operator<(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:119
friend F32vec4 bool2int(const F32vec4 &a)
F32vec4 fvec
Definition: P4_F32vec4.h:218
Double_t z
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
friend F32vec4 cos(const F32vec4 &a)
friend F32vec4 operator<=(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:122
basic_istream< char, char_traits< char > > istream
float & operator[](int i)
Definition: P4_F32vec4.h:50
nsL1vector __attribute__
#define _f1(A, F)
const int fvecLen
Definition: P4_F32vec4.h:220
Double_t x
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:91
TFile * f2
friend F32vec4 operator-(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:64
friend F32vec4 sgn(const F32vec4 &a)
Definition: P4_F32vec4.h:94
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:69
Double_t y
friend F32vec4 operator>=(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:128
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:73
friend ostream & operator<<(ostream &strm, const F32vec4 &a)
float fscal
Definition: P4_F32vec4.h:219
friend F32vec4 operator*(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:65
friend F32vec4 sin(const F32vec4 &a)
std::vector< T > TStd
friend istream & operator>>(istream &strm, F32vec4 &a)
__m128 v
Definition: P4_F32vec4.h:48
F32vec4(const F32vec4 &a)