2 * Note: this file was generated by the Gromacs avx_128_fma_double kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_double.h"
34 #include "kernelutil_x86_avx_128_fma_double.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water3-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
61 int j_coord_offsetA,j_coord_offsetB;
62 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
64 real *shiftvec,*fshift,*x,*f;
65 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
67 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
69 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
71 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
72 int vdwjidx0A,vdwjidx0B;
73 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
75 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
76 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
77 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
80 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
83 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
84 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
85 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
86 real rswitch_scalar,d_scalar;
87 __m128d dummy_mask,cutoff_mask;
88 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
89 __m128d one = _mm_set1_pd(1.0);
90 __m128d two = _mm_set1_pd(2.0);
96 jindex = nlist->jindex;
98 shiftidx = nlist->shift;
100 shiftvec = fr->shift_vec[0];
101 fshift = fr->fshift[0];
102 facel = _mm_set1_pd(fr->epsfac);
103 charge = mdatoms->chargeA;
104 krf = _mm_set1_pd(fr->ic->k_rf);
105 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
106 crf = _mm_set1_pd(fr->ic->c_rf);
107 nvdwtype = fr->ntype;
109 vdwtype = mdatoms->typeA;
111 /* Setup water-specific parameters */
112 inr = nlist->iinr[0];
113 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
114 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
115 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
116 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
118 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
119 rcutoff_scalar = fr->rcoulomb;
120 rcutoff = _mm_set1_pd(rcutoff_scalar);
121 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
123 rswitch_scalar = fr->rvdw_switch;
124 rswitch = _mm_set1_pd(rswitch_scalar);
125 /* Setup switch parameters */
126 d_scalar = rcutoff_scalar-rswitch_scalar;
127 d = _mm_set1_pd(d_scalar);
128 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
129 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
130 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
131 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
132 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
133 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
135 /* Avoid stupid compiler warnings */
143 /* Start outer loop over neighborlists */
144 for(iidx=0; iidx<nri; iidx++)
146 /* Load shift vector for this list */
147 i_shift_offset = DIM*shiftidx[iidx];
149 /* Load limits for loop over neighbors */
150 j_index_start = jindex[iidx];
151 j_index_end = jindex[iidx+1];
153 /* Get outer coordinate index */
155 i_coord_offset = DIM*inr;
157 /* Load i particle coords and add shift vector */
158 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
159 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
161 fix0 = _mm_setzero_pd();
162 fiy0 = _mm_setzero_pd();
163 fiz0 = _mm_setzero_pd();
164 fix1 = _mm_setzero_pd();
165 fiy1 = _mm_setzero_pd();
166 fiz1 = _mm_setzero_pd();
167 fix2 = _mm_setzero_pd();
168 fiy2 = _mm_setzero_pd();
169 fiz2 = _mm_setzero_pd();
171 /* Reset potential sums */
172 velecsum = _mm_setzero_pd();
173 vvdwsum = _mm_setzero_pd();
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
179 /* Get j neighbor index, and coordinate index */
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
185 /* load j atom coordinates */
186 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
189 /* Calculate displacement vector */
190 dx00 = _mm_sub_pd(ix0,jx0);
191 dy00 = _mm_sub_pd(iy0,jy0);
192 dz00 = _mm_sub_pd(iz0,jz0);
193 dx10 = _mm_sub_pd(ix1,jx0);
194 dy10 = _mm_sub_pd(iy1,jy0);
195 dz10 = _mm_sub_pd(iz1,jz0);
196 dx20 = _mm_sub_pd(ix2,jx0);
197 dy20 = _mm_sub_pd(iy2,jy0);
198 dz20 = _mm_sub_pd(iz2,jz0);
200 /* Calculate squared distance and things based on it */
201 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
202 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
203 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
205 rinv00 = gmx_mm_invsqrt_pd(rsq00);
206 rinv10 = gmx_mm_invsqrt_pd(rsq10);
207 rinv20 = gmx_mm_invsqrt_pd(rsq20);
209 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
210 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
211 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
213 /* Load parameters for j particles */
214 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
215 vdwjidx0A = 2*vdwtype[jnrA+0];
216 vdwjidx0B = 2*vdwtype[jnrB+0];
218 fjx0 = _mm_setzero_pd();
219 fjy0 = _mm_setzero_pd();
220 fjz0 = _mm_setzero_pd();
222 /**************************
223 * CALCULATE INTERACTIONS *
224 **************************/
226 if (gmx_mm_any_lt(rsq00,rcutoff2))
229 r00 = _mm_mul_pd(rsq00,rinv00);
231 /* Compute parameters for interactions between i and j atoms */
232 qq00 = _mm_mul_pd(iq0,jq0);
233 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
234 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
236 /* REACTION-FIELD ELECTROSTATICS */
237 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
238 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
240 /* LENNARD-JONES DISPERSION/REPULSION */
242 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
243 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
244 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
245 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
246 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
248 d = _mm_sub_pd(r00,rswitch);
249 d = _mm_max_pd(d,_mm_setzero_pd());
250 d2 = _mm_mul_pd(d,d);
251 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
253 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
255 /* Evaluate switch function */
256 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
257 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
258 vvdw = _mm_mul_pd(vvdw,sw);
259 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
261 /* Update potential sum for this i atom from the interaction with this j atom. */
262 velec = _mm_and_pd(velec,cutoff_mask);
263 velecsum = _mm_add_pd(velecsum,velec);
264 vvdw = _mm_and_pd(vvdw,cutoff_mask);
265 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
267 fscal = _mm_add_pd(felec,fvdw);
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 /* Compute parameters for interactions between i and j atoms */
290 qq10 = _mm_mul_pd(iq1,jq0);
292 /* REACTION-FIELD ELECTROSTATICS */
293 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
294 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
296 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
298 /* Update potential sum for this i atom from the interaction with this j atom. */
299 velec = _mm_and_pd(velec,cutoff_mask);
300 velecsum = _mm_add_pd(velecsum,velec);
304 fscal = _mm_and_pd(fscal,cutoff_mask);
306 /* Update vectorial force */
307 fix1 = _mm_macc_pd(dx10,fscal,fix1);
308 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
309 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
311 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
312 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
313 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
317 /**************************
318 * CALCULATE INTERACTIONS *
319 **************************/
321 if (gmx_mm_any_lt(rsq20,rcutoff2))
324 /* Compute parameters for interactions between i and j atoms */
325 qq20 = _mm_mul_pd(iq2,jq0);
327 /* REACTION-FIELD ELECTROSTATICS */
328 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
329 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
331 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
333 /* Update potential sum for this i atom from the interaction with this j atom. */
334 velec = _mm_and_pd(velec,cutoff_mask);
335 velecsum = _mm_add_pd(velecsum,velec);
339 fscal = _mm_and_pd(fscal,cutoff_mask);
341 /* Update vectorial force */
342 fix2 = _mm_macc_pd(dx20,fscal,fix2);
343 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
344 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
346 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
347 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
348 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
352 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
354 /* Inner loop uses 154 flops */
361 j_coord_offsetA = DIM*jnrA;
363 /* load j atom coordinates */
364 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
367 /* Calculate displacement vector */
368 dx00 = _mm_sub_pd(ix0,jx0);
369 dy00 = _mm_sub_pd(iy0,jy0);
370 dz00 = _mm_sub_pd(iz0,jz0);
371 dx10 = _mm_sub_pd(ix1,jx0);
372 dy10 = _mm_sub_pd(iy1,jy0);
373 dz10 = _mm_sub_pd(iz1,jz0);
374 dx20 = _mm_sub_pd(ix2,jx0);
375 dy20 = _mm_sub_pd(iy2,jy0);
376 dz20 = _mm_sub_pd(iz2,jz0);
378 /* Calculate squared distance and things based on it */
379 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
380 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
381 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
383 rinv00 = gmx_mm_invsqrt_pd(rsq00);
384 rinv10 = gmx_mm_invsqrt_pd(rsq10);
385 rinv20 = gmx_mm_invsqrt_pd(rsq20);
387 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
388 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
389 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
391 /* Load parameters for j particles */
392 jq0 = _mm_load_sd(charge+jnrA+0);
393 vdwjidx0A = 2*vdwtype[jnrA+0];
395 fjx0 = _mm_setzero_pd();
396 fjy0 = _mm_setzero_pd();
397 fjz0 = _mm_setzero_pd();
399 /**************************
400 * CALCULATE INTERACTIONS *
401 **************************/
403 if (gmx_mm_any_lt(rsq00,rcutoff2))
406 r00 = _mm_mul_pd(rsq00,rinv00);
408 /* Compute parameters for interactions between i and j atoms */
409 qq00 = _mm_mul_pd(iq0,jq0);
410 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
412 /* REACTION-FIELD ELECTROSTATICS */
413 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
414 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
416 /* LENNARD-JONES DISPERSION/REPULSION */
418 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
419 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
420 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
421 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
422 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
424 d = _mm_sub_pd(r00,rswitch);
425 d = _mm_max_pd(d,_mm_setzero_pd());
426 d2 = _mm_mul_pd(d,d);
427 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
429 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
431 /* Evaluate switch function */
432 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
433 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
434 vvdw = _mm_mul_pd(vvdw,sw);
435 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
437 /* Update potential sum for this i atom from the interaction with this j atom. */
438 velec = _mm_and_pd(velec,cutoff_mask);
439 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
440 velecsum = _mm_add_pd(velecsum,velec);
441 vvdw = _mm_and_pd(vvdw,cutoff_mask);
442 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
443 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
445 fscal = _mm_add_pd(felec,fvdw);
447 fscal = _mm_and_pd(fscal,cutoff_mask);
449 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
451 /* Update vectorial force */
452 fix0 = _mm_macc_pd(dx00,fscal,fix0);
453 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
454 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
456 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
457 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
458 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
462 /**************************
463 * CALCULATE INTERACTIONS *
464 **************************/
466 if (gmx_mm_any_lt(rsq10,rcutoff2))
469 /* Compute parameters for interactions between i and j atoms */
470 qq10 = _mm_mul_pd(iq1,jq0);
472 /* REACTION-FIELD ELECTROSTATICS */
473 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
474 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
476 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
478 /* Update potential sum for this i atom from the interaction with this j atom. */
479 velec = _mm_and_pd(velec,cutoff_mask);
480 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
481 velecsum = _mm_add_pd(velecsum,velec);
485 fscal = _mm_and_pd(fscal,cutoff_mask);
487 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
489 /* Update vectorial force */
490 fix1 = _mm_macc_pd(dx10,fscal,fix1);
491 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
492 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
494 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
495 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
496 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
500 /**************************
501 * CALCULATE INTERACTIONS *
502 **************************/
504 if (gmx_mm_any_lt(rsq20,rcutoff2))
507 /* Compute parameters for interactions between i and j atoms */
508 qq20 = _mm_mul_pd(iq2,jq0);
510 /* REACTION-FIELD ELECTROSTATICS */
511 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
512 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
514 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
516 /* Update potential sum for this i atom from the interaction with this j atom. */
517 velec = _mm_and_pd(velec,cutoff_mask);
518 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
519 velecsum = _mm_add_pd(velecsum,velec);
523 fscal = _mm_and_pd(fscal,cutoff_mask);
525 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
527 /* Update vectorial force */
528 fix2 = _mm_macc_pd(dx20,fscal,fix2);
529 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
530 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
532 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
533 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
534 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
538 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
540 /* Inner loop uses 154 flops */
543 /* End of innermost loop */
545 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
546 f+i_coord_offset,fshift+i_shift_offset);
549 /* Update potential energies */
550 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
551 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
553 /* Increment number of inner iterations */
554 inneriter += j_index_end - j_index_start;
556 /* Outer loop uses 20 flops */
559 /* Increment number of outer iterations */
562 /* Update outer/inner flops */
564 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
567 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
568 * Electrostatics interaction: ReactionField
569 * VdW interaction: LennardJones
570 * Geometry: Water3-Particle
571 * Calculate force/pot: Force
574 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
575 (t_nblist * gmx_restrict nlist,
576 rvec * gmx_restrict xx,
577 rvec * gmx_restrict ff,
578 t_forcerec * gmx_restrict fr,
579 t_mdatoms * gmx_restrict mdatoms,
580 nb_kernel_data_t * gmx_restrict kernel_data,
581 t_nrnb * gmx_restrict nrnb)
583 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
584 * just 0 for non-waters.
585 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
586 * jnr indices corresponding to data put in the four positions in the SIMD register.
588 int i_shift_offset,i_coord_offset,outeriter,inneriter;
589 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
591 int j_coord_offsetA,j_coord_offsetB;
592 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
594 real *shiftvec,*fshift,*x,*f;
595 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
597 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
599 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
601 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
602 int vdwjidx0A,vdwjidx0B;
603 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
604 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
605 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
606 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
607 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
610 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
613 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
614 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
615 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
616 real rswitch_scalar,d_scalar;
617 __m128d dummy_mask,cutoff_mask;
618 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
619 __m128d one = _mm_set1_pd(1.0);
620 __m128d two = _mm_set1_pd(2.0);
626 jindex = nlist->jindex;
628 shiftidx = nlist->shift;
630 shiftvec = fr->shift_vec[0];
631 fshift = fr->fshift[0];
632 facel = _mm_set1_pd(fr->epsfac);
633 charge = mdatoms->chargeA;
634 krf = _mm_set1_pd(fr->ic->k_rf);
635 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
636 crf = _mm_set1_pd(fr->ic->c_rf);
637 nvdwtype = fr->ntype;
639 vdwtype = mdatoms->typeA;
641 /* Setup water-specific parameters */
642 inr = nlist->iinr[0];
643 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
644 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
645 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
646 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
648 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
649 rcutoff_scalar = fr->rcoulomb;
650 rcutoff = _mm_set1_pd(rcutoff_scalar);
651 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
653 rswitch_scalar = fr->rvdw_switch;
654 rswitch = _mm_set1_pd(rswitch_scalar);
655 /* Setup switch parameters */
656 d_scalar = rcutoff_scalar-rswitch_scalar;
657 d = _mm_set1_pd(d_scalar);
658 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
659 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
660 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
661 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
662 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
663 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
665 /* Avoid stupid compiler warnings */
673 /* Start outer loop over neighborlists */
674 for(iidx=0; iidx<nri; iidx++)
676 /* Load shift vector for this list */
677 i_shift_offset = DIM*shiftidx[iidx];
679 /* Load limits for loop over neighbors */
680 j_index_start = jindex[iidx];
681 j_index_end = jindex[iidx+1];
683 /* Get outer coordinate index */
685 i_coord_offset = DIM*inr;
687 /* Load i particle coords and add shift vector */
688 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
689 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
691 fix0 = _mm_setzero_pd();
692 fiy0 = _mm_setzero_pd();
693 fiz0 = _mm_setzero_pd();
694 fix1 = _mm_setzero_pd();
695 fiy1 = _mm_setzero_pd();
696 fiz1 = _mm_setzero_pd();
697 fix2 = _mm_setzero_pd();
698 fiy2 = _mm_setzero_pd();
699 fiz2 = _mm_setzero_pd();
701 /* Start inner kernel loop */
702 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
705 /* Get j neighbor index, and coordinate index */
708 j_coord_offsetA = DIM*jnrA;
709 j_coord_offsetB = DIM*jnrB;
711 /* load j atom coordinates */
712 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
715 /* Calculate displacement vector */
716 dx00 = _mm_sub_pd(ix0,jx0);
717 dy00 = _mm_sub_pd(iy0,jy0);
718 dz00 = _mm_sub_pd(iz0,jz0);
719 dx10 = _mm_sub_pd(ix1,jx0);
720 dy10 = _mm_sub_pd(iy1,jy0);
721 dz10 = _mm_sub_pd(iz1,jz0);
722 dx20 = _mm_sub_pd(ix2,jx0);
723 dy20 = _mm_sub_pd(iy2,jy0);
724 dz20 = _mm_sub_pd(iz2,jz0);
726 /* Calculate squared distance and things based on it */
727 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
728 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
729 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
731 rinv00 = gmx_mm_invsqrt_pd(rsq00);
732 rinv10 = gmx_mm_invsqrt_pd(rsq10);
733 rinv20 = gmx_mm_invsqrt_pd(rsq20);
735 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
736 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
737 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
739 /* Load parameters for j particles */
740 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
741 vdwjidx0A = 2*vdwtype[jnrA+0];
742 vdwjidx0B = 2*vdwtype[jnrB+0];
744 fjx0 = _mm_setzero_pd();
745 fjy0 = _mm_setzero_pd();
746 fjz0 = _mm_setzero_pd();
748 /**************************
749 * CALCULATE INTERACTIONS *
750 **************************/
752 if (gmx_mm_any_lt(rsq00,rcutoff2))
755 r00 = _mm_mul_pd(rsq00,rinv00);
757 /* Compute parameters for interactions between i and j atoms */
758 qq00 = _mm_mul_pd(iq0,jq0);
759 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
760 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
762 /* REACTION-FIELD ELECTROSTATICS */
763 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
765 /* LENNARD-JONES DISPERSION/REPULSION */
767 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
768 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
769 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
770 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
771 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
773 d = _mm_sub_pd(r00,rswitch);
774 d = _mm_max_pd(d,_mm_setzero_pd());
775 d2 = _mm_mul_pd(d,d);
776 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
778 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
780 /* Evaluate switch function */
781 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
782 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
783 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
785 fscal = _mm_add_pd(felec,fvdw);
787 fscal = _mm_and_pd(fscal,cutoff_mask);
789 /* Update vectorial force */
790 fix0 = _mm_macc_pd(dx00,fscal,fix0);
791 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
792 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
794 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
795 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
796 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
800 /**************************
801 * CALCULATE INTERACTIONS *
802 **************************/
804 if (gmx_mm_any_lt(rsq10,rcutoff2))
807 /* Compute parameters for interactions between i and j atoms */
808 qq10 = _mm_mul_pd(iq1,jq0);
810 /* REACTION-FIELD ELECTROSTATICS */
811 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
813 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
817 fscal = _mm_and_pd(fscal,cutoff_mask);
819 /* Update vectorial force */
820 fix1 = _mm_macc_pd(dx10,fscal,fix1);
821 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
822 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
824 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
825 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
826 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
830 /**************************
831 * CALCULATE INTERACTIONS *
832 **************************/
834 if (gmx_mm_any_lt(rsq20,rcutoff2))
837 /* Compute parameters for interactions between i and j atoms */
838 qq20 = _mm_mul_pd(iq2,jq0);
840 /* REACTION-FIELD ELECTROSTATICS */
841 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
843 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
847 fscal = _mm_and_pd(fscal,cutoff_mask);
849 /* Update vectorial force */
850 fix2 = _mm_macc_pd(dx20,fscal,fix2);
851 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
852 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
854 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
855 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
856 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
860 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
862 /* Inner loop uses 133 flops */
869 j_coord_offsetA = DIM*jnrA;
871 /* load j atom coordinates */
872 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
875 /* Calculate displacement vector */
876 dx00 = _mm_sub_pd(ix0,jx0);
877 dy00 = _mm_sub_pd(iy0,jy0);
878 dz00 = _mm_sub_pd(iz0,jz0);
879 dx10 = _mm_sub_pd(ix1,jx0);
880 dy10 = _mm_sub_pd(iy1,jy0);
881 dz10 = _mm_sub_pd(iz1,jz0);
882 dx20 = _mm_sub_pd(ix2,jx0);
883 dy20 = _mm_sub_pd(iy2,jy0);
884 dz20 = _mm_sub_pd(iz2,jz0);
886 /* Calculate squared distance and things based on it */
887 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
888 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
889 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
891 rinv00 = gmx_mm_invsqrt_pd(rsq00);
892 rinv10 = gmx_mm_invsqrt_pd(rsq10);
893 rinv20 = gmx_mm_invsqrt_pd(rsq20);
895 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
896 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
897 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
899 /* Load parameters for j particles */
900 jq0 = _mm_load_sd(charge+jnrA+0);
901 vdwjidx0A = 2*vdwtype[jnrA+0];
903 fjx0 = _mm_setzero_pd();
904 fjy0 = _mm_setzero_pd();
905 fjz0 = _mm_setzero_pd();
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 if (gmx_mm_any_lt(rsq00,rcutoff2))
914 r00 = _mm_mul_pd(rsq00,rinv00);
916 /* Compute parameters for interactions between i and j atoms */
917 qq00 = _mm_mul_pd(iq0,jq0);
918 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
920 /* REACTION-FIELD ELECTROSTATICS */
921 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
923 /* LENNARD-JONES DISPERSION/REPULSION */
925 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
926 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
927 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
928 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
929 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
931 d = _mm_sub_pd(r00,rswitch);
932 d = _mm_max_pd(d,_mm_setzero_pd());
933 d2 = _mm_mul_pd(d,d);
934 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
936 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
938 /* Evaluate switch function */
939 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
940 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
941 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
943 fscal = _mm_add_pd(felec,fvdw);
945 fscal = _mm_and_pd(fscal,cutoff_mask);
947 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
949 /* Update vectorial force */
950 fix0 = _mm_macc_pd(dx00,fscal,fix0);
951 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
952 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
954 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
955 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
956 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
960 /**************************
961 * CALCULATE INTERACTIONS *
962 **************************/
964 if (gmx_mm_any_lt(rsq10,rcutoff2))
967 /* Compute parameters for interactions between i and j atoms */
968 qq10 = _mm_mul_pd(iq1,jq0);
970 /* REACTION-FIELD ELECTROSTATICS */
971 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
973 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
977 fscal = _mm_and_pd(fscal,cutoff_mask);
979 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
981 /* Update vectorial force */
982 fix1 = _mm_macc_pd(dx10,fscal,fix1);
983 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
984 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
986 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
987 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
988 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
992 /**************************
993 * CALCULATE INTERACTIONS *
994 **************************/
996 if (gmx_mm_any_lt(rsq20,rcutoff2))
999 /* Compute parameters for interactions between i and j atoms */
1000 qq20 = _mm_mul_pd(iq2,jq0);
1002 /* REACTION-FIELD ELECTROSTATICS */
1003 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1005 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1009 fscal = _mm_and_pd(fscal,cutoff_mask);
1011 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1013 /* Update vectorial force */
1014 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1015 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1016 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1018 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1019 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1020 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1024 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1026 /* Inner loop uses 133 flops */
1029 /* End of innermost loop */
1031 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1032 f+i_coord_offset,fshift+i_shift_offset);
1034 /* Increment number of inner iterations */
1035 inneriter += j_index_end - j_index_start;
1037 /* Outer loop uses 18 flops */
1040 /* Increment number of outer iterations */
1043 /* Update outer/inner flops */
1045 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*133);