Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatrix2x1.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 DMatrix2x1{
8 public:
10  mA[0]=mA[1]=0.;
11  }
12  DMatrix2x1(double x, double y){
13  mA[0]=x;
14  mA[1]=y;
15  }
17 
18  // Set the two components of the matrix
19  void Set(double c1, double c2){
20  mA[0]=c1;
21  mA[1]=c2;
22  }
23  // Access by row
24  double &operator() (int row){
25  return mA[row];
26  }
27  double operator() (int row) const{
28  return mA[row];
29  }
30 
31  // Matrix subtraction
32  DMatrix2x1 operator-(const DMatrix2x1 &m2) const{
33  return DMatrix2x1(mA[0]-m2(0),mA[1]-m2(1));
34  }
35 
36  // Matrix addition
37  DMatrix2x1 operator+(const DMatrix2x1 &m2) const{
38  return DMatrix2x1(mA[0]+m2(0),mA[1]+m2(1));
39  }
40 
41  void Print(){
42  cout << "DMatrix2x1:" <<endl;
43  cout << " | 0 |" <<endl;
44  cout << "----------------------" <<endl;
45  for (unsigned int i=0;i<2;i++){
46  cout <<" "<<i<<" |" << setw(11)<<setprecision(4) << mA[i] << endl;
47  }
48  }
49 
50 
51 private:
52  double mA[2];
53 
54 };
55 
56 
57 // Scale 2x1 matrix by a floating point number
58 inline DMatrix2x1 operator*(const double c,const DMatrix2x1 &M){
59  return DMatrix2x1(c*M(0),c*M(1));
60 }
61 
62 
63 
64 
65 #else
66 
67 // Matrix class with SIMD instructions
68 
69 class DMatrix2x1{
70  public:
71  DMatrix2x1()
72  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
73  {
74  mA->v=_mm_setzero_pd();
75  };
76  DMatrix2x1(double x, double y)
77  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
78  {
79  mA->v=_mm_setr_pd(x,y);
80  }
81  DMatrix2x1(__m128d v)
82  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
83  {
84  mA->v=v;
85  }
86  DMatrix2x1(const DMatrix2x1& dm)
87  : mA( ALIGNED_16_BLOCK_PTR(union dvec, 1, mA) )
88  {
89  mA->v=dm.mA->v;
90  }
91  ~DMatrix2x1(){};
92 
93  __m128d GetV() const{
94  return mA->v;
95  }
96 
97  // Assignment
98  DMatrix2x1& operator=(const DMatrix2x1& dm){
99  mA->v=dm.mA->v;
100  return *this;
101  }
102 
103  // Set the two components of the matrix
104  void Set(double c1, double c2){
105  mA->v=_mm_setr_pd(c1,c2);
106  }
107 
108  // Access by row
109  double &operator() (int row){
110  return mA->d[row];
111  }
112  double operator() (int row) const{
113  return mA->d[row];
114  }
115 
116  // Matrix subtraction
117  DMatrix2x1 operator-(const DMatrix2x1 &m2) const{
118  return DMatrix2x1(_mm_sub_pd(GetV(),m2.GetV()));
119  }
120 
121  // Matrix addition
122  DMatrix2x1 operator+(const DMatrix2x1 &m2) const{
123  return DMatrix2x1(_mm_add_pd(GetV(),m2.GetV()));
124  }
125 
126  void Print(){
127  cout << "DMatrix2x1:" <<endl;
128  cout << " | 0 |" <<endl;
129  cout << "----------------------" <<endl;
130  for (unsigned int i=0;i<2;i++){
131  cout <<" "<<i<<" |" << setw(11)<<setprecision(4) << mA->d[i] << endl;
132  }
133  }
134 
135 
136 
137  private:
138  union dvec{
139  __m128d v;
140  double d[2];
141  };
142  ALIGNED_16_BLOCK(union dvec, 1, mA)
143 };
144 
145 // Scale 2x1 matrix by a floating point number
146 inline DMatrix2x1 operator*(double c, const DMatrix2x1 &M){
147  return DMatrix2x1(_mm_mul_pd(M.GetV(),_mm_set1_pd(c)));
148 }
149 #endif
void Set(double c1, double c2)
Definition: DMatrix2x1.h:19
double mA[2]
Definition: DMatrix2x1.h:52
void Print()
Definition: DMatrix2x1.h:41
DMatrix2x1 operator+(const DMatrix2x1 &m2) const
Definition: DMatrix2x1.h:37
DMatrix2x1 operator*(const double c, const DMatrix2x1 &M)
Definition: DMatrix2x1.h:58
#define ALIGNED_16_BLOCK_PTR(TYPE, NUM, PTR)
Definition: align_16.h:24
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define c
#define y
DMatrix2x1()
Definition: DMatrix2x1.h:9
DMatrix2x1 operator-(const DMatrix2x1 &m2) const
Definition: DMatrix2x1.h:32
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
Double_t c2[2][NMODULES]
Definition: tw_corr.C:69
double & operator()(int row)
Definition: DMatrix2x1.h:24
DMatrix2x1(double x, double y)
Definition: DMatrix2x1.h:12
#define ALIGNED_16_BLOCK(TYPE, NUM, PTR)
Definition: align_16.h:19