2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Water3
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
91 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
93 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
96 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
97 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
98 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
99 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
100 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
101 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
102 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
103 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
106 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
109 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
110 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
111 __m128 dummy_mask,cutoff_mask;
112 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
113 __m128 one = _mm_set1_ps(1.0);
114 __m128 two = _mm_set1_ps(2.0);
120 jindex = nlist->jindex;
122 shiftidx = nlist->shift;
124 shiftvec = fr->shift_vec[0];
125 fshift = fr->fshift[0];
126 facel = _mm_set1_ps(fr->ic->epsfac);
127 charge = mdatoms->chargeA;
128 krf = _mm_set1_ps(fr->ic->k_rf);
129 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
130 crf = _mm_set1_ps(fr->ic->c_rf);
131 nvdwtype = fr->ntype;
133 vdwtype = mdatoms->typeA;
135 /* Setup water-specific parameters */
136 inr = nlist->iinr[0];
137 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
138 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
139 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
140 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
142 jq0 = _mm_set1_ps(charge[inr+0]);
143 jq1 = _mm_set1_ps(charge[inr+1]);
144 jq2 = _mm_set1_ps(charge[inr+2]);
145 vdwjidx0A = 2*vdwtype[inr+0];
146 qq00 = _mm_mul_ps(iq0,jq0);
147 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
148 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
149 qq01 = _mm_mul_ps(iq0,jq1);
150 qq02 = _mm_mul_ps(iq0,jq2);
151 qq10 = _mm_mul_ps(iq1,jq0);
152 qq11 = _mm_mul_ps(iq1,jq1);
153 qq12 = _mm_mul_ps(iq1,jq2);
154 qq20 = _mm_mul_ps(iq2,jq0);
155 qq21 = _mm_mul_ps(iq2,jq1);
156 qq22 = _mm_mul_ps(iq2,jq2);
158 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
159 rcutoff_scalar = fr->ic->rcoulomb;
160 rcutoff = _mm_set1_ps(rcutoff_scalar);
161 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
163 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
164 rvdw = _mm_set1_ps(fr->ic->rvdw);
166 /* Avoid stupid compiler warnings */
167 jnrA = jnrB = jnrC = jnrD = 0;
176 for(iidx=0;iidx<4*DIM;iidx++)
181 /* Start outer loop over neighborlists */
182 for(iidx=0; iidx<nri; iidx++)
184 /* Load shift vector for this list */
185 i_shift_offset = DIM*shiftidx[iidx];
187 /* Load limits for loop over neighbors */
188 j_index_start = jindex[iidx];
189 j_index_end = jindex[iidx+1];
191 /* Get outer coordinate index */
193 i_coord_offset = DIM*inr;
195 /* Load i particle coords and add shift vector */
196 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
197 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
199 fix0 = _mm_setzero_ps();
200 fiy0 = _mm_setzero_ps();
201 fiz0 = _mm_setzero_ps();
202 fix1 = _mm_setzero_ps();
203 fiy1 = _mm_setzero_ps();
204 fiz1 = _mm_setzero_ps();
205 fix2 = _mm_setzero_ps();
206 fiy2 = _mm_setzero_ps();
207 fiz2 = _mm_setzero_ps();
209 /* Reset potential sums */
210 velecsum = _mm_setzero_ps();
211 vvdwsum = _mm_setzero_ps();
213 /* Start inner kernel loop */
214 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
217 /* Get j neighbor index, and coordinate index */
222 j_coord_offsetA = DIM*jnrA;
223 j_coord_offsetB = DIM*jnrB;
224 j_coord_offsetC = DIM*jnrC;
225 j_coord_offsetD = DIM*jnrD;
227 /* load j atom coordinates */
228 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
229 x+j_coord_offsetC,x+j_coord_offsetD,
230 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
232 /* Calculate displacement vector */
233 dx00 = _mm_sub_ps(ix0,jx0);
234 dy00 = _mm_sub_ps(iy0,jy0);
235 dz00 = _mm_sub_ps(iz0,jz0);
236 dx01 = _mm_sub_ps(ix0,jx1);
237 dy01 = _mm_sub_ps(iy0,jy1);
238 dz01 = _mm_sub_ps(iz0,jz1);
239 dx02 = _mm_sub_ps(ix0,jx2);
240 dy02 = _mm_sub_ps(iy0,jy2);
241 dz02 = _mm_sub_ps(iz0,jz2);
242 dx10 = _mm_sub_ps(ix1,jx0);
243 dy10 = _mm_sub_ps(iy1,jy0);
244 dz10 = _mm_sub_ps(iz1,jz0);
245 dx11 = _mm_sub_ps(ix1,jx1);
246 dy11 = _mm_sub_ps(iy1,jy1);
247 dz11 = _mm_sub_ps(iz1,jz1);
248 dx12 = _mm_sub_ps(ix1,jx2);
249 dy12 = _mm_sub_ps(iy1,jy2);
250 dz12 = _mm_sub_ps(iz1,jz2);
251 dx20 = _mm_sub_ps(ix2,jx0);
252 dy20 = _mm_sub_ps(iy2,jy0);
253 dz20 = _mm_sub_ps(iz2,jz0);
254 dx21 = _mm_sub_ps(ix2,jx1);
255 dy21 = _mm_sub_ps(iy2,jy1);
256 dz21 = _mm_sub_ps(iz2,jz1);
257 dx22 = _mm_sub_ps(ix2,jx2);
258 dy22 = _mm_sub_ps(iy2,jy2);
259 dz22 = _mm_sub_ps(iz2,jz2);
261 /* Calculate squared distance and things based on it */
262 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
263 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
264 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
265 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
266 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
267 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
268 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
269 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
270 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
272 rinv00 = avx128fma_invsqrt_f(rsq00);
273 rinv01 = avx128fma_invsqrt_f(rsq01);
274 rinv02 = avx128fma_invsqrt_f(rsq02);
275 rinv10 = avx128fma_invsqrt_f(rsq10);
276 rinv11 = avx128fma_invsqrt_f(rsq11);
277 rinv12 = avx128fma_invsqrt_f(rsq12);
278 rinv20 = avx128fma_invsqrt_f(rsq20);
279 rinv21 = avx128fma_invsqrt_f(rsq21);
280 rinv22 = avx128fma_invsqrt_f(rsq22);
282 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
283 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
284 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
285 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
286 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
287 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
288 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
289 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
290 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
292 fjx0 = _mm_setzero_ps();
293 fjy0 = _mm_setzero_ps();
294 fjz0 = _mm_setzero_ps();
295 fjx1 = _mm_setzero_ps();
296 fjy1 = _mm_setzero_ps();
297 fjz1 = _mm_setzero_ps();
298 fjx2 = _mm_setzero_ps();
299 fjy2 = _mm_setzero_ps();
300 fjz2 = _mm_setzero_ps();
302 /**************************
303 * CALCULATE INTERACTIONS *
304 **************************/
306 if (gmx_mm_any_lt(rsq00,rcutoff2))
309 /* REACTION-FIELD ELECTROSTATICS */
310 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
311 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
313 /* LENNARD-JONES DISPERSION/REPULSION */
315 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
316 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
317 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
318 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
319 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
320 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
322 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
324 /* Update potential sum for this i atom from the interaction with this j atom. */
325 velec = _mm_and_ps(velec,cutoff_mask);
326 velecsum = _mm_add_ps(velecsum,velec);
327 vvdw = _mm_and_ps(vvdw,cutoff_mask);
328 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
330 fscal = _mm_add_ps(felec,fvdw);
332 fscal = _mm_and_ps(fscal,cutoff_mask);
334 /* Update vectorial force */
335 fix0 = _mm_macc_ps(dx00,fscal,fix0);
336 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
337 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
339 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
340 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
341 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
345 /**************************
346 * CALCULATE INTERACTIONS *
347 **************************/
349 if (gmx_mm_any_lt(rsq01,rcutoff2))
352 /* REACTION-FIELD ELECTROSTATICS */
353 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
354 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
356 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
358 /* Update potential sum for this i atom from the interaction with this j atom. */
359 velec = _mm_and_ps(velec,cutoff_mask);
360 velecsum = _mm_add_ps(velecsum,velec);
364 fscal = _mm_and_ps(fscal,cutoff_mask);
366 /* Update vectorial force */
367 fix0 = _mm_macc_ps(dx01,fscal,fix0);
368 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
369 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
371 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
372 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
373 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
377 /**************************
378 * CALCULATE INTERACTIONS *
379 **************************/
381 if (gmx_mm_any_lt(rsq02,rcutoff2))
384 /* REACTION-FIELD ELECTROSTATICS */
385 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
386 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
388 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
390 /* Update potential sum for this i atom from the interaction with this j atom. */
391 velec = _mm_and_ps(velec,cutoff_mask);
392 velecsum = _mm_add_ps(velecsum,velec);
396 fscal = _mm_and_ps(fscal,cutoff_mask);
398 /* Update vectorial force */
399 fix0 = _mm_macc_ps(dx02,fscal,fix0);
400 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
401 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
403 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
404 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
405 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
409 /**************************
410 * CALCULATE INTERACTIONS *
411 **************************/
413 if (gmx_mm_any_lt(rsq10,rcutoff2))
416 /* REACTION-FIELD ELECTROSTATICS */
417 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
418 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
420 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
422 /* Update potential sum for this i atom from the interaction with this j atom. */
423 velec = _mm_and_ps(velec,cutoff_mask);
424 velecsum = _mm_add_ps(velecsum,velec);
428 fscal = _mm_and_ps(fscal,cutoff_mask);
430 /* Update vectorial force */
431 fix1 = _mm_macc_ps(dx10,fscal,fix1);
432 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
433 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
435 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
436 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
437 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 if (gmx_mm_any_lt(rsq11,rcutoff2))
448 /* REACTION-FIELD ELECTROSTATICS */
449 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
450 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
452 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
454 /* Update potential sum for this i atom from the interaction with this j atom. */
455 velec = _mm_and_ps(velec,cutoff_mask);
456 velecsum = _mm_add_ps(velecsum,velec);
460 fscal = _mm_and_ps(fscal,cutoff_mask);
462 /* Update vectorial force */
463 fix1 = _mm_macc_ps(dx11,fscal,fix1);
464 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
465 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
467 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
468 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
469 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
473 /**************************
474 * CALCULATE INTERACTIONS *
475 **************************/
477 if (gmx_mm_any_lt(rsq12,rcutoff2))
480 /* REACTION-FIELD ELECTROSTATICS */
481 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
482 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
484 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
486 /* Update potential sum for this i atom from the interaction with this j atom. */
487 velec = _mm_and_ps(velec,cutoff_mask);
488 velecsum = _mm_add_ps(velecsum,velec);
492 fscal = _mm_and_ps(fscal,cutoff_mask);
494 /* Update vectorial force */
495 fix1 = _mm_macc_ps(dx12,fscal,fix1);
496 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
497 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
499 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
500 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
501 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
505 /**************************
506 * CALCULATE INTERACTIONS *
507 **************************/
509 if (gmx_mm_any_lt(rsq20,rcutoff2))
512 /* REACTION-FIELD ELECTROSTATICS */
513 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
514 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
516 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
518 /* Update potential sum for this i atom from the interaction with this j atom. */
519 velec = _mm_and_ps(velec,cutoff_mask);
520 velecsum = _mm_add_ps(velecsum,velec);
524 fscal = _mm_and_ps(fscal,cutoff_mask);
526 /* Update vectorial force */
527 fix2 = _mm_macc_ps(dx20,fscal,fix2);
528 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
529 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
531 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
532 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
533 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
537 /**************************
538 * CALCULATE INTERACTIONS *
539 **************************/
541 if (gmx_mm_any_lt(rsq21,rcutoff2))
544 /* REACTION-FIELD ELECTROSTATICS */
545 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
546 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
548 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
550 /* Update potential sum for this i atom from the interaction with this j atom. */
551 velec = _mm_and_ps(velec,cutoff_mask);
552 velecsum = _mm_add_ps(velecsum,velec);
556 fscal = _mm_and_ps(fscal,cutoff_mask);
558 /* Update vectorial force */
559 fix2 = _mm_macc_ps(dx21,fscal,fix2);
560 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
561 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
563 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
564 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
565 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
569 /**************************
570 * CALCULATE INTERACTIONS *
571 **************************/
573 if (gmx_mm_any_lt(rsq22,rcutoff2))
576 /* REACTION-FIELD ELECTROSTATICS */
577 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
578 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
580 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
582 /* Update potential sum for this i atom from the interaction with this j atom. */
583 velec = _mm_and_ps(velec,cutoff_mask);
584 velecsum = _mm_add_ps(velecsum,velec);
588 fscal = _mm_and_ps(fscal,cutoff_mask);
590 /* Update vectorial force */
591 fix2 = _mm_macc_ps(dx22,fscal,fix2);
592 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
593 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
595 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
596 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
597 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
601 fjptrA = f+j_coord_offsetA;
602 fjptrB = f+j_coord_offsetB;
603 fjptrC = f+j_coord_offsetC;
604 fjptrD = f+j_coord_offsetD;
606 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
607 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
609 /* Inner loop uses 369 flops */
615 /* Get j neighbor index, and coordinate index */
616 jnrlistA = jjnr[jidx];
617 jnrlistB = jjnr[jidx+1];
618 jnrlistC = jjnr[jidx+2];
619 jnrlistD = jjnr[jidx+3];
620 /* Sign of each element will be negative for non-real atoms.
621 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
622 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
624 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
625 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
626 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
627 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
628 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
629 j_coord_offsetA = DIM*jnrA;
630 j_coord_offsetB = DIM*jnrB;
631 j_coord_offsetC = DIM*jnrC;
632 j_coord_offsetD = DIM*jnrD;
634 /* load j atom coordinates */
635 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
636 x+j_coord_offsetC,x+j_coord_offsetD,
637 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
639 /* Calculate displacement vector */
640 dx00 = _mm_sub_ps(ix0,jx0);
641 dy00 = _mm_sub_ps(iy0,jy0);
642 dz00 = _mm_sub_ps(iz0,jz0);
643 dx01 = _mm_sub_ps(ix0,jx1);
644 dy01 = _mm_sub_ps(iy0,jy1);
645 dz01 = _mm_sub_ps(iz0,jz1);
646 dx02 = _mm_sub_ps(ix0,jx2);
647 dy02 = _mm_sub_ps(iy0,jy2);
648 dz02 = _mm_sub_ps(iz0,jz2);
649 dx10 = _mm_sub_ps(ix1,jx0);
650 dy10 = _mm_sub_ps(iy1,jy0);
651 dz10 = _mm_sub_ps(iz1,jz0);
652 dx11 = _mm_sub_ps(ix1,jx1);
653 dy11 = _mm_sub_ps(iy1,jy1);
654 dz11 = _mm_sub_ps(iz1,jz1);
655 dx12 = _mm_sub_ps(ix1,jx2);
656 dy12 = _mm_sub_ps(iy1,jy2);
657 dz12 = _mm_sub_ps(iz1,jz2);
658 dx20 = _mm_sub_ps(ix2,jx0);
659 dy20 = _mm_sub_ps(iy2,jy0);
660 dz20 = _mm_sub_ps(iz2,jz0);
661 dx21 = _mm_sub_ps(ix2,jx1);
662 dy21 = _mm_sub_ps(iy2,jy1);
663 dz21 = _mm_sub_ps(iz2,jz1);
664 dx22 = _mm_sub_ps(ix2,jx2);
665 dy22 = _mm_sub_ps(iy2,jy2);
666 dz22 = _mm_sub_ps(iz2,jz2);
668 /* Calculate squared distance and things based on it */
669 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
670 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
671 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
672 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
673 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
674 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
675 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
676 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
677 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
679 rinv00 = avx128fma_invsqrt_f(rsq00);
680 rinv01 = avx128fma_invsqrt_f(rsq01);
681 rinv02 = avx128fma_invsqrt_f(rsq02);
682 rinv10 = avx128fma_invsqrt_f(rsq10);
683 rinv11 = avx128fma_invsqrt_f(rsq11);
684 rinv12 = avx128fma_invsqrt_f(rsq12);
685 rinv20 = avx128fma_invsqrt_f(rsq20);
686 rinv21 = avx128fma_invsqrt_f(rsq21);
687 rinv22 = avx128fma_invsqrt_f(rsq22);
689 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
690 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
691 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
692 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
693 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
694 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
695 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
696 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
697 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
699 fjx0 = _mm_setzero_ps();
700 fjy0 = _mm_setzero_ps();
701 fjz0 = _mm_setzero_ps();
702 fjx1 = _mm_setzero_ps();
703 fjy1 = _mm_setzero_ps();
704 fjz1 = _mm_setzero_ps();
705 fjx2 = _mm_setzero_ps();
706 fjy2 = _mm_setzero_ps();
707 fjz2 = _mm_setzero_ps();
709 /**************************
710 * CALCULATE INTERACTIONS *
711 **************************/
713 if (gmx_mm_any_lt(rsq00,rcutoff2))
716 /* REACTION-FIELD ELECTROSTATICS */
717 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
718 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
720 /* LENNARD-JONES DISPERSION/REPULSION */
722 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
723 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
724 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
725 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
726 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
727 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
729 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
731 /* Update potential sum for this i atom from the interaction with this j atom. */
732 velec = _mm_and_ps(velec,cutoff_mask);
733 velec = _mm_andnot_ps(dummy_mask,velec);
734 velecsum = _mm_add_ps(velecsum,velec);
735 vvdw = _mm_and_ps(vvdw,cutoff_mask);
736 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
737 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
739 fscal = _mm_add_ps(felec,fvdw);
741 fscal = _mm_and_ps(fscal,cutoff_mask);
743 fscal = _mm_andnot_ps(dummy_mask,fscal);
745 /* Update vectorial force */
746 fix0 = _mm_macc_ps(dx00,fscal,fix0);
747 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
748 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
750 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
751 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
752 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
756 /**************************
757 * CALCULATE INTERACTIONS *
758 **************************/
760 if (gmx_mm_any_lt(rsq01,rcutoff2))
763 /* REACTION-FIELD ELECTROSTATICS */
764 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
765 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
767 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
769 /* Update potential sum for this i atom from the interaction with this j atom. */
770 velec = _mm_and_ps(velec,cutoff_mask);
771 velec = _mm_andnot_ps(dummy_mask,velec);
772 velecsum = _mm_add_ps(velecsum,velec);
776 fscal = _mm_and_ps(fscal,cutoff_mask);
778 fscal = _mm_andnot_ps(dummy_mask,fscal);
780 /* Update vectorial force */
781 fix0 = _mm_macc_ps(dx01,fscal,fix0);
782 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
783 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
785 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
786 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
787 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
791 /**************************
792 * CALCULATE INTERACTIONS *
793 **************************/
795 if (gmx_mm_any_lt(rsq02,rcutoff2))
798 /* REACTION-FIELD ELECTROSTATICS */
799 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
800 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
802 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
804 /* Update potential sum for this i atom from the interaction with this j atom. */
805 velec = _mm_and_ps(velec,cutoff_mask);
806 velec = _mm_andnot_ps(dummy_mask,velec);
807 velecsum = _mm_add_ps(velecsum,velec);
811 fscal = _mm_and_ps(fscal,cutoff_mask);
813 fscal = _mm_andnot_ps(dummy_mask,fscal);
815 /* Update vectorial force */
816 fix0 = _mm_macc_ps(dx02,fscal,fix0);
817 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
818 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
820 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
821 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
822 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
826 /**************************
827 * CALCULATE INTERACTIONS *
828 **************************/
830 if (gmx_mm_any_lt(rsq10,rcutoff2))
833 /* REACTION-FIELD ELECTROSTATICS */
834 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
835 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
837 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
839 /* Update potential sum for this i atom from the interaction with this j atom. */
840 velec = _mm_and_ps(velec,cutoff_mask);
841 velec = _mm_andnot_ps(dummy_mask,velec);
842 velecsum = _mm_add_ps(velecsum,velec);
846 fscal = _mm_and_ps(fscal,cutoff_mask);
848 fscal = _mm_andnot_ps(dummy_mask,fscal);
850 /* Update vectorial force */
851 fix1 = _mm_macc_ps(dx10,fscal,fix1);
852 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
853 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
855 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
856 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
857 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
861 /**************************
862 * CALCULATE INTERACTIONS *
863 **************************/
865 if (gmx_mm_any_lt(rsq11,rcutoff2))
868 /* REACTION-FIELD ELECTROSTATICS */
869 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
870 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
872 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
874 /* Update potential sum for this i atom from the interaction with this j atom. */
875 velec = _mm_and_ps(velec,cutoff_mask);
876 velec = _mm_andnot_ps(dummy_mask,velec);
877 velecsum = _mm_add_ps(velecsum,velec);
881 fscal = _mm_and_ps(fscal,cutoff_mask);
883 fscal = _mm_andnot_ps(dummy_mask,fscal);
885 /* Update vectorial force */
886 fix1 = _mm_macc_ps(dx11,fscal,fix1);
887 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
888 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
890 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
891 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
892 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
896 /**************************
897 * CALCULATE INTERACTIONS *
898 **************************/
900 if (gmx_mm_any_lt(rsq12,rcutoff2))
903 /* REACTION-FIELD ELECTROSTATICS */
904 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
905 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
907 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
909 /* Update potential sum for this i atom from the interaction with this j atom. */
910 velec = _mm_and_ps(velec,cutoff_mask);
911 velec = _mm_andnot_ps(dummy_mask,velec);
912 velecsum = _mm_add_ps(velecsum,velec);
916 fscal = _mm_and_ps(fscal,cutoff_mask);
918 fscal = _mm_andnot_ps(dummy_mask,fscal);
920 /* Update vectorial force */
921 fix1 = _mm_macc_ps(dx12,fscal,fix1);
922 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
923 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
925 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
926 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
927 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
931 /**************************
932 * CALCULATE INTERACTIONS *
933 **************************/
935 if (gmx_mm_any_lt(rsq20,rcutoff2))
938 /* REACTION-FIELD ELECTROSTATICS */
939 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
940 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
942 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
944 /* Update potential sum for this i atom from the interaction with this j atom. */
945 velec = _mm_and_ps(velec,cutoff_mask);
946 velec = _mm_andnot_ps(dummy_mask,velec);
947 velecsum = _mm_add_ps(velecsum,velec);
951 fscal = _mm_and_ps(fscal,cutoff_mask);
953 fscal = _mm_andnot_ps(dummy_mask,fscal);
955 /* Update vectorial force */
956 fix2 = _mm_macc_ps(dx20,fscal,fix2);
957 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
958 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
960 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
961 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
962 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
966 /**************************
967 * CALCULATE INTERACTIONS *
968 **************************/
970 if (gmx_mm_any_lt(rsq21,rcutoff2))
973 /* REACTION-FIELD ELECTROSTATICS */
974 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
975 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
977 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
979 /* Update potential sum for this i atom from the interaction with this j atom. */
980 velec = _mm_and_ps(velec,cutoff_mask);
981 velec = _mm_andnot_ps(dummy_mask,velec);
982 velecsum = _mm_add_ps(velecsum,velec);
986 fscal = _mm_and_ps(fscal,cutoff_mask);
988 fscal = _mm_andnot_ps(dummy_mask,fscal);
990 /* Update vectorial force */
991 fix2 = _mm_macc_ps(dx21,fscal,fix2);
992 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
993 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
995 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
996 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
997 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1001 /**************************
1002 * CALCULATE INTERACTIONS *
1003 **************************/
1005 if (gmx_mm_any_lt(rsq22,rcutoff2))
1008 /* REACTION-FIELD ELECTROSTATICS */
1009 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
1010 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1012 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1014 /* Update potential sum for this i atom from the interaction with this j atom. */
1015 velec = _mm_and_ps(velec,cutoff_mask);
1016 velec = _mm_andnot_ps(dummy_mask,velec);
1017 velecsum = _mm_add_ps(velecsum,velec);
1021 fscal = _mm_and_ps(fscal,cutoff_mask);
1023 fscal = _mm_andnot_ps(dummy_mask,fscal);
1025 /* Update vectorial force */
1026 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1027 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1028 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1030 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1031 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1032 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1036 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1037 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1038 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1039 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1041 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1042 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1044 /* Inner loop uses 369 flops */
1047 /* End of innermost loop */
1049 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1050 f+i_coord_offset,fshift+i_shift_offset);
1053 /* Update potential energies */
1054 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1055 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1057 /* Increment number of inner iterations */
1058 inneriter += j_index_end - j_index_start;
1060 /* Outer loop uses 20 flops */
1063 /* Increment number of outer iterations */
1066 /* Update outer/inner flops */
1068 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*369);
1071 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1072 * Electrostatics interaction: ReactionField
1073 * VdW interaction: LennardJones
1074 * Geometry: Water3-Water3
1075 * Calculate force/pot: Force
1078 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1079 (t_nblist * gmx_restrict nlist,
1080 rvec * gmx_restrict xx,
1081 rvec * gmx_restrict ff,
1082 struct t_forcerec * gmx_restrict fr,
1083 t_mdatoms * gmx_restrict mdatoms,
1084 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1085 t_nrnb * gmx_restrict nrnb)
1087 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1088 * just 0 for non-waters.
1089 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1090 * jnr indices corresponding to data put in the four positions in the SIMD register.
1092 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1093 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1094 int jnrA,jnrB,jnrC,jnrD;
1095 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1096 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1097 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1098 real rcutoff_scalar;
1099 real *shiftvec,*fshift,*x,*f;
1100 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1101 real scratch[4*DIM];
1102 __m128 fscal,rcutoff,rcutoff2,jidxall;
1104 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1106 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1108 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1109 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1110 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1111 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1112 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1113 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1114 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1115 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1116 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1117 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1118 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1119 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1120 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1121 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1122 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1123 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1124 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1127 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1130 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1131 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1132 __m128 dummy_mask,cutoff_mask;
1133 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1134 __m128 one = _mm_set1_ps(1.0);
1135 __m128 two = _mm_set1_ps(2.0);
1141 jindex = nlist->jindex;
1143 shiftidx = nlist->shift;
1145 shiftvec = fr->shift_vec[0];
1146 fshift = fr->fshift[0];
1147 facel = _mm_set1_ps(fr->ic->epsfac);
1148 charge = mdatoms->chargeA;
1149 krf = _mm_set1_ps(fr->ic->k_rf);
1150 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1151 crf = _mm_set1_ps(fr->ic->c_rf);
1152 nvdwtype = fr->ntype;
1153 vdwparam = fr->nbfp;
1154 vdwtype = mdatoms->typeA;
1156 /* Setup water-specific parameters */
1157 inr = nlist->iinr[0];
1158 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1159 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1160 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1161 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1163 jq0 = _mm_set1_ps(charge[inr+0]);
1164 jq1 = _mm_set1_ps(charge[inr+1]);
1165 jq2 = _mm_set1_ps(charge[inr+2]);
1166 vdwjidx0A = 2*vdwtype[inr+0];
1167 qq00 = _mm_mul_ps(iq0,jq0);
1168 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1169 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1170 qq01 = _mm_mul_ps(iq0,jq1);
1171 qq02 = _mm_mul_ps(iq0,jq2);
1172 qq10 = _mm_mul_ps(iq1,jq0);
1173 qq11 = _mm_mul_ps(iq1,jq1);
1174 qq12 = _mm_mul_ps(iq1,jq2);
1175 qq20 = _mm_mul_ps(iq2,jq0);
1176 qq21 = _mm_mul_ps(iq2,jq1);
1177 qq22 = _mm_mul_ps(iq2,jq2);
1179 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1180 rcutoff_scalar = fr->ic->rcoulomb;
1181 rcutoff = _mm_set1_ps(rcutoff_scalar);
1182 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1184 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1185 rvdw = _mm_set1_ps(fr->ic->rvdw);
1187 /* Avoid stupid compiler warnings */
1188 jnrA = jnrB = jnrC = jnrD = 0;
1189 j_coord_offsetA = 0;
1190 j_coord_offsetB = 0;
1191 j_coord_offsetC = 0;
1192 j_coord_offsetD = 0;
1197 for(iidx=0;iidx<4*DIM;iidx++)
1199 scratch[iidx] = 0.0;
1202 /* Start outer loop over neighborlists */
1203 for(iidx=0; iidx<nri; iidx++)
1205 /* Load shift vector for this list */
1206 i_shift_offset = DIM*shiftidx[iidx];
1208 /* Load limits for loop over neighbors */
1209 j_index_start = jindex[iidx];
1210 j_index_end = jindex[iidx+1];
1212 /* Get outer coordinate index */
1214 i_coord_offset = DIM*inr;
1216 /* Load i particle coords and add shift vector */
1217 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1218 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1220 fix0 = _mm_setzero_ps();
1221 fiy0 = _mm_setzero_ps();
1222 fiz0 = _mm_setzero_ps();
1223 fix1 = _mm_setzero_ps();
1224 fiy1 = _mm_setzero_ps();
1225 fiz1 = _mm_setzero_ps();
1226 fix2 = _mm_setzero_ps();
1227 fiy2 = _mm_setzero_ps();
1228 fiz2 = _mm_setzero_ps();
1230 /* Start inner kernel loop */
1231 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1234 /* Get j neighbor index, and coordinate index */
1236 jnrB = jjnr[jidx+1];
1237 jnrC = jjnr[jidx+2];
1238 jnrD = jjnr[jidx+3];
1239 j_coord_offsetA = DIM*jnrA;
1240 j_coord_offsetB = DIM*jnrB;
1241 j_coord_offsetC = DIM*jnrC;
1242 j_coord_offsetD = DIM*jnrD;
1244 /* load j atom coordinates */
1245 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1246 x+j_coord_offsetC,x+j_coord_offsetD,
1247 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1249 /* Calculate displacement vector */
1250 dx00 = _mm_sub_ps(ix0,jx0);
1251 dy00 = _mm_sub_ps(iy0,jy0);
1252 dz00 = _mm_sub_ps(iz0,jz0);
1253 dx01 = _mm_sub_ps(ix0,jx1);
1254 dy01 = _mm_sub_ps(iy0,jy1);
1255 dz01 = _mm_sub_ps(iz0,jz1);
1256 dx02 = _mm_sub_ps(ix0,jx2);
1257 dy02 = _mm_sub_ps(iy0,jy2);
1258 dz02 = _mm_sub_ps(iz0,jz2);
1259 dx10 = _mm_sub_ps(ix1,jx0);
1260 dy10 = _mm_sub_ps(iy1,jy0);
1261 dz10 = _mm_sub_ps(iz1,jz0);
1262 dx11 = _mm_sub_ps(ix1,jx1);
1263 dy11 = _mm_sub_ps(iy1,jy1);
1264 dz11 = _mm_sub_ps(iz1,jz1);
1265 dx12 = _mm_sub_ps(ix1,jx2);
1266 dy12 = _mm_sub_ps(iy1,jy2);
1267 dz12 = _mm_sub_ps(iz1,jz2);
1268 dx20 = _mm_sub_ps(ix2,jx0);
1269 dy20 = _mm_sub_ps(iy2,jy0);
1270 dz20 = _mm_sub_ps(iz2,jz0);
1271 dx21 = _mm_sub_ps(ix2,jx1);
1272 dy21 = _mm_sub_ps(iy2,jy1);
1273 dz21 = _mm_sub_ps(iz2,jz1);
1274 dx22 = _mm_sub_ps(ix2,jx2);
1275 dy22 = _mm_sub_ps(iy2,jy2);
1276 dz22 = _mm_sub_ps(iz2,jz2);
1278 /* Calculate squared distance and things based on it */
1279 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1280 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1281 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1282 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1283 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1284 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1285 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1286 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1287 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1289 rinv00 = avx128fma_invsqrt_f(rsq00);
1290 rinv01 = avx128fma_invsqrt_f(rsq01);
1291 rinv02 = avx128fma_invsqrt_f(rsq02);
1292 rinv10 = avx128fma_invsqrt_f(rsq10);
1293 rinv11 = avx128fma_invsqrt_f(rsq11);
1294 rinv12 = avx128fma_invsqrt_f(rsq12);
1295 rinv20 = avx128fma_invsqrt_f(rsq20);
1296 rinv21 = avx128fma_invsqrt_f(rsq21);
1297 rinv22 = avx128fma_invsqrt_f(rsq22);
1299 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1300 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1301 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1302 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1303 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1304 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1305 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1306 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1307 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1309 fjx0 = _mm_setzero_ps();
1310 fjy0 = _mm_setzero_ps();
1311 fjz0 = _mm_setzero_ps();
1312 fjx1 = _mm_setzero_ps();
1313 fjy1 = _mm_setzero_ps();
1314 fjz1 = _mm_setzero_ps();
1315 fjx2 = _mm_setzero_ps();
1316 fjy2 = _mm_setzero_ps();
1317 fjz2 = _mm_setzero_ps();
1319 /**************************
1320 * CALCULATE INTERACTIONS *
1321 **************************/
1323 if (gmx_mm_any_lt(rsq00,rcutoff2))
1326 /* REACTION-FIELD ELECTROSTATICS */
1327 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1329 /* LENNARD-JONES DISPERSION/REPULSION */
1331 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1332 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1334 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1336 fscal = _mm_add_ps(felec,fvdw);
1338 fscal = _mm_and_ps(fscal,cutoff_mask);
1340 /* Update vectorial force */
1341 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1342 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1343 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1345 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1346 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1347 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1351 /**************************
1352 * CALCULATE INTERACTIONS *
1353 **************************/
1355 if (gmx_mm_any_lt(rsq01,rcutoff2))
1358 /* REACTION-FIELD ELECTROSTATICS */
1359 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1361 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1365 fscal = _mm_and_ps(fscal,cutoff_mask);
1367 /* Update vectorial force */
1368 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1369 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1370 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1372 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1373 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1374 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1378 /**************************
1379 * CALCULATE INTERACTIONS *
1380 **************************/
1382 if (gmx_mm_any_lt(rsq02,rcutoff2))
1385 /* REACTION-FIELD ELECTROSTATICS */
1386 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1388 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1392 fscal = _mm_and_ps(fscal,cutoff_mask);
1394 /* Update vectorial force */
1395 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1396 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1397 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1399 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1400 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1401 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1405 /**************************
1406 * CALCULATE INTERACTIONS *
1407 **************************/
1409 if (gmx_mm_any_lt(rsq10,rcutoff2))
1412 /* REACTION-FIELD ELECTROSTATICS */
1413 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1415 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1419 fscal = _mm_and_ps(fscal,cutoff_mask);
1421 /* Update vectorial force */
1422 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1423 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1424 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1426 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1427 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1428 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1432 /**************************
1433 * CALCULATE INTERACTIONS *
1434 **************************/
1436 if (gmx_mm_any_lt(rsq11,rcutoff2))
1439 /* REACTION-FIELD ELECTROSTATICS */
1440 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1442 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1446 fscal = _mm_and_ps(fscal,cutoff_mask);
1448 /* Update vectorial force */
1449 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1450 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1451 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1453 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1454 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1455 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1459 /**************************
1460 * CALCULATE INTERACTIONS *
1461 **************************/
1463 if (gmx_mm_any_lt(rsq12,rcutoff2))
1466 /* REACTION-FIELD ELECTROSTATICS */
1467 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1469 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1473 fscal = _mm_and_ps(fscal,cutoff_mask);
1475 /* Update vectorial force */
1476 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1477 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1478 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1480 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1481 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1482 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1486 /**************************
1487 * CALCULATE INTERACTIONS *
1488 **************************/
1490 if (gmx_mm_any_lt(rsq20,rcutoff2))
1493 /* REACTION-FIELD ELECTROSTATICS */
1494 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1496 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1500 fscal = _mm_and_ps(fscal,cutoff_mask);
1502 /* Update vectorial force */
1503 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1504 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1505 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1507 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1508 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1509 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1513 /**************************
1514 * CALCULATE INTERACTIONS *
1515 **************************/
1517 if (gmx_mm_any_lt(rsq21,rcutoff2))
1520 /* REACTION-FIELD ELECTROSTATICS */
1521 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1523 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1527 fscal = _mm_and_ps(fscal,cutoff_mask);
1529 /* Update vectorial force */
1530 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1531 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1532 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1534 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1535 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1536 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1540 /**************************
1541 * CALCULATE INTERACTIONS *
1542 **************************/
1544 if (gmx_mm_any_lt(rsq22,rcutoff2))
1547 /* REACTION-FIELD ELECTROSTATICS */
1548 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1550 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1554 fscal = _mm_and_ps(fscal,cutoff_mask);
1556 /* Update vectorial force */
1557 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1558 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1559 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1561 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1562 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1563 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1567 fjptrA = f+j_coord_offsetA;
1568 fjptrB = f+j_coord_offsetB;
1569 fjptrC = f+j_coord_offsetC;
1570 fjptrD = f+j_coord_offsetD;
1572 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1573 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1575 /* Inner loop uses 304 flops */
1578 if(jidx<j_index_end)
1581 /* Get j neighbor index, and coordinate index */
1582 jnrlistA = jjnr[jidx];
1583 jnrlistB = jjnr[jidx+1];
1584 jnrlistC = jjnr[jidx+2];
1585 jnrlistD = jjnr[jidx+3];
1586 /* Sign of each element will be negative for non-real atoms.
1587 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1588 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1590 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1591 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1592 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1593 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1594 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1595 j_coord_offsetA = DIM*jnrA;
1596 j_coord_offsetB = DIM*jnrB;
1597 j_coord_offsetC = DIM*jnrC;
1598 j_coord_offsetD = DIM*jnrD;
1600 /* load j atom coordinates */
1601 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1602 x+j_coord_offsetC,x+j_coord_offsetD,
1603 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1605 /* Calculate displacement vector */
1606 dx00 = _mm_sub_ps(ix0,jx0);
1607 dy00 = _mm_sub_ps(iy0,jy0);
1608 dz00 = _mm_sub_ps(iz0,jz0);
1609 dx01 = _mm_sub_ps(ix0,jx1);
1610 dy01 = _mm_sub_ps(iy0,jy1);
1611 dz01 = _mm_sub_ps(iz0,jz1);
1612 dx02 = _mm_sub_ps(ix0,jx2);
1613 dy02 = _mm_sub_ps(iy0,jy2);
1614 dz02 = _mm_sub_ps(iz0,jz2);
1615 dx10 = _mm_sub_ps(ix1,jx0);
1616 dy10 = _mm_sub_ps(iy1,jy0);
1617 dz10 = _mm_sub_ps(iz1,jz0);
1618 dx11 = _mm_sub_ps(ix1,jx1);
1619 dy11 = _mm_sub_ps(iy1,jy1);
1620 dz11 = _mm_sub_ps(iz1,jz1);
1621 dx12 = _mm_sub_ps(ix1,jx2);
1622 dy12 = _mm_sub_ps(iy1,jy2);
1623 dz12 = _mm_sub_ps(iz1,jz2);
1624 dx20 = _mm_sub_ps(ix2,jx0);
1625 dy20 = _mm_sub_ps(iy2,jy0);
1626 dz20 = _mm_sub_ps(iz2,jz0);
1627 dx21 = _mm_sub_ps(ix2,jx1);
1628 dy21 = _mm_sub_ps(iy2,jy1);
1629 dz21 = _mm_sub_ps(iz2,jz1);
1630 dx22 = _mm_sub_ps(ix2,jx2);
1631 dy22 = _mm_sub_ps(iy2,jy2);
1632 dz22 = _mm_sub_ps(iz2,jz2);
1634 /* Calculate squared distance and things based on it */
1635 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1636 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1637 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1638 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1639 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1640 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1641 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1642 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1643 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1645 rinv00 = avx128fma_invsqrt_f(rsq00);
1646 rinv01 = avx128fma_invsqrt_f(rsq01);
1647 rinv02 = avx128fma_invsqrt_f(rsq02);
1648 rinv10 = avx128fma_invsqrt_f(rsq10);
1649 rinv11 = avx128fma_invsqrt_f(rsq11);
1650 rinv12 = avx128fma_invsqrt_f(rsq12);
1651 rinv20 = avx128fma_invsqrt_f(rsq20);
1652 rinv21 = avx128fma_invsqrt_f(rsq21);
1653 rinv22 = avx128fma_invsqrt_f(rsq22);
1655 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1656 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1657 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1658 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1659 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1660 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1661 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1662 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1663 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1665 fjx0 = _mm_setzero_ps();
1666 fjy0 = _mm_setzero_ps();
1667 fjz0 = _mm_setzero_ps();
1668 fjx1 = _mm_setzero_ps();
1669 fjy1 = _mm_setzero_ps();
1670 fjz1 = _mm_setzero_ps();
1671 fjx2 = _mm_setzero_ps();
1672 fjy2 = _mm_setzero_ps();
1673 fjz2 = _mm_setzero_ps();
1675 /**************************
1676 * CALCULATE INTERACTIONS *
1677 **************************/
1679 if (gmx_mm_any_lt(rsq00,rcutoff2))
1682 /* REACTION-FIELD ELECTROSTATICS */
1683 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1685 /* LENNARD-JONES DISPERSION/REPULSION */
1687 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1688 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1690 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1692 fscal = _mm_add_ps(felec,fvdw);
1694 fscal = _mm_and_ps(fscal,cutoff_mask);
1696 fscal = _mm_andnot_ps(dummy_mask,fscal);
1698 /* Update vectorial force */
1699 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1700 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1701 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1703 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1704 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1705 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1709 /**************************
1710 * CALCULATE INTERACTIONS *
1711 **************************/
1713 if (gmx_mm_any_lt(rsq01,rcutoff2))
1716 /* REACTION-FIELD ELECTROSTATICS */
1717 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1719 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1723 fscal = _mm_and_ps(fscal,cutoff_mask);
1725 fscal = _mm_andnot_ps(dummy_mask,fscal);
1727 /* Update vectorial force */
1728 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1729 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1730 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1732 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1733 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1734 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1738 /**************************
1739 * CALCULATE INTERACTIONS *
1740 **************************/
1742 if (gmx_mm_any_lt(rsq02,rcutoff2))
1745 /* REACTION-FIELD ELECTROSTATICS */
1746 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1748 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1752 fscal = _mm_and_ps(fscal,cutoff_mask);
1754 fscal = _mm_andnot_ps(dummy_mask,fscal);
1756 /* Update vectorial force */
1757 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1758 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1759 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1761 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1762 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1763 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1767 /**************************
1768 * CALCULATE INTERACTIONS *
1769 **************************/
1771 if (gmx_mm_any_lt(rsq10,rcutoff2))
1774 /* REACTION-FIELD ELECTROSTATICS */
1775 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1777 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1781 fscal = _mm_and_ps(fscal,cutoff_mask);
1783 fscal = _mm_andnot_ps(dummy_mask,fscal);
1785 /* Update vectorial force */
1786 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1787 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1788 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1790 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1791 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1792 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1796 /**************************
1797 * CALCULATE INTERACTIONS *
1798 **************************/
1800 if (gmx_mm_any_lt(rsq11,rcutoff2))
1803 /* REACTION-FIELD ELECTROSTATICS */
1804 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1806 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1810 fscal = _mm_and_ps(fscal,cutoff_mask);
1812 fscal = _mm_andnot_ps(dummy_mask,fscal);
1814 /* Update vectorial force */
1815 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1816 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1817 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1819 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1820 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1821 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1825 /**************************
1826 * CALCULATE INTERACTIONS *
1827 **************************/
1829 if (gmx_mm_any_lt(rsq12,rcutoff2))
1832 /* REACTION-FIELD ELECTROSTATICS */
1833 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1835 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1839 fscal = _mm_and_ps(fscal,cutoff_mask);
1841 fscal = _mm_andnot_ps(dummy_mask,fscal);
1843 /* Update vectorial force */
1844 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1845 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1846 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1848 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1849 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1850 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1854 /**************************
1855 * CALCULATE INTERACTIONS *
1856 **************************/
1858 if (gmx_mm_any_lt(rsq20,rcutoff2))
1861 /* REACTION-FIELD ELECTROSTATICS */
1862 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1864 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1868 fscal = _mm_and_ps(fscal,cutoff_mask);
1870 fscal = _mm_andnot_ps(dummy_mask,fscal);
1872 /* Update vectorial force */
1873 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1874 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1875 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1877 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1878 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1879 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1883 /**************************
1884 * CALCULATE INTERACTIONS *
1885 **************************/
1887 if (gmx_mm_any_lt(rsq21,rcutoff2))
1890 /* REACTION-FIELD ELECTROSTATICS */
1891 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1893 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1897 fscal = _mm_and_ps(fscal,cutoff_mask);
1899 fscal = _mm_andnot_ps(dummy_mask,fscal);
1901 /* Update vectorial force */
1902 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1903 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1904 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1906 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1907 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1908 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1912 /**************************
1913 * CALCULATE INTERACTIONS *
1914 **************************/
1916 if (gmx_mm_any_lt(rsq22,rcutoff2))
1919 /* REACTION-FIELD ELECTROSTATICS */
1920 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1922 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1926 fscal = _mm_and_ps(fscal,cutoff_mask);
1928 fscal = _mm_andnot_ps(dummy_mask,fscal);
1930 /* Update vectorial force */
1931 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1932 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1933 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1935 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1936 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1937 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1941 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1942 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1943 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1944 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1946 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1947 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1949 /* Inner loop uses 304 flops */
1952 /* End of innermost loop */
1954 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1955 f+i_coord_offset,fshift+i_shift_offset);
1957 /* Increment number of inner iterations */
1958 inneriter += j_index_end - j_index_start;
1960 /* Outer loop uses 18 flops */
1963 /* Increment number of outer iterations */
1966 /* Update outer/inner flops */
1968 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*304);