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_ElecRFCut_VdwLJSh_GeomP1P1_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_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);
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->ic->epsfac);
111 charge = mdatoms->chargeA;
112 krf = _mm_set1_ps(fr->ic->k_rf);
113 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
114 crf = _mm_set1_ps(fr->ic->c_rf);
115 nvdwtype = fr->ntype;
117 vdwtype = mdatoms->typeA;
119 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120 rcutoff_scalar = fr->ic->rcoulomb;
121 rcutoff = _mm_set1_ps(rcutoff_scalar);
122 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
124 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
125 rvdw = _mm_set1_ps(fr->ic->rvdw);
127 /* Avoid stupid compiler warnings */
128 jnrA = jnrB = jnrC = jnrD = 0;
137 for(iidx=0;iidx<4*DIM;iidx++)
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
159 fix0 = _mm_setzero_ps();
160 fiy0 = _mm_setzero_ps();
161 fiz0 = _mm_setzero_ps();
163 /* Load parameters for i particles */
164 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
165 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
167 /* Reset potential sums */
168 velecsum = _mm_setzero_ps();
169 vvdwsum = _mm_setzero_ps();
171 /* Start inner kernel loop */
172 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
175 /* Get j neighbor index, and coordinate index */
180 j_coord_offsetA = DIM*jnrA;
181 j_coord_offsetB = DIM*jnrB;
182 j_coord_offsetC = DIM*jnrC;
183 j_coord_offsetD = DIM*jnrD;
185 /* load j atom coordinates */
186 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
187 x+j_coord_offsetC,x+j_coord_offsetD,
190 /* Calculate displacement vector */
191 dx00 = _mm_sub_ps(ix0,jx0);
192 dy00 = _mm_sub_ps(iy0,jy0);
193 dz00 = _mm_sub_ps(iz0,jz0);
195 /* Calculate squared distance and things based on it */
196 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
198 rinv00 = avx128fma_invsqrt_f(rsq00);
200 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
202 /* Load parameters for j particles */
203 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
204 charge+jnrC+0,charge+jnrD+0);
205 vdwjidx0A = 2*vdwtype[jnrA+0];
206 vdwjidx0B = 2*vdwtype[jnrB+0];
207 vdwjidx0C = 2*vdwtype[jnrC+0];
208 vdwjidx0D = 2*vdwtype[jnrD+0];
210 /**************************
211 * CALCULATE INTERACTIONS *
212 **************************/
214 if (gmx_mm_any_lt(rsq00,rcutoff2))
217 /* Compute parameters for interactions between i and j atoms */
218 qq00 = _mm_mul_ps(iq0,jq0);
219 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
220 vdwparam+vdwioffset0+vdwjidx0B,
221 vdwparam+vdwioffset0+vdwjidx0C,
222 vdwparam+vdwioffset0+vdwjidx0D,
225 /* REACTION-FIELD ELECTROSTATICS */
226 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
227 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
229 /* LENNARD-JONES DISPERSION/REPULSION */
231 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
232 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
233 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
234 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
235 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
236 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
238 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
240 /* Update potential sum for this i atom from the interaction with this j atom. */
241 velec = _mm_and_ps(velec,cutoff_mask);
242 velecsum = _mm_add_ps(velecsum,velec);
243 vvdw = _mm_and_ps(vvdw,cutoff_mask);
244 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
246 fscal = _mm_add_ps(felec,fvdw);
248 fscal = _mm_and_ps(fscal,cutoff_mask);
250 /* Update vectorial force */
251 fix0 = _mm_macc_ps(dx00,fscal,fix0);
252 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
253 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
255 fjptrA = f+j_coord_offsetA;
256 fjptrB = f+j_coord_offsetB;
257 fjptrC = f+j_coord_offsetC;
258 fjptrD = f+j_coord_offsetD;
259 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
260 _mm_mul_ps(dx00,fscal),
261 _mm_mul_ps(dy00,fscal),
262 _mm_mul_ps(dz00,fscal));
266 /* Inner loop uses 57 flops */
272 /* Get j neighbor index, and coordinate index */
273 jnrlistA = jjnr[jidx];
274 jnrlistB = jjnr[jidx+1];
275 jnrlistC = jjnr[jidx+2];
276 jnrlistD = jjnr[jidx+3];
277 /* Sign of each element will be negative for non-real atoms.
278 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
279 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
281 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
282 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
283 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
284 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
285 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
286 j_coord_offsetA = DIM*jnrA;
287 j_coord_offsetB = DIM*jnrB;
288 j_coord_offsetC = DIM*jnrC;
289 j_coord_offsetD = DIM*jnrD;
291 /* load j atom coordinates */
292 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
293 x+j_coord_offsetC,x+j_coord_offsetD,
296 /* Calculate displacement vector */
297 dx00 = _mm_sub_ps(ix0,jx0);
298 dy00 = _mm_sub_ps(iy0,jy0);
299 dz00 = _mm_sub_ps(iz0,jz0);
301 /* Calculate squared distance and things based on it */
302 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
304 rinv00 = avx128fma_invsqrt_f(rsq00);
306 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
308 /* Load parameters for j particles */
309 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
310 charge+jnrC+0,charge+jnrD+0);
311 vdwjidx0A = 2*vdwtype[jnrA+0];
312 vdwjidx0B = 2*vdwtype[jnrB+0];
313 vdwjidx0C = 2*vdwtype[jnrC+0];
314 vdwjidx0D = 2*vdwtype[jnrD+0];
316 /**************************
317 * CALCULATE INTERACTIONS *
318 **************************/
320 if (gmx_mm_any_lt(rsq00,rcutoff2))
323 /* Compute parameters for interactions between i and j atoms */
324 qq00 = _mm_mul_ps(iq0,jq0);
325 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
326 vdwparam+vdwioffset0+vdwjidx0B,
327 vdwparam+vdwioffset0+vdwjidx0C,
328 vdwparam+vdwioffset0+vdwjidx0D,
331 /* REACTION-FIELD ELECTROSTATICS */
332 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
333 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
335 /* LENNARD-JONES DISPERSION/REPULSION */
337 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
338 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
339 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
340 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
341 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
342 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
344 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
346 /* Update potential sum for this i atom from the interaction with this j atom. */
347 velec = _mm_and_ps(velec,cutoff_mask);
348 velec = _mm_andnot_ps(dummy_mask,velec);
349 velecsum = _mm_add_ps(velecsum,velec);
350 vvdw = _mm_and_ps(vvdw,cutoff_mask);
351 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
352 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
354 fscal = _mm_add_ps(felec,fvdw);
356 fscal = _mm_and_ps(fscal,cutoff_mask);
358 fscal = _mm_andnot_ps(dummy_mask,fscal);
360 /* Update vectorial force */
361 fix0 = _mm_macc_ps(dx00,fscal,fix0);
362 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
363 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
365 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
366 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
367 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
368 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
369 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
370 _mm_mul_ps(dx00,fscal),
371 _mm_mul_ps(dy00,fscal),
372 _mm_mul_ps(dz00,fscal));
376 /* Inner loop uses 57 flops */
379 /* End of innermost loop */
381 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
382 f+i_coord_offset,fshift+i_shift_offset);
385 /* Update potential energies */
386 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
387 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
389 /* Increment number of inner iterations */
390 inneriter += j_index_end - j_index_start;
392 /* Outer loop uses 9 flops */
395 /* Increment number of outer iterations */
398 /* Update outer/inner flops */
400 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*57);
403 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomP1P1_F_avx_128_fma_single
404 * Electrostatics interaction: ReactionField
405 * VdW interaction: LennardJones
406 * Geometry: Particle-Particle
407 * Calculate force/pot: Force
410 nb_kernel_ElecRFCut_VdwLJSh_GeomP1P1_F_avx_128_fma_single
411 (t_nblist * gmx_restrict nlist,
412 rvec * gmx_restrict xx,
413 rvec * gmx_restrict ff,
414 struct t_forcerec * gmx_restrict fr,
415 t_mdatoms * gmx_restrict mdatoms,
416 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
417 t_nrnb * gmx_restrict nrnb)
419 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
420 * just 0 for non-waters.
421 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
422 * jnr indices corresponding to data put in the four positions in the SIMD register.
424 int i_shift_offset,i_coord_offset,outeriter,inneriter;
425 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
426 int jnrA,jnrB,jnrC,jnrD;
427 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
428 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
429 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
431 real *shiftvec,*fshift,*x,*f;
432 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
434 __m128 fscal,rcutoff,rcutoff2,jidxall;
436 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
437 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
438 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
439 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
440 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
443 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
446 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
447 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
448 __m128 dummy_mask,cutoff_mask;
449 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
450 __m128 one = _mm_set1_ps(1.0);
451 __m128 two = _mm_set1_ps(2.0);
457 jindex = nlist->jindex;
459 shiftidx = nlist->shift;
461 shiftvec = fr->shift_vec[0];
462 fshift = fr->fshift[0];
463 facel = _mm_set1_ps(fr->ic->epsfac);
464 charge = mdatoms->chargeA;
465 krf = _mm_set1_ps(fr->ic->k_rf);
466 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
467 crf = _mm_set1_ps(fr->ic->c_rf);
468 nvdwtype = fr->ntype;
470 vdwtype = mdatoms->typeA;
472 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
473 rcutoff_scalar = fr->ic->rcoulomb;
474 rcutoff = _mm_set1_ps(rcutoff_scalar);
475 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
477 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
478 rvdw = _mm_set1_ps(fr->ic->rvdw);
480 /* Avoid stupid compiler warnings */
481 jnrA = jnrB = jnrC = jnrD = 0;
490 for(iidx=0;iidx<4*DIM;iidx++)
495 /* Start outer loop over neighborlists */
496 for(iidx=0; iidx<nri; iidx++)
498 /* Load shift vector for this list */
499 i_shift_offset = DIM*shiftidx[iidx];
501 /* Load limits for loop over neighbors */
502 j_index_start = jindex[iidx];
503 j_index_end = jindex[iidx+1];
505 /* Get outer coordinate index */
507 i_coord_offset = DIM*inr;
509 /* Load i particle coords and add shift vector */
510 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
512 fix0 = _mm_setzero_ps();
513 fiy0 = _mm_setzero_ps();
514 fiz0 = _mm_setzero_ps();
516 /* Load parameters for i particles */
517 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
518 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
520 /* Start inner kernel loop */
521 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
524 /* Get j neighbor index, and coordinate index */
529 j_coord_offsetA = DIM*jnrA;
530 j_coord_offsetB = DIM*jnrB;
531 j_coord_offsetC = DIM*jnrC;
532 j_coord_offsetD = DIM*jnrD;
534 /* load j atom coordinates */
535 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
536 x+j_coord_offsetC,x+j_coord_offsetD,
539 /* Calculate displacement vector */
540 dx00 = _mm_sub_ps(ix0,jx0);
541 dy00 = _mm_sub_ps(iy0,jy0);
542 dz00 = _mm_sub_ps(iz0,jz0);
544 /* Calculate squared distance and things based on it */
545 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
547 rinv00 = avx128fma_invsqrt_f(rsq00);
549 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
551 /* Load parameters for j particles */
552 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
553 charge+jnrC+0,charge+jnrD+0);
554 vdwjidx0A = 2*vdwtype[jnrA+0];
555 vdwjidx0B = 2*vdwtype[jnrB+0];
556 vdwjidx0C = 2*vdwtype[jnrC+0];
557 vdwjidx0D = 2*vdwtype[jnrD+0];
559 /**************************
560 * CALCULATE INTERACTIONS *
561 **************************/
563 if (gmx_mm_any_lt(rsq00,rcutoff2))
566 /* Compute parameters for interactions between i and j atoms */
567 qq00 = _mm_mul_ps(iq0,jq0);
568 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
569 vdwparam+vdwioffset0+vdwjidx0B,
570 vdwparam+vdwioffset0+vdwjidx0C,
571 vdwparam+vdwioffset0+vdwjidx0D,
574 /* REACTION-FIELD ELECTROSTATICS */
575 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
577 /* LENNARD-JONES DISPERSION/REPULSION */
579 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
580 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
582 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
584 fscal = _mm_add_ps(felec,fvdw);
586 fscal = _mm_and_ps(fscal,cutoff_mask);
588 /* Update vectorial force */
589 fix0 = _mm_macc_ps(dx00,fscal,fix0);
590 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
591 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
593 fjptrA = f+j_coord_offsetA;
594 fjptrB = f+j_coord_offsetB;
595 fjptrC = f+j_coord_offsetC;
596 fjptrD = f+j_coord_offsetD;
597 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
598 _mm_mul_ps(dx00,fscal),
599 _mm_mul_ps(dy00,fscal),
600 _mm_mul_ps(dz00,fscal));
604 /* Inner loop uses 40 flops */
610 /* Get j neighbor index, and coordinate index */
611 jnrlistA = jjnr[jidx];
612 jnrlistB = jjnr[jidx+1];
613 jnrlistC = jjnr[jidx+2];
614 jnrlistD = jjnr[jidx+3];
615 /* Sign of each element will be negative for non-real atoms.
616 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
617 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
619 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
620 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
621 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
622 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
623 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
624 j_coord_offsetA = DIM*jnrA;
625 j_coord_offsetB = DIM*jnrB;
626 j_coord_offsetC = DIM*jnrC;
627 j_coord_offsetD = DIM*jnrD;
629 /* load j atom coordinates */
630 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
631 x+j_coord_offsetC,x+j_coord_offsetD,
634 /* Calculate displacement vector */
635 dx00 = _mm_sub_ps(ix0,jx0);
636 dy00 = _mm_sub_ps(iy0,jy0);
637 dz00 = _mm_sub_ps(iz0,jz0);
639 /* Calculate squared distance and things based on it */
640 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
642 rinv00 = avx128fma_invsqrt_f(rsq00);
644 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
646 /* Load parameters for j particles */
647 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
648 charge+jnrC+0,charge+jnrD+0);
649 vdwjidx0A = 2*vdwtype[jnrA+0];
650 vdwjidx0B = 2*vdwtype[jnrB+0];
651 vdwjidx0C = 2*vdwtype[jnrC+0];
652 vdwjidx0D = 2*vdwtype[jnrD+0];
654 /**************************
655 * CALCULATE INTERACTIONS *
656 **************************/
658 if (gmx_mm_any_lt(rsq00,rcutoff2))
661 /* Compute parameters for interactions between i and j atoms */
662 qq00 = _mm_mul_ps(iq0,jq0);
663 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
664 vdwparam+vdwioffset0+vdwjidx0B,
665 vdwparam+vdwioffset0+vdwjidx0C,
666 vdwparam+vdwioffset0+vdwjidx0D,
669 /* REACTION-FIELD ELECTROSTATICS */
670 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
672 /* LENNARD-JONES DISPERSION/REPULSION */
674 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
675 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
677 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
679 fscal = _mm_add_ps(felec,fvdw);
681 fscal = _mm_and_ps(fscal,cutoff_mask);
683 fscal = _mm_andnot_ps(dummy_mask,fscal);
685 /* Update vectorial force */
686 fix0 = _mm_macc_ps(dx00,fscal,fix0);
687 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
688 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
690 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
691 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
692 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
693 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
694 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
695 _mm_mul_ps(dx00,fscal),
696 _mm_mul_ps(dy00,fscal),
697 _mm_mul_ps(dz00,fscal));
701 /* Inner loop uses 40 flops */
704 /* End of innermost loop */
706 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
707 f+i_coord_offset,fshift+i_shift_offset);
709 /* Increment number of inner iterations */
710 inneriter += j_index_end - j_index_start;
712 /* Outer loop uses 7 flops */
715 /* Increment number of outer iterations */
718 /* Update outer/inner flops */
720 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*40);