Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatrix2x5.h
Go to the documentation of this file.
1 #include <align_16.h>
2 
3 #ifndef USE_SSE2
4 
5 // Matrix class without SIMD instructions
6 
7 class DMatrix2x5{
8 public:
10  for (unsigned int i=0;i<2;i++){
11  for (unsigned int j=0;j<5;j++){
12  mA[i][j]=0.;
13  }
14  }
15  }
16  DMatrix2x5(double a1, double a2, double a3, double a4, double a5,
17  double b1, double b2, double b3, double b4, double b5){
18  mA[0][0]=a1;
19  mA[0][1]=a2;
20  mA[0][2]=a3;
21  mA[0][3]=a4;
22  mA[0][4]=a5;
23  mA[1][0]=b1;
24  mA[1][1]=b2;
25  mA[1][2]=b3;
26  mA[1][3]=b4;
27  mA[1][4]=b5;
28  }
29 
31 
32  double &operator() (int row, int col){
33  return mA[row][col];
34  }
35  double operator() (int row, int col) const{
36  return mA[row][col];
37  }
38  // Matrix multiplication: (2x5) x (5x2)
39 #define MUL5(i,j) mA[(i)][0]*m2(0,(j))+mA[(i)][1]*m2(1,(j))+mA[(i)][2]*m2(2,(j))+mA[(i)][3]*m2(3,(j))+mA[(i)][4]*m2(4,(j))
40 
41  DMatrix2x2 operator*(const DMatrix5x2 &m2) const{
42  return DMatrix2x2(MUL5(0,0),MUL5(0,1),MUL5(1,0),MUL5(1,1));
43  }
44 
45  // Matrix multiplication: (2x5) x (5x5)
46  DMatrix2x5 operator*(const DMatrix5x5 &m2) const{
47  return
48  DMatrix2x5(MUL5(0,0),MUL5(0,1),MUL5(0,2),MUL5(0,3),MUL5(0,4),
49  MUL5(1,0),MUL5(1,1),MUL5(1,2),MUL5(1,3),MUL5(1,4)
50  );
51  }
52 
53  void Print(){
54  cout << "DMatrix2x5:" <<endl;
55  cout << " | 0 | 1 | 2 | 3 | 4 |" <<endl;
56  cout << "-------------------------------------------------------------------" <<endl;
57  for (unsigned int i=0;i<2;i++){
58  cout <<" "<< i << " |";
59  for (unsigned int j=0;j<5;j++){
60  cout <<setw(11)<<setprecision(4)<< mA[i][j] <<" ";
61  }
62  cout << endl;
63  }
64  }
65 
66 private:
67  double mA[2][5];
68 
69 };
70 
71 #else
72 
73 // Matrix class with SIMD instructions
74 
75 class DMatrix2x5{
76  public:
77  DMatrix2x5()
78  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 5, mA) )
79  {
80  mA[0].v=_mm_setzero_pd();
81  mA[1].v=_mm_setzero_pd();
82  mA[2].v=_mm_setzero_pd();
83  mA[3].v=_mm_setzero_pd();
84  mA[4].v=_mm_setzero_pd();
85  }
86  DMatrix2x5(__m128d c1, __m128d c2, __m128d c3, __m128d c4, __m128d c5)
87  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 5, mA) )
88  {
89  mA[0].v=c1;
90  mA[1].v=c2;
91  mA[2].v=c3;
92  mA[3].v=c4;
93  mA[4].v=c5;
94  }
95  DMatrix2x5(const DMatrix2x5& dm)
96  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 5, mA) )
97  {
98  mA[0].v=dm.mA[0].v;
99  mA[1].v=dm.mA[1].v;
100  mA[2].v=dm.mA[2].v;
101  mA[3].v=dm.mA[3].v;
102  mA[4].v=dm.mA[4].v;
103  }
104  ~DMatrix2x5(){};
105 
106  __m128d GetV(const int col) const{
107  return mA[col].v;
108  }
109 
110  // Assignment
111  DMatrix2x5& operator=(const DMatrix2x5& dm){
112  mA[0].v=dm.mA[0].v;
113  mA[1].v=dm.mA[1].v;
114  mA[2].v=dm.mA[2].v;
115  mA[3].v=dm.mA[3].v;
116  mA[4].v=dm.mA[4].v;
117  return *this;
118  }
119 
120  double &operator() (int row, int col){
121  return mA[col].d[row];
122  }
123  double operator() (int row, int col) const{
124  return mA[col].d[row];
125  }
126 
127 // Preprocessor macro for multiplying two __m128d elements together
128 //#define MUL1(i,j) _mm_mul_pd(GetV((i)),_mm_set1_pd(m2((i),(j))))
129 
130  DMatrix2x2 operator*(const DMatrix5x2 &m2) const{
131  return DMatrix2x2(_mm_add_pd(MUL1(0,0),
132  _mm_add_pd(MUL1(1,0),
133  _mm_add_pd(MUL1(2,0),
134  _mm_add_pd(MUL1(3,0),MUL1(4,0))))),
135  _mm_add_pd(MUL1(0,1),
136  _mm_add_pd(MUL1(1,1),
137  _mm_add_pd(MUL1(2,1),
138  _mm_add_pd(MUL1(3,1),MUL1(4,1))))));
139 
140  }
141 
142  DMatrix2x5 operator*(const DMatrix5x5 &m2) const{
143  return
144  DMatrix2x5(_mm_add_pd(MUL1(0,0),
145  _mm_add_pd(MUL1(1,0),
146  _mm_add_pd(MUL1(2,0),
147  _mm_add_pd(MUL1(3,0),MUL1(4,0))))),
148  _mm_add_pd(MUL1(0,1),
149  _mm_add_pd(MUL1(1,1),
150  _mm_add_pd(MUL1(2,1),
151  _mm_add_pd(MUL1(3,1),MUL1(4,1))))),
152  _mm_add_pd(MUL1(0,2),
153  _mm_add_pd(MUL1(1,2),
154  _mm_add_pd(MUL1(2,2),
155  _mm_add_pd(MUL1(3,2),MUL1(4,2))))),
156  _mm_add_pd(MUL1(0,3),
157  _mm_add_pd(MUL1(1,3),
158  _mm_add_pd(MUL1(2,3),
159  _mm_add_pd(MUL1(3,3),MUL1(4,3))))),
160  _mm_add_pd(MUL1(0,4),
161  _mm_add_pd(MUL1(1,4),
162  _mm_add_pd(MUL1(2,4),
163  _mm_add_pd(MUL1(3,4),MUL1(4,4))))));
164  }
165 
166 
167 
168 
169  void Print(){
170  cout << "DMatrix2x5:" <<endl;
171  cout << " | 0 | 1 | 2 | 3 | 4 |" <<endl;
172  cout << "------------------------------------------------------------------" <<endl;
173 
174  for (unsigned int i=0;i<2;i++){
175  cout <<" "<< i << " |";
176  for (unsigned int j=0;j<5;j++){
177  cout << setw(11)<<setprecision(4) << mA[j].d[i] <<" ";
178  }
179  cout << endl;
180  }
181  }
182 
183  private:
184  union dvec{
185  __m128d v;
186  double d[2];
187  };
188  ALIGNED_16_BLOCK(union dvec, 5, mA)
189 };
190 #endif
191 
DMatrix2x5(double a1, double a2, double a3, double a4, double a5, double b1, double b2, double b3, double b4, double b5)
Definition: DMatrix2x5.h:16
#define ALIGNED_16_BLOCK_PTR(TYPE, NUM, PTR)
Definition: align_16.h:24
DMatrix2x5()
Definition: DMatrix2x5.h:9
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
double & operator()(int row, int col)
Definition: DMatrix2x5.h:32
Double_t c2[2][NMODULES]
Definition: tw_corr.C:69
double mA[2][5]
Definition: DMatrix2x5.h:67
void Print()
Definition: DMatrix2x5.h:53
DMatrix2x5 operator*(const DMatrix5x5 &m2) const
Definition: DMatrix2x5.h:46
TCanvas * c4
#define MUL5(i, j)
Definition: DMatrix2x5.h:39
#define ALIGNED_16_BLOCK(TYPE, NUM, PTR)
Definition: align_16.h:19
TCanvas * c3
DMatrix2x2 operator*(const DMatrix5x2 &m2) const
Definition: DMatrix2x5.h:41