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