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