2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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_ElecCoul_VdwCSTab_GeomW4W4_VF_avx_128_fma_single
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water4-Water4
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_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;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
93 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
94 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
95 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
96 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
97 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
98 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
99 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
100 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
101 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
102 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
103 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
104 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
105 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
106 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
107 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
108 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
111 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
114 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
115 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
117 __m128i ifour = _mm_set1_epi32(4);
118 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
120 __m128 dummy_mask,cutoff_mask;
121 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
122 __m128 one = _mm_set1_ps(1.0);
123 __m128 two = _mm_set1_ps(2.0);
129 jindex = nlist->jindex;
131 shiftidx = nlist->shift;
133 shiftvec = fr->shift_vec[0];
134 fshift = fr->fshift[0];
135 facel = _mm_set1_ps(fr->ic->epsfac);
136 charge = mdatoms->chargeA;
137 nvdwtype = fr->ntype;
139 vdwtype = mdatoms->typeA;
141 vftab = kernel_data->table_vdw->data;
142 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
144 /* Setup water-specific parameters */
145 inr = nlist->iinr[0];
146 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
147 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
148 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
149 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
151 jq1 = _mm_set1_ps(charge[inr+1]);
152 jq2 = _mm_set1_ps(charge[inr+2]);
153 jq3 = _mm_set1_ps(charge[inr+3]);
154 vdwjidx0A = 2*vdwtype[inr+0];
155 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
156 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
157 qq11 = _mm_mul_ps(iq1,jq1);
158 qq12 = _mm_mul_ps(iq1,jq2);
159 qq13 = _mm_mul_ps(iq1,jq3);
160 qq21 = _mm_mul_ps(iq2,jq1);
161 qq22 = _mm_mul_ps(iq2,jq2);
162 qq23 = _mm_mul_ps(iq2,jq3);
163 qq31 = _mm_mul_ps(iq3,jq1);
164 qq32 = _mm_mul_ps(iq3,jq2);
165 qq33 = _mm_mul_ps(iq3,jq3);
167 /* Avoid stupid compiler warnings */
168 jnrA = jnrB = jnrC = jnrD = 0;
177 for(iidx=0;iidx<4*DIM;iidx++)
182 /* Start outer loop over neighborlists */
183 for(iidx=0; iidx<nri; iidx++)
185 /* Load shift vector for this list */
186 i_shift_offset = DIM*shiftidx[iidx];
188 /* Load limits for loop over neighbors */
189 j_index_start = jindex[iidx];
190 j_index_end = jindex[iidx+1];
192 /* Get outer coordinate index */
194 i_coord_offset = DIM*inr;
196 /* Load i particle coords and add shift vector */
197 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
198 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
200 fix0 = _mm_setzero_ps();
201 fiy0 = _mm_setzero_ps();
202 fiz0 = _mm_setzero_ps();
203 fix1 = _mm_setzero_ps();
204 fiy1 = _mm_setzero_ps();
205 fiz1 = _mm_setzero_ps();
206 fix2 = _mm_setzero_ps();
207 fiy2 = _mm_setzero_ps();
208 fiz2 = _mm_setzero_ps();
209 fix3 = _mm_setzero_ps();
210 fiy3 = _mm_setzero_ps();
211 fiz3 = _mm_setzero_ps();
213 /* Reset potential sums */
214 velecsum = _mm_setzero_ps();
215 vvdwsum = _mm_setzero_ps();
217 /* Start inner kernel loop */
218 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
221 /* Get j neighbor index, and coordinate index */
226 j_coord_offsetA = DIM*jnrA;
227 j_coord_offsetB = DIM*jnrB;
228 j_coord_offsetC = DIM*jnrC;
229 j_coord_offsetD = DIM*jnrD;
231 /* load j atom coordinates */
232 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
233 x+j_coord_offsetC,x+j_coord_offsetD,
234 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
235 &jy2,&jz2,&jx3,&jy3,&jz3);
237 /* Calculate displacement vector */
238 dx00 = _mm_sub_ps(ix0,jx0);
239 dy00 = _mm_sub_ps(iy0,jy0);
240 dz00 = _mm_sub_ps(iz0,jz0);
241 dx11 = _mm_sub_ps(ix1,jx1);
242 dy11 = _mm_sub_ps(iy1,jy1);
243 dz11 = _mm_sub_ps(iz1,jz1);
244 dx12 = _mm_sub_ps(ix1,jx2);
245 dy12 = _mm_sub_ps(iy1,jy2);
246 dz12 = _mm_sub_ps(iz1,jz2);
247 dx13 = _mm_sub_ps(ix1,jx3);
248 dy13 = _mm_sub_ps(iy1,jy3);
249 dz13 = _mm_sub_ps(iz1,jz3);
250 dx21 = _mm_sub_ps(ix2,jx1);
251 dy21 = _mm_sub_ps(iy2,jy1);
252 dz21 = _mm_sub_ps(iz2,jz1);
253 dx22 = _mm_sub_ps(ix2,jx2);
254 dy22 = _mm_sub_ps(iy2,jy2);
255 dz22 = _mm_sub_ps(iz2,jz2);
256 dx23 = _mm_sub_ps(ix2,jx3);
257 dy23 = _mm_sub_ps(iy2,jy3);
258 dz23 = _mm_sub_ps(iz2,jz3);
259 dx31 = _mm_sub_ps(ix3,jx1);
260 dy31 = _mm_sub_ps(iy3,jy1);
261 dz31 = _mm_sub_ps(iz3,jz1);
262 dx32 = _mm_sub_ps(ix3,jx2);
263 dy32 = _mm_sub_ps(iy3,jy2);
264 dz32 = _mm_sub_ps(iz3,jz2);
265 dx33 = _mm_sub_ps(ix3,jx3);
266 dy33 = _mm_sub_ps(iy3,jy3);
267 dz33 = _mm_sub_ps(iz3,jz3);
269 /* Calculate squared distance and things based on it */
270 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
271 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
272 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
273 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
274 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
275 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
276 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
277 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
278 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
279 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
281 rinv00 = avx128fma_invsqrt_f(rsq00);
282 rinv11 = avx128fma_invsqrt_f(rsq11);
283 rinv12 = avx128fma_invsqrt_f(rsq12);
284 rinv13 = avx128fma_invsqrt_f(rsq13);
285 rinv21 = avx128fma_invsqrt_f(rsq21);
286 rinv22 = avx128fma_invsqrt_f(rsq22);
287 rinv23 = avx128fma_invsqrt_f(rsq23);
288 rinv31 = avx128fma_invsqrt_f(rsq31);
289 rinv32 = avx128fma_invsqrt_f(rsq32);
290 rinv33 = avx128fma_invsqrt_f(rsq33);
292 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
293 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
294 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
295 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
296 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
297 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
298 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
299 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
300 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
302 fjx0 = _mm_setzero_ps();
303 fjy0 = _mm_setzero_ps();
304 fjz0 = _mm_setzero_ps();
305 fjx1 = _mm_setzero_ps();
306 fjy1 = _mm_setzero_ps();
307 fjz1 = _mm_setzero_ps();
308 fjx2 = _mm_setzero_ps();
309 fjy2 = _mm_setzero_ps();
310 fjz2 = _mm_setzero_ps();
311 fjx3 = _mm_setzero_ps();
312 fjy3 = _mm_setzero_ps();
313 fjz3 = _mm_setzero_ps();
315 /**************************
316 * CALCULATE INTERACTIONS *
317 **************************/
319 r00 = _mm_mul_ps(rsq00,rinv00);
321 /* Calculate table index by multiplying r with table scale and truncate to integer */
322 rt = _mm_mul_ps(r00,vftabscale);
323 vfitab = _mm_cvttps_epi32(rt);
325 vfeps = _mm_frcz_ps(rt);
327 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
329 twovfeps = _mm_add_ps(vfeps,vfeps);
330 vfitab = _mm_slli_epi32(vfitab,3);
332 /* CUBIC SPLINE TABLE DISPERSION */
333 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
334 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
335 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
336 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
337 _MM_TRANSPOSE4_PS(Y,F,G,H);
338 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
339 VV = _mm_macc_ps(vfeps,Fp,Y);
340 vvdw6 = _mm_mul_ps(c6_00,VV);
341 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
342 fvdw6 = _mm_mul_ps(c6_00,FF);
344 /* CUBIC SPLINE TABLE REPULSION */
345 vfitab = _mm_add_epi32(vfitab,ifour);
346 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
347 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
348 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
349 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
350 _MM_TRANSPOSE4_PS(Y,F,G,H);
351 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
352 VV = _mm_macc_ps(vfeps,Fp,Y);
353 vvdw12 = _mm_mul_ps(c12_00,VV);
354 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
355 fvdw12 = _mm_mul_ps(c12_00,FF);
356 vvdw = _mm_add_ps(vvdw12,vvdw6);
357 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
364 /* Update vectorial force */
365 fix0 = _mm_macc_ps(dx00,fscal,fix0);
366 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
367 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
369 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
370 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
371 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
373 /**************************
374 * CALCULATE INTERACTIONS *
375 **************************/
377 /* COULOMB ELECTROSTATICS */
378 velec = _mm_mul_ps(qq11,rinv11);
379 felec = _mm_mul_ps(velec,rinvsq11);
381 /* Update potential sum for this i atom from the interaction with this j atom. */
382 velecsum = _mm_add_ps(velecsum,velec);
386 /* Update vectorial force */
387 fix1 = _mm_macc_ps(dx11,fscal,fix1);
388 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
389 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
391 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
392 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
393 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
395 /**************************
396 * CALCULATE INTERACTIONS *
397 **************************/
399 /* COULOMB ELECTROSTATICS */
400 velec = _mm_mul_ps(qq12,rinv12);
401 felec = _mm_mul_ps(velec,rinvsq12);
403 /* Update potential sum for this i atom from the interaction with this j atom. */
404 velecsum = _mm_add_ps(velecsum,velec);
408 /* Update vectorial force */
409 fix1 = _mm_macc_ps(dx12,fscal,fix1);
410 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
411 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
413 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
414 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
415 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
417 /**************************
418 * CALCULATE INTERACTIONS *
419 **************************/
421 /* COULOMB ELECTROSTATICS */
422 velec = _mm_mul_ps(qq13,rinv13);
423 felec = _mm_mul_ps(velec,rinvsq13);
425 /* Update potential sum for this i atom from the interaction with this j atom. */
426 velecsum = _mm_add_ps(velecsum,velec);
430 /* Update vectorial force */
431 fix1 = _mm_macc_ps(dx13,fscal,fix1);
432 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
433 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
435 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
436 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
437 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
439 /**************************
440 * CALCULATE INTERACTIONS *
441 **************************/
443 /* COULOMB ELECTROSTATICS */
444 velec = _mm_mul_ps(qq21,rinv21);
445 felec = _mm_mul_ps(velec,rinvsq21);
447 /* Update potential sum for this i atom from the interaction with this j atom. */
448 velecsum = _mm_add_ps(velecsum,velec);
452 /* Update vectorial force */
453 fix2 = _mm_macc_ps(dx21,fscal,fix2);
454 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
455 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
457 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
458 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
459 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
461 /**************************
462 * CALCULATE INTERACTIONS *
463 **************************/
465 /* COULOMB ELECTROSTATICS */
466 velec = _mm_mul_ps(qq22,rinv22);
467 felec = _mm_mul_ps(velec,rinvsq22);
469 /* Update potential sum for this i atom from the interaction with this j atom. */
470 velecsum = _mm_add_ps(velecsum,velec);
474 /* Update vectorial force */
475 fix2 = _mm_macc_ps(dx22,fscal,fix2);
476 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
477 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
479 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
480 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
481 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
483 /**************************
484 * CALCULATE INTERACTIONS *
485 **************************/
487 /* COULOMB ELECTROSTATICS */
488 velec = _mm_mul_ps(qq23,rinv23);
489 felec = _mm_mul_ps(velec,rinvsq23);
491 /* Update potential sum for this i atom from the interaction with this j atom. */
492 velecsum = _mm_add_ps(velecsum,velec);
496 /* Update vectorial force */
497 fix2 = _mm_macc_ps(dx23,fscal,fix2);
498 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
499 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
501 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
502 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
503 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
505 /**************************
506 * CALCULATE INTERACTIONS *
507 **************************/
509 /* COULOMB ELECTROSTATICS */
510 velec = _mm_mul_ps(qq31,rinv31);
511 felec = _mm_mul_ps(velec,rinvsq31);
513 /* Update potential sum for this i atom from the interaction with this j atom. */
514 velecsum = _mm_add_ps(velecsum,velec);
518 /* Update vectorial force */
519 fix3 = _mm_macc_ps(dx31,fscal,fix3);
520 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
521 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
523 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
524 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
525 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
527 /**************************
528 * CALCULATE INTERACTIONS *
529 **************************/
531 /* COULOMB ELECTROSTATICS */
532 velec = _mm_mul_ps(qq32,rinv32);
533 felec = _mm_mul_ps(velec,rinvsq32);
535 /* Update potential sum for this i atom from the interaction with this j atom. */
536 velecsum = _mm_add_ps(velecsum,velec);
540 /* Update vectorial force */
541 fix3 = _mm_macc_ps(dx32,fscal,fix3);
542 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
543 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
545 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
546 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
547 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
549 /**************************
550 * CALCULATE INTERACTIONS *
551 **************************/
553 /* COULOMB ELECTROSTATICS */
554 velec = _mm_mul_ps(qq33,rinv33);
555 felec = _mm_mul_ps(velec,rinvsq33);
557 /* Update potential sum for this i atom from the interaction with this j atom. */
558 velecsum = _mm_add_ps(velecsum,velec);
562 /* Update vectorial force */
563 fix3 = _mm_macc_ps(dx33,fscal,fix3);
564 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
565 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
567 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
568 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
569 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
571 fjptrA = f+j_coord_offsetA;
572 fjptrB = f+j_coord_offsetB;
573 fjptrC = f+j_coord_offsetC;
574 fjptrD = f+j_coord_offsetD;
576 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
577 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
578 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
580 /* Inner loop uses 341 flops */
586 /* Get j neighbor index, and coordinate index */
587 jnrlistA = jjnr[jidx];
588 jnrlistB = jjnr[jidx+1];
589 jnrlistC = jjnr[jidx+2];
590 jnrlistD = jjnr[jidx+3];
591 /* Sign of each element will be negative for non-real atoms.
592 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
593 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
595 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
596 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
597 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
598 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
599 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
600 j_coord_offsetA = DIM*jnrA;
601 j_coord_offsetB = DIM*jnrB;
602 j_coord_offsetC = DIM*jnrC;
603 j_coord_offsetD = DIM*jnrD;
605 /* load j atom coordinates */
606 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
607 x+j_coord_offsetC,x+j_coord_offsetD,
608 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
609 &jy2,&jz2,&jx3,&jy3,&jz3);
611 /* Calculate displacement vector */
612 dx00 = _mm_sub_ps(ix0,jx0);
613 dy00 = _mm_sub_ps(iy0,jy0);
614 dz00 = _mm_sub_ps(iz0,jz0);
615 dx11 = _mm_sub_ps(ix1,jx1);
616 dy11 = _mm_sub_ps(iy1,jy1);
617 dz11 = _mm_sub_ps(iz1,jz1);
618 dx12 = _mm_sub_ps(ix1,jx2);
619 dy12 = _mm_sub_ps(iy1,jy2);
620 dz12 = _mm_sub_ps(iz1,jz2);
621 dx13 = _mm_sub_ps(ix1,jx3);
622 dy13 = _mm_sub_ps(iy1,jy3);
623 dz13 = _mm_sub_ps(iz1,jz3);
624 dx21 = _mm_sub_ps(ix2,jx1);
625 dy21 = _mm_sub_ps(iy2,jy1);
626 dz21 = _mm_sub_ps(iz2,jz1);
627 dx22 = _mm_sub_ps(ix2,jx2);
628 dy22 = _mm_sub_ps(iy2,jy2);
629 dz22 = _mm_sub_ps(iz2,jz2);
630 dx23 = _mm_sub_ps(ix2,jx3);
631 dy23 = _mm_sub_ps(iy2,jy3);
632 dz23 = _mm_sub_ps(iz2,jz3);
633 dx31 = _mm_sub_ps(ix3,jx1);
634 dy31 = _mm_sub_ps(iy3,jy1);
635 dz31 = _mm_sub_ps(iz3,jz1);
636 dx32 = _mm_sub_ps(ix3,jx2);
637 dy32 = _mm_sub_ps(iy3,jy2);
638 dz32 = _mm_sub_ps(iz3,jz2);
639 dx33 = _mm_sub_ps(ix3,jx3);
640 dy33 = _mm_sub_ps(iy3,jy3);
641 dz33 = _mm_sub_ps(iz3,jz3);
643 /* Calculate squared distance and things based on it */
644 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
645 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
646 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
647 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
648 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
649 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
650 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
651 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
652 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
653 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
655 rinv00 = avx128fma_invsqrt_f(rsq00);
656 rinv11 = avx128fma_invsqrt_f(rsq11);
657 rinv12 = avx128fma_invsqrt_f(rsq12);
658 rinv13 = avx128fma_invsqrt_f(rsq13);
659 rinv21 = avx128fma_invsqrt_f(rsq21);
660 rinv22 = avx128fma_invsqrt_f(rsq22);
661 rinv23 = avx128fma_invsqrt_f(rsq23);
662 rinv31 = avx128fma_invsqrt_f(rsq31);
663 rinv32 = avx128fma_invsqrt_f(rsq32);
664 rinv33 = avx128fma_invsqrt_f(rsq33);
666 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
667 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
668 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
669 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
670 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
671 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
672 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
673 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
674 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
676 fjx0 = _mm_setzero_ps();
677 fjy0 = _mm_setzero_ps();
678 fjz0 = _mm_setzero_ps();
679 fjx1 = _mm_setzero_ps();
680 fjy1 = _mm_setzero_ps();
681 fjz1 = _mm_setzero_ps();
682 fjx2 = _mm_setzero_ps();
683 fjy2 = _mm_setzero_ps();
684 fjz2 = _mm_setzero_ps();
685 fjx3 = _mm_setzero_ps();
686 fjy3 = _mm_setzero_ps();
687 fjz3 = _mm_setzero_ps();
689 /**************************
690 * CALCULATE INTERACTIONS *
691 **************************/
693 r00 = _mm_mul_ps(rsq00,rinv00);
694 r00 = _mm_andnot_ps(dummy_mask,r00);
696 /* Calculate table index by multiplying r with table scale and truncate to integer */
697 rt = _mm_mul_ps(r00,vftabscale);
698 vfitab = _mm_cvttps_epi32(rt);
700 vfeps = _mm_frcz_ps(rt);
702 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
704 twovfeps = _mm_add_ps(vfeps,vfeps);
705 vfitab = _mm_slli_epi32(vfitab,3);
707 /* CUBIC SPLINE TABLE DISPERSION */
708 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
709 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
710 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
711 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
712 _MM_TRANSPOSE4_PS(Y,F,G,H);
713 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
714 VV = _mm_macc_ps(vfeps,Fp,Y);
715 vvdw6 = _mm_mul_ps(c6_00,VV);
716 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
717 fvdw6 = _mm_mul_ps(c6_00,FF);
719 /* CUBIC SPLINE TABLE REPULSION */
720 vfitab = _mm_add_epi32(vfitab,ifour);
721 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
722 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
723 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
724 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
725 _MM_TRANSPOSE4_PS(Y,F,G,H);
726 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
727 VV = _mm_macc_ps(vfeps,Fp,Y);
728 vvdw12 = _mm_mul_ps(c12_00,VV);
729 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
730 fvdw12 = _mm_mul_ps(c12_00,FF);
731 vvdw = _mm_add_ps(vvdw12,vvdw6);
732 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
734 /* Update potential sum for this i atom from the interaction with this j atom. */
735 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
736 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
740 fscal = _mm_andnot_ps(dummy_mask,fscal);
742 /* Update vectorial force */
743 fix0 = _mm_macc_ps(dx00,fscal,fix0);
744 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
745 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
747 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
748 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
749 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
751 /**************************
752 * CALCULATE INTERACTIONS *
753 **************************/
755 /* COULOMB ELECTROSTATICS */
756 velec = _mm_mul_ps(qq11,rinv11);
757 felec = _mm_mul_ps(velec,rinvsq11);
759 /* Update potential sum for this i atom from the interaction with this j atom. */
760 velec = _mm_andnot_ps(dummy_mask,velec);
761 velecsum = _mm_add_ps(velecsum,velec);
765 fscal = _mm_andnot_ps(dummy_mask,fscal);
767 /* Update vectorial force */
768 fix1 = _mm_macc_ps(dx11,fscal,fix1);
769 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
770 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
772 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
773 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
774 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
776 /**************************
777 * CALCULATE INTERACTIONS *
778 **************************/
780 /* COULOMB ELECTROSTATICS */
781 velec = _mm_mul_ps(qq12,rinv12);
782 felec = _mm_mul_ps(velec,rinvsq12);
784 /* Update potential sum for this i atom from the interaction with this j atom. */
785 velec = _mm_andnot_ps(dummy_mask,velec);
786 velecsum = _mm_add_ps(velecsum,velec);
790 fscal = _mm_andnot_ps(dummy_mask,fscal);
792 /* Update vectorial force */
793 fix1 = _mm_macc_ps(dx12,fscal,fix1);
794 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
795 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
797 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
798 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
799 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
801 /**************************
802 * CALCULATE INTERACTIONS *
803 **************************/
805 /* COULOMB ELECTROSTATICS */
806 velec = _mm_mul_ps(qq13,rinv13);
807 felec = _mm_mul_ps(velec,rinvsq13);
809 /* Update potential sum for this i atom from the interaction with this j atom. */
810 velec = _mm_andnot_ps(dummy_mask,velec);
811 velecsum = _mm_add_ps(velecsum,velec);
815 fscal = _mm_andnot_ps(dummy_mask,fscal);
817 /* Update vectorial force */
818 fix1 = _mm_macc_ps(dx13,fscal,fix1);
819 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
820 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
822 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
823 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
824 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
826 /**************************
827 * CALCULATE INTERACTIONS *
828 **************************/
830 /* COULOMB ELECTROSTATICS */
831 velec = _mm_mul_ps(qq21,rinv21);
832 felec = _mm_mul_ps(velec,rinvsq21);
834 /* Update potential sum for this i atom from the interaction with this j atom. */
835 velec = _mm_andnot_ps(dummy_mask,velec);
836 velecsum = _mm_add_ps(velecsum,velec);
840 fscal = _mm_andnot_ps(dummy_mask,fscal);
842 /* Update vectorial force */
843 fix2 = _mm_macc_ps(dx21,fscal,fix2);
844 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
845 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
847 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
848 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
849 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
851 /**************************
852 * CALCULATE INTERACTIONS *
853 **************************/
855 /* COULOMB ELECTROSTATICS */
856 velec = _mm_mul_ps(qq22,rinv22);
857 felec = _mm_mul_ps(velec,rinvsq22);
859 /* Update potential sum for this i atom from the interaction with this j atom. */
860 velec = _mm_andnot_ps(dummy_mask,velec);
861 velecsum = _mm_add_ps(velecsum,velec);
865 fscal = _mm_andnot_ps(dummy_mask,fscal);
867 /* Update vectorial force */
868 fix2 = _mm_macc_ps(dx22,fscal,fix2);
869 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
870 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
872 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
873 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
874 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
876 /**************************
877 * CALCULATE INTERACTIONS *
878 **************************/
880 /* COULOMB ELECTROSTATICS */
881 velec = _mm_mul_ps(qq23,rinv23);
882 felec = _mm_mul_ps(velec,rinvsq23);
884 /* Update potential sum for this i atom from the interaction with this j atom. */
885 velec = _mm_andnot_ps(dummy_mask,velec);
886 velecsum = _mm_add_ps(velecsum,velec);
890 fscal = _mm_andnot_ps(dummy_mask,fscal);
892 /* Update vectorial force */
893 fix2 = _mm_macc_ps(dx23,fscal,fix2);
894 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
895 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
897 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
898 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
899 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
901 /**************************
902 * CALCULATE INTERACTIONS *
903 **************************/
905 /* COULOMB ELECTROSTATICS */
906 velec = _mm_mul_ps(qq31,rinv31);
907 felec = _mm_mul_ps(velec,rinvsq31);
909 /* Update potential sum for this i atom from the interaction with this j atom. */
910 velec = _mm_andnot_ps(dummy_mask,velec);
911 velecsum = _mm_add_ps(velecsum,velec);
915 fscal = _mm_andnot_ps(dummy_mask,fscal);
917 /* Update vectorial force */
918 fix3 = _mm_macc_ps(dx31,fscal,fix3);
919 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
920 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
922 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
923 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
924 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
926 /**************************
927 * CALCULATE INTERACTIONS *
928 **************************/
930 /* COULOMB ELECTROSTATICS */
931 velec = _mm_mul_ps(qq32,rinv32);
932 felec = _mm_mul_ps(velec,rinvsq32);
934 /* Update potential sum for this i atom from the interaction with this j atom. */
935 velec = _mm_andnot_ps(dummy_mask,velec);
936 velecsum = _mm_add_ps(velecsum,velec);
940 fscal = _mm_andnot_ps(dummy_mask,fscal);
942 /* Update vectorial force */
943 fix3 = _mm_macc_ps(dx32,fscal,fix3);
944 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
945 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
947 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
948 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
949 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
951 /**************************
952 * CALCULATE INTERACTIONS *
953 **************************/
955 /* COULOMB ELECTROSTATICS */
956 velec = _mm_mul_ps(qq33,rinv33);
957 felec = _mm_mul_ps(velec,rinvsq33);
959 /* Update potential sum for this i atom from the interaction with this j atom. */
960 velec = _mm_andnot_ps(dummy_mask,velec);
961 velecsum = _mm_add_ps(velecsum,velec);
965 fscal = _mm_andnot_ps(dummy_mask,fscal);
967 /* Update vectorial force */
968 fix3 = _mm_macc_ps(dx33,fscal,fix3);
969 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
970 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
972 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
973 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
974 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
976 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
977 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
978 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
979 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
981 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
982 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
983 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
985 /* Inner loop uses 342 flops */
988 /* End of innermost loop */
990 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
991 f+i_coord_offset,fshift+i_shift_offset);
994 /* Update potential energies */
995 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
996 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
998 /* Increment number of inner iterations */
999 inneriter += j_index_end - j_index_start;
1001 /* Outer loop uses 26 flops */
1004 /* Increment number of outer iterations */
1007 /* Update outer/inner flops */
1009 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*342);
1012 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_F_avx_128_fma_single
1013 * Electrostatics interaction: Coulomb
1014 * VdW interaction: CubicSplineTable
1015 * Geometry: Water4-Water4
1016 * Calculate force/pot: Force
1019 nb_kernel_ElecCoul_VdwCSTab_GeomW4W4_F_avx_128_fma_single
1020 (t_nblist * gmx_restrict nlist,
1021 rvec * gmx_restrict xx,
1022 rvec * gmx_restrict ff,
1023 struct t_forcerec * gmx_restrict fr,
1024 t_mdatoms * gmx_restrict mdatoms,
1025 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1026 t_nrnb * gmx_restrict nrnb)
1028 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1029 * just 0 for non-waters.
1030 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1031 * jnr indices corresponding to data put in the four positions in the SIMD register.
1033 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1034 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1035 int jnrA,jnrB,jnrC,jnrD;
1036 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1037 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1038 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1039 real rcutoff_scalar;
1040 real *shiftvec,*fshift,*x,*f;
1041 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1042 real scratch[4*DIM];
1043 __m128 fscal,rcutoff,rcutoff2,jidxall;
1045 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1047 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1049 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1051 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1052 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1053 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1054 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1055 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1056 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1057 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1058 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1059 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1060 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1061 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1062 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1063 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1064 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1065 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1066 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1067 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1068 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1069 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1070 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1073 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1076 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1077 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1079 __m128i ifour = _mm_set1_epi32(4);
1080 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
1082 __m128 dummy_mask,cutoff_mask;
1083 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1084 __m128 one = _mm_set1_ps(1.0);
1085 __m128 two = _mm_set1_ps(2.0);
1091 jindex = nlist->jindex;
1093 shiftidx = nlist->shift;
1095 shiftvec = fr->shift_vec[0];
1096 fshift = fr->fshift[0];
1097 facel = _mm_set1_ps(fr->ic->epsfac);
1098 charge = mdatoms->chargeA;
1099 nvdwtype = fr->ntype;
1100 vdwparam = fr->nbfp;
1101 vdwtype = mdatoms->typeA;
1103 vftab = kernel_data->table_vdw->data;
1104 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
1106 /* Setup water-specific parameters */
1107 inr = nlist->iinr[0];
1108 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1109 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1110 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1111 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1113 jq1 = _mm_set1_ps(charge[inr+1]);
1114 jq2 = _mm_set1_ps(charge[inr+2]);
1115 jq3 = _mm_set1_ps(charge[inr+3]);
1116 vdwjidx0A = 2*vdwtype[inr+0];
1117 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1118 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1119 qq11 = _mm_mul_ps(iq1,jq1);
1120 qq12 = _mm_mul_ps(iq1,jq2);
1121 qq13 = _mm_mul_ps(iq1,jq3);
1122 qq21 = _mm_mul_ps(iq2,jq1);
1123 qq22 = _mm_mul_ps(iq2,jq2);
1124 qq23 = _mm_mul_ps(iq2,jq3);
1125 qq31 = _mm_mul_ps(iq3,jq1);
1126 qq32 = _mm_mul_ps(iq3,jq2);
1127 qq33 = _mm_mul_ps(iq3,jq3);
1129 /* Avoid stupid compiler warnings */
1130 jnrA = jnrB = jnrC = jnrD = 0;
1131 j_coord_offsetA = 0;
1132 j_coord_offsetB = 0;
1133 j_coord_offsetC = 0;
1134 j_coord_offsetD = 0;
1139 for(iidx=0;iidx<4*DIM;iidx++)
1141 scratch[iidx] = 0.0;
1144 /* Start outer loop over neighborlists */
1145 for(iidx=0; iidx<nri; iidx++)
1147 /* Load shift vector for this list */
1148 i_shift_offset = DIM*shiftidx[iidx];
1150 /* Load limits for loop over neighbors */
1151 j_index_start = jindex[iidx];
1152 j_index_end = jindex[iidx+1];
1154 /* Get outer coordinate index */
1156 i_coord_offset = DIM*inr;
1158 /* Load i particle coords and add shift vector */
1159 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1160 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1162 fix0 = _mm_setzero_ps();
1163 fiy0 = _mm_setzero_ps();
1164 fiz0 = _mm_setzero_ps();
1165 fix1 = _mm_setzero_ps();
1166 fiy1 = _mm_setzero_ps();
1167 fiz1 = _mm_setzero_ps();
1168 fix2 = _mm_setzero_ps();
1169 fiy2 = _mm_setzero_ps();
1170 fiz2 = _mm_setzero_ps();
1171 fix3 = _mm_setzero_ps();
1172 fiy3 = _mm_setzero_ps();
1173 fiz3 = _mm_setzero_ps();
1175 /* Start inner kernel loop */
1176 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1179 /* Get j neighbor index, and coordinate index */
1181 jnrB = jjnr[jidx+1];
1182 jnrC = jjnr[jidx+2];
1183 jnrD = jjnr[jidx+3];
1184 j_coord_offsetA = DIM*jnrA;
1185 j_coord_offsetB = DIM*jnrB;
1186 j_coord_offsetC = DIM*jnrC;
1187 j_coord_offsetD = DIM*jnrD;
1189 /* load j atom coordinates */
1190 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1191 x+j_coord_offsetC,x+j_coord_offsetD,
1192 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1193 &jy2,&jz2,&jx3,&jy3,&jz3);
1195 /* Calculate displacement vector */
1196 dx00 = _mm_sub_ps(ix0,jx0);
1197 dy00 = _mm_sub_ps(iy0,jy0);
1198 dz00 = _mm_sub_ps(iz0,jz0);
1199 dx11 = _mm_sub_ps(ix1,jx1);
1200 dy11 = _mm_sub_ps(iy1,jy1);
1201 dz11 = _mm_sub_ps(iz1,jz1);
1202 dx12 = _mm_sub_ps(ix1,jx2);
1203 dy12 = _mm_sub_ps(iy1,jy2);
1204 dz12 = _mm_sub_ps(iz1,jz2);
1205 dx13 = _mm_sub_ps(ix1,jx3);
1206 dy13 = _mm_sub_ps(iy1,jy3);
1207 dz13 = _mm_sub_ps(iz1,jz3);
1208 dx21 = _mm_sub_ps(ix2,jx1);
1209 dy21 = _mm_sub_ps(iy2,jy1);
1210 dz21 = _mm_sub_ps(iz2,jz1);
1211 dx22 = _mm_sub_ps(ix2,jx2);
1212 dy22 = _mm_sub_ps(iy2,jy2);
1213 dz22 = _mm_sub_ps(iz2,jz2);
1214 dx23 = _mm_sub_ps(ix2,jx3);
1215 dy23 = _mm_sub_ps(iy2,jy3);
1216 dz23 = _mm_sub_ps(iz2,jz3);
1217 dx31 = _mm_sub_ps(ix3,jx1);
1218 dy31 = _mm_sub_ps(iy3,jy1);
1219 dz31 = _mm_sub_ps(iz3,jz1);
1220 dx32 = _mm_sub_ps(ix3,jx2);
1221 dy32 = _mm_sub_ps(iy3,jy2);
1222 dz32 = _mm_sub_ps(iz3,jz2);
1223 dx33 = _mm_sub_ps(ix3,jx3);
1224 dy33 = _mm_sub_ps(iy3,jy3);
1225 dz33 = _mm_sub_ps(iz3,jz3);
1227 /* Calculate squared distance and things based on it */
1228 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1229 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1230 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1231 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1232 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1233 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1234 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1235 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1236 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1237 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1239 rinv00 = avx128fma_invsqrt_f(rsq00);
1240 rinv11 = avx128fma_invsqrt_f(rsq11);
1241 rinv12 = avx128fma_invsqrt_f(rsq12);
1242 rinv13 = avx128fma_invsqrt_f(rsq13);
1243 rinv21 = avx128fma_invsqrt_f(rsq21);
1244 rinv22 = avx128fma_invsqrt_f(rsq22);
1245 rinv23 = avx128fma_invsqrt_f(rsq23);
1246 rinv31 = avx128fma_invsqrt_f(rsq31);
1247 rinv32 = avx128fma_invsqrt_f(rsq32);
1248 rinv33 = avx128fma_invsqrt_f(rsq33);
1250 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1251 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1252 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1253 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1254 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1255 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1256 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1257 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1258 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1260 fjx0 = _mm_setzero_ps();
1261 fjy0 = _mm_setzero_ps();
1262 fjz0 = _mm_setzero_ps();
1263 fjx1 = _mm_setzero_ps();
1264 fjy1 = _mm_setzero_ps();
1265 fjz1 = _mm_setzero_ps();
1266 fjx2 = _mm_setzero_ps();
1267 fjy2 = _mm_setzero_ps();
1268 fjz2 = _mm_setzero_ps();
1269 fjx3 = _mm_setzero_ps();
1270 fjy3 = _mm_setzero_ps();
1271 fjz3 = _mm_setzero_ps();
1273 /**************************
1274 * CALCULATE INTERACTIONS *
1275 **************************/
1277 r00 = _mm_mul_ps(rsq00,rinv00);
1279 /* Calculate table index by multiplying r with table scale and truncate to integer */
1280 rt = _mm_mul_ps(r00,vftabscale);
1281 vfitab = _mm_cvttps_epi32(rt);
1283 vfeps = _mm_frcz_ps(rt);
1285 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1287 twovfeps = _mm_add_ps(vfeps,vfeps);
1288 vfitab = _mm_slli_epi32(vfitab,3);
1290 /* CUBIC SPLINE TABLE DISPERSION */
1291 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1292 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1293 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1294 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1295 _MM_TRANSPOSE4_PS(Y,F,G,H);
1296 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1297 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1298 fvdw6 = _mm_mul_ps(c6_00,FF);
1300 /* CUBIC SPLINE TABLE REPULSION */
1301 vfitab = _mm_add_epi32(vfitab,ifour);
1302 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1303 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1304 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1305 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1306 _MM_TRANSPOSE4_PS(Y,F,G,H);
1307 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1308 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1309 fvdw12 = _mm_mul_ps(c12_00,FF);
1310 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1314 /* Update vectorial force */
1315 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1316 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1317 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1319 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1320 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1321 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1323 /**************************
1324 * CALCULATE INTERACTIONS *
1325 **************************/
1327 /* COULOMB ELECTROSTATICS */
1328 velec = _mm_mul_ps(qq11,rinv11);
1329 felec = _mm_mul_ps(velec,rinvsq11);
1333 /* Update vectorial force */
1334 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1335 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1336 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1338 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1339 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1340 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1342 /**************************
1343 * CALCULATE INTERACTIONS *
1344 **************************/
1346 /* COULOMB ELECTROSTATICS */
1347 velec = _mm_mul_ps(qq12,rinv12);
1348 felec = _mm_mul_ps(velec,rinvsq12);
1352 /* Update vectorial force */
1353 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1354 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1355 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1357 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1358 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1359 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1361 /**************************
1362 * CALCULATE INTERACTIONS *
1363 **************************/
1365 /* COULOMB ELECTROSTATICS */
1366 velec = _mm_mul_ps(qq13,rinv13);
1367 felec = _mm_mul_ps(velec,rinvsq13);
1371 /* Update vectorial force */
1372 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1373 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1374 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1376 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1377 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1378 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1380 /**************************
1381 * CALCULATE INTERACTIONS *
1382 **************************/
1384 /* COULOMB ELECTROSTATICS */
1385 velec = _mm_mul_ps(qq21,rinv21);
1386 felec = _mm_mul_ps(velec,rinvsq21);
1390 /* Update vectorial force */
1391 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1392 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1393 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1395 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1396 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1397 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1399 /**************************
1400 * CALCULATE INTERACTIONS *
1401 **************************/
1403 /* COULOMB ELECTROSTATICS */
1404 velec = _mm_mul_ps(qq22,rinv22);
1405 felec = _mm_mul_ps(velec,rinvsq22);
1409 /* Update vectorial force */
1410 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1411 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1412 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1414 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1415 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1416 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1418 /**************************
1419 * CALCULATE INTERACTIONS *
1420 **************************/
1422 /* COULOMB ELECTROSTATICS */
1423 velec = _mm_mul_ps(qq23,rinv23);
1424 felec = _mm_mul_ps(velec,rinvsq23);
1428 /* Update vectorial force */
1429 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1430 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1431 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1433 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1434 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1435 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1437 /**************************
1438 * CALCULATE INTERACTIONS *
1439 **************************/
1441 /* COULOMB ELECTROSTATICS */
1442 velec = _mm_mul_ps(qq31,rinv31);
1443 felec = _mm_mul_ps(velec,rinvsq31);
1447 /* Update vectorial force */
1448 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1449 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1450 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1452 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1453 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1454 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1456 /**************************
1457 * CALCULATE INTERACTIONS *
1458 **************************/
1460 /* COULOMB ELECTROSTATICS */
1461 velec = _mm_mul_ps(qq32,rinv32);
1462 felec = _mm_mul_ps(velec,rinvsq32);
1466 /* Update vectorial force */
1467 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1468 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1469 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1471 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1472 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1473 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1475 /**************************
1476 * CALCULATE INTERACTIONS *
1477 **************************/
1479 /* COULOMB ELECTROSTATICS */
1480 velec = _mm_mul_ps(qq33,rinv33);
1481 felec = _mm_mul_ps(velec,rinvsq33);
1485 /* Update vectorial force */
1486 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1487 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1488 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1490 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1491 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1492 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1494 fjptrA = f+j_coord_offsetA;
1495 fjptrB = f+j_coord_offsetB;
1496 fjptrC = f+j_coord_offsetC;
1497 fjptrD = f+j_coord_offsetD;
1499 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1500 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1501 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1503 /* Inner loop uses 324 flops */
1506 if(jidx<j_index_end)
1509 /* Get j neighbor index, and coordinate index */
1510 jnrlistA = jjnr[jidx];
1511 jnrlistB = jjnr[jidx+1];
1512 jnrlistC = jjnr[jidx+2];
1513 jnrlistD = jjnr[jidx+3];
1514 /* Sign of each element will be negative for non-real atoms.
1515 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1516 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1518 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1519 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1520 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1521 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1522 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1523 j_coord_offsetA = DIM*jnrA;
1524 j_coord_offsetB = DIM*jnrB;
1525 j_coord_offsetC = DIM*jnrC;
1526 j_coord_offsetD = DIM*jnrD;
1528 /* load j atom coordinates */
1529 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1530 x+j_coord_offsetC,x+j_coord_offsetD,
1531 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1532 &jy2,&jz2,&jx3,&jy3,&jz3);
1534 /* Calculate displacement vector */
1535 dx00 = _mm_sub_ps(ix0,jx0);
1536 dy00 = _mm_sub_ps(iy0,jy0);
1537 dz00 = _mm_sub_ps(iz0,jz0);
1538 dx11 = _mm_sub_ps(ix1,jx1);
1539 dy11 = _mm_sub_ps(iy1,jy1);
1540 dz11 = _mm_sub_ps(iz1,jz1);
1541 dx12 = _mm_sub_ps(ix1,jx2);
1542 dy12 = _mm_sub_ps(iy1,jy2);
1543 dz12 = _mm_sub_ps(iz1,jz2);
1544 dx13 = _mm_sub_ps(ix1,jx3);
1545 dy13 = _mm_sub_ps(iy1,jy3);
1546 dz13 = _mm_sub_ps(iz1,jz3);
1547 dx21 = _mm_sub_ps(ix2,jx1);
1548 dy21 = _mm_sub_ps(iy2,jy1);
1549 dz21 = _mm_sub_ps(iz2,jz1);
1550 dx22 = _mm_sub_ps(ix2,jx2);
1551 dy22 = _mm_sub_ps(iy2,jy2);
1552 dz22 = _mm_sub_ps(iz2,jz2);
1553 dx23 = _mm_sub_ps(ix2,jx3);
1554 dy23 = _mm_sub_ps(iy2,jy3);
1555 dz23 = _mm_sub_ps(iz2,jz3);
1556 dx31 = _mm_sub_ps(ix3,jx1);
1557 dy31 = _mm_sub_ps(iy3,jy1);
1558 dz31 = _mm_sub_ps(iz3,jz1);
1559 dx32 = _mm_sub_ps(ix3,jx2);
1560 dy32 = _mm_sub_ps(iy3,jy2);
1561 dz32 = _mm_sub_ps(iz3,jz2);
1562 dx33 = _mm_sub_ps(ix3,jx3);
1563 dy33 = _mm_sub_ps(iy3,jy3);
1564 dz33 = _mm_sub_ps(iz3,jz3);
1566 /* Calculate squared distance and things based on it */
1567 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1568 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1569 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1570 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1571 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1572 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1573 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1574 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1575 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1576 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1578 rinv00 = avx128fma_invsqrt_f(rsq00);
1579 rinv11 = avx128fma_invsqrt_f(rsq11);
1580 rinv12 = avx128fma_invsqrt_f(rsq12);
1581 rinv13 = avx128fma_invsqrt_f(rsq13);
1582 rinv21 = avx128fma_invsqrt_f(rsq21);
1583 rinv22 = avx128fma_invsqrt_f(rsq22);
1584 rinv23 = avx128fma_invsqrt_f(rsq23);
1585 rinv31 = avx128fma_invsqrt_f(rsq31);
1586 rinv32 = avx128fma_invsqrt_f(rsq32);
1587 rinv33 = avx128fma_invsqrt_f(rsq33);
1589 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1590 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1591 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1592 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1593 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1594 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1595 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1596 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1597 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1599 fjx0 = _mm_setzero_ps();
1600 fjy0 = _mm_setzero_ps();
1601 fjz0 = _mm_setzero_ps();
1602 fjx1 = _mm_setzero_ps();
1603 fjy1 = _mm_setzero_ps();
1604 fjz1 = _mm_setzero_ps();
1605 fjx2 = _mm_setzero_ps();
1606 fjy2 = _mm_setzero_ps();
1607 fjz2 = _mm_setzero_ps();
1608 fjx3 = _mm_setzero_ps();
1609 fjy3 = _mm_setzero_ps();
1610 fjz3 = _mm_setzero_ps();
1612 /**************************
1613 * CALCULATE INTERACTIONS *
1614 **************************/
1616 r00 = _mm_mul_ps(rsq00,rinv00);
1617 r00 = _mm_andnot_ps(dummy_mask,r00);
1619 /* Calculate table index by multiplying r with table scale and truncate to integer */
1620 rt = _mm_mul_ps(r00,vftabscale);
1621 vfitab = _mm_cvttps_epi32(rt);
1623 vfeps = _mm_frcz_ps(rt);
1625 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1627 twovfeps = _mm_add_ps(vfeps,vfeps);
1628 vfitab = _mm_slli_epi32(vfitab,3);
1630 /* CUBIC SPLINE TABLE DISPERSION */
1631 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1632 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1633 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1634 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1635 _MM_TRANSPOSE4_PS(Y,F,G,H);
1636 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1637 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1638 fvdw6 = _mm_mul_ps(c6_00,FF);
1640 /* CUBIC SPLINE TABLE REPULSION */
1641 vfitab = _mm_add_epi32(vfitab,ifour);
1642 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1643 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1644 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1645 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1646 _MM_TRANSPOSE4_PS(Y,F,G,H);
1647 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1648 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1649 fvdw12 = _mm_mul_ps(c12_00,FF);
1650 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1654 fscal = _mm_andnot_ps(dummy_mask,fscal);
1656 /* Update vectorial force */
1657 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1658 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1659 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1661 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1662 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1663 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1665 /**************************
1666 * CALCULATE INTERACTIONS *
1667 **************************/
1669 /* COULOMB ELECTROSTATICS */
1670 velec = _mm_mul_ps(qq11,rinv11);
1671 felec = _mm_mul_ps(velec,rinvsq11);
1675 fscal = _mm_andnot_ps(dummy_mask,fscal);
1677 /* Update vectorial force */
1678 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1679 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1680 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1682 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1683 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1684 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1686 /**************************
1687 * CALCULATE INTERACTIONS *
1688 **************************/
1690 /* COULOMB ELECTROSTATICS */
1691 velec = _mm_mul_ps(qq12,rinv12);
1692 felec = _mm_mul_ps(velec,rinvsq12);
1696 fscal = _mm_andnot_ps(dummy_mask,fscal);
1698 /* Update vectorial force */
1699 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1700 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1701 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1703 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1704 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1705 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1707 /**************************
1708 * CALCULATE INTERACTIONS *
1709 **************************/
1711 /* COULOMB ELECTROSTATICS */
1712 velec = _mm_mul_ps(qq13,rinv13);
1713 felec = _mm_mul_ps(velec,rinvsq13);
1717 fscal = _mm_andnot_ps(dummy_mask,fscal);
1719 /* Update vectorial force */
1720 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1721 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1722 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1724 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1725 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1726 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1728 /**************************
1729 * CALCULATE INTERACTIONS *
1730 **************************/
1732 /* COULOMB ELECTROSTATICS */
1733 velec = _mm_mul_ps(qq21,rinv21);
1734 felec = _mm_mul_ps(velec,rinvsq21);
1738 fscal = _mm_andnot_ps(dummy_mask,fscal);
1740 /* Update vectorial force */
1741 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1742 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1743 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1745 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1746 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1747 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1749 /**************************
1750 * CALCULATE INTERACTIONS *
1751 **************************/
1753 /* COULOMB ELECTROSTATICS */
1754 velec = _mm_mul_ps(qq22,rinv22);
1755 felec = _mm_mul_ps(velec,rinvsq22);
1759 fscal = _mm_andnot_ps(dummy_mask,fscal);
1761 /* Update vectorial force */
1762 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1763 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1764 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1766 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1767 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1768 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1770 /**************************
1771 * CALCULATE INTERACTIONS *
1772 **************************/
1774 /* COULOMB ELECTROSTATICS */
1775 velec = _mm_mul_ps(qq23,rinv23);
1776 felec = _mm_mul_ps(velec,rinvsq23);
1780 fscal = _mm_andnot_ps(dummy_mask,fscal);
1782 /* Update vectorial force */
1783 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1784 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1785 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1787 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1788 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1789 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1791 /**************************
1792 * CALCULATE INTERACTIONS *
1793 **************************/
1795 /* COULOMB ELECTROSTATICS */
1796 velec = _mm_mul_ps(qq31,rinv31);
1797 felec = _mm_mul_ps(velec,rinvsq31);
1801 fscal = _mm_andnot_ps(dummy_mask,fscal);
1803 /* Update vectorial force */
1804 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1805 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1806 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1808 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1809 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1810 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1812 /**************************
1813 * CALCULATE INTERACTIONS *
1814 **************************/
1816 /* COULOMB ELECTROSTATICS */
1817 velec = _mm_mul_ps(qq32,rinv32);
1818 felec = _mm_mul_ps(velec,rinvsq32);
1822 fscal = _mm_andnot_ps(dummy_mask,fscal);
1824 /* Update vectorial force */
1825 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1826 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1827 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1829 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1830 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1831 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1833 /**************************
1834 * CALCULATE INTERACTIONS *
1835 **************************/
1837 /* COULOMB ELECTROSTATICS */
1838 velec = _mm_mul_ps(qq33,rinv33);
1839 felec = _mm_mul_ps(velec,rinvsq33);
1843 fscal = _mm_andnot_ps(dummy_mask,fscal);
1845 /* Update vectorial force */
1846 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1847 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1848 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1850 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1851 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1852 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1854 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1855 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1856 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1857 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1859 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1860 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1861 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1863 /* Inner loop uses 325 flops */
1866 /* End of innermost loop */
1868 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1869 f+i_coord_offset,fshift+i_shift_offset);
1871 /* Increment number of inner iterations */
1872 inneriter += j_index_end - j_index_start;
1874 /* Outer loop uses 24 flops */
1877 /* Increment number of outer iterations */
1880 /* Update outer/inner flops */
1882 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*325);