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_GeomW3P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 int vdwjidx0A,vdwjidx0B;
87 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
90 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
91 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
94 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
98 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
99 __m128d dummy_mask,cutoff_mask;
100 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
101 __m128d one = _mm_set1_pd(1.0);
102 __m128d two = _mm_set1_pd(2.0);
108 jindex = nlist->jindex;
110 shiftidx = nlist->shift;
112 shiftvec = fr->shift_vec[0];
113 fshift = fr->fshift[0];
114 facel = _mm_set1_pd(fr->epsfac);
115 charge = mdatoms->chargeA;
116 krf = _mm_set1_pd(fr->ic->k_rf);
117 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
118 crf = _mm_set1_pd(fr->ic->c_rf);
119 nvdwtype = fr->ntype;
121 vdwtype = mdatoms->typeA;
123 /* Setup water-specific parameters */
124 inr = nlist->iinr[0];
125 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
126 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
127 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
128 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
130 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
131 rcutoff_scalar = fr->rcoulomb;
132 rcutoff = _mm_set1_pd(rcutoff_scalar);
133 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
135 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
136 rvdw = _mm_set1_pd(fr->rvdw);
138 /* Avoid stupid compiler warnings */
146 /* Start outer loop over neighborlists */
147 for(iidx=0; iidx<nri; iidx++)
149 /* Load shift vector for this list */
150 i_shift_offset = DIM*shiftidx[iidx];
152 /* Load limits for loop over neighbors */
153 j_index_start = jindex[iidx];
154 j_index_end = jindex[iidx+1];
156 /* Get outer coordinate index */
158 i_coord_offset = DIM*inr;
160 /* Load i particle coords and add shift vector */
161 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
162 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
164 fix0 = _mm_setzero_pd();
165 fiy0 = _mm_setzero_pd();
166 fiz0 = _mm_setzero_pd();
167 fix1 = _mm_setzero_pd();
168 fiy1 = _mm_setzero_pd();
169 fiz1 = _mm_setzero_pd();
170 fix2 = _mm_setzero_pd();
171 fiy2 = _mm_setzero_pd();
172 fiz2 = _mm_setzero_pd();
174 /* Reset potential sums */
175 velecsum = _mm_setzero_pd();
176 vvdwsum = _mm_setzero_pd();
178 /* Start inner kernel loop */
179 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
182 /* Get j neighbor index, and coordinate index */
185 j_coord_offsetA = DIM*jnrA;
186 j_coord_offsetB = DIM*jnrB;
188 /* load j atom coordinates */
189 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
192 /* Calculate displacement vector */
193 dx00 = _mm_sub_pd(ix0,jx0);
194 dy00 = _mm_sub_pd(iy0,jy0);
195 dz00 = _mm_sub_pd(iz0,jz0);
196 dx10 = _mm_sub_pd(ix1,jx0);
197 dy10 = _mm_sub_pd(iy1,jy0);
198 dz10 = _mm_sub_pd(iz1,jz0);
199 dx20 = _mm_sub_pd(ix2,jx0);
200 dy20 = _mm_sub_pd(iy2,jy0);
201 dz20 = _mm_sub_pd(iz2,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
205 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
206 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
208 rinv00 = gmx_mm_invsqrt_pd(rsq00);
209 rinv10 = gmx_mm_invsqrt_pd(rsq10);
210 rinv20 = gmx_mm_invsqrt_pd(rsq20);
212 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
213 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
214 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
216 /* Load parameters for j particles */
217 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
218 vdwjidx0A = 2*vdwtype[jnrA+0];
219 vdwjidx0B = 2*vdwtype[jnrB+0];
221 fjx0 = _mm_setzero_pd();
222 fjy0 = _mm_setzero_pd();
223 fjz0 = _mm_setzero_pd();
225 /**************************
226 * CALCULATE INTERACTIONS *
227 **************************/
229 if (gmx_mm_any_lt(rsq00,rcutoff2))
232 /* Compute parameters for interactions between i and j atoms */
233 qq00 = _mm_mul_pd(iq0,jq0);
234 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
235 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
237 /* REACTION-FIELD ELECTROSTATICS */
238 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
239 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
241 /* LENNARD-JONES DISPERSION/REPULSION */
243 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
244 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
245 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
246 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
247 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
248 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
250 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
252 /* Update potential sum for this i atom from the interaction with this j atom. */
253 velec = _mm_and_pd(velec,cutoff_mask);
254 velecsum = _mm_add_pd(velecsum,velec);
255 vvdw = _mm_and_pd(vvdw,cutoff_mask);
256 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
258 fscal = _mm_add_pd(felec,fvdw);
260 fscal = _mm_and_pd(fscal,cutoff_mask);
262 /* Update vectorial force */
263 fix0 = _mm_macc_pd(dx00,fscal,fix0);
264 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
265 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
267 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
268 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
269 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
273 /**************************
274 * CALCULATE INTERACTIONS *
275 **************************/
277 if (gmx_mm_any_lt(rsq10,rcutoff2))
280 /* Compute parameters for interactions between i and j atoms */
281 qq10 = _mm_mul_pd(iq1,jq0);
283 /* REACTION-FIELD ELECTROSTATICS */
284 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
285 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
287 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
289 /* Update potential sum for this i atom from the interaction with this j atom. */
290 velec = _mm_and_pd(velec,cutoff_mask);
291 velecsum = _mm_add_pd(velecsum,velec);
295 fscal = _mm_and_pd(fscal,cutoff_mask);
297 /* Update vectorial force */
298 fix1 = _mm_macc_pd(dx10,fscal,fix1);
299 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
300 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
302 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
303 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
304 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
308 /**************************
309 * CALCULATE INTERACTIONS *
310 **************************/
312 if (gmx_mm_any_lt(rsq20,rcutoff2))
315 /* Compute parameters for interactions between i and j atoms */
316 qq20 = _mm_mul_pd(iq2,jq0);
318 /* REACTION-FIELD ELECTROSTATICS */
319 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
320 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
322 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
324 /* Update potential sum for this i atom from the interaction with this j atom. */
325 velec = _mm_and_pd(velec,cutoff_mask);
326 velecsum = _mm_add_pd(velecsum,velec);
330 fscal = _mm_and_pd(fscal,cutoff_mask);
332 /* Update vectorial force */
333 fix2 = _mm_macc_pd(dx20,fscal,fix2);
334 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
335 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
337 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
338 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
339 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
343 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
345 /* Inner loop uses 138 flops */
352 j_coord_offsetA = DIM*jnrA;
354 /* load j atom coordinates */
355 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
358 /* Calculate displacement vector */
359 dx00 = _mm_sub_pd(ix0,jx0);
360 dy00 = _mm_sub_pd(iy0,jy0);
361 dz00 = _mm_sub_pd(iz0,jz0);
362 dx10 = _mm_sub_pd(ix1,jx0);
363 dy10 = _mm_sub_pd(iy1,jy0);
364 dz10 = _mm_sub_pd(iz1,jz0);
365 dx20 = _mm_sub_pd(ix2,jx0);
366 dy20 = _mm_sub_pd(iy2,jy0);
367 dz20 = _mm_sub_pd(iz2,jz0);
369 /* Calculate squared distance and things based on it */
370 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
371 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
372 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
374 rinv00 = gmx_mm_invsqrt_pd(rsq00);
375 rinv10 = gmx_mm_invsqrt_pd(rsq10);
376 rinv20 = gmx_mm_invsqrt_pd(rsq20);
378 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
379 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
380 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
382 /* Load parameters for j particles */
383 jq0 = _mm_load_sd(charge+jnrA+0);
384 vdwjidx0A = 2*vdwtype[jnrA+0];
386 fjx0 = _mm_setzero_pd();
387 fjy0 = _mm_setzero_pd();
388 fjz0 = _mm_setzero_pd();
390 /**************************
391 * CALCULATE INTERACTIONS *
392 **************************/
394 if (gmx_mm_any_lt(rsq00,rcutoff2))
397 /* Compute parameters for interactions between i and j atoms */
398 qq00 = _mm_mul_pd(iq0,jq0);
399 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
401 /* REACTION-FIELD ELECTROSTATICS */
402 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
403 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
405 /* LENNARD-JONES DISPERSION/REPULSION */
407 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
408 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
409 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
410 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
411 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
412 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
414 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
416 /* Update potential sum for this i atom from the interaction with this j atom. */
417 velec = _mm_and_pd(velec,cutoff_mask);
418 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
419 velecsum = _mm_add_pd(velecsum,velec);
420 vvdw = _mm_and_pd(vvdw,cutoff_mask);
421 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
422 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
424 fscal = _mm_add_pd(felec,fvdw);
426 fscal = _mm_and_pd(fscal,cutoff_mask);
428 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
430 /* Update vectorial force */
431 fix0 = _mm_macc_pd(dx00,fscal,fix0);
432 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
433 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
435 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
436 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
437 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 if (gmx_mm_any_lt(rsq10,rcutoff2))
448 /* Compute parameters for interactions between i and j atoms */
449 qq10 = _mm_mul_pd(iq1,jq0);
451 /* REACTION-FIELD ELECTROSTATICS */
452 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
453 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
455 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
457 /* Update potential sum for this i atom from the interaction with this j atom. */
458 velec = _mm_and_pd(velec,cutoff_mask);
459 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
460 velecsum = _mm_add_pd(velecsum,velec);
464 fscal = _mm_and_pd(fscal,cutoff_mask);
466 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
468 /* Update vectorial force */
469 fix1 = _mm_macc_pd(dx10,fscal,fix1);
470 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
471 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
473 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
474 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
475 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
479 /**************************
480 * CALCULATE INTERACTIONS *
481 **************************/
483 if (gmx_mm_any_lt(rsq20,rcutoff2))
486 /* Compute parameters for interactions between i and j atoms */
487 qq20 = _mm_mul_pd(iq2,jq0);
489 /* REACTION-FIELD ELECTROSTATICS */
490 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
491 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
493 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
495 /* Update potential sum for this i atom from the interaction with this j atom. */
496 velec = _mm_and_pd(velec,cutoff_mask);
497 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
498 velecsum = _mm_add_pd(velecsum,velec);
502 fscal = _mm_and_pd(fscal,cutoff_mask);
504 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
506 /* Update vectorial force */
507 fix2 = _mm_macc_pd(dx20,fscal,fix2);
508 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
509 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
511 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
512 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
513 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
517 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
519 /* Inner loop uses 138 flops */
522 /* End of innermost loop */
524 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
525 f+i_coord_offset,fshift+i_shift_offset);
528 /* Update potential energies */
529 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
530 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
532 /* Increment number of inner iterations */
533 inneriter += j_index_end - j_index_start;
535 /* Outer loop uses 20 flops */
538 /* Increment number of outer iterations */
541 /* Update outer/inner flops */
543 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*138);
546 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
547 * Electrostatics interaction: ReactionField
548 * VdW interaction: LennardJones
549 * Geometry: Water3-Particle
550 * Calculate force/pot: Force
553 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
554 (t_nblist * gmx_restrict nlist,
555 rvec * gmx_restrict xx,
556 rvec * gmx_restrict ff,
557 t_forcerec * gmx_restrict fr,
558 t_mdatoms * gmx_restrict mdatoms,
559 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
560 t_nrnb * gmx_restrict nrnb)
562 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
563 * just 0 for non-waters.
564 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
565 * jnr indices corresponding to data put in the four positions in the SIMD register.
567 int i_shift_offset,i_coord_offset,outeriter,inneriter;
568 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
570 int j_coord_offsetA,j_coord_offsetB;
571 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
573 real *shiftvec,*fshift,*x,*f;
574 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
576 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
578 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
580 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
581 int vdwjidx0A,vdwjidx0B;
582 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
583 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
584 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
585 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
586 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
589 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
592 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
593 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
594 __m128d dummy_mask,cutoff_mask;
595 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
596 __m128d one = _mm_set1_pd(1.0);
597 __m128d two = _mm_set1_pd(2.0);
603 jindex = nlist->jindex;
605 shiftidx = nlist->shift;
607 shiftvec = fr->shift_vec[0];
608 fshift = fr->fshift[0];
609 facel = _mm_set1_pd(fr->epsfac);
610 charge = mdatoms->chargeA;
611 krf = _mm_set1_pd(fr->ic->k_rf);
612 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
613 crf = _mm_set1_pd(fr->ic->c_rf);
614 nvdwtype = fr->ntype;
616 vdwtype = mdatoms->typeA;
618 /* Setup water-specific parameters */
619 inr = nlist->iinr[0];
620 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
621 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
622 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
623 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
625 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
626 rcutoff_scalar = fr->rcoulomb;
627 rcutoff = _mm_set1_pd(rcutoff_scalar);
628 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
630 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
631 rvdw = _mm_set1_pd(fr->rvdw);
633 /* Avoid stupid compiler warnings */
641 /* Start outer loop over neighborlists */
642 for(iidx=0; iidx<nri; iidx++)
644 /* Load shift vector for this list */
645 i_shift_offset = DIM*shiftidx[iidx];
647 /* Load limits for loop over neighbors */
648 j_index_start = jindex[iidx];
649 j_index_end = jindex[iidx+1];
651 /* Get outer coordinate index */
653 i_coord_offset = DIM*inr;
655 /* Load i particle coords and add shift vector */
656 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
657 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
659 fix0 = _mm_setzero_pd();
660 fiy0 = _mm_setzero_pd();
661 fiz0 = _mm_setzero_pd();
662 fix1 = _mm_setzero_pd();
663 fiy1 = _mm_setzero_pd();
664 fiz1 = _mm_setzero_pd();
665 fix2 = _mm_setzero_pd();
666 fiy2 = _mm_setzero_pd();
667 fiz2 = _mm_setzero_pd();
669 /* Start inner kernel loop */
670 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
673 /* Get j neighbor index, and coordinate index */
676 j_coord_offsetA = DIM*jnrA;
677 j_coord_offsetB = DIM*jnrB;
679 /* load j atom coordinates */
680 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
683 /* Calculate displacement vector */
684 dx00 = _mm_sub_pd(ix0,jx0);
685 dy00 = _mm_sub_pd(iy0,jy0);
686 dz00 = _mm_sub_pd(iz0,jz0);
687 dx10 = _mm_sub_pd(ix1,jx0);
688 dy10 = _mm_sub_pd(iy1,jy0);
689 dz10 = _mm_sub_pd(iz1,jz0);
690 dx20 = _mm_sub_pd(ix2,jx0);
691 dy20 = _mm_sub_pd(iy2,jy0);
692 dz20 = _mm_sub_pd(iz2,jz0);
694 /* Calculate squared distance and things based on it */
695 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
696 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
697 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
699 rinv00 = gmx_mm_invsqrt_pd(rsq00);
700 rinv10 = gmx_mm_invsqrt_pd(rsq10);
701 rinv20 = gmx_mm_invsqrt_pd(rsq20);
703 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
704 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
705 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
707 /* Load parameters for j particles */
708 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
709 vdwjidx0A = 2*vdwtype[jnrA+0];
710 vdwjidx0B = 2*vdwtype[jnrB+0];
712 fjx0 = _mm_setzero_pd();
713 fjy0 = _mm_setzero_pd();
714 fjz0 = _mm_setzero_pd();
716 /**************************
717 * CALCULATE INTERACTIONS *
718 **************************/
720 if (gmx_mm_any_lt(rsq00,rcutoff2))
723 /* Compute parameters for interactions between i and j atoms */
724 qq00 = _mm_mul_pd(iq0,jq0);
725 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
726 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
728 /* REACTION-FIELD ELECTROSTATICS */
729 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
731 /* LENNARD-JONES DISPERSION/REPULSION */
733 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
734 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
736 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
738 fscal = _mm_add_pd(felec,fvdw);
740 fscal = _mm_and_pd(fscal,cutoff_mask);
742 /* Update vectorial force */
743 fix0 = _mm_macc_pd(dx00,fscal,fix0);
744 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
745 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
747 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
748 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
749 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
753 /**************************
754 * CALCULATE INTERACTIONS *
755 **************************/
757 if (gmx_mm_any_lt(rsq10,rcutoff2))
760 /* Compute parameters for interactions between i and j atoms */
761 qq10 = _mm_mul_pd(iq1,jq0);
763 /* REACTION-FIELD ELECTROSTATICS */
764 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
766 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
770 fscal = _mm_and_pd(fscal,cutoff_mask);
772 /* Update vectorial force */
773 fix1 = _mm_macc_pd(dx10,fscal,fix1);
774 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
775 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
777 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
778 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
779 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
783 /**************************
784 * CALCULATE INTERACTIONS *
785 **************************/
787 if (gmx_mm_any_lt(rsq20,rcutoff2))
790 /* Compute parameters for interactions between i and j atoms */
791 qq20 = _mm_mul_pd(iq2,jq0);
793 /* REACTION-FIELD ELECTROSTATICS */
794 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
796 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
800 fscal = _mm_and_pd(fscal,cutoff_mask);
802 /* Update vectorial force */
803 fix2 = _mm_macc_pd(dx20,fscal,fix2);
804 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
805 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
807 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
808 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
809 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
813 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
815 /* Inner loop uses 109 flops */
822 j_coord_offsetA = DIM*jnrA;
824 /* load j atom coordinates */
825 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
828 /* Calculate displacement vector */
829 dx00 = _mm_sub_pd(ix0,jx0);
830 dy00 = _mm_sub_pd(iy0,jy0);
831 dz00 = _mm_sub_pd(iz0,jz0);
832 dx10 = _mm_sub_pd(ix1,jx0);
833 dy10 = _mm_sub_pd(iy1,jy0);
834 dz10 = _mm_sub_pd(iz1,jz0);
835 dx20 = _mm_sub_pd(ix2,jx0);
836 dy20 = _mm_sub_pd(iy2,jy0);
837 dz20 = _mm_sub_pd(iz2,jz0);
839 /* Calculate squared distance and things based on it */
840 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
841 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
842 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
844 rinv00 = gmx_mm_invsqrt_pd(rsq00);
845 rinv10 = gmx_mm_invsqrt_pd(rsq10);
846 rinv20 = gmx_mm_invsqrt_pd(rsq20);
848 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
849 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
850 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
852 /* Load parameters for j particles */
853 jq0 = _mm_load_sd(charge+jnrA+0);
854 vdwjidx0A = 2*vdwtype[jnrA+0];
856 fjx0 = _mm_setzero_pd();
857 fjy0 = _mm_setzero_pd();
858 fjz0 = _mm_setzero_pd();
860 /**************************
861 * CALCULATE INTERACTIONS *
862 **************************/
864 if (gmx_mm_any_lt(rsq00,rcutoff2))
867 /* Compute parameters for interactions between i and j atoms */
868 qq00 = _mm_mul_pd(iq0,jq0);
869 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
871 /* REACTION-FIELD ELECTROSTATICS */
872 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
874 /* LENNARD-JONES DISPERSION/REPULSION */
876 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
877 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
879 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
881 fscal = _mm_add_pd(felec,fvdw);
883 fscal = _mm_and_pd(fscal,cutoff_mask);
885 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
887 /* Update vectorial force */
888 fix0 = _mm_macc_pd(dx00,fscal,fix0);
889 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
890 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
892 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
893 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
894 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
898 /**************************
899 * CALCULATE INTERACTIONS *
900 **************************/
902 if (gmx_mm_any_lt(rsq10,rcutoff2))
905 /* Compute parameters for interactions between i and j atoms */
906 qq10 = _mm_mul_pd(iq1,jq0);
908 /* REACTION-FIELD ELECTROSTATICS */
909 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
911 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
915 fscal = _mm_and_pd(fscal,cutoff_mask);
917 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
919 /* Update vectorial force */
920 fix1 = _mm_macc_pd(dx10,fscal,fix1);
921 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
922 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
924 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
925 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
926 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
930 /**************************
931 * CALCULATE INTERACTIONS *
932 **************************/
934 if (gmx_mm_any_lt(rsq20,rcutoff2))
937 /* Compute parameters for interactions between i and j atoms */
938 qq20 = _mm_mul_pd(iq2,jq0);
940 /* REACTION-FIELD ELECTROSTATICS */
941 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
943 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
947 fscal = _mm_and_pd(fscal,cutoff_mask);
949 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
951 /* Update vectorial force */
952 fix2 = _mm_macc_pd(dx20,fscal,fix2);
953 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
954 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
956 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
957 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
958 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
962 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
964 /* Inner loop uses 109 flops */
967 /* End of innermost loop */
969 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
970 f+i_coord_offset,fshift+i_shift_offset);
972 /* Increment number of inner iterations */
973 inneriter += j_index_end - j_index_start;
975 /* Outer loop uses 18 flops */
978 /* Increment number of outer iterations */
981 /* Update outer/inner flops */
983 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*109);