Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatrix5x2.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 DMatrix5x2{
8 public:
10  for (unsigned int i=0;i<5;i++){
11  for (unsigned int j=0;j<2;j++){
12  mA[i][j]=0.;
13  }
14  }
15  }
16  DMatrix5x2(double A1,double A2,double B1,double B2,double C1,double C2,
17  double D1,double D2,double E1,double E2){
18  mA[0][0]=A1;
19  mA[0][1]=A2;
20  mA[1][0]=B1;
21  mA[1][1]=B2;
22  mA[2][0]=C1;
23  mA[2][1]=C2;
24  mA[3][0]=D1;
25  mA[3][1]=D2;
26  mA[4][0]=E1;
27  mA[4][1]=E2;
28  }
30 
31  // Access by indices
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 
39  // Assignment operator
41  for (unsigned int i=0;i<5;i++){
42  mA[i][0]=m2(i,0);
43  mA[i][1]=m2(i,1);
44  }
45  return *this;
46  }
47 
48 
49 
50  // multiplication: (5x2) x (2x1)
52  return DMatrix5x1(mA[0][0]*m2(0)+mA[0][1]*m2(1),
53  mA[1][0]*m2(0)+mA[1][1]*m2(1),
54  mA[2][0]*m2(0)+mA[2][1]*m2(1),
55  mA[3][0]*m2(0)+mA[3][1]*m2(1),
56  mA[4][0]*m2(0)+mA[4][1]*m2(1));
57  }
58  // multiplication: (5x2) x (2x2)
60  return DMatrix5x2(mA[0][0]*m2(0,0)+mA[0][1]*m2(1,0),
61  mA[0][0]*m2(0,1)+mA[0][1]*m2(1,1),
62 
63  mA[1][0]*m2(0,0)+mA[1][1]*m2(1,0),
64  mA[1][0]*m2(0,1)+mA[1][1]*m2(1,1),
65 
66  mA[2][0]*m2(0,0)+mA[2][1]*m2(1,0),
67  mA[2][0]*m2(0,1)+mA[2][1]*m2(1,1),
68 
69  mA[3][0]*m2(0,0)+mA[3][1]*m2(1,0),
70  mA[3][0]*m2(0,1)+mA[3][1]*m2(1,1),
71 
72  mA[4][0]*m2(0,0)+mA[4][1]*m2(1,0),
73  mA[4][0]*m2(0,1)+mA[4][1]*m2(1,1)
74  );
75  }
76 
77  void Print(){
78  cout << "DMatrix5x2:" <<endl;
79  cout << " | 0 | 1 |" <<endl;
80  cout << "----------------------------------" <<endl;
81  for (unsigned int i=0;i<5;i++){
82  cout <<" "<<i<<" |"<< setw(11)<<setprecision(4) << mA[i][0]
83  << setw(11)<<setprecision(4) << mA[i][1]<< endl;
84  }
85  }
86 
87 private:
88  double mA[5][2];
89 };
90 
91 
92 #else
93 
94 // Matrix class with SIMD instructions
95 
96 class DMatrix5x2{
97  public:
98  DMatrix5x2()
99  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 2, mA) )
100  {
101  for (unsigned int j=0;j<3;j++){
102  mA[0].v[j]=_mm_setzero_pd();
103  mA[1].v[j]=_mm_setzero_pd();
104  }
105  }
106  DMatrix5x2(__m128d aa, __m128d ab,
107  __m128d ba, __m128d bb,
108  __m128d ca, __m128d cb)
109  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 2, mA) )
110  {
111  mA[0].v[0]=aa;
112  mA[0].v[1]=ba;
113  mA[0].v[2]=ca;
114  mA[1].v[0]=ab;
115  mA[1].v[1]=bb;
116  mA[1].v[2]=cb;
117  }
118  DMatrix5x2(const DMatrix5x2& dm)
119  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 2, mA) )
120  {
121  mA[0].v[0]=dm.mA[0].v[0];
122  mA[0].v[1]=dm.mA[0].v[1];
123  mA[0].v[2]=dm.mA[0].v[2];
124  mA[1].v[0]=dm.mA[1].v[0];
125  mA[1].v[1]=dm.mA[1].v[1];
126  mA[1].v[2]=dm.mA[1].v[2];
127  }
128  ~DMatrix5x2(){};
129 
130  __m128d GetV(int pair, int col) const{
131  return mA[col].v[pair];
132  }
133  void SetV(int pair, int col, __m128d v){
134  mA[col].v[pair]=v;
135  }
136 
137  // Assignment
138  DMatrix5x2& operator=(const DMatrix5x2& dm){
139  mA[0].v[0]=dm.mA[0].v[0];
140  mA[0].v[1]=dm.mA[0].v[1];
141  mA[0].v[2]=dm.mA[0].v[2];
142  mA[1].v[0]=dm.mA[1].v[0];
143  mA[1].v[1]=dm.mA[1].v[1];
144  mA[1].v[2]=dm.mA[1].v[2];
145  return *this;
146  }
147 
148  double &operator() (int row,int col){
149  return mA[col].d[row];
150  }
151  double operator() (int row,int col) const{
152  return mA[col].d[row];
153  }
154 
155  DMatrix5x1 operator*(const DMatrix2x1 &m2){
156  ALIGNED_16_BLOCK_WITH_PTR(__m128d, 2, p)
157  __m128d &a=p[0];
158  __m128d &b=p[1];
159  a=_mm_set1_pd(m2(0));
160  b=_mm_set1_pd(m2(1));
161  return DMatrix5x1(_mm_add_pd(_mm_mul_pd(GetV(0,0),a),
162  _mm_mul_pd(GetV(0,1),b)),
163  _mm_add_pd(_mm_mul_pd(GetV(1,0),a),
164  _mm_mul_pd(GetV(1,1),b)),
165  _mm_add_pd(_mm_mul_pd(GetV(2,0),a),
166  _mm_mul_pd(GetV(2,1),b)));
167  }
168 
169  DMatrix5x2 operator*(const DMatrix2x2 &m2){
170  ALIGNED_16_BLOCK_WITH_PTR(__m128d, 4, p)
171  __m128d &a11=p[0]; // row,col
172  __m128d &a12=p[1];
173  __m128d &a21=p[2];
174  __m128d &a22=p[3];
175  a11=_mm_set1_pd(m2(0,0));
176  a12=_mm_set1_pd(m2(0,1));
177  a21=_mm_set1_pd(m2(1,0));
178  a22=_mm_set1_pd(m2(1,1));
179  return DMatrix5x2(_mm_add_pd(_mm_mul_pd(GetV(0,0),a11),
180  _mm_mul_pd(GetV(0,1),a21)),
181  _mm_add_pd(_mm_mul_pd(GetV(0,0),a12),
182  _mm_mul_pd(GetV(0,1),a22)),
183  _mm_add_pd(_mm_mul_pd(GetV(1,0),a11),
184  _mm_mul_pd(GetV(1,1),a21)),
185  _mm_add_pd(_mm_mul_pd(GetV(1,0),a12),
186  _mm_mul_pd(GetV(1,1),a22)),
187  _mm_add_pd(_mm_mul_pd(GetV(2,0),a11),
188  _mm_mul_pd(GetV(2,1),a21)),
189  _mm_add_pd(_mm_mul_pd(GetV(2,0),a12),
190  _mm_mul_pd(GetV(2,1),a22)));
191 
192  }
193 
194 
195 
196 
197  void Print(){
198  cout << "DMatrix5x2:" <<endl;
199  cout << " | 0 | 1 |" <<endl;
200  cout << "----------------------------------" <<endl;
201  for (unsigned int i=0;i<5;i++){
202  cout <<" "<<i<<" |"<< setw(11)<<setprecision(4) << mA[0].d[i]
203  << setw(11)<<setprecision(4) << mA[1].d[i]<< endl;
204  }
205  }
206 
207  private:
208  union dvec{
209  __m128d v[3];
210  double d[6];
211  };
212  ALIGNED_16_BLOCK(union dvec, 2, mA)
213  };
214 #endif
static double E1[100]
double & operator()(int row, int col)
Definition: DMatrix5x2.h:32
#define ALIGNED_16_BLOCK_PTR(TYPE, NUM, PTR)
Definition: align_16.h:24
double mA[5][2]
Definition: DMatrix5x2.h:88
void Print()
Definition: DMatrix5x2.h:77
#define ALIGNED_16_BLOCK_WITH_PTR(TYPE, NUM, PTR)
Definition: align_16.h:27
DMatrix5x2 & operator=(const DMatrix5x2 &m2)
Definition: DMatrix5x2.h:40
DMatrix5x2(double A1, double A2, double B1, double B2, double C1, double C2, double D1, double D2, double E1, double E2)
Definition: DMatrix5x2.h:16
DMatrix5x1 operator*(const DMatrix2x1 &m2)
Definition: DMatrix5x2.h:51
DMatrix5x2 operator*(const DMatrix2x2 &m2)
Definition: DMatrix5x2.h:59
DMatrix5x2()
Definition: DMatrix5x2.h:9
#define ALIGNED_16_BLOCK(TYPE, NUM, PTR)
Definition: align_16.h:19