2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
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_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
87 int vdwjidx0A,vdwjidx0B;
88 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
100 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
102 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
104 __m128d dummy_mask,cutoff_mask;
105 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
106 __m128d one = _mm_set1_pd(1.0);
107 __m128d two = _mm_set1_pd(2.0);
113 jindex = nlist->jindex;
115 shiftidx = nlist->shift;
117 shiftvec = fr->shift_vec[0];
118 fshift = fr->fshift[0];
119 facel = _mm_set1_pd(fr->ic->epsfac);
120 charge = mdatoms->chargeA;
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
126 ewtab = fr->ic->tabq_coul_FDV0;
127 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
128 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
130 /* Setup water-specific parameters */
131 inr = nlist->iinr[0];
132 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
133 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
134 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
135 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
137 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
138 rcutoff_scalar = fr->ic->rcoulomb;
139 rcutoff = _mm_set1_pd(rcutoff_scalar);
140 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
142 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
143 rvdw = _mm_set1_pd(fr->ic->rvdw);
145 /* Avoid stupid compiler warnings */
153 /* Start outer loop over neighborlists */
154 for(iidx=0; iidx<nri; iidx++)
156 /* Load shift vector for this list */
157 i_shift_offset = DIM*shiftidx[iidx];
159 /* Load limits for loop over neighbors */
160 j_index_start = jindex[iidx];
161 j_index_end = jindex[iidx+1];
163 /* Get outer coordinate index */
165 i_coord_offset = DIM*inr;
167 /* Load i particle coords and add shift vector */
168 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
169 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
171 fix0 = _mm_setzero_pd();
172 fiy0 = _mm_setzero_pd();
173 fiz0 = _mm_setzero_pd();
174 fix1 = _mm_setzero_pd();
175 fiy1 = _mm_setzero_pd();
176 fiz1 = _mm_setzero_pd();
177 fix2 = _mm_setzero_pd();
178 fiy2 = _mm_setzero_pd();
179 fiz2 = _mm_setzero_pd();
180 fix3 = _mm_setzero_pd();
181 fiy3 = _mm_setzero_pd();
182 fiz3 = _mm_setzero_pd();
184 /* Reset potential sums */
185 velecsum = _mm_setzero_pd();
186 vvdwsum = _mm_setzero_pd();
188 /* Start inner kernel loop */
189 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
192 /* Get j neighbor index, and coordinate index */
195 j_coord_offsetA = DIM*jnrA;
196 j_coord_offsetB = DIM*jnrB;
198 /* load j atom coordinates */
199 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
202 /* Calculate displacement vector */
203 dx00 = _mm_sub_pd(ix0,jx0);
204 dy00 = _mm_sub_pd(iy0,jy0);
205 dz00 = _mm_sub_pd(iz0,jz0);
206 dx10 = _mm_sub_pd(ix1,jx0);
207 dy10 = _mm_sub_pd(iy1,jy0);
208 dz10 = _mm_sub_pd(iz1,jz0);
209 dx20 = _mm_sub_pd(ix2,jx0);
210 dy20 = _mm_sub_pd(iy2,jy0);
211 dz20 = _mm_sub_pd(iz2,jz0);
212 dx30 = _mm_sub_pd(ix3,jx0);
213 dy30 = _mm_sub_pd(iy3,jy0);
214 dz30 = _mm_sub_pd(iz3,jz0);
216 /* Calculate squared distance and things based on it */
217 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
218 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
219 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
220 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
222 rinv10 = avx128fma_invsqrt_d(rsq10);
223 rinv20 = avx128fma_invsqrt_d(rsq20);
224 rinv30 = avx128fma_invsqrt_d(rsq30);
226 rinvsq00 = avx128fma_inv_d(rsq00);
227 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
228 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
229 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
231 /* Load parameters for j particles */
232 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
233 vdwjidx0A = 2*vdwtype[jnrA+0];
234 vdwjidx0B = 2*vdwtype[jnrB+0];
236 fjx0 = _mm_setzero_pd();
237 fjy0 = _mm_setzero_pd();
238 fjz0 = _mm_setzero_pd();
240 /**************************
241 * CALCULATE INTERACTIONS *
242 **************************/
244 if (gmx_mm_any_lt(rsq00,rcutoff2))
247 /* Compute parameters for interactions between i and j atoms */
248 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
249 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
251 /* LENNARD-JONES DISPERSION/REPULSION */
253 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
254 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
255 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
256 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
257 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
258 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
260 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 vvdw = _mm_and_pd(vvdw,cutoff_mask);
264 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
268 fscal = _mm_and_pd(fscal,cutoff_mask);
270 /* Update vectorial force */
271 fix0 = _mm_macc_pd(dx00,fscal,fix0);
272 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
273 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
275 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
276 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
277 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
281 /**************************
282 * CALCULATE INTERACTIONS *
283 **************************/
285 if (gmx_mm_any_lt(rsq10,rcutoff2))
288 r10 = _mm_mul_pd(rsq10,rinv10);
290 /* Compute parameters for interactions between i and j atoms */
291 qq10 = _mm_mul_pd(iq1,jq0);
293 /* EWALD ELECTROSTATICS */
295 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
296 ewrt = _mm_mul_pd(r10,ewtabscale);
297 ewitab = _mm_cvttpd_epi32(ewrt);
299 eweps = _mm_frcz_pd(ewrt);
301 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
303 twoeweps = _mm_add_pd(eweps,eweps);
304 ewitab = _mm_slli_epi32(ewitab,2);
305 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
306 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
307 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
308 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
309 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
310 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
311 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
312 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
313 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
314 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
316 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
318 /* Update potential sum for this i atom from the interaction with this j atom. */
319 velec = _mm_and_pd(velec,cutoff_mask);
320 velecsum = _mm_add_pd(velecsum,velec);
324 fscal = _mm_and_pd(fscal,cutoff_mask);
326 /* Update vectorial force */
327 fix1 = _mm_macc_pd(dx10,fscal,fix1);
328 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
329 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
331 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
332 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
333 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
337 /**************************
338 * CALCULATE INTERACTIONS *
339 **************************/
341 if (gmx_mm_any_lt(rsq20,rcutoff2))
344 r20 = _mm_mul_pd(rsq20,rinv20);
346 /* Compute parameters for interactions between i and j atoms */
347 qq20 = _mm_mul_pd(iq2,jq0);
349 /* EWALD ELECTROSTATICS */
351 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
352 ewrt = _mm_mul_pd(r20,ewtabscale);
353 ewitab = _mm_cvttpd_epi32(ewrt);
355 eweps = _mm_frcz_pd(ewrt);
357 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
359 twoeweps = _mm_add_pd(eweps,eweps);
360 ewitab = _mm_slli_epi32(ewitab,2);
361 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
362 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
363 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
364 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
365 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
366 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
367 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
368 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
369 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
370 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
372 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
374 /* Update potential sum for this i atom from the interaction with this j atom. */
375 velec = _mm_and_pd(velec,cutoff_mask);
376 velecsum = _mm_add_pd(velecsum,velec);
380 fscal = _mm_and_pd(fscal,cutoff_mask);
382 /* Update vectorial force */
383 fix2 = _mm_macc_pd(dx20,fscal,fix2);
384 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
385 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
387 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
388 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
389 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
393 /**************************
394 * CALCULATE INTERACTIONS *
395 **************************/
397 if (gmx_mm_any_lt(rsq30,rcutoff2))
400 r30 = _mm_mul_pd(rsq30,rinv30);
402 /* Compute parameters for interactions between i and j atoms */
403 qq30 = _mm_mul_pd(iq3,jq0);
405 /* EWALD ELECTROSTATICS */
407 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
408 ewrt = _mm_mul_pd(r30,ewtabscale);
409 ewitab = _mm_cvttpd_epi32(ewrt);
411 eweps = _mm_frcz_pd(ewrt);
413 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
415 twoeweps = _mm_add_pd(eweps,eweps);
416 ewitab = _mm_slli_epi32(ewitab,2);
417 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
418 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
419 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
420 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
421 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
422 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
423 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
424 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
425 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
426 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
428 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
430 /* Update potential sum for this i atom from the interaction with this j atom. */
431 velec = _mm_and_pd(velec,cutoff_mask);
432 velecsum = _mm_add_pd(velecsum,velec);
436 fscal = _mm_and_pd(fscal,cutoff_mask);
438 /* Update vectorial force */
439 fix3 = _mm_macc_pd(dx30,fscal,fix3);
440 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
441 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
443 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
444 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
445 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
449 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
451 /* Inner loop uses 194 flops */
458 j_coord_offsetA = DIM*jnrA;
460 /* load j atom coordinates */
461 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
464 /* Calculate displacement vector */
465 dx00 = _mm_sub_pd(ix0,jx0);
466 dy00 = _mm_sub_pd(iy0,jy0);
467 dz00 = _mm_sub_pd(iz0,jz0);
468 dx10 = _mm_sub_pd(ix1,jx0);
469 dy10 = _mm_sub_pd(iy1,jy0);
470 dz10 = _mm_sub_pd(iz1,jz0);
471 dx20 = _mm_sub_pd(ix2,jx0);
472 dy20 = _mm_sub_pd(iy2,jy0);
473 dz20 = _mm_sub_pd(iz2,jz0);
474 dx30 = _mm_sub_pd(ix3,jx0);
475 dy30 = _mm_sub_pd(iy3,jy0);
476 dz30 = _mm_sub_pd(iz3,jz0);
478 /* Calculate squared distance and things based on it */
479 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
480 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
481 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
482 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
484 rinv10 = avx128fma_invsqrt_d(rsq10);
485 rinv20 = avx128fma_invsqrt_d(rsq20);
486 rinv30 = avx128fma_invsqrt_d(rsq30);
488 rinvsq00 = avx128fma_inv_d(rsq00);
489 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
490 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
491 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
493 /* Load parameters for j particles */
494 jq0 = _mm_load_sd(charge+jnrA+0);
495 vdwjidx0A = 2*vdwtype[jnrA+0];
497 fjx0 = _mm_setzero_pd();
498 fjy0 = _mm_setzero_pd();
499 fjz0 = _mm_setzero_pd();
501 /**************************
502 * CALCULATE INTERACTIONS *
503 **************************/
505 if (gmx_mm_any_lt(rsq00,rcutoff2))
508 /* Compute parameters for interactions between i and j atoms */
509 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
511 /* LENNARD-JONES DISPERSION/REPULSION */
513 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
514 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
515 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
516 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
517 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
518 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
520 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
522 /* Update potential sum for this i atom from the interaction with this j atom. */
523 vvdw = _mm_and_pd(vvdw,cutoff_mask);
524 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
525 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
529 fscal = _mm_and_pd(fscal,cutoff_mask);
531 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
533 /* Update vectorial force */
534 fix0 = _mm_macc_pd(dx00,fscal,fix0);
535 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
536 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
538 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
539 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
540 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
544 /**************************
545 * CALCULATE INTERACTIONS *
546 **************************/
548 if (gmx_mm_any_lt(rsq10,rcutoff2))
551 r10 = _mm_mul_pd(rsq10,rinv10);
553 /* Compute parameters for interactions between i and j atoms */
554 qq10 = _mm_mul_pd(iq1,jq0);
556 /* EWALD ELECTROSTATICS */
558 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
559 ewrt = _mm_mul_pd(r10,ewtabscale);
560 ewitab = _mm_cvttpd_epi32(ewrt);
562 eweps = _mm_frcz_pd(ewrt);
564 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
566 twoeweps = _mm_add_pd(eweps,eweps);
567 ewitab = _mm_slli_epi32(ewitab,2);
568 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
569 ewtabD = _mm_setzero_pd();
570 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
571 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
572 ewtabFn = _mm_setzero_pd();
573 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
574 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
575 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
576 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
577 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
579 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
581 /* Update potential sum for this i atom from the interaction with this j atom. */
582 velec = _mm_and_pd(velec,cutoff_mask);
583 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
584 velecsum = _mm_add_pd(velecsum,velec);
588 fscal = _mm_and_pd(fscal,cutoff_mask);
590 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
592 /* Update vectorial force */
593 fix1 = _mm_macc_pd(dx10,fscal,fix1);
594 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
595 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
597 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
598 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
599 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
603 /**************************
604 * CALCULATE INTERACTIONS *
605 **************************/
607 if (gmx_mm_any_lt(rsq20,rcutoff2))
610 r20 = _mm_mul_pd(rsq20,rinv20);
612 /* Compute parameters for interactions between i and j atoms */
613 qq20 = _mm_mul_pd(iq2,jq0);
615 /* EWALD ELECTROSTATICS */
617 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
618 ewrt = _mm_mul_pd(r20,ewtabscale);
619 ewitab = _mm_cvttpd_epi32(ewrt);
621 eweps = _mm_frcz_pd(ewrt);
623 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
625 twoeweps = _mm_add_pd(eweps,eweps);
626 ewitab = _mm_slli_epi32(ewitab,2);
627 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
628 ewtabD = _mm_setzero_pd();
629 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
630 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
631 ewtabFn = _mm_setzero_pd();
632 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
633 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
634 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
635 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
636 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
638 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
640 /* Update potential sum for this i atom from the interaction with this j atom. */
641 velec = _mm_and_pd(velec,cutoff_mask);
642 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
643 velecsum = _mm_add_pd(velecsum,velec);
647 fscal = _mm_and_pd(fscal,cutoff_mask);
649 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
651 /* Update vectorial force */
652 fix2 = _mm_macc_pd(dx20,fscal,fix2);
653 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
654 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
656 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
657 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
658 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
666 if (gmx_mm_any_lt(rsq30,rcutoff2))
669 r30 = _mm_mul_pd(rsq30,rinv30);
671 /* Compute parameters for interactions between i and j atoms */
672 qq30 = _mm_mul_pd(iq3,jq0);
674 /* EWALD ELECTROSTATICS */
676 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
677 ewrt = _mm_mul_pd(r30,ewtabscale);
678 ewitab = _mm_cvttpd_epi32(ewrt);
680 eweps = _mm_frcz_pd(ewrt);
682 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
684 twoeweps = _mm_add_pd(eweps,eweps);
685 ewitab = _mm_slli_epi32(ewitab,2);
686 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
687 ewtabD = _mm_setzero_pd();
688 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
689 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
690 ewtabFn = _mm_setzero_pd();
691 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
692 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
693 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
694 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
695 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
697 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
699 /* Update potential sum for this i atom from the interaction with this j atom. */
700 velec = _mm_and_pd(velec,cutoff_mask);
701 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
702 velecsum = _mm_add_pd(velecsum,velec);
706 fscal = _mm_and_pd(fscal,cutoff_mask);
708 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
710 /* Update vectorial force */
711 fix3 = _mm_macc_pd(dx30,fscal,fix3);
712 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
713 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
715 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
716 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
717 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
721 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
723 /* Inner loop uses 194 flops */
726 /* End of innermost loop */
728 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
729 f+i_coord_offset,fshift+i_shift_offset);
732 /* Update potential energies */
733 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
734 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
736 /* Increment number of inner iterations */
737 inneriter += j_index_end - j_index_start;
739 /* Outer loop uses 26 flops */
742 /* Increment number of outer iterations */
745 /* Update outer/inner flops */
747 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*194);
750 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_double
751 * Electrostatics interaction: Ewald
752 * VdW interaction: LennardJones
753 * Geometry: Water4-Particle
754 * Calculate force/pot: Force
757 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_double
758 (t_nblist * gmx_restrict nlist,
759 rvec * gmx_restrict xx,
760 rvec * gmx_restrict ff,
761 struct t_forcerec * gmx_restrict fr,
762 t_mdatoms * gmx_restrict mdatoms,
763 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
764 t_nrnb * gmx_restrict nrnb)
766 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
767 * just 0 for non-waters.
768 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
769 * jnr indices corresponding to data put in the four positions in the SIMD register.
771 int i_shift_offset,i_coord_offset,outeriter,inneriter;
772 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
774 int j_coord_offsetA,j_coord_offsetB;
775 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
777 real *shiftvec,*fshift,*x,*f;
778 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
780 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
782 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
784 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
786 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
787 int vdwjidx0A,vdwjidx0B;
788 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
789 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
790 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
791 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
792 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
793 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
796 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
799 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
800 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
802 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
804 __m128d dummy_mask,cutoff_mask;
805 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
806 __m128d one = _mm_set1_pd(1.0);
807 __m128d two = _mm_set1_pd(2.0);
813 jindex = nlist->jindex;
815 shiftidx = nlist->shift;
817 shiftvec = fr->shift_vec[0];
818 fshift = fr->fshift[0];
819 facel = _mm_set1_pd(fr->ic->epsfac);
820 charge = mdatoms->chargeA;
821 nvdwtype = fr->ntype;
823 vdwtype = mdatoms->typeA;
825 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
826 ewtab = fr->ic->tabq_coul_F;
827 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
828 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
830 /* Setup water-specific parameters */
831 inr = nlist->iinr[0];
832 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
833 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
834 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
835 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
837 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
838 rcutoff_scalar = fr->ic->rcoulomb;
839 rcutoff = _mm_set1_pd(rcutoff_scalar);
840 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
842 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
843 rvdw = _mm_set1_pd(fr->ic->rvdw);
845 /* Avoid stupid compiler warnings */
853 /* Start outer loop over neighborlists */
854 for(iidx=0; iidx<nri; iidx++)
856 /* Load shift vector for this list */
857 i_shift_offset = DIM*shiftidx[iidx];
859 /* Load limits for loop over neighbors */
860 j_index_start = jindex[iidx];
861 j_index_end = jindex[iidx+1];
863 /* Get outer coordinate index */
865 i_coord_offset = DIM*inr;
867 /* Load i particle coords and add shift vector */
868 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
869 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
871 fix0 = _mm_setzero_pd();
872 fiy0 = _mm_setzero_pd();
873 fiz0 = _mm_setzero_pd();
874 fix1 = _mm_setzero_pd();
875 fiy1 = _mm_setzero_pd();
876 fiz1 = _mm_setzero_pd();
877 fix2 = _mm_setzero_pd();
878 fiy2 = _mm_setzero_pd();
879 fiz2 = _mm_setzero_pd();
880 fix3 = _mm_setzero_pd();
881 fiy3 = _mm_setzero_pd();
882 fiz3 = _mm_setzero_pd();
884 /* Start inner kernel loop */
885 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
888 /* Get j neighbor index, and coordinate index */
891 j_coord_offsetA = DIM*jnrA;
892 j_coord_offsetB = DIM*jnrB;
894 /* load j atom coordinates */
895 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
898 /* Calculate displacement vector */
899 dx00 = _mm_sub_pd(ix0,jx0);
900 dy00 = _mm_sub_pd(iy0,jy0);
901 dz00 = _mm_sub_pd(iz0,jz0);
902 dx10 = _mm_sub_pd(ix1,jx0);
903 dy10 = _mm_sub_pd(iy1,jy0);
904 dz10 = _mm_sub_pd(iz1,jz0);
905 dx20 = _mm_sub_pd(ix2,jx0);
906 dy20 = _mm_sub_pd(iy2,jy0);
907 dz20 = _mm_sub_pd(iz2,jz0);
908 dx30 = _mm_sub_pd(ix3,jx0);
909 dy30 = _mm_sub_pd(iy3,jy0);
910 dz30 = _mm_sub_pd(iz3,jz0);
912 /* Calculate squared distance and things based on it */
913 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
914 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
915 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
916 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
918 rinv10 = avx128fma_invsqrt_d(rsq10);
919 rinv20 = avx128fma_invsqrt_d(rsq20);
920 rinv30 = avx128fma_invsqrt_d(rsq30);
922 rinvsq00 = avx128fma_inv_d(rsq00);
923 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
924 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
925 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
927 /* Load parameters for j particles */
928 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
929 vdwjidx0A = 2*vdwtype[jnrA+0];
930 vdwjidx0B = 2*vdwtype[jnrB+0];
932 fjx0 = _mm_setzero_pd();
933 fjy0 = _mm_setzero_pd();
934 fjz0 = _mm_setzero_pd();
936 /**************************
937 * CALCULATE INTERACTIONS *
938 **************************/
940 if (gmx_mm_any_lt(rsq00,rcutoff2))
943 /* Compute parameters for interactions between i and j atoms */
944 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
945 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
947 /* LENNARD-JONES DISPERSION/REPULSION */
949 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
950 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
952 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
956 fscal = _mm_and_pd(fscal,cutoff_mask);
958 /* Update vectorial force */
959 fix0 = _mm_macc_pd(dx00,fscal,fix0);
960 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
961 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
963 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
964 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
965 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
969 /**************************
970 * CALCULATE INTERACTIONS *
971 **************************/
973 if (gmx_mm_any_lt(rsq10,rcutoff2))
976 r10 = _mm_mul_pd(rsq10,rinv10);
978 /* Compute parameters for interactions between i and j atoms */
979 qq10 = _mm_mul_pd(iq1,jq0);
981 /* EWALD ELECTROSTATICS */
983 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
984 ewrt = _mm_mul_pd(r10,ewtabscale);
985 ewitab = _mm_cvttpd_epi32(ewrt);
987 eweps = _mm_frcz_pd(ewrt);
989 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
991 twoeweps = _mm_add_pd(eweps,eweps);
992 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
994 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
995 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
997 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1001 fscal = _mm_and_pd(fscal,cutoff_mask);
1003 /* Update vectorial force */
1004 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1005 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1006 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1008 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1009 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1010 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1014 /**************************
1015 * CALCULATE INTERACTIONS *
1016 **************************/
1018 if (gmx_mm_any_lt(rsq20,rcutoff2))
1021 r20 = _mm_mul_pd(rsq20,rinv20);
1023 /* Compute parameters for interactions between i and j atoms */
1024 qq20 = _mm_mul_pd(iq2,jq0);
1026 /* EWALD ELECTROSTATICS */
1028 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1029 ewrt = _mm_mul_pd(r20,ewtabscale);
1030 ewitab = _mm_cvttpd_epi32(ewrt);
1032 eweps = _mm_frcz_pd(ewrt);
1034 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1036 twoeweps = _mm_add_pd(eweps,eweps);
1037 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
1039 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1040 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1042 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1046 fscal = _mm_and_pd(fscal,cutoff_mask);
1048 /* Update vectorial force */
1049 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1050 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1051 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1053 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1054 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1055 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1059 /**************************
1060 * CALCULATE INTERACTIONS *
1061 **************************/
1063 if (gmx_mm_any_lt(rsq30,rcutoff2))
1066 r30 = _mm_mul_pd(rsq30,rinv30);
1068 /* Compute parameters for interactions between i and j atoms */
1069 qq30 = _mm_mul_pd(iq3,jq0);
1071 /* EWALD ELECTROSTATICS */
1073 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1074 ewrt = _mm_mul_pd(r30,ewtabscale);
1075 ewitab = _mm_cvttpd_epi32(ewrt);
1077 eweps = _mm_frcz_pd(ewrt);
1079 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1081 twoeweps = _mm_add_pd(eweps,eweps);
1082 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
1084 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1085 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1087 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1091 fscal = _mm_and_pd(fscal,cutoff_mask);
1093 /* Update vectorial force */
1094 fix3 = _mm_macc_pd(dx30,fscal,fix3);
1095 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
1096 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
1098 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
1099 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
1100 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
1104 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1106 /* Inner loop uses 162 flops */
1109 if(jidx<j_index_end)
1113 j_coord_offsetA = DIM*jnrA;
1115 /* load j atom coordinates */
1116 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1119 /* Calculate displacement vector */
1120 dx00 = _mm_sub_pd(ix0,jx0);
1121 dy00 = _mm_sub_pd(iy0,jy0);
1122 dz00 = _mm_sub_pd(iz0,jz0);
1123 dx10 = _mm_sub_pd(ix1,jx0);
1124 dy10 = _mm_sub_pd(iy1,jy0);
1125 dz10 = _mm_sub_pd(iz1,jz0);
1126 dx20 = _mm_sub_pd(ix2,jx0);
1127 dy20 = _mm_sub_pd(iy2,jy0);
1128 dz20 = _mm_sub_pd(iz2,jz0);
1129 dx30 = _mm_sub_pd(ix3,jx0);
1130 dy30 = _mm_sub_pd(iy3,jy0);
1131 dz30 = _mm_sub_pd(iz3,jz0);
1133 /* Calculate squared distance and things based on it */
1134 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1135 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1136 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1137 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
1139 rinv10 = avx128fma_invsqrt_d(rsq10);
1140 rinv20 = avx128fma_invsqrt_d(rsq20);
1141 rinv30 = avx128fma_invsqrt_d(rsq30);
1143 rinvsq00 = avx128fma_inv_d(rsq00);
1144 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
1145 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
1146 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
1148 /* Load parameters for j particles */
1149 jq0 = _mm_load_sd(charge+jnrA+0);
1150 vdwjidx0A = 2*vdwtype[jnrA+0];
1152 fjx0 = _mm_setzero_pd();
1153 fjy0 = _mm_setzero_pd();
1154 fjz0 = _mm_setzero_pd();
1156 /**************************
1157 * CALCULATE INTERACTIONS *
1158 **************************/
1160 if (gmx_mm_any_lt(rsq00,rcutoff2))
1163 /* Compute parameters for interactions between i and j atoms */
1164 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
1166 /* LENNARD-JONES DISPERSION/REPULSION */
1168 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1169 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1171 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
1175 fscal = _mm_and_pd(fscal,cutoff_mask);
1177 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1179 /* Update vectorial force */
1180 fix0 = _mm_macc_pd(dx00,fscal,fix0);
1181 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
1182 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
1184 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
1185 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
1186 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
1190 /**************************
1191 * CALCULATE INTERACTIONS *
1192 **************************/
1194 if (gmx_mm_any_lt(rsq10,rcutoff2))
1197 r10 = _mm_mul_pd(rsq10,rinv10);
1199 /* Compute parameters for interactions between i and j atoms */
1200 qq10 = _mm_mul_pd(iq1,jq0);
1202 /* EWALD ELECTROSTATICS */
1204 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1205 ewrt = _mm_mul_pd(r10,ewtabscale);
1206 ewitab = _mm_cvttpd_epi32(ewrt);
1208 eweps = _mm_frcz_pd(ewrt);
1210 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1212 twoeweps = _mm_add_pd(eweps,eweps);
1213 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1214 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1215 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
1217 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1221 fscal = _mm_and_pd(fscal,cutoff_mask);
1223 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1225 /* Update vectorial force */
1226 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1227 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1228 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1230 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1231 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1232 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1236 /**************************
1237 * CALCULATE INTERACTIONS *
1238 **************************/
1240 if (gmx_mm_any_lt(rsq20,rcutoff2))
1243 r20 = _mm_mul_pd(rsq20,rinv20);
1245 /* Compute parameters for interactions between i and j atoms */
1246 qq20 = _mm_mul_pd(iq2,jq0);
1248 /* EWALD ELECTROSTATICS */
1250 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1251 ewrt = _mm_mul_pd(r20,ewtabscale);
1252 ewitab = _mm_cvttpd_epi32(ewrt);
1254 eweps = _mm_frcz_pd(ewrt);
1256 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1258 twoeweps = _mm_add_pd(eweps,eweps);
1259 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1260 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1261 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1263 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1267 fscal = _mm_and_pd(fscal,cutoff_mask);
1269 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1271 /* Update vectorial force */
1272 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1273 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1274 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1276 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1277 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1278 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1282 /**************************
1283 * CALCULATE INTERACTIONS *
1284 **************************/
1286 if (gmx_mm_any_lt(rsq30,rcutoff2))
1289 r30 = _mm_mul_pd(rsq30,rinv30);
1291 /* Compute parameters for interactions between i and j atoms */
1292 qq30 = _mm_mul_pd(iq3,jq0);
1294 /* EWALD ELECTROSTATICS */
1296 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1297 ewrt = _mm_mul_pd(r30,ewtabscale);
1298 ewitab = _mm_cvttpd_epi32(ewrt);
1300 eweps = _mm_frcz_pd(ewrt);
1302 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1304 twoeweps = _mm_add_pd(eweps,eweps);
1305 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1306 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1307 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1309 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1313 fscal = _mm_and_pd(fscal,cutoff_mask);
1315 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1317 /* Update vectorial force */
1318 fix3 = _mm_macc_pd(dx30,fscal,fix3);
1319 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
1320 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
1322 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
1323 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
1324 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
1328 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1330 /* Inner loop uses 162 flops */
1333 /* End of innermost loop */
1335 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1336 f+i_coord_offset,fshift+i_shift_offset);
1338 /* Increment number of inner iterations */
1339 inneriter += j_index_end - j_index_start;
1341 /* Outer loop uses 24 flops */
1344 /* Increment number of outer iterations */
1347 /* Update outer/inner flops */
1349 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*162);