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_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
101 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
102 __m128d dummy_mask,cutoff_mask;
103 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
104 __m128d one = _mm_set1_pd(1.0);
105 __m128d two = _mm_set1_pd(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_pd(fr->epsfac);
118 charge = mdatoms->chargeA;
119 krf = _mm_set1_pd(fr->ic->k_rf);
120 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
121 crf = _mm_set1_pd(fr->ic->c_rf);
122 nvdwtype = fr->ntype;
124 vdwtype = mdatoms->typeA;
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[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 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
131 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
133 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
134 rcutoff_scalar = fr->rcoulomb;
135 rcutoff = _mm_set1_pd(rcutoff_scalar);
136 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
138 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
139 rvdw = _mm_set1_pd(fr->rvdw);
141 /* Avoid stupid compiler warnings */
149 /* Start outer loop over neighborlists */
150 for(iidx=0; iidx<nri; iidx++)
152 /* Load shift vector for this list */
153 i_shift_offset = DIM*shiftidx[iidx];
155 /* Load limits for loop over neighbors */
156 j_index_start = jindex[iidx];
157 j_index_end = jindex[iidx+1];
159 /* Get outer coordinate index */
161 i_coord_offset = DIM*inr;
163 /* Load i particle coords and add shift vector */
164 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
165 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
167 fix0 = _mm_setzero_pd();
168 fiy0 = _mm_setzero_pd();
169 fiz0 = _mm_setzero_pd();
170 fix1 = _mm_setzero_pd();
171 fiy1 = _mm_setzero_pd();
172 fiz1 = _mm_setzero_pd();
173 fix2 = _mm_setzero_pd();
174 fiy2 = _mm_setzero_pd();
175 fiz2 = _mm_setzero_pd();
176 fix3 = _mm_setzero_pd();
177 fiy3 = _mm_setzero_pd();
178 fiz3 = _mm_setzero_pd();
180 /* Reset potential sums */
181 velecsum = _mm_setzero_pd();
182 vvdwsum = _mm_setzero_pd();
184 /* Start inner kernel loop */
185 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
188 /* Get j neighbor index, and coordinate index */
191 j_coord_offsetA = DIM*jnrA;
192 j_coord_offsetB = DIM*jnrB;
194 /* load j atom coordinates */
195 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
198 /* Calculate displacement vector */
199 dx00 = _mm_sub_pd(ix0,jx0);
200 dy00 = _mm_sub_pd(iy0,jy0);
201 dz00 = _mm_sub_pd(iz0,jz0);
202 dx10 = _mm_sub_pd(ix1,jx0);
203 dy10 = _mm_sub_pd(iy1,jy0);
204 dz10 = _mm_sub_pd(iz1,jz0);
205 dx20 = _mm_sub_pd(ix2,jx0);
206 dy20 = _mm_sub_pd(iy2,jy0);
207 dz20 = _mm_sub_pd(iz2,jz0);
208 dx30 = _mm_sub_pd(ix3,jx0);
209 dy30 = _mm_sub_pd(iy3,jy0);
210 dz30 = _mm_sub_pd(iz3,jz0);
212 /* Calculate squared distance and things based on it */
213 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
214 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
215 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
216 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
218 rinv10 = gmx_mm_invsqrt_pd(rsq10);
219 rinv20 = gmx_mm_invsqrt_pd(rsq20);
220 rinv30 = gmx_mm_invsqrt_pd(rsq30);
222 rinvsq00 = gmx_mm_inv_pd(rsq00);
223 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
224 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
225 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
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 /* Compute parameters for interactions between i and j atoms */
244 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
245 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
247 /* LENNARD-JONES DISPERSION/REPULSION */
249 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
250 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
251 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
252 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
253 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
254 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
256 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
258 /* Update potential sum for this i atom from the interaction with this j atom. */
259 vvdw = _mm_and_pd(vvdw,cutoff_mask);
260 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
264 fscal = _mm_and_pd(fscal,cutoff_mask);
266 /* Update vectorial force */
267 fix0 = _mm_macc_pd(dx00,fscal,fix0);
268 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
269 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
271 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
272 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
273 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
277 /**************************
278 * CALCULATE INTERACTIONS *
279 **************************/
281 if (gmx_mm_any_lt(rsq10,rcutoff2))
284 /* Compute parameters for interactions between i and j atoms */
285 qq10 = _mm_mul_pd(iq1,jq0);
287 /* REACTION-FIELD ELECTROSTATICS */
288 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
289 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
291 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
293 /* Update potential sum for this i atom from the interaction with this j atom. */
294 velec = _mm_and_pd(velec,cutoff_mask);
295 velecsum = _mm_add_pd(velecsum,velec);
299 fscal = _mm_and_pd(fscal,cutoff_mask);
301 /* Update vectorial force */
302 fix1 = _mm_macc_pd(dx10,fscal,fix1);
303 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
304 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
306 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
307 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
308 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
312 /**************************
313 * CALCULATE INTERACTIONS *
314 **************************/
316 if (gmx_mm_any_lt(rsq20,rcutoff2))
319 /* Compute parameters for interactions between i and j atoms */
320 qq20 = _mm_mul_pd(iq2,jq0);
322 /* REACTION-FIELD ELECTROSTATICS */
323 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
324 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
326 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
328 /* Update potential sum for this i atom from the interaction with this j atom. */
329 velec = _mm_and_pd(velec,cutoff_mask);
330 velecsum = _mm_add_pd(velecsum,velec);
334 fscal = _mm_and_pd(fscal,cutoff_mask);
336 /* Update vectorial force */
337 fix2 = _mm_macc_pd(dx20,fscal,fix2);
338 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
339 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
341 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
342 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
343 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
347 /**************************
348 * CALCULATE INTERACTIONS *
349 **************************/
351 if (gmx_mm_any_lt(rsq30,rcutoff2))
354 /* Compute parameters for interactions between i and j atoms */
355 qq30 = _mm_mul_pd(iq3,jq0);
357 /* REACTION-FIELD ELECTROSTATICS */
358 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
359 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
361 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
363 /* Update potential sum for this i atom from the interaction with this j atom. */
364 velec = _mm_and_pd(velec,cutoff_mask);
365 velecsum = _mm_add_pd(velecsum,velec);
369 fscal = _mm_and_pd(fscal,cutoff_mask);
371 /* Update vectorial force */
372 fix3 = _mm_macc_pd(dx30,fscal,fix3);
373 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
374 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
376 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
377 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
378 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
382 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
384 /* Inner loop uses 164 flops */
391 j_coord_offsetA = DIM*jnrA;
393 /* load j atom coordinates */
394 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
397 /* Calculate displacement vector */
398 dx00 = _mm_sub_pd(ix0,jx0);
399 dy00 = _mm_sub_pd(iy0,jy0);
400 dz00 = _mm_sub_pd(iz0,jz0);
401 dx10 = _mm_sub_pd(ix1,jx0);
402 dy10 = _mm_sub_pd(iy1,jy0);
403 dz10 = _mm_sub_pd(iz1,jz0);
404 dx20 = _mm_sub_pd(ix2,jx0);
405 dy20 = _mm_sub_pd(iy2,jy0);
406 dz20 = _mm_sub_pd(iz2,jz0);
407 dx30 = _mm_sub_pd(ix3,jx0);
408 dy30 = _mm_sub_pd(iy3,jy0);
409 dz30 = _mm_sub_pd(iz3,jz0);
411 /* Calculate squared distance and things based on it */
412 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
413 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
414 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
415 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
417 rinv10 = gmx_mm_invsqrt_pd(rsq10);
418 rinv20 = gmx_mm_invsqrt_pd(rsq20);
419 rinv30 = gmx_mm_invsqrt_pd(rsq30);
421 rinvsq00 = gmx_mm_inv_pd(rsq00);
422 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
423 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
424 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
426 /* Load parameters for j particles */
427 jq0 = _mm_load_sd(charge+jnrA+0);
428 vdwjidx0A = 2*vdwtype[jnrA+0];
430 fjx0 = _mm_setzero_pd();
431 fjy0 = _mm_setzero_pd();
432 fjz0 = _mm_setzero_pd();
434 /**************************
435 * CALCULATE INTERACTIONS *
436 **************************/
438 if (gmx_mm_any_lt(rsq00,rcutoff2))
441 /* Compute parameters for interactions between i and j atoms */
442 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
444 /* LENNARD-JONES DISPERSION/REPULSION */
446 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
447 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
448 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
449 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
450 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
451 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
453 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
455 /* Update potential sum for this i atom from the interaction with this j atom. */
456 vvdw = _mm_and_pd(vvdw,cutoff_mask);
457 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
458 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
462 fscal = _mm_and_pd(fscal,cutoff_mask);
464 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
466 /* Update vectorial force */
467 fix0 = _mm_macc_pd(dx00,fscal,fix0);
468 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
469 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
471 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
472 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
473 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
477 /**************************
478 * CALCULATE INTERACTIONS *
479 **************************/
481 if (gmx_mm_any_lt(rsq10,rcutoff2))
484 /* Compute parameters for interactions between i and j atoms */
485 qq10 = _mm_mul_pd(iq1,jq0);
487 /* REACTION-FIELD ELECTROSTATICS */
488 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
489 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
491 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
493 /* Update potential sum for this i atom from the interaction with this j atom. */
494 velec = _mm_and_pd(velec,cutoff_mask);
495 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
496 velecsum = _mm_add_pd(velecsum,velec);
500 fscal = _mm_and_pd(fscal,cutoff_mask);
502 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
504 /* Update vectorial force */
505 fix1 = _mm_macc_pd(dx10,fscal,fix1);
506 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
507 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
509 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
510 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
511 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
515 /**************************
516 * CALCULATE INTERACTIONS *
517 **************************/
519 if (gmx_mm_any_lt(rsq20,rcutoff2))
522 /* Compute parameters for interactions between i and j atoms */
523 qq20 = _mm_mul_pd(iq2,jq0);
525 /* REACTION-FIELD ELECTROSTATICS */
526 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
527 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
529 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
531 /* Update potential sum for this i atom from the interaction with this j atom. */
532 velec = _mm_and_pd(velec,cutoff_mask);
533 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
534 velecsum = _mm_add_pd(velecsum,velec);
538 fscal = _mm_and_pd(fscal,cutoff_mask);
540 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
542 /* Update vectorial force */
543 fix2 = _mm_macc_pd(dx20,fscal,fix2);
544 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
545 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
547 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
548 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
549 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
553 /**************************
554 * CALCULATE INTERACTIONS *
555 **************************/
557 if (gmx_mm_any_lt(rsq30,rcutoff2))
560 /* Compute parameters for interactions between i and j atoms */
561 qq30 = _mm_mul_pd(iq3,jq0);
563 /* REACTION-FIELD ELECTROSTATICS */
564 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
565 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
567 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
569 /* Update potential sum for this i atom from the interaction with this j atom. */
570 velec = _mm_and_pd(velec,cutoff_mask);
571 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
572 velecsum = _mm_add_pd(velecsum,velec);
576 fscal = _mm_and_pd(fscal,cutoff_mask);
578 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
580 /* Update vectorial force */
581 fix3 = _mm_macc_pd(dx30,fscal,fix3);
582 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
583 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
585 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
586 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
587 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
591 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
593 /* Inner loop uses 164 flops */
596 /* End of innermost loop */
598 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
599 f+i_coord_offset,fshift+i_shift_offset);
602 /* Update potential energies */
603 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
604 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
606 /* Increment number of inner iterations */
607 inneriter += j_index_end - j_index_start;
609 /* Outer loop uses 26 flops */
612 /* Increment number of outer iterations */
615 /* Update outer/inner flops */
617 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*164);
620 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_double
621 * Electrostatics interaction: ReactionField
622 * VdW interaction: LennardJones
623 * Geometry: Water4-Particle
624 * Calculate force/pot: Force
627 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_double
628 (t_nblist * gmx_restrict nlist,
629 rvec * gmx_restrict xx,
630 rvec * gmx_restrict ff,
631 t_forcerec * gmx_restrict fr,
632 t_mdatoms * gmx_restrict mdatoms,
633 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
634 t_nrnb * gmx_restrict nrnb)
636 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
637 * just 0 for non-waters.
638 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
639 * jnr indices corresponding to data put in the four positions in the SIMD register.
641 int i_shift_offset,i_coord_offset,outeriter,inneriter;
642 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
644 int j_coord_offsetA,j_coord_offsetB;
645 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
647 real *shiftvec,*fshift,*x,*f;
648 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
650 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
652 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
654 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
656 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
657 int vdwjidx0A,vdwjidx0B;
658 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
659 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
660 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
661 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
662 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
663 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
666 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
669 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
670 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
671 __m128d dummy_mask,cutoff_mask;
672 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
673 __m128d one = _mm_set1_pd(1.0);
674 __m128d two = _mm_set1_pd(2.0);
680 jindex = nlist->jindex;
682 shiftidx = nlist->shift;
684 shiftvec = fr->shift_vec[0];
685 fshift = fr->fshift[0];
686 facel = _mm_set1_pd(fr->epsfac);
687 charge = mdatoms->chargeA;
688 krf = _mm_set1_pd(fr->ic->k_rf);
689 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
690 crf = _mm_set1_pd(fr->ic->c_rf);
691 nvdwtype = fr->ntype;
693 vdwtype = mdatoms->typeA;
695 /* Setup water-specific parameters */
696 inr = nlist->iinr[0];
697 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
698 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
699 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
700 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
702 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
703 rcutoff_scalar = fr->rcoulomb;
704 rcutoff = _mm_set1_pd(rcutoff_scalar);
705 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
707 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
708 rvdw = _mm_set1_pd(fr->rvdw);
710 /* Avoid stupid compiler warnings */
718 /* Start outer loop over neighborlists */
719 for(iidx=0; iidx<nri; iidx++)
721 /* Load shift vector for this list */
722 i_shift_offset = DIM*shiftidx[iidx];
724 /* Load limits for loop over neighbors */
725 j_index_start = jindex[iidx];
726 j_index_end = jindex[iidx+1];
728 /* Get outer coordinate index */
730 i_coord_offset = DIM*inr;
732 /* Load i particle coords and add shift vector */
733 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
734 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
736 fix0 = _mm_setzero_pd();
737 fiy0 = _mm_setzero_pd();
738 fiz0 = _mm_setzero_pd();
739 fix1 = _mm_setzero_pd();
740 fiy1 = _mm_setzero_pd();
741 fiz1 = _mm_setzero_pd();
742 fix2 = _mm_setzero_pd();
743 fiy2 = _mm_setzero_pd();
744 fiz2 = _mm_setzero_pd();
745 fix3 = _mm_setzero_pd();
746 fiy3 = _mm_setzero_pd();
747 fiz3 = _mm_setzero_pd();
749 /* Start inner kernel loop */
750 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
753 /* Get j neighbor index, and coordinate index */
756 j_coord_offsetA = DIM*jnrA;
757 j_coord_offsetB = DIM*jnrB;
759 /* load j atom coordinates */
760 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
763 /* Calculate displacement vector */
764 dx00 = _mm_sub_pd(ix0,jx0);
765 dy00 = _mm_sub_pd(iy0,jy0);
766 dz00 = _mm_sub_pd(iz0,jz0);
767 dx10 = _mm_sub_pd(ix1,jx0);
768 dy10 = _mm_sub_pd(iy1,jy0);
769 dz10 = _mm_sub_pd(iz1,jz0);
770 dx20 = _mm_sub_pd(ix2,jx0);
771 dy20 = _mm_sub_pd(iy2,jy0);
772 dz20 = _mm_sub_pd(iz2,jz0);
773 dx30 = _mm_sub_pd(ix3,jx0);
774 dy30 = _mm_sub_pd(iy3,jy0);
775 dz30 = _mm_sub_pd(iz3,jz0);
777 /* Calculate squared distance and things based on it */
778 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
779 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
780 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
781 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
783 rinv10 = gmx_mm_invsqrt_pd(rsq10);
784 rinv20 = gmx_mm_invsqrt_pd(rsq20);
785 rinv30 = gmx_mm_invsqrt_pd(rsq30);
787 rinvsq00 = gmx_mm_inv_pd(rsq00);
788 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
789 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
790 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
792 /* Load parameters for j particles */
793 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
794 vdwjidx0A = 2*vdwtype[jnrA+0];
795 vdwjidx0B = 2*vdwtype[jnrB+0];
797 fjx0 = _mm_setzero_pd();
798 fjy0 = _mm_setzero_pd();
799 fjz0 = _mm_setzero_pd();
801 /**************************
802 * CALCULATE INTERACTIONS *
803 **************************/
805 if (gmx_mm_any_lt(rsq00,rcutoff2))
808 /* Compute parameters for interactions between i and j atoms */
809 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
810 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
812 /* LENNARD-JONES DISPERSION/REPULSION */
814 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
815 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
817 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
821 fscal = _mm_and_pd(fscal,cutoff_mask);
823 /* Update vectorial force */
824 fix0 = _mm_macc_pd(dx00,fscal,fix0);
825 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
826 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
828 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
829 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
830 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
834 /**************************
835 * CALCULATE INTERACTIONS *
836 **************************/
838 if (gmx_mm_any_lt(rsq10,rcutoff2))
841 /* Compute parameters for interactions between i and j atoms */
842 qq10 = _mm_mul_pd(iq1,jq0);
844 /* REACTION-FIELD ELECTROSTATICS */
845 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
847 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
851 fscal = _mm_and_pd(fscal,cutoff_mask);
853 /* Update vectorial force */
854 fix1 = _mm_macc_pd(dx10,fscal,fix1);
855 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
856 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
858 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
859 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
860 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
864 /**************************
865 * CALCULATE INTERACTIONS *
866 **************************/
868 if (gmx_mm_any_lt(rsq20,rcutoff2))
871 /* Compute parameters for interactions between i and j atoms */
872 qq20 = _mm_mul_pd(iq2,jq0);
874 /* REACTION-FIELD ELECTROSTATICS */
875 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
877 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
881 fscal = _mm_and_pd(fscal,cutoff_mask);
883 /* Update vectorial force */
884 fix2 = _mm_macc_pd(dx20,fscal,fix2);
885 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
886 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
888 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
889 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
890 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
894 /**************************
895 * CALCULATE INTERACTIONS *
896 **************************/
898 if (gmx_mm_any_lt(rsq30,rcutoff2))
901 /* Compute parameters for interactions between i and j atoms */
902 qq30 = _mm_mul_pd(iq3,jq0);
904 /* REACTION-FIELD ELECTROSTATICS */
905 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
907 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
911 fscal = _mm_and_pd(fscal,cutoff_mask);
913 /* Update vectorial force */
914 fix3 = _mm_macc_pd(dx30,fscal,fix3);
915 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
916 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
918 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
919 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
920 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
924 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
926 /* Inner loop uses 135 flops */
933 j_coord_offsetA = DIM*jnrA;
935 /* load j atom coordinates */
936 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
939 /* Calculate displacement vector */
940 dx00 = _mm_sub_pd(ix0,jx0);
941 dy00 = _mm_sub_pd(iy0,jy0);
942 dz00 = _mm_sub_pd(iz0,jz0);
943 dx10 = _mm_sub_pd(ix1,jx0);
944 dy10 = _mm_sub_pd(iy1,jy0);
945 dz10 = _mm_sub_pd(iz1,jz0);
946 dx20 = _mm_sub_pd(ix2,jx0);
947 dy20 = _mm_sub_pd(iy2,jy0);
948 dz20 = _mm_sub_pd(iz2,jz0);
949 dx30 = _mm_sub_pd(ix3,jx0);
950 dy30 = _mm_sub_pd(iy3,jy0);
951 dz30 = _mm_sub_pd(iz3,jz0);
953 /* Calculate squared distance and things based on it */
954 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
955 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
956 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
957 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
959 rinv10 = gmx_mm_invsqrt_pd(rsq10);
960 rinv20 = gmx_mm_invsqrt_pd(rsq20);
961 rinv30 = gmx_mm_invsqrt_pd(rsq30);
963 rinvsq00 = gmx_mm_inv_pd(rsq00);
964 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
965 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
966 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
968 /* Load parameters for j particles */
969 jq0 = _mm_load_sd(charge+jnrA+0);
970 vdwjidx0A = 2*vdwtype[jnrA+0];
972 fjx0 = _mm_setzero_pd();
973 fjy0 = _mm_setzero_pd();
974 fjz0 = _mm_setzero_pd();
976 /**************************
977 * CALCULATE INTERACTIONS *
978 **************************/
980 if (gmx_mm_any_lt(rsq00,rcutoff2))
983 /* Compute parameters for interactions between i and j atoms */
984 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
986 /* LENNARD-JONES DISPERSION/REPULSION */
988 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
989 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
991 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
995 fscal = _mm_and_pd(fscal,cutoff_mask);
997 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
999 /* Update vectorial force */
1000 fix0 = _mm_macc_pd(dx00,fscal,fix0);
1001 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
1002 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
1004 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
1005 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
1006 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
1010 /**************************
1011 * CALCULATE INTERACTIONS *
1012 **************************/
1014 if (gmx_mm_any_lt(rsq10,rcutoff2))
1017 /* Compute parameters for interactions between i and j atoms */
1018 qq10 = _mm_mul_pd(iq1,jq0);
1020 /* REACTION-FIELD ELECTROSTATICS */
1021 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
1023 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1027 fscal = _mm_and_pd(fscal,cutoff_mask);
1029 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1031 /* Update vectorial force */
1032 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1033 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1034 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1036 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1037 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1038 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1042 /**************************
1043 * CALCULATE INTERACTIONS *
1044 **************************/
1046 if (gmx_mm_any_lt(rsq20,rcutoff2))
1049 /* Compute parameters for interactions between i and j atoms */
1050 qq20 = _mm_mul_pd(iq2,jq0);
1052 /* REACTION-FIELD ELECTROSTATICS */
1053 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1055 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1059 fscal = _mm_and_pd(fscal,cutoff_mask);
1061 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1063 /* Update vectorial force */
1064 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1065 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1066 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1068 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1069 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1070 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1074 /**************************
1075 * CALCULATE INTERACTIONS *
1076 **************************/
1078 if (gmx_mm_any_lt(rsq30,rcutoff2))
1081 /* Compute parameters for interactions between i and j atoms */
1082 qq30 = _mm_mul_pd(iq3,jq0);
1084 /* REACTION-FIELD ELECTROSTATICS */
1085 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
1087 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1091 fscal = _mm_and_pd(fscal,cutoff_mask);
1093 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1095 /* Update vectorial force */
1096 fix3 = _mm_macc_pd(dx30,fscal,fix3);
1097 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
1098 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
1100 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
1101 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
1102 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
1106 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1108 /* Inner loop uses 135 flops */
1111 /* End of innermost loop */
1113 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1114 f+i_coord_offset,fshift+i_shift_offset);
1116 /* Increment number of inner iterations */
1117 inneriter += j_index_end - j_index_start;
1119 /* Outer loop uses 24 flops */
1122 /* Increment number of outer iterations */
1125 /* Update outer/inner flops */
1127 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*135);