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_sse4_1_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,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;
151 /* #if 'LJEwald' in KERNEL_VDW */
152 /* #for I,J in PAIRS_IJ */
153 __m128d c6grid_{I}{J};
155 __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,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} = sse41_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} = sse41_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});
556 /* #if 'LJEwald' in KERNEL_VDW */
557 c6grid_{I}{J} = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset{I}+vdwjidx{J}A);
563 /* #if 'table' in INTERACTION_FLAGS[I][J] */
564 /* Calculate table index by multiplying r with table scale and truncate to integer */
565 rt = _mm_mul_pd(r{I}{J},vftabscale);
566 vfitab = _mm_cvttpd_epi32(rt);
567 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
568 /* #define INNERFLOPS INNERFLOPS+4 */
569 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
570 /* ## 3 tables, 4 data per point: multiply index by 12 */
571 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
572 /* #elif 'Table' in KERNEL_ELEC */
573 /* ## 1 table, 4 data per point: multiply index by 4 */
574 vfitab = _mm_slli_epi32(vfitab,2);
575 /* #elif 'Table' in KERNEL_VDW */
576 /* ## 2 tables, 4 data per point: multiply index by 8 */
577 vfitab = _mm_slli_epi32(vfitab,3);
581 /* ## ELECTROSTATIC INTERACTIONS */
582 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
584 /* #if KERNEL_ELEC=='Coulomb' */
586 /* COULOMB ELECTROSTATICS */
587 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
588 /* #define INNERFLOPS INNERFLOPS+1 */
589 /* #if 'Force' in KERNEL_VF */
590 felec = _mm_mul_pd(velec,rinvsq{I}{J});
591 /* #define INNERFLOPS INNERFLOPS+2 */
594 /* #elif KERNEL_ELEC=='ReactionField' */
596 /* REACTION-FIELD ELECTROSTATICS */
597 /* #if 'Potential' in KERNEL_VF */
598 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_add_pd(rinv{I}{J},_mm_mul_pd(krf,rsq{I}{J})),crf));
599 /* #define INNERFLOPS INNERFLOPS+4 */
601 /* #if 'Force' in KERNEL_VF */
602 felec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_mul_pd(rinv{I}{J},rinvsq{I}{J}),krf2));
603 /* #define INNERFLOPS INNERFLOPS+3 */
606 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
608 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
609 isaprod = _mm_mul_pd(isai{I},isaj{J});
610 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq{I}{J},_mm_mul_pd(isaprod,gbinvepsdiff)));
611 gbscale = _mm_mul_pd(isaprod,gbtabscale);
612 /* #define INNERFLOPS INNERFLOPS+5 */
614 /* Calculate generalized born table index - this is a separate table from the normal one,
615 * but we use the same procedure by multiplying r with scale and truncating to integer.
617 rt = _mm_mul_pd(r{I}{J},gbscale);
618 gbitab = _mm_cvttpd_epi32(rt);
619 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
620 gbitab = _mm_slli_epi32(gbitab,2);
622 Y = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) );
623 /* #if ROUND == 'Loop' */
624 F = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) );
626 F = _mm_setzero_pd();
628 GMX_MM_TRANSPOSE2_PD(Y,F);
629 G = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) +2);
630 /* #if ROUND == 'Loop' */
631 H = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) +2);
633 H = _mm_setzero_pd();
635 GMX_MM_TRANSPOSE2_PD(G,H);
636 Heps = _mm_mul_pd(gbeps,H);
637 Fp = _mm_add_pd(F,_mm_mul_pd(gbeps,_mm_add_pd(G,Heps)));
638 VV = _mm_add_pd(Y,_mm_mul_pd(gbeps,Fp));
639 vgb = _mm_mul_pd(gbqqfactor,VV);
640 /* #define INNERFLOPS INNERFLOPS+10 */
642 /* #if 'Force' in KERNEL_VF */
643 FF = _mm_add_pd(Fp,_mm_mul_pd(gbeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
644 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
645 dvdatmp = _mm_mul_pd(minushalf,_mm_add_pd(vgb,_mm_mul_pd(fgb,r{I}{J})));
646 /* #if ROUND == 'Epilogue' */
647 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
649 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
650 /* #if ROUND == 'Loop' */
651 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
653 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
655 /* #define INNERFLOPS INNERFLOPS+13 */
657 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
658 /* #define INNERFLOPS INNERFLOPS+1 */
659 /* #if 'Force' in KERNEL_VF */
660 felec = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec,rinv{I}{J}),fgb),rinv{I}{J});
661 /* #define INNERFLOPS INNERFLOPS+3 */
664 /* #elif KERNEL_ELEC=='Ewald' */
665 /* EWALD ELECTROSTATICS */
667 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
668 ewrt = _mm_mul_pd(r{I}{J},ewtabscale);
669 ewitab = _mm_cvttpd_epi32(ewrt);
670 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
671 /* #define INNERFLOPS INNERFLOPS+4 */
672 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
673 ewitab = _mm_slli_epi32(ewitab,2);
674 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
675 /* #if ROUND == 'Loop' */
676 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
678 ewtabD = _mm_setzero_pd();
680 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
681 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
682 /* #if ROUND == 'Loop' */
683 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
685 ewtabFn = _mm_setzero_pd();
687 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
688 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
689 /* #define INNERFLOPS INNERFLOPS+2 */
690 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
691 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
692 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_sub_pd(rinv{I}{J},sh_ewald),velec));
693 /* #define INNERFLOPS INNERFLOPS+7 */
695 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
696 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(rinv{I}{J},velec));
697 /* #define INNERFLOPS INNERFLOPS+6 */
699 /* #if 'Force' in KERNEL_VF */
700 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
701 /* #define INNERFLOPS INNERFLOPS+3 */
703 /* #elif KERNEL_VF=='Force' */
704 /* #if ROUND == 'Loop' */
705 gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
708 gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
710 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
711 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
712 /* #define INNERFLOPS INNERFLOPS+7 */
715 /* #elif KERNEL_ELEC=='CubicSplineTable' */
717 /* CUBIC SPLINE TABLE ELECTROSTATICS */
718 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
719 /* #if ROUND == 'Loop' */
720 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
722 F = _mm_setzero_pd();
724 GMX_MM_TRANSPOSE2_PD(Y,F);
725 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
726 /* #if ROUND == 'Loop' */
727 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
729 H = _mm_setzero_pd();
731 GMX_MM_TRANSPOSE2_PD(G,H);
732 Heps = _mm_mul_pd(vfeps,H);
733 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
734 /* #define INNERFLOPS INNERFLOPS+4 */
735 /* #if 'Potential' in KERNEL_VF */
736 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
737 velec = _mm_mul_pd(qq{I}{J},VV);
738 /* #define INNERFLOPS INNERFLOPS+3 */
740 /* #if 'Force' in KERNEL_VF */
741 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
742 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq{I}{J},FF),_mm_mul_pd(vftabscale,rinv{I}{J})));
743 /* #define INNERFLOPS INNERFLOPS+7 */
746 /* ## End of check for electrostatics interaction forms */
748 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
750 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
752 /* #if KERNEL_VDW=='LennardJones' */
754 /* LENNARD-JONES DISPERSION/REPULSION */
756 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
757 /* #define INNERFLOPS INNERFLOPS+2 */
758 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
759 vvdw6 = _mm_mul_pd(c6_{I}{J},rinvsix);
760 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
761 /* #define INNERFLOPS INNERFLOPS+3 */
762 /* #if KERNEL_MOD_VDW=='PotentialShift' */
763 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
764 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_{I}{J},sh_vdw_invrcut6)),one_sixth));
765 /* #define INNERFLOPS INNERFLOPS+8 */
767 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
768 /* #define INNERFLOPS INNERFLOPS+3 */
770 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
771 /* #if 'Force' in KERNEL_VF */
772 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq{I}{J});
773 /* #define INNERFLOPS INNERFLOPS+2 */
775 /* #elif KERNEL_VF=='Force' */
776 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
777 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_{I}{J},rinvsix),c6_{I}{J}),_mm_mul_pd(rinvsix,rinvsq{I}{J}));
778 /* #define INNERFLOPS INNERFLOPS+4 */
781 /* #elif KERNEL_VDW=='CubicSplineTable' */
783 /* CUBIC SPLINE TABLE DISPERSION */
784 /* #if 'Table' in KERNEL_ELEC */
785 vfitab = _mm_add_epi32(vfitab,ifour);
787 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
788 /* #if ROUND == 'Loop' */
789 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
791 F = _mm_setzero_pd();
793 GMX_MM_TRANSPOSE2_PD(Y,F);
794 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
795 /* #if ROUND == 'Loop' */
796 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
798 H = _mm_setzero_pd();
800 GMX_MM_TRANSPOSE2_PD(G,H);
801 Heps = _mm_mul_pd(vfeps,H);
802 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
803 /* #define INNERFLOPS INNERFLOPS+4 */
804 /* #if 'Potential' in KERNEL_VF */
805 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
806 vvdw6 = _mm_mul_pd(c6_{I}{J},VV);
807 /* #define INNERFLOPS INNERFLOPS+3 */
809 /* #if 'Force' in KERNEL_VF */
810 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
811 fvdw6 = _mm_mul_pd(c6_{I}{J},FF);
812 /* #define INNERFLOPS INNERFLOPS+4 */
815 /* CUBIC SPLINE TABLE REPULSION */
816 vfitab = _mm_add_epi32(vfitab,ifour);
817 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
818 /* #if ROUND == 'Loop' */
819 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
821 F = _mm_setzero_pd();
823 GMX_MM_TRANSPOSE2_PD(Y,F);
824 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
825 /* #if ROUND == 'Loop' */
826 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
828 H = _mm_setzero_pd();
830 GMX_MM_TRANSPOSE2_PD(G,H);
831 Heps = _mm_mul_pd(vfeps,H);
832 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
833 /* #define INNERFLOPS INNERFLOPS+4 */
834 /* #if 'Potential' in KERNEL_VF */
835 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
836 vvdw12 = _mm_mul_pd(c12_{I}{J},VV);
837 /* #define INNERFLOPS INNERFLOPS+3 */
839 /* #if 'Force' in KERNEL_VF */
840 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
841 fvdw12 = _mm_mul_pd(c12_{I}{J},FF);
842 /* #define INNERFLOPS INNERFLOPS+5 */
844 /* #if 'Potential' in KERNEL_VF */
845 vvdw = _mm_add_pd(vvdw12,vvdw6);
846 /* #define INNERFLOPS INNERFLOPS+1 */
848 /* #if 'Force' in KERNEL_VF */
849 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv{I}{J})));
850 /* #define INNERFLOPS INNERFLOPS+4 */
854 /* #elif KERNEL_VDW=='LJEwald' */
856 /* Analytical LJ-PME */
857 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
858 ewcljrsq = _mm_mul_pd(ewclj2,rsq{I}{J});
859 ewclj6 = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
860 exponent = sse41_exp_d(ewcljrsq);
861 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
862 poly = _mm_mul_pd(exponent,_mm_add_pd(_mm_sub_pd(one,ewcljrsq),_mm_mul_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half)));
863 /* #define INNERFLOPS INNERFLOPS+11 */
864 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch'*/
865 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
866 vvdw6 = _mm_mul_pd(_mm_sub_pd(c6_{I}{J},_mm_mul_pd(c6grid_{I}{J},_mm_sub_pd(one,poly))),rinvsix);
867 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
868 /* #define INNERFLOPS INNERFLOPS+6 */
869 /* #if KERNEL_MOD_VDW=='PotentialShift' */
870 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))),one_twelfth),
871 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_add_pd(_mm_mul_pd(c6_{I}{J},sh_vdw_invrcut6),_mm_mul_pd(c6grid_{I}{J},sh_lj_ewald))),one_sixth));
872 /* #define INNERFLOPS INNERFLOPS+9 */
874 vvdw = _mm_sub_pd(_mm_mul_pd(vvdw12,one_twelfth),_mm_mul_pd(vvdw6,one_sixth));
875 /* #define INNERFLOPS INNERFLOPS+3 */
877 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
878 /* #if 'Force' in KERNEL_VF */
879 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
880 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,_mm_sub_pd(vvdw6,_mm_mul_pd(_mm_mul_pd(c6grid_{I}{J},one_sixth),_mm_mul_pd(exponent,ewclj6)))),rinvsq{I}{J});
881 /* #define INNERFLOPS INNERFLOPS+6 */
883 /* #elif KERNEL_VF=='Force' */
884 /* f6A = 6 * C6grid * (1 - poly) */
885 f6A = _mm_mul_pd(c6grid_{I}{J},_mm_sub_pd(one,poly));
886 /* f6B = C6grid * exponent * beta^6 */
887 f6B = _mm_mul_pd(_mm_mul_pd(c6grid_{I}{J},one_sixth),_mm_mul_pd(exponent,ewclj6));
888 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
889 fvdw = _mm_mul_pd(_mm_add_pd(_mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_{I}{J},rinvsix),_mm_sub_pd(c6_{I}{J},f6A)),rinvsix),f6B),rinvsq{I}{J});
890 /* #define INNERFLOPS INNERFLOPS+11 */
893 /* ## End of check for vdw interaction forms */
895 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
897 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
898 d = _mm_sub_pd(r{I}{J},rswitch);
899 d = _mm_max_pd(d,_mm_setzero_pd());
900 d2 = _mm_mul_pd(d,d);
901 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_add_pd(swV3,_mm_mul_pd(d,_mm_add_pd(swV4,_mm_mul_pd(d,swV5)))))));
902 /* #define INNERFLOPS INNERFLOPS+10 */
904 /* #if 'Force' in KERNEL_VF */
905 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
906 /* #define INNERFLOPS INNERFLOPS+5 */
909 /* Evaluate switch function */
910 /* #if 'Force' in KERNEL_VF */
911 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
912 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
913 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(velec,dsw)) );
914 /* #define INNERFLOPS INNERFLOPS+4 */
916 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
917 fvdw = _mm_sub_pd( _mm_mul_pd(fvdw,sw) , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(vvdw,dsw)) );
918 /* #define INNERFLOPS INNERFLOPS+4 */
921 /* #if 'Potential' in KERNEL_VF */
922 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
923 velec = _mm_mul_pd(velec,sw);
924 /* #define INNERFLOPS INNERFLOPS+1 */
926 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
927 vvdw = _mm_mul_pd(vvdw,sw);
928 /* #define INNERFLOPS INNERFLOPS+1 */
932 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
933 cutoff_mask = _mm_cmplt_pd(rsq{I}{J},rcutoff2);
934 /* #define INNERFLOPS INNERFLOPS+1 */
937 /* #if 'Potential' in KERNEL_VF */
938 /* Update potential sum for this i atom from the interaction with this j atom. */
939 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
940 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
941 velec = _mm_and_pd(velec,cutoff_mask);
942 /* #define INNERFLOPS INNERFLOPS+1 */
944 /* #if ROUND == 'Epilogue' */
945 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
947 velecsum = _mm_add_pd(velecsum,velec);
948 /* #define INNERFLOPS INNERFLOPS+1 */
949 /* #if KERNEL_ELEC=='GeneralizedBorn' */
950 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
951 vgb = _mm_and_pd(vgb,cutoff_mask);
952 /* #define INNERFLOPS INNERFLOPS+1 */
954 /* #if ROUND == 'Epilogue' */
955 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
957 vgbsum = _mm_add_pd(vgbsum,vgb);
958 /* #define INNERFLOPS INNERFLOPS+1 */
961 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
962 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
963 vvdw = _mm_and_pd(vvdw,cutoff_mask);
964 /* #define INNERFLOPS INNERFLOPS+1 */
966 /* #if ROUND == 'Epilogue' */
967 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
969 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
970 /* #define INNERFLOPS INNERFLOPS+1 */
974 /* #if 'Force' in KERNEL_VF */
976 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
977 fscal = _mm_add_pd(felec,fvdw);
978 /* #define INNERFLOPS INNERFLOPS+1 */
979 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
981 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
985 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
986 fscal = _mm_and_pd(fscal,cutoff_mask);
987 /* #define INNERFLOPS INNERFLOPS+1 */
990 /* #if ROUND == 'Epilogue' */
991 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
994 /* Calculate temporary vectorial force */
995 tx = _mm_mul_pd(fscal,dx{I}{J});
996 ty = _mm_mul_pd(fscal,dy{I}{J});
997 tz = _mm_mul_pd(fscal,dz{I}{J});
999 /* Update vectorial force */
1000 fix{I} = _mm_add_pd(fix{I},tx);
1001 fiy{I} = _mm_add_pd(fiy{I},ty);
1002 fiz{I} = _mm_add_pd(fiz{I},tz);
1003 /* #define INNERFLOPS INNERFLOPS+6 */
1005 /* #if GEOMETRY_I == 'Particle' */
1006 /* #if ROUND == 'Loop' */
1007 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
1009 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
1011 /* #define INNERFLOPS INNERFLOPS+3 */
1013 fjx{J} = _mm_add_pd(fjx{J},tx);
1014 fjy{J} = _mm_add_pd(fjy{J},ty);
1015 fjz{J} = _mm_add_pd(fjz{J},tz);
1016 /* #define INNERFLOPS INNERFLOPS+3 */
1021 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
1022 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1027 /* ## End of check for the interaction being outside the cutoff */
1030 /* ## End of loop over i-j interaction pairs */
1032 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1033 /* #if ROUND == 'Loop' */
1034 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1036 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1038 /* #define INNERFLOPS INNERFLOPS+3 */
1039 /* #elif GEOMETRY_J == 'Water3' */
1040 /* #if ROUND == 'Loop' */
1041 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1043 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1045 /* #define INNERFLOPS INNERFLOPS+9 */
1046 /* #elif GEOMETRY_J == 'Water4' */
1047 /* #if 0 in PARTICLES_J */
1048 /* #if ROUND == 'Loop' */
1049 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);
1051 gmx_mm_decrement_4rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1053 /* #define INNERFLOPS INNERFLOPS+12 */
1055 /* #if ROUND == 'Loop' */
1056 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);
1058 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1060 /* #define INNERFLOPS INNERFLOPS+9 */
1064 /* Inner loop uses {INNERFLOPS} flops */
1069 /* End of innermost loop */
1071 /* #if 'Force' in KERNEL_VF */
1072 /* #if GEOMETRY_I == 'Particle' */
1073 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
1074 f+i_coord_offset,fshift+i_shift_offset);
1075 /* #define OUTERFLOPS OUTERFLOPS+6 */
1076 /* #elif GEOMETRY_I == 'Water3' */
1077 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1078 f+i_coord_offset,fshift+i_shift_offset);
1079 /* #define OUTERFLOPS OUTERFLOPS+18 */
1080 /* #elif GEOMETRY_I == 'Water4' */
1081 /* #if 0 in PARTICLES_I */
1082 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1083 f+i_coord_offset,fshift+i_shift_offset);
1084 /* #define OUTERFLOPS OUTERFLOPS+24 */
1086 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1087 f+i_coord_offset+DIM,fshift+i_shift_offset);
1088 /* #define OUTERFLOPS OUTERFLOPS+18 */
1093 /* #if 'Potential' in KERNEL_VF */
1095 /* Update potential energies */
1096 /* #if KERNEL_ELEC != 'None' */
1097 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
1098 /* #define OUTERFLOPS OUTERFLOPS+1 */
1100 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1101 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
1102 /* #define OUTERFLOPS OUTERFLOPS+1 */
1104 /* #if KERNEL_VDW != 'None' */
1105 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
1106 /* #define OUTERFLOPS OUTERFLOPS+1 */
1109 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1110 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai{I},isai{I}));
1111 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
1114 /* Increment number of inner iterations */
1115 inneriter += j_index_end - j_index_start;
1117 /* Outer loop uses {OUTERFLOPS} flops */
1120 /* Increment number of outer iterations */
1123 /* Update outer/inner flops */
1124 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1125 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1126 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1127 /* #if GEOMETRY_I == 'Water3' */
1128 /* #define ISUFFIX '_W3' */
1129 /* #elif GEOMETRY_I == 'Water4' */
1130 /* #define ISUFFIX '_W4' */
1132 /* #define ISUFFIX '' */
1134 /* #if GEOMETRY_J == 'Water3' */
1135 /* #define JSUFFIX 'W3' */
1136 /* #elif GEOMETRY_J == 'Water4' */
1137 /* #define JSUFFIX 'W4' */
1139 /* #define JSUFFIX '' */
1141 /* #if 'PotentialAndForce' in KERNEL_VF */
1142 /* #define VFSUFFIX '_VF' */
1143 /* #elif 'Potential' in KERNEL_VF */
1144 /* #define VFSUFFIX '_V' */
1146 /* #define VFSUFFIX '_F' */
1149 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1150 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1151 /* #elif KERNEL_ELEC != 'None' */
1152 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1154 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});