ergo
vector_intrin.h
Go to the documentation of this file.
1/* Ergo, version 3.8.2, a program for linear scaling electronic structure
2 * calculations.
3 * Copyright (C) 2023 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4 * and Anastasia Kruchinina.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Primary academic reference:
20 * Ergo: An open-source program for linear-scaling electronic structure
21 * calculations,
22 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23 * Kruchinina,
24 * SoftwareX 7, 107 (2018),
25 * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26 *
27 * For further information about Ergo, see <http://www.ergoscf.org>.
28 */
29
38/*
39 * Templates for efficient gemm kernels.
40 * For architectures with SSE2 or higher.
41 *
42 * Copyright Emanuel Rubensson, 2009
43 *
44 *
45 *
46 *
47 */
48
49#ifndef VECTOR_INTRIN
50#define VECTOR_INTRIN
51#include "common.h"
52#include "g_intrin.h"
53
59template<typename Treal, typename Treg>
61 public:
62 inline void ALWAYS_INLINE load_p(Treal const * ptr) {
63 values = _mm_load_p(ptr);
64 }
65 inline void ALWAYS_INLINE load1_p(Treal const * ptr) {
66 values = _mm_load1_p(ptr);
67 }
68 inline void ALWAYS_INLINE store_p(Treal * ptr) const {
69 _mm_store_p ( ptr, values );
70 }
72 values = _mm_mul_p ( other.values, values );
73 return *this;
74 }
76 values = _mm_add_p ( other.values, values );
77 return *this;
78 }
80 Treg tmp;
81 tmp = _mm_load_p(ptr);
82 values = _mm_add_p ( tmp, values );
83 return *this;
84 }
85#if 0
86 inline void ALWAYS_INLINE xor_p( Vector_intrin<Treal, Treg> const & other ) {
87 values = _mm_xor_p ( other.values, values );
88 }
89#endif
90 inline void ALWAYS_INLINE set_to_zero() {
92 }
93 protected:
94 Treg values;
95 private:
96};
97
98template<typename Treal>
99class Vector_intrin<Treal, Treal> {
100 public:
101 inline void ALWAYS_INLINE load_p(Treal const * ptr) {
102 values = *ptr;
103 }
104 inline void ALWAYS_INLINE load1_p(Treal const * ptr) {
105 values = *ptr;
106 }
107 inline void ALWAYS_INLINE store_p(Treal * ptr) const {
108 *ptr = values;
109 }
111 values *= other.values;
112 return *this;
113 }
115 values += other.values;
116 return *this;
117 }
119 values += *ptr;
120 return *this;
121 }
122#if 0
123 inline void ALWAYS_INLINE xor_p( Vector_intrin<Treal, Treg> const & other ) {
124 values = _mm_xor_p ( other.values, values );
125 }
126#endif
128 values = 0;
129 }
130 protected:
131 Treal values;
132 private:
133};
134
135
136
137
138
139
140#if 0
141template<>
142class Vector_intrin<double, double> {
143 public:
144 inline void ALWAYS_INLINE load_p(double const * ptr) {
145 values[0] = *ptr;
146 values[1] = ptr[1];
147 }
148 inline void ALWAYS_INLINE load1_p(double const * ptr) {
149 values[0] = *ptr;
150 values[1] = *ptr;
151 }
152 inline void ALWAYS_INLINE store_p(double * ptr) const {
153 ptr[0] = values[0];
154 ptr[1] = values[1];
155 }
156 inline Vector_intrin<double, double>& ALWAYS_INLINE operator*= ( Vector_intrin<double, double> const & other ) {
157 values[0] *= other.values[0];
158 values[1] *= other.values[1];
159 }
160 inline Vector_intrin<double, double>& ALWAYS_INLINE operator+= ( Vector_intrin<double, double> const & other ) {
161 values[0] += other.values[0];
162 values[1] += other.values[1];
163 }
164 inline Vector_intrin<double, double>& ALWAYS_INLINE operator+= ( double const * ptr ) {
165 values[0] += *ptr;
166 values[1] += ptr[1];
167 }
168#if 0
169 inline void ALWAYS_INLINE xor_p( Vector_intrin<double, Treg> const & other ) {
170 values = _mm_xor_p ( other.values, values );
171 }
172#endif
173 inline void ALWAYS_INLINE set_to_zero() {
174 values[0] = 0;
175 values[1] = 0;
176 }
177 protected:
178 double values[2];
179 private:
180};
181#endif
182
183#endif // VECTOR_INTRIN
Treal values
Definition vector_intrin.h:131
void ALWAYS_INLINE load1_p(Treal const *ptr)
Definition vector_intrin.h:104
void ALWAYS_INLINE load_p(Treal const *ptr)
Definition vector_intrin.h:101
void ALWAYS_INLINE set_to_zero()
Definition vector_intrin.h:127
void ALWAYS_INLINE store_p(Treal *ptr) const
Definition vector_intrin.h:107
Vector class template for access to SIMD operations.
Definition vector_intrin.h:60
Vector_intrin< Treal, Treg > &ALWAYS_INLINE operator+=(Vector_intrin< Treal, Treg > const &other)
Definition vector_intrin.h:75
void ALWAYS_INLINE load1_p(Treal const *ptr)
Definition vector_intrin.h:65
void ALWAYS_INLINE load_p(Treal const *ptr)
Definition vector_intrin.h:62
void ALWAYS_INLINE store_p(Treal *ptr) const
Definition vector_intrin.h:68
Treg values
Definition vector_intrin.h:94
void ALWAYS_INLINE set_to_zero()
Definition vector_intrin.h:90
Vector_intrin< Treal, Treg > &ALWAYS_INLINE operator*=(Vector_intrin< Treal, Treg > const &other)
Definition vector_intrin.h:71
Macros for inlining and static assertions and structs for access to matrix elements specifying the la...
#define ALWAYS_INLINE
Definition common.h:45
Templates for convenient access to intrinsic instructions.
static Treg _mm_load1_p(Treal const *ptr)
static void _mm_store_p(Treal *ptr, Treg A)
static Treg _mm_load_p(Treal const *ptr)
static Treg _mm_xor_p(Treg A, Treg B)
static Treg _mm_add_p(Treg A, Treg B)
static Treg _mm_mul_p(Treg A, Treg B)