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_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_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;
85 int vdwjidx0A,vdwjidx0B;
86 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
89 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
90 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
96 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
97 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
98 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
99 real rswitch_scalar,d_scalar;
100 __m128d dummy_mask,cutoff_mask;
101 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
102 __m128d one = _mm_set1_pd(1.0);
103 __m128d two = _mm_set1_pd(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_pd(fr->ic->epsfac);
116 charge = mdatoms->chargeA;
117 krf = _mm_set1_pd(fr->ic->k_rf);
118 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
119 crf = _mm_set1_pd(fr->ic->c_rf);
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 /* Setup water-specific parameters */
125 inr = nlist->iinr[0];
126 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
127 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
128 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
129 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
131 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
132 rcutoff_scalar = fr->ic->rcoulomb;
133 rcutoff = _mm_set1_pd(rcutoff_scalar);
134 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
136 rswitch_scalar = fr->ic->rvdw_switch;
137 rswitch = _mm_set1_pd(rswitch_scalar);
138 /* Setup switch parameters */
139 d_scalar = rcutoff_scalar-rswitch_scalar;
140 d = _mm_set1_pd(d_scalar);
141 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
142 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
143 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
144 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
145 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
146 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
148 /* Avoid stupid compiler warnings */
156 /* Start outer loop over neighborlists */
157 for(iidx=0; iidx<nri; iidx++)
159 /* Load shift vector for this list */
160 i_shift_offset = DIM*shiftidx[iidx];
162 /* Load limits for loop over neighbors */
163 j_index_start = jindex[iidx];
164 j_index_end = jindex[iidx+1];
166 /* Get outer coordinate index */
168 i_coord_offset = DIM*inr;
170 /* Load i particle coords and add shift vector */
171 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
172 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
174 fix0 = _mm_setzero_pd();
175 fiy0 = _mm_setzero_pd();
176 fiz0 = _mm_setzero_pd();
177 fix1 = _mm_setzero_pd();
178 fiy1 = _mm_setzero_pd();
179 fiz1 = _mm_setzero_pd();
180 fix2 = _mm_setzero_pd();
181 fiy2 = _mm_setzero_pd();
182 fiz2 = _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);
213 /* Calculate squared distance and things based on it */
214 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
215 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
216 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
218 rinv00 = avx128fma_invsqrt_d(rsq00);
219 rinv10 = avx128fma_invsqrt_d(rsq10);
220 rinv20 = avx128fma_invsqrt_d(rsq20);
222 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
223 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
224 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
226 /* Load parameters for j particles */
227 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
228 vdwjidx0A = 2*vdwtype[jnrA+0];
229 vdwjidx0B = 2*vdwtype[jnrB+0];
231 fjx0 = _mm_setzero_pd();
232 fjy0 = _mm_setzero_pd();
233 fjz0 = _mm_setzero_pd();
235 /**************************
236 * CALCULATE INTERACTIONS *
237 **************************/
239 if (gmx_mm_any_lt(rsq00,rcutoff2))
242 r00 = _mm_mul_pd(rsq00,rinv00);
244 /* Compute parameters for interactions between i and j atoms */
245 qq00 = _mm_mul_pd(iq0,jq0);
246 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
247 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
249 /* REACTION-FIELD ELECTROSTATICS */
250 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
251 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
253 /* LENNARD-JONES DISPERSION/REPULSION */
255 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
256 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
257 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
258 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
259 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
261 d = _mm_sub_pd(r00,rswitch);
262 d = _mm_max_pd(d,_mm_setzero_pd());
263 d2 = _mm_mul_pd(d,d);
264 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
266 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
268 /* Evaluate switch function */
269 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
270 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
271 vvdw = _mm_mul_pd(vvdw,sw);
272 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
274 /* Update potential sum for this i atom from the interaction with this j atom. */
275 velec = _mm_and_pd(velec,cutoff_mask);
276 velecsum = _mm_add_pd(velecsum,velec);
277 vvdw = _mm_and_pd(vvdw,cutoff_mask);
278 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
280 fscal = _mm_add_pd(felec,fvdw);
282 fscal = _mm_and_pd(fscal,cutoff_mask);
284 /* Update vectorial force */
285 fix0 = _mm_macc_pd(dx00,fscal,fix0);
286 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
287 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
289 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
290 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
291 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
295 /**************************
296 * CALCULATE INTERACTIONS *
297 **************************/
299 if (gmx_mm_any_lt(rsq10,rcutoff2))
302 /* Compute parameters for interactions between i and j atoms */
303 qq10 = _mm_mul_pd(iq1,jq0);
305 /* REACTION-FIELD ELECTROSTATICS */
306 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
307 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
309 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
311 /* Update potential sum for this i atom from the interaction with this j atom. */
312 velec = _mm_and_pd(velec,cutoff_mask);
313 velecsum = _mm_add_pd(velecsum,velec);
317 fscal = _mm_and_pd(fscal,cutoff_mask);
319 /* Update vectorial force */
320 fix1 = _mm_macc_pd(dx10,fscal,fix1);
321 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
322 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
324 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
325 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
326 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
330 /**************************
331 * CALCULATE INTERACTIONS *
332 **************************/
334 if (gmx_mm_any_lt(rsq20,rcutoff2))
337 /* Compute parameters for interactions between i and j atoms */
338 qq20 = _mm_mul_pd(iq2,jq0);
340 /* REACTION-FIELD ELECTROSTATICS */
341 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
342 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
344 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
346 /* Update potential sum for this i atom from the interaction with this j atom. */
347 velec = _mm_and_pd(velec,cutoff_mask);
348 velecsum = _mm_add_pd(velecsum,velec);
352 fscal = _mm_and_pd(fscal,cutoff_mask);
354 /* Update vectorial force */
355 fix2 = _mm_macc_pd(dx20,fscal,fix2);
356 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
357 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
359 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
360 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
361 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
365 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
367 /* Inner loop uses 154 flops */
374 j_coord_offsetA = DIM*jnrA;
376 /* load j atom coordinates */
377 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
380 /* Calculate displacement vector */
381 dx00 = _mm_sub_pd(ix0,jx0);
382 dy00 = _mm_sub_pd(iy0,jy0);
383 dz00 = _mm_sub_pd(iz0,jz0);
384 dx10 = _mm_sub_pd(ix1,jx0);
385 dy10 = _mm_sub_pd(iy1,jy0);
386 dz10 = _mm_sub_pd(iz1,jz0);
387 dx20 = _mm_sub_pd(ix2,jx0);
388 dy20 = _mm_sub_pd(iy2,jy0);
389 dz20 = _mm_sub_pd(iz2,jz0);
391 /* Calculate squared distance and things based on it */
392 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
393 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
394 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
396 rinv00 = avx128fma_invsqrt_d(rsq00);
397 rinv10 = avx128fma_invsqrt_d(rsq10);
398 rinv20 = avx128fma_invsqrt_d(rsq20);
400 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
401 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
402 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
404 /* Load parameters for j particles */
405 jq0 = _mm_load_sd(charge+jnrA+0);
406 vdwjidx0A = 2*vdwtype[jnrA+0];
408 fjx0 = _mm_setzero_pd();
409 fjy0 = _mm_setzero_pd();
410 fjz0 = _mm_setzero_pd();
412 /**************************
413 * CALCULATE INTERACTIONS *
414 **************************/
416 if (gmx_mm_any_lt(rsq00,rcutoff2))
419 r00 = _mm_mul_pd(rsq00,rinv00);
421 /* Compute parameters for interactions between i and j atoms */
422 qq00 = _mm_mul_pd(iq0,jq0);
423 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
425 /* REACTION-FIELD ELECTROSTATICS */
426 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
427 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
429 /* LENNARD-JONES DISPERSION/REPULSION */
431 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
432 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
433 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
434 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
435 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
437 d = _mm_sub_pd(r00,rswitch);
438 d = _mm_max_pd(d,_mm_setzero_pd());
439 d2 = _mm_mul_pd(d,d);
440 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
442 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
444 /* Evaluate switch function */
445 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
446 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
447 vvdw = _mm_mul_pd(vvdw,sw);
448 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
450 /* Update potential sum for this i atom from the interaction with this j atom. */
451 velec = _mm_and_pd(velec,cutoff_mask);
452 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
453 velecsum = _mm_add_pd(velecsum,velec);
454 vvdw = _mm_and_pd(vvdw,cutoff_mask);
455 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
456 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
458 fscal = _mm_add_pd(felec,fvdw);
460 fscal = _mm_and_pd(fscal,cutoff_mask);
462 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
464 /* Update vectorial force */
465 fix0 = _mm_macc_pd(dx00,fscal,fix0);
466 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
467 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
469 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
470 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
471 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
475 /**************************
476 * CALCULATE INTERACTIONS *
477 **************************/
479 if (gmx_mm_any_lt(rsq10,rcutoff2))
482 /* Compute parameters for interactions between i and j atoms */
483 qq10 = _mm_mul_pd(iq1,jq0);
485 /* REACTION-FIELD ELECTROSTATICS */
486 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
487 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
489 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
491 /* Update potential sum for this i atom from the interaction with this j atom. */
492 velec = _mm_and_pd(velec,cutoff_mask);
493 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
494 velecsum = _mm_add_pd(velecsum,velec);
498 fscal = _mm_and_pd(fscal,cutoff_mask);
500 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
502 /* Update vectorial force */
503 fix1 = _mm_macc_pd(dx10,fscal,fix1);
504 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
505 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
507 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
508 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
509 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
513 /**************************
514 * CALCULATE INTERACTIONS *
515 **************************/
517 if (gmx_mm_any_lt(rsq20,rcutoff2))
520 /* Compute parameters for interactions between i and j atoms */
521 qq20 = _mm_mul_pd(iq2,jq0);
523 /* REACTION-FIELD ELECTROSTATICS */
524 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
525 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
527 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
529 /* Update potential sum for this i atom from the interaction with this j atom. */
530 velec = _mm_and_pd(velec,cutoff_mask);
531 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
532 velecsum = _mm_add_pd(velecsum,velec);
536 fscal = _mm_and_pd(fscal,cutoff_mask);
538 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
540 /* Update vectorial force */
541 fix2 = _mm_macc_pd(dx20,fscal,fix2);
542 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
543 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
545 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
546 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
547 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
551 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
553 /* Inner loop uses 154 flops */
556 /* End of innermost loop */
558 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
559 f+i_coord_offset,fshift+i_shift_offset);
562 /* Update potential energies */
563 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
564 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
566 /* Increment number of inner iterations */
567 inneriter += j_index_end - j_index_start;
569 /* Outer loop uses 20 flops */
572 /* Increment number of outer iterations */
575 /* Update outer/inner flops */
577 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
580 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
581 * Electrostatics interaction: ReactionField
582 * VdW interaction: LennardJones
583 * Geometry: Water3-Particle
584 * Calculate force/pot: Force
587 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
588 (t_nblist * gmx_restrict nlist,
589 rvec * gmx_restrict xx,
590 rvec * gmx_restrict ff,
591 struct t_forcerec * gmx_restrict fr,
592 t_mdatoms * gmx_restrict mdatoms,
593 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
594 t_nrnb * gmx_restrict nrnb)
596 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
597 * just 0 for non-waters.
598 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
599 * jnr indices corresponding to data put in the four positions in the SIMD register.
601 int i_shift_offset,i_coord_offset,outeriter,inneriter;
602 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
604 int j_coord_offsetA,j_coord_offsetB;
605 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
607 real *shiftvec,*fshift,*x,*f;
608 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
610 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
612 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
614 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
615 int vdwjidx0A,vdwjidx0B;
616 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
617 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
618 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
619 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
620 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
623 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
626 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
627 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
628 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
629 real rswitch_scalar,d_scalar;
630 __m128d dummy_mask,cutoff_mask;
631 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
632 __m128d one = _mm_set1_pd(1.0);
633 __m128d two = _mm_set1_pd(2.0);
639 jindex = nlist->jindex;
641 shiftidx = nlist->shift;
643 shiftvec = fr->shift_vec[0];
644 fshift = fr->fshift[0];
645 facel = _mm_set1_pd(fr->ic->epsfac);
646 charge = mdatoms->chargeA;
647 krf = _mm_set1_pd(fr->ic->k_rf);
648 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
649 crf = _mm_set1_pd(fr->ic->c_rf);
650 nvdwtype = fr->ntype;
652 vdwtype = mdatoms->typeA;
654 /* Setup water-specific parameters */
655 inr = nlist->iinr[0];
656 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
657 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
658 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
659 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
661 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
662 rcutoff_scalar = fr->ic->rcoulomb;
663 rcutoff = _mm_set1_pd(rcutoff_scalar);
664 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
666 rswitch_scalar = fr->ic->rvdw_switch;
667 rswitch = _mm_set1_pd(rswitch_scalar);
668 /* Setup switch parameters */
669 d_scalar = rcutoff_scalar-rswitch_scalar;
670 d = _mm_set1_pd(d_scalar);
671 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
672 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
673 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
674 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
675 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
676 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
678 /* Avoid stupid compiler warnings */
686 /* Start outer loop over neighborlists */
687 for(iidx=0; iidx<nri; iidx++)
689 /* Load shift vector for this list */
690 i_shift_offset = DIM*shiftidx[iidx];
692 /* Load limits for loop over neighbors */
693 j_index_start = jindex[iidx];
694 j_index_end = jindex[iidx+1];
696 /* Get outer coordinate index */
698 i_coord_offset = DIM*inr;
700 /* Load i particle coords and add shift vector */
701 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
702 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
704 fix0 = _mm_setzero_pd();
705 fiy0 = _mm_setzero_pd();
706 fiz0 = _mm_setzero_pd();
707 fix1 = _mm_setzero_pd();
708 fiy1 = _mm_setzero_pd();
709 fiz1 = _mm_setzero_pd();
710 fix2 = _mm_setzero_pd();
711 fiy2 = _mm_setzero_pd();
712 fiz2 = _mm_setzero_pd();
714 /* Start inner kernel loop */
715 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
718 /* Get j neighbor index, and coordinate index */
721 j_coord_offsetA = DIM*jnrA;
722 j_coord_offsetB = DIM*jnrB;
724 /* load j atom coordinates */
725 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
728 /* Calculate displacement vector */
729 dx00 = _mm_sub_pd(ix0,jx0);
730 dy00 = _mm_sub_pd(iy0,jy0);
731 dz00 = _mm_sub_pd(iz0,jz0);
732 dx10 = _mm_sub_pd(ix1,jx0);
733 dy10 = _mm_sub_pd(iy1,jy0);
734 dz10 = _mm_sub_pd(iz1,jz0);
735 dx20 = _mm_sub_pd(ix2,jx0);
736 dy20 = _mm_sub_pd(iy2,jy0);
737 dz20 = _mm_sub_pd(iz2,jz0);
739 /* Calculate squared distance and things based on it */
740 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
741 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
742 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
744 rinv00 = avx128fma_invsqrt_d(rsq00);
745 rinv10 = avx128fma_invsqrt_d(rsq10);
746 rinv20 = avx128fma_invsqrt_d(rsq20);
748 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
749 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
750 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
752 /* Load parameters for j particles */
753 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
754 vdwjidx0A = 2*vdwtype[jnrA+0];
755 vdwjidx0B = 2*vdwtype[jnrB+0];
757 fjx0 = _mm_setzero_pd();
758 fjy0 = _mm_setzero_pd();
759 fjz0 = _mm_setzero_pd();
761 /**************************
762 * CALCULATE INTERACTIONS *
763 **************************/
765 if (gmx_mm_any_lt(rsq00,rcutoff2))
768 r00 = _mm_mul_pd(rsq00,rinv00);
770 /* Compute parameters for interactions between i and j atoms */
771 qq00 = _mm_mul_pd(iq0,jq0);
772 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
773 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
775 /* REACTION-FIELD ELECTROSTATICS */
776 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
778 /* LENNARD-JONES DISPERSION/REPULSION */
780 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
781 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
782 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
783 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
784 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
786 d = _mm_sub_pd(r00,rswitch);
787 d = _mm_max_pd(d,_mm_setzero_pd());
788 d2 = _mm_mul_pd(d,d);
789 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
791 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
793 /* Evaluate switch function */
794 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
795 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
796 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
798 fscal = _mm_add_pd(felec,fvdw);
800 fscal = _mm_and_pd(fscal,cutoff_mask);
802 /* Update vectorial force */
803 fix0 = _mm_macc_pd(dx00,fscal,fix0);
804 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
805 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
807 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
808 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
809 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
813 /**************************
814 * CALCULATE INTERACTIONS *
815 **************************/
817 if (gmx_mm_any_lt(rsq10,rcutoff2))
820 /* Compute parameters for interactions between i and j atoms */
821 qq10 = _mm_mul_pd(iq1,jq0);
823 /* REACTION-FIELD ELECTROSTATICS */
824 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
826 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
830 fscal = _mm_and_pd(fscal,cutoff_mask);
832 /* Update vectorial force */
833 fix1 = _mm_macc_pd(dx10,fscal,fix1);
834 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
835 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
837 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
838 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
839 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
843 /**************************
844 * CALCULATE INTERACTIONS *
845 **************************/
847 if (gmx_mm_any_lt(rsq20,rcutoff2))
850 /* Compute parameters for interactions between i and j atoms */
851 qq20 = _mm_mul_pd(iq2,jq0);
853 /* REACTION-FIELD ELECTROSTATICS */
854 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
856 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
860 fscal = _mm_and_pd(fscal,cutoff_mask);
862 /* Update vectorial force */
863 fix2 = _mm_macc_pd(dx20,fscal,fix2);
864 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
865 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
867 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
868 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
869 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
873 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
875 /* Inner loop uses 133 flops */
882 j_coord_offsetA = DIM*jnrA;
884 /* load j atom coordinates */
885 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
888 /* Calculate displacement vector */
889 dx00 = _mm_sub_pd(ix0,jx0);
890 dy00 = _mm_sub_pd(iy0,jy0);
891 dz00 = _mm_sub_pd(iz0,jz0);
892 dx10 = _mm_sub_pd(ix1,jx0);
893 dy10 = _mm_sub_pd(iy1,jy0);
894 dz10 = _mm_sub_pd(iz1,jz0);
895 dx20 = _mm_sub_pd(ix2,jx0);
896 dy20 = _mm_sub_pd(iy2,jy0);
897 dz20 = _mm_sub_pd(iz2,jz0);
899 /* Calculate squared distance and things based on it */
900 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
901 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
902 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
904 rinv00 = avx128fma_invsqrt_d(rsq00);
905 rinv10 = avx128fma_invsqrt_d(rsq10);
906 rinv20 = avx128fma_invsqrt_d(rsq20);
908 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
909 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
910 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
912 /* Load parameters for j particles */
913 jq0 = _mm_load_sd(charge+jnrA+0);
914 vdwjidx0A = 2*vdwtype[jnrA+0];
916 fjx0 = _mm_setzero_pd();
917 fjy0 = _mm_setzero_pd();
918 fjz0 = _mm_setzero_pd();
920 /**************************
921 * CALCULATE INTERACTIONS *
922 **************************/
924 if (gmx_mm_any_lt(rsq00,rcutoff2))
927 r00 = _mm_mul_pd(rsq00,rinv00);
929 /* Compute parameters for interactions between i and j atoms */
930 qq00 = _mm_mul_pd(iq0,jq0);
931 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
933 /* REACTION-FIELD ELECTROSTATICS */
934 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
936 /* LENNARD-JONES DISPERSION/REPULSION */
938 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
939 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
940 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
941 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
942 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
944 d = _mm_sub_pd(r00,rswitch);
945 d = _mm_max_pd(d,_mm_setzero_pd());
946 d2 = _mm_mul_pd(d,d);
947 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
949 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
951 /* Evaluate switch function */
952 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
953 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
954 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
956 fscal = _mm_add_pd(felec,fvdw);
958 fscal = _mm_and_pd(fscal,cutoff_mask);
960 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
962 /* Update vectorial force */
963 fix0 = _mm_macc_pd(dx00,fscal,fix0);
964 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
965 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
967 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
968 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
969 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
973 /**************************
974 * CALCULATE INTERACTIONS *
975 **************************/
977 if (gmx_mm_any_lt(rsq10,rcutoff2))
980 /* Compute parameters for interactions between i and j atoms */
981 qq10 = _mm_mul_pd(iq1,jq0);
983 /* REACTION-FIELD ELECTROSTATICS */
984 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
986 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
990 fscal = _mm_and_pd(fscal,cutoff_mask);
992 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
994 /* Update vectorial force */
995 fix1 = _mm_macc_pd(dx10,fscal,fix1);
996 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
997 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
999 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1000 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1001 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1005 /**************************
1006 * CALCULATE INTERACTIONS *
1007 **************************/
1009 if (gmx_mm_any_lt(rsq20,rcutoff2))
1012 /* Compute parameters for interactions between i and j atoms */
1013 qq20 = _mm_mul_pd(iq2,jq0);
1015 /* REACTION-FIELD ELECTROSTATICS */
1016 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1018 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1022 fscal = _mm_and_pd(fscal,cutoff_mask);
1024 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1026 /* Update vectorial force */
1027 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1028 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1029 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1031 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1032 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1033 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1037 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1039 /* Inner loop uses 133 flops */
1042 /* End of innermost loop */
1044 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1045 f+i_coord_offset,fshift+i_shift_offset);
1047 /* Increment number of inner iterations */
1048 inneriter += j_index_end - j_index_start;
1050 /* Outer loop uses 18 flops */
1053 /* Increment number of outer iterations */
1056 /* Update outer/inner flops */
1058 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*133);