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_double.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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
111 int j_coord_offsetA,j_coord_offsetB;
112 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
114 real *shiftvec,*fshift,*x,*f;
115 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
116 /* #for I in PARTICLES_I */
118 __m128d ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
120 /* #for J in PARTICLES_J */
121 int vdwjidx{J}A,vdwjidx{J}B;
122 __m128d jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
124 /* #for I,J in PAIRS_IJ */
125 __m128d 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};
127 /* #if KERNEL_ELEC != 'None' */
128 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
131 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
133 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
134 __m128d minushalf = _mm_set1_pd(-0.5);
135 real *invsqrta,*dvda,*gbtab;
137 /* #if KERNEL_VDW != 'None' */
139 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
142 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
143 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
145 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
147 __m128i ifour = _mm_set1_epi32(4);
148 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
151 /* #if 'LJEwald' in KERNEL_VDW */
152 /* #for I,J in PAIRS_IJ */
153 __m128d c6grid_{I}{J};
156 __m128d ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
157 __m128d one_half = _mm_set1_pd(0.5);
158 __m128d minus_one = _mm_set1_pd(-1.0);
160 /* #if 'Ewald' in KERNEL_ELEC */
162 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
165 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
166 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
167 real rswitch_scalar,d_scalar;
169 __m128d dummy_mask,cutoff_mask;
170 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
171 __m128d one = _mm_set1_pd(1.0);
172 __m128d two = _mm_set1_pd(2.0);
178 jindex = nlist->jindex;
180 shiftidx = nlist->shift;
182 shiftvec = fr->shift_vec[0];
183 fshift = fr->fshift[0];
184 /* #if KERNEL_ELEC != 'None' */
185 facel = _mm_set1_pd(fr->ic->epsfac);
186 charge = mdatoms->chargeA;
187 /* #if 'ReactionField' in KERNEL_ELEC */
188 krf = _mm_set1_pd(fr->ic->k_rf);
189 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
190 crf = _mm_set1_pd(fr->ic->c_rf);
193 /* #if KERNEL_VDW != 'None' */
194 nvdwtype = fr->ntype;
196 vdwtype = mdatoms->typeA;
198 /* #if 'LJEwald' in KERNEL_VDW */
199 vdwgridparam = fr->ljpme_c6grid;
200 sh_lj_ewald = _mm_set1_pd(fr->ic->sh_lj_ewald);
201 ewclj = _mm_set1_pd(fr->ic->ewaldcoeff_lj);
202 ewclj2 = _mm_mul_pd(minus_one,_mm_mul_pd(ewclj,ewclj));
205 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
206 vftab = kernel_data->table_elec_vdw->data;
207 vftabscale = _mm_set1_pd(kernel_data->table_elec_vdw->scale);
208 /* #elif 'Table' in KERNEL_ELEC */
209 vftab = kernel_data->table_elec->data;
210 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
211 /* #elif 'Table' in KERNEL_VDW */
212 vftab = kernel_data->table_vdw->data;
213 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
216 /* #if 'Ewald' in KERNEL_ELEC */
217 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
218 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
219 ewtab = fr->ic->tabq_coul_F;
220 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
221 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
223 ewtab = fr->ic->tabq_coul_FDV0;
224 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
225 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
229 /* #if KERNEL_ELEC=='GeneralizedBorn' */
230 invsqrta = fr->invsqrta;
232 gbtabscale = _mm_set1_pd(fr->gbtab->scale);
233 gbtab = fr->gbtab->data;
234 gbinvepsdiff = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
237 /* #if 'Water' in GEOMETRY_I */
238 /* Setup water-specific parameters */
239 inr = nlist->iinr[0];
240 /* #for I in PARTICLES_ELEC_I */
241 iq{I} = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+{I}]));
243 /* #for I in PARTICLES_VDW_I */
244 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
248 /* #if 'Water' in GEOMETRY_J */
249 /* #for J in PARTICLES_ELEC_J */
250 jq{J} = _mm_set1_pd(charge[inr+{J}]);
252 /* #for J in PARTICLES_VDW_J */
253 vdwjidx{J}A = 2*vdwtype[inr+{J}];
255 /* #for I,J in PAIRS_IJ */
256 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
257 qq{I}{J} = _mm_mul_pd(iq{I},jq{J});
259 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
260 /* #if 'LJEwald' in KERNEL_VDW */
261 c6_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
262 c12_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
263 c6grid_{I}{J} = _mm_set1_pd(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
265 c6_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
266 c12_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
272 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
273 /* #if KERNEL_ELEC!='None' */
274 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
275 rcutoff_scalar = fr->ic->rcoulomb;
277 rcutoff_scalar = fr->ic->rvdw;
279 rcutoff = _mm_set1_pd(rcutoff_scalar);
280 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
283 /* #if KERNEL_MOD_VDW=='PotentialShift' */
284 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
285 rvdw = _mm_set1_pd(fr->ic->rvdw);
288 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
289 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
290 rswitch_scalar = fr->ic->rcoulomb_switch;
291 rswitch = _mm_set1_pd(rswitch_scalar);
293 rswitch_scalar = fr->ic->rvdw_switch;
294 rswitch = _mm_set1_pd(rswitch_scalar);
296 /* Setup switch parameters */
297 d_scalar = rcutoff_scalar-rswitch_scalar;
298 d = _mm_set1_pd(d_scalar);
299 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
300 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
301 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
302 /* #if 'Force' in KERNEL_VF */
303 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
304 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
305 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
309 /* Avoid stupid compiler warnings */
314 /* ## Keep track of the floating point operations we issue for reporting! */
315 /* #define OUTERFLOPS 0 */
319 /* Start outer loop over neighborlists */
320 for(iidx=0; iidx<nri; iidx++)
322 /* Load shift vector for this list */
323 i_shift_offset = DIM*shiftidx[iidx];
325 /* Load limits for loop over neighbors */
326 j_index_start = jindex[iidx];
327 j_index_end = jindex[iidx+1];
329 /* Get outer coordinate index */
331 i_coord_offset = DIM*inr;
333 /* Load i particle coords and add shift vector */
334 /* #if GEOMETRY_I == 'Particle' */
335 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
336 /* #elif GEOMETRY_I == 'Water3' */
337 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
338 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
339 /* #elif GEOMETRY_I == 'Water4' */
340 /* #if 0 in PARTICLES_I */
341 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
342 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
344 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
345 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
349 /* #if 'Force' in KERNEL_VF */
350 /* #for I in PARTICLES_I */
351 fix{I} = _mm_setzero_pd();
352 fiy{I} = _mm_setzero_pd();
353 fiz{I} = _mm_setzero_pd();
357 /* ## For water we already preloaded parameters at the start of the kernel */
358 /* #if not 'Water' in GEOMETRY_I */
359 /* Load parameters for i particles */
360 /* #for I in PARTICLES_ELEC_I */
361 iq{I} = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+{I}));
362 /* #define OUTERFLOPS OUTERFLOPS+1 */
363 /* #if KERNEL_ELEC=='GeneralizedBorn' */
364 isai{I} = _mm_load1_pd(invsqrta+inr+{I});
367 /* #for I in PARTICLES_VDW_I */
368 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
372 /* #if 'Potential' in KERNEL_VF */
373 /* Reset potential sums */
374 /* #if KERNEL_ELEC != 'None' */
375 velecsum = _mm_setzero_pd();
377 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
378 vgbsum = _mm_setzero_pd();
380 /* #if KERNEL_VDW != 'None' */
381 vvdwsum = _mm_setzero_pd();
384 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
385 dvdasum = _mm_setzero_pd();
388 /* #for ROUND in ['Loop','Epilogue'] */
390 /* #if ROUND =='Loop' */
391 /* Start inner kernel loop */
392 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
394 /* ## First round is normal loop (next statement resets indentation) */
401 /* ## Second round is epilogue */
403 /* #define INNERFLOPS 0 */
405 /* #if ROUND =='Loop' */
406 /* Get j neighbor index, and coordinate index */
409 j_coord_offsetA = DIM*jnrA;
410 j_coord_offsetB = DIM*jnrB;
412 /* load j atom coordinates */
413 /* #if GEOMETRY_J == 'Particle' */
414 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
416 /* #elif GEOMETRY_J == 'Water3' */
417 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
418 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
419 /* #elif GEOMETRY_J == 'Water4' */
420 /* #if 0 in PARTICLES_J */
421 gmx_mm_load_4rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
422 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
423 &jy2,&jz2,&jx3,&jy3,&jz3);
425 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
426 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
431 j_coord_offsetA = DIM*jnrA;
433 /* load j atom coordinates */
434 /* #if GEOMETRY_J == 'Particle' */
435 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
437 /* #elif GEOMETRY_J == 'Water3' */
438 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
439 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
440 /* #elif GEOMETRY_J == 'Water4' */
441 /* #if 0 in PARTICLES_J */
442 gmx_mm_load_4rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
443 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
444 &jy2,&jz2,&jx3,&jy3,&jz3);
446 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA+DIM,
447 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
452 /* Calculate displacement vector */
453 /* #for I,J in PAIRS_IJ */
454 dx{I}{J} = _mm_sub_pd(ix{I},jx{J});
455 dy{I}{J} = _mm_sub_pd(iy{I},jy{J});
456 dz{I}{J} = _mm_sub_pd(iz{I},jz{J});
457 /* #define INNERFLOPS INNERFLOPS+3 */
460 /* Calculate squared distance and things based on it */
461 /* #for I,J in PAIRS_IJ */
462 rsq{I}{J} = gmx_mm_calc_rsq_pd(dx{I}{J},dy{I}{J},dz{I}{J});
463 /* #define INNERFLOPS INNERFLOPS+5 */
466 /* #for I,J in PAIRS_IJ */
467 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
468 rinv{I}{J} = avx128fma_invsqrt_d(rsq{I}{J});
469 /* #define INNERFLOPS INNERFLOPS+5 */
473 /* #for I,J in PAIRS_IJ */
474 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
475 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
476 rinvsq{I}{J} = avx128fma_inv_d(rsq{I}{J});
477 /* #define INNERFLOPS INNERFLOPS+4 */
479 rinvsq{I}{J} = _mm_mul_pd(rinv{I}{J},rinv{I}{J});
480 /* #define INNERFLOPS INNERFLOPS+1 */
485 /* #if not 'Water' in GEOMETRY_J */
486 /* Load parameters for j particles */
487 /* #for J in PARTICLES_ELEC_J */
488 /* #if ROUND =='Loop' */
489 jq{J} = gmx_mm_load_2real_swizzle_pd(charge+jnrA+{J},charge+jnrB+{J});
491 jq{J} = _mm_load_sd(charge+jnrA+{J});
493 /* #if KERNEL_ELEC=='GeneralizedBorn' */
494 /* #if ROUND =='Loop' */
495 isaj{J} = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+{J},invsqrta+jnrB+{J});
497 isaj{J} = _mm_load_sd(invsqrta+jnrA+{J});
501 /* #for J in PARTICLES_VDW_J */
502 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
503 /* #if ROUND =='Loop' */
504 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
509 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
510 /* #for J in PARTICLES_J */
511 fjx{J} = _mm_setzero_pd();
512 fjy{J} = _mm_setzero_pd();
513 fjz{J} = _mm_setzero_pd();
517 /* #for I,J in PAIRS_IJ */
519 /**************************
520 * CALCULATE INTERACTIONS *
521 **************************/
523 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
524 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
525 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
527 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
530 /* #define INNERFLOPS INNERFLOPS+1 */
533 /* #if 'r' in INTERACTION_FLAGS[I][J] */
534 r{I}{J} = _mm_mul_pd(rsq{I}{J},rinv{I}{J});
535 /* #define INNERFLOPS INNERFLOPS+1 */
538 /* ## For water geometries we already loaded parameters at the start of the kernel */
539 /* #if not 'Water' in GEOMETRY_J */
540 /* Compute parameters for interactions between i and j atoms */
541 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
542 qq{I}{J} = _mm_mul_pd(iq{I},jq{J});
543 /* #define INNERFLOPS INNERFLOPS+1 */
545 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
546 /* #if ROUND == 'Loop' */
547 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset{I}+vdwjidx{J}A,
548 vdwparam+vdwioffset{I}+vdwjidx{J}B,&c6_{I}{J},&c12_{I}{J});
549 /* #if 'LJEwald' in KERNEL_VDW */
550 c6grid_{I}{J} = gmx_mm_load_2real_swizzle_pd(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
551 vdwgridparam+vdwioffset{I}+vdwjidx{J}B);
554 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset{I}+vdwjidx{J}A,&c6_{I}{J},&c12_{I}{J});
555 /* #if 'LJEwald' in KERNEL_VDW */
556 c6grid_{I}{J} = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset{I}+vdwjidx{J}A);
562 /* #if 'table' in INTERACTION_FLAGS[I][J] */
563 /* Calculate table index by multiplying r with table scale and truncate to integer */
564 rt = _mm_mul_pd(r{I}{J},vftabscale);
565 vfitab = _mm_cvttpd_epi32(rt);
567 vfeps = _mm_frcz_pd(rt);
569 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
571 twovfeps = _mm_add_pd(vfeps,vfeps);
572 /* #define INNERFLOPS INNERFLOPS+4 */
573 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
574 /* ## 3 tables, 4 data per point: multiply index by 12 */
575 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
576 /* #elif 'Table' in KERNEL_ELEC */
577 /* ## 1 table, 4 data per point: multiply index by 4 */
578 vfitab = _mm_slli_epi32(vfitab,2);
579 /* #elif 'Table' in KERNEL_VDW */
580 /* ## 2 tables, 4 data per point: multiply index by 8 */
581 vfitab = _mm_slli_epi32(vfitab,3);
585 /* ## ELECTROSTATIC INTERACTIONS */
586 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
588 /* #if KERNEL_ELEC=='Coulomb' */
590 /* COULOMB ELECTROSTATICS */
591 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
592 /* #define INNERFLOPS INNERFLOPS+1 */
593 /* #if 'Force' in KERNEL_VF */
594 felec = _mm_mul_pd(velec,rinvsq{I}{J});
595 /* #define INNERFLOPS INNERFLOPS+2 */
598 /* #elif KERNEL_ELEC=='ReactionField' */
600 /* REACTION-FIELD ELECTROSTATICS */
601 /* #if 'Potential' in KERNEL_VF */
602 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_macc_pd(krf,rsq{I}{J},rinv{I}{J}),crf));
603 /* #define INNERFLOPS INNERFLOPS+4 */
605 /* #if 'Force' in KERNEL_VF */
606 felec = _mm_mul_pd(qq{I}{J},_mm_msub_pd(rinv{I}{J},rinvsq{I}{J},krf2));
607 /* #define INNERFLOPS INNERFLOPS+3 */
610 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
612 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
613 isaprod = _mm_mul_pd(isai{I},isaj{J});
614 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq{I}{J},_mm_mul_pd(isaprod,gbinvepsdiff)));
615 gbscale = _mm_mul_pd(isaprod,gbtabscale);
616 /* #define INNERFLOPS INNERFLOPS+5 */
618 /* Calculate generalized born table index - this is a separate table from the normal one,
619 * but we use the same procedure by multiplying r with scale and truncating to integer.
621 rt = _mm_mul_pd(r{I}{J},gbscale);
622 gbitab = _mm_cvttpd_epi32(rt);
624 gbeps = _mm_frcz_pd(rt);
626 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
628 gbitab = _mm_slli_epi32(gbitab,2);
630 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
631 /* #if ROUND == 'Loop' */
632 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
634 F = _mm_setzero_pd();
636 GMX_MM_TRANSPOSE2_PD(Y,F);
637 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
638 /* #if ROUND == 'Loop' */
639 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
641 H = _mm_setzero_pd();
643 GMX_MM_TRANSPOSE2_PD(G,H);
644 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
645 VV = _mm_macc_pd(gbeps,Fp,Y);
646 vgb = _mm_mul_pd(gbqqfactor,VV);
647 /* #define INNERFLOPS INNERFLOPS+10 */
649 /* #if 'Force' in KERNEL_VF */
650 twogbeps = _mm_add_pd(gbeps,gbeps);
651 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
652 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
653 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r{I}{J},vgb));
654 /* #if ROUND == 'Epilogue' */
655 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
657 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
658 /* #if ROUND == 'Loop' */
659 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
661 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
663 /* #define INNERFLOPS INNERFLOPS+13 */
665 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
666 /* #define INNERFLOPS INNERFLOPS+1 */
667 /* #if 'Force' in KERNEL_VF */
668 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv{I}{J},fgb),rinv{I}{J});
669 /* #define INNERFLOPS INNERFLOPS+3 */
672 /* #elif KERNEL_ELEC=='Ewald' */
673 /* EWALD ELECTROSTATICS */
675 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
676 ewrt = _mm_mul_pd(r{I}{J},ewtabscale);
677 ewitab = _mm_cvttpd_epi32(ewrt);
679 eweps = _mm_frcz_pd(ewrt);
681 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
683 twoeweps = _mm_add_pd(eweps,eweps);
684 /* #define INNERFLOPS INNERFLOPS+4 */
685 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
686 ewitab = _mm_slli_epi32(ewitab,2);
687 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
688 /* #if ROUND == 'Loop' */
689 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
691 ewtabD = _mm_setzero_pd();
693 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
694 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
695 /* #if ROUND == 'Loop' */
696 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
698 ewtabFn = _mm_setzero_pd();
700 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
701 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
702 /* #define INNERFLOPS INNERFLOPS+2 */
703 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
704 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
705 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_sub_pd(rinv{I}{J},sh_ewald),velec));
706 /* #define INNERFLOPS INNERFLOPS+7 */
708 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
709 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(rinv{I}{J},velec));
710 /* #define INNERFLOPS INNERFLOPS+6 */
712 /* #if 'Force' in KERNEL_VF */
713 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
714 /* #define INNERFLOPS INNERFLOPS+3 */
716 /* #elif KERNEL_VF=='Force' */
717 /* #if ROUND == 'Loop' */
718 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
721 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
723 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
724 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
725 /* #define INNERFLOPS INNERFLOPS+7 */
728 /* #elif KERNEL_ELEC=='CubicSplineTable' */
730 /* CUBIC SPLINE TABLE ELECTROSTATICS */
731 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
732 /* #if ROUND == 'Loop' */
733 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
735 F = _mm_setzero_pd();
737 GMX_MM_TRANSPOSE2_PD(Y,F);
738 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
739 /* #if ROUND == 'Loop' */
740 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
742 H = _mm_setzero_pd();
744 GMX_MM_TRANSPOSE2_PD(G,H);
745 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
746 /* #define INNERFLOPS INNERFLOPS+4 */
747 /* #if 'Potential' in KERNEL_VF */
748 VV = _mm_macc_pd(vfeps,Fp,Y);
749 velec = _mm_mul_pd(qq{I}{J},VV);
750 /* #define INNERFLOPS INNERFLOPS+3 */
752 /* #if 'Force' in KERNEL_VF */
753 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
754 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq{I}{J},FF),_mm_mul_pd(vftabscale,rinv{I}{J})));
755 /* #define INNERFLOPS INNERFLOPS+7 */
758 /* ## End of check for electrostatics interaction forms */
760 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
762 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
764 /* #if KERNEL_VDW=='LennardJones' */
766 /* LENNARD-JONES DISPERSION/REPULSION */
768 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
769 /* #define INNERFLOPS INNERFLOPS+2 */
770 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
771 vvdw6 = _mm_mul_pd(c6_{I}{J},rinvsix);
772 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
773 /* #define INNERFLOPS INNERFLOPS+3 */
774 /* #if KERNEL_MOD_VDW=='PotentialShift' */
775 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
776 _mm_mul_pd(_mm_nmacc_pd( c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
777 /* #define INNERFLOPS INNERFLOPS+8 */
779 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
780 /* #define INNERFLOPS INNERFLOPS+3 */
782 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
783 /* #if 'Force' in KERNEL_VF */
784 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq{I}{J});
785 /* #define INNERFLOPS INNERFLOPS+2 */
787 /* #elif KERNEL_VF=='Force' */
788 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
789 fvdw = _mm_mul_pd(_mm_msub_pd(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_pd(rinvsix,rinvsq{I}{J}));
790 /* #define INNERFLOPS INNERFLOPS+4 */
793 /* #elif KERNEL_VDW=='CubicSplineTable' */
795 /* CUBIC SPLINE TABLE DISPERSION */
796 /* #if 'Table' in KERNEL_ELEC */
797 vfitab = _mm_add_epi32(vfitab,ifour);
799 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
800 /* #if ROUND == 'Loop' */
801 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
803 F = _mm_setzero_pd();
805 GMX_MM_TRANSPOSE2_PD(Y,F);
806 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
807 /* #if ROUND == 'Loop' */
808 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
810 H = _mm_setzero_pd();
812 GMX_MM_TRANSPOSE2_PD(G,H);
813 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
814 /* #define INNERFLOPS INNERFLOPS+4 */
815 /* #if 'Potential' in KERNEL_VF */
816 VV = _mm_macc_pd(vfeps,Fp,Y);
817 vvdw6 = _mm_mul_pd(c6_{I}{J},VV);
818 /* #define INNERFLOPS INNERFLOPS+3 */
820 /* #if 'Force' in KERNEL_VF */
821 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
822 fvdw6 = _mm_mul_pd(c6_{I}{J},FF);
823 /* #define INNERFLOPS INNERFLOPS+4 */
826 /* CUBIC SPLINE TABLE REPULSION */
827 vfitab = _mm_add_epi32(vfitab,ifour);
828 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
829 /* #if ROUND == 'Loop' */
830 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
832 F = _mm_setzero_pd();
834 GMX_MM_TRANSPOSE2_PD(Y,F);
835 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
836 /* #if ROUND == 'Loop' */
837 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
839 H = _mm_setzero_pd();
841 GMX_MM_TRANSPOSE2_PD(G,H);
842 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
843 /* #define INNERFLOPS INNERFLOPS+4 */
844 /* #if 'Potential' in KERNEL_VF */
845 VV = _mm_macc_pd(vfeps,Fp,Y);
846 vvdw12 = _mm_mul_pd(c12_{I}{J},VV);
847 /* #define INNERFLOPS INNERFLOPS+3 */
849 /* #if 'Force' in KERNEL_VF */
850 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
851 fvdw12 = _mm_mul_pd(c12_{I}{J},FF);
852 /* #define INNERFLOPS INNERFLOPS+5 */
854 /* #if 'Potential' in KERNEL_VF */
855 vvdw = _mm_add_pd(vvdw12,vvdw6);
856 /* #define INNERFLOPS INNERFLOPS+1 */
858 /* #if 'Force' in KERNEL_VF */
859 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv{I}{J})));
860 /* #define INNERFLOPS INNERFLOPS+4 */
863 /* #elif KERNEL_VDW=='LJEwald' */
865 /* Analytical LJ-PME */
866 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
867 ewcljrsq = _mm_mul_pd(ewclj2,rsq{I}{J});
868 ewclj6 = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
869 exponent = avx128fma_exp_d(ewcljrsq);
870 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
871 poly = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
872 /* #define INNERFLOPS INNERFLOPS+10 */
873 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
874 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
875 vvdw6 = _mm_mul_pd(_mm_macc_pd(-c6grid_{I}{J},_mm_sub_pd(one,poly),c6_{I}{J}),rinvsix);
876 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
877 /* #define INNERFLOPS INNERFLOPS+5 */
878 /* #if KERNEL_MOD_VDW=='PotentialShift' */
879 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
880 _mm_mul_pd(_mm_sub_pd(vvdw6,_mm_macc_pd(c6grid_{I}{J},sh_lj_ewald,_mm_mul_pd(c6_{I}{J},sh_vdw_invrcut6))),one_sixth));
881 /* #define INNERFLOPS INNERFLOPS+6 */
883 vvdw = _mm_msub_pd(vvdw12,one_twelfth,_mm_mul_pd(vvdw6,one_sixth));
884 /* #define INNERFLOPS INNERFLOPS+2 */
886 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
887 /* #if 'Force' in KERNEL_VF */
888 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
889 fvdw = _mm_mul_pd(_mm_add_pd(vvdw12,_mm_msub_pd(_mm_mul_pd(c6grid_{I}{J},one_sixth),_mm_mul_pd(exponent,ewclj6),vvdw6)),rinvsq{I}{J});
890 /* #define INNERFLOPS INNERFLOPS+5 */
892 /* #elif KERNEL_VF=='Force' */
893 /* f6A = 6 * C6grid * (1 - poly) */
894 f6A = _mm_mul_pd(c6grid_{I}{J},_mm_sub_pd(one,poly));
895 /* f6B = C6grid * exponent * beta^6 */
896 f6B = _mm_mul_pd(_mm_mul_pd(c6grid_{I}{J},one_sixth),_mm_mul_pd(exponent,ewclj6));
897 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
898 fvdw = _mm_mul_pd(_mm_macc_pd(_mm_msub_pd(c12_{I}{J},rinvsix,_mm_sub_pd(c6_{I}{J},f6A)),rinvsix,f6B),rinvsq{I}{J});
899 /* #define INNERFLOPS INNERFLOPS+10 */
902 /* ## End of check for vdw interaction forms */
904 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
906 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
907 d = _mm_sub_pd(r{I}{J},rswitch);
908 d = _mm_max_pd(d,_mm_setzero_pd());
909 d2 = _mm_mul_pd(d,d);
910 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
911 /* #define INNERFLOPS INNERFLOPS+10 */
913 /* #if 'Force' in KERNEL_VF */
914 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
915 /* #define INNERFLOPS INNERFLOPS+5 */
918 /* Evaluate switch function */
919 /* #if 'Force' in KERNEL_VF */
920 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
921 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
922 felec = _mm_msub_pd( felec,sw , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(velec,dsw)) );
923 /* #define INNERFLOPS INNERFLOPS+4 */
925 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
926 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(vvdw,dsw)) );
927 /* #define INNERFLOPS INNERFLOPS+4 */
930 /* #if 'Potential' in KERNEL_VF */
931 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
932 velec = _mm_mul_pd(velec,sw);
933 /* #define INNERFLOPS INNERFLOPS+1 */
935 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
936 vvdw = _mm_mul_pd(vvdw,sw);
937 /* #define INNERFLOPS INNERFLOPS+1 */
941 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
942 cutoff_mask = _mm_cmplt_pd(rsq{I}{J},rcutoff2);
943 /* #define INNERFLOPS INNERFLOPS+1 */
946 /* #if 'Potential' in KERNEL_VF */
947 /* Update potential sum for this i atom from the interaction with this j atom. */
948 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
949 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
950 velec = _mm_and_pd(velec,cutoff_mask);
951 /* #define INNERFLOPS INNERFLOPS+1 */
953 /* #if ROUND == 'Epilogue' */
954 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
956 velecsum = _mm_add_pd(velecsum,velec);
957 /* #define INNERFLOPS INNERFLOPS+1 */
958 /* #if KERNEL_ELEC=='GeneralizedBorn' */
959 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
960 vgb = _mm_and_pd(vgb,cutoff_mask);
961 /* #define INNERFLOPS INNERFLOPS+1 */
963 /* #if ROUND == 'Epilogue' */
964 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
966 vgbsum = _mm_add_pd(vgbsum,vgb);
967 /* #define INNERFLOPS INNERFLOPS+1 */
970 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
971 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
972 vvdw = _mm_and_pd(vvdw,cutoff_mask);
973 /* #define INNERFLOPS INNERFLOPS+1 */
975 /* #if ROUND == 'Epilogue' */
976 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
978 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
979 /* #define INNERFLOPS INNERFLOPS+1 */
983 /* #if 'Force' in KERNEL_VF */
985 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
986 fscal = _mm_add_pd(felec,fvdw);
987 /* #define INNERFLOPS INNERFLOPS+1 */
988 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
990 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
994 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
995 fscal = _mm_and_pd(fscal,cutoff_mask);
996 /* #define INNERFLOPS INNERFLOPS+1 */
999 /* #if ROUND == 'Epilogue' */
1000 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1003 /* ## Construction of vectorial force built into FMA instructions now */
1004 /* #define INNERFLOPS INNERFLOPS+3 */
1006 /* Update vectorial force */
1007 fix{I} = _mm_macc_pd(dx{I}{J},fscal,fix{I});
1008 fiy{I} = _mm_macc_pd(dy{I}{J},fscal,fiy{I});
1009 fiz{I} = _mm_macc_pd(dz{I}{J},fscal,fiz{I});
1010 /* #define INNERFLOPS INNERFLOPS+6 */
1012 /* #if GEOMETRY_I == 'Particle' */
1013 /* #if ROUND == 'Loop' */
1014 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
1015 _mm_mul_pd(dx{I}{J},fscal),
1016 _mm_mul_pd(dy{I}{J},fscal),
1017 _mm_mul_pd(dz{I}{J},fscal));
1019 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
1020 _mm_mul_pd(dx{I}{J},fscal),
1021 _mm_mul_pd(dy{I}{J},fscal),
1022 _mm_mul_pd(dz{I}{J},fscal));
1024 /* #define INNERFLOPS INNERFLOPS+3 */
1026 fjx{J} = _mm_macc_pd(dx{I}{J},fscal,fjx{J});
1027 fjy{J} = _mm_macc_pd(dy{I}{J},fscal,fjy{J});
1028 fjz{J} = _mm_macc_pd(dz{I}{J},fscal,fjz{J});
1029 /* #define INNERFLOPS INNERFLOPS+3 */
1034 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
1035 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1040 /* ## End of check for the interaction being outside the cutoff */
1043 /* ## End of loop over i-j interaction pairs */
1045 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1046 /* #if ROUND == 'Loop' */
1047 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1049 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1051 /* #define INNERFLOPS INNERFLOPS+3 */
1052 /* #elif GEOMETRY_J == 'Water3' */
1053 /* #if ROUND == 'Loop' */
1054 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1056 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1058 /* #define INNERFLOPS INNERFLOPS+9 */
1059 /* #elif GEOMETRY_J == 'Water4' */
1060 /* #if 0 in PARTICLES_J */
1061 /* #if ROUND == 'Loop' */
1062 gmx_mm_decrement_4rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1064 gmx_mm_decrement_4rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1066 /* #define INNERFLOPS INNERFLOPS+12 */
1068 /* #if ROUND == 'Loop' */
1069 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA+DIM,f+j_coord_offsetB+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1071 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1073 /* #define INNERFLOPS INNERFLOPS+9 */
1077 /* Inner loop uses {INNERFLOPS} flops */
1082 /* End of innermost loop */
1084 /* #if 'Force' in KERNEL_VF */
1085 /* #if GEOMETRY_I == 'Particle' */
1086 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
1087 f+i_coord_offset,fshift+i_shift_offset);
1088 /* #define OUTERFLOPS OUTERFLOPS+6 */
1089 /* #elif GEOMETRY_I == 'Water3' */
1090 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1091 f+i_coord_offset,fshift+i_shift_offset);
1092 /* #define OUTERFLOPS OUTERFLOPS+18 */
1093 /* #elif GEOMETRY_I == 'Water4' */
1094 /* #if 0 in PARTICLES_I */
1095 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1096 f+i_coord_offset,fshift+i_shift_offset);
1097 /* #define OUTERFLOPS OUTERFLOPS+24 */
1099 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1100 f+i_coord_offset+DIM,fshift+i_shift_offset);
1101 /* #define OUTERFLOPS OUTERFLOPS+18 */
1106 /* #if 'Potential' in KERNEL_VF */
1108 /* Update potential energies */
1109 /* #if KERNEL_ELEC != 'None' */
1110 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
1111 /* #define OUTERFLOPS OUTERFLOPS+1 */
1113 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1114 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
1115 /* #define OUTERFLOPS OUTERFLOPS+1 */
1117 /* #if KERNEL_VDW != 'None' */
1118 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
1119 /* #define OUTERFLOPS OUTERFLOPS+1 */
1122 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1123 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai{I},isai{I}));
1124 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
1127 /* Increment number of inner iterations */
1128 inneriter += j_index_end - j_index_start;
1130 /* Outer loop uses {OUTERFLOPS} flops */
1133 /* Increment number of outer iterations */
1136 /* Update outer/inner flops */
1137 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1138 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1139 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1140 /* #if GEOMETRY_I == 'Water3' */
1141 /* #define ISUFFIX '_W3' */
1142 /* #elif GEOMETRY_I == 'Water4' */
1143 /* #define ISUFFIX '_W4' */
1145 /* #define ISUFFIX '' */
1147 /* #if GEOMETRY_J == 'Water3' */
1148 /* #define JSUFFIX 'W3' */
1149 /* #elif GEOMETRY_J == 'Water4' */
1150 /* #define JSUFFIX 'W4' */
1152 /* #define JSUFFIX '' */
1154 /* #if 'PotentialAndForce' in KERNEL_VF */
1155 /* #define VFSUFFIX '_VF' */
1156 /* #elif 'Potential' in KERNEL_VF */
1157 /* #define VFSUFFIX '_V' */
1159 /* #define VFSUFFIX '_F' */
1162 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1163 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1164 /* #elif KERNEL_ELEC != 'None' */
1165 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1167 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});