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 "types/simple.h"
45 #include "gromacs/math/vec.h"
48 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
49 #include "kernelutil_x86_avx_128_fma_single.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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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;
111 int jnrA,jnrB,jnrC,jnrD;
112 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
113 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
114 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
116 real *shiftvec,*fshift,*x,*f;
117 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
119 __m128 fscal,rcutoff,rcutoff2,jidxall;
120 /* #for I in PARTICLES_I */
122 __m128 ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
124 /* #for J in PARTICLES_J */
125 int vdwjidx{J}A,vdwjidx{J}B,vdwjidx{J}C,vdwjidx{J}D;
126 __m128 jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
128 /* #for I,J in PAIRS_IJ */
129 __m128 dx{I}{J},dy{I}{J},dz{I}{J},rsq{I}{J},rinv{I}{J},rinvsq{I}{J},r{I}{J},qq{I}{J},c6_{I}{J},c12_{I}{J};
131 /* #if KERNEL_ELEC != 'None' */
132 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
135 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
137 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
138 __m128 minushalf = _mm_set1_ps(-0.5);
139 real *invsqrta,*dvda,*gbtab;
141 /* #if KERNEL_VDW != 'None' */
143 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
146 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
147 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
149 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
151 __m128i ifour = _mm_set1_epi32(4);
152 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
155 /* #if 'LJEwald' in KERNEL_VDW */
156 /* #for I,J in PAIRS_IJ */
157 __m128 c6grid_{I}{J};
160 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
161 __m128 one_half = _mm_set1_ps(0.5);
162 __m128 minus_one = _mm_set1_ps(-1.0);
164 /* #if 'Ewald' in KERNEL_ELEC */
166 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
167 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
170 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
171 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
172 real rswitch_scalar,d_scalar;
174 __m128 dummy_mask,cutoff_mask;
175 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
176 __m128 one = _mm_set1_ps(1.0);
177 __m128 two = _mm_set1_ps(2.0);
183 jindex = nlist->jindex;
185 shiftidx = nlist->shift;
187 shiftvec = fr->shift_vec[0];
188 fshift = fr->fshift[0];
189 /* #if KERNEL_ELEC != 'None' */
190 facel = _mm_set1_ps(fr->epsfac);
191 charge = mdatoms->chargeA;
192 /* #if 'ReactionField' in KERNEL_ELEC */
193 krf = _mm_set1_ps(fr->ic->k_rf);
194 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
195 crf = _mm_set1_ps(fr->ic->c_rf);
198 /* #if KERNEL_VDW != 'None' */
199 nvdwtype = fr->ntype;
201 vdwtype = mdatoms->typeA;
203 /* #if 'LJEwald' in KERNEL_VDW */
204 vdwgridparam = fr->ljpme_c6grid;
205 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
206 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
207 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
210 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
211 vftab = kernel_data->table_elec_vdw->data;
212 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
213 /* #elif 'Table' in KERNEL_ELEC */
214 vftab = kernel_data->table_elec->data;
215 vftabscale = _mm_set1_ps(kernel_data->table_elec->scale);
216 /* #elif 'Table' in KERNEL_VDW */
217 vftab = kernel_data->table_vdw->data;
218 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
221 /* #if 'Ewald' in KERNEL_ELEC */
222 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
223 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
224 beta2 = _mm_mul_ps(beta,beta);
225 beta3 = _mm_mul_ps(beta,beta2);
226 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
227 ewtab = fr->ic->tabq_coul_F;
228 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
229 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
231 ewtab = fr->ic->tabq_coul_FDV0;
232 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
233 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
237 /* #if KERNEL_ELEC=='GeneralizedBorn' */
238 invsqrta = fr->invsqrta;
240 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
241 gbtab = fr->gbtab.data;
242 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
245 /* #if 'Water' in GEOMETRY_I */
246 /* Setup water-specific parameters */
247 inr = nlist->iinr[0];
248 /* #for I in PARTICLES_ELEC_I */
249 iq{I} = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+{I}]));
251 /* #for I in PARTICLES_VDW_I */
252 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
256 /* #if 'Water' in GEOMETRY_J */
257 /* #for J in PARTICLES_ELEC_J */
258 jq{J} = _mm_set1_ps(charge[inr+{J}]);
260 /* #for J in PARTICLES_VDW_J */
261 vdwjidx{J}A = 2*vdwtype[inr+{J}];
263 /* #for I,J in PAIRS_IJ */
264 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
265 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
267 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
268 /* #if 'LJEwald' in KERNEL_VDW */
269 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
270 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
271 c6grid_{I}{J} = _mm_set1_ps(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
273 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
274 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
280 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
281 /* #if KERNEL_ELEC!='None' */
282 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
283 rcutoff_scalar = fr->rcoulomb;
285 rcutoff_scalar = fr->rvdw;
287 rcutoff = _mm_set1_ps(rcutoff_scalar);
288 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
291 /* #if KERNEL_MOD_VDW=='PotentialShift' */
292 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
293 rvdw = _mm_set1_ps(fr->rvdw);
296 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
297 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
298 rswitch_scalar = fr->rcoulomb_switch;
299 rswitch = _mm_set1_ps(rswitch_scalar);
301 rswitch_scalar = fr->rvdw_switch;
302 rswitch = _mm_set1_ps(rswitch_scalar);
304 /* Setup switch parameters */
305 d_scalar = rcutoff_scalar-rswitch_scalar;
306 d = _mm_set1_ps(d_scalar);
307 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
308 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
309 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
310 /* #if 'Force' in KERNEL_VF */
311 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
312 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
313 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
317 /* Avoid stupid compiler warnings */
318 jnrA = jnrB = jnrC = jnrD = 0;
324 /* ## Keep track of the floating point operations we issue for reporting! */
325 /* #define OUTERFLOPS 0 */
329 for(iidx=0;iidx<4*DIM;iidx++)
334 /* Start outer loop over neighborlists */
335 for(iidx=0; iidx<nri; iidx++)
337 /* Load shift vector for this list */
338 i_shift_offset = DIM*shiftidx[iidx];
340 /* Load limits for loop over neighbors */
341 j_index_start = jindex[iidx];
342 j_index_end = jindex[iidx+1];
344 /* Get outer coordinate index */
346 i_coord_offset = DIM*inr;
348 /* Load i particle coords and add shift vector */
349 /* #if GEOMETRY_I == 'Particle' */
350 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
351 /* #elif GEOMETRY_I == 'Water3' */
352 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
353 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
354 /* #elif GEOMETRY_I == 'Water4' */
355 /* #if 0 in PARTICLES_I */
356 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
357 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
359 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
360 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
364 /* #if 'Force' in KERNEL_VF */
365 /* #for I in PARTICLES_I */
366 fix{I} = _mm_setzero_ps();
367 fiy{I} = _mm_setzero_ps();
368 fiz{I} = _mm_setzero_ps();
372 /* ## For water we already preloaded parameters at the start of the kernel */
373 /* #if not 'Water' in GEOMETRY_I */
374 /* Load parameters for i particles */
375 /* #for I in PARTICLES_ELEC_I */
376 iq{I} = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+{I}));
377 /* #define OUTERFLOPS OUTERFLOPS+1 */
378 /* #if KERNEL_ELEC=='GeneralizedBorn' */
379 isai{I} = _mm_load1_ps(invsqrta+inr+{I});
382 /* #for I in PARTICLES_VDW_I */
383 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
387 /* #if 'Potential' in KERNEL_VF */
388 /* Reset potential sums */
389 /* #if KERNEL_ELEC != 'None' */
390 velecsum = _mm_setzero_ps();
392 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
393 vgbsum = _mm_setzero_ps();
395 /* #if KERNEL_VDW != 'None' */
396 vvdwsum = _mm_setzero_ps();
399 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
400 dvdasum = _mm_setzero_ps();
403 /* #for ROUND in ['Loop','Epilogue'] */
405 /* #if ROUND =='Loop' */
406 /* Start inner kernel loop */
407 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
409 /* ## First round is normal loop (next statement resets indentation) */
416 /* ## Second round is epilogue */
418 /* #define INNERFLOPS 0 */
420 /* Get j neighbor index, and coordinate index */
421 /* #if ROUND =='Loop' */
427 jnrlistA = jjnr[jidx];
428 jnrlistB = jjnr[jidx+1];
429 jnrlistC = jjnr[jidx+2];
430 jnrlistD = jjnr[jidx+3];
431 /* Sign of each element will be negative for non-real atoms.
432 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
433 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
435 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
436 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
437 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
438 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
439 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
441 j_coord_offsetA = DIM*jnrA;
442 j_coord_offsetB = DIM*jnrB;
443 j_coord_offsetC = DIM*jnrC;
444 j_coord_offsetD = DIM*jnrD;
446 /* load j atom coordinates */
447 /* #if GEOMETRY_J == 'Particle' */
448 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
449 x+j_coord_offsetC,x+j_coord_offsetD,
451 /* #elif GEOMETRY_J == 'Water3' */
452 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
453 x+j_coord_offsetC,x+j_coord_offsetD,
454 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
455 /* #elif GEOMETRY_J == 'Water4' */
456 /* #if 0 in PARTICLES_J */
457 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
458 x+j_coord_offsetC,x+j_coord_offsetD,
459 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
460 &jy2,&jz2,&jx3,&jy3,&jz3);
462 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
463 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
464 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
468 /* Calculate displacement vector */
469 /* #for I,J in PAIRS_IJ */
470 dx{I}{J} = _mm_sub_ps(ix{I},jx{J});
471 dy{I}{J} = _mm_sub_ps(iy{I},jy{J});
472 dz{I}{J} = _mm_sub_ps(iz{I},jz{J});
473 /* #define INNERFLOPS INNERFLOPS+3 */
476 /* Calculate squared distance and things based on it */
477 /* #for I,J in PAIRS_IJ */
478 rsq{I}{J} = gmx_mm_calc_rsq_ps(dx{I}{J},dy{I}{J},dz{I}{J});
479 /* #define INNERFLOPS INNERFLOPS+5 */
482 /* #for I,J in PAIRS_IJ */
483 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
484 rinv{I}{J} = gmx_mm_invsqrt_ps(rsq{I}{J});
485 /* #define INNERFLOPS INNERFLOPS+5 */
489 /* #for I,J in PAIRS_IJ */
490 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
491 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
492 rinvsq{I}{J} = gmx_mm_inv_ps(rsq{I}{J});
493 /* #define INNERFLOPS INNERFLOPS+4 */
495 rinvsq{I}{J} = _mm_mul_ps(rinv{I}{J},rinv{I}{J});
496 /* #define INNERFLOPS INNERFLOPS+1 */
501 /* #if not 'Water' in GEOMETRY_J */
502 /* Load parameters for j particles */
503 /* #for J in PARTICLES_ELEC_J */
504 jq{J} = gmx_mm_load_4real_swizzle_ps(charge+jnrA+{J},charge+jnrB+{J},
505 charge+jnrC+{J},charge+jnrD+{J});
506 /* #if KERNEL_ELEC=='GeneralizedBorn' */
507 isaj{J} = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+{J},invsqrta+jnrB+{J},
508 invsqrta+jnrC+{J},invsqrta+jnrD+{J});
511 /* #for J in PARTICLES_VDW_J */
512 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
513 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
514 vdwjidx{J}C = 2*vdwtype[jnrC+{J}];
515 vdwjidx{J}D = 2*vdwtype[jnrD+{J}];
519 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
520 /* #for J in PARTICLES_J */
521 fjx{J} = _mm_setzero_ps();
522 fjy{J} = _mm_setzero_ps();
523 fjz{J} = _mm_setzero_ps();
527 /* #for I,J in PAIRS_IJ */
529 /**************************
530 * CALCULATE INTERACTIONS *
531 **************************/
533 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
534 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
535 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
536 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
538 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
541 /* #define INNERFLOPS INNERFLOPS+1 */
544 /* #if 'r' in INTERACTION_FLAGS[I][J] */
545 r{I}{J} = _mm_mul_ps(rsq{I}{J},rinv{I}{J});
546 /* #if ROUND == 'Epilogue' */
547 r{I}{J} = _mm_andnot_ps(dummy_mask,r{I}{J});
548 /* #define INNERFLOPS INNERFLOPS+1 */
550 /* #define INNERFLOPS INNERFLOPS+1 */
553 /* ## For water geometries we already loaded parameters at the start of the kernel */
554 /* #if not 'Water' in GEOMETRY_J */
555 /* Compute parameters for interactions between i and j atoms */
556 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
557 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
558 /* #define INNERFLOPS INNERFLOPS+1 */
560 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
561 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset{I}+vdwjidx{J}A,
562 vdwparam+vdwioffset{I}+vdwjidx{J}B,
563 vdwparam+vdwioffset{I}+vdwjidx{J}C,
564 vdwparam+vdwioffset{I}+vdwjidx{J}D,
565 &c6_{I}{J},&c12_{I}{J});
567 /* #if 'LJEwald' in KERNEL_VDW */
568 c6grid_{I}{J} = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
569 vdwgridparam+vdwioffset{I}+vdwjidx{J}B,
570 vdwgridparam+vdwioffset{I}+vdwjidx{J}C,
571 vdwgridparam+vdwioffset{I}+vdwjidx{J}D);
577 /* #if 'table' in INTERACTION_FLAGS[I][J] */
578 /* Calculate table index by multiplying r with table scale and truncate to integer */
579 rt = _mm_mul_ps(r{I}{J},vftabscale);
580 vfitab = _mm_cvttps_epi32(rt);
582 vfeps = _mm_frcz_ps(rt);
584 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
586 twovfeps = _mm_add_ps(vfeps,vfeps);
587 /* #define INNERFLOPS INNERFLOPS+4 */
588 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
589 /* ## 3 tables, 4 bytes per point: multiply index by 12 */
590 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
591 /* #elif 'Table' in KERNEL_ELEC */
592 /* ## 1 table, 4 bytes per point: multiply index by 4 */
593 vfitab = _mm_slli_epi32(vfitab,2);
594 /* #elif 'Table' in KERNEL_VDW */
595 /* ## 2 tables, 4 bytes per point: multiply index by 8 */
596 vfitab = _mm_slli_epi32(vfitab,3);
600 /* ## ELECTROSTATIC INTERACTIONS */
601 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
603 /* #if KERNEL_ELEC=='Coulomb' */
605 /* COULOMB ELECTROSTATICS */
606 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
607 /* #define INNERFLOPS INNERFLOPS+1 */
608 /* #if 'Force' in KERNEL_VF */
609 felec = _mm_mul_ps(velec,rinvsq{I}{J});
610 /* #define INNERFLOPS INNERFLOPS+2 */
613 /* #elif KERNEL_ELEC=='ReactionField' */
615 /* REACTION-FIELD ELECTROSTATICS */
616 /* #if 'Potential' in KERNEL_VF */
617 velec = _mm_mul_ps(qq{I}{J},_mm_sub_ps(_mm_macc_ps(krf,rsq{I}{J},rinv{I}{J}),crf));
618 /* #define INNERFLOPS INNERFLOPS+4 */
620 /* #if 'Force' in KERNEL_VF */
621 felec = _mm_mul_ps(qq{I}{J},_mm_msub_ps(rinv{I}{J},rinvsq{I}{J},krf2));
622 /* #define INNERFLOPS INNERFLOPS+3 */
625 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
627 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
628 isaprod = _mm_mul_ps(isai{I},isaj{J});
629 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq{I}{J},_mm_mul_ps(isaprod,gbinvepsdiff)));
630 gbscale = _mm_mul_ps(isaprod,gbtabscale);
631 /* #define INNERFLOPS INNERFLOPS+5 */
633 /* Calculate generalized born table index - this is a separate table from the normal one,
634 * but we use the same procedure by multiplying r with scale and truncating to integer.
636 rt = _mm_mul_ps(r{I}{J},gbscale);
637 gbitab = _mm_cvttps_epi32(rt);
639 gbeps = _mm_frcz_ps(rt);
641 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
643 gbitab = _mm_slli_epi32(gbitab,2);
645 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
646 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
647 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
648 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
649 _MM_TRANSPOSE4_PS(Y,F,G,H);
650 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
651 VV = _mm_macc_ps(gbeps,Fp,Y);
652 vgb = _mm_mul_ps(gbqqfactor,VV);
653 /* #define INNERFLOPS INNERFLOPS+10 */
655 /* #if 'Force' in KERNEL_VF */
656 twogbeps = _mm_add_ps(gbeps,gbeps);
657 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
658 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
659 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r{I}{J},vgb));
660 /* #if ROUND == 'Epilogue' */
661 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
663 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
664 /* #if ROUND == 'Loop' */
670 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
671 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
672 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
673 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
674 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
676 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj{J},isaj{J})));
677 /* #define INNERFLOPS INNERFLOPS+13 */
679 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
680 /* #define INNERFLOPS INNERFLOPS+1 */
681 /* #if 'Force' in KERNEL_VF */
682 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv{I}{J},fgb),rinv{I}{J});
683 /* #define INNERFLOPS INNERFLOPS+3 */
686 /* #elif KERNEL_ELEC=='Ewald' */
687 /* EWALD ELECTROSTATICS */
689 /* Analytical PME correction */
690 zeta2 = _mm_mul_ps(beta2,rsq{I}{J});
691 /* #if 'Force' in KERNEL_VF */
692 rinv3 = _mm_mul_ps(rinvsq{I}{J},rinv{I}{J});
693 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
694 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
695 felec = _mm_mul_ps(qq{I}{J},felec);
697 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
698 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
699 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
700 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv{I}{J},sh_ewald));
702 velec = _mm_nmacc_ps(pmecorrV,beta,rinv{I}{J});
704 velec = _mm_mul_ps(qq{I}{J},velec);
707 /* #elif KERNEL_ELEC=='CubicSplineTable' */
709 /* CUBIC SPLINE TABLE ELECTROSTATICS */
710 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
711 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
712 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
713 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
714 _MM_TRANSPOSE4_PS(Y,F,G,H);
715 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
716 /* #define INNERFLOPS INNERFLOPS+4 */
717 /* #if 'Potential' in KERNEL_VF */
718 VV = _mm_macc_ps(vfeps,Fp,Y);
719 velec = _mm_mul_ps(qq{I}{J},VV);
720 /* #define INNERFLOPS INNERFLOPS+3 */
722 /* #if 'Force' in KERNEL_VF */
723 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
724 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq{I}{J},FF),_mm_mul_ps(vftabscale,rinv{I}{J})));
725 /* #define INNERFLOPS INNERFLOPS+7 */
728 /* ## End of check for electrostatics interaction forms */
730 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
732 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
734 /* #if KERNEL_VDW=='LennardJones' */
736 /* LENNARD-JONES DISPERSION/REPULSION */
738 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
739 /* #define INNERFLOPS INNERFLOPS+2 */
740 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
741 vvdw6 = _mm_mul_ps(c6_{I}{J},rinvsix);
742 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
743 /* #define INNERFLOPS INNERFLOPS+3 */
744 /* #if KERNEL_MOD_VDW=='PotentialShift' */
745 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
746 _mm_mul_ps( _mm_nmacc_ps(c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
747 /* #define INNERFLOPS INNERFLOPS+8 */
749 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
750 /* #define INNERFLOPS INNERFLOPS+3 */
752 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
753 /* #if 'Force' in KERNEL_VF */
754 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq{I}{J});
755 /* #define INNERFLOPS INNERFLOPS+2 */
757 /* #elif KERNEL_VF=='Force' */
758 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
759 fvdw = _mm_mul_ps(_mm_msub_ps(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_ps(rinvsix,rinvsq{I}{J}));
760 /* #define INNERFLOPS INNERFLOPS+4 */
763 /* #elif KERNEL_VDW=='CubicSplineTable' */
765 /* CUBIC SPLINE TABLE DISPERSION */
766 /* #if 'Table' in KERNEL_ELEC */
767 vfitab = _mm_add_epi32(vfitab,ifour);
769 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
770 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
771 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
772 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
773 _MM_TRANSPOSE4_PS(Y,F,G,H);
774 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
775 /* #define INNERFLOPS INNERFLOPS+4 */
776 /* #if 'Potential' in KERNEL_VF */
777 VV = _mm_macc_ps(vfeps,Fp,Y);
778 vvdw6 = _mm_mul_ps(c6_{I}{J},VV);
779 /* #define INNERFLOPS INNERFLOPS+3 */
781 /* #if 'Force' in KERNEL_VF */
782 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
783 fvdw6 = _mm_mul_ps(c6_{I}{J},FF);
784 /* #define INNERFLOPS INNERFLOPS+4 */
787 /* CUBIC SPLINE TABLE REPULSION */
788 vfitab = _mm_add_epi32(vfitab,ifour);
789 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
790 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
791 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
792 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
793 _MM_TRANSPOSE4_PS(Y,F,G,H);
794 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
795 /* #define INNERFLOPS INNERFLOPS+4 */
796 /* #if 'Potential' in KERNEL_VF */
797 VV = _mm_macc_ps(vfeps,Fp,Y);
798 vvdw12 = _mm_mul_ps(c12_{I}{J},VV);
799 /* #define INNERFLOPS INNERFLOPS+3 */
801 /* #if 'Force' in KERNEL_VF */
802 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
803 fvdw12 = _mm_mul_ps(c12_{I}{J},FF);
804 /* #define INNERFLOPS INNERFLOPS+5 */
806 /* #if 'Potential' in KERNEL_VF */
807 vvdw = _mm_add_ps(vvdw12,vvdw6);
808 /* #define INNERFLOPS INNERFLOPS+1 */
810 /* #if 'Force' in KERNEL_VF */
811 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv{I}{J})));
812 /* #define INNERFLOPS INNERFLOPS+4 */
815 /* #elif KERNEL_VDW=='LJEwald' */
817 /* Analytical LJ-PME */
818 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
819 ewcljrsq = _mm_mul_ps(ewclj2,rsq{I}{J});
820 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
821 exponent = gmx_simd_exp_r(ewcljrsq);
822 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
823 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
824 /* #define INNERFLOPS INNERFLOPS+10 */
825 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
826 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
827 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_{I}{J},_mm_sub_ps(one,poly),c6_{I}{J}),rinvsix);
828 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
829 /* #define INNERFLOPS INNERFLOPS+5 */
830 /* #if KERNEL_MOD_VDW=='PotentialShift' */
831 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
832 _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_{I}{J},sh_lj_ewald,_mm_mul_ps(c6_{I}{J},sh_vdw_invrcut6))),one_sixth));
833 /* #define INNERFLOPS INNERFLOPS+7 */
835 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
836 /* #define INNERFLOPS INNERFLOPS+2 */
838 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
839 /* #if 'Force' in KERNEL_VF */
840 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
841 fvdw = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_{I}{J},one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq{I}{J});
842 /* #define INNERFLOPS INNERFLOPS+5 */
844 /* #elif KERNEL_VF=='Force' */
845 /* f6A = 6 * C6grid * (1 - poly) */
846 f6A = _mm_mul_ps(c6grid_{I}{J},_mm_sub_ps(one,poly));
847 /* f6B = C6grid * exponent * beta^6 */
848 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_{I}{J},one_sixth),_mm_mul_ps(exponent,ewclj6));
849 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
850 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_{I}{J},rinvsix,_mm_sub_ps(c6_{I}{J},f6A)),rinvsix,f6B),rinvsq{I}{J});
851 /* #define INNERFLOPS INNERFLOPS+10 */
854 /* ## End of check for vdw interaction forms */
856 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
858 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
859 d = _mm_sub_ps(r{I}{J},rswitch);
860 d = _mm_max_ps(d,_mm_setzero_ps());
861 d2 = _mm_mul_ps(d,d);
862 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
863 /* #define INNERFLOPS INNERFLOPS+10 */
865 /* #if 'Force' in KERNEL_VF */
866 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
867 /* #define INNERFLOPS INNERFLOPS+5 */
870 /* Evaluate switch function */
871 /* #if 'Force' in KERNEL_VF */
872 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
873 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
874 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(velec,dsw)) );
875 /* #define INNERFLOPS INNERFLOPS+4 */
877 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
878 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(vvdw,dsw)) );
879 /* #define INNERFLOPS INNERFLOPS+4 */
882 /* #if 'Potential' in KERNEL_VF */
883 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
884 velec = _mm_mul_ps(velec,sw);
885 /* #define INNERFLOPS INNERFLOPS+1 */
887 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
888 vvdw = _mm_mul_ps(vvdw,sw);
889 /* #define INNERFLOPS INNERFLOPS+1 */
893 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
894 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
895 cutoff_mask = _mm_cmplt_ps(rsq{I}{J},rcutoff2);
896 /* #define INNERFLOPS INNERFLOPS+1 */
899 /* #if 'Potential' in KERNEL_VF */
900 /* Update potential sum for this i atom from the interaction with this j atom. */
901 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
902 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
903 velec = _mm_and_ps(velec,cutoff_mask);
904 /* #define INNERFLOPS INNERFLOPS+1 */
906 /* #if ROUND == 'Epilogue' */
907 velec = _mm_andnot_ps(dummy_mask,velec);
909 velecsum = _mm_add_ps(velecsum,velec);
910 /* #define INNERFLOPS INNERFLOPS+1 */
911 /* #if KERNEL_ELEC=='GeneralizedBorn' */
912 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
913 vgb = _mm_and_ps(vgb,cutoff_mask);
914 /* #define INNERFLOPS INNERFLOPS+1 */
916 /* #if ROUND == 'Epilogue' */
917 vgb = _mm_andnot_ps(dummy_mask,vgb);
919 vgbsum = _mm_add_ps(vgbsum,vgb);
920 /* #define INNERFLOPS INNERFLOPS+1 */
923 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
924 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
925 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
926 vvdw = _mm_and_ps(vvdw,cutoff_mask);
927 /* #define INNERFLOPS INNERFLOPS+1 */
929 /* #if ROUND == 'Epilogue' */
930 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
932 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
933 /* #define INNERFLOPS INNERFLOPS+1 */
937 /* #if 'Force' in KERNEL_VF */
939 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
940 fscal = _mm_add_ps(felec,fvdw);
941 /* #define INNERFLOPS INNERFLOPS+1 */
942 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
944 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
948 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
949 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
950 fscal = _mm_and_ps(fscal,cutoff_mask);
951 /* #define INNERFLOPS INNERFLOPS+1 */
954 /* #if ROUND == 'Epilogue' */
955 fscal = _mm_andnot_ps(dummy_mask,fscal);
958 /* ## Construction of vectorial force built into FMA instructions now */
959 /* #define INNERFLOPS INNERFLOPS+3 */
961 /* Update vectorial force */
962 fix{I} = _mm_macc_ps(dx{I}{J},fscal,fix{I});
963 fiy{I} = _mm_macc_ps(dy{I}{J},fscal,fiy{I});
964 fiz{I} = _mm_macc_ps(dz{I}{J},fscal,fiz{I});
965 /* #define INNERFLOPS INNERFLOPS+6 */
967 /* #if GEOMETRY_I == 'Particle' */
968 /* #if ROUND == 'Loop' */
969 fjptrA = f+j_coord_offsetA;
970 fjptrB = f+j_coord_offsetB;
971 fjptrC = f+j_coord_offsetC;
972 fjptrD = f+j_coord_offsetD;
974 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
975 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
976 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
977 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
979 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
980 _mm_mul_ps(dx{I}{J},fscal),
981 _mm_mul_ps(dy{I}{J},fscal),
982 _mm_mul_ps(dz{I}{J},fscal));
983 /* #define INNERFLOPS INNERFLOPS+3 */
985 fjx{J} = _mm_macc_ps(dx{I}{J},fscal,fjx{J});
986 fjy{J} = _mm_macc_ps(dy{I}{J},fscal,fjy{J});
987 fjz{J} = _mm_macc_ps(dz{I}{J},fscal,fjz{J});
988 /* #define INNERFLOPS INNERFLOPS+3 */
993 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
994 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
995 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1000 /* ## End of check for the interaction being outside the cutoff */
1003 /* ## End of loop over i-j interaction pairs */
1005 /* #if GEOMETRY_I != 'Particle' */
1006 /* #if ROUND == 'Loop' */
1007 fjptrA = f+j_coord_offsetA;
1008 fjptrB = f+j_coord_offsetB;
1009 fjptrC = f+j_coord_offsetC;
1010 fjptrD = f+j_coord_offsetD;
1012 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1013 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1014 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1015 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1019 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1020 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1021 /* #elif GEOMETRY_J == 'Water3' */
1022 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1023 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1024 /* #define INNERFLOPS INNERFLOPS+9 */
1025 /* #elif GEOMETRY_J == 'Water4' */
1026 /* #if 0 in PARTICLES_J */
1027 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1028 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1029 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1030 /* #define INNERFLOPS INNERFLOPS+12 */
1032 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1033 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1034 /* #define INNERFLOPS INNERFLOPS+9 */
1038 /* Inner loop uses {INNERFLOPS} flops */
1043 /* End of innermost loop */
1045 /* #if 'Force' in KERNEL_VF */
1046 /* #if GEOMETRY_I == 'Particle' */
1047 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
1048 f+i_coord_offset,fshift+i_shift_offset);
1049 /* #define OUTERFLOPS OUTERFLOPS+6 */
1050 /* #elif GEOMETRY_I == 'Water3' */
1051 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1052 f+i_coord_offset,fshift+i_shift_offset);
1053 /* #define OUTERFLOPS OUTERFLOPS+18 */
1054 /* #elif GEOMETRY_I == 'Water4' */
1055 /* #if 0 in PARTICLES_I */
1056 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1057 f+i_coord_offset,fshift+i_shift_offset);
1058 /* #define OUTERFLOPS OUTERFLOPS+24 */
1060 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1061 f+i_coord_offset+DIM,fshift+i_shift_offset);
1062 /* #define OUTERFLOPS OUTERFLOPS+18 */
1067 /* #if 'Potential' in KERNEL_VF */
1069 /* Update potential energies */
1070 /* #if KERNEL_ELEC != 'None' */
1071 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1072 /* #define OUTERFLOPS OUTERFLOPS+1 */
1074 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1075 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
1076 /* #define OUTERFLOPS OUTERFLOPS+1 */
1078 /* #if KERNEL_VDW != 'None' */
1079 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1080 /* #define OUTERFLOPS OUTERFLOPS+1 */
1083 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1084 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai{I},isai{I}));
1085 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
1088 /* Increment number of inner iterations */
1089 inneriter += j_index_end - j_index_start;
1091 /* Outer loop uses {OUTERFLOPS} flops */
1094 /* Increment number of outer iterations */
1097 /* Update outer/inner flops */
1098 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1099 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1100 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1101 /* #if GEOMETRY_I == 'Water3' */
1102 /* #define ISUFFIX '_W3' */
1103 /* #elif GEOMETRY_I == 'Water4' */
1104 /* #define ISUFFIX '_W4' */
1106 /* #define ISUFFIX '' */
1108 /* #if GEOMETRY_J == 'Water3' */
1109 /* #define JSUFFIX 'W3' */
1110 /* #elif GEOMETRY_J == 'Water4' */
1111 /* #define JSUFFIX 'W4' */
1113 /* #define JSUFFIX '' */
1115 /* #if 'PotentialAndForce' in KERNEL_VF */
1116 /* #define VFSUFFIX '_VF' */
1117 /* #elif 'Potential' in KERNEL_VF */
1118 /* #define VFSUFFIX '_V' */
1120 /* #define VFSUFFIX '_F' */
1123 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1124 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1125 /* #elif KERNEL_ELEC != 'None' */
1126 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1128 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});