2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 "types/simple.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_VF_avx_128_fma_double
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
100 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
101 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
102 real rswitch_scalar,d_scalar;
103 __m128d dummy_mask,cutoff_mask;
104 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
105 __m128d one = _mm_set1_pd(1.0);
106 __m128d two = _mm_set1_pd(2.0);
112 jindex = nlist->jindex;
114 shiftidx = nlist->shift;
116 shiftvec = fr->shift_vec[0];
117 fshift = fr->fshift[0];
118 facel = _mm_set1_pd(fr->epsfac);
119 charge = mdatoms->chargeA;
120 krf = _mm_set1_pd(fr->ic->k_rf);
121 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
122 crf = _mm_set1_pd(fr->ic->c_rf);
123 nvdwtype = fr->ntype;
125 vdwtype = mdatoms->typeA;
127 /* Setup water-specific parameters */
128 inr = nlist->iinr[0];
129 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
130 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
131 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
132 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
134 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
135 rcutoff_scalar = fr->rcoulomb;
136 rcutoff = _mm_set1_pd(rcutoff_scalar);
137 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
139 rswitch_scalar = fr->rvdw_switch;
140 rswitch = _mm_set1_pd(rswitch_scalar);
141 /* Setup switch parameters */
142 d_scalar = rcutoff_scalar-rswitch_scalar;
143 d = _mm_set1_pd(d_scalar);
144 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
145 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
146 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
147 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
148 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
149 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
151 /* Avoid stupid compiler warnings */
159 /* Start outer loop over neighborlists */
160 for(iidx=0; iidx<nri; iidx++)
162 /* Load shift vector for this list */
163 i_shift_offset = DIM*shiftidx[iidx];
165 /* Load limits for loop over neighbors */
166 j_index_start = jindex[iidx];
167 j_index_end = jindex[iidx+1];
169 /* Get outer coordinate index */
171 i_coord_offset = DIM*inr;
173 /* Load i particle coords and add shift vector */
174 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
175 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
177 fix0 = _mm_setzero_pd();
178 fiy0 = _mm_setzero_pd();
179 fiz0 = _mm_setzero_pd();
180 fix1 = _mm_setzero_pd();
181 fiy1 = _mm_setzero_pd();
182 fiz1 = _mm_setzero_pd();
183 fix2 = _mm_setzero_pd();
184 fiy2 = _mm_setzero_pd();
185 fiz2 = _mm_setzero_pd();
187 /* Reset potential sums */
188 velecsum = _mm_setzero_pd();
189 vvdwsum = _mm_setzero_pd();
191 /* Start inner kernel loop */
192 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
195 /* Get j neighbor index, and coordinate index */
198 j_coord_offsetA = DIM*jnrA;
199 j_coord_offsetB = DIM*jnrB;
201 /* load j atom coordinates */
202 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
205 /* Calculate displacement vector */
206 dx00 = _mm_sub_pd(ix0,jx0);
207 dy00 = _mm_sub_pd(iy0,jy0);
208 dz00 = _mm_sub_pd(iz0,jz0);
209 dx10 = _mm_sub_pd(ix1,jx0);
210 dy10 = _mm_sub_pd(iy1,jy0);
211 dz10 = _mm_sub_pd(iz1,jz0);
212 dx20 = _mm_sub_pd(ix2,jx0);
213 dy20 = _mm_sub_pd(iy2,jy0);
214 dz20 = _mm_sub_pd(iz2,jz0);
216 /* Calculate squared distance and things based on it */
217 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
218 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
219 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
221 rinv00 = gmx_mm_invsqrt_pd(rsq00);
222 rinv10 = gmx_mm_invsqrt_pd(rsq10);
223 rinv20 = gmx_mm_invsqrt_pd(rsq20);
225 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
226 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
227 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
229 /* Load parameters for j particles */
230 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
231 vdwjidx0A = 2*vdwtype[jnrA+0];
232 vdwjidx0B = 2*vdwtype[jnrB+0];
234 fjx0 = _mm_setzero_pd();
235 fjy0 = _mm_setzero_pd();
236 fjz0 = _mm_setzero_pd();
238 /**************************
239 * CALCULATE INTERACTIONS *
240 **************************/
242 if (gmx_mm_any_lt(rsq00,rcutoff2))
245 r00 = _mm_mul_pd(rsq00,rinv00);
247 /* Compute parameters for interactions between i and j atoms */
248 qq00 = _mm_mul_pd(iq0,jq0);
249 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
250 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
252 /* REACTION-FIELD ELECTROSTATICS */
253 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
254 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
256 /* LENNARD-JONES DISPERSION/REPULSION */
258 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
259 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
260 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
261 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
262 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
264 d = _mm_sub_pd(r00,rswitch);
265 d = _mm_max_pd(d,_mm_setzero_pd());
266 d2 = _mm_mul_pd(d,d);
267 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
269 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
271 /* Evaluate switch function */
272 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
273 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
274 vvdw = _mm_mul_pd(vvdw,sw);
275 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
277 /* Update potential sum for this i atom from the interaction with this j atom. */
278 velec = _mm_and_pd(velec,cutoff_mask);
279 velecsum = _mm_add_pd(velecsum,velec);
280 vvdw = _mm_and_pd(vvdw,cutoff_mask);
281 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
283 fscal = _mm_add_pd(felec,fvdw);
285 fscal = _mm_and_pd(fscal,cutoff_mask);
287 /* Update vectorial force */
288 fix0 = _mm_macc_pd(dx00,fscal,fix0);
289 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
290 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
292 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
293 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
294 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
298 /**************************
299 * CALCULATE INTERACTIONS *
300 **************************/
302 if (gmx_mm_any_lt(rsq10,rcutoff2))
305 /* Compute parameters for interactions between i and j atoms */
306 qq10 = _mm_mul_pd(iq1,jq0);
308 /* REACTION-FIELD ELECTROSTATICS */
309 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
310 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
312 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
314 /* Update potential sum for this i atom from the interaction with this j atom. */
315 velec = _mm_and_pd(velec,cutoff_mask);
316 velecsum = _mm_add_pd(velecsum,velec);
320 fscal = _mm_and_pd(fscal,cutoff_mask);
322 /* Update vectorial force */
323 fix1 = _mm_macc_pd(dx10,fscal,fix1);
324 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
325 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
327 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
328 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
329 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
333 /**************************
334 * CALCULATE INTERACTIONS *
335 **************************/
337 if (gmx_mm_any_lt(rsq20,rcutoff2))
340 /* Compute parameters for interactions between i and j atoms */
341 qq20 = _mm_mul_pd(iq2,jq0);
343 /* REACTION-FIELD ELECTROSTATICS */
344 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
345 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
347 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
349 /* Update potential sum for this i atom from the interaction with this j atom. */
350 velec = _mm_and_pd(velec,cutoff_mask);
351 velecsum = _mm_add_pd(velecsum,velec);
355 fscal = _mm_and_pd(fscal,cutoff_mask);
357 /* Update vectorial force */
358 fix2 = _mm_macc_pd(dx20,fscal,fix2);
359 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
360 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
362 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
363 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
364 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
368 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
370 /* Inner loop uses 154 flops */
377 j_coord_offsetA = DIM*jnrA;
379 /* load j atom coordinates */
380 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
383 /* Calculate displacement vector */
384 dx00 = _mm_sub_pd(ix0,jx0);
385 dy00 = _mm_sub_pd(iy0,jy0);
386 dz00 = _mm_sub_pd(iz0,jz0);
387 dx10 = _mm_sub_pd(ix1,jx0);
388 dy10 = _mm_sub_pd(iy1,jy0);
389 dz10 = _mm_sub_pd(iz1,jz0);
390 dx20 = _mm_sub_pd(ix2,jx0);
391 dy20 = _mm_sub_pd(iy2,jy0);
392 dz20 = _mm_sub_pd(iz2,jz0);
394 /* Calculate squared distance and things based on it */
395 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
396 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
397 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
399 rinv00 = gmx_mm_invsqrt_pd(rsq00);
400 rinv10 = gmx_mm_invsqrt_pd(rsq10);
401 rinv20 = gmx_mm_invsqrt_pd(rsq20);
403 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
404 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
405 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
407 /* Load parameters for j particles */
408 jq0 = _mm_load_sd(charge+jnrA+0);
409 vdwjidx0A = 2*vdwtype[jnrA+0];
411 fjx0 = _mm_setzero_pd();
412 fjy0 = _mm_setzero_pd();
413 fjz0 = _mm_setzero_pd();
415 /**************************
416 * CALCULATE INTERACTIONS *
417 **************************/
419 if (gmx_mm_any_lt(rsq00,rcutoff2))
422 r00 = _mm_mul_pd(rsq00,rinv00);
424 /* Compute parameters for interactions between i and j atoms */
425 qq00 = _mm_mul_pd(iq0,jq0);
426 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
428 /* REACTION-FIELD ELECTROSTATICS */
429 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
430 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
432 /* LENNARD-JONES DISPERSION/REPULSION */
434 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
435 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
436 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
437 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
438 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
440 d = _mm_sub_pd(r00,rswitch);
441 d = _mm_max_pd(d,_mm_setzero_pd());
442 d2 = _mm_mul_pd(d,d);
443 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
445 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
447 /* Evaluate switch function */
448 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
449 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
450 vvdw = _mm_mul_pd(vvdw,sw);
451 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm_and_pd(velec,cutoff_mask);
455 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
456 velecsum = _mm_add_pd(velecsum,velec);
457 vvdw = _mm_and_pd(vvdw,cutoff_mask);
458 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
459 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
461 fscal = _mm_add_pd(felec,fvdw);
463 fscal = _mm_and_pd(fscal,cutoff_mask);
465 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
467 /* Update vectorial force */
468 fix0 = _mm_macc_pd(dx00,fscal,fix0);
469 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
470 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
472 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
473 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
474 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
478 /**************************
479 * CALCULATE INTERACTIONS *
480 **************************/
482 if (gmx_mm_any_lt(rsq10,rcutoff2))
485 /* Compute parameters for interactions between i and j atoms */
486 qq10 = _mm_mul_pd(iq1,jq0);
488 /* REACTION-FIELD ELECTROSTATICS */
489 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
490 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
492 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
494 /* Update potential sum for this i atom from the interaction with this j atom. */
495 velec = _mm_and_pd(velec,cutoff_mask);
496 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
497 velecsum = _mm_add_pd(velecsum,velec);
501 fscal = _mm_and_pd(fscal,cutoff_mask);
503 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
505 /* Update vectorial force */
506 fix1 = _mm_macc_pd(dx10,fscal,fix1);
507 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
508 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
510 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
511 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
512 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
516 /**************************
517 * CALCULATE INTERACTIONS *
518 **************************/
520 if (gmx_mm_any_lt(rsq20,rcutoff2))
523 /* Compute parameters for interactions between i and j atoms */
524 qq20 = _mm_mul_pd(iq2,jq0);
526 /* REACTION-FIELD ELECTROSTATICS */
527 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
528 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
530 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
532 /* Update potential sum for this i atom from the interaction with this j atom. */
533 velec = _mm_and_pd(velec,cutoff_mask);
534 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
535 velecsum = _mm_add_pd(velecsum,velec);
539 fscal = _mm_and_pd(fscal,cutoff_mask);
541 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
543 /* Update vectorial force */
544 fix2 = _mm_macc_pd(dx20,fscal,fix2);
545 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
546 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
548 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
549 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
550 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
554 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
556 /* Inner loop uses 154 flops */
559 /* End of innermost loop */
561 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
562 f+i_coord_offset,fshift+i_shift_offset);
565 /* Update potential energies */
566 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
567 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
569 /* Increment number of inner iterations */
570 inneriter += j_index_end - j_index_start;
572 /* Outer loop uses 20 flops */
575 /* Increment number of outer iterations */
578 /* Update outer/inner flops */
580 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
583 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
584 * Electrostatics interaction: ReactionField
585 * VdW interaction: LennardJones
586 * Geometry: Water3-Particle
587 * Calculate force/pot: Force
590 nb_kernel_ElecRFCut_VdwLJSw_GeomW3P1_F_avx_128_fma_double
591 (t_nblist * gmx_restrict nlist,
592 rvec * gmx_restrict xx,
593 rvec * gmx_restrict ff,
594 t_forcerec * gmx_restrict fr,
595 t_mdatoms * gmx_restrict mdatoms,
596 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
597 t_nrnb * gmx_restrict nrnb)
599 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
600 * just 0 for non-waters.
601 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
602 * jnr indices corresponding to data put in the four positions in the SIMD register.
604 int i_shift_offset,i_coord_offset,outeriter,inneriter;
605 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
607 int j_coord_offsetA,j_coord_offsetB;
608 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
610 real *shiftvec,*fshift,*x,*f;
611 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
613 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
615 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
617 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
618 int vdwjidx0A,vdwjidx0B;
619 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
620 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
621 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
622 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
623 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
626 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
629 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
630 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
631 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
632 real rswitch_scalar,d_scalar;
633 __m128d dummy_mask,cutoff_mask;
634 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
635 __m128d one = _mm_set1_pd(1.0);
636 __m128d two = _mm_set1_pd(2.0);
642 jindex = nlist->jindex;
644 shiftidx = nlist->shift;
646 shiftvec = fr->shift_vec[0];
647 fshift = fr->fshift[0];
648 facel = _mm_set1_pd(fr->epsfac);
649 charge = mdatoms->chargeA;
650 krf = _mm_set1_pd(fr->ic->k_rf);
651 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
652 crf = _mm_set1_pd(fr->ic->c_rf);
653 nvdwtype = fr->ntype;
655 vdwtype = mdatoms->typeA;
657 /* Setup water-specific parameters */
658 inr = nlist->iinr[0];
659 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
660 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
661 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
662 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
664 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
665 rcutoff_scalar = fr->rcoulomb;
666 rcutoff = _mm_set1_pd(rcutoff_scalar);
667 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
669 rswitch_scalar = fr->rvdw_switch;
670 rswitch = _mm_set1_pd(rswitch_scalar);
671 /* Setup switch parameters */
672 d_scalar = rcutoff_scalar-rswitch_scalar;
673 d = _mm_set1_pd(d_scalar);
674 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
675 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
676 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
677 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
678 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
679 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
681 /* Avoid stupid compiler warnings */
689 /* Start outer loop over neighborlists */
690 for(iidx=0; iidx<nri; iidx++)
692 /* Load shift vector for this list */
693 i_shift_offset = DIM*shiftidx[iidx];
695 /* Load limits for loop over neighbors */
696 j_index_start = jindex[iidx];
697 j_index_end = jindex[iidx+1];
699 /* Get outer coordinate index */
701 i_coord_offset = DIM*inr;
703 /* Load i particle coords and add shift vector */
704 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
705 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
707 fix0 = _mm_setzero_pd();
708 fiy0 = _mm_setzero_pd();
709 fiz0 = _mm_setzero_pd();
710 fix1 = _mm_setzero_pd();
711 fiy1 = _mm_setzero_pd();
712 fiz1 = _mm_setzero_pd();
713 fix2 = _mm_setzero_pd();
714 fiy2 = _mm_setzero_pd();
715 fiz2 = _mm_setzero_pd();
717 /* Start inner kernel loop */
718 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
721 /* Get j neighbor index, and coordinate index */
724 j_coord_offsetA = DIM*jnrA;
725 j_coord_offsetB = DIM*jnrB;
727 /* load j atom coordinates */
728 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
731 /* Calculate displacement vector */
732 dx00 = _mm_sub_pd(ix0,jx0);
733 dy00 = _mm_sub_pd(iy0,jy0);
734 dz00 = _mm_sub_pd(iz0,jz0);
735 dx10 = _mm_sub_pd(ix1,jx0);
736 dy10 = _mm_sub_pd(iy1,jy0);
737 dz10 = _mm_sub_pd(iz1,jz0);
738 dx20 = _mm_sub_pd(ix2,jx0);
739 dy20 = _mm_sub_pd(iy2,jy0);
740 dz20 = _mm_sub_pd(iz2,jz0);
742 /* Calculate squared distance and things based on it */
743 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
744 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
745 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
747 rinv00 = gmx_mm_invsqrt_pd(rsq00);
748 rinv10 = gmx_mm_invsqrt_pd(rsq10);
749 rinv20 = gmx_mm_invsqrt_pd(rsq20);
751 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
752 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
753 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
755 /* Load parameters for j particles */
756 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
757 vdwjidx0A = 2*vdwtype[jnrA+0];
758 vdwjidx0B = 2*vdwtype[jnrB+0];
760 fjx0 = _mm_setzero_pd();
761 fjy0 = _mm_setzero_pd();
762 fjz0 = _mm_setzero_pd();
764 /**************************
765 * CALCULATE INTERACTIONS *
766 **************************/
768 if (gmx_mm_any_lt(rsq00,rcutoff2))
771 r00 = _mm_mul_pd(rsq00,rinv00);
773 /* Compute parameters for interactions between i and j atoms */
774 qq00 = _mm_mul_pd(iq0,jq0);
775 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
776 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
778 /* REACTION-FIELD ELECTROSTATICS */
779 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
781 /* LENNARD-JONES DISPERSION/REPULSION */
783 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
784 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
785 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
786 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
787 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
789 d = _mm_sub_pd(r00,rswitch);
790 d = _mm_max_pd(d,_mm_setzero_pd());
791 d2 = _mm_mul_pd(d,d);
792 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
794 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
796 /* Evaluate switch function */
797 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
798 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
799 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
801 fscal = _mm_add_pd(felec,fvdw);
803 fscal = _mm_and_pd(fscal,cutoff_mask);
805 /* Update vectorial force */
806 fix0 = _mm_macc_pd(dx00,fscal,fix0);
807 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
808 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
810 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
811 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
812 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
816 /**************************
817 * CALCULATE INTERACTIONS *
818 **************************/
820 if (gmx_mm_any_lt(rsq10,rcutoff2))
823 /* Compute parameters for interactions between i and j atoms */
824 qq10 = _mm_mul_pd(iq1,jq0);
826 /* REACTION-FIELD ELECTROSTATICS */
827 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
829 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
833 fscal = _mm_and_pd(fscal,cutoff_mask);
835 /* Update vectorial force */
836 fix1 = _mm_macc_pd(dx10,fscal,fix1);
837 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
838 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
840 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
841 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
842 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
846 /**************************
847 * CALCULATE INTERACTIONS *
848 **************************/
850 if (gmx_mm_any_lt(rsq20,rcutoff2))
853 /* Compute parameters for interactions between i and j atoms */
854 qq20 = _mm_mul_pd(iq2,jq0);
856 /* REACTION-FIELD ELECTROSTATICS */
857 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
859 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
863 fscal = _mm_and_pd(fscal,cutoff_mask);
865 /* Update vectorial force */
866 fix2 = _mm_macc_pd(dx20,fscal,fix2);
867 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
868 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
870 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
871 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
872 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
876 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
878 /* Inner loop uses 133 flops */
885 j_coord_offsetA = DIM*jnrA;
887 /* load j atom coordinates */
888 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
891 /* Calculate displacement vector */
892 dx00 = _mm_sub_pd(ix0,jx0);
893 dy00 = _mm_sub_pd(iy0,jy0);
894 dz00 = _mm_sub_pd(iz0,jz0);
895 dx10 = _mm_sub_pd(ix1,jx0);
896 dy10 = _mm_sub_pd(iy1,jy0);
897 dz10 = _mm_sub_pd(iz1,jz0);
898 dx20 = _mm_sub_pd(ix2,jx0);
899 dy20 = _mm_sub_pd(iy2,jy0);
900 dz20 = _mm_sub_pd(iz2,jz0);
902 /* Calculate squared distance and things based on it */
903 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
904 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
905 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
907 rinv00 = gmx_mm_invsqrt_pd(rsq00);
908 rinv10 = gmx_mm_invsqrt_pd(rsq10);
909 rinv20 = gmx_mm_invsqrt_pd(rsq20);
911 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
912 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
913 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
915 /* Load parameters for j particles */
916 jq0 = _mm_load_sd(charge+jnrA+0);
917 vdwjidx0A = 2*vdwtype[jnrA+0];
919 fjx0 = _mm_setzero_pd();
920 fjy0 = _mm_setzero_pd();
921 fjz0 = _mm_setzero_pd();
923 /**************************
924 * CALCULATE INTERACTIONS *
925 **************************/
927 if (gmx_mm_any_lt(rsq00,rcutoff2))
930 r00 = _mm_mul_pd(rsq00,rinv00);
932 /* Compute parameters for interactions between i and j atoms */
933 qq00 = _mm_mul_pd(iq0,jq0);
934 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
936 /* REACTION-FIELD ELECTROSTATICS */
937 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
939 /* LENNARD-JONES DISPERSION/REPULSION */
941 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
942 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
943 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
944 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
945 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
947 d = _mm_sub_pd(r00,rswitch);
948 d = _mm_max_pd(d,_mm_setzero_pd());
949 d2 = _mm_mul_pd(d,d);
950 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
952 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
954 /* Evaluate switch function */
955 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
956 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
957 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
959 fscal = _mm_add_pd(felec,fvdw);
961 fscal = _mm_and_pd(fscal,cutoff_mask);
963 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
965 /* Update vectorial force */
966 fix0 = _mm_macc_pd(dx00,fscal,fix0);
967 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
968 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
970 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
971 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
972 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
976 /**************************
977 * CALCULATE INTERACTIONS *
978 **************************/
980 if (gmx_mm_any_lt(rsq10,rcutoff2))
983 /* Compute parameters for interactions between i and j atoms */
984 qq10 = _mm_mul_pd(iq1,jq0);
986 /* REACTION-FIELD ELECTROSTATICS */
987 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
989 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
993 fscal = _mm_and_pd(fscal,cutoff_mask);
995 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
997 /* Update vectorial force */
998 fix1 = _mm_macc_pd(dx10,fscal,fix1);
999 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1000 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1002 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1003 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1004 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1008 /**************************
1009 * CALCULATE INTERACTIONS *
1010 **************************/
1012 if (gmx_mm_any_lt(rsq20,rcutoff2))
1015 /* Compute parameters for interactions between i and j atoms */
1016 qq20 = _mm_mul_pd(iq2,jq0);
1018 /* REACTION-FIELD ELECTROSTATICS */
1019 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1021 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1025 fscal = _mm_and_pd(fscal,cutoff_mask);
1027 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1029 /* Update vectorial force */
1030 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1031 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1032 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1034 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1035 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1036 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1040 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1042 /* Inner loop uses 133 flops */
1045 /* End of innermost loop */
1047 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1048 f+i_coord_offset,fshift+i_shift_offset);
1050 /* Increment number of inner iterations */
1051 inneriter += j_index_end - j_index_start;
1053 /* Outer loop uses 18 flops */
1056 /* Increment number of outer iterations */
1059 /* Update outer/inner flops */
1061 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*133);