2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
106 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
108 __m128 dummy_mask,cutoff_mask;
109 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
110 __m128 one = _mm_set1_ps(1.0);
111 __m128 two = _mm_set1_ps(2.0);
117 jindex = nlist->jindex;
119 shiftidx = nlist->shift;
121 shiftvec = fr->shift_vec[0];
122 fshift = fr->fshift[0];
123 facel = _mm_set1_ps(fr->ic->epsfac);
124 charge = mdatoms->chargeA;
125 nvdwtype = fr->ntype;
127 vdwtype = mdatoms->typeA;
129 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
130 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
131 beta2 = _mm_mul_ps(beta,beta);
132 beta3 = _mm_mul_ps(beta,beta2);
133 ewtab = fr->ic->tabq_coul_FDV0;
134 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
135 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
137 /* Setup water-specific parameters */
138 inr = nlist->iinr[0];
139 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
140 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
141 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
142 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
144 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
145 rcutoff_scalar = fr->ic->rcoulomb;
146 rcutoff = _mm_set1_ps(rcutoff_scalar);
147 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
149 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
150 rvdw = _mm_set1_ps(fr->ic->rvdw);
152 /* Avoid stupid compiler warnings */
153 jnrA = jnrB = jnrC = jnrD = 0;
162 for(iidx=0;iidx<4*DIM;iidx++)
167 /* Start outer loop over neighborlists */
168 for(iidx=0; iidx<nri; iidx++)
170 /* Load shift vector for this list */
171 i_shift_offset = DIM*shiftidx[iidx];
173 /* Load limits for loop over neighbors */
174 j_index_start = jindex[iidx];
175 j_index_end = jindex[iidx+1];
177 /* Get outer coordinate index */
179 i_coord_offset = DIM*inr;
181 /* Load i particle coords and add shift vector */
182 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
183 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
185 fix0 = _mm_setzero_ps();
186 fiy0 = _mm_setzero_ps();
187 fiz0 = _mm_setzero_ps();
188 fix1 = _mm_setzero_ps();
189 fiy1 = _mm_setzero_ps();
190 fiz1 = _mm_setzero_ps();
191 fix2 = _mm_setzero_ps();
192 fiy2 = _mm_setzero_ps();
193 fiz2 = _mm_setzero_ps();
194 fix3 = _mm_setzero_ps();
195 fiy3 = _mm_setzero_ps();
196 fiz3 = _mm_setzero_ps();
198 /* Reset potential sums */
199 velecsum = _mm_setzero_ps();
200 vvdwsum = _mm_setzero_ps();
202 /* Start inner kernel loop */
203 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
206 /* Get j neighbor index, and coordinate index */
211 j_coord_offsetA = DIM*jnrA;
212 j_coord_offsetB = DIM*jnrB;
213 j_coord_offsetC = DIM*jnrC;
214 j_coord_offsetD = DIM*jnrD;
216 /* load j atom coordinates */
217 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
218 x+j_coord_offsetC,x+j_coord_offsetD,
221 /* Calculate displacement vector */
222 dx00 = _mm_sub_ps(ix0,jx0);
223 dy00 = _mm_sub_ps(iy0,jy0);
224 dz00 = _mm_sub_ps(iz0,jz0);
225 dx10 = _mm_sub_ps(ix1,jx0);
226 dy10 = _mm_sub_ps(iy1,jy0);
227 dz10 = _mm_sub_ps(iz1,jz0);
228 dx20 = _mm_sub_ps(ix2,jx0);
229 dy20 = _mm_sub_ps(iy2,jy0);
230 dz20 = _mm_sub_ps(iz2,jz0);
231 dx30 = _mm_sub_ps(ix3,jx0);
232 dy30 = _mm_sub_ps(iy3,jy0);
233 dz30 = _mm_sub_ps(iz3,jz0);
235 /* Calculate squared distance and things based on it */
236 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
237 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
238 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
239 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
241 rinv10 = avx128fma_invsqrt_f(rsq10);
242 rinv20 = avx128fma_invsqrt_f(rsq20);
243 rinv30 = avx128fma_invsqrt_f(rsq30);
245 rinvsq00 = avx128fma_inv_f(rsq00);
246 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
247 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
248 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
250 /* Load parameters for j particles */
251 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
252 charge+jnrC+0,charge+jnrD+0);
253 vdwjidx0A = 2*vdwtype[jnrA+0];
254 vdwjidx0B = 2*vdwtype[jnrB+0];
255 vdwjidx0C = 2*vdwtype[jnrC+0];
256 vdwjidx0D = 2*vdwtype[jnrD+0];
258 fjx0 = _mm_setzero_ps();
259 fjy0 = _mm_setzero_ps();
260 fjz0 = _mm_setzero_ps();
262 /**************************
263 * CALCULATE INTERACTIONS *
264 **************************/
266 if (gmx_mm_any_lt(rsq00,rcutoff2))
269 /* Compute parameters for interactions between i and j atoms */
270 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
271 vdwparam+vdwioffset0+vdwjidx0B,
272 vdwparam+vdwioffset0+vdwjidx0C,
273 vdwparam+vdwioffset0+vdwjidx0D,
276 /* LENNARD-JONES DISPERSION/REPULSION */
278 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
279 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
280 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
281 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
282 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
283 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
285 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 vvdw = _mm_and_ps(vvdw,cutoff_mask);
289 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
293 fscal = _mm_and_ps(fscal,cutoff_mask);
295 /* Update vectorial force */
296 fix0 = _mm_macc_ps(dx00,fscal,fix0);
297 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
298 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
300 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
301 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
302 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
306 /**************************
307 * CALCULATE INTERACTIONS *
308 **************************/
310 if (gmx_mm_any_lt(rsq10,rcutoff2))
313 r10 = _mm_mul_ps(rsq10,rinv10);
315 /* Compute parameters for interactions between i and j atoms */
316 qq10 = _mm_mul_ps(iq1,jq0);
318 /* EWALD ELECTROSTATICS */
320 /* Analytical PME correction */
321 zeta2 = _mm_mul_ps(beta2,rsq10);
322 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
323 pmecorrF = avx128fma_pmecorrF_f(zeta2);
324 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
325 felec = _mm_mul_ps(qq10,felec);
326 pmecorrV = avx128fma_pmecorrV_f(zeta2);
327 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
328 velec = _mm_mul_ps(qq10,velec);
330 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
332 /* Update potential sum for this i atom from the interaction with this j atom. */
333 velec = _mm_and_ps(velec,cutoff_mask);
334 velecsum = _mm_add_ps(velecsum,velec);
338 fscal = _mm_and_ps(fscal,cutoff_mask);
340 /* Update vectorial force */
341 fix1 = _mm_macc_ps(dx10,fscal,fix1);
342 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
343 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
345 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
346 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
347 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
351 /**************************
352 * CALCULATE INTERACTIONS *
353 **************************/
355 if (gmx_mm_any_lt(rsq20,rcutoff2))
358 r20 = _mm_mul_ps(rsq20,rinv20);
360 /* Compute parameters for interactions between i and j atoms */
361 qq20 = _mm_mul_ps(iq2,jq0);
363 /* EWALD ELECTROSTATICS */
365 /* Analytical PME correction */
366 zeta2 = _mm_mul_ps(beta2,rsq20);
367 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
368 pmecorrF = avx128fma_pmecorrF_f(zeta2);
369 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
370 felec = _mm_mul_ps(qq20,felec);
371 pmecorrV = avx128fma_pmecorrV_f(zeta2);
372 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
373 velec = _mm_mul_ps(qq20,velec);
375 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
377 /* Update potential sum for this i atom from the interaction with this j atom. */
378 velec = _mm_and_ps(velec,cutoff_mask);
379 velecsum = _mm_add_ps(velecsum,velec);
383 fscal = _mm_and_ps(fscal,cutoff_mask);
385 /* Update vectorial force */
386 fix2 = _mm_macc_ps(dx20,fscal,fix2);
387 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
388 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
390 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
391 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
392 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
396 /**************************
397 * CALCULATE INTERACTIONS *
398 **************************/
400 if (gmx_mm_any_lt(rsq30,rcutoff2))
403 r30 = _mm_mul_ps(rsq30,rinv30);
405 /* Compute parameters for interactions between i and j atoms */
406 qq30 = _mm_mul_ps(iq3,jq0);
408 /* EWALD ELECTROSTATICS */
410 /* Analytical PME correction */
411 zeta2 = _mm_mul_ps(beta2,rsq30);
412 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
413 pmecorrF = avx128fma_pmecorrF_f(zeta2);
414 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
415 felec = _mm_mul_ps(qq30,felec);
416 pmecorrV = avx128fma_pmecorrV_f(zeta2);
417 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
418 velec = _mm_mul_ps(qq30,velec);
420 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
422 /* Update potential sum for this i atom from the interaction with this j atom. */
423 velec = _mm_and_ps(velec,cutoff_mask);
424 velecsum = _mm_add_ps(velecsum,velec);
428 fscal = _mm_and_ps(fscal,cutoff_mask);
430 /* Update vectorial force */
431 fix3 = _mm_macc_ps(dx30,fscal,fix3);
432 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
433 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
435 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
436 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
437 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
441 fjptrA = f+j_coord_offsetA;
442 fjptrB = f+j_coord_offsetB;
443 fjptrC = f+j_coord_offsetC;
444 fjptrD = f+j_coord_offsetD;
446 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
448 /* Inner loop uses 143 flops */
454 /* Get j neighbor index, and coordinate index */
455 jnrlistA = jjnr[jidx];
456 jnrlistB = jjnr[jidx+1];
457 jnrlistC = jjnr[jidx+2];
458 jnrlistD = jjnr[jidx+3];
459 /* Sign of each element will be negative for non-real atoms.
460 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
461 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
463 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
464 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
465 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
466 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
467 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
468 j_coord_offsetA = DIM*jnrA;
469 j_coord_offsetB = DIM*jnrB;
470 j_coord_offsetC = DIM*jnrC;
471 j_coord_offsetD = DIM*jnrD;
473 /* load j atom coordinates */
474 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
475 x+j_coord_offsetC,x+j_coord_offsetD,
478 /* Calculate displacement vector */
479 dx00 = _mm_sub_ps(ix0,jx0);
480 dy00 = _mm_sub_ps(iy0,jy0);
481 dz00 = _mm_sub_ps(iz0,jz0);
482 dx10 = _mm_sub_ps(ix1,jx0);
483 dy10 = _mm_sub_ps(iy1,jy0);
484 dz10 = _mm_sub_ps(iz1,jz0);
485 dx20 = _mm_sub_ps(ix2,jx0);
486 dy20 = _mm_sub_ps(iy2,jy0);
487 dz20 = _mm_sub_ps(iz2,jz0);
488 dx30 = _mm_sub_ps(ix3,jx0);
489 dy30 = _mm_sub_ps(iy3,jy0);
490 dz30 = _mm_sub_ps(iz3,jz0);
492 /* Calculate squared distance and things based on it */
493 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
494 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
495 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
496 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
498 rinv10 = avx128fma_invsqrt_f(rsq10);
499 rinv20 = avx128fma_invsqrt_f(rsq20);
500 rinv30 = avx128fma_invsqrt_f(rsq30);
502 rinvsq00 = avx128fma_inv_f(rsq00);
503 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
504 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
505 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
507 /* Load parameters for j particles */
508 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
509 charge+jnrC+0,charge+jnrD+0);
510 vdwjidx0A = 2*vdwtype[jnrA+0];
511 vdwjidx0B = 2*vdwtype[jnrB+0];
512 vdwjidx0C = 2*vdwtype[jnrC+0];
513 vdwjidx0D = 2*vdwtype[jnrD+0];
515 fjx0 = _mm_setzero_ps();
516 fjy0 = _mm_setzero_ps();
517 fjz0 = _mm_setzero_ps();
519 /**************************
520 * CALCULATE INTERACTIONS *
521 **************************/
523 if (gmx_mm_any_lt(rsq00,rcutoff2))
526 /* Compute parameters for interactions between i and j atoms */
527 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
528 vdwparam+vdwioffset0+vdwjidx0B,
529 vdwparam+vdwioffset0+vdwjidx0C,
530 vdwparam+vdwioffset0+vdwjidx0D,
533 /* LENNARD-JONES DISPERSION/REPULSION */
535 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
536 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
537 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
538 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
539 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
540 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
542 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
544 /* Update potential sum for this i atom from the interaction with this j atom. */
545 vvdw = _mm_and_ps(vvdw,cutoff_mask);
546 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
547 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
551 fscal = _mm_and_ps(fscal,cutoff_mask);
553 fscal = _mm_andnot_ps(dummy_mask,fscal);
555 /* Update vectorial force */
556 fix0 = _mm_macc_ps(dx00,fscal,fix0);
557 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
558 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
560 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
561 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
562 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
566 /**************************
567 * CALCULATE INTERACTIONS *
568 **************************/
570 if (gmx_mm_any_lt(rsq10,rcutoff2))
573 r10 = _mm_mul_ps(rsq10,rinv10);
574 r10 = _mm_andnot_ps(dummy_mask,r10);
576 /* Compute parameters for interactions between i and j atoms */
577 qq10 = _mm_mul_ps(iq1,jq0);
579 /* EWALD ELECTROSTATICS */
581 /* Analytical PME correction */
582 zeta2 = _mm_mul_ps(beta2,rsq10);
583 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
584 pmecorrF = avx128fma_pmecorrF_f(zeta2);
585 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
586 felec = _mm_mul_ps(qq10,felec);
587 pmecorrV = avx128fma_pmecorrV_f(zeta2);
588 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
589 velec = _mm_mul_ps(qq10,velec);
591 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
593 /* Update potential sum for this i atom from the interaction with this j atom. */
594 velec = _mm_and_ps(velec,cutoff_mask);
595 velec = _mm_andnot_ps(dummy_mask,velec);
596 velecsum = _mm_add_ps(velecsum,velec);
600 fscal = _mm_and_ps(fscal,cutoff_mask);
602 fscal = _mm_andnot_ps(dummy_mask,fscal);
604 /* Update vectorial force */
605 fix1 = _mm_macc_ps(dx10,fscal,fix1);
606 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
607 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
609 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
610 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
611 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq20,rcutoff2))
622 r20 = _mm_mul_ps(rsq20,rinv20);
623 r20 = _mm_andnot_ps(dummy_mask,r20);
625 /* Compute parameters for interactions between i and j atoms */
626 qq20 = _mm_mul_ps(iq2,jq0);
628 /* EWALD ELECTROSTATICS */
630 /* Analytical PME correction */
631 zeta2 = _mm_mul_ps(beta2,rsq20);
632 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
633 pmecorrF = avx128fma_pmecorrF_f(zeta2);
634 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
635 felec = _mm_mul_ps(qq20,felec);
636 pmecorrV = avx128fma_pmecorrV_f(zeta2);
637 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
638 velec = _mm_mul_ps(qq20,velec);
640 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
642 /* Update potential sum for this i atom from the interaction with this j atom. */
643 velec = _mm_and_ps(velec,cutoff_mask);
644 velec = _mm_andnot_ps(dummy_mask,velec);
645 velecsum = _mm_add_ps(velecsum,velec);
649 fscal = _mm_and_ps(fscal,cutoff_mask);
651 fscal = _mm_andnot_ps(dummy_mask,fscal);
653 /* Update vectorial force */
654 fix2 = _mm_macc_ps(dx20,fscal,fix2);
655 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
656 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
658 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
659 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
660 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
664 /**************************
665 * CALCULATE INTERACTIONS *
666 **************************/
668 if (gmx_mm_any_lt(rsq30,rcutoff2))
671 r30 = _mm_mul_ps(rsq30,rinv30);
672 r30 = _mm_andnot_ps(dummy_mask,r30);
674 /* Compute parameters for interactions between i and j atoms */
675 qq30 = _mm_mul_ps(iq3,jq0);
677 /* EWALD ELECTROSTATICS */
679 /* Analytical PME correction */
680 zeta2 = _mm_mul_ps(beta2,rsq30);
681 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
682 pmecorrF = avx128fma_pmecorrF_f(zeta2);
683 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
684 felec = _mm_mul_ps(qq30,felec);
685 pmecorrV = avx128fma_pmecorrV_f(zeta2);
686 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
687 velec = _mm_mul_ps(qq30,velec);
689 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
691 /* Update potential sum for this i atom from the interaction with this j atom. */
692 velec = _mm_and_ps(velec,cutoff_mask);
693 velec = _mm_andnot_ps(dummy_mask,velec);
694 velecsum = _mm_add_ps(velecsum,velec);
698 fscal = _mm_and_ps(fscal,cutoff_mask);
700 fscal = _mm_andnot_ps(dummy_mask,fscal);
702 /* Update vectorial force */
703 fix3 = _mm_macc_ps(dx30,fscal,fix3);
704 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
705 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
707 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
708 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
709 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
713 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
714 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
715 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
716 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
718 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
720 /* Inner loop uses 146 flops */
723 /* End of innermost loop */
725 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
726 f+i_coord_offset,fshift+i_shift_offset);
729 /* Update potential energies */
730 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
731 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
733 /* Increment number of inner iterations */
734 inneriter += j_index_end - j_index_start;
736 /* Outer loop uses 26 flops */
739 /* Increment number of outer iterations */
742 /* Update outer/inner flops */
744 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*146);
747 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_single
748 * Electrostatics interaction: Ewald
749 * VdW interaction: LennardJones
750 * Geometry: Water4-Particle
751 * Calculate force/pot: Force
754 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_single
755 (t_nblist * gmx_restrict nlist,
756 rvec * gmx_restrict xx,
757 rvec * gmx_restrict ff,
758 struct t_forcerec * gmx_restrict fr,
759 t_mdatoms * gmx_restrict mdatoms,
760 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
761 t_nrnb * gmx_restrict nrnb)
763 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
764 * just 0 for non-waters.
765 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
766 * jnr indices corresponding to data put in the four positions in the SIMD register.
768 int i_shift_offset,i_coord_offset,outeriter,inneriter;
769 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
770 int jnrA,jnrB,jnrC,jnrD;
771 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
772 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
773 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
775 real *shiftvec,*fshift,*x,*f;
776 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
778 __m128 fscal,rcutoff,rcutoff2,jidxall;
780 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
782 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
784 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
786 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
787 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
788 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
789 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
790 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
791 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
792 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
793 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
796 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
799 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
800 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
802 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
803 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
805 __m128 dummy_mask,cutoff_mask;
806 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
807 __m128 one = _mm_set1_ps(1.0);
808 __m128 two = _mm_set1_ps(2.0);
814 jindex = nlist->jindex;
816 shiftidx = nlist->shift;
818 shiftvec = fr->shift_vec[0];
819 fshift = fr->fshift[0];
820 facel = _mm_set1_ps(fr->ic->epsfac);
821 charge = mdatoms->chargeA;
822 nvdwtype = fr->ntype;
824 vdwtype = mdatoms->typeA;
826 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
827 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
828 beta2 = _mm_mul_ps(beta,beta);
829 beta3 = _mm_mul_ps(beta,beta2);
830 ewtab = fr->ic->tabq_coul_F;
831 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
832 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
834 /* Setup water-specific parameters */
835 inr = nlist->iinr[0];
836 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
837 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
838 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
839 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
841 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
842 rcutoff_scalar = fr->ic->rcoulomb;
843 rcutoff = _mm_set1_ps(rcutoff_scalar);
844 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
846 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
847 rvdw = _mm_set1_ps(fr->ic->rvdw);
849 /* Avoid stupid compiler warnings */
850 jnrA = jnrB = jnrC = jnrD = 0;
859 for(iidx=0;iidx<4*DIM;iidx++)
864 /* Start outer loop over neighborlists */
865 for(iidx=0; iidx<nri; iidx++)
867 /* Load shift vector for this list */
868 i_shift_offset = DIM*shiftidx[iidx];
870 /* Load limits for loop over neighbors */
871 j_index_start = jindex[iidx];
872 j_index_end = jindex[iidx+1];
874 /* Get outer coordinate index */
876 i_coord_offset = DIM*inr;
878 /* Load i particle coords and add shift vector */
879 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
880 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
882 fix0 = _mm_setzero_ps();
883 fiy0 = _mm_setzero_ps();
884 fiz0 = _mm_setzero_ps();
885 fix1 = _mm_setzero_ps();
886 fiy1 = _mm_setzero_ps();
887 fiz1 = _mm_setzero_ps();
888 fix2 = _mm_setzero_ps();
889 fiy2 = _mm_setzero_ps();
890 fiz2 = _mm_setzero_ps();
891 fix3 = _mm_setzero_ps();
892 fiy3 = _mm_setzero_ps();
893 fiz3 = _mm_setzero_ps();
895 /* Start inner kernel loop */
896 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
899 /* Get j neighbor index, and coordinate index */
904 j_coord_offsetA = DIM*jnrA;
905 j_coord_offsetB = DIM*jnrB;
906 j_coord_offsetC = DIM*jnrC;
907 j_coord_offsetD = DIM*jnrD;
909 /* load j atom coordinates */
910 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
911 x+j_coord_offsetC,x+j_coord_offsetD,
914 /* Calculate displacement vector */
915 dx00 = _mm_sub_ps(ix0,jx0);
916 dy00 = _mm_sub_ps(iy0,jy0);
917 dz00 = _mm_sub_ps(iz0,jz0);
918 dx10 = _mm_sub_ps(ix1,jx0);
919 dy10 = _mm_sub_ps(iy1,jy0);
920 dz10 = _mm_sub_ps(iz1,jz0);
921 dx20 = _mm_sub_ps(ix2,jx0);
922 dy20 = _mm_sub_ps(iy2,jy0);
923 dz20 = _mm_sub_ps(iz2,jz0);
924 dx30 = _mm_sub_ps(ix3,jx0);
925 dy30 = _mm_sub_ps(iy3,jy0);
926 dz30 = _mm_sub_ps(iz3,jz0);
928 /* Calculate squared distance and things based on it */
929 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
930 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
931 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
932 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
934 rinv10 = avx128fma_invsqrt_f(rsq10);
935 rinv20 = avx128fma_invsqrt_f(rsq20);
936 rinv30 = avx128fma_invsqrt_f(rsq30);
938 rinvsq00 = avx128fma_inv_f(rsq00);
939 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
940 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
941 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
943 /* Load parameters for j particles */
944 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
945 charge+jnrC+0,charge+jnrD+0);
946 vdwjidx0A = 2*vdwtype[jnrA+0];
947 vdwjidx0B = 2*vdwtype[jnrB+0];
948 vdwjidx0C = 2*vdwtype[jnrC+0];
949 vdwjidx0D = 2*vdwtype[jnrD+0];
951 fjx0 = _mm_setzero_ps();
952 fjy0 = _mm_setzero_ps();
953 fjz0 = _mm_setzero_ps();
955 /**************************
956 * CALCULATE INTERACTIONS *
957 **************************/
959 if (gmx_mm_any_lt(rsq00,rcutoff2))
962 /* Compute parameters for interactions between i and j atoms */
963 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
964 vdwparam+vdwioffset0+vdwjidx0B,
965 vdwparam+vdwioffset0+vdwjidx0C,
966 vdwparam+vdwioffset0+vdwjidx0D,
969 /* LENNARD-JONES DISPERSION/REPULSION */
971 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
972 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
974 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
978 fscal = _mm_and_ps(fscal,cutoff_mask);
980 /* Update vectorial force */
981 fix0 = _mm_macc_ps(dx00,fscal,fix0);
982 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
983 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
985 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
986 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
987 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
991 /**************************
992 * CALCULATE INTERACTIONS *
993 **************************/
995 if (gmx_mm_any_lt(rsq10,rcutoff2))
998 r10 = _mm_mul_ps(rsq10,rinv10);
1000 /* Compute parameters for interactions between i and j atoms */
1001 qq10 = _mm_mul_ps(iq1,jq0);
1003 /* EWALD ELECTROSTATICS */
1005 /* Analytical PME correction */
1006 zeta2 = _mm_mul_ps(beta2,rsq10);
1007 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1008 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1009 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1010 felec = _mm_mul_ps(qq10,felec);
1012 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1016 fscal = _mm_and_ps(fscal,cutoff_mask);
1018 /* Update vectorial force */
1019 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1020 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1021 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1023 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1024 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1025 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1029 /**************************
1030 * CALCULATE INTERACTIONS *
1031 **************************/
1033 if (gmx_mm_any_lt(rsq20,rcutoff2))
1036 r20 = _mm_mul_ps(rsq20,rinv20);
1038 /* Compute parameters for interactions between i and j atoms */
1039 qq20 = _mm_mul_ps(iq2,jq0);
1041 /* EWALD ELECTROSTATICS */
1043 /* Analytical PME correction */
1044 zeta2 = _mm_mul_ps(beta2,rsq20);
1045 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1046 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1047 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1048 felec = _mm_mul_ps(qq20,felec);
1050 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1054 fscal = _mm_and_ps(fscal,cutoff_mask);
1056 /* Update vectorial force */
1057 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1058 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1059 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1061 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1062 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1063 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1067 /**************************
1068 * CALCULATE INTERACTIONS *
1069 **************************/
1071 if (gmx_mm_any_lt(rsq30,rcutoff2))
1074 r30 = _mm_mul_ps(rsq30,rinv30);
1076 /* Compute parameters for interactions between i and j atoms */
1077 qq30 = _mm_mul_ps(iq3,jq0);
1079 /* EWALD ELECTROSTATICS */
1081 /* Analytical PME correction */
1082 zeta2 = _mm_mul_ps(beta2,rsq30);
1083 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1084 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1085 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1086 felec = _mm_mul_ps(qq30,felec);
1088 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1092 fscal = _mm_and_ps(fscal,cutoff_mask);
1094 /* Update vectorial force */
1095 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1096 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1097 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1099 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1100 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1101 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1105 fjptrA = f+j_coord_offsetA;
1106 fjptrB = f+j_coord_offsetB;
1107 fjptrC = f+j_coord_offsetC;
1108 fjptrD = f+j_coord_offsetD;
1110 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1112 /* Inner loop uses 126 flops */
1115 if(jidx<j_index_end)
1118 /* Get j neighbor index, and coordinate index */
1119 jnrlistA = jjnr[jidx];
1120 jnrlistB = jjnr[jidx+1];
1121 jnrlistC = jjnr[jidx+2];
1122 jnrlistD = jjnr[jidx+3];
1123 /* Sign of each element will be negative for non-real atoms.
1124 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1125 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1127 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1128 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1129 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1130 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1131 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1132 j_coord_offsetA = DIM*jnrA;
1133 j_coord_offsetB = DIM*jnrB;
1134 j_coord_offsetC = DIM*jnrC;
1135 j_coord_offsetD = DIM*jnrD;
1137 /* load j atom coordinates */
1138 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1139 x+j_coord_offsetC,x+j_coord_offsetD,
1142 /* Calculate displacement vector */
1143 dx00 = _mm_sub_ps(ix0,jx0);
1144 dy00 = _mm_sub_ps(iy0,jy0);
1145 dz00 = _mm_sub_ps(iz0,jz0);
1146 dx10 = _mm_sub_ps(ix1,jx0);
1147 dy10 = _mm_sub_ps(iy1,jy0);
1148 dz10 = _mm_sub_ps(iz1,jz0);
1149 dx20 = _mm_sub_ps(ix2,jx0);
1150 dy20 = _mm_sub_ps(iy2,jy0);
1151 dz20 = _mm_sub_ps(iz2,jz0);
1152 dx30 = _mm_sub_ps(ix3,jx0);
1153 dy30 = _mm_sub_ps(iy3,jy0);
1154 dz30 = _mm_sub_ps(iz3,jz0);
1156 /* Calculate squared distance and things based on it */
1157 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1158 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1159 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1160 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1162 rinv10 = avx128fma_invsqrt_f(rsq10);
1163 rinv20 = avx128fma_invsqrt_f(rsq20);
1164 rinv30 = avx128fma_invsqrt_f(rsq30);
1166 rinvsq00 = avx128fma_inv_f(rsq00);
1167 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1168 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1169 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1171 /* Load parameters for j particles */
1172 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1173 charge+jnrC+0,charge+jnrD+0);
1174 vdwjidx0A = 2*vdwtype[jnrA+0];
1175 vdwjidx0B = 2*vdwtype[jnrB+0];
1176 vdwjidx0C = 2*vdwtype[jnrC+0];
1177 vdwjidx0D = 2*vdwtype[jnrD+0];
1179 fjx0 = _mm_setzero_ps();
1180 fjy0 = _mm_setzero_ps();
1181 fjz0 = _mm_setzero_ps();
1183 /**************************
1184 * CALCULATE INTERACTIONS *
1185 **************************/
1187 if (gmx_mm_any_lt(rsq00,rcutoff2))
1190 /* Compute parameters for interactions between i and j atoms */
1191 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1192 vdwparam+vdwioffset0+vdwjidx0B,
1193 vdwparam+vdwioffset0+vdwjidx0C,
1194 vdwparam+vdwioffset0+vdwjidx0D,
1197 /* LENNARD-JONES DISPERSION/REPULSION */
1199 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1200 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1202 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1206 fscal = _mm_and_ps(fscal,cutoff_mask);
1208 fscal = _mm_andnot_ps(dummy_mask,fscal);
1210 /* Update vectorial force */
1211 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1212 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1213 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1215 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1216 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1217 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1221 /**************************
1222 * CALCULATE INTERACTIONS *
1223 **************************/
1225 if (gmx_mm_any_lt(rsq10,rcutoff2))
1228 r10 = _mm_mul_ps(rsq10,rinv10);
1229 r10 = _mm_andnot_ps(dummy_mask,r10);
1231 /* Compute parameters for interactions between i and j atoms */
1232 qq10 = _mm_mul_ps(iq1,jq0);
1234 /* EWALD ELECTROSTATICS */
1236 /* Analytical PME correction */
1237 zeta2 = _mm_mul_ps(beta2,rsq10);
1238 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1239 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1240 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1241 felec = _mm_mul_ps(qq10,felec);
1243 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1247 fscal = _mm_and_ps(fscal,cutoff_mask);
1249 fscal = _mm_andnot_ps(dummy_mask,fscal);
1251 /* Update vectorial force */
1252 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1253 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1254 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1256 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1257 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1258 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1262 /**************************
1263 * CALCULATE INTERACTIONS *
1264 **************************/
1266 if (gmx_mm_any_lt(rsq20,rcutoff2))
1269 r20 = _mm_mul_ps(rsq20,rinv20);
1270 r20 = _mm_andnot_ps(dummy_mask,r20);
1272 /* Compute parameters for interactions between i and j atoms */
1273 qq20 = _mm_mul_ps(iq2,jq0);
1275 /* EWALD ELECTROSTATICS */
1277 /* Analytical PME correction */
1278 zeta2 = _mm_mul_ps(beta2,rsq20);
1279 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1280 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1281 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1282 felec = _mm_mul_ps(qq20,felec);
1284 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1288 fscal = _mm_and_ps(fscal,cutoff_mask);
1290 fscal = _mm_andnot_ps(dummy_mask,fscal);
1292 /* Update vectorial force */
1293 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1294 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1295 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1297 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1298 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1299 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1303 /**************************
1304 * CALCULATE INTERACTIONS *
1305 **************************/
1307 if (gmx_mm_any_lt(rsq30,rcutoff2))
1310 r30 = _mm_mul_ps(rsq30,rinv30);
1311 r30 = _mm_andnot_ps(dummy_mask,r30);
1313 /* Compute parameters for interactions between i and j atoms */
1314 qq30 = _mm_mul_ps(iq3,jq0);
1316 /* EWALD ELECTROSTATICS */
1318 /* Analytical PME correction */
1319 zeta2 = _mm_mul_ps(beta2,rsq30);
1320 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1321 pmecorrF = avx128fma_pmecorrF_f(zeta2);
1322 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1323 felec = _mm_mul_ps(qq30,felec);
1325 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1329 fscal = _mm_and_ps(fscal,cutoff_mask);
1331 fscal = _mm_andnot_ps(dummy_mask,fscal);
1333 /* Update vectorial force */
1334 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1335 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1336 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1338 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1339 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1340 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1344 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1345 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1346 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1347 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1349 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1351 /* Inner loop uses 129 flops */
1354 /* End of innermost loop */
1356 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1357 f+i_coord_offset,fshift+i_shift_offset);
1359 /* Increment number of inner iterations */
1360 inneriter += j_index_end - j_index_start;
1362 /* Outer loop uses 24 flops */
1365 /* Increment number of outer iterations */
1368 /* Update outer/inner flops */
1370 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*129);