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_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_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;
86 int vdwjidx0A,vdwjidx0B;
87 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
90 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
91 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
94 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
98 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
99 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
100 real rswitch_scalar,d_scalar;
101 __m128d dummy_mask,cutoff_mask;
102 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
103 __m128d one = _mm_set1_pd(1.0);
104 __m128d two = _mm_set1_pd(2.0);
110 jindex = nlist->jindex;
112 shiftidx = nlist->shift;
114 shiftvec = fr->shift_vec[0];
115 fshift = fr->fshift[0];
116 facel = _mm_set1_pd(fr->epsfac);
117 charge = mdatoms->chargeA;
118 krf = _mm_set1_pd(fr->ic->k_rf);
119 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
120 crf = _mm_set1_pd(fr->ic->c_rf);
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 /* Setup water-specific parameters */
126 inr = nlist->iinr[0];
127 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
128 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
129 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
130 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
132 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
133 rcutoff_scalar = fr->rcoulomb;
134 rcutoff = _mm_set1_pd(rcutoff_scalar);
135 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
137 rswitch_scalar = fr->rvdw_switch;
138 rswitch = _mm_set1_pd(rswitch_scalar);
139 /* Setup switch parameters */
140 d_scalar = rcutoff_scalar-rswitch_scalar;
141 d = _mm_set1_pd(d_scalar);
142 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
143 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
144 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
145 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
146 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
147 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
149 /* Avoid stupid compiler warnings */
157 /* Start outer loop over neighborlists */
158 for(iidx=0; iidx<nri; iidx++)
160 /* Load shift vector for this list */
161 i_shift_offset = DIM*shiftidx[iidx];
163 /* Load limits for loop over neighbors */
164 j_index_start = jindex[iidx];
165 j_index_end = jindex[iidx+1];
167 /* Get outer coordinate index */
169 i_coord_offset = DIM*inr;
171 /* Load i particle coords and add shift vector */
172 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
173 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
175 fix0 = _mm_setzero_pd();
176 fiy0 = _mm_setzero_pd();
177 fiz0 = _mm_setzero_pd();
178 fix1 = _mm_setzero_pd();
179 fiy1 = _mm_setzero_pd();
180 fiz1 = _mm_setzero_pd();
181 fix2 = _mm_setzero_pd();
182 fiy2 = _mm_setzero_pd();
183 fiz2 = _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);
214 /* Calculate squared distance and things based on it */
215 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
216 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
217 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
219 rinv00 = gmx_mm_invsqrt_pd(rsq00);
220 rinv10 = gmx_mm_invsqrt_pd(rsq10);
221 rinv20 = gmx_mm_invsqrt_pd(rsq20);
223 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
224 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
225 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
227 /* Load parameters for j particles */
228 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
229 vdwjidx0A = 2*vdwtype[jnrA+0];
230 vdwjidx0B = 2*vdwtype[jnrB+0];
232 fjx0 = _mm_setzero_pd();
233 fjy0 = _mm_setzero_pd();
234 fjz0 = _mm_setzero_pd();
236 /**************************
237 * CALCULATE INTERACTIONS *
238 **************************/
240 if (gmx_mm_any_lt(rsq00,rcutoff2))
243 r00 = _mm_mul_pd(rsq00,rinv00);
245 /* Compute parameters for interactions between i and j atoms */
246 qq00 = _mm_mul_pd(iq0,jq0);
247 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
248 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
250 /* REACTION-FIELD ELECTROSTATICS */
251 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
252 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
254 /* LENNARD-JONES DISPERSION/REPULSION */
256 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
257 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
258 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
259 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
260 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
262 d = _mm_sub_pd(r00,rswitch);
263 d = _mm_max_pd(d,_mm_setzero_pd());
264 d2 = _mm_mul_pd(d,d);
265 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
267 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
269 /* Evaluate switch function */
270 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
271 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
272 vvdw = _mm_mul_pd(vvdw,sw);
273 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_and_pd(velec,cutoff_mask);
277 velecsum = _mm_add_pd(velecsum,velec);
278 vvdw = _mm_and_pd(vvdw,cutoff_mask);
279 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
281 fscal = _mm_add_pd(felec,fvdw);
283 fscal = _mm_and_pd(fscal,cutoff_mask);
285 /* Update vectorial force */
286 fix0 = _mm_macc_pd(dx00,fscal,fix0);
287 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
288 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
290 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
291 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
292 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
296 /**************************
297 * CALCULATE INTERACTIONS *
298 **************************/
300 if (gmx_mm_any_lt(rsq10,rcutoff2))
303 /* Compute parameters for interactions between i and j atoms */
304 qq10 = _mm_mul_pd(iq1,jq0);
306 /* REACTION-FIELD ELECTROSTATICS */
307 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
308 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
310 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
312 /* Update potential sum for this i atom from the interaction with this j atom. */
313 velec = _mm_and_pd(velec,cutoff_mask);
314 velecsum = _mm_add_pd(velecsum,velec);
318 fscal = _mm_and_pd(fscal,cutoff_mask);
320 /* Update vectorial force */
321 fix1 = _mm_macc_pd(dx10,fscal,fix1);
322 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
323 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
325 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
326 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
327 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
331 /**************************
332 * CALCULATE INTERACTIONS *
333 **************************/
335 if (gmx_mm_any_lt(rsq20,rcutoff2))
338 /* Compute parameters for interactions between i and j atoms */
339 qq20 = _mm_mul_pd(iq2,jq0);
341 /* REACTION-FIELD ELECTROSTATICS */
342 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
343 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
345 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
347 /* Update potential sum for this i atom from the interaction with this j atom. */
348 velec = _mm_and_pd(velec,cutoff_mask);
349 velecsum = _mm_add_pd(velecsum,velec);
353 fscal = _mm_and_pd(fscal,cutoff_mask);
355 /* Update vectorial force */
356 fix2 = _mm_macc_pd(dx20,fscal,fix2);
357 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
358 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
360 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
361 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
362 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
366 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
368 /* Inner loop uses 154 flops */
375 j_coord_offsetA = DIM*jnrA;
377 /* load j atom coordinates */
378 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
381 /* Calculate displacement vector */
382 dx00 = _mm_sub_pd(ix0,jx0);
383 dy00 = _mm_sub_pd(iy0,jy0);
384 dz00 = _mm_sub_pd(iz0,jz0);
385 dx10 = _mm_sub_pd(ix1,jx0);
386 dy10 = _mm_sub_pd(iy1,jy0);
387 dz10 = _mm_sub_pd(iz1,jz0);
388 dx20 = _mm_sub_pd(ix2,jx0);
389 dy20 = _mm_sub_pd(iy2,jy0);
390 dz20 = _mm_sub_pd(iz2,jz0);
392 /* Calculate squared distance and things based on it */
393 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
394 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
395 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
397 rinv00 = gmx_mm_invsqrt_pd(rsq00);
398 rinv10 = gmx_mm_invsqrt_pd(rsq10);
399 rinv20 = gmx_mm_invsqrt_pd(rsq20);
401 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
402 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
403 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
405 /* Load parameters for j particles */
406 jq0 = _mm_load_sd(charge+jnrA+0);
407 vdwjidx0A = 2*vdwtype[jnrA+0];
409 fjx0 = _mm_setzero_pd();
410 fjy0 = _mm_setzero_pd();
411 fjz0 = _mm_setzero_pd();
413 /**************************
414 * CALCULATE INTERACTIONS *
415 **************************/
417 if (gmx_mm_any_lt(rsq00,rcutoff2))
420 r00 = _mm_mul_pd(rsq00,rinv00);
422 /* Compute parameters for interactions between i and j atoms */
423 qq00 = _mm_mul_pd(iq0,jq0);
424 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
426 /* REACTION-FIELD ELECTROSTATICS */
427 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
428 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
430 /* LENNARD-JONES DISPERSION/REPULSION */
432 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
433 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
434 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
435 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
436 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
438 d = _mm_sub_pd(r00,rswitch);
439 d = _mm_max_pd(d,_mm_setzero_pd());
440 d2 = _mm_mul_pd(d,d);
441 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
443 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
445 /* Evaluate switch function */
446 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
447 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
448 vvdw = _mm_mul_pd(vvdw,sw);
449 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
451 /* Update potential sum for this i atom from the interaction with this j atom. */
452 velec = _mm_and_pd(velec,cutoff_mask);
453 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
454 velecsum = _mm_add_pd(velecsum,velec);
455 vvdw = _mm_and_pd(vvdw,cutoff_mask);
456 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
457 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
459 fscal = _mm_add_pd(felec,fvdw);
461 fscal = _mm_and_pd(fscal,cutoff_mask);
463 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
465 /* Update vectorial force */
466 fix0 = _mm_macc_pd(dx00,fscal,fix0);
467 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
468 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
470 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
471 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
472 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
476 /**************************
477 * CALCULATE INTERACTIONS *
478 **************************/
480 if (gmx_mm_any_lt(rsq10,rcutoff2))
483 /* Compute parameters for interactions between i and j atoms */
484 qq10 = _mm_mul_pd(iq1,jq0);
486 /* REACTION-FIELD ELECTROSTATICS */
487 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
488 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
490 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
492 /* Update potential sum for this i atom from the interaction with this j atom. */
493 velec = _mm_and_pd(velec,cutoff_mask);
494 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
495 velecsum = _mm_add_pd(velecsum,velec);
499 fscal = _mm_and_pd(fscal,cutoff_mask);
501 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
503 /* Update vectorial force */
504 fix1 = _mm_macc_pd(dx10,fscal,fix1);
505 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
506 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
508 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
509 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
510 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
514 /**************************
515 * CALCULATE INTERACTIONS *
516 **************************/
518 if (gmx_mm_any_lt(rsq20,rcutoff2))
521 /* Compute parameters for interactions between i and j atoms */
522 qq20 = _mm_mul_pd(iq2,jq0);
524 /* REACTION-FIELD ELECTROSTATICS */
525 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
526 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
528 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
530 /* Update potential sum for this i atom from the interaction with this j atom. */
531 velec = _mm_and_pd(velec,cutoff_mask);
532 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
533 velecsum = _mm_add_pd(velecsum,velec);
537 fscal = _mm_and_pd(fscal,cutoff_mask);
539 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
541 /* Update vectorial force */
542 fix2 = _mm_macc_pd(dx20,fscal,fix2);
543 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
544 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
546 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
547 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
548 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
552 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
554 /* Inner loop uses 154 flops */
557 /* End of innermost loop */
559 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
560 f+i_coord_offset,fshift+i_shift_offset);
563 /* Update potential energies */
564 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
565 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
567 /* Increment number of inner iterations */
568 inneriter += j_index_end - j_index_start;
570 /* Outer loop uses 20 flops */
573 /* Increment number of outer iterations */
576 /* Update outer/inner flops */
578 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
581 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
582 * Electrostatics interaction: ReactionField
583 * VdW interaction: LennardJones
584 * Geometry: Water3-Particle
585 * Calculate force/pot: Force
588 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
589 (t_nblist * gmx_restrict nlist,
590 rvec * gmx_restrict xx,
591 rvec * gmx_restrict ff,
592 t_forcerec * gmx_restrict fr,
593 t_mdatoms * gmx_restrict mdatoms,
594 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
595 t_nrnb * gmx_restrict nrnb)
597 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
598 * just 0 for non-waters.
599 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
600 * jnr indices corresponding to data put in the four positions in the SIMD register.
602 int i_shift_offset,i_coord_offset,outeriter,inneriter;
603 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
605 int j_coord_offsetA,j_coord_offsetB;
606 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
608 real *shiftvec,*fshift,*x,*f;
609 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
611 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
613 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
615 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
616 int vdwjidx0A,vdwjidx0B;
617 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
618 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
619 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
620 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
621 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
624 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
627 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
628 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
629 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
630 real rswitch_scalar,d_scalar;
631 __m128d dummy_mask,cutoff_mask;
632 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
633 __m128d one = _mm_set1_pd(1.0);
634 __m128d two = _mm_set1_pd(2.0);
640 jindex = nlist->jindex;
642 shiftidx = nlist->shift;
644 shiftvec = fr->shift_vec[0];
645 fshift = fr->fshift[0];
646 facel = _mm_set1_pd(fr->epsfac);
647 charge = mdatoms->chargeA;
648 krf = _mm_set1_pd(fr->ic->k_rf);
649 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
650 crf = _mm_set1_pd(fr->ic->c_rf);
651 nvdwtype = fr->ntype;
653 vdwtype = mdatoms->typeA;
655 /* Setup water-specific parameters */
656 inr = nlist->iinr[0];
657 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
658 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
659 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
660 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
662 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
663 rcutoff_scalar = fr->rcoulomb;
664 rcutoff = _mm_set1_pd(rcutoff_scalar);
665 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
667 rswitch_scalar = fr->rvdw_switch;
668 rswitch = _mm_set1_pd(rswitch_scalar);
669 /* Setup switch parameters */
670 d_scalar = rcutoff_scalar-rswitch_scalar;
671 d = _mm_set1_pd(d_scalar);
672 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
673 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
674 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
675 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
676 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
677 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
679 /* Avoid stupid compiler warnings */
687 /* Start outer loop over neighborlists */
688 for(iidx=0; iidx<nri; iidx++)
690 /* Load shift vector for this list */
691 i_shift_offset = DIM*shiftidx[iidx];
693 /* Load limits for loop over neighbors */
694 j_index_start = jindex[iidx];
695 j_index_end = jindex[iidx+1];
697 /* Get outer coordinate index */
699 i_coord_offset = DIM*inr;
701 /* Load i particle coords and add shift vector */
702 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
703 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
705 fix0 = _mm_setzero_pd();
706 fiy0 = _mm_setzero_pd();
707 fiz0 = _mm_setzero_pd();
708 fix1 = _mm_setzero_pd();
709 fiy1 = _mm_setzero_pd();
710 fiz1 = _mm_setzero_pd();
711 fix2 = _mm_setzero_pd();
712 fiy2 = _mm_setzero_pd();
713 fiz2 = _mm_setzero_pd();
715 /* Start inner kernel loop */
716 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
719 /* Get j neighbor index, and coordinate index */
722 j_coord_offsetA = DIM*jnrA;
723 j_coord_offsetB = DIM*jnrB;
725 /* load j atom coordinates */
726 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
729 /* Calculate displacement vector */
730 dx00 = _mm_sub_pd(ix0,jx0);
731 dy00 = _mm_sub_pd(iy0,jy0);
732 dz00 = _mm_sub_pd(iz0,jz0);
733 dx10 = _mm_sub_pd(ix1,jx0);
734 dy10 = _mm_sub_pd(iy1,jy0);
735 dz10 = _mm_sub_pd(iz1,jz0);
736 dx20 = _mm_sub_pd(ix2,jx0);
737 dy20 = _mm_sub_pd(iy2,jy0);
738 dz20 = _mm_sub_pd(iz2,jz0);
740 /* Calculate squared distance and things based on it */
741 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
742 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
743 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
745 rinv00 = gmx_mm_invsqrt_pd(rsq00);
746 rinv10 = gmx_mm_invsqrt_pd(rsq10);
747 rinv20 = gmx_mm_invsqrt_pd(rsq20);
749 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
750 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
751 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
753 /* Load parameters for j particles */
754 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
755 vdwjidx0A = 2*vdwtype[jnrA+0];
756 vdwjidx0B = 2*vdwtype[jnrB+0];
758 fjx0 = _mm_setzero_pd();
759 fjy0 = _mm_setzero_pd();
760 fjz0 = _mm_setzero_pd();
762 /**************************
763 * CALCULATE INTERACTIONS *
764 **************************/
766 if (gmx_mm_any_lt(rsq00,rcutoff2))
769 r00 = _mm_mul_pd(rsq00,rinv00);
771 /* Compute parameters for interactions between i and j atoms */
772 qq00 = _mm_mul_pd(iq0,jq0);
773 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
774 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
776 /* REACTION-FIELD ELECTROSTATICS */
777 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
779 /* LENNARD-JONES DISPERSION/REPULSION */
781 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
782 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
783 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
784 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
785 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
787 d = _mm_sub_pd(r00,rswitch);
788 d = _mm_max_pd(d,_mm_setzero_pd());
789 d2 = _mm_mul_pd(d,d);
790 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
792 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
794 /* Evaluate switch function */
795 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
796 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
797 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
799 fscal = _mm_add_pd(felec,fvdw);
801 fscal = _mm_and_pd(fscal,cutoff_mask);
803 /* Update vectorial force */
804 fix0 = _mm_macc_pd(dx00,fscal,fix0);
805 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
806 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
808 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
809 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
810 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
814 /**************************
815 * CALCULATE INTERACTIONS *
816 **************************/
818 if (gmx_mm_any_lt(rsq10,rcutoff2))
821 /* Compute parameters for interactions between i and j atoms */
822 qq10 = _mm_mul_pd(iq1,jq0);
824 /* REACTION-FIELD ELECTROSTATICS */
825 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
827 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
831 fscal = _mm_and_pd(fscal,cutoff_mask);
833 /* Update vectorial force */
834 fix1 = _mm_macc_pd(dx10,fscal,fix1);
835 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
836 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
838 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
839 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
840 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
844 /**************************
845 * CALCULATE INTERACTIONS *
846 **************************/
848 if (gmx_mm_any_lt(rsq20,rcutoff2))
851 /* Compute parameters for interactions between i and j atoms */
852 qq20 = _mm_mul_pd(iq2,jq0);
854 /* REACTION-FIELD ELECTROSTATICS */
855 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
857 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
861 fscal = _mm_and_pd(fscal,cutoff_mask);
863 /* Update vectorial force */
864 fix2 = _mm_macc_pd(dx20,fscal,fix2);
865 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
866 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
868 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
869 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
870 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
874 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
876 /* Inner loop uses 133 flops */
883 j_coord_offsetA = DIM*jnrA;
885 /* load j atom coordinates */
886 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
889 /* Calculate displacement vector */
890 dx00 = _mm_sub_pd(ix0,jx0);
891 dy00 = _mm_sub_pd(iy0,jy0);
892 dz00 = _mm_sub_pd(iz0,jz0);
893 dx10 = _mm_sub_pd(ix1,jx0);
894 dy10 = _mm_sub_pd(iy1,jy0);
895 dz10 = _mm_sub_pd(iz1,jz0);
896 dx20 = _mm_sub_pd(ix2,jx0);
897 dy20 = _mm_sub_pd(iy2,jy0);
898 dz20 = _mm_sub_pd(iz2,jz0);
900 /* Calculate squared distance and things based on it */
901 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
902 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
903 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
905 rinv00 = gmx_mm_invsqrt_pd(rsq00);
906 rinv10 = gmx_mm_invsqrt_pd(rsq10);
907 rinv20 = gmx_mm_invsqrt_pd(rsq20);
909 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
910 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
911 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
913 /* Load parameters for j particles */
914 jq0 = _mm_load_sd(charge+jnrA+0);
915 vdwjidx0A = 2*vdwtype[jnrA+0];
917 fjx0 = _mm_setzero_pd();
918 fjy0 = _mm_setzero_pd();
919 fjz0 = _mm_setzero_pd();
921 /**************************
922 * CALCULATE INTERACTIONS *
923 **************************/
925 if (gmx_mm_any_lt(rsq00,rcutoff2))
928 r00 = _mm_mul_pd(rsq00,rinv00);
930 /* Compute parameters for interactions between i and j atoms */
931 qq00 = _mm_mul_pd(iq0,jq0);
932 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
934 /* REACTION-FIELD ELECTROSTATICS */
935 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
937 /* LENNARD-JONES DISPERSION/REPULSION */
939 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
940 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
941 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
942 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
943 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
945 d = _mm_sub_pd(r00,rswitch);
946 d = _mm_max_pd(d,_mm_setzero_pd());
947 d2 = _mm_mul_pd(d,d);
948 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
950 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
952 /* Evaluate switch function */
953 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
954 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
955 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
957 fscal = _mm_add_pd(felec,fvdw);
959 fscal = _mm_and_pd(fscal,cutoff_mask);
961 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
963 /* Update vectorial force */
964 fix0 = _mm_macc_pd(dx00,fscal,fix0);
965 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
966 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
968 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
969 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
970 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
974 /**************************
975 * CALCULATE INTERACTIONS *
976 **************************/
978 if (gmx_mm_any_lt(rsq10,rcutoff2))
981 /* Compute parameters for interactions between i and j atoms */
982 qq10 = _mm_mul_pd(iq1,jq0);
984 /* REACTION-FIELD ELECTROSTATICS */
985 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
987 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
991 fscal = _mm_and_pd(fscal,cutoff_mask);
993 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
995 /* Update vectorial force */
996 fix1 = _mm_macc_pd(dx10,fscal,fix1);
997 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
998 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1000 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1001 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1002 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1006 /**************************
1007 * CALCULATE INTERACTIONS *
1008 **************************/
1010 if (gmx_mm_any_lt(rsq20,rcutoff2))
1013 /* Compute parameters for interactions between i and j atoms */
1014 qq20 = _mm_mul_pd(iq2,jq0);
1016 /* REACTION-FIELD ELECTROSTATICS */
1017 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1019 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1023 fscal = _mm_and_pd(fscal,cutoff_mask);
1025 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1027 /* Update vectorial force */
1028 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1029 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1030 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1032 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1033 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1034 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1038 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1040 /* Inner loop uses 133 flops */
1043 /* End of innermost loop */
1045 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1046 f+i_coord_offset,fshift+i_shift_offset);
1048 /* Increment number of inner iterations */
1049 inneriter += j_index_end - j_index_start;
1051 /* Outer loop uses 18 flops */
1054 /* Increment number of outer iterations */
1057 /* Update outer/inner flops */
1059 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*133);