2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015,2017,2019, 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_SSE4_1_SIMD_DOUBLE_H
37 #define GMX_SIMD_IMPL_X86_SSE4_1_SIMD_DOUBLE_H
41 #include <smmintrin.h>
43 #include "gromacs/simd/impl_x86_sse2/impl_x86_sse2_simd_double.h"
49 static inline std::int32_t gmx_simdcall extract(SimdDInt32 a)
51 return _mm_extract_epi32(a.simdInternal_, index);
54 static inline SimdDouble maskzRsqrt(SimdDouble x, SimdDBool m)
57 x.simdInternal_ = _mm_blendv_pd(_mm_set1_pd(1.0), x.simdInternal_, m.simdInternal_);
59 return { _mm_and_pd(_mm_cvtps_pd(_mm_rsqrt_ps(_mm_cvtpd_ps(x.simdInternal_))), m.simdInternal_) };
62 static inline SimdDouble maskzRcp(SimdDouble x, SimdDBool m)
65 x.simdInternal_ = _mm_blendv_pd(_mm_set1_pd(1.0), x.simdInternal_, m.simdInternal_);
67 return { _mm_and_pd(_mm_cvtps_pd(_mm_rcp_ps(_mm_cvtpd_ps(x.simdInternal_))), m.simdInternal_) };
70 static inline SimdDouble gmx_simdcall round(SimdDouble x)
72 return { _mm_round_pd(x.simdInternal_, _MM_FROUND_NINT) };
75 static inline SimdDouble gmx_simdcall trunc(SimdDouble x)
77 return { _mm_round_pd(x.simdInternal_, _MM_FROUND_TRUNC) };
80 static inline SimdDBool gmx_simdcall testBits(SimdDouble a)
82 __m128i ia = _mm_castpd_si128(a.simdInternal_);
83 __m128i res = _mm_andnot_si128(_mm_cmpeq_epi64(ia, _mm_setzero_si128()), _mm_cmpeq_epi64(ia, ia));
85 return { _mm_castsi128_pd(res) };
88 static inline SimdDouble gmx_simdcall blend(SimdDouble a, SimdDouble b, SimdDBool sel)
90 return { _mm_blendv_pd(a.simdInternal_, b.simdInternal_, sel.simdInternal_) };
93 static inline SimdDInt32 gmx_simdcall operator*(SimdDInt32 a, SimdDInt32 b)
95 return { _mm_mullo_epi32(a.simdInternal_, b.simdInternal_) };
98 static inline SimdDInt32 gmx_simdcall blend(SimdDInt32 a, SimdDInt32 b, SimdDIBool sel)
100 return { _mm_blendv_epi8(a.simdInternal_, b.simdInternal_, sel.simdInternal_) };
103 template<MathOptimization opt = MathOptimization::Safe>
104 static inline SimdDouble ldexp(SimdDouble value, SimdDInt32 exponent)
106 const __m128i exponentBias = _mm_set1_epi32(1023);
107 __m128i iExponent = _mm_add_epi32(exponent.simdInternal_, exponentBias);
109 if (opt == MathOptimization::Safe)
111 // Make sure biased argument is not negative
112 iExponent = _mm_max_epi32(iExponent, _mm_setzero_si128());
115 // After conversion integers will be in slot 0,1. Move them to 0,2 so
116 // we can do a 64-bit shift and get them to the dp exponents.
117 iExponent = _mm_shuffle_epi32(iExponent, _MM_SHUFFLE(3, 1, 2, 0));
118 iExponent = _mm_slli_epi64(iExponent, 52);
120 return { _mm_mul_pd(value.simdInternal_, _mm_castsi128_pd(iExponent)) };
125 #endif // GMX_SIMD_IMPL_X86_SSE4_1_SIMD_DOUBLE_H