2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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.
35 #ifndef _kernelutil_x86_avx_128_fma_single_h_
36 #define _kernelutil_x86_avx_128_fma_single_h_
40 #include <immintrin.h>
44 # include <x86intrin.h>
47 #define gmx_mm_castsi128_ps _mm_castsi128_ps
48 #define gmx_mm_extract_epi32 _mm_extract_epi32
50 /* Work around gcc bug with wrong type for mask formal parameter to maskload/maskstore */
51 #ifdef GMX_SIMD_X86_AVX_GCC_MASKLOAD_BUG
52 # define gmx_mm_maskload_ps(mem, mask) _mm_maskload_ps((mem), _mm_castsi128_ps(mask))
53 # define gmx_mm_maskstore_ps(mem, mask, x) _mm_maskstore_ps((mem), _mm_castsi128_ps(mask), (x))
54 # define gmx_mm256_maskload_ps(mem, mask) _mm256_maskload_ps((mem), _mm256_castsi256_ps(mask))
55 # define gmx_mm256_maskstore_ps(mem, mask, x) _mm256_maskstore_ps((mem), _mm256_castsi256_ps(mask), (x))
57 # define gmx_mm_maskload_ps(mem, mask) _mm_maskload_ps((mem), (mask))
58 # define gmx_mm_maskstore_ps(mem, mask, x) _mm_maskstore_ps((mem), (mask), (x))
59 # define gmx_mm256_maskload_ps(mem, mask) _mm256_maskload_ps((mem), (mask))
60 # define gmx_mm256_maskstore_ps(mem, mask, x) _mm256_maskstore_ps((mem), (mask), (x))
63 /* Normal sum of four xmm registers */
64 #define gmx_mm_sum4_ps(t0, t1, t2, t3) _mm_add_ps(_mm_add_ps(t0, t1), _mm_add_ps(t2, t3))
66 static gmx_inline int gmx_simdcall
67 gmx_mm_any_lt(__m128 a, __m128 b)
69 return _mm_movemask_ps(_mm_cmplt_ps(a, b));
72 static gmx_inline __m128 gmx_simdcall
73 gmx_mm_calc_rsq_ps(__m128 dx, __m128 dy, __m128 dz)
75 return _mm_macc_ps(dx, dx, _mm_macc_ps(dy, dy, _mm_mul_ps(dz, dz)));
78 /* Load a single value from 1-4 places, merge into xmm register */
80 static gmx_inline __m128 gmx_simdcall
81 gmx_mm_load_4real_swizzle_ps(const float * gmx_restrict ptrA,
82 const float * gmx_restrict ptrB,
83 const float * gmx_restrict ptrC,
84 const float * gmx_restrict ptrD)
88 t1 = _mm_unpacklo_ps(_mm_load_ss(ptrA), _mm_load_ss(ptrC));
89 t2 = _mm_unpacklo_ps(_mm_load_ss(ptrB), _mm_load_ss(ptrD));
90 return _mm_unpacklo_ps(t1, t2);
94 static gmx_inline void gmx_simdcall
95 gmx_mm_store_4real_swizzle_ps(float * gmx_restrict ptrA,
96 float * gmx_restrict ptrB,
97 float * gmx_restrict ptrC,
98 float * gmx_restrict ptrD, __m128 xmm1)
102 t2 = _mm_permute_ps(xmm1, _MM_SHUFFLE(1, 1, 1, 1));
103 t3 = _mm_permute_ps(xmm1, _MM_SHUFFLE(2, 2, 2, 2));
104 t4 = _mm_permute_ps(xmm1, _MM_SHUFFLE(3, 3, 3, 3));
105 _mm_store_ss(ptrA, xmm1);
106 _mm_store_ss(ptrB, t2);
107 _mm_store_ss(ptrC, t3);
108 _mm_store_ss(ptrD, t4);
112 static gmx_inline void gmx_simdcall
113 gmx_mm_increment_4real_swizzle_ps(float * gmx_restrict ptrA,
114 float * gmx_restrict ptrB,
115 float * gmx_restrict ptrC,
116 float * gmx_restrict ptrD, __m128 xmm1)
120 tmp = gmx_mm_load_4real_swizzle_ps(ptrA, ptrB, ptrC, ptrD);
121 tmp = _mm_add_ps(tmp, xmm1);
122 gmx_mm_store_4real_swizzle_ps(ptrA, ptrB, ptrC, ptrD, tmp);
126 static gmx_inline void gmx_simdcall
127 gmx_mm_load_4pair_swizzle_ps(const float * gmx_restrict p1,
128 const float * gmx_restrict p2,
129 const float * gmx_restrict p3,
130 const float * gmx_restrict p4,
131 __m128 * gmx_restrict c6, __m128 * gmx_restrict c12)
133 __m128 t1, t2, t3, t4;
134 t1 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)p1);
135 t2 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)p2);
136 t3 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)p3);
137 t4 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)p4);
138 t1 = _mm_unpacklo_ps(t1, t3);
139 t2 = _mm_unpacklo_ps(t2, t4);
140 *c6 = _mm_unpacklo_ps(t1, t2);
141 *c12 = _mm_unpackhi_ps(t1, t2);
147 static gmx_inline void gmx_simdcall
148 gmx_mm_load_shift_and_1rvec_broadcast_ps(const float * gmx_restrict xyz_shift,
149 const float * gmx_restrict xyz,
150 __m128 * gmx_restrict x1,
151 __m128 * gmx_restrict y1,
152 __m128 * gmx_restrict z1)
154 __m128 t1, t2, t3, t4;
156 t1 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)xyz_shift);
157 t2 = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)xyz);
158 t3 = _mm_load_ss(xyz_shift+2);
159 t4 = _mm_load_ss(xyz+2);
160 t1 = _mm_add_ps(t1, t2);
161 t3 = _mm_add_ss(t3, t4);
163 *x1 = _mm_permute_ps(t1, _MM_SHUFFLE(0, 0, 0, 0));
164 *y1 = _mm_permute_ps(t1, _MM_SHUFFLE(1, 1, 1, 1));
165 *z1 = _mm_permute_ps(t3, _MM_SHUFFLE(0, 0, 0, 0));
169 static gmx_inline void gmx_simdcall
170 gmx_mm_load_shift_and_3rvec_broadcast_ps(const float * gmx_restrict xyz_shift,
171 const float * gmx_restrict xyz,
172 __m128 * gmx_restrict x1, __m128 * gmx_restrict y1, __m128 * gmx_restrict z1,
173 __m128 * gmx_restrict x2, __m128 * gmx_restrict y2, __m128 * gmx_restrict z2,
174 __m128 * gmx_restrict x3, __m128 * gmx_restrict y3, __m128 * gmx_restrict z3)
177 __m128 t1, t2, t3, t4, t5, t6;
179 tA = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)xyz_shift);
180 tB = _mm_load_ss(xyz_shift+2);
182 t1 = _mm_loadu_ps(xyz);
183 t2 = _mm_loadu_ps(xyz+4);
184 t3 = _mm_load_ss(xyz+8);
186 tA = _mm_movelh_ps(tA, tB);
187 t4 = _mm_permute_ps(tA, _MM_SHUFFLE(0, 2, 1, 0));
188 t5 = _mm_permute_ps(tA, _MM_SHUFFLE(1, 0, 2, 1));
189 t6 = _mm_permute_ps(tA, _MM_SHUFFLE(2, 1, 0, 2));
191 t1 = _mm_add_ps(t1, t4);
192 t2 = _mm_add_ps(t2, t5);
193 t3 = _mm_add_ss(t3, t6);
195 *x1 = _mm_permute_ps(t1, _MM_SHUFFLE(0, 0, 0, 0));
196 *y1 = _mm_permute_ps(t1, _MM_SHUFFLE(1, 1, 1, 1));
197 *z1 = _mm_permute_ps(t1, _MM_SHUFFLE(2, 2, 2, 2));
198 *x2 = _mm_permute_ps(t1, _MM_SHUFFLE(3, 3, 3, 3));
199 *y2 = _mm_permute_ps(t2, _MM_SHUFFLE(0, 0, 0, 0));
200 *z2 = _mm_permute_ps(t2, _MM_SHUFFLE(1, 1, 1, 1));
201 *x3 = _mm_permute_ps(t2, _MM_SHUFFLE(2, 2, 2, 2));
202 *y3 = _mm_permute_ps(t2, _MM_SHUFFLE(3, 3, 3, 3));
203 *z3 = _mm_permute_ps(t3, _MM_SHUFFLE(0, 0, 0, 0));
207 static gmx_inline void gmx_simdcall
208 gmx_mm_load_shift_and_4rvec_broadcast_ps(const float * gmx_restrict xyz_shift,
209 const float * gmx_restrict xyz,
210 __m128 * gmx_restrict x1, __m128 * gmx_restrict y1, __m128 * gmx_restrict z1,
211 __m128 * gmx_restrict x2, __m128 * gmx_restrict y2, __m128 * gmx_restrict z2,
212 __m128 * gmx_restrict x3, __m128 * gmx_restrict y3, __m128 * gmx_restrict z3,
213 __m128 * gmx_restrict x4, __m128 * gmx_restrict y4, __m128 * gmx_restrict z4)
216 __m128 t1, t2, t3, t4, t5, t6;
218 tA = _mm_loadl_pi(_mm_setzero_ps(), (__m64 *)xyz_shift);
219 tB = _mm_load_ss(xyz_shift+2);
221 t1 = _mm_loadu_ps(xyz);
222 t2 = _mm_loadu_ps(xyz+4);
223 t3 = _mm_loadu_ps(xyz+8);
225 tA = _mm_movelh_ps(tA, tB);
226 t4 = _mm_permute_ps(tA, _MM_SHUFFLE(0, 2, 1, 0));
227 t5 = _mm_permute_ps(tA, _MM_SHUFFLE(1, 0, 2, 1));
228 t6 = _mm_permute_ps(tA, _MM_SHUFFLE(2, 1, 0, 2));
230 t1 = _mm_add_ps(t1, t4);
231 t2 = _mm_add_ps(t2, t5);
232 t3 = _mm_add_ps(t3, t6);
234 *x1 = _mm_permute_ps(t1, _MM_SHUFFLE(0, 0, 0, 0));
235 *y1 = _mm_permute_ps(t1, _MM_SHUFFLE(1, 1, 1, 1));
236 *z1 = _mm_permute_ps(t1, _MM_SHUFFLE(2, 2, 2, 2));
237 *x2 = _mm_permute_ps(t1, _MM_SHUFFLE(3, 3, 3, 3));
238 *y2 = _mm_permute_ps(t2, _MM_SHUFFLE(0, 0, 0, 0));
239 *z2 = _mm_permute_ps(t2, _MM_SHUFFLE(1, 1, 1, 1));
240 *x3 = _mm_permute_ps(t2, _MM_SHUFFLE(2, 2, 2, 2));
241 *y3 = _mm_permute_ps(t2, _MM_SHUFFLE(3, 3, 3, 3));
242 *z3 = _mm_permute_ps(t3, _MM_SHUFFLE(0, 0, 0, 0));
243 *x4 = _mm_permute_ps(t3, _MM_SHUFFLE(1, 1, 1, 1));
244 *y4 = _mm_permute_ps(t3, _MM_SHUFFLE(2, 2, 2, 2));
245 *z4 = _mm_permute_ps(t3, _MM_SHUFFLE(3, 3, 3, 3));
249 static gmx_inline void gmx_simdcall
250 gmx_mm_load_1rvec_4ptr_swizzle_ps(const float * gmx_restrict ptrA, const float * gmx_restrict ptrB,
251 const float * gmx_restrict ptrC, const float * gmx_restrict ptrD,
252 __m128 * gmx_restrict x1, __m128 * gmx_restrict y1, __m128 * gmx_restrict z1)
254 __m128 t1, t2, t3, t4;
255 __m128i mask = _mm_set_epi32(0, -1, -1, -1);
256 t1 = gmx_mm_maskload_ps(ptrA, mask);
257 t2 = gmx_mm_maskload_ps(ptrB, mask);
258 t3 = gmx_mm_maskload_ps(ptrC, mask);
259 t4 = gmx_mm_maskload_ps(ptrD, mask);
260 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
267 static gmx_inline void gmx_simdcall
268 gmx_mm_load_3rvec_4ptr_swizzle_ps(const float * gmx_restrict ptrA, const float * gmx_restrict ptrB,
269 const float * gmx_restrict ptrC, const float * gmx_restrict ptrD,
270 __m128 * gmx_restrict x1, __m128 * gmx_restrict y1, __m128 * gmx_restrict z1,
271 __m128 * gmx_restrict x2, __m128 * gmx_restrict y2, __m128 * gmx_restrict z2,
272 __m128 * gmx_restrict x3, __m128 * gmx_restrict y3, __m128 * gmx_restrict z3)
274 __m128 t1, t2, t3, t4;
275 t1 = _mm_loadu_ps(ptrA);
276 t2 = _mm_loadu_ps(ptrB);
277 t3 = _mm_loadu_ps(ptrC);
278 t4 = _mm_loadu_ps(ptrD);
279 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
284 t1 = _mm_loadu_ps(ptrA+4);
285 t2 = _mm_loadu_ps(ptrB+4);
286 t3 = _mm_loadu_ps(ptrC+4);
287 t4 = _mm_loadu_ps(ptrD+4);
288 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
293 t1 = _mm_load_ss(ptrA+8);
294 t2 = _mm_load_ss(ptrB+8);
295 t3 = _mm_load_ss(ptrC+8);
296 t4 = _mm_load_ss(ptrD+8);
297 t1 = _mm_unpacklo_ps(t1, t3);
298 t3 = _mm_unpacklo_ps(t2, t4);
299 *z3 = _mm_unpacklo_ps(t1, t3);
303 static gmx_inline void gmx_simdcall
304 gmx_mm_load_4rvec_4ptr_swizzle_ps(const float * gmx_restrict ptrA, const float * gmx_restrict ptrB,
305 const float * gmx_restrict ptrC, const float * gmx_restrict ptrD,
306 __m128 * gmx_restrict x1, __m128 * gmx_restrict y1, __m128 * gmx_restrict z1,
307 __m128 * gmx_restrict x2, __m128 * gmx_restrict y2, __m128 * gmx_restrict z2,
308 __m128 * gmx_restrict x3, __m128 * gmx_restrict y3, __m128 * gmx_restrict z3,
309 __m128 * gmx_restrict x4, __m128 * gmx_restrict y4, __m128 * gmx_restrict z4)
311 __m128 t1, t2, t3, t4;
312 t1 = _mm_loadu_ps(ptrA);
313 t2 = _mm_loadu_ps(ptrB);
314 t3 = _mm_loadu_ps(ptrC);
315 t4 = _mm_loadu_ps(ptrD);
316 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
321 t1 = _mm_loadu_ps(ptrA+4);
322 t2 = _mm_loadu_ps(ptrB+4);
323 t3 = _mm_loadu_ps(ptrC+4);
324 t4 = _mm_loadu_ps(ptrD+4);
325 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
330 t1 = _mm_loadu_ps(ptrA+8);
331 t2 = _mm_loadu_ps(ptrB+8);
332 t3 = _mm_loadu_ps(ptrC+8);
333 t4 = _mm_loadu_ps(ptrD+8);
334 _MM_TRANSPOSE4_PS(t1, t2, t3, t4);
342 static gmx_inline void gmx_simdcall
343 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(float * gmx_restrict ptrA, float * gmx_restrict ptrB,
344 float * gmx_restrict ptrC, float * gmx_restrict ptrD,
345 __m128 x1, __m128 y1, __m128 z1)
347 __m128 t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12;
348 t5 = _mm_unpacklo_ps(y1, z1);
349 t6 = _mm_unpackhi_ps(y1, z1);
350 t7 = _mm_shuffle_ps(x1, t5, _MM_SHUFFLE(1, 0, 0, 0));
351 t8 = _mm_shuffle_ps(x1, t5, _MM_SHUFFLE(3, 2, 0, 1));
352 t9 = _mm_shuffle_ps(x1, t6, _MM_SHUFFLE(1, 0, 0, 2));
353 t10 = _mm_shuffle_ps(x1, t6, _MM_SHUFFLE(3, 2, 0, 3));
354 t1 = _mm_load_ss(ptrA);
355 t1 = _mm_loadh_pi(t1, (__m64 *)(ptrA+1));
356 t1 = _mm_sub_ps(t1, t7);
357 _mm_store_ss(ptrA, t1);
358 _mm_storeh_pi((__m64 *)(ptrA+1), t1);
359 t2 = _mm_load_ss(ptrB);
360 t2 = _mm_loadh_pi(t2, (__m64 *)(ptrB+1));
361 t2 = _mm_sub_ps(t2, t8);
362 _mm_store_ss(ptrB, t2);
363 _mm_storeh_pi((__m64 *)(ptrB+1), t2);
364 t3 = _mm_load_ss(ptrC);
365 t3 = _mm_loadh_pi(t3, (__m64 *)(ptrC+1));
366 t3 = _mm_sub_ps(t3, t9);
367 _mm_store_ss(ptrC, t3);
368 _mm_storeh_pi((__m64 *)(ptrC+1), t3);
369 t4 = _mm_load_ss(ptrD);
370 t4 = _mm_loadh_pi(t4, (__m64 *)(ptrD+1));
371 t4 = _mm_sub_ps(t4, t10);
372 _mm_store_ss(ptrD, t4);
373 _mm_storeh_pi((__m64 *)(ptrD+1), t4);
377 static gmx_inline void gmx_simdcall
378 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(float * gmx_restrict ptrA, float * gmx_restrict ptrB,
379 float * gmx_restrict ptrC, float * gmx_restrict ptrD,
380 __m128 x1, __m128 y1, __m128 z1,
381 __m128 x2, __m128 y2, __m128 z2,
382 __m128 x3, __m128 y3, __m128 z3)
384 __m128 t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;
385 __m128 t11, t12, t13, t14, t15, t16, t17, t18, t19;
386 __m128 t20, t21, t22, t23, t24, t25;
387 t13 = _mm_unpackhi_ps(x1, y1);
388 x1 = _mm_unpacklo_ps(x1, y1);
389 t14 = _mm_unpackhi_ps(z1, x2);
390 z1 = _mm_unpacklo_ps(z1, x2);
391 t15 = _mm_unpackhi_ps(y2, z2);
392 y2 = _mm_unpacklo_ps(y2, z2);
393 t16 = _mm_unpackhi_ps(x3, y3);
394 x3 = _mm_unpacklo_ps(x3, y3);
395 t17 = _mm_permute_ps(z3, _MM_SHUFFLE(0, 0, 0, 1));
396 t18 = _mm_movehl_ps(z3, z3);
397 t19 = _mm_permute_ps(t18, _MM_SHUFFLE(0, 0, 0, 1));
398 t20 = _mm_movelh_ps(x1, z1);
399 t21 = _mm_movehl_ps(z1, x1);
400 t22 = _mm_movelh_ps(t13, t14);
401 t14 = _mm_movehl_ps(t14, t13);
402 t23 = _mm_movelh_ps(y2, x3);
403 t24 = _mm_movehl_ps(x3, y2);
404 t25 = _mm_movelh_ps(t15, t16);
405 t16 = _mm_movehl_ps(t16, t15);
406 t1 = _mm_loadu_ps(ptrA);
407 t2 = _mm_loadu_ps(ptrA+4);
408 t3 = _mm_load_ss(ptrA+8);
409 t1 = _mm_sub_ps(t1, t20);
410 t2 = _mm_sub_ps(t2, t23);
411 t3 = _mm_sub_ss(t3, z3);
412 _mm_storeu_ps(ptrA, t1);
413 _mm_storeu_ps(ptrA+4, t2);
414 _mm_store_ss(ptrA+8, t3);
415 t4 = _mm_loadu_ps(ptrB);
416 t5 = _mm_loadu_ps(ptrB+4);
417 t6 = _mm_load_ss(ptrB+8);
418 t4 = _mm_sub_ps(t4, t21);
419 t5 = _mm_sub_ps(t5, t24);
420 t6 = _mm_sub_ss(t6, t17);
421 _mm_storeu_ps(ptrB, t4);
422 _mm_storeu_ps(ptrB+4, t5);
423 _mm_store_ss(ptrB+8, t6);
424 t7 = _mm_loadu_ps(ptrC);
425 t8 = _mm_loadu_ps(ptrC+4);
426 t9 = _mm_load_ss(ptrC+8);
427 t7 = _mm_sub_ps(t7, t22);
428 t8 = _mm_sub_ps(t8, t25);
429 t9 = _mm_sub_ss(t9, t18);
430 _mm_storeu_ps(ptrC, t7);
431 _mm_storeu_ps(ptrC+4, t8);
432 _mm_store_ss(ptrC+8, t9);
433 t10 = _mm_loadu_ps(ptrD);
434 t11 = _mm_loadu_ps(ptrD+4);
435 t12 = _mm_load_ss(ptrD+8);
436 t10 = _mm_sub_ps(t10, t14);
437 t11 = _mm_sub_ps(t11, t16);
438 t12 = _mm_sub_ss(t12, t19);
439 _mm_storeu_ps(ptrD, t10);
440 _mm_storeu_ps(ptrD+4, t11);
441 _mm_store_ss(ptrD+8, t12);
445 static gmx_inline void gmx_simdcall
446 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(float * gmx_restrict ptrA, float * gmx_restrict ptrB,
447 float * gmx_restrict ptrC, float * gmx_restrict ptrD,
448 __m128 x1, __m128 y1, __m128 z1,
449 __m128 x2, __m128 y2, __m128 z2,
450 __m128 x3, __m128 y3, __m128 z3,
451 __m128 x4, __m128 y4, __m128 z4)
453 __m128 t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11;
454 __m128 t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22;
456 t13 = _mm_unpackhi_ps(x1, y1);
457 x1 = _mm_unpacklo_ps(x1, y1);
458 t14 = _mm_unpackhi_ps(z1, x2);
459 z1 = _mm_unpacklo_ps(z1, x2);
460 t15 = _mm_unpackhi_ps(y2, z2);
461 y2 = _mm_unpacklo_ps(y2, z2);
462 t16 = _mm_unpackhi_ps(x3, y3);
463 x3 = _mm_unpacklo_ps(x3, y3);
464 t17 = _mm_unpackhi_ps(z3, x4);
465 z3 = _mm_unpacklo_ps(z3, x4);
466 t18 = _mm_unpackhi_ps(y4, z4);
467 y4 = _mm_unpacklo_ps(y4, z4);
468 t19 = _mm_movelh_ps(x1, z1);
469 z1 = _mm_movehl_ps(z1, x1);
470 t20 = _mm_movelh_ps(t13, t14);
471 t14 = _mm_movehl_ps(t14, t13);
472 t21 = _mm_movelh_ps(y2, x3);
473 x3 = _mm_movehl_ps(x3, y2);
474 t22 = _mm_movelh_ps(t15, t16);
475 t16 = _mm_movehl_ps(t16, t15);
476 t23 = _mm_movelh_ps(z3, y4);
477 y4 = _mm_movehl_ps(y4, z3);
478 t24 = _mm_movelh_ps(t17, t18);
479 t18 = _mm_movehl_ps(t18, t17);
480 t1 = _mm_loadu_ps(ptrA);
481 t2 = _mm_loadu_ps(ptrA+4);
482 t3 = _mm_loadu_ps(ptrA+8);
483 t1 = _mm_sub_ps(t1, t19);
484 t2 = _mm_sub_ps(t2, t21);
485 t3 = _mm_sub_ps(t3, t23);
486 _mm_storeu_ps(ptrA, t1);
487 _mm_storeu_ps(ptrA+4, t2);
488 _mm_storeu_ps(ptrA+8, t3);
489 t4 = _mm_loadu_ps(ptrB);
490 t5 = _mm_loadu_ps(ptrB+4);
491 t6 = _mm_loadu_ps(ptrB+8);
492 t4 = _mm_sub_ps(t4, z1);
493 t5 = _mm_sub_ps(t5, x3);
494 t6 = _mm_sub_ps(t6, y4);
495 _mm_storeu_ps(ptrB, t4);
496 _mm_storeu_ps(ptrB+4, t5);
497 _mm_storeu_ps(ptrB+8, t6);
498 t7 = _mm_loadu_ps(ptrC);
499 t8 = _mm_loadu_ps(ptrC+4);
500 t9 = _mm_loadu_ps(ptrC+8);
501 t7 = _mm_sub_ps(t7, t20);
502 t8 = _mm_sub_ps(t8, t22);
503 t9 = _mm_sub_ps(t9, t24);
504 _mm_storeu_ps(ptrC, t7);
505 _mm_storeu_ps(ptrC+4, t8);
506 _mm_storeu_ps(ptrC+8, t9);
507 t10 = _mm_loadu_ps(ptrD);
508 t11 = _mm_loadu_ps(ptrD+4);
509 t12 = _mm_loadu_ps(ptrD+8);
510 t10 = _mm_sub_ps(t10, t14);
511 t11 = _mm_sub_ps(t11, t16);
512 t12 = _mm_sub_ps(t12, t18);
513 _mm_storeu_ps(ptrD, t10);
514 _mm_storeu_ps(ptrD+4, t11);
515 _mm_storeu_ps(ptrD+8, t12);
519 static gmx_inline void gmx_simdcall
520 gmx_mm_update_iforce_1atom_swizzle_ps(__m128 fix1, __m128 fiy1, __m128 fiz1,
521 float * gmx_restrict fptr,
522 float * gmx_restrict fshiftptr)
526 fix1 = _mm_hadd_ps(fix1, fix1);
527 fiy1 = _mm_hadd_ps(fiy1, fiz1);
529 fix1 = _mm_hadd_ps(fix1, fiy1); /* fiz1 fiy1 fix1 fix1 */
531 t2 = _mm_load_ss(fptr);
532 t2 = _mm_loadh_pi(t2, (__m64 *)(fptr+1));
533 t3 = _mm_load_ss(fshiftptr);
534 t3 = _mm_loadh_pi(t3, (__m64 *)(fshiftptr+1));
536 t2 = _mm_add_ps(t2, fix1);
537 t3 = _mm_add_ps(t3, fix1);
539 _mm_store_ss(fptr, t2);
540 _mm_storeh_pi((__m64 *)(fptr+1), t2);
541 _mm_store_ss(fshiftptr, t3);
542 _mm_storeh_pi((__m64 *)(fshiftptr+1), t3);
546 static gmx_inline void gmx_simdcall
547 gmx_mm_update_iforce_3atom_swizzle_ps(__m128 fix1, __m128 fiy1, __m128 fiz1,
548 __m128 fix2, __m128 fiy2, __m128 fiz2,
549 __m128 fix3, __m128 fiy3, __m128 fiz3,
550 float * gmx_restrict fptr,
551 float * gmx_restrict fshiftptr)
553 __m128 t1, t2, t3, t4;
555 fix1 = _mm_hadd_ps(fix1, fiy1);
556 fiz1 = _mm_hadd_ps(fiz1, fix2);
557 fiy2 = _mm_hadd_ps(fiy2, fiz2);
558 fix3 = _mm_hadd_ps(fix3, fiy3);
559 fiz3 = _mm_hadd_ps(fiz3, fiz3);
561 fix1 = _mm_hadd_ps(fix1, fiz1); /* fix2 fiz1 fiy1 fix1 */
562 fiy2 = _mm_hadd_ps(fiy2, fix3); /* fiy3 fix3 fiz2 fiy2 */
563 fiz3 = _mm_hadd_ps(fiz3, fiz3); /* - - - fiz3 */
565 _mm_storeu_ps(fptr, _mm_add_ps(fix1, _mm_loadu_ps(fptr) ));
566 _mm_storeu_ps(fptr+4, _mm_add_ps(fiy2, _mm_loadu_ps(fptr+4)));
567 _mm_store_ss (fptr+8, _mm_add_ss(fiz3, _mm_load_ss(fptr+8) ));
569 t4 = _mm_load_ss(fshiftptr+2);
570 t4 = _mm_loadh_pi(t4, (__m64 *)(fshiftptr));
572 t1 = _mm_shuffle_ps(fiz3, fix1, _MM_SHUFFLE(1, 0, 0, 0)); /* fiy1 fix1 - fiz3 */
573 t2 = _mm_shuffle_ps(fix1, fiy2, _MM_SHUFFLE(3, 2, 2, 2)); /* fiy3 fix3 - fiz1 */
574 t3 = _mm_shuffle_ps(fiy2, fix1, _MM_SHUFFLE(3, 3, 0, 1)); /* fix2 fix2 fiy2 fiz2 */
575 t3 = _mm_permute_ps(t3, _MM_SHUFFLE(1, 2, 0, 0)); /* fiy2 fix2 - fiz2 */
577 t1 = _mm_add_ps(t1, t2);
578 t3 = _mm_add_ps(t3, t4);
579 t1 = _mm_add_ps(t1, t3); /* y x - z */
581 _mm_store_ss(fshiftptr+2, t1);
582 _mm_storeh_pi((__m64 *)(fshiftptr), t1);
586 static gmx_inline void gmx_simdcall
587 gmx_mm_update_iforce_4atom_swizzle_ps(__m128 fix1, __m128 fiy1, __m128 fiz1,
588 __m128 fix2, __m128 fiy2, __m128 fiz2,
589 __m128 fix3, __m128 fiy3, __m128 fiz3,
590 __m128 fix4, __m128 fiy4, __m128 fiz4,
591 float * gmx_restrict fptr,
592 float * gmx_restrict fshiftptr)
594 __m128 t1, t2, t3, t4, t5;
596 fix1 = _mm_hadd_ps(fix1, fiy1);
597 fiz1 = _mm_hadd_ps(fiz1, fix2);
598 fiy2 = _mm_hadd_ps(fiy2, fiz2);
599 fix3 = _mm_hadd_ps(fix3, fiy3);
600 fiz3 = _mm_hadd_ps(fiz3, fix4);
601 fiy4 = _mm_hadd_ps(fiy4, fiz4);
603 fix1 = _mm_hadd_ps(fix1, fiz1); /* fix2 fiz1 fiy1 fix1 */
604 fiy2 = _mm_hadd_ps(fiy2, fix3); /* fiy3 fix3 fiz2 fiy2 */
605 fiz3 = _mm_hadd_ps(fiz3, fiy4); /* fiz4 fiy4 fix4 fiz3 */
607 _mm_storeu_ps(fptr, _mm_add_ps(fix1, _mm_loadu_ps(fptr) ));
608 _mm_storeu_ps(fptr+4, _mm_add_ps(fiy2, _mm_loadu_ps(fptr+4)));
609 _mm_storeu_ps(fptr+8, _mm_add_ps(fiz3, _mm_loadu_ps(fptr+8)));
611 t5 = _mm_load_ss(fshiftptr+2);
612 t5 = _mm_loadh_pi(t5, (__m64 *)(fshiftptr));
614 t1 = _mm_permute_ps(fix1, _MM_SHUFFLE(1, 0, 2, 2));
615 t2 = _mm_permute_ps(fiy2, _MM_SHUFFLE(3, 2, 1, 1));
616 t3 = _mm_permute_ps(fiz3, _MM_SHUFFLE(2, 1, 0, 0));
617 t4 = _mm_shuffle_ps(fix1, fiy2, _MM_SHUFFLE(0, 0, 3, 3));
618 t4 = _mm_shuffle_ps(fiz3, t4, _MM_SHUFFLE(2, 0, 3, 3));
620 t1 = _mm_add_ps(t1, t2);
621 t3 = _mm_add_ps(t3, t4);
622 t1 = _mm_add_ps(t1, t3);
623 t5 = _mm_add_ps(t5, t1);
625 _mm_store_ss(fshiftptr+2, t5);
626 _mm_storeh_pi((__m64 *)(fshiftptr), t5);
630 static gmx_inline void gmx_simdcall
631 gmx_mm_update_1pot_ps(__m128 pot1, float * gmx_restrict ptrA)
633 pot1 = _mm_hadd_ps(pot1, pot1);
634 pot1 = _mm_hadd_ps(pot1, pot1);
635 _mm_store_ss(ptrA, _mm_add_ss(pot1, _mm_load_ss(ptrA)));
638 static gmx_inline void gmx_simdcall
639 gmx_mm_update_2pot_ps(__m128 pot1, float * gmx_restrict ptrA,
640 __m128 pot2, float * gmx_restrict ptrB)
642 pot1 = _mm_hadd_ps(pot1, pot2);
643 pot1 = _mm_hadd_ps(pot1, pot1);
644 pot2 = _mm_permute_ps(pot1, _MM_SHUFFLE(0, 0, 0, 1));
645 _mm_store_ss(ptrA, _mm_add_ss(pot1, _mm_load_ss(ptrA)));
646 _mm_store_ss(ptrB, _mm_add_ss(pot2, _mm_load_ss(ptrB)));
650 #endif /* _kernelutil_x86_avx_128_fma_single_h_ */