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_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJSh_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 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
97 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
99 __m128 dummy_mask,cutoff_mask;
100 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
101 __m128 one = _mm_set1_ps(1.0);
102 __m128 two = _mm_set1_ps(2.0);
108 jindex = nlist->jindex;
110 shiftidx = nlist->shift;
112 shiftvec = fr->shift_vec[0];
113 fshift = fr->fshift[0];
114 facel = _mm_set1_ps(fr->ic->epsfac);
115 charge = mdatoms->chargeA;
116 nvdwtype = fr->ntype;
118 vdwtype = mdatoms->typeA;
120 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
121 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
122 beta2 = _mm_mul_ps(beta,beta);
123 beta3 = _mm_mul_ps(beta,beta2);
124 ewtab = fr->ic->tabq_coul_FDV0;
125 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
126 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
128 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
129 rcutoff_scalar = fr->ic->rcoulomb;
130 rcutoff = _mm_set1_ps(rcutoff_scalar);
131 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
133 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
134 rvdw = _mm_set1_ps(fr->ic->rvdw);
136 /* Avoid stupid compiler warnings */
137 jnrA = jnrB = jnrC = jnrD = 0;
146 for(iidx=0;iidx<4*DIM;iidx++)
151 /* Start outer loop over neighborlists */
152 for(iidx=0; iidx<nri; iidx++)
154 /* Load shift vector for this list */
155 i_shift_offset = DIM*shiftidx[iidx];
157 /* Load limits for loop over neighbors */
158 j_index_start = jindex[iidx];
159 j_index_end = jindex[iidx+1];
161 /* Get outer coordinate index */
163 i_coord_offset = DIM*inr;
165 /* Load i particle coords and add shift vector */
166 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
168 fix0 = _mm_setzero_ps();
169 fiy0 = _mm_setzero_ps();
170 fiz0 = _mm_setzero_ps();
172 /* Load parameters for i particles */
173 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
174 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
176 /* Reset potential sums */
177 velecsum = _mm_setzero_ps();
178 vvdwsum = _mm_setzero_ps();
180 /* Start inner kernel loop */
181 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
184 /* Get j neighbor index, and coordinate index */
189 j_coord_offsetA = DIM*jnrA;
190 j_coord_offsetB = DIM*jnrB;
191 j_coord_offsetC = DIM*jnrC;
192 j_coord_offsetD = DIM*jnrD;
194 /* load j atom coordinates */
195 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196 x+j_coord_offsetC,x+j_coord_offsetD,
199 /* Calculate displacement vector */
200 dx00 = _mm_sub_ps(ix0,jx0);
201 dy00 = _mm_sub_ps(iy0,jy0);
202 dz00 = _mm_sub_ps(iz0,jz0);
204 /* Calculate squared distance and things based on it */
205 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
207 rinv00 = avx128fma_invsqrt_f(rsq00);
209 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
211 /* Load parameters for j particles */
212 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
213 charge+jnrC+0,charge+jnrD+0);
214 vdwjidx0A = 2*vdwtype[jnrA+0];
215 vdwjidx0B = 2*vdwtype[jnrB+0];
216 vdwjidx0C = 2*vdwtype[jnrC+0];
217 vdwjidx0D = 2*vdwtype[jnrD+0];
219 /**************************
220 * CALCULATE INTERACTIONS *
221 **************************/
223 if (gmx_mm_any_lt(rsq00,rcutoff2))
226 r00 = _mm_mul_ps(rsq00,rinv00);
228 /* Compute parameters for interactions between i and j atoms */
229 qq00 = _mm_mul_ps(iq0,jq0);
230 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
231 vdwparam+vdwioffset0+vdwjidx0B,
232 vdwparam+vdwioffset0+vdwjidx0C,
233 vdwparam+vdwioffset0+vdwjidx0D,
236 /* EWALD ELECTROSTATICS */
238 /* Analytical PME correction */
239 zeta2 = _mm_mul_ps(beta2,rsq00);
240 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
241 pmecorrF = avx128fma_pmecorrF_f(zeta2);
242 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
243 felec = _mm_mul_ps(qq00,felec);
244 pmecorrV = avx128fma_pmecorrV_f(zeta2);
245 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
246 velec = _mm_mul_ps(qq00,velec);
248 /* LENNARD-JONES DISPERSION/REPULSION */
250 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
251 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
252 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
253 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
254 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
255 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
257 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
259 /* Update potential sum for this i atom from the interaction with this j atom. */
260 velec = _mm_and_ps(velec,cutoff_mask);
261 velecsum = _mm_add_ps(velecsum,velec);
262 vvdw = _mm_and_ps(vvdw,cutoff_mask);
263 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
265 fscal = _mm_add_ps(felec,fvdw);
267 fscal = _mm_and_ps(fscal,cutoff_mask);
269 /* Update vectorial force */
270 fix0 = _mm_macc_ps(dx00,fscal,fix0);
271 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
272 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
274 fjptrA = f+j_coord_offsetA;
275 fjptrB = f+j_coord_offsetB;
276 fjptrC = f+j_coord_offsetC;
277 fjptrD = f+j_coord_offsetD;
278 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
279 _mm_mul_ps(dx00,fscal),
280 _mm_mul_ps(dy00,fscal),
281 _mm_mul_ps(dz00,fscal));
285 /* Inner loop uses 51 flops */
291 /* Get j neighbor index, and coordinate index */
292 jnrlistA = jjnr[jidx];
293 jnrlistB = jjnr[jidx+1];
294 jnrlistC = jjnr[jidx+2];
295 jnrlistD = jjnr[jidx+3];
296 /* Sign of each element will be negative for non-real atoms.
297 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
298 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
300 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
301 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
302 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
303 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
304 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
305 j_coord_offsetA = DIM*jnrA;
306 j_coord_offsetB = DIM*jnrB;
307 j_coord_offsetC = DIM*jnrC;
308 j_coord_offsetD = DIM*jnrD;
310 /* load j atom coordinates */
311 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
312 x+j_coord_offsetC,x+j_coord_offsetD,
315 /* Calculate displacement vector */
316 dx00 = _mm_sub_ps(ix0,jx0);
317 dy00 = _mm_sub_ps(iy0,jy0);
318 dz00 = _mm_sub_ps(iz0,jz0);
320 /* Calculate squared distance and things based on it */
321 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
323 rinv00 = avx128fma_invsqrt_f(rsq00);
325 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
327 /* Load parameters for j particles */
328 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
329 charge+jnrC+0,charge+jnrD+0);
330 vdwjidx0A = 2*vdwtype[jnrA+0];
331 vdwjidx0B = 2*vdwtype[jnrB+0];
332 vdwjidx0C = 2*vdwtype[jnrC+0];
333 vdwjidx0D = 2*vdwtype[jnrD+0];
335 /**************************
336 * CALCULATE INTERACTIONS *
337 **************************/
339 if (gmx_mm_any_lt(rsq00,rcutoff2))
342 r00 = _mm_mul_ps(rsq00,rinv00);
343 r00 = _mm_andnot_ps(dummy_mask,r00);
345 /* Compute parameters for interactions between i and j atoms */
346 qq00 = _mm_mul_ps(iq0,jq0);
347 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
348 vdwparam+vdwioffset0+vdwjidx0B,
349 vdwparam+vdwioffset0+vdwjidx0C,
350 vdwparam+vdwioffset0+vdwjidx0D,
353 /* EWALD ELECTROSTATICS */
355 /* Analytical PME correction */
356 zeta2 = _mm_mul_ps(beta2,rsq00);
357 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
358 pmecorrF = avx128fma_pmecorrF_f(zeta2);
359 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
360 felec = _mm_mul_ps(qq00,felec);
361 pmecorrV = avx128fma_pmecorrV_f(zeta2);
362 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
363 velec = _mm_mul_ps(qq00,velec);
365 /* LENNARD-JONES DISPERSION/REPULSION */
367 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
368 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
369 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
370 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
371 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
372 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
374 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
376 /* Update potential sum for this i atom from the interaction with this j atom. */
377 velec = _mm_and_ps(velec,cutoff_mask);
378 velec = _mm_andnot_ps(dummy_mask,velec);
379 velecsum = _mm_add_ps(velecsum,velec);
380 vvdw = _mm_and_ps(vvdw,cutoff_mask);
381 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
382 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
384 fscal = _mm_add_ps(felec,fvdw);
386 fscal = _mm_and_ps(fscal,cutoff_mask);
388 fscal = _mm_andnot_ps(dummy_mask,fscal);
390 /* Update vectorial force */
391 fix0 = _mm_macc_ps(dx00,fscal,fix0);
392 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
393 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
395 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
396 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
397 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
398 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
399 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
400 _mm_mul_ps(dx00,fscal),
401 _mm_mul_ps(dy00,fscal),
402 _mm_mul_ps(dz00,fscal));
406 /* Inner loop uses 52 flops */
409 /* End of innermost loop */
411 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
412 f+i_coord_offset,fshift+i_shift_offset);
415 /* Update potential energies */
416 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
417 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
419 /* Increment number of inner iterations */
420 inneriter += j_index_end - j_index_start;
422 /* Outer loop uses 9 flops */
425 /* Increment number of outer iterations */
428 /* Update outer/inner flops */
430 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*52);
433 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_single
434 * Electrostatics interaction: Ewald
435 * VdW interaction: LennardJones
436 * Geometry: Particle-Particle
437 * Calculate force/pot: Force
440 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_single
441 (t_nblist * gmx_restrict nlist,
442 rvec * gmx_restrict xx,
443 rvec * gmx_restrict ff,
444 struct t_forcerec * gmx_restrict fr,
445 t_mdatoms * gmx_restrict mdatoms,
446 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
447 t_nrnb * gmx_restrict nrnb)
449 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
450 * just 0 for non-waters.
451 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
452 * jnr indices corresponding to data put in the four positions in the SIMD register.
454 int i_shift_offset,i_coord_offset,outeriter,inneriter;
455 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
456 int jnrA,jnrB,jnrC,jnrD;
457 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
458 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
459 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
461 real *shiftvec,*fshift,*x,*f;
462 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
464 __m128 fscal,rcutoff,rcutoff2,jidxall;
466 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
467 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
468 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
469 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
470 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
473 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
476 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
477 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
479 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
480 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
482 __m128 dummy_mask,cutoff_mask;
483 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
484 __m128 one = _mm_set1_ps(1.0);
485 __m128 two = _mm_set1_ps(2.0);
491 jindex = nlist->jindex;
493 shiftidx = nlist->shift;
495 shiftvec = fr->shift_vec[0];
496 fshift = fr->fshift[0];
497 facel = _mm_set1_ps(fr->ic->epsfac);
498 charge = mdatoms->chargeA;
499 nvdwtype = fr->ntype;
501 vdwtype = mdatoms->typeA;
503 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
504 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
505 beta2 = _mm_mul_ps(beta,beta);
506 beta3 = _mm_mul_ps(beta,beta2);
507 ewtab = fr->ic->tabq_coul_F;
508 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
509 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
511 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
512 rcutoff_scalar = fr->ic->rcoulomb;
513 rcutoff = _mm_set1_ps(rcutoff_scalar);
514 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
516 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
517 rvdw = _mm_set1_ps(fr->ic->rvdw);
519 /* Avoid stupid compiler warnings */
520 jnrA = jnrB = jnrC = jnrD = 0;
529 for(iidx=0;iidx<4*DIM;iidx++)
534 /* Start outer loop over neighborlists */
535 for(iidx=0; iidx<nri; iidx++)
537 /* Load shift vector for this list */
538 i_shift_offset = DIM*shiftidx[iidx];
540 /* Load limits for loop over neighbors */
541 j_index_start = jindex[iidx];
542 j_index_end = jindex[iidx+1];
544 /* Get outer coordinate index */
546 i_coord_offset = DIM*inr;
548 /* Load i particle coords and add shift vector */
549 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
551 fix0 = _mm_setzero_ps();
552 fiy0 = _mm_setzero_ps();
553 fiz0 = _mm_setzero_ps();
555 /* Load parameters for i particles */
556 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
557 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
559 /* Start inner kernel loop */
560 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
563 /* Get j neighbor index, and coordinate index */
568 j_coord_offsetA = DIM*jnrA;
569 j_coord_offsetB = DIM*jnrB;
570 j_coord_offsetC = DIM*jnrC;
571 j_coord_offsetD = DIM*jnrD;
573 /* load j atom coordinates */
574 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
575 x+j_coord_offsetC,x+j_coord_offsetD,
578 /* Calculate displacement vector */
579 dx00 = _mm_sub_ps(ix0,jx0);
580 dy00 = _mm_sub_ps(iy0,jy0);
581 dz00 = _mm_sub_ps(iz0,jz0);
583 /* Calculate squared distance and things based on it */
584 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
586 rinv00 = avx128fma_invsqrt_f(rsq00);
588 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
590 /* Load parameters for j particles */
591 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
592 charge+jnrC+0,charge+jnrD+0);
593 vdwjidx0A = 2*vdwtype[jnrA+0];
594 vdwjidx0B = 2*vdwtype[jnrB+0];
595 vdwjidx0C = 2*vdwtype[jnrC+0];
596 vdwjidx0D = 2*vdwtype[jnrD+0];
598 /**************************
599 * CALCULATE INTERACTIONS *
600 **************************/
602 if (gmx_mm_any_lt(rsq00,rcutoff2))
605 r00 = _mm_mul_ps(rsq00,rinv00);
607 /* Compute parameters for interactions between i and j atoms */
608 qq00 = _mm_mul_ps(iq0,jq0);
609 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
610 vdwparam+vdwioffset0+vdwjidx0B,
611 vdwparam+vdwioffset0+vdwjidx0C,
612 vdwparam+vdwioffset0+vdwjidx0D,
615 /* EWALD ELECTROSTATICS */
617 /* Analytical PME correction */
618 zeta2 = _mm_mul_ps(beta2,rsq00);
619 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
620 pmecorrF = avx128fma_pmecorrF_f(zeta2);
621 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
622 felec = _mm_mul_ps(qq00,felec);
624 /* LENNARD-JONES DISPERSION/REPULSION */
626 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
627 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
629 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
631 fscal = _mm_add_ps(felec,fvdw);
633 fscal = _mm_and_ps(fscal,cutoff_mask);
635 /* Update vectorial force */
636 fix0 = _mm_macc_ps(dx00,fscal,fix0);
637 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
638 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
640 fjptrA = f+j_coord_offsetA;
641 fjptrB = f+j_coord_offsetB;
642 fjptrC = f+j_coord_offsetC;
643 fjptrD = f+j_coord_offsetD;
644 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
645 _mm_mul_ps(dx00,fscal),
646 _mm_mul_ps(dy00,fscal),
647 _mm_mul_ps(dz00,fscal));
651 /* Inner loop uses 38 flops */
657 /* Get j neighbor index, and coordinate index */
658 jnrlistA = jjnr[jidx];
659 jnrlistB = jjnr[jidx+1];
660 jnrlistC = jjnr[jidx+2];
661 jnrlistD = jjnr[jidx+3];
662 /* Sign of each element will be negative for non-real atoms.
663 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
664 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
666 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
667 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
668 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
669 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
670 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
671 j_coord_offsetA = DIM*jnrA;
672 j_coord_offsetB = DIM*jnrB;
673 j_coord_offsetC = DIM*jnrC;
674 j_coord_offsetD = DIM*jnrD;
676 /* load j atom coordinates */
677 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
678 x+j_coord_offsetC,x+j_coord_offsetD,
681 /* Calculate displacement vector */
682 dx00 = _mm_sub_ps(ix0,jx0);
683 dy00 = _mm_sub_ps(iy0,jy0);
684 dz00 = _mm_sub_ps(iz0,jz0);
686 /* Calculate squared distance and things based on it */
687 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
689 rinv00 = avx128fma_invsqrt_f(rsq00);
691 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
693 /* Load parameters for j particles */
694 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
695 charge+jnrC+0,charge+jnrD+0);
696 vdwjidx0A = 2*vdwtype[jnrA+0];
697 vdwjidx0B = 2*vdwtype[jnrB+0];
698 vdwjidx0C = 2*vdwtype[jnrC+0];
699 vdwjidx0D = 2*vdwtype[jnrD+0];
701 /**************************
702 * CALCULATE INTERACTIONS *
703 **************************/
705 if (gmx_mm_any_lt(rsq00,rcutoff2))
708 r00 = _mm_mul_ps(rsq00,rinv00);
709 r00 = _mm_andnot_ps(dummy_mask,r00);
711 /* Compute parameters for interactions between i and j atoms */
712 qq00 = _mm_mul_ps(iq0,jq0);
713 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
714 vdwparam+vdwioffset0+vdwjidx0B,
715 vdwparam+vdwioffset0+vdwjidx0C,
716 vdwparam+vdwioffset0+vdwjidx0D,
719 /* EWALD ELECTROSTATICS */
721 /* Analytical PME correction */
722 zeta2 = _mm_mul_ps(beta2,rsq00);
723 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
724 pmecorrF = avx128fma_pmecorrF_f(zeta2);
725 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
726 felec = _mm_mul_ps(qq00,felec);
728 /* LENNARD-JONES DISPERSION/REPULSION */
730 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
731 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
733 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
735 fscal = _mm_add_ps(felec,fvdw);
737 fscal = _mm_and_ps(fscal,cutoff_mask);
739 fscal = _mm_andnot_ps(dummy_mask,fscal);
741 /* Update vectorial force */
742 fix0 = _mm_macc_ps(dx00,fscal,fix0);
743 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
744 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
746 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
747 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
748 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
749 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
750 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
751 _mm_mul_ps(dx00,fscal),
752 _mm_mul_ps(dy00,fscal),
753 _mm_mul_ps(dz00,fscal));
757 /* Inner loop uses 39 flops */
760 /* End of innermost loop */
762 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
763 f+i_coord_offset,fshift+i_shift_offset);
765 /* Increment number of inner iterations */
766 inneriter += j_index_end - j_index_start;
768 /* Outer loop uses 7 flops */
771 /* Increment number of outer iterations */
774 /* Update outer/inner flops */
776 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*39);