ergo
vector_intrin.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 /*
28  * Templates for efficient gemm kernels.
29  * For architectures with SSE2 or higher.
30  *
31  * Copyright Emanuel Rubensson, 2009
32  *
33  *
34  *
35  *
36  */
37 
38 #ifndef VECTOR_INTRIN
39 #define VECTOR_INTRIN
40 #include "common.h"
41 #include "g_intrin.h"
42 
48 template<typename Treal, typename Treg>
49  class Vector_intrin {
50  public:
51  inline void ALWAYS_INLINE load_p(Treal const * ptr) {
52  values = _mm_load_p(ptr);
53  }
54  inline void ALWAYS_INLINE load1_p(Treal const * ptr) {
55  values = _mm_load1_p(ptr);
56  }
57  inline void ALWAYS_INLINE store_p(Treal * ptr) const {
58  _mm_store_p ( ptr, values );
59  }
61  values = _mm_mul_p ( other.values, values );
62  return *this;
63  }
65  values = _mm_add_p ( other.values, values );
66  return *this;
67  }
68  inline Vector_intrin<Treal, Treg>& ALWAYS_INLINE operator+= ( Treal const * ptr ) {
69  Treg tmp;
70  tmp = _mm_load_p(ptr);
71  values = _mm_add_p ( tmp, values );
72  return *this;
73  }
74 #if 0
75  inline void ALWAYS_INLINE xor_p( Vector_intrin<Treal, Treg> const & other ) {
76  values = _mm_xor_p ( other.values, values );
77  }
78 #endif
79  inline void ALWAYS_INLINE set_to_zero() {
81  }
82  protected:
83  Treg values;
84  private:
85 };
86 
87 template<typename Treal>
88 class Vector_intrin<Treal, Treal> {
89  public:
90  inline void ALWAYS_INLINE load_p(Treal const * ptr) {
91  values = *ptr;
92  }
93  inline void ALWAYS_INLINE load1_p(Treal const * ptr) {
94  values = *ptr;
95  }
96  inline void ALWAYS_INLINE store_p(Treal * ptr) const {
97  *ptr = values;
98  }
100  values *= other.values;
101  return *this;
102  }
104  values += other.values;
105  return *this;
106  }
108  values += *ptr;
109  return *this;
110  }
111 #if 0
112  inline void ALWAYS_INLINE xor_p( Vector_intrin<Treal, Treg> const & other ) {
113  values = _mm_xor_p ( other.values, values );
114  }
115 #endif
116  inline void ALWAYS_INLINE set_to_zero() {
117  values = 0;
118  }
119  protected:
120  Treal values;
121  private:
122 };
123 
124 
125 
126 
127 
128 
129 #if 0
130 template<>
131 class Vector_intrin<double, double> {
132  public:
133  inline void ALWAYS_INLINE load_p(double const * ptr) {
134  values[0] = *ptr;
135  values[1] = ptr[1];
136  }
137  inline void ALWAYS_INLINE load1_p(double const * ptr) {
138  values[0] = *ptr;
139  values[1] = *ptr;
140  }
141  inline void ALWAYS_INLINE store_p(double * ptr) const {
142  ptr[0] = values[0];
143  ptr[1] = values[1];
144  }
146  values[0] *= other.values[0];
147  values[1] *= other.values[1];
148  }
150  values[0] += other.values[0];
151  values[1] += other.values[1];
152  }
153  inline Vector_intrin<double, double>& ALWAYS_INLINE operator+= ( double const * ptr ) {
154  values[0] += *ptr;
155  values[1] += ptr[1];
156  }
157 #if 0
158  inline void ALWAYS_INLINE xor_p( Vector_intrin<double, Treg> const & other ) {
159  values = _mm_xor_p ( other.values, values );
160  }
161 #endif
162  inline void ALWAYS_INLINE set_to_zero() {
163  values[0] = 0;
164  values[1] = 0;
165  }
166  protected:
167  double values[2];
168  private:
169 };
170 #endif
171 
172 #endif // VECTOR_INTRIN
Treal values
Definition: vector_intrin.h:120
void ALWAYS_INLINE load1_p(Treal const *ptr)
Definition: vector_intrin.h:54
static void _mm_store_p(Treal *ptr, Treg A)
Vector_intrin< Treal, Treg > &ALWAYS_INLINE operator+=(Vector_intrin< Treal, Treg > const &other)
Definition: vector_intrin.h:64
Definition: vector_intrin.h:88
void ALWAYS_INLINE set_to_zero()
Definition: vector_intrin.h:79
static Treg _mm_add_p(Treg A, Treg B)
void ALWAYS_INLINE load_p(Treal const *ptr)
Definition: vector_intrin.h:90
#define ALWAYS_INLINE
Definition: common.h:31
void ALWAYS_INLINE store_p(Treal *ptr) const
Definition: vector_intrin.h:57
void ALWAYS_INLINE load1_p(Treal const *ptr)
Definition: vector_intrin.h:93
void ALWAYS_INLINE store_p(Treal *ptr) const
Definition: vector_intrin.h:96
Vector_intrin< Treal, Treg > &ALWAYS_INLINE operator*=(Vector_intrin< Treal, Treg > const &other)
Definition: vector_intrin.h:60
static Treg _mm_xor_p(Treg A, Treg B)
static Treg _mm_load1_p(Treal const *ptr)
static Treg _mm_mul_p(Treg A, Treg B)
void ALWAYS_INLINE set_to_zero()
Definition: vector_intrin.h:116
Treg values
Definition: vector_intrin.h:83
static Treg _mm_load_p(Treal const *ptr)
void ALWAYS_INLINE load_p(Treal const *ptr)
Definition: vector_intrin.h:51
Vector class template for access to SIMD operations.
Definition: vector_intrin.h:49