LIBINT 2.9.0
intrinsic_operations.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint library.
5 *
6 * Libint library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser 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 * Libint library 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint library. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_include_libint2intrinsicoperations_h_
22#define _libint2_include_libint2intrinsicoperations_h_
23
24#include <libint2/config.h>
25
26#ifdef __cplusplus
27
28namespace libint2 {
29
31// using native FMA instructions, if available (see, e.g. vector_x86.h)
32
33#if defined(LIBINT_GENERATE_FMA)
34#if defined(LIBINT_HAS_CXX11)
36template <typename X, typename Y, typename Z>
37inline auto fma_plus(X x, Y y, Z z) -> decltype(x * y + z) {
38 return x * y + z;
39}
40
42template <typename X, typename Y, typename Z>
43inline auto fma_minus(X x, Y y, Z z) -> decltype(x * y - z) {
44 return x * y - z;
45}
46#else // LIBINT_HAS_CXX11
47#error "support for FMA requires compiler capable of C++11 or later"
48#endif // LIBINT_HAS_CXX11
49#endif // LIBINT_GENERATE_FMA
50
52
53}; // namespace libint2
54
59#define _libint2_static_api_bzero_short_(X, nelem) \
60 for (int i = 0; i < (nelem); ++i) { \
61 (X)[i] = 0.0; \
62 }
64#define _libint2_static_api_copy_short_(X, Y, nelem) \
65 for (int i = 0; i < (nelem); ++i) { \
66 (X)[i] = (Y)[i]; \
67 }
69#define _libint2_static_api_scale_short_(X, Y, nelem, a) \
70 for (int i = 0; i < (nelem); ++i) { \
71 (X)[i] = (a) * (Y)[i]; \
72 }
74#define _libint2_static_api_scale_vec_short_(X, Y, nelem, a, vl) \
75 for (int i = 0, iv = 0; i < (nelem) / (vl); ++i) { \
76 for (int v = 0; v < (vl); ++v, ++iv) { \
77 (X)[iv] = (a)[v] * (Y)[iv]; \
78 } \
79 }
81#if defined(LIBINT_GENERATE_FMA)
82#define _libint2_static_api_inc_short_(X, Y, nelem, a) \
83 for (int i = 0; i < (nelem); ++i) { \
84 (X)[i] = libint2::fma_plus((a), (Y)[i], (X)[i]); \
85 }
86#else
87#define _libint2_static_api_inc_short_(X, Y, nelem, a) \
88 for (int i = 0; i < (nelem); ++i) { \
89 (X)[i] += (a) * (Y)[i]; \
90 }
91#endif
93#define _libint2_static_api_inc1_short_(X, Y, nelem) \
94 for (int i = 0; i < (nelem); ++i) { \
95 (X)[i] += (Y)[i]; \
96 }
97
98#endif
99
100#endif
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
auto fma_plus(X x, Y y, Z z) -> decltype(x *y+z)
Definition intrinsic_operations.h:37
auto fma_minus(X x, Y y, Z z) -> decltype(x *y - z)
Definition intrinsic_operations.h:43