3 * This file is part of the GROMACS molecular simulation package.
5 * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
36 #error This file must be processed with the Gromacs pre-preprocessor
38 /* #if INCLUDE_HEADER */
45 #include "../nb_kernel.h"
46 #include "gromacs/gmxlib/nrnb.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 /* ## List of variables set by the generating script: */
53 /* ## Setttings that apply to the entire kernel: */
54 /* ## KERNEL_ELEC: String, choice for electrostatic interactions */
55 /* ## KERNEL_VDW: String, choice for van der Waals interactions */
56 /* ## KERNEL_NAME: String, name of this kernel */
57 /* ## KERNEL_VF: String telling if we calculate potential, force, or both */
58 /* ## GEOMETRY_I/GEOMETRY_J: String, name of each geometry, e.g. 'Water3' or '1Particle' */
60 /* ## Setttings that apply to particles in the outer (I) or inner (J) loops: */
61 /* ## PARTICLES_I[]/ Arrays with lists of i/j particles to use in kernel. It is */
62 /* ## PARTICLES_J[]: just [0] for particle geometry, but can be longer for water */
63 /* ## PARTICLES_ELEC_I[]/ Arrays with lists of i/j particle that have electrostatics */
64 /* ## PARTICLES_ELEC_J[]: interactions that should be calculated in this kernel. */
65 /* ## PARTICLES_VDW_I[]/ Arrays with the list of i/j particle that have VdW */
66 /* ## PARTICLES_VDW_J[]: interactions that should be calculated in this kernel. */
68 /* ## Setttings for pairs of interactions (e.g. 2nd i particle against 1st j particle) */
69 /* ## PAIRS_IJ[]: Array with (i,j) tuples of pairs for which interactions */
70 /* ## should be calculated in this kernel. Zero-charge particles */
71 /* ## do not have interactions with particles without vdw, and */
72 /* ## Vdw-only interactions are not evaluated in a no-vdw-kernel. */
73 /* ## INTERACTION_FLAGS[][]: 2D matrix, dimension e.g. 3*3 for water-water interactions. */
74 /* ## For each i-j pair, the element [I][J] is a list of strings */
75 /* ## defining properties/flags of this interaction. Examples */
76 /* ## include 'electrostatics'/'vdw' if that type of interaction */
77 /* ## should be evaluated, 'rsq'/'rinv'/'rinvsq' if those values */
78 /* ## are needed, and 'exactcutoff' or 'shift','switch' to */
79 /* ## decide if the force/potential should be modified. This way */
80 /* ## we only calculate values absolutely needed for each case. */
82 /* ## Calculate the size and offset for (merged/interleaved) table data */
85 * Gromacs nonbonded kernel: {KERNEL_NAME}
86 * Electrostatics interaction: {KERNEL_ELEC}
87 * VdW interaction: {KERNEL_VDW}
88 * Geometry: {GEOMETRY_I}-{GEOMETRY_J}
89 * Calculate force/pot: {KERNEL_VF}
93 (t_nblist * gmx_restrict nlist,
94 rvec * gmx_restrict xx,
95 rvec * gmx_restrict ff,
96 struct t_forcerec * gmx_restrict fr,
97 t_mdatoms * gmx_restrict mdatoms,
98 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
99 t_nrnb * gmx_restrict nrnb)
101 /* ## Not all variables are used for all kernels, but any optimizing compiler fixes that, */
102 /* ## so there is no point in going to extremes to exclude variables that are not needed. */
103 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
104 * just 0 for non-waters.
105 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
106 * jnr indices corresponding to data put in the four positions in the SIMD register.
108 int i_shift_offset,i_coord_offset,outeriter,inneriter;
109 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
110 int jnrA,jnrB,jnrC,jnrD;
111 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
112 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
113 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
115 real *shiftvec,*fshift,*x,*f;
116 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
118 __m128 fscal,rcutoff,rcutoff2,jidxall;
119 /* #for I in PARTICLES_I */
121 __m128 ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
123 /* #for J in PARTICLES_J */
124 int vdwjidx{J}A,vdwjidx{J}B,vdwjidx{J}C,vdwjidx{J}D;
125 __m128 jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
127 /* #for I,J in PAIRS_IJ */
128 __m128 dx{I}{J},dy{I}{J},dz{I}{J},rsq{I}{J},rinv{I}{J},rinvsq{I}{J},r{I}{J},qq{I}{J},c6_{I}{J},c12_{I}{J};
130 /* #if KERNEL_ELEC != 'None' */
131 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
134 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
136 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
137 __m128 minushalf = _mm_set1_ps(-0.5);
138 real *invsqrta,*dvda,*gbtab;
140 /* #if KERNEL_VDW != 'None' */
142 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
145 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
146 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
148 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
150 __m128i ifour = _mm_set1_epi32(4);
151 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
154 /* #if 'LJEwald' in KERNEL_VDW */
155 /* #for I,J in PAIRS_IJ */
156 __m128 c6grid_{I}{J};
159 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
160 __m128 one_half = _mm_set1_ps(0.5);
161 __m128 minus_one = _mm_set1_ps(-1.0);
163 /* #if 'Ewald' in KERNEL_ELEC */
165 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
166 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
169 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
170 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
171 real rswitch_scalar,d_scalar;
173 __m128 dummy_mask,cutoff_mask;
174 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
175 __m128 one = _mm_set1_ps(1.0);
176 __m128 two = _mm_set1_ps(2.0);
182 jindex = nlist->jindex;
184 shiftidx = nlist->shift;
186 shiftvec = fr->shift_vec[0];
187 fshift = fr->fshift[0];
188 /* #if KERNEL_ELEC != 'None' */
189 facel = _mm_set1_ps(fr->ic->epsfac);
190 charge = mdatoms->chargeA;
191 /* #if 'ReactionField' in KERNEL_ELEC */
192 krf = _mm_set1_ps(fr->ic->k_rf);
193 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
194 crf = _mm_set1_ps(fr->ic->c_rf);
197 /* #if KERNEL_VDW != 'None' */
198 nvdwtype = fr->ntype;
200 vdwtype = mdatoms->typeA;
202 /* #if 'LJEwald' in KERNEL_VDW */
203 vdwgridparam = fr->ljpme_c6grid;
204 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
205 ewclj = _mm_set1_ps(fr->ic->ewaldcoeff_lj);
206 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
209 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
210 vftab = kernel_data->table_elec_vdw->data;
211 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
212 /* #elif 'Table' in KERNEL_ELEC */
213 vftab = kernel_data->table_elec->data;
214 vftabscale = _mm_set1_ps(kernel_data->table_elec->scale);
215 /* #elif 'Table' in KERNEL_VDW */
216 vftab = kernel_data->table_vdw->data;
217 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
220 /* #if 'Ewald' in KERNEL_ELEC */
221 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
222 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
223 beta2 = _mm_mul_ps(beta,beta);
224 beta3 = _mm_mul_ps(beta,beta2);
225 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
226 ewtab = fr->ic->tabq_coul_F;
227 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
228 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
230 ewtab = fr->ic->tabq_coul_FDV0;
231 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
232 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
236 /* #if KERNEL_ELEC=='GeneralizedBorn' */
237 invsqrta = fr->invsqrta;
239 gbtabscale = _mm_set1_ps(fr->gbtab->scale);
240 gbtab = fr->gbtab->data;
241 gbinvepsdiff = _mm_set1_ps((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
244 /* #if 'Water' in GEOMETRY_I */
245 /* Setup water-specific parameters */
246 inr = nlist->iinr[0];
247 /* #for I in PARTICLES_ELEC_I */
248 iq{I} = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+{I}]));
250 /* #for I in PARTICLES_VDW_I */
251 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
255 /* #if 'Water' in GEOMETRY_J */
256 /* #for J in PARTICLES_ELEC_J */
257 jq{J} = _mm_set1_ps(charge[inr+{J}]);
259 /* #for J in PARTICLES_VDW_J */
260 vdwjidx{J}A = 2*vdwtype[inr+{J}];
262 /* #for I,J in PAIRS_IJ */
263 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
264 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
266 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
267 /* #if 'LJEwald' in KERNEL_VDW */
268 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
269 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
270 c6grid_{I}{J} = _mm_set1_ps(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
272 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
273 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
279 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
280 /* #if KERNEL_ELEC!='None' */
281 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
282 rcutoff_scalar = fr->ic->rcoulomb;
284 rcutoff_scalar = fr->ic->rvdw;
286 rcutoff = _mm_set1_ps(rcutoff_scalar);
287 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
290 /* #if KERNEL_MOD_VDW=='PotentialShift' */
291 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
292 rvdw = _mm_set1_ps(fr->ic->rvdw);
295 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
296 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
297 rswitch_scalar = fr->ic->rcoulomb_switch;
298 rswitch = _mm_set1_ps(rswitch_scalar);
300 rswitch_scalar = fr->ic->rvdw_switch;
301 rswitch = _mm_set1_ps(rswitch_scalar);
303 /* Setup switch parameters */
304 d_scalar = rcutoff_scalar-rswitch_scalar;
305 d = _mm_set1_ps(d_scalar);
306 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
307 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
308 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
309 /* #if 'Force' in KERNEL_VF */
310 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
311 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
312 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
316 /* Avoid stupid compiler warnings */
317 jnrA = jnrB = jnrC = jnrD = 0;
323 /* ## Keep track of the floating point operations we issue for reporting! */
324 /* #define OUTERFLOPS 0 */
328 for(iidx=0;iidx<4*DIM;iidx++)
333 /* Start outer loop over neighborlists */
334 for(iidx=0; iidx<nri; iidx++)
336 /* Load shift vector for this list */
337 i_shift_offset = DIM*shiftidx[iidx];
339 /* Load limits for loop over neighbors */
340 j_index_start = jindex[iidx];
341 j_index_end = jindex[iidx+1];
343 /* Get outer coordinate index */
345 i_coord_offset = DIM*inr;
347 /* Load i particle coords and add shift vector */
348 /* #if GEOMETRY_I == 'Particle' */
349 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
350 /* #elif GEOMETRY_I == 'Water3' */
351 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
352 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
353 /* #elif GEOMETRY_I == 'Water4' */
354 /* #if 0 in PARTICLES_I */
355 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
356 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
358 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
359 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
363 /* #if 'Force' in KERNEL_VF */
364 /* #for I in PARTICLES_I */
365 fix{I} = _mm_setzero_ps();
366 fiy{I} = _mm_setzero_ps();
367 fiz{I} = _mm_setzero_ps();
371 /* ## For water we already preloaded parameters at the start of the kernel */
372 /* #if not 'Water' in GEOMETRY_I */
373 /* Load parameters for i particles */
374 /* #for I in PARTICLES_ELEC_I */
375 iq{I} = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+{I}));
376 /* #define OUTERFLOPS OUTERFLOPS+1 */
377 /* #if KERNEL_ELEC=='GeneralizedBorn' */
378 isai{I} = _mm_load1_ps(invsqrta+inr+{I});
381 /* #for I in PARTICLES_VDW_I */
382 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
386 /* #if 'Potential' in KERNEL_VF */
387 /* Reset potential sums */
388 /* #if KERNEL_ELEC != 'None' */
389 velecsum = _mm_setzero_ps();
391 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
392 vgbsum = _mm_setzero_ps();
394 /* #if KERNEL_VDW != 'None' */
395 vvdwsum = _mm_setzero_ps();
398 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
399 dvdasum = _mm_setzero_ps();
402 /* #for ROUND in ['Loop','Epilogue'] */
404 /* #if ROUND =='Loop' */
405 /* Start inner kernel loop */
406 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
408 /* ## First round is normal loop (next statement resets indentation) */
415 /* ## Second round is epilogue */
417 /* #define INNERFLOPS 0 */
419 /* Get j neighbor index, and coordinate index */
420 /* #if ROUND =='Loop' */
426 jnrlistA = jjnr[jidx];
427 jnrlistB = jjnr[jidx+1];
428 jnrlistC = jjnr[jidx+2];
429 jnrlistD = jjnr[jidx+3];
430 /* Sign of each element will be negative for non-real atoms.
431 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
432 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
434 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
435 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
436 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
437 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
438 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
440 j_coord_offsetA = DIM*jnrA;
441 j_coord_offsetB = DIM*jnrB;
442 j_coord_offsetC = DIM*jnrC;
443 j_coord_offsetD = DIM*jnrD;
445 /* load j atom coordinates */
446 /* #if GEOMETRY_J == 'Particle' */
447 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
448 x+j_coord_offsetC,x+j_coord_offsetD,
450 /* #elif GEOMETRY_J == 'Water3' */
451 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
452 x+j_coord_offsetC,x+j_coord_offsetD,
453 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
454 /* #elif GEOMETRY_J == 'Water4' */
455 /* #if 0 in PARTICLES_J */
456 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
457 x+j_coord_offsetC,x+j_coord_offsetD,
458 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
459 &jy2,&jz2,&jx3,&jy3,&jz3);
461 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
462 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
463 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
467 /* Calculate displacement vector */
468 /* #for I,J in PAIRS_IJ */
469 dx{I}{J} = _mm_sub_ps(ix{I},jx{J});
470 dy{I}{J} = _mm_sub_ps(iy{I},jy{J});
471 dz{I}{J} = _mm_sub_ps(iz{I},jz{J});
472 /* #define INNERFLOPS INNERFLOPS+3 */
475 /* Calculate squared distance and things based on it */
476 /* #for I,J in PAIRS_IJ */
477 rsq{I}{J} = gmx_mm_calc_rsq_ps(dx{I}{J},dy{I}{J},dz{I}{J});
478 /* #define INNERFLOPS INNERFLOPS+5 */
481 /* #for I,J in PAIRS_IJ */
482 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
483 rinv{I}{J} = avx128fma_invsqrt_f(rsq{I}{J});
484 /* #define INNERFLOPS INNERFLOPS+5 */
488 /* #for I,J in PAIRS_IJ */
489 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
490 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
491 rinvsq{I}{J} = avx128fma_inv_f(rsq{I}{J});
492 /* #define INNERFLOPS INNERFLOPS+4 */
494 rinvsq{I}{J} = _mm_mul_ps(rinv{I}{J},rinv{I}{J});
495 /* #define INNERFLOPS INNERFLOPS+1 */
500 /* #if not 'Water' in GEOMETRY_J */
501 /* Load parameters for j particles */
502 /* #for J in PARTICLES_ELEC_J */
503 jq{J} = gmx_mm_load_4real_swizzle_ps(charge+jnrA+{J},charge+jnrB+{J},
504 charge+jnrC+{J},charge+jnrD+{J});
505 /* #if KERNEL_ELEC=='GeneralizedBorn' */
506 isaj{J} = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+{J},invsqrta+jnrB+{J},
507 invsqrta+jnrC+{J},invsqrta+jnrD+{J});
510 /* #for J in PARTICLES_VDW_J */
511 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
512 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
513 vdwjidx{J}C = 2*vdwtype[jnrC+{J}];
514 vdwjidx{J}D = 2*vdwtype[jnrD+{J}];
518 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
519 /* #for J in PARTICLES_J */
520 fjx{J} = _mm_setzero_ps();
521 fjy{J} = _mm_setzero_ps();
522 fjz{J} = _mm_setzero_ps();
526 /* #for I,J in PAIRS_IJ */
528 /**************************
529 * CALCULATE INTERACTIONS *
530 **************************/
532 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
533 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
534 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
535 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
537 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
540 /* #define INNERFLOPS INNERFLOPS+1 */
543 /* #if 'r' in INTERACTION_FLAGS[I][J] */
544 r{I}{J} = _mm_mul_ps(rsq{I}{J},rinv{I}{J});
545 /* #if ROUND == 'Epilogue' */
546 r{I}{J} = _mm_andnot_ps(dummy_mask,r{I}{J});
547 /* #define INNERFLOPS INNERFLOPS+1 */
549 /* #define INNERFLOPS INNERFLOPS+1 */
552 /* ## For water geometries we already loaded parameters at the start of the kernel */
553 /* #if not 'Water' in GEOMETRY_J */
554 /* Compute parameters for interactions between i and j atoms */
555 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
556 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
557 /* #define INNERFLOPS INNERFLOPS+1 */
559 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
560 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset{I}+vdwjidx{J}A,
561 vdwparam+vdwioffset{I}+vdwjidx{J}B,
562 vdwparam+vdwioffset{I}+vdwjidx{J}C,
563 vdwparam+vdwioffset{I}+vdwjidx{J}D,
564 &c6_{I}{J},&c12_{I}{J});
566 /* #if 'LJEwald' in KERNEL_VDW */
567 c6grid_{I}{J} = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
568 vdwgridparam+vdwioffset{I}+vdwjidx{J}B,
569 vdwgridparam+vdwioffset{I}+vdwjidx{J}C,
570 vdwgridparam+vdwioffset{I}+vdwjidx{J}D);
576 /* #if 'table' in INTERACTION_FLAGS[I][J] */
577 /* Calculate table index by multiplying r with table scale and truncate to integer */
578 rt = _mm_mul_ps(r{I}{J},vftabscale);
579 vfitab = _mm_cvttps_epi32(rt);
581 vfeps = _mm_frcz_ps(rt);
583 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
585 twovfeps = _mm_add_ps(vfeps,vfeps);
586 /* #define INNERFLOPS INNERFLOPS+4 */
587 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
588 /* ## 3 tables, 4 bytes per point: multiply index by 12 */
589 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
590 /* #elif 'Table' in KERNEL_ELEC */
591 /* ## 1 table, 4 bytes per point: multiply index by 4 */
592 vfitab = _mm_slli_epi32(vfitab,2);
593 /* #elif 'Table' in KERNEL_VDW */
594 /* ## 2 tables, 4 bytes per point: multiply index by 8 */
595 vfitab = _mm_slli_epi32(vfitab,3);
599 /* ## ELECTROSTATIC INTERACTIONS */
600 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
602 /* #if KERNEL_ELEC=='Coulomb' */
604 /* COULOMB ELECTROSTATICS */
605 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
606 /* #define INNERFLOPS INNERFLOPS+1 */
607 /* #if 'Force' in KERNEL_VF */
608 felec = _mm_mul_ps(velec,rinvsq{I}{J});
609 /* #define INNERFLOPS INNERFLOPS+2 */
612 /* #elif KERNEL_ELEC=='ReactionField' */
614 /* REACTION-FIELD ELECTROSTATICS */
615 /* #if 'Potential' in KERNEL_VF */
616 velec = _mm_mul_ps(qq{I}{J},_mm_sub_ps(_mm_macc_ps(krf,rsq{I}{J},rinv{I}{J}),crf));
617 /* #define INNERFLOPS INNERFLOPS+4 */
619 /* #if 'Force' in KERNEL_VF */
620 felec = _mm_mul_ps(qq{I}{J},_mm_msub_ps(rinv{I}{J},rinvsq{I}{J},krf2));
621 /* #define INNERFLOPS INNERFLOPS+3 */
624 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
626 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
627 isaprod = _mm_mul_ps(isai{I},isaj{J});
628 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq{I}{J},_mm_mul_ps(isaprod,gbinvepsdiff)));
629 gbscale = _mm_mul_ps(isaprod,gbtabscale);
630 /* #define INNERFLOPS INNERFLOPS+5 */
632 /* Calculate generalized born table index - this is a separate table from the normal one,
633 * but we use the same procedure by multiplying r with scale and truncating to integer.
635 rt = _mm_mul_ps(r{I}{J},gbscale);
636 gbitab = _mm_cvttps_epi32(rt);
638 gbeps = _mm_frcz_ps(rt);
640 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
642 gbitab = _mm_slli_epi32(gbitab,2);
644 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
645 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
646 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
647 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
648 _MM_TRANSPOSE4_PS(Y,F,G,H);
649 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
650 VV = _mm_macc_ps(gbeps,Fp,Y);
651 vgb = _mm_mul_ps(gbqqfactor,VV);
652 /* #define INNERFLOPS INNERFLOPS+10 */
654 /* #if 'Force' in KERNEL_VF */
655 twogbeps = _mm_add_ps(gbeps,gbeps);
656 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
657 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
658 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r{I}{J},vgb));
659 /* #if ROUND == 'Epilogue' */
660 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
662 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
663 /* #if ROUND == 'Loop' */
669 /* 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. */
670 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
671 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
672 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
673 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
675 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj{J},isaj{J})));
676 /* #define INNERFLOPS INNERFLOPS+13 */
678 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
679 /* #define INNERFLOPS INNERFLOPS+1 */
680 /* #if 'Force' in KERNEL_VF */
681 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv{I}{J},fgb),rinv{I}{J});
682 /* #define INNERFLOPS INNERFLOPS+3 */
685 /* #elif KERNEL_ELEC=='Ewald' */
686 /* EWALD ELECTROSTATICS */
688 /* Analytical PME correction */
689 zeta2 = _mm_mul_ps(beta2,rsq{I}{J});
690 /* #if 'Force' in KERNEL_VF */
691 rinv3 = _mm_mul_ps(rinvsq{I}{J},rinv{I}{J});
692 pmecorrF = avx128fma_pmecorrF_f(zeta2);
693 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
694 felec = _mm_mul_ps(qq{I}{J},felec);
696 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
697 pmecorrV = avx128fma_pmecorrV_f(zeta2);
698 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
699 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv{I}{J},sh_ewald));
701 velec = _mm_nmacc_ps(pmecorrV,beta,rinv{I}{J});
703 velec = _mm_mul_ps(qq{I}{J},velec);
706 /* #elif KERNEL_ELEC=='CubicSplineTable' */
708 /* CUBIC SPLINE TABLE ELECTROSTATICS */
709 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
710 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
711 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
712 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
713 _MM_TRANSPOSE4_PS(Y,F,G,H);
714 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
715 /* #define INNERFLOPS INNERFLOPS+4 */
716 /* #if 'Potential' in KERNEL_VF */
717 VV = _mm_macc_ps(vfeps,Fp,Y);
718 velec = _mm_mul_ps(qq{I}{J},VV);
719 /* #define INNERFLOPS INNERFLOPS+3 */
721 /* #if 'Force' in KERNEL_VF */
722 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
723 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq{I}{J},FF),_mm_mul_ps(vftabscale,rinv{I}{J})));
724 /* #define INNERFLOPS INNERFLOPS+7 */
727 /* ## End of check for electrostatics interaction forms */
729 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
731 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
733 /* #if KERNEL_VDW=='LennardJones' */
735 /* LENNARD-JONES DISPERSION/REPULSION */
737 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
738 /* #define INNERFLOPS INNERFLOPS+2 */
739 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
740 vvdw6 = _mm_mul_ps(c6_{I}{J},rinvsix);
741 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
742 /* #define INNERFLOPS INNERFLOPS+3 */
743 /* #if KERNEL_MOD_VDW=='PotentialShift' */
744 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
745 _mm_mul_ps( _mm_nmacc_ps(c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
746 /* #define INNERFLOPS INNERFLOPS+8 */
748 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
749 /* #define INNERFLOPS INNERFLOPS+3 */
751 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
752 /* #if 'Force' in KERNEL_VF */
753 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq{I}{J});
754 /* #define INNERFLOPS INNERFLOPS+2 */
756 /* #elif KERNEL_VF=='Force' */
757 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
758 fvdw = _mm_mul_ps(_mm_msub_ps(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_ps(rinvsix,rinvsq{I}{J}));
759 /* #define INNERFLOPS INNERFLOPS+4 */
762 /* #elif KERNEL_VDW=='CubicSplineTable' */
764 /* CUBIC SPLINE TABLE DISPERSION */
765 /* #if 'Table' in KERNEL_ELEC */
766 vfitab = _mm_add_epi32(vfitab,ifour);
768 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
769 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
770 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
771 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
772 _MM_TRANSPOSE4_PS(Y,F,G,H);
773 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
774 /* #define INNERFLOPS INNERFLOPS+4 */
775 /* #if 'Potential' in KERNEL_VF */
776 VV = _mm_macc_ps(vfeps,Fp,Y);
777 vvdw6 = _mm_mul_ps(c6_{I}{J},VV);
778 /* #define INNERFLOPS INNERFLOPS+3 */
780 /* #if 'Force' in KERNEL_VF */
781 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
782 fvdw6 = _mm_mul_ps(c6_{I}{J},FF);
783 /* #define INNERFLOPS INNERFLOPS+4 */
786 /* CUBIC SPLINE TABLE REPULSION */
787 vfitab = _mm_add_epi32(vfitab,ifour);
788 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
789 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
790 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
791 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
792 _MM_TRANSPOSE4_PS(Y,F,G,H);
793 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
794 /* #define INNERFLOPS INNERFLOPS+4 */
795 /* #if 'Potential' in KERNEL_VF */
796 VV = _mm_macc_ps(vfeps,Fp,Y);
797 vvdw12 = _mm_mul_ps(c12_{I}{J},VV);
798 /* #define INNERFLOPS INNERFLOPS+3 */
800 /* #if 'Force' in KERNEL_VF */
801 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
802 fvdw12 = _mm_mul_ps(c12_{I}{J},FF);
803 /* #define INNERFLOPS INNERFLOPS+5 */
805 /* #if 'Potential' in KERNEL_VF */
806 vvdw = _mm_add_ps(vvdw12,vvdw6);
807 /* #define INNERFLOPS INNERFLOPS+1 */
809 /* #if 'Force' in KERNEL_VF */
810 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv{I}{J})));
811 /* #define INNERFLOPS INNERFLOPS+4 */
814 /* #elif KERNEL_VDW=='LJEwald' */
816 /* Analytical LJ-PME */
817 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
818 ewcljrsq = _mm_mul_ps(ewclj2,rsq{I}{J});
819 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
820 exponent = avx128fma_exp_f(ewcljrsq);
821 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
822 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
823 /* #define INNERFLOPS INNERFLOPS+10 */
824 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
825 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
826 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_{I}{J},_mm_sub_ps(one,poly),c6_{I}{J}),rinvsix);
827 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
828 /* #define INNERFLOPS INNERFLOPS+5 */
829 /* #if KERNEL_MOD_VDW=='PotentialShift' */
830 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
831 _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_{I}{J},sh_lj_ewald,_mm_mul_ps(c6_{I}{J},sh_vdw_invrcut6))),one_sixth));
832 /* #define INNERFLOPS INNERFLOPS+7 */
834 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
835 /* #define INNERFLOPS INNERFLOPS+2 */
837 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
838 /* #if 'Force' in KERNEL_VF */
839 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
840 fvdw = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_{I}{J},one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq{I}{J});
841 /* #define INNERFLOPS INNERFLOPS+5 */
843 /* #elif KERNEL_VF=='Force' */
844 /* f6A = 6 * C6grid * (1 - poly) */
845 f6A = _mm_mul_ps(c6grid_{I}{J},_mm_sub_ps(one,poly));
846 /* f6B = C6grid * exponent * beta^6 */
847 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_{I}{J},one_sixth),_mm_mul_ps(exponent,ewclj6));
848 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
849 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_{I}{J},rinvsix,_mm_sub_ps(c6_{I}{J},f6A)),rinvsix,f6B),rinvsq{I}{J});
850 /* #define INNERFLOPS INNERFLOPS+10 */
853 /* ## End of check for vdw interaction forms */
855 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
857 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
858 d = _mm_sub_ps(r{I}{J},rswitch);
859 d = _mm_max_ps(d,_mm_setzero_ps());
860 d2 = _mm_mul_ps(d,d);
861 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
862 /* #define INNERFLOPS INNERFLOPS+10 */
864 /* #if 'Force' in KERNEL_VF */
865 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
866 /* #define INNERFLOPS INNERFLOPS+5 */
869 /* Evaluate switch function */
870 /* #if 'Force' in KERNEL_VF */
871 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
872 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
873 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(velec,dsw)) );
874 /* #define INNERFLOPS INNERFLOPS+4 */
876 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
877 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(vvdw,dsw)) );
878 /* #define INNERFLOPS INNERFLOPS+4 */
881 /* #if 'Potential' in KERNEL_VF */
882 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
883 velec = _mm_mul_ps(velec,sw);
884 /* #define INNERFLOPS INNERFLOPS+1 */
886 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
887 vvdw = _mm_mul_ps(vvdw,sw);
888 /* #define INNERFLOPS INNERFLOPS+1 */
892 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
893 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
894 cutoff_mask = _mm_cmplt_ps(rsq{I}{J},rcutoff2);
895 /* #define INNERFLOPS INNERFLOPS+1 */
898 /* #if 'Potential' in KERNEL_VF */
899 /* Update potential sum for this i atom from the interaction with this j atom. */
900 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
901 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
902 velec = _mm_and_ps(velec,cutoff_mask);
903 /* #define INNERFLOPS INNERFLOPS+1 */
905 /* #if ROUND == 'Epilogue' */
906 velec = _mm_andnot_ps(dummy_mask,velec);
908 velecsum = _mm_add_ps(velecsum,velec);
909 /* #define INNERFLOPS INNERFLOPS+1 */
910 /* #if KERNEL_ELEC=='GeneralizedBorn' */
911 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
912 vgb = _mm_and_ps(vgb,cutoff_mask);
913 /* #define INNERFLOPS INNERFLOPS+1 */
915 /* #if ROUND == 'Epilogue' */
916 vgb = _mm_andnot_ps(dummy_mask,vgb);
918 vgbsum = _mm_add_ps(vgbsum,vgb);
919 /* #define INNERFLOPS INNERFLOPS+1 */
922 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
923 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
924 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
925 vvdw = _mm_and_ps(vvdw,cutoff_mask);
926 /* #define INNERFLOPS INNERFLOPS+1 */
928 /* #if ROUND == 'Epilogue' */
929 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
931 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
932 /* #define INNERFLOPS INNERFLOPS+1 */
936 /* #if 'Force' in KERNEL_VF */
938 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
939 fscal = _mm_add_ps(felec,fvdw);
940 /* #define INNERFLOPS INNERFLOPS+1 */
941 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
943 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
947 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
948 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
949 fscal = _mm_and_ps(fscal,cutoff_mask);
950 /* #define INNERFLOPS INNERFLOPS+1 */
953 /* #if ROUND == 'Epilogue' */
954 fscal = _mm_andnot_ps(dummy_mask,fscal);
957 /* ## Construction of vectorial force built into FMA instructions now */
958 /* #define INNERFLOPS INNERFLOPS+3 */
960 /* Update vectorial force */
961 fix{I} = _mm_macc_ps(dx{I}{J},fscal,fix{I});
962 fiy{I} = _mm_macc_ps(dy{I}{J},fscal,fiy{I});
963 fiz{I} = _mm_macc_ps(dz{I}{J},fscal,fiz{I});
964 /* #define INNERFLOPS INNERFLOPS+6 */
966 /* #if GEOMETRY_I == 'Particle' */
967 /* #if ROUND == 'Loop' */
968 fjptrA = f+j_coord_offsetA;
969 fjptrB = f+j_coord_offsetB;
970 fjptrC = f+j_coord_offsetC;
971 fjptrD = f+j_coord_offsetD;
973 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
974 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
975 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
976 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
978 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
979 _mm_mul_ps(dx{I}{J},fscal),
980 _mm_mul_ps(dy{I}{J},fscal),
981 _mm_mul_ps(dz{I}{J},fscal));
982 /* #define INNERFLOPS INNERFLOPS+3 */
984 fjx{J} = _mm_macc_ps(dx{I}{J},fscal,fjx{J});
985 fjy{J} = _mm_macc_ps(dy{I}{J},fscal,fjy{J});
986 fjz{J} = _mm_macc_ps(dz{I}{J},fscal,fjz{J});
987 /* #define INNERFLOPS INNERFLOPS+3 */
992 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
993 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
994 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
999 /* ## End of check for the interaction being outside the cutoff */
1002 /* ## End of loop over i-j interaction pairs */
1004 /* #if GEOMETRY_I != 'Particle' */
1005 /* #if ROUND == 'Loop' */
1006 fjptrA = f+j_coord_offsetA;
1007 fjptrB = f+j_coord_offsetB;
1008 fjptrC = f+j_coord_offsetC;
1009 fjptrD = f+j_coord_offsetD;
1011 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1012 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1013 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1014 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1018 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1019 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1020 /* #elif GEOMETRY_J == 'Water3' */
1021 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1022 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1023 /* #define INNERFLOPS INNERFLOPS+9 */
1024 /* #elif GEOMETRY_J == 'Water4' */
1025 /* #if 0 in PARTICLES_J */
1026 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1027 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1028 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1029 /* #define INNERFLOPS INNERFLOPS+12 */
1031 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1032 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1033 /* #define INNERFLOPS INNERFLOPS+9 */
1037 /* Inner loop uses {INNERFLOPS} flops */
1042 /* End of innermost loop */
1044 /* #if 'Force' in KERNEL_VF */
1045 /* #if GEOMETRY_I == 'Particle' */
1046 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
1047 f+i_coord_offset,fshift+i_shift_offset);
1048 /* #define OUTERFLOPS OUTERFLOPS+6 */
1049 /* #elif GEOMETRY_I == 'Water3' */
1050 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1051 f+i_coord_offset,fshift+i_shift_offset);
1052 /* #define OUTERFLOPS OUTERFLOPS+18 */
1053 /* #elif GEOMETRY_I == 'Water4' */
1054 /* #if 0 in PARTICLES_I */
1055 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1056 f+i_coord_offset,fshift+i_shift_offset);
1057 /* #define OUTERFLOPS OUTERFLOPS+24 */
1059 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1060 f+i_coord_offset+DIM,fshift+i_shift_offset);
1061 /* #define OUTERFLOPS OUTERFLOPS+18 */
1066 /* #if 'Potential' in KERNEL_VF */
1068 /* Update potential energies */
1069 /* #if KERNEL_ELEC != 'None' */
1070 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1071 /* #define OUTERFLOPS OUTERFLOPS+1 */
1073 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1074 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
1075 /* #define OUTERFLOPS OUTERFLOPS+1 */
1077 /* #if KERNEL_VDW != 'None' */
1078 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1079 /* #define OUTERFLOPS OUTERFLOPS+1 */
1082 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1083 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai{I},isai{I}));
1084 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
1087 /* Increment number of inner iterations */
1088 inneriter += j_index_end - j_index_start;
1090 /* Outer loop uses {OUTERFLOPS} flops */
1093 /* Increment number of outer iterations */
1096 /* Update outer/inner flops */
1097 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1098 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1099 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1100 /* #if GEOMETRY_I == 'Water3' */
1101 /* #define ISUFFIX '_W3' */
1102 /* #elif GEOMETRY_I == 'Water4' */
1103 /* #define ISUFFIX '_W4' */
1105 /* #define ISUFFIX '' */
1107 /* #if GEOMETRY_J == 'Water3' */
1108 /* #define JSUFFIX 'W3' */
1109 /* #elif GEOMETRY_J == 'Water4' */
1110 /* #define JSUFFIX 'W4' */
1112 /* #define JSUFFIX '' */
1114 /* #if 'PotentialAndForce' in KERNEL_VF */
1115 /* #define VFSUFFIX '_VF' */
1116 /* #elif 'Potential' in KERNEL_VF */
1117 /* #define VFSUFFIX '_V' */
1119 /* #define VFSUFFIX '_F' */
1122 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1123 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1124 /* #elif KERNEL_ELEC != 'None' */
1125 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1127 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});