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_ElecGB_VdwLJ_GeomP1P1_VF_avx_128_fma_single
51 * Electrostatics interaction: GeneralizedBorn
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecGB_VdwLJ_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 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
91 __m128 minushalf = _mm_set1_ps(-0.5);
92 real *invsqrta,*dvda,*gbtab;
94 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
98 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
100 __m128i ifour = _mm_set1_epi32(4);
101 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
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 invsqrta = fr->invsqrta;
126 gbtabscale = _mm_set1_ps(fr->gbtab->scale);
127 gbtab = fr->gbtab->data;
128 gbinvepsdiff = _mm_set1_ps((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = jnrC = jnrD = 0;
140 for(iidx=0;iidx<4*DIM;iidx++)
145 /* Start outer loop over neighborlists */
146 for(iidx=0; iidx<nri; iidx++)
148 /* Load shift vector for this list */
149 i_shift_offset = DIM*shiftidx[iidx];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
162 fix0 = _mm_setzero_ps();
163 fiy0 = _mm_setzero_ps();
164 fiz0 = _mm_setzero_ps();
166 /* Load parameters for i particles */
167 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
168 isai0 = _mm_load1_ps(invsqrta+inr+0);
169 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
171 /* Reset potential sums */
172 velecsum = _mm_setzero_ps();
173 vgbsum = _mm_setzero_ps();
174 vvdwsum = _mm_setzero_ps();
175 dvdasum = _mm_setzero_ps();
177 /* Start inner kernel loop */
178 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
181 /* Get j neighbor index, and coordinate index */
186 j_coord_offsetA = DIM*jnrA;
187 j_coord_offsetB = DIM*jnrB;
188 j_coord_offsetC = DIM*jnrC;
189 j_coord_offsetD = DIM*jnrD;
191 /* load j atom coordinates */
192 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
193 x+j_coord_offsetC,x+j_coord_offsetD,
196 /* Calculate displacement vector */
197 dx00 = _mm_sub_ps(ix0,jx0);
198 dy00 = _mm_sub_ps(iy0,jy0);
199 dz00 = _mm_sub_ps(iz0,jz0);
201 /* Calculate squared distance and things based on it */
202 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
204 rinv00 = avx128fma_invsqrt_f(rsq00);
206 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
208 /* Load parameters for j particles */
209 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
210 charge+jnrC+0,charge+jnrD+0);
211 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
212 invsqrta+jnrC+0,invsqrta+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 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
233 isaprod = _mm_mul_ps(isai0,isaj0);
234 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
235 gbscale = _mm_mul_ps(isaprod,gbtabscale);
237 /* Calculate generalized born table index - this is a separate table from the normal one,
238 * but we use the same procedure by multiplying r with scale and truncating to integer.
240 rt = _mm_mul_ps(r00,gbscale);
241 gbitab = _mm_cvttps_epi32(rt);
243 gbeps = _mm_frcz_ps(rt);
245 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
247 gbitab = _mm_slli_epi32(gbitab,2);
249 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
250 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
251 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
252 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
253 _MM_TRANSPOSE4_PS(Y,F,G,H);
254 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
255 VV = _mm_macc_ps(gbeps,Fp,Y);
256 vgb = _mm_mul_ps(gbqqfactor,VV);
258 twogbeps = _mm_add_ps(gbeps,gbeps);
259 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
260 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
261 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
262 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
267 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
268 velec = _mm_mul_ps(qq00,rinv00);
269 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
271 /* LENNARD-JONES DISPERSION/REPULSION */
273 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
274 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
275 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
276 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
277 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
279 /* Update potential sum for this i atom from the interaction with this j atom. */
280 velecsum = _mm_add_ps(velecsum,velec);
281 vgbsum = _mm_add_ps(vgbsum,vgb);
282 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
284 fscal = _mm_add_ps(felec,fvdw);
286 /* Update vectorial force */
287 fix0 = _mm_macc_ps(dx00,fscal,fix0);
288 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
289 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
291 fjptrA = f+j_coord_offsetA;
292 fjptrB = f+j_coord_offsetB;
293 fjptrC = f+j_coord_offsetC;
294 fjptrD = f+j_coord_offsetD;
295 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
296 _mm_mul_ps(dx00,fscal),
297 _mm_mul_ps(dy00,fscal),
298 _mm_mul_ps(dz00,fscal));
300 /* Inner loop uses 74 flops */
306 /* Get j neighbor index, and coordinate index */
307 jnrlistA = jjnr[jidx];
308 jnrlistB = jjnr[jidx+1];
309 jnrlistC = jjnr[jidx+2];
310 jnrlistD = jjnr[jidx+3];
311 /* Sign of each element will be negative for non-real atoms.
312 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
313 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
315 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
316 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
317 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
318 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
319 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
320 j_coord_offsetA = DIM*jnrA;
321 j_coord_offsetB = DIM*jnrB;
322 j_coord_offsetC = DIM*jnrC;
323 j_coord_offsetD = DIM*jnrD;
325 /* load j atom coordinates */
326 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
327 x+j_coord_offsetC,x+j_coord_offsetD,
330 /* Calculate displacement vector */
331 dx00 = _mm_sub_ps(ix0,jx0);
332 dy00 = _mm_sub_ps(iy0,jy0);
333 dz00 = _mm_sub_ps(iz0,jz0);
335 /* Calculate squared distance and things based on it */
336 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
338 rinv00 = avx128fma_invsqrt_f(rsq00);
340 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
342 /* Load parameters for j particles */
343 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
344 charge+jnrC+0,charge+jnrD+0);
345 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
346 invsqrta+jnrC+0,invsqrta+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 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
368 isaprod = _mm_mul_ps(isai0,isaj0);
369 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
370 gbscale = _mm_mul_ps(isaprod,gbtabscale);
372 /* Calculate generalized born table index - this is a separate table from the normal one,
373 * but we use the same procedure by multiplying r with scale and truncating to integer.
375 rt = _mm_mul_ps(r00,gbscale);
376 gbitab = _mm_cvttps_epi32(rt);
378 gbeps = _mm_frcz_ps(rt);
380 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
382 gbitab = _mm_slli_epi32(gbitab,2);
384 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
385 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
386 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
387 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
388 _MM_TRANSPOSE4_PS(Y,F,G,H);
389 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
390 VV = _mm_macc_ps(gbeps,Fp,Y);
391 vgb = _mm_mul_ps(gbqqfactor,VV);
393 twogbeps = _mm_add_ps(gbeps,gbeps);
394 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
395 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
396 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
397 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
398 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
399 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
400 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
401 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
402 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
403 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
404 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
405 velec = _mm_mul_ps(qq00,rinv00);
406 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
408 /* LENNARD-JONES DISPERSION/REPULSION */
410 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
411 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
412 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
413 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
414 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
416 /* Update potential sum for this i atom from the interaction with this j atom. */
417 velec = _mm_andnot_ps(dummy_mask,velec);
418 velecsum = _mm_add_ps(velecsum,velec);
419 vgb = _mm_andnot_ps(dummy_mask,vgb);
420 vgbsum = _mm_add_ps(vgbsum,vgb);
421 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
422 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
424 fscal = _mm_add_ps(felec,fvdw);
426 fscal = _mm_andnot_ps(dummy_mask,fscal);
428 /* Update vectorial force */
429 fix0 = _mm_macc_ps(dx00,fscal,fix0);
430 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
431 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
433 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
434 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
435 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
436 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
437 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
438 _mm_mul_ps(dx00,fscal),
439 _mm_mul_ps(dy00,fscal),
440 _mm_mul_ps(dz00,fscal));
442 /* Inner loop uses 75 flops */
445 /* End of innermost loop */
447 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
448 f+i_coord_offset,fshift+i_shift_offset);
451 /* Update potential energies */
452 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
453 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
454 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
455 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
456 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
458 /* Increment number of inner iterations */
459 inneriter += j_index_end - j_index_start;
461 /* Outer loop uses 10 flops */
464 /* Increment number of outer iterations */
467 /* Update outer/inner flops */
469 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*75);
472 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
473 * Electrostatics interaction: GeneralizedBorn
474 * VdW interaction: LennardJones
475 * Geometry: Particle-Particle
476 * Calculate force/pot: Force
479 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
480 (t_nblist * gmx_restrict nlist,
481 rvec * gmx_restrict xx,
482 rvec * gmx_restrict ff,
483 struct t_forcerec * gmx_restrict fr,
484 t_mdatoms * gmx_restrict mdatoms,
485 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
486 t_nrnb * gmx_restrict nrnb)
488 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
489 * just 0 for non-waters.
490 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
491 * jnr indices corresponding to data put in the four positions in the SIMD register.
493 int i_shift_offset,i_coord_offset,outeriter,inneriter;
494 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
495 int jnrA,jnrB,jnrC,jnrD;
496 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
497 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
498 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
500 real *shiftvec,*fshift,*x,*f;
501 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
503 __m128 fscal,rcutoff,rcutoff2,jidxall;
505 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
506 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
507 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
508 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
509 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
512 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
513 __m128 minushalf = _mm_set1_ps(-0.5);
514 real *invsqrta,*dvda,*gbtab;
516 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
519 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
520 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
522 __m128i ifour = _mm_set1_epi32(4);
523 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
525 __m128 dummy_mask,cutoff_mask;
526 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
527 __m128 one = _mm_set1_ps(1.0);
528 __m128 two = _mm_set1_ps(2.0);
534 jindex = nlist->jindex;
536 shiftidx = nlist->shift;
538 shiftvec = fr->shift_vec[0];
539 fshift = fr->fshift[0];
540 facel = _mm_set1_ps(fr->ic->epsfac);
541 charge = mdatoms->chargeA;
542 nvdwtype = fr->ntype;
544 vdwtype = mdatoms->typeA;
546 invsqrta = fr->invsqrta;
548 gbtabscale = _mm_set1_ps(fr->gbtab->scale);
549 gbtab = fr->gbtab->data;
550 gbinvepsdiff = _mm_set1_ps((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
552 /* Avoid stupid compiler warnings */
553 jnrA = jnrB = jnrC = jnrD = 0;
562 for(iidx=0;iidx<4*DIM;iidx++)
567 /* Start outer loop over neighborlists */
568 for(iidx=0; iidx<nri; iidx++)
570 /* Load shift vector for this list */
571 i_shift_offset = DIM*shiftidx[iidx];
573 /* Load limits for loop over neighbors */
574 j_index_start = jindex[iidx];
575 j_index_end = jindex[iidx+1];
577 /* Get outer coordinate index */
579 i_coord_offset = DIM*inr;
581 /* Load i particle coords and add shift vector */
582 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
584 fix0 = _mm_setzero_ps();
585 fiy0 = _mm_setzero_ps();
586 fiz0 = _mm_setzero_ps();
588 /* Load parameters for i particles */
589 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
590 isai0 = _mm_load1_ps(invsqrta+inr+0);
591 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
593 dvdasum = _mm_setzero_ps();
595 /* Start inner kernel loop */
596 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
599 /* Get j neighbor index, and coordinate index */
604 j_coord_offsetA = DIM*jnrA;
605 j_coord_offsetB = DIM*jnrB;
606 j_coord_offsetC = DIM*jnrC;
607 j_coord_offsetD = DIM*jnrD;
609 /* load j atom coordinates */
610 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
611 x+j_coord_offsetC,x+j_coord_offsetD,
614 /* Calculate displacement vector */
615 dx00 = _mm_sub_ps(ix0,jx0);
616 dy00 = _mm_sub_ps(iy0,jy0);
617 dz00 = _mm_sub_ps(iz0,jz0);
619 /* Calculate squared distance and things based on it */
620 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
622 rinv00 = avx128fma_invsqrt_f(rsq00);
624 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
626 /* Load parameters for j particles */
627 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
628 charge+jnrC+0,charge+jnrD+0);
629 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
630 invsqrta+jnrC+0,invsqrta+jnrD+0);
631 vdwjidx0A = 2*vdwtype[jnrA+0];
632 vdwjidx0B = 2*vdwtype[jnrB+0];
633 vdwjidx0C = 2*vdwtype[jnrC+0];
634 vdwjidx0D = 2*vdwtype[jnrD+0];
636 /**************************
637 * CALCULATE INTERACTIONS *
638 **************************/
640 r00 = _mm_mul_ps(rsq00,rinv00);
642 /* Compute parameters for interactions between i and j atoms */
643 qq00 = _mm_mul_ps(iq0,jq0);
644 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
645 vdwparam+vdwioffset0+vdwjidx0B,
646 vdwparam+vdwioffset0+vdwjidx0C,
647 vdwparam+vdwioffset0+vdwjidx0D,
650 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
651 isaprod = _mm_mul_ps(isai0,isaj0);
652 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
653 gbscale = _mm_mul_ps(isaprod,gbtabscale);
655 /* Calculate generalized born table index - this is a separate table from the normal one,
656 * but we use the same procedure by multiplying r with scale and truncating to integer.
658 rt = _mm_mul_ps(r00,gbscale);
659 gbitab = _mm_cvttps_epi32(rt);
661 gbeps = _mm_frcz_ps(rt);
663 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
665 gbitab = _mm_slli_epi32(gbitab,2);
667 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
668 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
669 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
670 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
671 _MM_TRANSPOSE4_PS(Y,F,G,H);
672 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
673 VV = _mm_macc_ps(gbeps,Fp,Y);
674 vgb = _mm_mul_ps(gbqqfactor,VV);
676 twogbeps = _mm_add_ps(gbeps,gbeps);
677 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
678 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
679 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
680 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
685 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
686 velec = _mm_mul_ps(qq00,rinv00);
687 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
689 /* LENNARD-JONES DISPERSION/REPULSION */
691 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
692 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
694 fscal = _mm_add_ps(felec,fvdw);
696 /* Update vectorial force */
697 fix0 = _mm_macc_ps(dx00,fscal,fix0);
698 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
699 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
701 fjptrA = f+j_coord_offsetA;
702 fjptrB = f+j_coord_offsetB;
703 fjptrC = f+j_coord_offsetC;
704 fjptrD = f+j_coord_offsetD;
705 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
706 _mm_mul_ps(dx00,fscal),
707 _mm_mul_ps(dy00,fscal),
708 _mm_mul_ps(dz00,fscal));
710 /* Inner loop uses 67 flops */
716 /* Get j neighbor index, and coordinate index */
717 jnrlistA = jjnr[jidx];
718 jnrlistB = jjnr[jidx+1];
719 jnrlistC = jjnr[jidx+2];
720 jnrlistD = jjnr[jidx+3];
721 /* Sign of each element will be negative for non-real atoms.
722 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
723 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
725 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
726 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
727 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
728 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
729 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
730 j_coord_offsetA = DIM*jnrA;
731 j_coord_offsetB = DIM*jnrB;
732 j_coord_offsetC = DIM*jnrC;
733 j_coord_offsetD = DIM*jnrD;
735 /* load j atom coordinates */
736 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
737 x+j_coord_offsetC,x+j_coord_offsetD,
740 /* Calculate displacement vector */
741 dx00 = _mm_sub_ps(ix0,jx0);
742 dy00 = _mm_sub_ps(iy0,jy0);
743 dz00 = _mm_sub_ps(iz0,jz0);
745 /* Calculate squared distance and things based on it */
746 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
748 rinv00 = avx128fma_invsqrt_f(rsq00);
750 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
752 /* Load parameters for j particles */
753 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
754 charge+jnrC+0,charge+jnrD+0);
755 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
756 invsqrta+jnrC+0,invsqrta+jnrD+0);
757 vdwjidx0A = 2*vdwtype[jnrA+0];
758 vdwjidx0B = 2*vdwtype[jnrB+0];
759 vdwjidx0C = 2*vdwtype[jnrC+0];
760 vdwjidx0D = 2*vdwtype[jnrD+0];
762 /**************************
763 * CALCULATE INTERACTIONS *
764 **************************/
766 r00 = _mm_mul_ps(rsq00,rinv00);
767 r00 = _mm_andnot_ps(dummy_mask,r00);
769 /* Compute parameters for interactions between i and j atoms */
770 qq00 = _mm_mul_ps(iq0,jq0);
771 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
772 vdwparam+vdwioffset0+vdwjidx0B,
773 vdwparam+vdwioffset0+vdwjidx0C,
774 vdwparam+vdwioffset0+vdwjidx0D,
777 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
778 isaprod = _mm_mul_ps(isai0,isaj0);
779 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
780 gbscale = _mm_mul_ps(isaprod,gbtabscale);
782 /* Calculate generalized born table index - this is a separate table from the normal one,
783 * but we use the same procedure by multiplying r with scale and truncating to integer.
785 rt = _mm_mul_ps(r00,gbscale);
786 gbitab = _mm_cvttps_epi32(rt);
788 gbeps = _mm_frcz_ps(rt);
790 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
792 gbitab = _mm_slli_epi32(gbitab,2);
794 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
795 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
796 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
797 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
798 _MM_TRANSPOSE4_PS(Y,F,G,H);
799 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
800 VV = _mm_macc_ps(gbeps,Fp,Y);
801 vgb = _mm_mul_ps(gbqqfactor,VV);
803 twogbeps = _mm_add_ps(gbeps,gbeps);
804 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
805 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
806 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
807 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
808 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
809 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
810 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
811 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
812 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
813 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
814 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
815 velec = _mm_mul_ps(qq00,rinv00);
816 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
818 /* LENNARD-JONES DISPERSION/REPULSION */
820 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
821 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
823 fscal = _mm_add_ps(felec,fvdw);
825 fscal = _mm_andnot_ps(dummy_mask,fscal);
827 /* Update vectorial force */
828 fix0 = _mm_macc_ps(dx00,fscal,fix0);
829 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
830 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
832 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
833 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
834 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
835 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
836 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
837 _mm_mul_ps(dx00,fscal),
838 _mm_mul_ps(dy00,fscal),
839 _mm_mul_ps(dz00,fscal));
841 /* Inner loop uses 68 flops */
844 /* End of innermost loop */
846 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
847 f+i_coord_offset,fshift+i_shift_offset);
849 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
850 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
852 /* Increment number of inner iterations */
853 inneriter += j_index_end - j_index_start;
855 /* Outer loop uses 7 flops */
858 /* Increment number of outer iterations */
861 /* Update outer/inner flops */
863 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*68);