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.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
94 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
95 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
96 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
97 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
100 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128 dummy_mask,cutoff_mask;
106 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107 __m128 one = _mm_set1_ps(1.0);
108 __m128 two = _mm_set1_ps(2.0);
114 jindex = nlist->jindex;
116 shiftidx = nlist->shift;
118 shiftvec = fr->shift_vec[0];
119 fshift = fr->fshift[0];
120 facel = _mm_set1_ps(fr->epsfac);
121 charge = mdatoms->chargeA;
122 nvdwtype = fr->ntype;
124 vdwtype = mdatoms->typeA;
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[0];
128 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
129 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
130 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
131 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
133 /* Avoid stupid compiler warnings */
134 jnrA = jnrB = jnrC = jnrD = 0;
143 for(iidx=0;iidx<4*DIM;iidx++)
148 /* Start outer loop over neighborlists */
149 for(iidx=0; iidx<nri; iidx++)
151 /* Load shift vector for this list */
152 i_shift_offset = DIM*shiftidx[iidx];
154 /* Load limits for loop over neighbors */
155 j_index_start = jindex[iidx];
156 j_index_end = jindex[iidx+1];
158 /* Get outer coordinate index */
160 i_coord_offset = DIM*inr;
162 /* Load i particle coords and add shift vector */
163 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
164 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
166 fix0 = _mm_setzero_ps();
167 fiy0 = _mm_setzero_ps();
168 fiz0 = _mm_setzero_ps();
169 fix1 = _mm_setzero_ps();
170 fiy1 = _mm_setzero_ps();
171 fiz1 = _mm_setzero_ps();
172 fix2 = _mm_setzero_ps();
173 fiy2 = _mm_setzero_ps();
174 fiz2 = _mm_setzero_ps();
175 fix3 = _mm_setzero_ps();
176 fiy3 = _mm_setzero_ps();
177 fiz3 = _mm_setzero_ps();
179 /* Reset potential sums */
180 velecsum = _mm_setzero_ps();
181 vvdwsum = _mm_setzero_ps();
183 /* Start inner kernel loop */
184 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
187 /* Get j neighbor index, and coordinate index */
192 j_coord_offsetA = DIM*jnrA;
193 j_coord_offsetB = DIM*jnrB;
194 j_coord_offsetC = DIM*jnrC;
195 j_coord_offsetD = DIM*jnrD;
197 /* load j atom coordinates */
198 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
199 x+j_coord_offsetC,x+j_coord_offsetD,
202 /* Calculate displacement vector */
203 dx00 = _mm_sub_ps(ix0,jx0);
204 dy00 = _mm_sub_ps(iy0,jy0);
205 dz00 = _mm_sub_ps(iz0,jz0);
206 dx10 = _mm_sub_ps(ix1,jx0);
207 dy10 = _mm_sub_ps(iy1,jy0);
208 dz10 = _mm_sub_ps(iz1,jz0);
209 dx20 = _mm_sub_ps(ix2,jx0);
210 dy20 = _mm_sub_ps(iy2,jy0);
211 dz20 = _mm_sub_ps(iz2,jz0);
212 dx30 = _mm_sub_ps(ix3,jx0);
213 dy30 = _mm_sub_ps(iy3,jy0);
214 dz30 = _mm_sub_ps(iz3,jz0);
216 /* Calculate squared distance and things based on it */
217 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
218 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
219 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
220 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
222 rinv10 = gmx_mm_invsqrt_ps(rsq10);
223 rinv20 = gmx_mm_invsqrt_ps(rsq20);
224 rinv30 = gmx_mm_invsqrt_ps(rsq30);
226 rinvsq00 = gmx_mm_inv_ps(rsq00);
227 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
228 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
229 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
231 /* Load parameters for j particles */
232 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
233 charge+jnrC+0,charge+jnrD+0);
234 vdwjidx0A = 2*vdwtype[jnrA+0];
235 vdwjidx0B = 2*vdwtype[jnrB+0];
236 vdwjidx0C = 2*vdwtype[jnrC+0];
237 vdwjidx0D = 2*vdwtype[jnrD+0];
239 fjx0 = _mm_setzero_ps();
240 fjy0 = _mm_setzero_ps();
241 fjz0 = _mm_setzero_ps();
243 /**************************
244 * CALCULATE INTERACTIONS *
245 **************************/
247 /* Compute parameters for interactions between i and j atoms */
248 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
249 vdwparam+vdwioffset0+vdwjidx0B,
250 vdwparam+vdwioffset0+vdwjidx0C,
251 vdwparam+vdwioffset0+vdwjidx0D,
254 /* LENNARD-JONES DISPERSION/REPULSION */
256 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
257 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
258 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
259 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
260 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
267 /* Update vectorial force */
268 fix0 = _mm_macc_ps(dx00,fscal,fix0);
269 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
270 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
272 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
273 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
274 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
276 /**************************
277 * CALCULATE INTERACTIONS *
278 **************************/
280 /* Compute parameters for interactions between i and j atoms */
281 qq10 = _mm_mul_ps(iq1,jq0);
283 /* COULOMB ELECTROSTATICS */
284 velec = _mm_mul_ps(qq10,rinv10);
285 felec = _mm_mul_ps(velec,rinvsq10);
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 velecsum = _mm_add_ps(velecsum,velec);
292 /* Update vectorial force */
293 fix1 = _mm_macc_ps(dx10,fscal,fix1);
294 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
295 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
297 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
298 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
299 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
301 /**************************
302 * CALCULATE INTERACTIONS *
303 **************************/
305 /* Compute parameters for interactions between i and j atoms */
306 qq20 = _mm_mul_ps(iq2,jq0);
308 /* COULOMB ELECTROSTATICS */
309 velec = _mm_mul_ps(qq20,rinv20);
310 felec = _mm_mul_ps(velec,rinvsq20);
312 /* Update potential sum for this i atom from the interaction with this j atom. */
313 velecsum = _mm_add_ps(velecsum,velec);
317 /* Update vectorial force */
318 fix2 = _mm_macc_ps(dx20,fscal,fix2);
319 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
320 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
322 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
323 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
324 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
326 /**************************
327 * CALCULATE INTERACTIONS *
328 **************************/
330 /* Compute parameters for interactions between i and j atoms */
331 qq30 = _mm_mul_ps(iq3,jq0);
333 /* COULOMB ELECTROSTATICS */
334 velec = _mm_mul_ps(qq30,rinv30);
335 felec = _mm_mul_ps(velec,rinvsq30);
337 /* Update potential sum for this i atom from the interaction with this j atom. */
338 velecsum = _mm_add_ps(velecsum,velec);
342 /* Update vectorial force */
343 fix3 = _mm_macc_ps(dx30,fscal,fix3);
344 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
345 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
347 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
348 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
349 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
351 fjptrA = f+j_coord_offsetA;
352 fjptrB = f+j_coord_offsetB;
353 fjptrC = f+j_coord_offsetC;
354 fjptrD = f+j_coord_offsetD;
356 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
358 /* Inner loop uses 128 flops */
364 /* Get j neighbor index, and coordinate index */
365 jnrlistA = jjnr[jidx];
366 jnrlistB = jjnr[jidx+1];
367 jnrlistC = jjnr[jidx+2];
368 jnrlistD = jjnr[jidx+3];
369 /* Sign of each element will be negative for non-real atoms.
370 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
371 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
373 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
374 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
375 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
376 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
377 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
378 j_coord_offsetA = DIM*jnrA;
379 j_coord_offsetB = DIM*jnrB;
380 j_coord_offsetC = DIM*jnrC;
381 j_coord_offsetD = DIM*jnrD;
383 /* load j atom coordinates */
384 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
385 x+j_coord_offsetC,x+j_coord_offsetD,
388 /* Calculate displacement vector */
389 dx00 = _mm_sub_ps(ix0,jx0);
390 dy00 = _mm_sub_ps(iy0,jy0);
391 dz00 = _mm_sub_ps(iz0,jz0);
392 dx10 = _mm_sub_ps(ix1,jx0);
393 dy10 = _mm_sub_ps(iy1,jy0);
394 dz10 = _mm_sub_ps(iz1,jz0);
395 dx20 = _mm_sub_ps(ix2,jx0);
396 dy20 = _mm_sub_ps(iy2,jy0);
397 dz20 = _mm_sub_ps(iz2,jz0);
398 dx30 = _mm_sub_ps(ix3,jx0);
399 dy30 = _mm_sub_ps(iy3,jy0);
400 dz30 = _mm_sub_ps(iz3,jz0);
402 /* Calculate squared distance and things based on it */
403 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
404 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
405 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
406 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
408 rinv10 = gmx_mm_invsqrt_ps(rsq10);
409 rinv20 = gmx_mm_invsqrt_ps(rsq20);
410 rinv30 = gmx_mm_invsqrt_ps(rsq30);
412 rinvsq00 = gmx_mm_inv_ps(rsq00);
413 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
414 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
415 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
417 /* Load parameters for j particles */
418 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
419 charge+jnrC+0,charge+jnrD+0);
420 vdwjidx0A = 2*vdwtype[jnrA+0];
421 vdwjidx0B = 2*vdwtype[jnrB+0];
422 vdwjidx0C = 2*vdwtype[jnrC+0];
423 vdwjidx0D = 2*vdwtype[jnrD+0];
425 fjx0 = _mm_setzero_ps();
426 fjy0 = _mm_setzero_ps();
427 fjz0 = _mm_setzero_ps();
429 /**************************
430 * CALCULATE INTERACTIONS *
431 **************************/
433 /* Compute parameters for interactions between i and j atoms */
434 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
435 vdwparam+vdwioffset0+vdwjidx0B,
436 vdwparam+vdwioffset0+vdwjidx0C,
437 vdwparam+vdwioffset0+vdwjidx0D,
440 /* LENNARD-JONES DISPERSION/REPULSION */
442 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
443 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
444 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
445 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
446 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
448 /* Update potential sum for this i atom from the interaction with this j atom. */
449 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
450 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
454 fscal = _mm_andnot_ps(dummy_mask,fscal);
456 /* Update vectorial force */
457 fix0 = _mm_macc_ps(dx00,fscal,fix0);
458 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
459 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
461 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
462 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
463 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
465 /**************************
466 * CALCULATE INTERACTIONS *
467 **************************/
469 /* Compute parameters for interactions between i and j atoms */
470 qq10 = _mm_mul_ps(iq1,jq0);
472 /* COULOMB ELECTROSTATICS */
473 velec = _mm_mul_ps(qq10,rinv10);
474 felec = _mm_mul_ps(velec,rinvsq10);
476 /* Update potential sum for this i atom from the interaction with this j atom. */
477 velec = _mm_andnot_ps(dummy_mask,velec);
478 velecsum = _mm_add_ps(velecsum,velec);
482 fscal = _mm_andnot_ps(dummy_mask,fscal);
484 /* Update vectorial force */
485 fix1 = _mm_macc_ps(dx10,fscal,fix1);
486 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
487 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
489 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
490 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
491 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
493 /**************************
494 * CALCULATE INTERACTIONS *
495 **************************/
497 /* Compute parameters for interactions between i and j atoms */
498 qq20 = _mm_mul_ps(iq2,jq0);
500 /* COULOMB ELECTROSTATICS */
501 velec = _mm_mul_ps(qq20,rinv20);
502 felec = _mm_mul_ps(velec,rinvsq20);
504 /* Update potential sum for this i atom from the interaction with this j atom. */
505 velec = _mm_andnot_ps(dummy_mask,velec);
506 velecsum = _mm_add_ps(velecsum,velec);
510 fscal = _mm_andnot_ps(dummy_mask,fscal);
512 /* Update vectorial force */
513 fix2 = _mm_macc_ps(dx20,fscal,fix2);
514 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
515 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
517 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
518 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
519 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
521 /**************************
522 * CALCULATE INTERACTIONS *
523 **************************/
525 /* Compute parameters for interactions between i and j atoms */
526 qq30 = _mm_mul_ps(iq3,jq0);
528 /* COULOMB ELECTROSTATICS */
529 velec = _mm_mul_ps(qq30,rinv30);
530 felec = _mm_mul_ps(velec,rinvsq30);
532 /* Update potential sum for this i atom from the interaction with this j atom. */
533 velec = _mm_andnot_ps(dummy_mask,velec);
534 velecsum = _mm_add_ps(velecsum,velec);
538 fscal = _mm_andnot_ps(dummy_mask,fscal);
540 /* Update vectorial force */
541 fix3 = _mm_macc_ps(dx30,fscal,fix3);
542 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
543 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
545 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
546 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
547 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
549 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
550 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
551 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
552 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
554 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
556 /* Inner loop uses 128 flops */
559 /* End of innermost loop */
561 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
562 f+i_coord_offset,fshift+i_shift_offset);
565 /* Update potential energies */
566 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
567 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
569 /* Increment number of inner iterations */
570 inneriter += j_index_end - j_index_start;
572 /* Outer loop uses 26 flops */
575 /* Increment number of outer iterations */
578 /* Update outer/inner flops */
580 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*128);
583 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
584 * Electrostatics interaction: Coulomb
585 * VdW interaction: LennardJones
586 * Geometry: Water4-Particle
587 * Calculate force/pot: Force
590 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
591 (t_nblist * gmx_restrict nlist,
592 rvec * gmx_restrict xx,
593 rvec * gmx_restrict ff,
594 t_forcerec * gmx_restrict fr,
595 t_mdatoms * gmx_restrict mdatoms,
596 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
597 t_nrnb * gmx_restrict nrnb)
599 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
600 * just 0 for non-waters.
601 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
602 * jnr indices corresponding to data put in the four positions in the SIMD register.
604 int i_shift_offset,i_coord_offset,outeriter,inneriter;
605 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
606 int jnrA,jnrB,jnrC,jnrD;
607 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
608 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
609 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
611 real *shiftvec,*fshift,*x,*f;
612 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
614 __m128 fscal,rcutoff,rcutoff2,jidxall;
616 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
618 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
620 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
622 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
623 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
624 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
625 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
626 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
627 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
628 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
629 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
632 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
635 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
636 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
637 __m128 dummy_mask,cutoff_mask;
638 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
639 __m128 one = _mm_set1_ps(1.0);
640 __m128 two = _mm_set1_ps(2.0);
646 jindex = nlist->jindex;
648 shiftidx = nlist->shift;
650 shiftvec = fr->shift_vec[0];
651 fshift = fr->fshift[0];
652 facel = _mm_set1_ps(fr->epsfac);
653 charge = mdatoms->chargeA;
654 nvdwtype = fr->ntype;
656 vdwtype = mdatoms->typeA;
658 /* Setup water-specific parameters */
659 inr = nlist->iinr[0];
660 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
661 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
662 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
663 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
665 /* Avoid stupid compiler warnings */
666 jnrA = jnrB = jnrC = jnrD = 0;
675 for(iidx=0;iidx<4*DIM;iidx++)
680 /* Start outer loop over neighborlists */
681 for(iidx=0; iidx<nri; iidx++)
683 /* Load shift vector for this list */
684 i_shift_offset = DIM*shiftidx[iidx];
686 /* Load limits for loop over neighbors */
687 j_index_start = jindex[iidx];
688 j_index_end = jindex[iidx+1];
690 /* Get outer coordinate index */
692 i_coord_offset = DIM*inr;
694 /* Load i particle coords and add shift vector */
695 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
696 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
698 fix0 = _mm_setzero_ps();
699 fiy0 = _mm_setzero_ps();
700 fiz0 = _mm_setzero_ps();
701 fix1 = _mm_setzero_ps();
702 fiy1 = _mm_setzero_ps();
703 fiz1 = _mm_setzero_ps();
704 fix2 = _mm_setzero_ps();
705 fiy2 = _mm_setzero_ps();
706 fiz2 = _mm_setzero_ps();
707 fix3 = _mm_setzero_ps();
708 fiy3 = _mm_setzero_ps();
709 fiz3 = _mm_setzero_ps();
711 /* Start inner kernel loop */
712 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
715 /* Get j neighbor index, and coordinate index */
720 j_coord_offsetA = DIM*jnrA;
721 j_coord_offsetB = DIM*jnrB;
722 j_coord_offsetC = DIM*jnrC;
723 j_coord_offsetD = DIM*jnrD;
725 /* load j atom coordinates */
726 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
727 x+j_coord_offsetC,x+j_coord_offsetD,
730 /* Calculate displacement vector */
731 dx00 = _mm_sub_ps(ix0,jx0);
732 dy00 = _mm_sub_ps(iy0,jy0);
733 dz00 = _mm_sub_ps(iz0,jz0);
734 dx10 = _mm_sub_ps(ix1,jx0);
735 dy10 = _mm_sub_ps(iy1,jy0);
736 dz10 = _mm_sub_ps(iz1,jz0);
737 dx20 = _mm_sub_ps(ix2,jx0);
738 dy20 = _mm_sub_ps(iy2,jy0);
739 dz20 = _mm_sub_ps(iz2,jz0);
740 dx30 = _mm_sub_ps(ix3,jx0);
741 dy30 = _mm_sub_ps(iy3,jy0);
742 dz30 = _mm_sub_ps(iz3,jz0);
744 /* Calculate squared distance and things based on it */
745 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
746 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
747 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
748 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
750 rinv10 = gmx_mm_invsqrt_ps(rsq10);
751 rinv20 = gmx_mm_invsqrt_ps(rsq20);
752 rinv30 = gmx_mm_invsqrt_ps(rsq30);
754 rinvsq00 = gmx_mm_inv_ps(rsq00);
755 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
756 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
757 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
759 /* Load parameters for j particles */
760 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
761 charge+jnrC+0,charge+jnrD+0);
762 vdwjidx0A = 2*vdwtype[jnrA+0];
763 vdwjidx0B = 2*vdwtype[jnrB+0];
764 vdwjidx0C = 2*vdwtype[jnrC+0];
765 vdwjidx0D = 2*vdwtype[jnrD+0];
767 fjx0 = _mm_setzero_ps();
768 fjy0 = _mm_setzero_ps();
769 fjz0 = _mm_setzero_ps();
771 /**************************
772 * CALCULATE INTERACTIONS *
773 **************************/
775 /* Compute parameters for interactions between i and j atoms */
776 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
777 vdwparam+vdwioffset0+vdwjidx0B,
778 vdwparam+vdwioffset0+vdwjidx0C,
779 vdwparam+vdwioffset0+vdwjidx0D,
782 /* LENNARD-JONES DISPERSION/REPULSION */
784 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
785 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
789 /* Update vectorial force */
790 fix0 = _mm_macc_ps(dx00,fscal,fix0);
791 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
792 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
794 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
795 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
796 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
798 /**************************
799 * CALCULATE INTERACTIONS *
800 **************************/
802 /* Compute parameters for interactions between i and j atoms */
803 qq10 = _mm_mul_ps(iq1,jq0);
805 /* COULOMB ELECTROSTATICS */
806 velec = _mm_mul_ps(qq10,rinv10);
807 felec = _mm_mul_ps(velec,rinvsq10);
811 /* Update vectorial force */
812 fix1 = _mm_macc_ps(dx10,fscal,fix1);
813 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
814 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
816 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
817 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
818 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
820 /**************************
821 * CALCULATE INTERACTIONS *
822 **************************/
824 /* Compute parameters for interactions between i and j atoms */
825 qq20 = _mm_mul_ps(iq2,jq0);
827 /* COULOMB ELECTROSTATICS */
828 velec = _mm_mul_ps(qq20,rinv20);
829 felec = _mm_mul_ps(velec,rinvsq20);
833 /* Update vectorial force */
834 fix2 = _mm_macc_ps(dx20,fscal,fix2);
835 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
836 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
838 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
839 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
840 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
842 /**************************
843 * CALCULATE INTERACTIONS *
844 **************************/
846 /* Compute parameters for interactions between i and j atoms */
847 qq30 = _mm_mul_ps(iq3,jq0);
849 /* COULOMB ELECTROSTATICS */
850 velec = _mm_mul_ps(qq30,rinv30);
851 felec = _mm_mul_ps(velec,rinvsq30);
855 /* Update vectorial force */
856 fix3 = _mm_macc_ps(dx30,fscal,fix3);
857 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
858 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
860 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
861 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
862 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
864 fjptrA = f+j_coord_offsetA;
865 fjptrB = f+j_coord_offsetB;
866 fjptrC = f+j_coord_offsetC;
867 fjptrD = f+j_coord_offsetD;
869 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
871 /* Inner loop uses 120 flops */
877 /* Get j neighbor index, and coordinate index */
878 jnrlistA = jjnr[jidx];
879 jnrlistB = jjnr[jidx+1];
880 jnrlistC = jjnr[jidx+2];
881 jnrlistD = jjnr[jidx+3];
882 /* Sign of each element will be negative for non-real atoms.
883 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
884 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
886 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
887 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
888 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
889 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
890 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
891 j_coord_offsetA = DIM*jnrA;
892 j_coord_offsetB = DIM*jnrB;
893 j_coord_offsetC = DIM*jnrC;
894 j_coord_offsetD = DIM*jnrD;
896 /* load j atom coordinates */
897 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
898 x+j_coord_offsetC,x+j_coord_offsetD,
901 /* Calculate displacement vector */
902 dx00 = _mm_sub_ps(ix0,jx0);
903 dy00 = _mm_sub_ps(iy0,jy0);
904 dz00 = _mm_sub_ps(iz0,jz0);
905 dx10 = _mm_sub_ps(ix1,jx0);
906 dy10 = _mm_sub_ps(iy1,jy0);
907 dz10 = _mm_sub_ps(iz1,jz0);
908 dx20 = _mm_sub_ps(ix2,jx0);
909 dy20 = _mm_sub_ps(iy2,jy0);
910 dz20 = _mm_sub_ps(iz2,jz0);
911 dx30 = _mm_sub_ps(ix3,jx0);
912 dy30 = _mm_sub_ps(iy3,jy0);
913 dz30 = _mm_sub_ps(iz3,jz0);
915 /* Calculate squared distance and things based on it */
916 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
917 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
918 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
919 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
921 rinv10 = gmx_mm_invsqrt_ps(rsq10);
922 rinv20 = gmx_mm_invsqrt_ps(rsq20);
923 rinv30 = gmx_mm_invsqrt_ps(rsq30);
925 rinvsq00 = gmx_mm_inv_ps(rsq00);
926 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
927 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
928 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
930 /* Load parameters for j particles */
931 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
932 charge+jnrC+0,charge+jnrD+0);
933 vdwjidx0A = 2*vdwtype[jnrA+0];
934 vdwjidx0B = 2*vdwtype[jnrB+0];
935 vdwjidx0C = 2*vdwtype[jnrC+0];
936 vdwjidx0D = 2*vdwtype[jnrD+0];
938 fjx0 = _mm_setzero_ps();
939 fjy0 = _mm_setzero_ps();
940 fjz0 = _mm_setzero_ps();
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 /* Compute parameters for interactions between i and j atoms */
947 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
948 vdwparam+vdwioffset0+vdwjidx0B,
949 vdwparam+vdwioffset0+vdwjidx0C,
950 vdwparam+vdwioffset0+vdwjidx0D,
953 /* LENNARD-JONES DISPERSION/REPULSION */
955 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
956 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
960 fscal = _mm_andnot_ps(dummy_mask,fscal);
962 /* Update vectorial force */
963 fix0 = _mm_macc_ps(dx00,fscal,fix0);
964 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
965 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
967 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
968 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
969 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
971 /**************************
972 * CALCULATE INTERACTIONS *
973 **************************/
975 /* Compute parameters for interactions between i and j atoms */
976 qq10 = _mm_mul_ps(iq1,jq0);
978 /* COULOMB ELECTROSTATICS */
979 velec = _mm_mul_ps(qq10,rinv10);
980 felec = _mm_mul_ps(velec,rinvsq10);
984 fscal = _mm_andnot_ps(dummy_mask,fscal);
986 /* Update vectorial force */
987 fix1 = _mm_macc_ps(dx10,fscal,fix1);
988 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
989 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
991 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
992 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
993 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
995 /**************************
996 * CALCULATE INTERACTIONS *
997 **************************/
999 /* Compute parameters for interactions between i and j atoms */
1000 qq20 = _mm_mul_ps(iq2,jq0);
1002 /* COULOMB ELECTROSTATICS */
1003 velec = _mm_mul_ps(qq20,rinv20);
1004 felec = _mm_mul_ps(velec,rinvsq20);
1008 fscal = _mm_andnot_ps(dummy_mask,fscal);
1010 /* Update vectorial force */
1011 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1012 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1013 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1015 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1016 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1017 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1019 /**************************
1020 * CALCULATE INTERACTIONS *
1021 **************************/
1023 /* Compute parameters for interactions between i and j atoms */
1024 qq30 = _mm_mul_ps(iq3,jq0);
1026 /* COULOMB ELECTROSTATICS */
1027 velec = _mm_mul_ps(qq30,rinv30);
1028 felec = _mm_mul_ps(velec,rinvsq30);
1032 fscal = _mm_andnot_ps(dummy_mask,fscal);
1034 /* Update vectorial force */
1035 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1036 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1037 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1039 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1040 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1041 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1043 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1044 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1045 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1046 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1048 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1050 /* Inner loop uses 120 flops */
1053 /* End of innermost loop */
1055 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1056 f+i_coord_offset,fshift+i_shift_offset);
1058 /* Increment number of inner iterations */
1059 inneriter += j_index_end - j_index_start;
1061 /* Outer loop uses 24 flops */
1064 /* Increment number of outer iterations */
1067 /* Update outer/inner flops */
1069 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*120);