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