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