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_double 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_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
101 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
103 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
105 __m128d dummy_mask,cutoff_mask;
106 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
107 __m128d one = _mm_set1_pd(1.0);
108 __m128d two = _mm_set1_pd(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_pd(fr->epsfac);
121 charge = mdatoms->chargeA;
122 nvdwtype = fr->ntype;
124 vdwtype = mdatoms->typeA;
126 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
127 ewtab = fr->ic->tabq_coul_FDV0;
128 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
129 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
131 /* Setup water-specific parameters */
132 inr = nlist->iinr[0];
133 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
134 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
135 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
136 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
138 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
139 rcutoff_scalar = fr->rcoulomb;
140 rcutoff = _mm_set1_pd(rcutoff_scalar);
141 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
143 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
144 rvdw = _mm_set1_pd(fr->rvdw);
146 /* Avoid stupid compiler warnings */
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
172 fix0 = _mm_setzero_pd();
173 fiy0 = _mm_setzero_pd();
174 fiz0 = _mm_setzero_pd();
175 fix1 = _mm_setzero_pd();
176 fiy1 = _mm_setzero_pd();
177 fiz1 = _mm_setzero_pd();
178 fix2 = _mm_setzero_pd();
179 fiy2 = _mm_setzero_pd();
180 fiz2 = _mm_setzero_pd();
181 fix3 = _mm_setzero_pd();
182 fiy3 = _mm_setzero_pd();
183 fiz3 = _mm_setzero_pd();
185 /* Reset potential sums */
186 velecsum = _mm_setzero_pd();
187 vvdwsum = _mm_setzero_pd();
189 /* Start inner kernel loop */
190 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
193 /* Get j neighbor index, and coordinate index */
196 j_coord_offsetA = DIM*jnrA;
197 j_coord_offsetB = DIM*jnrB;
199 /* load j atom coordinates */
200 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
203 /* Calculate displacement vector */
204 dx00 = _mm_sub_pd(ix0,jx0);
205 dy00 = _mm_sub_pd(iy0,jy0);
206 dz00 = _mm_sub_pd(iz0,jz0);
207 dx10 = _mm_sub_pd(ix1,jx0);
208 dy10 = _mm_sub_pd(iy1,jy0);
209 dz10 = _mm_sub_pd(iz1,jz0);
210 dx20 = _mm_sub_pd(ix2,jx0);
211 dy20 = _mm_sub_pd(iy2,jy0);
212 dz20 = _mm_sub_pd(iz2,jz0);
213 dx30 = _mm_sub_pd(ix3,jx0);
214 dy30 = _mm_sub_pd(iy3,jy0);
215 dz30 = _mm_sub_pd(iz3,jz0);
217 /* Calculate squared distance and things based on it */
218 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
219 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
220 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
221 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
223 rinv10 = gmx_mm_invsqrt_pd(rsq10);
224 rinv20 = gmx_mm_invsqrt_pd(rsq20);
225 rinv30 = gmx_mm_invsqrt_pd(rsq30);
227 rinvsq00 = gmx_mm_inv_pd(rsq00);
228 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
229 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
230 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
232 /* Load parameters for j particles */
233 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
234 vdwjidx0A = 2*vdwtype[jnrA+0];
235 vdwjidx0B = 2*vdwtype[jnrB+0];
237 fjx0 = _mm_setzero_pd();
238 fjy0 = _mm_setzero_pd();
239 fjz0 = _mm_setzero_pd();
241 /**************************
242 * CALCULATE INTERACTIONS *
243 **************************/
245 if (gmx_mm_any_lt(rsq00,rcutoff2))
248 /* Compute parameters for interactions between i and j atoms */
249 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
250 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
252 /* LENNARD-JONES DISPERSION/REPULSION */
254 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
255 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
256 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
257 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
258 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
259 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
261 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
263 /* Update potential sum for this i atom from the interaction with this j atom. */
264 vvdw = _mm_and_pd(vvdw,cutoff_mask);
265 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
269 fscal = _mm_and_pd(fscal,cutoff_mask);
271 /* Update vectorial force */
272 fix0 = _mm_macc_pd(dx00,fscal,fix0);
273 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
274 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
276 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
277 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
278 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
282 /**************************
283 * CALCULATE INTERACTIONS *
284 **************************/
286 if (gmx_mm_any_lt(rsq10,rcutoff2))
289 r10 = _mm_mul_pd(rsq10,rinv10);
291 /* Compute parameters for interactions between i and j atoms */
292 qq10 = _mm_mul_pd(iq1,jq0);
294 /* EWALD ELECTROSTATICS */
296 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
297 ewrt = _mm_mul_pd(r10,ewtabscale);
298 ewitab = _mm_cvttpd_epi32(ewrt);
300 eweps = _mm_frcz_pd(ewrt);
302 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
304 twoeweps = _mm_add_pd(eweps,eweps);
305 ewitab = _mm_slli_epi32(ewitab,2);
306 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
307 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
308 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
309 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
310 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
311 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
312 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
313 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
314 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
315 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
317 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
319 /* Update potential sum for this i atom from the interaction with this j atom. */
320 velec = _mm_and_pd(velec,cutoff_mask);
321 velecsum = _mm_add_pd(velecsum,velec);
325 fscal = _mm_and_pd(fscal,cutoff_mask);
327 /* Update vectorial force */
328 fix1 = _mm_macc_pd(dx10,fscal,fix1);
329 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
330 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
332 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
333 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
334 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
338 /**************************
339 * CALCULATE INTERACTIONS *
340 **************************/
342 if (gmx_mm_any_lt(rsq20,rcutoff2))
345 r20 = _mm_mul_pd(rsq20,rinv20);
347 /* Compute parameters for interactions between i and j atoms */
348 qq20 = _mm_mul_pd(iq2,jq0);
350 /* EWALD ELECTROSTATICS */
352 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
353 ewrt = _mm_mul_pd(r20,ewtabscale);
354 ewitab = _mm_cvttpd_epi32(ewrt);
356 eweps = _mm_frcz_pd(ewrt);
358 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
360 twoeweps = _mm_add_pd(eweps,eweps);
361 ewitab = _mm_slli_epi32(ewitab,2);
362 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
363 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
364 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
365 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
366 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
367 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
368 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
369 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
370 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
371 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
373 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
375 /* Update potential sum for this i atom from the interaction with this j atom. */
376 velec = _mm_and_pd(velec,cutoff_mask);
377 velecsum = _mm_add_pd(velecsum,velec);
381 fscal = _mm_and_pd(fscal,cutoff_mask);
383 /* Update vectorial force */
384 fix2 = _mm_macc_pd(dx20,fscal,fix2);
385 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
386 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
388 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
389 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
390 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
394 /**************************
395 * CALCULATE INTERACTIONS *
396 **************************/
398 if (gmx_mm_any_lt(rsq30,rcutoff2))
401 r30 = _mm_mul_pd(rsq30,rinv30);
403 /* Compute parameters for interactions between i and j atoms */
404 qq30 = _mm_mul_pd(iq3,jq0);
406 /* EWALD ELECTROSTATICS */
408 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
409 ewrt = _mm_mul_pd(r30,ewtabscale);
410 ewitab = _mm_cvttpd_epi32(ewrt);
412 eweps = _mm_frcz_pd(ewrt);
414 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
416 twoeweps = _mm_add_pd(eweps,eweps);
417 ewitab = _mm_slli_epi32(ewitab,2);
418 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
419 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
420 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
421 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
422 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
423 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
424 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
425 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
426 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
427 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
429 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
431 /* Update potential sum for this i atom from the interaction with this j atom. */
432 velec = _mm_and_pd(velec,cutoff_mask);
433 velecsum = _mm_add_pd(velecsum,velec);
437 fscal = _mm_and_pd(fscal,cutoff_mask);
439 /* Update vectorial force */
440 fix3 = _mm_macc_pd(dx30,fscal,fix3);
441 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
442 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
444 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
445 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
446 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
450 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
452 /* Inner loop uses 194 flops */
459 j_coord_offsetA = DIM*jnrA;
461 /* load j atom coordinates */
462 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
465 /* Calculate displacement vector */
466 dx00 = _mm_sub_pd(ix0,jx0);
467 dy00 = _mm_sub_pd(iy0,jy0);
468 dz00 = _mm_sub_pd(iz0,jz0);
469 dx10 = _mm_sub_pd(ix1,jx0);
470 dy10 = _mm_sub_pd(iy1,jy0);
471 dz10 = _mm_sub_pd(iz1,jz0);
472 dx20 = _mm_sub_pd(ix2,jx0);
473 dy20 = _mm_sub_pd(iy2,jy0);
474 dz20 = _mm_sub_pd(iz2,jz0);
475 dx30 = _mm_sub_pd(ix3,jx0);
476 dy30 = _mm_sub_pd(iy3,jy0);
477 dz30 = _mm_sub_pd(iz3,jz0);
479 /* Calculate squared distance and things based on it */
480 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
481 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
482 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
483 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
485 rinv10 = gmx_mm_invsqrt_pd(rsq10);
486 rinv20 = gmx_mm_invsqrt_pd(rsq20);
487 rinv30 = gmx_mm_invsqrt_pd(rsq30);
489 rinvsq00 = gmx_mm_inv_pd(rsq00);
490 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
491 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
492 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
494 /* Load parameters for j particles */
495 jq0 = _mm_load_sd(charge+jnrA+0);
496 vdwjidx0A = 2*vdwtype[jnrA+0];
498 fjx0 = _mm_setzero_pd();
499 fjy0 = _mm_setzero_pd();
500 fjz0 = _mm_setzero_pd();
502 /**************************
503 * CALCULATE INTERACTIONS *
504 **************************/
506 if (gmx_mm_any_lt(rsq00,rcutoff2))
509 /* Compute parameters for interactions between i and j atoms */
510 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
512 /* LENNARD-JONES DISPERSION/REPULSION */
514 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
515 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
516 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
517 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
518 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
519 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
521 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
523 /* Update potential sum for this i atom from the interaction with this j atom. */
524 vvdw = _mm_and_pd(vvdw,cutoff_mask);
525 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
526 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
530 fscal = _mm_and_pd(fscal,cutoff_mask);
532 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
534 /* Update vectorial force */
535 fix0 = _mm_macc_pd(dx00,fscal,fix0);
536 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
537 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
539 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
540 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
541 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
545 /**************************
546 * CALCULATE INTERACTIONS *
547 **************************/
549 if (gmx_mm_any_lt(rsq10,rcutoff2))
552 r10 = _mm_mul_pd(rsq10,rinv10);
554 /* Compute parameters for interactions between i and j atoms */
555 qq10 = _mm_mul_pd(iq1,jq0);
557 /* EWALD ELECTROSTATICS */
559 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
560 ewrt = _mm_mul_pd(r10,ewtabscale);
561 ewitab = _mm_cvttpd_epi32(ewrt);
563 eweps = _mm_frcz_pd(ewrt);
565 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
567 twoeweps = _mm_add_pd(eweps,eweps);
568 ewitab = _mm_slli_epi32(ewitab,2);
569 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
570 ewtabD = _mm_setzero_pd();
571 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
572 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
573 ewtabFn = _mm_setzero_pd();
574 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
575 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
576 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
577 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
578 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
580 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
582 /* Update potential sum for this i atom from the interaction with this j atom. */
583 velec = _mm_and_pd(velec,cutoff_mask);
584 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
585 velecsum = _mm_add_pd(velecsum,velec);
589 fscal = _mm_and_pd(fscal,cutoff_mask);
591 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
593 /* Update vectorial force */
594 fix1 = _mm_macc_pd(dx10,fscal,fix1);
595 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
596 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
598 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
599 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
600 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
604 /**************************
605 * CALCULATE INTERACTIONS *
606 **************************/
608 if (gmx_mm_any_lt(rsq20,rcutoff2))
611 r20 = _mm_mul_pd(rsq20,rinv20);
613 /* Compute parameters for interactions between i and j atoms */
614 qq20 = _mm_mul_pd(iq2,jq0);
616 /* EWALD ELECTROSTATICS */
618 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
619 ewrt = _mm_mul_pd(r20,ewtabscale);
620 ewitab = _mm_cvttpd_epi32(ewrt);
622 eweps = _mm_frcz_pd(ewrt);
624 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
626 twoeweps = _mm_add_pd(eweps,eweps);
627 ewitab = _mm_slli_epi32(ewitab,2);
628 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
629 ewtabD = _mm_setzero_pd();
630 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
631 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
632 ewtabFn = _mm_setzero_pd();
633 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
634 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
635 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
636 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
637 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
639 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
641 /* Update potential sum for this i atom from the interaction with this j atom. */
642 velec = _mm_and_pd(velec,cutoff_mask);
643 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
644 velecsum = _mm_add_pd(velecsum,velec);
648 fscal = _mm_and_pd(fscal,cutoff_mask);
650 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
652 /* Update vectorial force */
653 fix2 = _mm_macc_pd(dx20,fscal,fix2);
654 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
655 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
657 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
658 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
659 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
663 /**************************
664 * CALCULATE INTERACTIONS *
665 **************************/
667 if (gmx_mm_any_lt(rsq30,rcutoff2))
670 r30 = _mm_mul_pd(rsq30,rinv30);
672 /* Compute parameters for interactions between i and j atoms */
673 qq30 = _mm_mul_pd(iq3,jq0);
675 /* EWALD ELECTROSTATICS */
677 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
678 ewrt = _mm_mul_pd(r30,ewtabscale);
679 ewitab = _mm_cvttpd_epi32(ewrt);
681 eweps = _mm_frcz_pd(ewrt);
683 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
685 twoeweps = _mm_add_pd(eweps,eweps);
686 ewitab = _mm_slli_epi32(ewitab,2);
687 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
688 ewtabD = _mm_setzero_pd();
689 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
690 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
691 ewtabFn = _mm_setzero_pd();
692 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
693 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
694 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
695 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
696 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
698 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
700 /* Update potential sum for this i atom from the interaction with this j atom. */
701 velec = _mm_and_pd(velec,cutoff_mask);
702 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
703 velecsum = _mm_add_pd(velecsum,velec);
707 fscal = _mm_and_pd(fscal,cutoff_mask);
709 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
711 /* Update vectorial force */
712 fix3 = _mm_macc_pd(dx30,fscal,fix3);
713 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
714 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
716 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
717 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
718 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
722 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
724 /* Inner loop uses 194 flops */
727 /* End of innermost loop */
729 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
730 f+i_coord_offset,fshift+i_shift_offset);
733 /* Update potential energies */
734 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
735 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
737 /* Increment number of inner iterations */
738 inneriter += j_index_end - j_index_start;
740 /* Outer loop uses 26 flops */
743 /* Increment number of outer iterations */
746 /* Update outer/inner flops */
748 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*194);
751 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_double
752 * Electrostatics interaction: Ewald
753 * VdW interaction: LennardJones
754 * Geometry: Water4-Particle
755 * Calculate force/pot: Force
758 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_double
759 (t_nblist * gmx_restrict nlist,
760 rvec * gmx_restrict xx,
761 rvec * gmx_restrict ff,
762 t_forcerec * gmx_restrict fr,
763 t_mdatoms * gmx_restrict mdatoms,
764 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
765 t_nrnb * gmx_restrict nrnb)
767 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
768 * just 0 for non-waters.
769 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
770 * jnr indices corresponding to data put in the four positions in the SIMD register.
772 int i_shift_offset,i_coord_offset,outeriter,inneriter;
773 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
775 int j_coord_offsetA,j_coord_offsetB;
776 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
778 real *shiftvec,*fshift,*x,*f;
779 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
781 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
783 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
785 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
787 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
788 int vdwjidx0A,vdwjidx0B;
789 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
790 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
791 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
792 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
793 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
794 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
797 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
800 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
801 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
803 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
805 __m128d dummy_mask,cutoff_mask;
806 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
807 __m128d one = _mm_set1_pd(1.0);
808 __m128d two = _mm_set1_pd(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_pd(fr->epsfac);
821 charge = mdatoms->chargeA;
822 nvdwtype = fr->ntype;
824 vdwtype = mdatoms->typeA;
826 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
827 ewtab = fr->ic->tabq_coul_F;
828 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
829 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
831 /* Setup water-specific parameters */
832 inr = nlist->iinr[0];
833 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
834 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
835 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
836 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
838 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
839 rcutoff_scalar = fr->rcoulomb;
840 rcutoff = _mm_set1_pd(rcutoff_scalar);
841 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
843 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
844 rvdw = _mm_set1_pd(fr->rvdw);
846 /* Avoid stupid compiler warnings */
854 /* Start outer loop over neighborlists */
855 for(iidx=0; iidx<nri; iidx++)
857 /* Load shift vector for this list */
858 i_shift_offset = DIM*shiftidx[iidx];
860 /* Load limits for loop over neighbors */
861 j_index_start = jindex[iidx];
862 j_index_end = jindex[iidx+1];
864 /* Get outer coordinate index */
866 i_coord_offset = DIM*inr;
868 /* Load i particle coords and add shift vector */
869 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
870 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
872 fix0 = _mm_setzero_pd();
873 fiy0 = _mm_setzero_pd();
874 fiz0 = _mm_setzero_pd();
875 fix1 = _mm_setzero_pd();
876 fiy1 = _mm_setzero_pd();
877 fiz1 = _mm_setzero_pd();
878 fix2 = _mm_setzero_pd();
879 fiy2 = _mm_setzero_pd();
880 fiz2 = _mm_setzero_pd();
881 fix3 = _mm_setzero_pd();
882 fiy3 = _mm_setzero_pd();
883 fiz3 = _mm_setzero_pd();
885 /* Start inner kernel loop */
886 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
889 /* Get j neighbor index, and coordinate index */
892 j_coord_offsetA = DIM*jnrA;
893 j_coord_offsetB = DIM*jnrB;
895 /* load j atom coordinates */
896 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
899 /* Calculate displacement vector */
900 dx00 = _mm_sub_pd(ix0,jx0);
901 dy00 = _mm_sub_pd(iy0,jy0);
902 dz00 = _mm_sub_pd(iz0,jz0);
903 dx10 = _mm_sub_pd(ix1,jx0);
904 dy10 = _mm_sub_pd(iy1,jy0);
905 dz10 = _mm_sub_pd(iz1,jz0);
906 dx20 = _mm_sub_pd(ix2,jx0);
907 dy20 = _mm_sub_pd(iy2,jy0);
908 dz20 = _mm_sub_pd(iz2,jz0);
909 dx30 = _mm_sub_pd(ix3,jx0);
910 dy30 = _mm_sub_pd(iy3,jy0);
911 dz30 = _mm_sub_pd(iz3,jz0);
913 /* Calculate squared distance and things based on it */
914 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
915 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
916 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
917 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
919 rinv10 = gmx_mm_invsqrt_pd(rsq10);
920 rinv20 = gmx_mm_invsqrt_pd(rsq20);
921 rinv30 = gmx_mm_invsqrt_pd(rsq30);
923 rinvsq00 = gmx_mm_inv_pd(rsq00);
924 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
925 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
926 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
928 /* Load parameters for j particles */
929 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
930 vdwjidx0A = 2*vdwtype[jnrA+0];
931 vdwjidx0B = 2*vdwtype[jnrB+0];
933 fjx0 = _mm_setzero_pd();
934 fjy0 = _mm_setzero_pd();
935 fjz0 = _mm_setzero_pd();
937 /**************************
938 * CALCULATE INTERACTIONS *
939 **************************/
941 if (gmx_mm_any_lt(rsq00,rcutoff2))
944 /* Compute parameters for interactions between i and j atoms */
945 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
946 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
948 /* LENNARD-JONES DISPERSION/REPULSION */
950 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
951 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
953 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
957 fscal = _mm_and_pd(fscal,cutoff_mask);
959 /* Update vectorial force */
960 fix0 = _mm_macc_pd(dx00,fscal,fix0);
961 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
962 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
964 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
965 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
966 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
970 /**************************
971 * CALCULATE INTERACTIONS *
972 **************************/
974 if (gmx_mm_any_lt(rsq10,rcutoff2))
977 r10 = _mm_mul_pd(rsq10,rinv10);
979 /* Compute parameters for interactions between i and j atoms */
980 qq10 = _mm_mul_pd(iq1,jq0);
982 /* EWALD ELECTROSTATICS */
984 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
985 ewrt = _mm_mul_pd(r10,ewtabscale);
986 ewitab = _mm_cvttpd_epi32(ewrt);
988 eweps = _mm_frcz_pd(ewrt);
990 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
992 twoeweps = _mm_add_pd(eweps,eweps);
993 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
995 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
996 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
998 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1002 fscal = _mm_and_pd(fscal,cutoff_mask);
1004 /* Update vectorial force */
1005 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1006 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1007 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1009 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1010 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1011 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1015 /**************************
1016 * CALCULATE INTERACTIONS *
1017 **************************/
1019 if (gmx_mm_any_lt(rsq20,rcutoff2))
1022 r20 = _mm_mul_pd(rsq20,rinv20);
1024 /* Compute parameters for interactions between i and j atoms */
1025 qq20 = _mm_mul_pd(iq2,jq0);
1027 /* EWALD ELECTROSTATICS */
1029 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1030 ewrt = _mm_mul_pd(r20,ewtabscale);
1031 ewitab = _mm_cvttpd_epi32(ewrt);
1033 eweps = _mm_frcz_pd(ewrt);
1035 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1037 twoeweps = _mm_add_pd(eweps,eweps);
1038 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
1040 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1041 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1043 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1047 fscal = _mm_and_pd(fscal,cutoff_mask);
1049 /* Update vectorial force */
1050 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1051 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1052 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1054 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1055 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1056 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1060 /**************************
1061 * CALCULATE INTERACTIONS *
1062 **************************/
1064 if (gmx_mm_any_lt(rsq30,rcutoff2))
1067 r30 = _mm_mul_pd(rsq30,rinv30);
1069 /* Compute parameters for interactions between i and j atoms */
1070 qq30 = _mm_mul_pd(iq3,jq0);
1072 /* EWALD ELECTROSTATICS */
1074 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1075 ewrt = _mm_mul_pd(r30,ewtabscale);
1076 ewitab = _mm_cvttpd_epi32(ewrt);
1078 eweps = _mm_frcz_pd(ewrt);
1080 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1082 twoeweps = _mm_add_pd(eweps,eweps);
1083 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
1085 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1086 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1088 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1092 fscal = _mm_and_pd(fscal,cutoff_mask);
1094 /* Update vectorial force */
1095 fix3 = _mm_macc_pd(dx30,fscal,fix3);
1096 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
1097 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
1099 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
1100 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
1101 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
1105 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1107 /* Inner loop uses 162 flops */
1110 if(jidx<j_index_end)
1114 j_coord_offsetA = DIM*jnrA;
1116 /* load j atom coordinates */
1117 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1120 /* Calculate displacement vector */
1121 dx00 = _mm_sub_pd(ix0,jx0);
1122 dy00 = _mm_sub_pd(iy0,jy0);
1123 dz00 = _mm_sub_pd(iz0,jz0);
1124 dx10 = _mm_sub_pd(ix1,jx0);
1125 dy10 = _mm_sub_pd(iy1,jy0);
1126 dz10 = _mm_sub_pd(iz1,jz0);
1127 dx20 = _mm_sub_pd(ix2,jx0);
1128 dy20 = _mm_sub_pd(iy2,jy0);
1129 dz20 = _mm_sub_pd(iz2,jz0);
1130 dx30 = _mm_sub_pd(ix3,jx0);
1131 dy30 = _mm_sub_pd(iy3,jy0);
1132 dz30 = _mm_sub_pd(iz3,jz0);
1134 /* Calculate squared distance and things based on it */
1135 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1136 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1137 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1138 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
1140 rinv10 = gmx_mm_invsqrt_pd(rsq10);
1141 rinv20 = gmx_mm_invsqrt_pd(rsq20);
1142 rinv30 = gmx_mm_invsqrt_pd(rsq30);
1144 rinvsq00 = gmx_mm_inv_pd(rsq00);
1145 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
1146 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
1147 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
1149 /* Load parameters for j particles */
1150 jq0 = _mm_load_sd(charge+jnrA+0);
1151 vdwjidx0A = 2*vdwtype[jnrA+0];
1153 fjx0 = _mm_setzero_pd();
1154 fjy0 = _mm_setzero_pd();
1155 fjz0 = _mm_setzero_pd();
1157 /**************************
1158 * CALCULATE INTERACTIONS *
1159 **************************/
1161 if (gmx_mm_any_lt(rsq00,rcutoff2))
1164 /* Compute parameters for interactions between i and j atoms */
1165 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
1167 /* LENNARD-JONES DISPERSION/REPULSION */
1169 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1170 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1172 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
1176 fscal = _mm_and_pd(fscal,cutoff_mask);
1178 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1180 /* Update vectorial force */
1181 fix0 = _mm_macc_pd(dx00,fscal,fix0);
1182 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
1183 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
1185 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
1186 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
1187 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
1191 /**************************
1192 * CALCULATE INTERACTIONS *
1193 **************************/
1195 if (gmx_mm_any_lt(rsq10,rcutoff2))
1198 r10 = _mm_mul_pd(rsq10,rinv10);
1200 /* Compute parameters for interactions between i and j atoms */
1201 qq10 = _mm_mul_pd(iq1,jq0);
1203 /* EWALD ELECTROSTATICS */
1205 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1206 ewrt = _mm_mul_pd(r10,ewtabscale);
1207 ewitab = _mm_cvttpd_epi32(ewrt);
1209 eweps = _mm_frcz_pd(ewrt);
1211 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1213 twoeweps = _mm_add_pd(eweps,eweps);
1214 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1215 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1216 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
1218 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1222 fscal = _mm_and_pd(fscal,cutoff_mask);
1224 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1226 /* Update vectorial force */
1227 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1228 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1229 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1231 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1232 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1233 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1237 /**************************
1238 * CALCULATE INTERACTIONS *
1239 **************************/
1241 if (gmx_mm_any_lt(rsq20,rcutoff2))
1244 r20 = _mm_mul_pd(rsq20,rinv20);
1246 /* Compute parameters for interactions between i and j atoms */
1247 qq20 = _mm_mul_pd(iq2,jq0);
1249 /* EWALD ELECTROSTATICS */
1251 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1252 ewrt = _mm_mul_pd(r20,ewtabscale);
1253 ewitab = _mm_cvttpd_epi32(ewrt);
1255 eweps = _mm_frcz_pd(ewrt);
1257 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1259 twoeweps = _mm_add_pd(eweps,eweps);
1260 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1261 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1262 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1264 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1268 fscal = _mm_and_pd(fscal,cutoff_mask);
1270 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1272 /* Update vectorial force */
1273 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1274 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1275 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1277 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1278 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1279 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1283 /**************************
1284 * CALCULATE INTERACTIONS *
1285 **************************/
1287 if (gmx_mm_any_lt(rsq30,rcutoff2))
1290 r30 = _mm_mul_pd(rsq30,rinv30);
1292 /* Compute parameters for interactions between i and j atoms */
1293 qq30 = _mm_mul_pd(iq3,jq0);
1295 /* EWALD ELECTROSTATICS */
1297 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1298 ewrt = _mm_mul_pd(r30,ewtabscale);
1299 ewitab = _mm_cvttpd_epi32(ewrt);
1301 eweps = _mm_frcz_pd(ewrt);
1303 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1305 twoeweps = _mm_add_pd(eweps,eweps);
1306 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1307 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1308 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1310 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1314 fscal = _mm_and_pd(fscal,cutoff_mask);
1316 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1318 /* Update vectorial force */
1319 fix3 = _mm_macc_pd(dx30,fscal,fix3);
1320 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
1321 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
1323 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
1324 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
1325 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
1329 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1331 /* Inner loop uses 162 flops */
1334 /* End of innermost loop */
1336 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1337 f+i_coord_offset,fshift+i_shift_offset);
1339 /* Increment number of inner iterations */
1340 inneriter += j_index_end - j_index_start;
1342 /* Outer loop uses 24 flops */
1345 /* Increment number of outer iterations */
1348 /* Update outer/inner flops */
1350 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*162);