2 #error This file must be processed with the Gromacs pre-preprocessor
4 /* #if INCLUDE_HEADER */
11 #include "../nb_kernel.h"
12 #include "types/simple.h"
16 #include "gmx_math_x86_avx_128_fma_single.h"
17 #include "kernelutil_x86_avx_128_fma_single.h"
20 /* ## List of variables set by the generating script: */
22 /* ## Setttings that apply to the entire kernel: */
23 /* ## KERNEL_ELEC: String, choice for electrostatic interactions */
24 /* ## KERNEL_VDW: String, choice for van der Waals interactions */
25 /* ## KERNEL_NAME: String, name of this kernel */
26 /* ## KERNEL_VF: String telling if we calculate potential, force, or both */
27 /* ## GEOMETRY_I/GEOMETRY_J: String, name of each geometry, e.g. 'Water3' or '1Particle' */
29 /* ## Setttings that apply to particles in the outer (I) or inner (J) loops: */
30 /* ## PARTICLES_I[]/ Arrays with lists of i/j particles to use in kernel. It is */
31 /* ## PARTICLES_J[]: just [0] for particle geometry, but can be longer for water */
32 /* ## PARTICLES_ELEC_I[]/ Arrays with lists of i/j particle that have electrostatics */
33 /* ## PARTICLES_ELEC_J[]: interactions that should be calculated in this kernel. */
34 /* ## PARTICLES_VDW_I[]/ Arrays with the list of i/j particle that have VdW */
35 /* ## PARTICLES_VDW_J[]: interactions that should be calculated in this kernel. */
37 /* ## Setttings for pairs of interactions (e.g. 2nd i particle against 1st j particle) */
38 /* ## PAIRS_IJ[]: Array with (i,j) tuples of pairs for which interactions */
39 /* ## should be calculated in this kernel. Zero-charge particles */
40 /* ## do not have interactions with particles without vdw, and */
41 /* ## Vdw-only interactions are not evaluated in a no-vdw-kernel. */
42 /* ## INTERACTION_FLAGS[][]: 2D matrix, dimension e.g. 3*3 for water-water interactions. */
43 /* ## For each i-j pair, the element [I][J] is a list of strings */
44 /* ## defining properties/flags of this interaction. Examples */
45 /* ## include 'electrostatics'/'vdw' if that type of interaction */
46 /* ## should be evaluated, 'rsq'/'rinv'/'rinvsq' if those values */
47 /* ## are needed, and 'exactcutoff' or 'shift','switch' to */
48 /* ## decide if the force/potential should be modified. This way */
49 /* ## we only calculate values absolutely needed for each case. */
51 /* ## Calculate the size and offset for (merged/interleaved) table data */
54 * Gromacs nonbonded kernel: {KERNEL_NAME}
55 * Electrostatics interaction: {KERNEL_ELEC}
56 * VdW interaction: {KERNEL_VDW}
57 * Geometry: {GEOMETRY_I}-{GEOMETRY_J}
58 * Calculate force/pot: {KERNEL_VF}
62 (t_nblist * gmx_restrict nlist,
63 rvec * gmx_restrict xx,
64 rvec * gmx_restrict ff,
65 t_forcerec * gmx_restrict fr,
66 t_mdatoms * gmx_restrict mdatoms,
67 nb_kernel_data_t * gmx_restrict kernel_data,
68 t_nrnb * gmx_restrict nrnb)
70 /* ## Not all variables are used for all kernels, but any optimizing compiler fixes that, */
71 /* ## so there is no point in going to extremes to exclude variables that are not needed. */
72 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
73 * just 0 for non-waters.
74 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
75 * jnr indices corresponding to data put in the four positions in the SIMD register.
77 int i_shift_offset,i_coord_offset,outeriter,inneriter;
78 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
79 int jnrA,jnrB,jnrC,jnrD;
80 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
81 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
82 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
84 real *shiftvec,*fshift,*x,*f;
85 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
87 __m128 fscal,rcutoff,rcutoff2,jidxall;
88 /* #for I in PARTICLES_I */
90 __m128 ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
92 /* #for J in PARTICLES_J */
93 int vdwjidx{J}A,vdwjidx{J}B,vdwjidx{J}C,vdwjidx{J}D;
94 __m128 jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
96 /* #for I,J in PAIRS_IJ */
97 __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};
99 /* #if KERNEL_ELEC != 'None' */
100 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
103 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
105 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
106 __m128 minushalf = _mm_set1_ps(-0.5);
107 real *invsqrta,*dvda,*gbtab;
109 /* #if KERNEL_VDW != 'None' */
111 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
114 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
115 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
117 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
119 __m128i ifour = _mm_set1_epi32(4);
120 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
123 /* #if 'Ewald' in KERNEL_ELEC */
125 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
126 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
129 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
130 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
131 real rswitch_scalar,d_scalar;
133 __m128 dummy_mask,cutoff_mask;
134 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
135 __m128 one = _mm_set1_ps(1.0);
136 __m128 two = _mm_set1_ps(2.0);
142 jindex = nlist->jindex;
144 shiftidx = nlist->shift;
146 shiftvec = fr->shift_vec[0];
147 fshift = fr->fshift[0];
148 /* #if KERNEL_ELEC != 'None' */
149 facel = _mm_set1_ps(fr->epsfac);
150 charge = mdatoms->chargeA;
151 /* #if 'ReactionField' in KERNEL_ELEC */
152 krf = _mm_set1_ps(fr->ic->k_rf);
153 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
154 crf = _mm_set1_ps(fr->ic->c_rf);
157 /* #if KERNEL_VDW != 'None' */
158 nvdwtype = fr->ntype;
160 vdwtype = mdatoms->typeA;
163 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
164 vftab = kernel_data->table_elec_vdw->data;
165 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
166 /* #elif 'Table' in KERNEL_ELEC */
167 vftab = kernel_data->table_elec->data;
168 vftabscale = _mm_set1_ps(kernel_data->table_elec->scale);
169 /* #elif 'Table' in KERNEL_VDW */
170 vftab = kernel_data->table_vdw->data;
171 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
174 /* #if 'Ewald' in KERNEL_ELEC */
175 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
176 beta = _mm_set1_ps(fr->ic->ewaldcoeff);
177 beta2 = _mm_mul_ps(beta,beta);
178 beta3 = _mm_mul_ps(beta,beta2);
179 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
180 ewtab = fr->ic->tabq_coul_F;
181 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
182 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
184 ewtab = fr->ic->tabq_coul_FDV0;
185 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
186 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
190 /* #if KERNEL_ELEC=='GeneralizedBorn' */
191 invsqrta = fr->invsqrta;
193 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
194 gbtab = fr->gbtab.data;
195 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
198 /* #if 'Water' in GEOMETRY_I */
199 /* Setup water-specific parameters */
200 inr = nlist->iinr[0];
201 /* #for I in PARTICLES_ELEC_I */
202 iq{I} = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+{I}]));
204 /* #for I in PARTICLES_VDW_I */
205 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
209 /* #if 'Water' in GEOMETRY_J */
210 /* #for J in PARTICLES_ELEC_J */
211 jq{J} = _mm_set1_ps(charge[inr+{J}]);
213 /* #for J in PARTICLES_VDW_J */
214 vdwjidx{J}A = 2*vdwtype[inr+{J}];
216 /* #for I,J in PAIRS_IJ */
217 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
218 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
220 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
221 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
222 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
227 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
228 /* #if KERNEL_ELEC!='None' */
229 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
230 rcutoff_scalar = fr->rcoulomb;
232 rcutoff_scalar = fr->rvdw;
234 rcutoff = _mm_set1_ps(rcutoff_scalar);
235 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
238 /* #if KERNEL_MOD_VDW=='PotentialShift' */
239 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
240 rvdw = _mm_set1_ps(fr->rvdw);
243 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
244 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
245 rswitch_scalar = fr->rcoulomb_switch;
246 rswitch = _mm_set1_ps(rswitch_scalar);
248 rswitch_scalar = fr->rvdw_switch;
249 rswitch = _mm_set1_ps(rswitch_scalar);
251 /* Setup switch parameters */
252 d_scalar = rcutoff_scalar-rswitch_scalar;
253 d = _mm_set1_ps(d_scalar);
254 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
255 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
256 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
257 /* #if 'Force' in KERNEL_VF */
258 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
259 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
260 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
264 /* Avoid stupid compiler warnings */
265 jnrA = jnrB = jnrC = jnrD = 0;
271 /* ## Keep track of the floating point operations we issue for reporting! */
272 /* #define OUTERFLOPS 0 */
276 for(iidx=0;iidx<4*DIM;iidx++)
281 /* Start outer loop over neighborlists */
282 for(iidx=0; iidx<nri; iidx++)
284 /* Load shift vector for this list */
285 i_shift_offset = DIM*shiftidx[iidx];
287 /* Load limits for loop over neighbors */
288 j_index_start = jindex[iidx];
289 j_index_end = jindex[iidx+1];
291 /* Get outer coordinate index */
293 i_coord_offset = DIM*inr;
295 /* Load i particle coords and add shift vector */
296 /* #if GEOMETRY_I == 'Particle' */
297 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
298 /* #elif GEOMETRY_I == 'Water3' */
299 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
300 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
301 /* #elif GEOMETRY_I == 'Water4' */
302 /* #if 0 in PARTICLES_I */
303 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
304 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
306 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
307 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
311 /* #if 'Force' in KERNEL_VF */
312 /* #for I in PARTICLES_I */
313 fix{I} = _mm_setzero_ps();
314 fiy{I} = _mm_setzero_ps();
315 fiz{I} = _mm_setzero_ps();
319 /* ## For water we already preloaded parameters at the start of the kernel */
320 /* #if not 'Water' in GEOMETRY_I */
321 /* Load parameters for i particles */
322 /* #for I in PARTICLES_ELEC_I */
323 iq{I} = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+{I}));
324 /* #define OUTERFLOPS OUTERFLOPS+1 */
325 /* #if KERNEL_ELEC=='GeneralizedBorn' */
326 isai{I} = _mm_load1_ps(invsqrta+inr+{I});
329 /* #for I in PARTICLES_VDW_I */
330 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
334 /* #if 'Potential' in KERNEL_VF */
335 /* Reset potential sums */
336 /* #if KERNEL_ELEC != 'None' */
337 velecsum = _mm_setzero_ps();
339 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
340 vgbsum = _mm_setzero_ps();
342 /* #if KERNEL_VDW != 'None' */
343 vvdwsum = _mm_setzero_ps();
346 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
347 dvdasum = _mm_setzero_ps();
350 /* #for ROUND in ['Loop','Epilogue'] */
352 /* #if ROUND =='Loop' */
353 /* Start inner kernel loop */
354 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
356 /* ## First round is normal loop (next statement resets indentation) */
363 /* ## Second round is epilogue */
365 /* #define INNERFLOPS 0 */
367 /* Get j neighbor index, and coordinate index */
368 /* #if ROUND =='Loop' */
374 jnrlistA = jjnr[jidx];
375 jnrlistB = jjnr[jidx+1];
376 jnrlistC = jjnr[jidx+2];
377 jnrlistD = jjnr[jidx+3];
378 /* Sign of each element will be negative for non-real atoms.
379 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
380 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
382 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
383 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
384 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
385 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
386 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
388 j_coord_offsetA = DIM*jnrA;
389 j_coord_offsetB = DIM*jnrB;
390 j_coord_offsetC = DIM*jnrC;
391 j_coord_offsetD = DIM*jnrD;
393 /* load j atom coordinates */
394 /* #if GEOMETRY_J == 'Particle' */
395 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
396 x+j_coord_offsetC,x+j_coord_offsetD,
398 /* #elif GEOMETRY_J == 'Water3' */
399 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
400 x+j_coord_offsetC,x+j_coord_offsetD,
401 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
402 /* #elif GEOMETRY_J == 'Water4' */
403 /* #if 0 in PARTICLES_J */
404 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
405 x+j_coord_offsetC,x+j_coord_offsetD,
406 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
407 &jy2,&jz2,&jx3,&jy3,&jz3);
409 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
410 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
411 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
415 /* Calculate displacement vector */
416 /* #for I,J in PAIRS_IJ */
417 dx{I}{J} = _mm_sub_ps(ix{I},jx{J});
418 dy{I}{J} = _mm_sub_ps(iy{I},jy{J});
419 dz{I}{J} = _mm_sub_ps(iz{I},jz{J});
420 /* #define INNERFLOPS INNERFLOPS+3 */
423 /* Calculate squared distance and things based on it */
424 /* #for I,J in PAIRS_IJ */
425 rsq{I}{J} = gmx_mm_calc_rsq_ps(dx{I}{J},dy{I}{J},dz{I}{J});
426 /* #define INNERFLOPS INNERFLOPS+5 */
429 /* #for I,J in PAIRS_IJ */
430 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
431 rinv{I}{J} = gmx_mm_invsqrt_ps(rsq{I}{J});
432 /* #define INNERFLOPS INNERFLOPS+5 */
436 /* #for I,J in PAIRS_IJ */
437 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
438 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
439 rinvsq{I}{J} = gmx_mm_inv_ps(rsq{I}{J});
440 /* #define INNERFLOPS INNERFLOPS+4 */
442 rinvsq{I}{J} = _mm_mul_ps(rinv{I}{J},rinv{I}{J});
443 /* #define INNERFLOPS INNERFLOPS+1 */
448 /* #if not 'Water' in GEOMETRY_J */
449 /* Load parameters for j particles */
450 /* #for J in PARTICLES_ELEC_J */
451 jq{J} = gmx_mm_load_4real_swizzle_ps(charge+jnrA+{J},charge+jnrB+{J},
452 charge+jnrC+{J},charge+jnrD+{J});
453 /* #if KERNEL_ELEC=='GeneralizedBorn' */
454 isaj{J} = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+{J},invsqrta+jnrB+{J},
455 invsqrta+jnrC+{J},invsqrta+jnrD+{J});
458 /* #for J in PARTICLES_VDW_J */
459 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
460 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
461 vdwjidx{J}C = 2*vdwtype[jnrC+{J}];
462 vdwjidx{J}D = 2*vdwtype[jnrD+{J}];
466 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
467 /* #for J in PARTICLES_J */
468 fjx{J} = _mm_setzero_ps();
469 fjy{J} = _mm_setzero_ps();
470 fjz{J} = _mm_setzero_ps();
474 /* #for I,J in PAIRS_IJ */
476 /**************************
477 * CALCULATE INTERACTIONS *
478 **************************/
480 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
481 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
482 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
483 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
485 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
488 /* #define INNERFLOPS INNERFLOPS+1 */
491 /* #if 'r' in INTERACTION_FLAGS[I][J] */
492 r{I}{J} = _mm_mul_ps(rsq{I}{J},rinv{I}{J});
493 /* #if ROUND == 'Epilogue' */
494 r{I}{J} = _mm_andnot_ps(dummy_mask,r{I}{J});
495 /* #define INNERFLOPS INNERFLOPS+1 */
497 /* #define INNERFLOPS INNERFLOPS+1 */
500 /* ## For water geometries we already loaded parameters at the start of the kernel */
501 /* #if not 'Water' in GEOMETRY_J */
502 /* Compute parameters for interactions between i and j atoms */
503 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
504 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
505 /* #define INNERFLOPS INNERFLOPS+1 */
507 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
508 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset{I}+vdwjidx{J}A,
509 vdwparam+vdwioffset{I}+vdwjidx{J}B,
510 vdwparam+vdwioffset{I}+vdwjidx{J}C,
511 vdwparam+vdwioffset{I}+vdwjidx{J}D,
512 &c6_{I}{J},&c12_{I}{J});
516 /* #if 'table' in INTERACTION_FLAGS[I][J] */
517 /* Calculate table index by multiplying r with table scale and truncate to integer */
518 rt = _mm_mul_ps(r{I}{J},vftabscale);
519 vfitab = _mm_cvttps_epi32(rt);
521 vfeps = _mm_frcz_ps(rt);
523 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
525 twovfeps = _mm_add_ps(vfeps,vfeps);
526 /* #define INNERFLOPS INNERFLOPS+4 */
527 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
528 /* ## 3 tables, 4 bytes per point: multiply index by 12 */
529 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
530 /* #elif 'Table' in KERNEL_ELEC */
531 /* ## 1 table, 4 bytes per point: multiply index by 4 */
532 vfitab = _mm_slli_epi32(vfitab,2);
533 /* #elif 'Table' in KERNEL_VDW */
534 /* ## 2 tables, 4 bytes per point: multiply index by 8 */
535 vfitab = _mm_slli_epi32(vfitab,3);
539 /* ## ELECTROSTATIC INTERACTIONS */
540 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
542 /* #if KERNEL_ELEC=='Coulomb' */
544 /* COULOMB ELECTROSTATICS */
545 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
546 /* #define INNERFLOPS INNERFLOPS+1 */
547 /* #if 'Force' in KERNEL_VF */
548 felec = _mm_mul_ps(velec,rinvsq{I}{J});
549 /* #define INNERFLOPS INNERFLOPS+2 */
552 /* #elif KERNEL_ELEC=='ReactionField' */
554 /* REACTION-FIELD ELECTROSTATICS */
555 /* #if 'Potential' in KERNEL_VF */
556 velec = _mm_mul_ps(qq{I}{J},_mm_sub_ps(_mm_macc_ps(krf,rsq{I}{J},rinv{I}{J}),crf));
557 /* #define INNERFLOPS INNERFLOPS+4 */
559 /* #if 'Force' in KERNEL_VF */
560 felec = _mm_mul_ps(qq{I}{J},_mm_msub_ps(rinv{I}{J},rinvsq{I}{J},krf2));
561 /* #define INNERFLOPS INNERFLOPS+3 */
564 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
566 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
567 isaprod = _mm_mul_ps(isai{I},isaj{J});
568 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq{I}{J},_mm_mul_ps(isaprod,gbinvepsdiff)));
569 gbscale = _mm_mul_ps(isaprod,gbtabscale);
570 /* #define INNERFLOPS INNERFLOPS+5 */
572 /* Calculate generalized born table index - this is a separate table from the normal one,
573 * but we use the same procedure by multiplying r with scale and truncating to integer.
575 rt = _mm_mul_ps(r{I}{J},gbscale);
576 gbitab = _mm_cvttps_epi32(rt);
578 gbeps = _mm_frcz_ps(rt);
580 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
582 gbitab = _mm_slli_epi32(gbitab,2);
584 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
585 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
586 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
587 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
588 _MM_TRANSPOSE4_PS(Y,F,G,H);
589 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
590 VV = _mm_macc_ps(gbeps,Fp,Y);
591 vgb = _mm_mul_ps(gbqqfactor,VV);
592 /* #define INNERFLOPS INNERFLOPS+10 */
594 /* #if 'Force' in KERNEL_VF */
595 twogbeps = _mm_add_ps(gbeps,gbeps);
596 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
597 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
598 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r{I}{J},vgb));
599 /* #if ROUND == 'Epilogue' */
600 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
602 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
603 /* #if ROUND == 'Loop' */
609 /* 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. */
610 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
611 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
612 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
613 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
615 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj{J},isaj{J})));
616 /* #define INNERFLOPS INNERFLOPS+13 */
618 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
619 /* #define INNERFLOPS INNERFLOPS+1 */
620 /* #if 'Force' in KERNEL_VF */
621 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv{I}{J},fgb),rinv{I}{J});
622 /* #define INNERFLOPS INNERFLOPS+3 */
625 /* #elif KERNEL_ELEC=='Ewald' */
626 /* EWALD ELECTROSTATICS */
628 /* Analytical PME correction */
629 zeta2 = _mm_mul_ps(beta2,rsq{I}{J});
630 /* #if 'Force' in KERNEL_VF */
631 rinv3 = _mm_mul_ps(rinvsq{I}{J},rinv{I}{J});
632 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
633 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
634 felec = _mm_mul_ps(qq{I}{J},felec);
636 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
637 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
638 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
639 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv{I}{J},sh_ewald));
641 velec = _mm_nmacc_ps(pmecorrV,beta,rinv{I}{J});
643 velec = _mm_mul_ps(qq{I}{J},velec);
646 /* #elif KERNEL_ELEC=='CubicSplineTable' */
648 /* CUBIC SPLINE TABLE ELECTROSTATICS */
649 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
650 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
651 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
652 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
653 _MM_TRANSPOSE4_PS(Y,F,G,H);
654 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
655 /* #define INNERFLOPS INNERFLOPS+4 */
656 /* #if 'Potential' in KERNEL_VF */
657 VV = _mm_macc_ps(vfeps,Fp,Y);
658 velec = _mm_mul_ps(qq{I}{J},VV);
659 /* #define INNERFLOPS INNERFLOPS+3 */
661 /* #if 'Force' in KERNEL_VF */
662 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
663 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq{I}{J},FF),_mm_mul_ps(vftabscale,rinv{I}{J})));
664 /* #define INNERFLOPS INNERFLOPS+7 */
667 /* ## End of check for electrostatics interaction forms */
669 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
671 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
673 /* #if KERNEL_VDW=='LennardJones' */
675 /* LENNARD-JONES DISPERSION/REPULSION */
677 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
678 /* #define INNERFLOPS INNERFLOPS+2 */
679 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
680 vvdw6 = _mm_mul_ps(c6_{I}{J},rinvsix);
681 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
682 /* #define INNERFLOPS INNERFLOPS+3 */
683 /* #if KERNEL_MOD_VDW=='PotentialShift' */
684 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
685 _mm_mul_ps( _mm_nmacc_ps(c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
686 /* #define INNERFLOPS INNERFLOPS+8 */
688 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
689 /* #define INNERFLOPS INNERFLOPS+3 */
691 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
692 /* #if 'Force' in KERNEL_VF */
693 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq{I}{J});
694 /* #define INNERFLOPS INNERFLOPS+2 */
696 /* #elif KERNEL_VF=='Force' */
697 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
698 fvdw = _mm_mul_ps(_mm_msub_ps(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_ps(rinvsix,rinvsq{I}{J}));
699 /* #define INNERFLOPS INNERFLOPS+4 */
702 /* #elif KERNEL_VDW=='CubicSplineTable' */
704 /* CUBIC SPLINE TABLE DISPERSION */
705 /* #if 'Table' in KERNEL_ELEC */
706 vfitab = _mm_add_epi32(vfitab,ifour);
708 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
709 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
710 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
711 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
712 _MM_TRANSPOSE4_PS(Y,F,G,H);
713 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
714 /* #define INNERFLOPS INNERFLOPS+4 */
715 /* #if 'Potential' in KERNEL_VF */
716 VV = _mm_macc_ps(vfeps,Fp,Y);
717 vvdw6 = _mm_mul_ps(c6_{I}{J},VV);
718 /* #define INNERFLOPS INNERFLOPS+3 */
720 /* #if 'Force' in KERNEL_VF */
721 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
722 fvdw6 = _mm_mul_ps(c6_{I}{J},FF);
723 /* #define INNERFLOPS INNERFLOPS+4 */
726 /* CUBIC SPLINE TABLE REPULSION */
727 vfitab = _mm_add_epi32(vfitab,ifour);
728 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
729 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
730 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
731 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
732 _MM_TRANSPOSE4_PS(Y,F,G,H);
733 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
734 /* #define INNERFLOPS INNERFLOPS+4 */
735 /* #if 'Potential' in KERNEL_VF */
736 VV = _mm_macc_ps(vfeps,Fp,Y);
737 vvdw12 = _mm_mul_ps(c12_{I}{J},VV);
738 /* #define INNERFLOPS INNERFLOPS+3 */
740 /* #if 'Force' in KERNEL_VF */
741 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
742 fvdw12 = _mm_mul_ps(c12_{I}{J},FF);
743 /* #define INNERFLOPS INNERFLOPS+5 */
745 /* #if 'Potential' in KERNEL_VF */
746 vvdw = _mm_add_ps(vvdw12,vvdw6);
747 /* #define INNERFLOPS INNERFLOPS+1 */
749 /* #if 'Force' in KERNEL_VF */
750 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv{I}{J})));
751 /* #define INNERFLOPS INNERFLOPS+4 */
754 /* ## End of check for vdw interaction forms */
756 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
758 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
759 d = _mm_sub_ps(r{I}{J},rswitch);
760 d = _mm_max_ps(d,_mm_setzero_ps());
761 d2 = _mm_mul_ps(d,d);
762 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
763 /* #define INNERFLOPS INNERFLOPS+10 */
765 /* #if 'Force' in KERNEL_VF */
766 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
767 /* #define INNERFLOPS INNERFLOPS+5 */
770 /* Evaluate switch function */
771 /* #if 'Force' in KERNEL_VF */
772 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
773 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
774 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(velec,dsw)) );
775 /* #define INNERFLOPS INNERFLOPS+4 */
777 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
778 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(vvdw,dsw)) );
779 /* #define INNERFLOPS INNERFLOPS+4 */
782 /* #if 'Potential' in KERNEL_VF */
783 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
784 velec = _mm_mul_ps(velec,sw);
785 /* #define INNERFLOPS INNERFLOPS+1 */
787 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
788 vvdw = _mm_mul_ps(vvdw,sw);
789 /* #define INNERFLOPS INNERFLOPS+1 */
793 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
794 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
795 cutoff_mask = _mm_cmplt_ps(rsq{I}{J},rcutoff2);
796 /* #define INNERFLOPS INNERFLOPS+1 */
799 /* #if 'Potential' in KERNEL_VF */
800 /* Update potential sum for this i atom from the interaction with this j atom. */
801 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
802 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
803 velec = _mm_and_ps(velec,cutoff_mask);
804 /* #define INNERFLOPS INNERFLOPS+1 */
806 /* #if ROUND == 'Epilogue' */
807 velec = _mm_andnot_ps(dummy_mask,velec);
809 velecsum = _mm_add_ps(velecsum,velec);
810 /* #define INNERFLOPS INNERFLOPS+1 */
811 /* #if KERNEL_ELEC=='GeneralizedBorn' */
812 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
813 vgb = _mm_and_ps(vgb,cutoff_mask);
814 /* #define INNERFLOPS INNERFLOPS+1 */
816 /* #if ROUND == 'Epilogue' */
817 vgb = _mm_andnot_ps(dummy_mask,vgb);
819 vgbsum = _mm_add_ps(vgbsum,vgb);
820 /* #define INNERFLOPS INNERFLOPS+1 */
823 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
824 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
825 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
826 vvdw = _mm_and_ps(vvdw,cutoff_mask);
827 /* #define INNERFLOPS INNERFLOPS+1 */
829 /* #if ROUND == 'Epilogue' */
830 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
832 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
833 /* #define INNERFLOPS INNERFLOPS+1 */
837 /* #if 'Force' in KERNEL_VF */
839 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
840 fscal = _mm_add_ps(felec,fvdw);
841 /* #define INNERFLOPS INNERFLOPS+1 */
842 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
844 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
848 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
849 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
850 fscal = _mm_and_ps(fscal,cutoff_mask);
851 /* #define INNERFLOPS INNERFLOPS+1 */
854 /* #if ROUND == 'Epilogue' */
855 fscal = _mm_andnot_ps(dummy_mask,fscal);
858 /* ## Construction of vectorial force built into FMA instructions now */
859 /* #define INNERFLOPS INNERFLOPS+3 */
861 /* Update vectorial force */
862 fix{I} = _mm_macc_ps(dx{I}{J},fscal,fix{I});
863 fiy{I} = _mm_macc_ps(dy{I}{J},fscal,fiy{I});
864 fiz{I} = _mm_macc_ps(dz{I}{J},fscal,fiz{I});
865 /* #define INNERFLOPS INNERFLOPS+6 */
867 /* #if GEOMETRY_I == 'Particle' */
868 /* #if ROUND == 'Loop' */
869 fjptrA = f+j_coord_offsetA;
870 fjptrB = f+j_coord_offsetB;
871 fjptrC = f+j_coord_offsetC;
872 fjptrD = f+j_coord_offsetD;
874 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
875 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
876 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
877 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
879 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
880 _mm_mul_ps(dx{I}{J},fscal),
881 _mm_mul_ps(dy{I}{J},fscal),
882 _mm_mul_ps(dz{I}{J},fscal));
883 /* #define INNERFLOPS INNERFLOPS+3 */
885 fjx{J} = _mm_macc_ps(dx{I}{J},fscal,fjx{J});
886 fjy{J} = _mm_macc_ps(dy{I}{J},fscal,fjy{J});
887 fjz{J} = _mm_macc_ps(dz{I}{J},fscal,fjz{J});
888 /* #define INNERFLOPS INNERFLOPS+3 */
893 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
894 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
895 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
900 /* ## End of check for the interaction being outside the cutoff */
903 /* ## End of loop over i-j interaction pairs */
905 /* #if GEOMETRY_I != 'Particle' */
906 /* #if ROUND == 'Loop' */
907 fjptrA = f+j_coord_offsetA;
908 fjptrB = f+j_coord_offsetB;
909 fjptrC = f+j_coord_offsetC;
910 fjptrD = f+j_coord_offsetD;
912 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
913 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
914 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
915 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
919 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
920 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
921 /* #elif GEOMETRY_J == 'Water3' */
922 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
923 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
924 /* #define INNERFLOPS INNERFLOPS+9 */
925 /* #elif GEOMETRY_J == 'Water4' */
926 /* #if 0 in PARTICLES_J */
927 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
928 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
929 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
930 /* #define INNERFLOPS INNERFLOPS+12 */
932 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
933 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
934 /* #define INNERFLOPS INNERFLOPS+9 */
938 /* Inner loop uses {INNERFLOPS} flops */
943 /* End of innermost loop */
945 /* #if 'Force' in KERNEL_VF */
946 /* #if GEOMETRY_I == 'Particle' */
947 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
948 f+i_coord_offset,fshift+i_shift_offset);
949 /* #define OUTERFLOPS OUTERFLOPS+6 */
950 /* #elif GEOMETRY_I == 'Water3' */
951 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
952 f+i_coord_offset,fshift+i_shift_offset);
953 /* #define OUTERFLOPS OUTERFLOPS+18 */
954 /* #elif GEOMETRY_I == 'Water4' */
955 /* #if 0 in PARTICLES_I */
956 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
957 f+i_coord_offset,fshift+i_shift_offset);
958 /* #define OUTERFLOPS OUTERFLOPS+24 */
960 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
961 f+i_coord_offset+DIM,fshift+i_shift_offset);
962 /* #define OUTERFLOPS OUTERFLOPS+18 */
967 /* #if 'Potential' in KERNEL_VF */
969 /* Update potential energies */
970 /* #if KERNEL_ELEC != 'None' */
971 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
972 /* #define OUTERFLOPS OUTERFLOPS+1 */
974 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
975 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
976 /* #define OUTERFLOPS OUTERFLOPS+1 */
978 /* #if KERNEL_VDW != 'None' */
979 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
980 /* #define OUTERFLOPS OUTERFLOPS+1 */
983 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
984 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai{I},isai{I}));
985 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
988 /* Increment number of inner iterations */
989 inneriter += j_index_end - j_index_start;
991 /* Outer loop uses {OUTERFLOPS} flops */
994 /* Increment number of outer iterations */
997 /* Update outer/inner flops */
998 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
999 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1000 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1001 /* #if GEOMETRY_I == 'Water3' */
1002 /* #define ISUFFIX '_W3' */
1003 /* #elif GEOMETRY_I == 'Water4' */
1004 /* #define ISUFFIX '_W4' */
1006 /* #define ISUFFIX '' */
1008 /* #if GEOMETRY_J == 'Water3' */
1009 /* #define JSUFFIX 'W3' */
1010 /* #elif GEOMETRY_J == 'Water4' */
1011 /* #define JSUFFIX 'W4' */
1013 /* #define JSUFFIX '' */
1015 /* #if 'PotentialAndForce' in KERNEL_VF */
1016 /* #define VFSUFFIX '_VF' */
1017 /* #elif 'Potential' in KERNEL_VF */
1018 /* #define VFSUFFIX '_V' */
1020 /* #define VFSUFFIX '_F' */
1023 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1024 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1025 /* #elif KERNEL_ELEC != 'None' */
1026 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1028 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});