3 * This file is part of the GROMACS molecular simulation package.
5 * Copyright (c) 2012,2013,2014, 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 */
43 #include "../nb_kernel.h"
44 #include "gromacs/legacyheaders/types/simple.h"
45 #include "gromacs/math/vec.h"
46 #include "gromacs/legacyheaders/nrnb.h"
48 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
49 #include "kernelutil_x86_avx_128_fma_double.h"
52 /* ## List of variables set by the generating script: */
54 /* ## Setttings that apply to the entire kernel: */
55 /* ## KERNEL_ELEC: String, choice for electrostatic interactions */
56 /* ## KERNEL_VDW: String, choice for van der Waals interactions */
57 /* ## KERNEL_NAME: String, name of this kernel */
58 /* ## KERNEL_VF: String telling if we calculate potential, force, or both */
59 /* ## GEOMETRY_I/GEOMETRY_J: String, name of each geometry, e.g. 'Water3' or '1Particle' */
61 /* ## Setttings that apply to particles in the outer (I) or inner (J) loops: */
62 /* ## PARTICLES_I[]/ Arrays with lists of i/j particles to use in kernel. It is */
63 /* ## PARTICLES_J[]: just [0] for particle geometry, but can be longer for water */
64 /* ## PARTICLES_ELEC_I[]/ Arrays with lists of i/j particle that have electrostatics */
65 /* ## PARTICLES_ELEC_J[]: interactions that should be calculated in this kernel. */
66 /* ## PARTICLES_VDW_I[]/ Arrays with the list of i/j particle that have VdW */
67 /* ## PARTICLES_VDW_J[]: interactions that should be calculated in this kernel. */
69 /* ## Setttings for pairs of interactions (e.g. 2nd i particle against 1st j particle) */
70 /* ## PAIRS_IJ[]: Array with (i,j) tuples of pairs for which interactions */
71 /* ## should be calculated in this kernel. Zero-charge particles */
72 /* ## do not have interactions with particles without vdw, and */
73 /* ## Vdw-only interactions are not evaluated in a no-vdw-kernel. */
74 /* ## INTERACTION_FLAGS[][]: 2D matrix, dimension e.g. 3*3 for water-water interactions. */
75 /* ## For each i-j pair, the element [I][J] is a list of strings */
76 /* ## defining properties/flags of this interaction. Examples */
77 /* ## include 'electrostatics'/'vdw' if that type of interaction */
78 /* ## should be evaluated, 'rsq'/'rinv'/'rinvsq' if those values */
79 /* ## are needed, and 'exactcutoff' or 'shift','switch' to */
80 /* ## decide if the force/potential should be modified. This way */
81 /* ## we only calculate values absolutely needed for each case. */
83 /* ## Calculate the size and offset for (merged/interleaved) table data */
86 * Gromacs nonbonded kernel: {KERNEL_NAME}
87 * Electrostatics interaction: {KERNEL_ELEC}
88 * VdW interaction: {KERNEL_VDW}
89 * Geometry: {GEOMETRY_I}-{GEOMETRY_J}
90 * Calculate force/pot: {KERNEL_VF}
94 (t_nblist * gmx_restrict nlist,
95 rvec * gmx_restrict xx,
96 rvec * gmx_restrict ff,
97 t_forcerec * gmx_restrict fr,
98 t_mdatoms * gmx_restrict mdatoms,
99 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
100 t_nrnb * gmx_restrict nrnb)
102 /* ## Not all variables are used for all kernels, but any optimizing compiler fixes that, */
103 /* ## so there is no point in going to extremes to exclude variables that are not needed. */
104 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
105 * just 0 for non-waters.
106 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
107 * jnr indices corresponding to data put in the four positions in the SIMD register.
109 int i_shift_offset,i_coord_offset,outeriter,inneriter;
110 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
112 int j_coord_offsetA,j_coord_offsetB;
113 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
115 real *shiftvec,*fshift,*x,*f;
116 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
117 /* #for I in PARTICLES_I */
119 __m128d ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
121 /* #for J in PARTICLES_J */
122 int vdwjidx{J}A,vdwjidx{J}B;
123 __m128d jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
125 /* #for I,J in PAIRS_IJ */
126 __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};
128 /* #if KERNEL_ELEC != 'None' */
129 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
132 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
134 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
135 __m128d minushalf = _mm_set1_pd(-0.5);
136 real *invsqrta,*dvda,*gbtab;
138 /* #if KERNEL_VDW != 'None' */
140 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
143 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
144 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
146 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
148 __m128i ifour = _mm_set1_epi32(4);
149 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
152 /* #if 'LJEwald' in KERNEL_VDW */
153 /* #for I,J in PAIRS_IJ */
154 __m128d c6grid_{I}{J};
157 __m128d ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
158 __m128d one_half = _mm_set1_pd(0.5);
159 __m128d minus_one = _mm_set1_pd(-1.0);
161 /* #if 'Ewald' in KERNEL_ELEC */
163 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
166 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
167 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
168 real rswitch_scalar,d_scalar;
170 __m128d dummy_mask,cutoff_mask;
171 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
172 __m128d one = _mm_set1_pd(1.0);
173 __m128d two = _mm_set1_pd(2.0);
179 jindex = nlist->jindex;
181 shiftidx = nlist->shift;
183 shiftvec = fr->shift_vec[0];
184 fshift = fr->fshift[0];
185 /* #if KERNEL_ELEC != 'None' */
186 facel = _mm_set1_pd(fr->epsfac);
187 charge = mdatoms->chargeA;
188 /* #if 'ReactionField' in KERNEL_ELEC */
189 krf = _mm_set1_pd(fr->ic->k_rf);
190 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
191 crf = _mm_set1_pd(fr->ic->c_rf);
194 /* #if KERNEL_VDW != 'None' */
195 nvdwtype = fr->ntype;
197 vdwtype = mdatoms->typeA;
199 /* #if 'LJEwald' in KERNEL_VDW */
200 vdwgridparam = fr->ljpme_c6grid;
201 sh_lj_ewald = _mm_set1_pd(fr->ic->sh_lj_ewald);
202 ewclj = _mm_set1_pd(fr->ewaldcoeff_lj);
203 ewclj2 = _mm_mul_pd(minus_one,_mm_mul_pd(ewclj,ewclj));
206 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
207 vftab = kernel_data->table_elec_vdw->data;
208 vftabscale = _mm_set1_pd(kernel_data->table_elec_vdw->scale);
209 /* #elif 'Table' in KERNEL_ELEC */
210 vftab = kernel_data->table_elec->data;
211 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
212 /* #elif 'Table' in KERNEL_VDW */
213 vftab = kernel_data->table_vdw->data;
214 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
217 /* #if 'Ewald' in KERNEL_ELEC */
218 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
219 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
220 ewtab = fr->ic->tabq_coul_F;
221 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
222 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
224 ewtab = fr->ic->tabq_coul_FDV0;
225 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
226 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
230 /* #if KERNEL_ELEC=='GeneralizedBorn' */
231 invsqrta = fr->invsqrta;
233 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
234 gbtab = fr->gbtab.data;
235 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
238 /* #if 'Water' in GEOMETRY_I */
239 /* Setup water-specific parameters */
240 inr = nlist->iinr[0];
241 /* #for I in PARTICLES_ELEC_I */
242 iq{I} = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+{I}]));
244 /* #for I in PARTICLES_VDW_I */
245 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
249 /* #if 'Water' in GEOMETRY_J */
250 /* #for J in PARTICLES_ELEC_J */
251 jq{J} = _mm_set1_pd(charge[inr+{J}]);
253 /* #for J in PARTICLES_VDW_J */
254 vdwjidx{J}A = 2*vdwtype[inr+{J}];
256 /* #for I,J in PAIRS_IJ */
257 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
258 qq{I}{J} = _mm_mul_pd(iq{I},jq{J});
260 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
261 /* #if 'LJEwald' in KERNEL_VDW */
262 c6_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
263 c12_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
264 c6grid_{I}{J} = _mm_set1_pd(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
266 c6_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
267 c12_{I}{J} = _mm_set1_pd(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
273 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
274 /* #if KERNEL_ELEC!='None' */
275 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
276 rcutoff_scalar = fr->rcoulomb;
278 rcutoff_scalar = fr->rvdw;
280 rcutoff = _mm_set1_pd(rcutoff_scalar);
281 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
284 /* #if KERNEL_MOD_VDW=='PotentialShift' */
285 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
286 rvdw = _mm_set1_pd(fr->rvdw);
289 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
290 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
291 rswitch_scalar = fr->rcoulomb_switch;
292 rswitch = _mm_set1_pd(rswitch_scalar);
294 rswitch_scalar = fr->rvdw_switch;
295 rswitch = _mm_set1_pd(rswitch_scalar);
297 /* Setup switch parameters */
298 d_scalar = rcutoff_scalar-rswitch_scalar;
299 d = _mm_set1_pd(d_scalar);
300 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
301 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
302 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
303 /* #if 'Force' in KERNEL_VF */
304 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
305 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
306 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
310 /* Avoid stupid compiler warnings */
315 /* ## Keep track of the floating point operations we issue for reporting! */
316 /* #define OUTERFLOPS 0 */
320 /* Start outer loop over neighborlists */
321 for(iidx=0; iidx<nri; iidx++)
323 /* Load shift vector for this list */
324 i_shift_offset = DIM*shiftidx[iidx];
326 /* Load limits for loop over neighbors */
327 j_index_start = jindex[iidx];
328 j_index_end = jindex[iidx+1];
330 /* Get outer coordinate index */
332 i_coord_offset = DIM*inr;
334 /* Load i particle coords and add shift vector */
335 /* #if GEOMETRY_I == 'Particle' */
336 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
337 /* #elif GEOMETRY_I == 'Water3' */
338 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
339 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
340 /* #elif GEOMETRY_I == 'Water4' */
341 /* #if 0 in PARTICLES_I */
342 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
343 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
345 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
346 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
350 /* #if 'Force' in KERNEL_VF */
351 /* #for I in PARTICLES_I */
352 fix{I} = _mm_setzero_pd();
353 fiy{I} = _mm_setzero_pd();
354 fiz{I} = _mm_setzero_pd();
358 /* ## For water we already preloaded parameters at the start of the kernel */
359 /* #if not 'Water' in GEOMETRY_I */
360 /* Load parameters for i particles */
361 /* #for I in PARTICLES_ELEC_I */
362 iq{I} = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+{I}));
363 /* #define OUTERFLOPS OUTERFLOPS+1 */
364 /* #if KERNEL_ELEC=='GeneralizedBorn' */
365 isai{I} = _mm_load1_pd(invsqrta+inr+{I});
368 /* #for I in PARTICLES_VDW_I */
369 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
373 /* #if 'Potential' in KERNEL_VF */
374 /* Reset potential sums */
375 /* #if KERNEL_ELEC != 'None' */
376 velecsum = _mm_setzero_pd();
378 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
379 vgbsum = _mm_setzero_pd();
381 /* #if KERNEL_VDW != 'None' */
382 vvdwsum = _mm_setzero_pd();
385 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
386 dvdasum = _mm_setzero_pd();
389 /* #for ROUND in ['Loop','Epilogue'] */
391 /* #if ROUND =='Loop' */
392 /* Start inner kernel loop */
393 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
395 /* ## First round is normal loop (next statement resets indentation) */
402 /* ## Second round is epilogue */
404 /* #define INNERFLOPS 0 */
406 /* #if ROUND =='Loop' */
407 /* Get j neighbor index, and coordinate index */
410 j_coord_offsetA = DIM*jnrA;
411 j_coord_offsetB = DIM*jnrB;
413 /* load j atom coordinates */
414 /* #if GEOMETRY_J == 'Particle' */
415 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
417 /* #elif GEOMETRY_J == 'Water3' */
418 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
419 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
420 /* #elif GEOMETRY_J == 'Water4' */
421 /* #if 0 in PARTICLES_J */
422 gmx_mm_load_4rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
423 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
424 &jy2,&jz2,&jx3,&jy3,&jz3);
426 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
427 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
432 j_coord_offsetA = DIM*jnrA;
434 /* load j atom coordinates */
435 /* #if GEOMETRY_J == 'Particle' */
436 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
438 /* #elif GEOMETRY_J == 'Water3' */
439 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
440 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
441 /* #elif GEOMETRY_J == 'Water4' */
442 /* #if 0 in PARTICLES_J */
443 gmx_mm_load_4rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
444 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
445 &jy2,&jz2,&jx3,&jy3,&jz3);
447 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA+DIM,
448 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
453 /* Calculate displacement vector */
454 /* #for I,J in PAIRS_IJ */
455 dx{I}{J} = _mm_sub_pd(ix{I},jx{J});
456 dy{I}{J} = _mm_sub_pd(iy{I},jy{J});
457 dz{I}{J} = _mm_sub_pd(iz{I},jz{J});
458 /* #define INNERFLOPS INNERFLOPS+3 */
461 /* Calculate squared distance and things based on it */
462 /* #for I,J in PAIRS_IJ */
463 rsq{I}{J} = gmx_mm_calc_rsq_pd(dx{I}{J},dy{I}{J},dz{I}{J});
464 /* #define INNERFLOPS INNERFLOPS+5 */
467 /* #for I,J in PAIRS_IJ */
468 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
469 rinv{I}{J} = gmx_mm_invsqrt_pd(rsq{I}{J});
470 /* #define INNERFLOPS INNERFLOPS+5 */
474 /* #for I,J in PAIRS_IJ */
475 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
476 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
477 rinvsq{I}{J} = gmx_mm_inv_pd(rsq{I}{J});
478 /* #define INNERFLOPS INNERFLOPS+4 */
480 rinvsq{I}{J} = _mm_mul_pd(rinv{I}{J},rinv{I}{J});
481 /* #define INNERFLOPS INNERFLOPS+1 */
486 /* #if not 'Water' in GEOMETRY_J */
487 /* Load parameters for j particles */
488 /* #for J in PARTICLES_ELEC_J */
489 /* #if ROUND =='Loop' */
490 jq{J} = gmx_mm_load_2real_swizzle_pd(charge+jnrA+{J},charge+jnrB+{J});
492 jq{J} = _mm_load_sd(charge+jnrA+{J});
494 /* #if KERNEL_ELEC=='GeneralizedBorn' */
495 /* #if ROUND =='Loop' */
496 isaj{J} = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+{J},invsqrta+jnrB+{J});
498 isaj{J} = _mm_load_sd(invsqrta+jnrA+{J});
502 /* #for J in PARTICLES_VDW_J */
503 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
504 /* #if ROUND =='Loop' */
505 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
510 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
511 /* #for J in PARTICLES_J */
512 fjx{J} = _mm_setzero_pd();
513 fjy{J} = _mm_setzero_pd();
514 fjz{J} = _mm_setzero_pd();
518 /* #for I,J in PAIRS_IJ */
520 /**************************
521 * CALCULATE INTERACTIONS *
522 **************************/
524 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
525 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
526 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
528 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
531 /* #define INNERFLOPS INNERFLOPS+1 */
534 /* #if 'r' in INTERACTION_FLAGS[I][J] */
535 r{I}{J} = _mm_mul_pd(rsq{I}{J},rinv{I}{J});
536 /* #define INNERFLOPS INNERFLOPS+1 */
539 /* ## For water geometries we already loaded parameters at the start of the kernel */
540 /* #if not 'Water' in GEOMETRY_J */
541 /* Compute parameters for interactions between i and j atoms */
542 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
543 qq{I}{J} = _mm_mul_pd(iq{I},jq{J});
544 /* #define INNERFLOPS INNERFLOPS+1 */
546 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
547 /* #if ROUND == 'Loop' */
548 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset{I}+vdwjidx{J}A,
549 vdwparam+vdwioffset{I}+vdwjidx{J}B,&c6_{I}{J},&c12_{I}{J});
550 /* #if 'LJEwald' in KERNEL_VDW */
551 c6grid_{I}{J} = gmx_mm_load_2real_swizzle_pd(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
552 vdwgridparam+vdwioffset{I}+vdwjidx{J}B);
555 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);
568 vfeps = _mm_frcz_pd(rt);
570 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
572 twovfeps = _mm_add_pd(vfeps,vfeps);
573 /* #define INNERFLOPS INNERFLOPS+4 */
574 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
575 /* ## 3 tables, 4 data per point: multiply index by 12 */
576 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
577 /* #elif 'Table' in KERNEL_ELEC */
578 /* ## 1 table, 4 data per point: multiply index by 4 */
579 vfitab = _mm_slli_epi32(vfitab,2);
580 /* #elif 'Table' in KERNEL_VDW */
581 /* ## 2 tables, 4 data per point: multiply index by 8 */
582 vfitab = _mm_slli_epi32(vfitab,3);
586 /* ## ELECTROSTATIC INTERACTIONS */
587 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
589 /* #if KERNEL_ELEC=='Coulomb' */
591 /* COULOMB ELECTROSTATICS */
592 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
593 /* #define INNERFLOPS INNERFLOPS+1 */
594 /* #if 'Force' in KERNEL_VF */
595 felec = _mm_mul_pd(velec,rinvsq{I}{J});
596 /* #define INNERFLOPS INNERFLOPS+2 */
599 /* #elif KERNEL_ELEC=='ReactionField' */
601 /* REACTION-FIELD ELECTROSTATICS */
602 /* #if 'Potential' in KERNEL_VF */
603 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_macc_pd(krf,rsq{I}{J},rinv{I}{J}),crf));
604 /* #define INNERFLOPS INNERFLOPS+4 */
606 /* #if 'Force' in KERNEL_VF */
607 felec = _mm_mul_pd(qq{I}{J},_mm_msub_pd(rinv{I}{J},rinvsq{I}{J},krf2));
608 /* #define INNERFLOPS INNERFLOPS+3 */
611 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
613 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
614 isaprod = _mm_mul_pd(isai{I},isaj{J});
615 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq{I}{J},_mm_mul_pd(isaprod,gbinvepsdiff)));
616 gbscale = _mm_mul_pd(isaprod,gbtabscale);
617 /* #define INNERFLOPS INNERFLOPS+5 */
619 /* Calculate generalized born table index - this is a separate table from the normal one,
620 * but we use the same procedure by multiplying r with scale and truncating to integer.
622 rt = _mm_mul_pd(r{I}{J},gbscale);
623 gbitab = _mm_cvttpd_epi32(rt);
625 gbeps = _mm_frcz_pd(rt);
627 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
629 gbitab = _mm_slli_epi32(gbitab,2);
631 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
632 /* #if ROUND == 'Loop' */
633 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
635 F = _mm_setzero_pd();
637 GMX_MM_TRANSPOSE2_PD(Y,F);
638 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
639 /* #if ROUND == 'Loop' */
640 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
642 H = _mm_setzero_pd();
644 GMX_MM_TRANSPOSE2_PD(G,H);
645 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
646 VV = _mm_macc_pd(gbeps,Fp,Y);
647 vgb = _mm_mul_pd(gbqqfactor,VV);
648 /* #define INNERFLOPS INNERFLOPS+10 */
650 /* #if 'Force' in KERNEL_VF */
651 twogbeps = _mm_add_pd(gbeps,gbeps);
652 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
653 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
654 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r{I}{J},vgb));
655 /* #if ROUND == 'Epilogue' */
656 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
658 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
659 /* #if ROUND == 'Loop' */
660 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
662 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj{J},isaj{J})));
664 /* #define INNERFLOPS INNERFLOPS+13 */
666 velec = _mm_mul_pd(qq{I}{J},rinv{I}{J});
667 /* #define INNERFLOPS INNERFLOPS+1 */
668 /* #if 'Force' in KERNEL_VF */
669 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv{I}{J},fgb),rinv{I}{J});
670 /* #define INNERFLOPS INNERFLOPS+3 */
673 /* #elif KERNEL_ELEC=='Ewald' */
674 /* EWALD ELECTROSTATICS */
676 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
677 ewrt = _mm_mul_pd(r{I}{J},ewtabscale);
678 ewitab = _mm_cvttpd_epi32(ewrt);
680 eweps = _mm_frcz_pd(ewrt);
682 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
684 twoeweps = _mm_add_pd(eweps,eweps);
685 /* #define INNERFLOPS INNERFLOPS+4 */
686 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
687 ewitab = _mm_slli_epi32(ewitab,2);
688 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
689 /* #if ROUND == 'Loop' */
690 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
692 ewtabD = _mm_setzero_pd();
694 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
695 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
696 /* #if ROUND == 'Loop' */
697 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
699 ewtabFn = _mm_setzero_pd();
701 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
702 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
703 /* #define INNERFLOPS INNERFLOPS+2 */
704 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
705 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
706 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(_mm_sub_pd(rinv{I}{J},sh_ewald),velec));
707 /* #define INNERFLOPS INNERFLOPS+7 */
709 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
710 velec = _mm_mul_pd(qq{I}{J},_mm_sub_pd(rinv{I}{J},velec));
711 /* #define INNERFLOPS INNERFLOPS+6 */
713 /* #if 'Force' in KERNEL_VF */
714 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
715 /* #define INNERFLOPS INNERFLOPS+3 */
717 /* #elif KERNEL_VF=='Force' */
718 /* #if ROUND == 'Loop' */
719 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
722 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
724 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
725 felec = _mm_mul_pd(_mm_mul_pd(qq{I}{J},rinv{I}{J}),_mm_sub_pd(rinvsq{I}{J},felec));
726 /* #define INNERFLOPS INNERFLOPS+7 */
729 /* #elif KERNEL_ELEC=='CubicSplineTable' */
731 /* CUBIC SPLINE TABLE ELECTROSTATICS */
732 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
733 /* #if ROUND == 'Loop' */
734 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
736 F = _mm_setzero_pd();
738 GMX_MM_TRANSPOSE2_PD(Y,F);
739 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
740 /* #if ROUND == 'Loop' */
741 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
743 H = _mm_setzero_pd();
745 GMX_MM_TRANSPOSE2_PD(G,H);
746 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
747 /* #define INNERFLOPS INNERFLOPS+4 */
748 /* #if 'Potential' in KERNEL_VF */
749 VV = _mm_macc_pd(vfeps,Fp,Y);
750 velec = _mm_mul_pd(qq{I}{J},VV);
751 /* #define INNERFLOPS INNERFLOPS+3 */
753 /* #if 'Force' in KERNEL_VF */
754 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
755 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq{I}{J},FF),_mm_mul_pd(vftabscale,rinv{I}{J})));
756 /* #define INNERFLOPS INNERFLOPS+7 */
759 /* ## End of check for electrostatics interaction forms */
761 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
763 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
765 /* #if KERNEL_VDW=='LennardJones' */
767 /* LENNARD-JONES DISPERSION/REPULSION */
769 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
770 /* #define INNERFLOPS INNERFLOPS+2 */
771 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
772 vvdw6 = _mm_mul_pd(c6_{I}{J},rinvsix);
773 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
774 /* #define INNERFLOPS INNERFLOPS+3 */
775 /* #if KERNEL_MOD_VDW=='PotentialShift' */
776 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
777 _mm_mul_pd(_mm_nmacc_pd( c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
778 /* #define INNERFLOPS INNERFLOPS+8 */
780 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
781 /* #define INNERFLOPS INNERFLOPS+3 */
783 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
784 /* #if 'Force' in KERNEL_VF */
785 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq{I}{J});
786 /* #define INNERFLOPS INNERFLOPS+2 */
788 /* #elif KERNEL_VF=='Force' */
789 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
790 fvdw = _mm_mul_pd(_mm_msub_pd(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_pd(rinvsix,rinvsq{I}{J}));
791 /* #define INNERFLOPS INNERFLOPS+4 */
794 /* #elif KERNEL_VDW=='CubicSplineTable' */
796 /* CUBIC SPLINE TABLE DISPERSION */
797 /* #if 'Table' in KERNEL_ELEC */
798 vfitab = _mm_add_epi32(vfitab,ifour);
800 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
801 /* #if ROUND == 'Loop' */
802 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
804 F = _mm_setzero_pd();
806 GMX_MM_TRANSPOSE2_PD(Y,F);
807 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
808 /* #if ROUND == 'Loop' */
809 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
811 H = _mm_setzero_pd();
813 GMX_MM_TRANSPOSE2_PD(G,H);
814 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
815 /* #define INNERFLOPS INNERFLOPS+4 */
816 /* #if 'Potential' in KERNEL_VF */
817 VV = _mm_macc_pd(vfeps,Fp,Y);
818 vvdw6 = _mm_mul_pd(c6_{I}{J},VV);
819 /* #define INNERFLOPS INNERFLOPS+3 */
821 /* #if 'Force' in KERNEL_VF */
822 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
823 fvdw6 = _mm_mul_pd(c6_{I}{J},FF);
824 /* #define INNERFLOPS INNERFLOPS+4 */
827 /* CUBIC SPLINE TABLE REPULSION */
828 vfitab = _mm_add_epi32(vfitab,ifour);
829 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
830 /* #if ROUND == 'Loop' */
831 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
833 F = _mm_setzero_pd();
835 GMX_MM_TRANSPOSE2_PD(Y,F);
836 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
837 /* #if ROUND == 'Loop' */
838 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
840 H = _mm_setzero_pd();
842 GMX_MM_TRANSPOSE2_PD(G,H);
843 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
844 /* #define INNERFLOPS INNERFLOPS+4 */
845 /* #if 'Potential' in KERNEL_VF */
846 VV = _mm_macc_pd(vfeps,Fp,Y);
847 vvdw12 = _mm_mul_pd(c12_{I}{J},VV);
848 /* #define INNERFLOPS INNERFLOPS+3 */
850 /* #if 'Force' in KERNEL_VF */
851 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
852 fvdw12 = _mm_mul_pd(c12_{I}{J},FF);
853 /* #define INNERFLOPS INNERFLOPS+5 */
855 /* #if 'Potential' in KERNEL_VF */
856 vvdw = _mm_add_pd(vvdw12,vvdw6);
857 /* #define INNERFLOPS INNERFLOPS+1 */
859 /* #if 'Force' in KERNEL_VF */
860 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv{I}{J})));
861 /* #define INNERFLOPS INNERFLOPS+4 */
864 /* #elif KERNEL_VDW=='LJEwald' */
866 /* Analytical LJ-PME */
867 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
868 ewcljrsq = _mm_mul_pd(ewclj2,rsq{I}{J});
869 ewclj6 = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
870 exponent = gmx_simd_exp_d(ewcljrsq);
871 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
872 poly = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
873 /* #define INNERFLOPS INNERFLOPS+10 */
874 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
875 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
876 vvdw6 = _mm_mul_pd(_mm_macc_pd(-c6grid_{I}{J},_mm_sub_pd(one,poly),c6_{I}{J}),rinvsix);
877 vvdw12 = _mm_mul_pd(c12_{I}{J},_mm_mul_pd(rinvsix,rinvsix));
878 /* #define INNERFLOPS INNERFLOPS+5 */
879 /* #if KERNEL_MOD_VDW=='PotentialShift' */
880 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_{I}{J},_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
881 _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));
882 /* #define INNERFLOPS INNERFLOPS+6 */
884 vvdw = _mm_msub_pd(vvdw12,one_twelfth,_mm_mul_pd(vvdw6,one_sixth));
885 /* #define INNERFLOPS INNERFLOPS+2 */
887 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
888 /* #if 'Force' in KERNEL_VF */
889 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
890 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});
891 /* #define INNERFLOPS INNERFLOPS+5 */
893 /* #elif KERNEL_VF=='Force' */
894 /* f6A = 6 * C6grid * (1 - poly) */
895 f6A = _mm_mul_pd(c6grid_{I}{J},_mm_sub_pd(one,poly));
896 /* f6B = C6grid * exponent * beta^6 */
897 f6B = _mm_mul_pd(_mm_mul_pd(c6grid_{I}{J},one_sixth),_mm_mul_pd(exponent,ewclj6));
898 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
899 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});
900 /* #define INNERFLOPS INNERFLOPS+10 */
903 /* ## End of check for vdw interaction forms */
905 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
907 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
908 d = _mm_sub_pd(r{I}{J},rswitch);
909 d = _mm_max_pd(d,_mm_setzero_pd());
910 d2 = _mm_mul_pd(d,d);
911 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
912 /* #define INNERFLOPS INNERFLOPS+10 */
914 /* #if 'Force' in KERNEL_VF */
915 dsw = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
916 /* #define INNERFLOPS INNERFLOPS+5 */
919 /* Evaluate switch function */
920 /* #if 'Force' in KERNEL_VF */
921 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
922 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
923 felec = _mm_msub_pd( felec,sw , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(velec,dsw)) );
924 /* #define INNERFLOPS INNERFLOPS+4 */
926 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
927 fvdw = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv{I}{J},_mm_mul_pd(vvdw,dsw)) );
928 /* #define INNERFLOPS INNERFLOPS+4 */
931 /* #if 'Potential' in KERNEL_VF */
932 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
933 velec = _mm_mul_pd(velec,sw);
934 /* #define INNERFLOPS INNERFLOPS+1 */
936 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
937 vvdw = _mm_mul_pd(vvdw,sw);
938 /* #define INNERFLOPS INNERFLOPS+1 */
942 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
943 cutoff_mask = _mm_cmplt_pd(rsq{I}{J},rcutoff2);
944 /* #define INNERFLOPS INNERFLOPS+1 */
947 /* #if 'Potential' in KERNEL_VF */
948 /* Update potential sum for this i atom from the interaction with this j atom. */
949 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
950 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
951 velec = _mm_and_pd(velec,cutoff_mask);
952 /* #define INNERFLOPS INNERFLOPS+1 */
954 /* #if ROUND == 'Epilogue' */
955 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
957 velecsum = _mm_add_pd(velecsum,velec);
958 /* #define INNERFLOPS INNERFLOPS+1 */
959 /* #if KERNEL_ELEC=='GeneralizedBorn' */
960 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
961 vgb = _mm_and_pd(vgb,cutoff_mask);
962 /* #define INNERFLOPS INNERFLOPS+1 */
964 /* #if ROUND == 'Epilogue' */
965 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
967 vgbsum = _mm_add_pd(vgbsum,vgb);
968 /* #define INNERFLOPS INNERFLOPS+1 */
971 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
972 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
973 vvdw = _mm_and_pd(vvdw,cutoff_mask);
974 /* #define INNERFLOPS INNERFLOPS+1 */
976 /* #if ROUND == 'Epilogue' */
977 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
979 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
980 /* #define INNERFLOPS INNERFLOPS+1 */
984 /* #if 'Force' in KERNEL_VF */
986 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
987 fscal = _mm_add_pd(felec,fvdw);
988 /* #define INNERFLOPS INNERFLOPS+1 */
989 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
991 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
995 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
996 fscal = _mm_and_pd(fscal,cutoff_mask);
997 /* #define INNERFLOPS INNERFLOPS+1 */
1000 /* #if ROUND == 'Epilogue' */
1001 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1004 /* ## Construction of vectorial force built into FMA instructions now */
1005 /* #define INNERFLOPS INNERFLOPS+3 */
1007 /* Update vectorial force */
1008 fix{I} = _mm_macc_pd(dx{I}{J},fscal,fix{I});
1009 fiy{I} = _mm_macc_pd(dy{I}{J},fscal,fiy{I});
1010 fiz{I} = _mm_macc_pd(dz{I}{J},fscal,fiz{I});
1011 /* #define INNERFLOPS INNERFLOPS+6 */
1013 /* #if GEOMETRY_I == 'Particle' */
1014 /* #if ROUND == 'Loop' */
1015 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
1016 _mm_mul_pd(dx{I}{J},fscal),
1017 _mm_mul_pd(dy{I}{J},fscal),
1018 _mm_mul_pd(dz{I}{J},fscal));
1020 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
1021 _mm_mul_pd(dx{I}{J},fscal),
1022 _mm_mul_pd(dy{I}{J},fscal),
1023 _mm_mul_pd(dz{I}{J},fscal));
1025 /* #define INNERFLOPS INNERFLOPS+3 */
1027 fjx{J} = _mm_macc_pd(dx{I}{J},fscal,fjx{J});
1028 fjy{J} = _mm_macc_pd(dy{I}{J},fscal,fjy{J});
1029 fjz{J} = _mm_macc_pd(dz{I}{J},fscal,fjz{J});
1030 /* #define INNERFLOPS INNERFLOPS+3 */
1035 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
1036 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1041 /* ## End of check for the interaction being outside the cutoff */
1044 /* ## End of loop over i-j interaction pairs */
1046 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1047 /* #if ROUND == 'Loop' */
1048 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1050 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1052 /* #define INNERFLOPS INNERFLOPS+3 */
1053 /* #elif GEOMETRY_J == 'Water3' */
1054 /* #if ROUND == 'Loop' */
1055 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1057 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1059 /* #define INNERFLOPS INNERFLOPS+9 */
1060 /* #elif GEOMETRY_J == 'Water4' */
1061 /* #if 0 in PARTICLES_J */
1062 /* #if ROUND == 'Loop' */
1063 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);
1065 gmx_mm_decrement_4rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1067 /* #define INNERFLOPS INNERFLOPS+12 */
1069 /* #if ROUND == 'Loop' */
1070 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);
1072 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1074 /* #define INNERFLOPS INNERFLOPS+9 */
1078 /* Inner loop uses {INNERFLOPS} flops */
1083 /* End of innermost loop */
1085 /* #if 'Force' in KERNEL_VF */
1086 /* #if GEOMETRY_I == 'Particle' */
1087 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
1088 f+i_coord_offset,fshift+i_shift_offset);
1089 /* #define OUTERFLOPS OUTERFLOPS+6 */
1090 /* #elif GEOMETRY_I == 'Water3' */
1091 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1092 f+i_coord_offset,fshift+i_shift_offset);
1093 /* #define OUTERFLOPS OUTERFLOPS+18 */
1094 /* #elif GEOMETRY_I == 'Water4' */
1095 /* #if 0 in PARTICLES_I */
1096 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1097 f+i_coord_offset,fshift+i_shift_offset);
1098 /* #define OUTERFLOPS OUTERFLOPS+24 */
1100 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1101 f+i_coord_offset+DIM,fshift+i_shift_offset);
1102 /* #define OUTERFLOPS OUTERFLOPS+18 */
1107 /* #if 'Potential' in KERNEL_VF */
1109 /* Update potential energies */
1110 /* #if KERNEL_ELEC != 'None' */
1111 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
1112 /* #define OUTERFLOPS OUTERFLOPS+1 */
1114 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1115 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
1116 /* #define OUTERFLOPS OUTERFLOPS+1 */
1118 /* #if KERNEL_VDW != 'None' */
1119 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
1120 /* #define OUTERFLOPS OUTERFLOPS+1 */
1123 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1124 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai{I},isai{I}));
1125 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
1128 /* Increment number of inner iterations */
1129 inneriter += j_index_end - j_index_start;
1131 /* Outer loop uses {OUTERFLOPS} flops */
1134 /* Increment number of outer iterations */
1137 /* Update outer/inner flops */
1138 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1139 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1140 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1141 /* #if GEOMETRY_I == 'Water3' */
1142 /* #define ISUFFIX '_W3' */
1143 /* #elif GEOMETRY_I == 'Water4' */
1144 /* #define ISUFFIX '_W4' */
1146 /* #define ISUFFIX '' */
1148 /* #if GEOMETRY_J == 'Water3' */
1149 /* #define JSUFFIX 'W3' */
1150 /* #elif GEOMETRY_J == 'Water4' */
1151 /* #define JSUFFIX 'W4' */
1153 /* #define JSUFFIX '' */
1155 /* #if 'PotentialAndForce' in KERNEL_VF */
1156 /* #define VFSUFFIX '_VF' */
1157 /* #elif 'Potential' in KERNEL_VF */
1158 /* #define VFSUFFIX '_V' */
1160 /* #define VFSUFFIX '_F' */
1163 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1164 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1165 /* #elif KERNEL_ELEC != 'None' */
1166 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1168 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});