Clean up cmake build host detection
[gromacs.git] / src / gromacs / simd / impl_x86_avx2_256 / impl_x86_avx2_256_simd_double.h
blob21c4cf9f1b5f64e139b34d2a9231ec988a34c1ed
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 #ifndef GMX_SIMD_IMPL_X86_AVX2_256_SIMD_DOUBLE_H
37 #define GMX_SIMD_IMPL_X86_AVX2_256_SIMD_DOUBLE_H
39 #include "config.h"
41 #include <immintrin.h>
43 #include "gromacs/simd/impl_x86_avx_256/impl_x86_avx_256_simd_double.h"
45 namespace gmx
48 static inline SimdDouble gmx_simdcall
49 fma(SimdDouble a, SimdDouble b, SimdDouble c)
51 return {
52 _mm256_fmadd_pd(a.simdInternal_, b.simdInternal_, c.simdInternal_)
56 static inline SimdDouble gmx_simdcall
57 fms(SimdDouble a, SimdDouble b, SimdDouble c)
59 return {
60 _mm256_fmsub_pd(a.simdInternal_, b.simdInternal_, c.simdInternal_)
64 static inline SimdDouble gmx_simdcall
65 fnma(SimdDouble a, SimdDouble b, SimdDouble c)
67 return {
68 _mm256_fnmadd_pd(a.simdInternal_, b.simdInternal_, c.simdInternal_)
72 static inline SimdDouble gmx_simdcall
73 fnms(SimdDouble a, SimdDouble b, SimdDouble c)
75 return {
76 _mm256_fnmsub_pd(a.simdInternal_, b.simdInternal_, c.simdInternal_)
80 static inline SimdDBool gmx_simdcall
81 testBits(SimdDouble a)
83 __m256i ia = _mm256_castpd_si256(a.simdInternal_);
84 __m256i res = _mm256_andnot_si256( _mm256_cmpeq_epi64(ia, _mm256_setzero_si256()), _mm256_cmpeq_epi64(ia, ia));
86 return {
87 _mm256_castsi256_pd(res)
91 static inline SimdDouble
92 frexp(SimdDouble value, SimdDInt32 * exponent)
94 const __m256d exponentMask = _mm256_castsi256_pd(_mm256_set1_epi64x(0x7FF0000000000000LL));
95 const __m256d mantissaMask = _mm256_castsi256_pd( _mm256_set1_epi64x(0x800FFFFFFFFFFFFFLL));
96 const __m256i exponentBias = _mm256_set1_epi64x(1022LL); // add 1 to make our definition identical to frexp()
97 const __m256d half = _mm256_set1_pd(0.5);
98 __m256i iExponent;
99 __m128i iExponent128;
101 iExponent = _mm256_castpd_si256(_mm256_and_pd(value.simdInternal_, exponentMask));
102 iExponent = _mm256_sub_epi64(_mm256_srli_epi64(iExponent, 52), exponentBias);
103 iExponent = _mm256_shuffle_epi32(iExponent, _MM_SHUFFLE(3, 1, 2, 0));
105 iExponent128 = _mm256_extractf128_si256(iExponent, 1);
106 exponent->simdInternal_ = _mm_unpacklo_epi64(_mm256_castsi256_si128(iExponent), iExponent128);
108 return {
109 _mm256_or_pd(_mm256_and_pd(value.simdInternal_, mantissaMask), half)
113 static inline SimdDouble
114 ldexp(SimdDouble value, SimdDInt32 exponent)
116 const __m256i exponentBias = _mm256_set1_epi64x(1023LL);
117 __m256i iExponent = _mm256_cvtepi32_epi64(exponent.simdInternal_);
119 iExponent = _mm256_slli_epi64(_mm256_add_epi64(iExponent, exponentBias), 52);
120 return {
121 _mm256_mul_pd(value.simdInternal_, _mm256_castsi256_pd(iExponent))
125 } // namespace gmx
127 #endif // GMX_SIMD_IMPL_X86_AVX2_256_SIMD_DOUBLE_H