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