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_ElecEw_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: CubicSplineTable
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwCSTab_GeomP1P1_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;
84 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
93 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
94 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
96 __m128i ifour = _mm_set1_epi32(4);
97 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
100 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
101 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
103 __m128 dummy_mask,cutoff_mask;
104 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
105 __m128 one = _mm_set1_ps(1.0);
106 __m128 two = _mm_set1_ps(2.0);
112 jindex = nlist->jindex;
114 shiftidx = nlist->shift;
116 shiftvec = fr->shift_vec[0];
117 fshift = fr->fshift[0];
118 facel = _mm_set1_ps(fr->ic->epsfac);
119 charge = mdatoms->chargeA;
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 vftab = kernel_data->table_vdw->data;
125 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
127 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
128 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
129 beta2 = _mm_mul_ps(beta,beta);
130 beta3 = _mm_mul_ps(beta,beta2);
131 ewtab = fr->ic->tabq_coul_FDV0;
132 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
133 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
135 /* Avoid stupid compiler warnings */
136 jnrA = jnrB = jnrC = jnrD = 0;
145 for(iidx=0;iidx<4*DIM;iidx++)
150 /* Start outer loop over neighborlists */
151 for(iidx=0; iidx<nri; iidx++)
153 /* Load shift vector for this list */
154 i_shift_offset = DIM*shiftidx[iidx];
156 /* Load limits for loop over neighbors */
157 j_index_start = jindex[iidx];
158 j_index_end = jindex[iidx+1];
160 /* Get outer coordinate index */
162 i_coord_offset = DIM*inr;
164 /* Load i particle coords and add shift vector */
165 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
167 fix0 = _mm_setzero_ps();
168 fiy0 = _mm_setzero_ps();
169 fiz0 = _mm_setzero_ps();
171 /* Load parameters for i particles */
172 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
173 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
175 /* Reset potential sums */
176 velecsum = _mm_setzero_ps();
177 vvdwsum = _mm_setzero_ps();
179 /* Start inner kernel loop */
180 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
183 /* Get j neighbor index, and coordinate index */
188 j_coord_offsetA = DIM*jnrA;
189 j_coord_offsetB = DIM*jnrB;
190 j_coord_offsetC = DIM*jnrC;
191 j_coord_offsetD = DIM*jnrD;
193 /* load j atom coordinates */
194 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
195 x+j_coord_offsetC,x+j_coord_offsetD,
198 /* Calculate displacement vector */
199 dx00 = _mm_sub_ps(ix0,jx0);
200 dy00 = _mm_sub_ps(iy0,jy0);
201 dz00 = _mm_sub_ps(iz0,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
206 rinv00 = avx128fma_invsqrt_f(rsq00);
208 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
210 /* Load parameters for j particles */
211 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
212 charge+jnrC+0,charge+jnrD+0);
213 vdwjidx0A = 2*vdwtype[jnrA+0];
214 vdwjidx0B = 2*vdwtype[jnrB+0];
215 vdwjidx0C = 2*vdwtype[jnrC+0];
216 vdwjidx0D = 2*vdwtype[jnrD+0];
218 /**************************
219 * CALCULATE INTERACTIONS *
220 **************************/
222 r00 = _mm_mul_ps(rsq00,rinv00);
224 /* Compute parameters for interactions between i and j atoms */
225 qq00 = _mm_mul_ps(iq0,jq0);
226 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
227 vdwparam+vdwioffset0+vdwjidx0B,
228 vdwparam+vdwioffset0+vdwjidx0C,
229 vdwparam+vdwioffset0+vdwjidx0D,
232 /* Calculate table index by multiplying r with table scale and truncate to integer */
233 rt = _mm_mul_ps(r00,vftabscale);
234 vfitab = _mm_cvttps_epi32(rt);
236 vfeps = _mm_frcz_ps(rt);
238 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
240 twovfeps = _mm_add_ps(vfeps,vfeps);
241 vfitab = _mm_slli_epi32(vfitab,3);
243 /* EWALD ELECTROSTATICS */
245 /* Analytical PME correction */
246 zeta2 = _mm_mul_ps(beta2,rsq00);
247 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
248 pmecorrF = avx128fma_pmecorrF_f(zeta2);
249 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
250 felec = _mm_mul_ps(qq00,felec);
251 pmecorrV = avx128fma_pmecorrV_f(zeta2);
252 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
253 velec = _mm_mul_ps(qq00,velec);
255 /* CUBIC SPLINE TABLE DISPERSION */
256 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
257 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
258 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
259 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
260 _MM_TRANSPOSE4_PS(Y,F,G,H);
261 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
262 VV = _mm_macc_ps(vfeps,Fp,Y);
263 vvdw6 = _mm_mul_ps(c6_00,VV);
264 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
265 fvdw6 = _mm_mul_ps(c6_00,FF);
267 /* CUBIC SPLINE TABLE REPULSION */
268 vfitab = _mm_add_epi32(vfitab,ifour);
269 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
270 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
271 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
272 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
273 _MM_TRANSPOSE4_PS(Y,F,G,H);
274 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
275 VV = _mm_macc_ps(vfeps,Fp,Y);
276 vvdw12 = _mm_mul_ps(c12_00,VV);
277 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
278 fvdw12 = _mm_mul_ps(c12_00,FF);
279 vvdw = _mm_add_ps(vvdw12,vvdw6);
280 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
282 /* Update potential sum for this i atom from the interaction with this j atom. */
283 velecsum = _mm_add_ps(velecsum,velec);
284 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
286 fscal = _mm_add_ps(felec,fvdw);
288 /* Update vectorial force */
289 fix0 = _mm_macc_ps(dx00,fscal,fix0);
290 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
291 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
293 fjptrA = f+j_coord_offsetA;
294 fjptrB = f+j_coord_offsetB;
295 fjptrC = f+j_coord_offsetC;
296 fjptrD = f+j_coord_offsetD;
297 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
298 _mm_mul_ps(dx00,fscal),
299 _mm_mul_ps(dy00,fscal),
300 _mm_mul_ps(dz00,fscal));
302 /* Inner loop uses 63 flops */
308 /* Get j neighbor index, and coordinate index */
309 jnrlistA = jjnr[jidx];
310 jnrlistB = jjnr[jidx+1];
311 jnrlistC = jjnr[jidx+2];
312 jnrlistD = jjnr[jidx+3];
313 /* Sign of each element will be negative for non-real atoms.
314 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
315 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
317 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
318 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
319 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
320 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
321 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
322 j_coord_offsetA = DIM*jnrA;
323 j_coord_offsetB = DIM*jnrB;
324 j_coord_offsetC = DIM*jnrC;
325 j_coord_offsetD = DIM*jnrD;
327 /* load j atom coordinates */
328 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
329 x+j_coord_offsetC,x+j_coord_offsetD,
332 /* Calculate displacement vector */
333 dx00 = _mm_sub_ps(ix0,jx0);
334 dy00 = _mm_sub_ps(iy0,jy0);
335 dz00 = _mm_sub_ps(iz0,jz0);
337 /* Calculate squared distance and things based on it */
338 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
340 rinv00 = avx128fma_invsqrt_f(rsq00);
342 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
344 /* Load parameters for j particles */
345 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
346 charge+jnrC+0,charge+jnrD+0);
347 vdwjidx0A = 2*vdwtype[jnrA+0];
348 vdwjidx0B = 2*vdwtype[jnrB+0];
349 vdwjidx0C = 2*vdwtype[jnrC+0];
350 vdwjidx0D = 2*vdwtype[jnrD+0];
352 /**************************
353 * CALCULATE INTERACTIONS *
354 **************************/
356 r00 = _mm_mul_ps(rsq00,rinv00);
357 r00 = _mm_andnot_ps(dummy_mask,r00);
359 /* Compute parameters for interactions between i and j atoms */
360 qq00 = _mm_mul_ps(iq0,jq0);
361 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
362 vdwparam+vdwioffset0+vdwjidx0B,
363 vdwparam+vdwioffset0+vdwjidx0C,
364 vdwparam+vdwioffset0+vdwjidx0D,
367 /* Calculate table index by multiplying r with table scale and truncate to integer */
368 rt = _mm_mul_ps(r00,vftabscale);
369 vfitab = _mm_cvttps_epi32(rt);
371 vfeps = _mm_frcz_ps(rt);
373 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
375 twovfeps = _mm_add_ps(vfeps,vfeps);
376 vfitab = _mm_slli_epi32(vfitab,3);
378 /* EWALD ELECTROSTATICS */
380 /* Analytical PME correction */
381 zeta2 = _mm_mul_ps(beta2,rsq00);
382 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
383 pmecorrF = avx128fma_pmecorrF_f(zeta2);
384 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
385 felec = _mm_mul_ps(qq00,felec);
386 pmecorrV = avx128fma_pmecorrV_f(zeta2);
387 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
388 velec = _mm_mul_ps(qq00,velec);
390 /* CUBIC SPLINE TABLE DISPERSION */
391 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
392 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
393 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
394 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
395 _MM_TRANSPOSE4_PS(Y,F,G,H);
396 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
397 VV = _mm_macc_ps(vfeps,Fp,Y);
398 vvdw6 = _mm_mul_ps(c6_00,VV);
399 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
400 fvdw6 = _mm_mul_ps(c6_00,FF);
402 /* CUBIC SPLINE TABLE REPULSION */
403 vfitab = _mm_add_epi32(vfitab,ifour);
404 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
405 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
406 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
407 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
408 _MM_TRANSPOSE4_PS(Y,F,G,H);
409 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
410 VV = _mm_macc_ps(vfeps,Fp,Y);
411 vvdw12 = _mm_mul_ps(c12_00,VV);
412 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
413 fvdw12 = _mm_mul_ps(c12_00,FF);
414 vvdw = _mm_add_ps(vvdw12,vvdw6);
415 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
417 /* Update potential sum for this i atom from the interaction with this j atom. */
418 velec = _mm_andnot_ps(dummy_mask,velec);
419 velecsum = _mm_add_ps(velecsum,velec);
420 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
421 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
423 fscal = _mm_add_ps(felec,fvdw);
425 fscal = _mm_andnot_ps(dummy_mask,fscal);
427 /* Update vectorial force */
428 fix0 = _mm_macc_ps(dx00,fscal,fix0);
429 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
430 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
432 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
433 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
434 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
435 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
436 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
437 _mm_mul_ps(dx00,fscal),
438 _mm_mul_ps(dy00,fscal),
439 _mm_mul_ps(dz00,fscal));
441 /* Inner loop uses 64 flops */
444 /* End of innermost loop */
446 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
447 f+i_coord_offset,fshift+i_shift_offset);
450 /* Update potential energies */
451 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
452 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
454 /* Increment number of inner iterations */
455 inneriter += j_index_end - j_index_start;
457 /* Outer loop uses 9 flops */
460 /* Increment number of outer iterations */
463 /* Update outer/inner flops */
465 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*64);
468 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_avx_128_fma_single
469 * Electrostatics interaction: Ewald
470 * VdW interaction: CubicSplineTable
471 * Geometry: Particle-Particle
472 * Calculate force/pot: Force
475 nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_avx_128_fma_single
476 (t_nblist * gmx_restrict nlist,
477 rvec * gmx_restrict xx,
478 rvec * gmx_restrict ff,
479 struct t_forcerec * gmx_restrict fr,
480 t_mdatoms * gmx_restrict mdatoms,
481 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
482 t_nrnb * gmx_restrict nrnb)
484 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
485 * just 0 for non-waters.
486 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
487 * jnr indices corresponding to data put in the four positions in the SIMD register.
489 int i_shift_offset,i_coord_offset,outeriter,inneriter;
490 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
491 int jnrA,jnrB,jnrC,jnrD;
492 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
493 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
494 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
496 real *shiftvec,*fshift,*x,*f;
497 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
499 __m128 fscal,rcutoff,rcutoff2,jidxall;
501 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
502 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
503 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
504 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
505 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
508 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
511 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
512 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
514 __m128i ifour = _mm_set1_epi32(4);
515 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
518 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
519 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
521 __m128 dummy_mask,cutoff_mask;
522 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
523 __m128 one = _mm_set1_ps(1.0);
524 __m128 two = _mm_set1_ps(2.0);
530 jindex = nlist->jindex;
532 shiftidx = nlist->shift;
534 shiftvec = fr->shift_vec[0];
535 fshift = fr->fshift[0];
536 facel = _mm_set1_ps(fr->ic->epsfac);
537 charge = mdatoms->chargeA;
538 nvdwtype = fr->ntype;
540 vdwtype = mdatoms->typeA;
542 vftab = kernel_data->table_vdw->data;
543 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
545 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
546 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
547 beta2 = _mm_mul_ps(beta,beta);
548 beta3 = _mm_mul_ps(beta,beta2);
549 ewtab = fr->ic->tabq_coul_F;
550 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
551 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
553 /* Avoid stupid compiler warnings */
554 jnrA = jnrB = jnrC = jnrD = 0;
563 for(iidx=0;iidx<4*DIM;iidx++)
568 /* Start outer loop over neighborlists */
569 for(iidx=0; iidx<nri; iidx++)
571 /* Load shift vector for this list */
572 i_shift_offset = DIM*shiftidx[iidx];
574 /* Load limits for loop over neighbors */
575 j_index_start = jindex[iidx];
576 j_index_end = jindex[iidx+1];
578 /* Get outer coordinate index */
580 i_coord_offset = DIM*inr;
582 /* Load i particle coords and add shift vector */
583 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
585 fix0 = _mm_setzero_ps();
586 fiy0 = _mm_setzero_ps();
587 fiz0 = _mm_setzero_ps();
589 /* Load parameters for i particles */
590 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
591 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
593 /* Start inner kernel loop */
594 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
597 /* Get j neighbor index, and coordinate index */
602 j_coord_offsetA = DIM*jnrA;
603 j_coord_offsetB = DIM*jnrB;
604 j_coord_offsetC = DIM*jnrC;
605 j_coord_offsetD = DIM*jnrD;
607 /* load j atom coordinates */
608 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
609 x+j_coord_offsetC,x+j_coord_offsetD,
612 /* Calculate displacement vector */
613 dx00 = _mm_sub_ps(ix0,jx0);
614 dy00 = _mm_sub_ps(iy0,jy0);
615 dz00 = _mm_sub_ps(iz0,jz0);
617 /* Calculate squared distance and things based on it */
618 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
620 rinv00 = avx128fma_invsqrt_f(rsq00);
622 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
624 /* Load parameters for j particles */
625 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
626 charge+jnrC+0,charge+jnrD+0);
627 vdwjidx0A = 2*vdwtype[jnrA+0];
628 vdwjidx0B = 2*vdwtype[jnrB+0];
629 vdwjidx0C = 2*vdwtype[jnrC+0];
630 vdwjidx0D = 2*vdwtype[jnrD+0];
632 /**************************
633 * CALCULATE INTERACTIONS *
634 **************************/
636 r00 = _mm_mul_ps(rsq00,rinv00);
638 /* Compute parameters for interactions between i and j atoms */
639 qq00 = _mm_mul_ps(iq0,jq0);
640 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
641 vdwparam+vdwioffset0+vdwjidx0B,
642 vdwparam+vdwioffset0+vdwjidx0C,
643 vdwparam+vdwioffset0+vdwjidx0D,
646 /* Calculate table index by multiplying r with table scale and truncate to integer */
647 rt = _mm_mul_ps(r00,vftabscale);
648 vfitab = _mm_cvttps_epi32(rt);
650 vfeps = _mm_frcz_ps(rt);
652 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
654 twovfeps = _mm_add_ps(vfeps,vfeps);
655 vfitab = _mm_slli_epi32(vfitab,3);
657 /* EWALD ELECTROSTATICS */
659 /* Analytical PME correction */
660 zeta2 = _mm_mul_ps(beta2,rsq00);
661 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
662 pmecorrF = avx128fma_pmecorrF_f(zeta2);
663 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
664 felec = _mm_mul_ps(qq00,felec);
666 /* CUBIC SPLINE TABLE DISPERSION */
667 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
668 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
669 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
670 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
671 _MM_TRANSPOSE4_PS(Y,F,G,H);
672 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
673 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
674 fvdw6 = _mm_mul_ps(c6_00,FF);
676 /* CUBIC SPLINE TABLE REPULSION */
677 vfitab = _mm_add_epi32(vfitab,ifour);
678 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
679 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
680 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
681 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
682 _MM_TRANSPOSE4_PS(Y,F,G,H);
683 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
684 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
685 fvdw12 = _mm_mul_ps(c12_00,FF);
686 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
688 fscal = _mm_add_ps(felec,fvdw);
690 /* Update vectorial force */
691 fix0 = _mm_macc_ps(dx00,fscal,fix0);
692 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
693 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
695 fjptrA = f+j_coord_offsetA;
696 fjptrB = f+j_coord_offsetB;
697 fjptrC = f+j_coord_offsetC;
698 fjptrD = f+j_coord_offsetD;
699 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
700 _mm_mul_ps(dx00,fscal),
701 _mm_mul_ps(dy00,fscal),
702 _mm_mul_ps(dz00,fscal));
704 /* Inner loop uses 54 flops */
710 /* Get j neighbor index, and coordinate index */
711 jnrlistA = jjnr[jidx];
712 jnrlistB = jjnr[jidx+1];
713 jnrlistC = jjnr[jidx+2];
714 jnrlistD = jjnr[jidx+3];
715 /* Sign of each element will be negative for non-real atoms.
716 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
717 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
719 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
720 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
721 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
722 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
723 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
724 j_coord_offsetA = DIM*jnrA;
725 j_coord_offsetB = DIM*jnrB;
726 j_coord_offsetC = DIM*jnrC;
727 j_coord_offsetD = DIM*jnrD;
729 /* load j atom coordinates */
730 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
731 x+j_coord_offsetC,x+j_coord_offsetD,
734 /* Calculate displacement vector */
735 dx00 = _mm_sub_ps(ix0,jx0);
736 dy00 = _mm_sub_ps(iy0,jy0);
737 dz00 = _mm_sub_ps(iz0,jz0);
739 /* Calculate squared distance and things based on it */
740 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
742 rinv00 = avx128fma_invsqrt_f(rsq00);
744 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
746 /* Load parameters for j particles */
747 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
748 charge+jnrC+0,charge+jnrD+0);
749 vdwjidx0A = 2*vdwtype[jnrA+0];
750 vdwjidx0B = 2*vdwtype[jnrB+0];
751 vdwjidx0C = 2*vdwtype[jnrC+0];
752 vdwjidx0D = 2*vdwtype[jnrD+0];
754 /**************************
755 * CALCULATE INTERACTIONS *
756 **************************/
758 r00 = _mm_mul_ps(rsq00,rinv00);
759 r00 = _mm_andnot_ps(dummy_mask,r00);
761 /* Compute parameters for interactions between i and j atoms */
762 qq00 = _mm_mul_ps(iq0,jq0);
763 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
764 vdwparam+vdwioffset0+vdwjidx0B,
765 vdwparam+vdwioffset0+vdwjidx0C,
766 vdwparam+vdwioffset0+vdwjidx0D,
769 /* Calculate table index by multiplying r with table scale and truncate to integer */
770 rt = _mm_mul_ps(r00,vftabscale);
771 vfitab = _mm_cvttps_epi32(rt);
773 vfeps = _mm_frcz_ps(rt);
775 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
777 twovfeps = _mm_add_ps(vfeps,vfeps);
778 vfitab = _mm_slli_epi32(vfitab,3);
780 /* EWALD ELECTROSTATICS */
782 /* Analytical PME correction */
783 zeta2 = _mm_mul_ps(beta2,rsq00);
784 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
785 pmecorrF = avx128fma_pmecorrF_f(zeta2);
786 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
787 felec = _mm_mul_ps(qq00,felec);
789 /* CUBIC SPLINE TABLE DISPERSION */
790 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
791 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
792 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
793 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
794 _MM_TRANSPOSE4_PS(Y,F,G,H);
795 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
796 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
797 fvdw6 = _mm_mul_ps(c6_00,FF);
799 /* CUBIC SPLINE TABLE REPULSION */
800 vfitab = _mm_add_epi32(vfitab,ifour);
801 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
802 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
803 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
804 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
805 _MM_TRANSPOSE4_PS(Y,F,G,H);
806 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
807 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
808 fvdw12 = _mm_mul_ps(c12_00,FF);
809 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
811 fscal = _mm_add_ps(felec,fvdw);
813 fscal = _mm_andnot_ps(dummy_mask,fscal);
815 /* Update vectorial force */
816 fix0 = _mm_macc_ps(dx00,fscal,fix0);
817 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
818 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
820 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
821 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
822 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
823 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
824 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
825 _mm_mul_ps(dx00,fscal),
826 _mm_mul_ps(dy00,fscal),
827 _mm_mul_ps(dz00,fscal));
829 /* Inner loop uses 55 flops */
832 /* End of innermost loop */
834 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
835 f+i_coord_offset,fshift+i_shift_offset);
837 /* Increment number of inner iterations */
838 inneriter += j_index_end - j_index_start;
840 /* Outer loop uses 7 flops */
843 /* Increment number of outer iterations */
846 /* Update outer/inner flops */
848 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*55);