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_VdwLJSh_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_VdwLJSh_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 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 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
138 rvdw = _mm_set1_pd(fr->rvdw);
140 /* Avoid stupid compiler warnings */
148 /* Start outer loop over neighborlists */
149 for(iidx=0; iidx<nri; iidx++)
151 /* Load shift vector for this list */
152 i_shift_offset = DIM*shiftidx[iidx];
154 /* Load limits for loop over neighbors */
155 j_index_start = jindex[iidx];
156 j_index_end = jindex[iidx+1];
158 /* Get outer coordinate index */
160 i_coord_offset = DIM*inr;
162 /* Load i particle coords and add shift vector */
163 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
164 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
166 fix0 = _mm_setzero_pd();
167 fiy0 = _mm_setzero_pd();
168 fiz0 = _mm_setzero_pd();
169 fix1 = _mm_setzero_pd();
170 fiy1 = _mm_setzero_pd();
171 fiz1 = _mm_setzero_pd();
172 fix2 = _mm_setzero_pd();
173 fiy2 = _mm_setzero_pd();
174 fiz2 = _mm_setzero_pd();
176 /* Reset potential sums */
177 velecsum = _mm_setzero_pd();
178 vvdwsum = _mm_setzero_pd();
180 /* Start inner kernel loop */
181 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
184 /* Get j neighbor index, and coordinate index */
187 j_coord_offsetA = DIM*jnrA;
188 j_coord_offsetB = DIM*jnrB;
190 /* load j atom coordinates */
191 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
194 /* Calculate displacement vector */
195 dx00 = _mm_sub_pd(ix0,jx0);
196 dy00 = _mm_sub_pd(iy0,jy0);
197 dz00 = _mm_sub_pd(iz0,jz0);
198 dx10 = _mm_sub_pd(ix1,jx0);
199 dy10 = _mm_sub_pd(iy1,jy0);
200 dz10 = _mm_sub_pd(iz1,jz0);
201 dx20 = _mm_sub_pd(ix2,jx0);
202 dy20 = _mm_sub_pd(iy2,jy0);
203 dz20 = _mm_sub_pd(iz2,jz0);
205 /* Calculate squared distance and things based on it */
206 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
207 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
208 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
210 rinv00 = gmx_mm_invsqrt_pd(rsq00);
211 rinv10 = gmx_mm_invsqrt_pd(rsq10);
212 rinv20 = gmx_mm_invsqrt_pd(rsq20);
214 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
215 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
216 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
218 /* Load parameters for j particles */
219 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
220 vdwjidx0A = 2*vdwtype[jnrA+0];
221 vdwjidx0B = 2*vdwtype[jnrB+0];
223 fjx0 = _mm_setzero_pd();
224 fjy0 = _mm_setzero_pd();
225 fjz0 = _mm_setzero_pd();
227 /**************************
228 * CALCULATE INTERACTIONS *
229 **************************/
231 if (gmx_mm_any_lt(rsq00,rcutoff2))
234 /* Compute parameters for interactions between i and j atoms */
235 qq00 = _mm_mul_pd(iq0,jq0);
236 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
237 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
239 /* REACTION-FIELD ELECTROSTATICS */
240 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
241 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
243 /* LENNARD-JONES DISPERSION/REPULSION */
245 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
246 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
247 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
248 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
249 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
250 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
252 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
254 /* Update potential sum for this i atom from the interaction with this j atom. */
255 velec = _mm_and_pd(velec,cutoff_mask);
256 velecsum = _mm_add_pd(velecsum,velec);
257 vvdw = _mm_and_pd(vvdw,cutoff_mask);
258 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
260 fscal = _mm_add_pd(felec,fvdw);
262 fscal = _mm_and_pd(fscal,cutoff_mask);
264 /* Update vectorial force */
265 fix0 = _mm_macc_pd(dx00,fscal,fix0);
266 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
267 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
269 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
270 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
271 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
275 /**************************
276 * CALCULATE INTERACTIONS *
277 **************************/
279 if (gmx_mm_any_lt(rsq10,rcutoff2))
282 /* Compute parameters for interactions between i and j atoms */
283 qq10 = _mm_mul_pd(iq1,jq0);
285 /* REACTION-FIELD ELECTROSTATICS */
286 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
287 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
289 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
291 /* Update potential sum for this i atom from the interaction with this j atom. */
292 velec = _mm_and_pd(velec,cutoff_mask);
293 velecsum = _mm_add_pd(velecsum,velec);
297 fscal = _mm_and_pd(fscal,cutoff_mask);
299 /* Update vectorial force */
300 fix1 = _mm_macc_pd(dx10,fscal,fix1);
301 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
302 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
304 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
305 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
306 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
310 /**************************
311 * CALCULATE INTERACTIONS *
312 **************************/
314 if (gmx_mm_any_lt(rsq20,rcutoff2))
317 /* Compute parameters for interactions between i and j atoms */
318 qq20 = _mm_mul_pd(iq2,jq0);
320 /* REACTION-FIELD ELECTROSTATICS */
321 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
322 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
324 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
326 /* Update potential sum for this i atom from the interaction with this j atom. */
327 velec = _mm_and_pd(velec,cutoff_mask);
328 velecsum = _mm_add_pd(velecsum,velec);
332 fscal = _mm_and_pd(fscal,cutoff_mask);
334 /* Update vectorial force */
335 fix2 = _mm_macc_pd(dx20,fscal,fix2);
336 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
337 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
339 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
340 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
341 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
345 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
347 /* Inner loop uses 138 flops */
354 j_coord_offsetA = DIM*jnrA;
356 /* load j atom coordinates */
357 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
360 /* Calculate displacement vector */
361 dx00 = _mm_sub_pd(ix0,jx0);
362 dy00 = _mm_sub_pd(iy0,jy0);
363 dz00 = _mm_sub_pd(iz0,jz0);
364 dx10 = _mm_sub_pd(ix1,jx0);
365 dy10 = _mm_sub_pd(iy1,jy0);
366 dz10 = _mm_sub_pd(iz1,jz0);
367 dx20 = _mm_sub_pd(ix2,jx0);
368 dy20 = _mm_sub_pd(iy2,jy0);
369 dz20 = _mm_sub_pd(iz2,jz0);
371 /* Calculate squared distance and things based on it */
372 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
373 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
374 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
376 rinv00 = gmx_mm_invsqrt_pd(rsq00);
377 rinv10 = gmx_mm_invsqrt_pd(rsq10);
378 rinv20 = gmx_mm_invsqrt_pd(rsq20);
380 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
381 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
382 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
384 /* Load parameters for j particles */
385 jq0 = _mm_load_sd(charge+jnrA+0);
386 vdwjidx0A = 2*vdwtype[jnrA+0];
388 fjx0 = _mm_setzero_pd();
389 fjy0 = _mm_setzero_pd();
390 fjz0 = _mm_setzero_pd();
392 /**************************
393 * CALCULATE INTERACTIONS *
394 **************************/
396 if (gmx_mm_any_lt(rsq00,rcutoff2))
399 /* Compute parameters for interactions between i and j atoms */
400 qq00 = _mm_mul_pd(iq0,jq0);
401 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
403 /* REACTION-FIELD ELECTROSTATICS */
404 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
405 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
407 /* LENNARD-JONES DISPERSION/REPULSION */
409 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
410 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
411 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
412 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
413 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
414 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
416 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
418 /* Update potential sum for this i atom from the interaction with this j atom. */
419 velec = _mm_and_pd(velec,cutoff_mask);
420 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
421 velecsum = _mm_add_pd(velecsum,velec);
422 vvdw = _mm_and_pd(vvdw,cutoff_mask);
423 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
424 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
426 fscal = _mm_add_pd(felec,fvdw);
428 fscal = _mm_and_pd(fscal,cutoff_mask);
430 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
432 /* Update vectorial force */
433 fix0 = _mm_macc_pd(dx00,fscal,fix0);
434 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
435 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
437 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
438 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
439 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
443 /**************************
444 * CALCULATE INTERACTIONS *
445 **************************/
447 if (gmx_mm_any_lt(rsq10,rcutoff2))
450 /* Compute parameters for interactions between i and j atoms */
451 qq10 = _mm_mul_pd(iq1,jq0);
453 /* REACTION-FIELD ELECTROSTATICS */
454 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
455 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
457 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
459 /* Update potential sum for this i atom from the interaction with this j atom. */
460 velec = _mm_and_pd(velec,cutoff_mask);
461 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
462 velecsum = _mm_add_pd(velecsum,velec);
466 fscal = _mm_and_pd(fscal,cutoff_mask);
468 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
470 /* Update vectorial force */
471 fix1 = _mm_macc_pd(dx10,fscal,fix1);
472 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
473 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
475 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
476 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
477 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
481 /**************************
482 * CALCULATE INTERACTIONS *
483 **************************/
485 if (gmx_mm_any_lt(rsq20,rcutoff2))
488 /* Compute parameters for interactions between i and j atoms */
489 qq20 = _mm_mul_pd(iq2,jq0);
491 /* REACTION-FIELD ELECTROSTATICS */
492 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
493 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
495 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
497 /* Update potential sum for this i atom from the interaction with this j atom. */
498 velec = _mm_and_pd(velec,cutoff_mask);
499 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
500 velecsum = _mm_add_pd(velecsum,velec);
504 fscal = _mm_and_pd(fscal,cutoff_mask);
506 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
508 /* Update vectorial force */
509 fix2 = _mm_macc_pd(dx20,fscal,fix2);
510 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
511 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
513 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
514 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
515 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
519 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
521 /* Inner loop uses 138 flops */
524 /* End of innermost loop */
526 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
527 f+i_coord_offset,fshift+i_shift_offset);
530 /* Update potential energies */
531 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
532 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
534 /* Increment number of inner iterations */
535 inneriter += j_index_end - j_index_start;
537 /* Outer loop uses 20 flops */
540 /* Increment number of outer iterations */
543 /* Update outer/inner flops */
545 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*138);
548 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
549 * Electrostatics interaction: ReactionField
550 * VdW interaction: LennardJones
551 * Geometry: Water3-Particle
552 * Calculate force/pot: Force
555 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
556 (t_nblist * gmx_restrict nlist,
557 rvec * gmx_restrict xx,
558 rvec * gmx_restrict ff,
559 t_forcerec * gmx_restrict fr,
560 t_mdatoms * gmx_restrict mdatoms,
561 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
562 t_nrnb * gmx_restrict nrnb)
564 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
565 * just 0 for non-waters.
566 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
567 * jnr indices corresponding to data put in the four positions in the SIMD register.
569 int i_shift_offset,i_coord_offset,outeriter,inneriter;
570 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
572 int j_coord_offsetA,j_coord_offsetB;
573 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
575 real *shiftvec,*fshift,*x,*f;
576 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
578 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
580 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
582 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
583 int vdwjidx0A,vdwjidx0B;
584 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
585 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
586 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
587 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
588 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
591 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
594 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
595 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
596 __m128d dummy_mask,cutoff_mask;
597 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
598 __m128d one = _mm_set1_pd(1.0);
599 __m128d two = _mm_set1_pd(2.0);
605 jindex = nlist->jindex;
607 shiftidx = nlist->shift;
609 shiftvec = fr->shift_vec[0];
610 fshift = fr->fshift[0];
611 facel = _mm_set1_pd(fr->epsfac);
612 charge = mdatoms->chargeA;
613 krf = _mm_set1_pd(fr->ic->k_rf);
614 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
615 crf = _mm_set1_pd(fr->ic->c_rf);
616 nvdwtype = fr->ntype;
618 vdwtype = mdatoms->typeA;
620 /* Setup water-specific parameters */
621 inr = nlist->iinr[0];
622 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
623 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
624 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
625 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
627 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
628 rcutoff_scalar = fr->rcoulomb;
629 rcutoff = _mm_set1_pd(rcutoff_scalar);
630 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
632 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
633 rvdw = _mm_set1_pd(fr->rvdw);
635 /* Avoid stupid compiler warnings */
643 /* Start outer loop over neighborlists */
644 for(iidx=0; iidx<nri; iidx++)
646 /* Load shift vector for this list */
647 i_shift_offset = DIM*shiftidx[iidx];
649 /* Load limits for loop over neighbors */
650 j_index_start = jindex[iidx];
651 j_index_end = jindex[iidx+1];
653 /* Get outer coordinate index */
655 i_coord_offset = DIM*inr;
657 /* Load i particle coords and add shift vector */
658 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
659 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
661 fix0 = _mm_setzero_pd();
662 fiy0 = _mm_setzero_pd();
663 fiz0 = _mm_setzero_pd();
664 fix1 = _mm_setzero_pd();
665 fiy1 = _mm_setzero_pd();
666 fiz1 = _mm_setzero_pd();
667 fix2 = _mm_setzero_pd();
668 fiy2 = _mm_setzero_pd();
669 fiz2 = _mm_setzero_pd();
671 /* Start inner kernel loop */
672 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
675 /* Get j neighbor index, and coordinate index */
678 j_coord_offsetA = DIM*jnrA;
679 j_coord_offsetB = DIM*jnrB;
681 /* load j atom coordinates */
682 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
685 /* Calculate displacement vector */
686 dx00 = _mm_sub_pd(ix0,jx0);
687 dy00 = _mm_sub_pd(iy0,jy0);
688 dz00 = _mm_sub_pd(iz0,jz0);
689 dx10 = _mm_sub_pd(ix1,jx0);
690 dy10 = _mm_sub_pd(iy1,jy0);
691 dz10 = _mm_sub_pd(iz1,jz0);
692 dx20 = _mm_sub_pd(ix2,jx0);
693 dy20 = _mm_sub_pd(iy2,jy0);
694 dz20 = _mm_sub_pd(iz2,jz0);
696 /* Calculate squared distance and things based on it */
697 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
698 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
699 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
701 rinv00 = gmx_mm_invsqrt_pd(rsq00);
702 rinv10 = gmx_mm_invsqrt_pd(rsq10);
703 rinv20 = gmx_mm_invsqrt_pd(rsq20);
705 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
706 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
707 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
709 /* Load parameters for j particles */
710 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
711 vdwjidx0A = 2*vdwtype[jnrA+0];
712 vdwjidx0B = 2*vdwtype[jnrB+0];
714 fjx0 = _mm_setzero_pd();
715 fjy0 = _mm_setzero_pd();
716 fjz0 = _mm_setzero_pd();
718 /**************************
719 * CALCULATE INTERACTIONS *
720 **************************/
722 if (gmx_mm_any_lt(rsq00,rcutoff2))
725 /* Compute parameters for interactions between i and j atoms */
726 qq00 = _mm_mul_pd(iq0,jq0);
727 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
728 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
730 /* REACTION-FIELD ELECTROSTATICS */
731 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
733 /* LENNARD-JONES DISPERSION/REPULSION */
735 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
736 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
738 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
740 fscal = _mm_add_pd(felec,fvdw);
742 fscal = _mm_and_pd(fscal,cutoff_mask);
744 /* Update vectorial force */
745 fix0 = _mm_macc_pd(dx00,fscal,fix0);
746 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
747 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
749 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
750 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
751 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
755 /**************************
756 * CALCULATE INTERACTIONS *
757 **************************/
759 if (gmx_mm_any_lt(rsq10,rcutoff2))
762 /* Compute parameters for interactions between i and j atoms */
763 qq10 = _mm_mul_pd(iq1,jq0);
765 /* REACTION-FIELD ELECTROSTATICS */
766 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
768 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
772 fscal = _mm_and_pd(fscal,cutoff_mask);
774 /* Update vectorial force */
775 fix1 = _mm_macc_pd(dx10,fscal,fix1);
776 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
777 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
779 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
780 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
781 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
785 /**************************
786 * CALCULATE INTERACTIONS *
787 **************************/
789 if (gmx_mm_any_lt(rsq20,rcutoff2))
792 /* Compute parameters for interactions between i and j atoms */
793 qq20 = _mm_mul_pd(iq2,jq0);
795 /* REACTION-FIELD ELECTROSTATICS */
796 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
798 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
802 fscal = _mm_and_pd(fscal,cutoff_mask);
804 /* Update vectorial force */
805 fix2 = _mm_macc_pd(dx20,fscal,fix2);
806 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
807 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
809 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
810 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
811 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
815 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
817 /* Inner loop uses 109 flops */
824 j_coord_offsetA = DIM*jnrA;
826 /* load j atom coordinates */
827 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
830 /* Calculate displacement vector */
831 dx00 = _mm_sub_pd(ix0,jx0);
832 dy00 = _mm_sub_pd(iy0,jy0);
833 dz00 = _mm_sub_pd(iz0,jz0);
834 dx10 = _mm_sub_pd(ix1,jx0);
835 dy10 = _mm_sub_pd(iy1,jy0);
836 dz10 = _mm_sub_pd(iz1,jz0);
837 dx20 = _mm_sub_pd(ix2,jx0);
838 dy20 = _mm_sub_pd(iy2,jy0);
839 dz20 = _mm_sub_pd(iz2,jz0);
841 /* Calculate squared distance and things based on it */
842 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
843 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
844 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
846 rinv00 = gmx_mm_invsqrt_pd(rsq00);
847 rinv10 = gmx_mm_invsqrt_pd(rsq10);
848 rinv20 = gmx_mm_invsqrt_pd(rsq20);
850 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
851 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
852 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
854 /* Load parameters for j particles */
855 jq0 = _mm_load_sd(charge+jnrA+0);
856 vdwjidx0A = 2*vdwtype[jnrA+0];
858 fjx0 = _mm_setzero_pd();
859 fjy0 = _mm_setzero_pd();
860 fjz0 = _mm_setzero_pd();
862 /**************************
863 * CALCULATE INTERACTIONS *
864 **************************/
866 if (gmx_mm_any_lt(rsq00,rcutoff2))
869 /* Compute parameters for interactions between i and j atoms */
870 qq00 = _mm_mul_pd(iq0,jq0);
871 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
873 /* REACTION-FIELD ELECTROSTATICS */
874 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
876 /* LENNARD-JONES DISPERSION/REPULSION */
878 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
879 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
881 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
883 fscal = _mm_add_pd(felec,fvdw);
885 fscal = _mm_and_pd(fscal,cutoff_mask);
887 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
889 /* Update vectorial force */
890 fix0 = _mm_macc_pd(dx00,fscal,fix0);
891 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
892 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
894 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
895 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
896 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
900 /**************************
901 * CALCULATE INTERACTIONS *
902 **************************/
904 if (gmx_mm_any_lt(rsq10,rcutoff2))
907 /* Compute parameters for interactions between i and j atoms */
908 qq10 = _mm_mul_pd(iq1,jq0);
910 /* REACTION-FIELD ELECTROSTATICS */
911 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
913 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
917 fscal = _mm_and_pd(fscal,cutoff_mask);
919 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
921 /* Update vectorial force */
922 fix1 = _mm_macc_pd(dx10,fscal,fix1);
923 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
924 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
926 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
927 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
928 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
932 /**************************
933 * CALCULATE INTERACTIONS *
934 **************************/
936 if (gmx_mm_any_lt(rsq20,rcutoff2))
939 /* Compute parameters for interactions between i and j atoms */
940 qq20 = _mm_mul_pd(iq2,jq0);
942 /* REACTION-FIELD ELECTROSTATICS */
943 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
945 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
949 fscal = _mm_and_pd(fscal,cutoff_mask);
951 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
953 /* Update vectorial force */
954 fix2 = _mm_macc_pd(dx20,fscal,fix2);
955 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
956 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
958 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
959 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
960 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
964 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
966 /* Inner loop uses 109 flops */
969 /* End of innermost loop */
971 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
972 f+i_coord_offset,fshift+i_shift_offset);
974 /* Increment number of inner iterations */
975 inneriter += j_index_end - j_index_start;
977 /* Outer loop uses 18 flops */
980 /* Increment number of outer iterations */
983 /* Update outer/inner flops */
985 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*109);