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 */
45 #include "../nb_kernel.h"
46 #include "gromacs/legacyheaders/types/simple.h"
47 #include "gromacs/math/vec.h"
48 #include "gromacs/legacyheaders/nrnb.h"
50 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
51 #include "kernelutil_x86_avx_128_fma_single.h"
54 /* ## List of variables set by the generating script: */
56 /* ## Setttings that apply to the entire kernel: */
57 /* ## KERNEL_ELEC: String, choice for electrostatic interactions */
58 /* ## KERNEL_VDW: String, choice for van der Waals interactions */
59 /* ## KERNEL_NAME: String, name of this kernel */
60 /* ## KERNEL_VF: String telling if we calculate potential, force, or both */
61 /* ## GEOMETRY_I/GEOMETRY_J: String, name of each geometry, e.g. 'Water3' or '1Particle' */
63 /* ## Setttings that apply to particles in the outer (I) or inner (J) loops: */
64 /* ## PARTICLES_I[]/ Arrays with lists of i/j particles to use in kernel. It is */
65 /* ## PARTICLES_J[]: just [0] for particle geometry, but can be longer for water */
66 /* ## PARTICLES_ELEC_I[]/ Arrays with lists of i/j particle that have electrostatics */
67 /* ## PARTICLES_ELEC_J[]: interactions that should be calculated in this kernel. */
68 /* ## PARTICLES_VDW_I[]/ Arrays with the list of i/j particle that have VdW */
69 /* ## PARTICLES_VDW_J[]: interactions that should be calculated in this kernel. */
71 /* ## Setttings for pairs of interactions (e.g. 2nd i particle against 1st j particle) */
72 /* ## PAIRS_IJ[]: Array with (i,j) tuples of pairs for which interactions */
73 /* ## should be calculated in this kernel. Zero-charge particles */
74 /* ## do not have interactions with particles without vdw, and */
75 /* ## Vdw-only interactions are not evaluated in a no-vdw-kernel. */
76 /* ## INTERACTION_FLAGS[][]: 2D matrix, dimension e.g. 3*3 for water-water interactions. */
77 /* ## For each i-j pair, the element [I][J] is a list of strings */
78 /* ## defining properties/flags of this interaction. Examples */
79 /* ## include 'electrostatics'/'vdw' if that type of interaction */
80 /* ## should be evaluated, 'rsq'/'rinv'/'rinvsq' if those values */
81 /* ## are needed, and 'exactcutoff' or 'shift','switch' to */
82 /* ## decide if the force/potential should be modified. This way */
83 /* ## we only calculate values absolutely needed for each case. */
85 /* ## Calculate the size and offset for (merged/interleaved) table data */
88 * Gromacs nonbonded kernel: {KERNEL_NAME}
89 * Electrostatics interaction: {KERNEL_ELEC}
90 * VdW interaction: {KERNEL_VDW}
91 * Geometry: {GEOMETRY_I}-{GEOMETRY_J}
92 * Calculate force/pot: {KERNEL_VF}
96 (t_nblist * gmx_restrict nlist,
97 rvec * gmx_restrict xx,
98 rvec * gmx_restrict ff,
99 t_forcerec * gmx_restrict fr,
100 t_mdatoms * gmx_restrict mdatoms,
101 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
102 t_nrnb * gmx_restrict nrnb)
104 /* ## Not all variables are used for all kernels, but any optimizing compiler fixes that, */
105 /* ## so there is no point in going to extremes to exclude variables that are not needed. */
106 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
107 * just 0 for non-waters.
108 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
109 * jnr indices corresponding to data put in the four positions in the SIMD register.
111 int i_shift_offset,i_coord_offset,outeriter,inneriter;
112 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
113 int jnrA,jnrB,jnrC,jnrD;
114 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
115 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
116 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
118 real *shiftvec,*fshift,*x,*f;
119 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
121 __m128 fscal,rcutoff,rcutoff2,jidxall;
122 /* #for I in PARTICLES_I */
124 __m128 ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
126 /* #for J in PARTICLES_J */
127 int vdwjidx{J}A,vdwjidx{J}B,vdwjidx{J}C,vdwjidx{J}D;
128 __m128 jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
130 /* #for I,J in PAIRS_IJ */
131 __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};
133 /* #if KERNEL_ELEC != 'None' */
134 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
137 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
139 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
140 __m128 minushalf = _mm_set1_ps(-0.5);
141 real *invsqrta,*dvda,*gbtab;
143 /* #if KERNEL_VDW != 'None' */
145 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
148 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
149 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
151 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
153 __m128i ifour = _mm_set1_epi32(4);
154 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
157 /* #if 'LJEwald' in KERNEL_VDW */
158 /* #for I,J in PAIRS_IJ */
159 __m128 c6grid_{I}{J};
162 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
163 __m128 one_half = _mm_set1_ps(0.5);
164 __m128 minus_one = _mm_set1_ps(-1.0);
166 /* #if 'Ewald' in KERNEL_ELEC */
168 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
169 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
172 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
173 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
174 real rswitch_scalar,d_scalar;
176 __m128 dummy_mask,cutoff_mask;
177 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
178 __m128 one = _mm_set1_ps(1.0);
179 __m128 two = _mm_set1_ps(2.0);
185 jindex = nlist->jindex;
187 shiftidx = nlist->shift;
189 shiftvec = fr->shift_vec[0];
190 fshift = fr->fshift[0];
191 /* #if KERNEL_ELEC != 'None' */
192 facel = _mm_set1_ps(fr->epsfac);
193 charge = mdatoms->chargeA;
194 /* #if 'ReactionField' in KERNEL_ELEC */
195 krf = _mm_set1_ps(fr->ic->k_rf);
196 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
197 crf = _mm_set1_ps(fr->ic->c_rf);
200 /* #if KERNEL_VDW != 'None' */
201 nvdwtype = fr->ntype;
203 vdwtype = mdatoms->typeA;
205 /* #if 'LJEwald' in KERNEL_VDW */
206 vdwgridparam = fr->ljpme_c6grid;
207 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
208 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
209 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
212 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
213 vftab = kernel_data->table_elec_vdw->data;
214 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
215 /* #elif 'Table' in KERNEL_ELEC */
216 vftab = kernel_data->table_elec->data;
217 vftabscale = _mm_set1_ps(kernel_data->table_elec->scale);
218 /* #elif 'Table' in KERNEL_VDW */
219 vftab = kernel_data->table_vdw->data;
220 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
223 /* #if 'Ewald' in KERNEL_ELEC */
224 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
225 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
226 beta2 = _mm_mul_ps(beta,beta);
227 beta3 = _mm_mul_ps(beta,beta2);
228 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
229 ewtab = fr->ic->tabq_coul_F;
230 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
231 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
233 ewtab = fr->ic->tabq_coul_FDV0;
234 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
235 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
239 /* #if KERNEL_ELEC=='GeneralizedBorn' */
240 invsqrta = fr->invsqrta;
242 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
243 gbtab = fr->gbtab.data;
244 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
247 /* #if 'Water' in GEOMETRY_I */
248 /* Setup water-specific parameters */
249 inr = nlist->iinr[0];
250 /* #for I in PARTICLES_ELEC_I */
251 iq{I} = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+{I}]));
253 /* #for I in PARTICLES_VDW_I */
254 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
258 /* #if 'Water' in GEOMETRY_J */
259 /* #for J in PARTICLES_ELEC_J */
260 jq{J} = _mm_set1_ps(charge[inr+{J}]);
262 /* #for J in PARTICLES_VDW_J */
263 vdwjidx{J}A = 2*vdwtype[inr+{J}];
265 /* #for I,J in PAIRS_IJ */
266 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
267 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
269 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
270 /* #if 'LJEwald' in KERNEL_VDW */
271 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
272 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
273 c6grid_{I}{J} = _mm_set1_ps(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
275 c6_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
276 c12_{I}{J} = _mm_set1_ps(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
282 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
283 /* #if KERNEL_ELEC!='None' */
284 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
285 rcutoff_scalar = fr->rcoulomb;
287 rcutoff_scalar = fr->rvdw;
289 rcutoff = _mm_set1_ps(rcutoff_scalar);
290 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
293 /* #if KERNEL_MOD_VDW=='PotentialShift' */
294 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
295 rvdw = _mm_set1_ps(fr->rvdw);
298 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
299 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
300 rswitch_scalar = fr->rcoulomb_switch;
301 rswitch = _mm_set1_ps(rswitch_scalar);
303 rswitch_scalar = fr->rvdw_switch;
304 rswitch = _mm_set1_ps(rswitch_scalar);
306 /* Setup switch parameters */
307 d_scalar = rcutoff_scalar-rswitch_scalar;
308 d = _mm_set1_ps(d_scalar);
309 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
310 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
311 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
312 /* #if 'Force' in KERNEL_VF */
313 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
314 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
315 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
319 /* Avoid stupid compiler warnings */
320 jnrA = jnrB = jnrC = jnrD = 0;
326 /* ## Keep track of the floating point operations we issue for reporting! */
327 /* #define OUTERFLOPS 0 */
331 for(iidx=0;iidx<4*DIM;iidx++)
336 /* Start outer loop over neighborlists */
337 for(iidx=0; iidx<nri; iidx++)
339 /* Load shift vector for this list */
340 i_shift_offset = DIM*shiftidx[iidx];
342 /* Load limits for loop over neighbors */
343 j_index_start = jindex[iidx];
344 j_index_end = jindex[iidx+1];
346 /* Get outer coordinate index */
348 i_coord_offset = DIM*inr;
350 /* Load i particle coords and add shift vector */
351 /* #if GEOMETRY_I == 'Particle' */
352 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
353 /* #elif GEOMETRY_I == 'Water3' */
354 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
355 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
356 /* #elif GEOMETRY_I == 'Water4' */
357 /* #if 0 in PARTICLES_I */
358 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
359 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
361 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
362 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
366 /* #if 'Force' in KERNEL_VF */
367 /* #for I in PARTICLES_I */
368 fix{I} = _mm_setzero_ps();
369 fiy{I} = _mm_setzero_ps();
370 fiz{I} = _mm_setzero_ps();
374 /* ## For water we already preloaded parameters at the start of the kernel */
375 /* #if not 'Water' in GEOMETRY_I */
376 /* Load parameters for i particles */
377 /* #for I in PARTICLES_ELEC_I */
378 iq{I} = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+{I}));
379 /* #define OUTERFLOPS OUTERFLOPS+1 */
380 /* #if KERNEL_ELEC=='GeneralizedBorn' */
381 isai{I} = _mm_load1_ps(invsqrta+inr+{I});
384 /* #for I in PARTICLES_VDW_I */
385 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
389 /* #if 'Potential' in KERNEL_VF */
390 /* Reset potential sums */
391 /* #if KERNEL_ELEC != 'None' */
392 velecsum = _mm_setzero_ps();
394 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
395 vgbsum = _mm_setzero_ps();
397 /* #if KERNEL_VDW != 'None' */
398 vvdwsum = _mm_setzero_ps();
401 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
402 dvdasum = _mm_setzero_ps();
405 /* #for ROUND in ['Loop','Epilogue'] */
407 /* #if ROUND =='Loop' */
408 /* Start inner kernel loop */
409 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
411 /* ## First round is normal loop (next statement resets indentation) */
418 /* ## Second round is epilogue */
420 /* #define INNERFLOPS 0 */
422 /* Get j neighbor index, and coordinate index */
423 /* #if ROUND =='Loop' */
429 jnrlistA = jjnr[jidx];
430 jnrlistB = jjnr[jidx+1];
431 jnrlistC = jjnr[jidx+2];
432 jnrlistD = jjnr[jidx+3];
433 /* Sign of each element will be negative for non-real atoms.
434 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
435 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
437 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
438 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
439 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
440 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
441 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
443 j_coord_offsetA = DIM*jnrA;
444 j_coord_offsetB = DIM*jnrB;
445 j_coord_offsetC = DIM*jnrC;
446 j_coord_offsetD = DIM*jnrD;
448 /* load j atom coordinates */
449 /* #if GEOMETRY_J == 'Particle' */
450 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
451 x+j_coord_offsetC,x+j_coord_offsetD,
453 /* #elif GEOMETRY_J == 'Water3' */
454 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
455 x+j_coord_offsetC,x+j_coord_offsetD,
456 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
457 /* #elif GEOMETRY_J == 'Water4' */
458 /* #if 0 in PARTICLES_J */
459 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
460 x+j_coord_offsetC,x+j_coord_offsetD,
461 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
462 &jy2,&jz2,&jx3,&jy3,&jz3);
464 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
465 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
466 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
470 /* Calculate displacement vector */
471 /* #for I,J in PAIRS_IJ */
472 dx{I}{J} = _mm_sub_ps(ix{I},jx{J});
473 dy{I}{J} = _mm_sub_ps(iy{I},jy{J});
474 dz{I}{J} = _mm_sub_ps(iz{I},jz{J});
475 /* #define INNERFLOPS INNERFLOPS+3 */
478 /* Calculate squared distance and things based on it */
479 /* #for I,J in PAIRS_IJ */
480 rsq{I}{J} = gmx_mm_calc_rsq_ps(dx{I}{J},dy{I}{J},dz{I}{J});
481 /* #define INNERFLOPS INNERFLOPS+5 */
484 /* #for I,J in PAIRS_IJ */
485 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
486 rinv{I}{J} = gmx_mm_invsqrt_ps(rsq{I}{J});
487 /* #define INNERFLOPS INNERFLOPS+5 */
491 /* #for I,J in PAIRS_IJ */
492 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
493 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
494 rinvsq{I}{J} = gmx_mm_inv_ps(rsq{I}{J});
495 /* #define INNERFLOPS INNERFLOPS+4 */
497 rinvsq{I}{J} = _mm_mul_ps(rinv{I}{J},rinv{I}{J});
498 /* #define INNERFLOPS INNERFLOPS+1 */
503 /* #if not 'Water' in GEOMETRY_J */
504 /* Load parameters for j particles */
505 /* #for J in PARTICLES_ELEC_J */
506 jq{J} = gmx_mm_load_4real_swizzle_ps(charge+jnrA+{J},charge+jnrB+{J},
507 charge+jnrC+{J},charge+jnrD+{J});
508 /* #if KERNEL_ELEC=='GeneralizedBorn' */
509 isaj{J} = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+{J},invsqrta+jnrB+{J},
510 invsqrta+jnrC+{J},invsqrta+jnrD+{J});
513 /* #for J in PARTICLES_VDW_J */
514 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
515 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
516 vdwjidx{J}C = 2*vdwtype[jnrC+{J}];
517 vdwjidx{J}D = 2*vdwtype[jnrD+{J}];
521 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
522 /* #for J in PARTICLES_J */
523 fjx{J} = _mm_setzero_ps();
524 fjy{J} = _mm_setzero_ps();
525 fjz{J} = _mm_setzero_ps();
529 /* #for I,J in PAIRS_IJ */
531 /**************************
532 * CALCULATE INTERACTIONS *
533 **************************/
535 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
536 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
537 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
538 if (gmx_mm_any_lt(rsq{I}{J},rcutoff2))
540 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
543 /* #define INNERFLOPS INNERFLOPS+1 */
546 /* #if 'r' in INTERACTION_FLAGS[I][J] */
547 r{I}{J} = _mm_mul_ps(rsq{I}{J},rinv{I}{J});
548 /* #if ROUND == 'Epilogue' */
549 r{I}{J} = _mm_andnot_ps(dummy_mask,r{I}{J});
550 /* #define INNERFLOPS INNERFLOPS+1 */
552 /* #define INNERFLOPS INNERFLOPS+1 */
555 /* ## For water geometries we already loaded parameters at the start of the kernel */
556 /* #if not 'Water' in GEOMETRY_J */
557 /* Compute parameters for interactions between i and j atoms */
558 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
559 qq{I}{J} = _mm_mul_ps(iq{I},jq{J});
560 /* #define INNERFLOPS INNERFLOPS+1 */
562 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
563 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset{I}+vdwjidx{J}A,
564 vdwparam+vdwioffset{I}+vdwjidx{J}B,
565 vdwparam+vdwioffset{I}+vdwjidx{J}C,
566 vdwparam+vdwioffset{I}+vdwjidx{J}D,
567 &c6_{I}{J},&c12_{I}{J});
569 /* #if 'LJEwald' in KERNEL_VDW */
570 c6grid_{I}{J} = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
571 vdwgridparam+vdwioffset{I}+vdwjidx{J}B,
572 vdwgridparam+vdwioffset{I}+vdwjidx{J}C,
573 vdwgridparam+vdwioffset{I}+vdwjidx{J}D);
579 /* #if 'table' in INTERACTION_FLAGS[I][J] */
580 /* Calculate table index by multiplying r with table scale and truncate to integer */
581 rt = _mm_mul_ps(r{I}{J},vftabscale);
582 vfitab = _mm_cvttps_epi32(rt);
584 vfeps = _mm_frcz_ps(rt);
586 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
588 twovfeps = _mm_add_ps(vfeps,vfeps);
589 /* #define INNERFLOPS INNERFLOPS+4 */
590 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
591 /* ## 3 tables, 4 bytes per point: multiply index by 12 */
592 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
593 /* #elif 'Table' in KERNEL_ELEC */
594 /* ## 1 table, 4 bytes per point: multiply index by 4 */
595 vfitab = _mm_slli_epi32(vfitab,2);
596 /* #elif 'Table' in KERNEL_VDW */
597 /* ## 2 tables, 4 bytes per point: multiply index by 8 */
598 vfitab = _mm_slli_epi32(vfitab,3);
602 /* ## ELECTROSTATIC INTERACTIONS */
603 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
605 /* #if KERNEL_ELEC=='Coulomb' */
607 /* COULOMB ELECTROSTATICS */
608 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
609 /* #define INNERFLOPS INNERFLOPS+1 */
610 /* #if 'Force' in KERNEL_VF */
611 felec = _mm_mul_ps(velec,rinvsq{I}{J});
612 /* #define INNERFLOPS INNERFLOPS+2 */
615 /* #elif KERNEL_ELEC=='ReactionField' */
617 /* REACTION-FIELD ELECTROSTATICS */
618 /* #if 'Potential' in KERNEL_VF */
619 velec = _mm_mul_ps(qq{I}{J},_mm_sub_ps(_mm_macc_ps(krf,rsq{I}{J},rinv{I}{J}),crf));
620 /* #define INNERFLOPS INNERFLOPS+4 */
622 /* #if 'Force' in KERNEL_VF */
623 felec = _mm_mul_ps(qq{I}{J},_mm_msub_ps(rinv{I}{J},rinvsq{I}{J},krf2));
624 /* #define INNERFLOPS INNERFLOPS+3 */
627 /* #elif KERNEL_ELEC=='GeneralizedBorn' */
629 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
630 isaprod = _mm_mul_ps(isai{I},isaj{J});
631 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq{I}{J},_mm_mul_ps(isaprod,gbinvepsdiff)));
632 gbscale = _mm_mul_ps(isaprod,gbtabscale);
633 /* #define INNERFLOPS INNERFLOPS+5 */
635 /* Calculate generalized born table index - this is a separate table from the normal one,
636 * but we use the same procedure by multiplying r with scale and truncating to integer.
638 rt = _mm_mul_ps(r{I}{J},gbscale);
639 gbitab = _mm_cvttps_epi32(rt);
641 gbeps = _mm_frcz_ps(rt);
643 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
645 gbitab = _mm_slli_epi32(gbitab,2);
647 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
648 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
649 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
650 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
651 _MM_TRANSPOSE4_PS(Y,F,G,H);
652 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
653 VV = _mm_macc_ps(gbeps,Fp,Y);
654 vgb = _mm_mul_ps(gbqqfactor,VV);
655 /* #define INNERFLOPS INNERFLOPS+10 */
657 /* #if 'Force' in KERNEL_VF */
658 twogbeps = _mm_add_ps(gbeps,gbeps);
659 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
660 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
661 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r{I}{J},vgb));
662 /* #if ROUND == 'Epilogue' */
663 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
665 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
666 /* #if ROUND == 'Loop' */
672 /* 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. */
673 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
674 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
675 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
676 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
678 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj{J},isaj{J})));
679 /* #define INNERFLOPS INNERFLOPS+13 */
681 velec = _mm_mul_ps(qq{I}{J},rinv{I}{J});
682 /* #define INNERFLOPS INNERFLOPS+1 */
683 /* #if 'Force' in KERNEL_VF */
684 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv{I}{J},fgb),rinv{I}{J});
685 /* #define INNERFLOPS INNERFLOPS+3 */
688 /* #elif KERNEL_ELEC=='Ewald' */
689 /* EWALD ELECTROSTATICS */
691 /* Analytical PME correction */
692 zeta2 = _mm_mul_ps(beta2,rsq{I}{J});
693 /* #if 'Force' in KERNEL_VF */
694 rinv3 = _mm_mul_ps(rinvsq{I}{J},rinv{I}{J});
695 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
696 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
697 felec = _mm_mul_ps(qq{I}{J},felec);
699 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
700 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
701 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
702 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv{I}{J},sh_ewald));
704 velec = _mm_nmacc_ps(pmecorrV,beta,rinv{I}{J});
706 velec = _mm_mul_ps(qq{I}{J},velec);
709 /* #elif KERNEL_ELEC=='CubicSplineTable' */
711 /* CUBIC SPLINE TABLE ELECTROSTATICS */
712 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
713 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
714 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
715 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
716 _MM_TRANSPOSE4_PS(Y,F,G,H);
717 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
718 /* #define INNERFLOPS INNERFLOPS+4 */
719 /* #if 'Potential' in KERNEL_VF */
720 VV = _mm_macc_ps(vfeps,Fp,Y);
721 velec = _mm_mul_ps(qq{I}{J},VV);
722 /* #define INNERFLOPS INNERFLOPS+3 */
724 /* #if 'Force' in KERNEL_VF */
725 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
726 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq{I}{J},FF),_mm_mul_ps(vftabscale,rinv{I}{J})));
727 /* #define INNERFLOPS INNERFLOPS+7 */
730 /* ## End of check for electrostatics interaction forms */
732 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
734 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
736 /* #if KERNEL_VDW=='LennardJones' */
738 /* LENNARD-JONES DISPERSION/REPULSION */
740 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
741 /* #define INNERFLOPS INNERFLOPS+2 */
742 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
743 vvdw6 = _mm_mul_ps(c6_{I}{J},rinvsix);
744 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
745 /* #define INNERFLOPS INNERFLOPS+3 */
746 /* #if KERNEL_MOD_VDW=='PotentialShift' */
747 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
748 _mm_mul_ps( _mm_nmacc_ps(c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
749 /* #define INNERFLOPS INNERFLOPS+8 */
751 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
752 /* #define INNERFLOPS INNERFLOPS+3 */
754 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
755 /* #if 'Force' in KERNEL_VF */
756 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq{I}{J});
757 /* #define INNERFLOPS INNERFLOPS+2 */
759 /* #elif KERNEL_VF=='Force' */
760 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
761 fvdw = _mm_mul_ps(_mm_msub_ps(c12_{I}{J},rinvsix,c6_{I}{J}),_mm_mul_ps(rinvsix,rinvsq{I}{J}));
762 /* #define INNERFLOPS INNERFLOPS+4 */
765 /* #elif KERNEL_VDW=='CubicSplineTable' */
767 /* CUBIC SPLINE TABLE DISPERSION */
768 /* #if 'Table' in KERNEL_ELEC */
769 vfitab = _mm_add_epi32(vfitab,ifour);
771 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
772 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
773 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
774 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
775 _MM_TRANSPOSE4_PS(Y,F,G,H);
776 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
777 /* #define INNERFLOPS INNERFLOPS+4 */
778 /* #if 'Potential' in KERNEL_VF */
779 VV = _mm_macc_ps(vfeps,Fp,Y);
780 vvdw6 = _mm_mul_ps(c6_{I}{J},VV);
781 /* #define INNERFLOPS INNERFLOPS+3 */
783 /* #if 'Force' in KERNEL_VF */
784 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
785 fvdw6 = _mm_mul_ps(c6_{I}{J},FF);
786 /* #define INNERFLOPS INNERFLOPS+4 */
789 /* CUBIC SPLINE TABLE REPULSION */
790 vfitab = _mm_add_epi32(vfitab,ifour);
791 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
792 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
793 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
794 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
795 _MM_TRANSPOSE4_PS(Y,F,G,H);
796 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
797 /* #define INNERFLOPS INNERFLOPS+4 */
798 /* #if 'Potential' in KERNEL_VF */
799 VV = _mm_macc_ps(vfeps,Fp,Y);
800 vvdw12 = _mm_mul_ps(c12_{I}{J},VV);
801 /* #define INNERFLOPS INNERFLOPS+3 */
803 /* #if 'Force' in KERNEL_VF */
804 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
805 fvdw12 = _mm_mul_ps(c12_{I}{J},FF);
806 /* #define INNERFLOPS INNERFLOPS+5 */
808 /* #if 'Potential' in KERNEL_VF */
809 vvdw = _mm_add_ps(vvdw12,vvdw6);
810 /* #define INNERFLOPS INNERFLOPS+1 */
812 /* #if 'Force' in KERNEL_VF */
813 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv{I}{J})));
814 /* #define INNERFLOPS INNERFLOPS+4 */
817 /* #elif KERNEL_VDW=='LJEwald' */
819 /* Analytical LJ-PME */
820 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
821 ewcljrsq = _mm_mul_ps(ewclj2,rsq{I}{J});
822 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
823 exponent = gmx_simd_exp_r(ewcljrsq);
824 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
825 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
826 /* #define INNERFLOPS INNERFLOPS+10 */
827 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
828 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
829 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_{I}{J},_mm_sub_ps(one,poly),c6_{I}{J}),rinvsix);
830 vvdw12 = _mm_mul_ps(c12_{I}{J},_mm_mul_ps(rinvsix,rinvsix));
831 /* #define INNERFLOPS INNERFLOPS+5 */
832 /* #if KERNEL_MOD_VDW=='PotentialShift' */
833 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_{I}{J},_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
834 _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));
835 /* #define INNERFLOPS INNERFLOPS+7 */
837 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
838 /* #define INNERFLOPS INNERFLOPS+2 */
840 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
841 /* #if 'Force' in KERNEL_VF */
842 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
843 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});
844 /* #define INNERFLOPS INNERFLOPS+5 */
846 /* #elif KERNEL_VF=='Force' */
847 /* f6A = 6 * C6grid * (1 - poly) */
848 f6A = _mm_mul_ps(c6grid_{I}{J},_mm_sub_ps(one,poly));
849 /* f6B = C6grid * exponent * beta^6 */
850 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_{I}{J},one_sixth),_mm_mul_ps(exponent,ewclj6));
851 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
852 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});
853 /* #define INNERFLOPS INNERFLOPS+10 */
856 /* ## End of check for vdw interaction forms */
858 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
860 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
861 d = _mm_sub_ps(r{I}{J},rswitch);
862 d = _mm_max_ps(d,_mm_setzero_ps());
863 d2 = _mm_mul_ps(d,d);
864 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
865 /* #define INNERFLOPS INNERFLOPS+10 */
867 /* #if 'Force' in KERNEL_VF */
868 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
869 /* #define INNERFLOPS INNERFLOPS+5 */
872 /* Evaluate switch function */
873 /* #if 'Force' in KERNEL_VF */
874 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
875 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
876 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(velec,dsw)) );
877 /* #define INNERFLOPS INNERFLOPS+4 */
879 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
880 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv{I}{J},_mm_mul_ps(vvdw,dsw)) );
881 /* #define INNERFLOPS INNERFLOPS+4 */
884 /* #if 'Potential' in KERNEL_VF */
885 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
886 velec = _mm_mul_ps(velec,sw);
887 /* #define INNERFLOPS INNERFLOPS+1 */
889 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
890 vvdw = _mm_mul_ps(vvdw,sw);
891 /* #define INNERFLOPS INNERFLOPS+1 */
895 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
896 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
897 cutoff_mask = _mm_cmplt_ps(rsq{I}{J},rcutoff2);
898 /* #define INNERFLOPS INNERFLOPS+1 */
901 /* #if 'Potential' in KERNEL_VF */
902 /* Update potential sum for this i atom from the interaction with this j atom. */
903 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
904 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
905 velec = _mm_and_ps(velec,cutoff_mask);
906 /* #define INNERFLOPS INNERFLOPS+1 */
908 /* #if ROUND == 'Epilogue' */
909 velec = _mm_andnot_ps(dummy_mask,velec);
911 velecsum = _mm_add_ps(velecsum,velec);
912 /* #define INNERFLOPS INNERFLOPS+1 */
913 /* #if KERNEL_ELEC=='GeneralizedBorn' */
914 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
915 vgb = _mm_and_ps(vgb,cutoff_mask);
916 /* #define INNERFLOPS INNERFLOPS+1 */
918 /* #if ROUND == 'Epilogue' */
919 vgb = _mm_andnot_ps(dummy_mask,vgb);
921 vgbsum = _mm_add_ps(vgbsum,vgb);
922 /* #define INNERFLOPS INNERFLOPS+1 */
925 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
926 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
927 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
928 vvdw = _mm_and_ps(vvdw,cutoff_mask);
929 /* #define INNERFLOPS INNERFLOPS+1 */
931 /* #if ROUND == 'Epilogue' */
932 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
934 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
935 /* #define INNERFLOPS INNERFLOPS+1 */
939 /* #if 'Force' in KERNEL_VF */
941 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
942 fscal = _mm_add_ps(felec,fvdw);
943 /* #define INNERFLOPS INNERFLOPS+1 */
944 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
946 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
950 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
951 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
952 fscal = _mm_and_ps(fscal,cutoff_mask);
953 /* #define INNERFLOPS INNERFLOPS+1 */
956 /* #if ROUND == 'Epilogue' */
957 fscal = _mm_andnot_ps(dummy_mask,fscal);
960 /* ## Construction of vectorial force built into FMA instructions now */
961 /* #define INNERFLOPS INNERFLOPS+3 */
963 /* Update vectorial force */
964 fix{I} = _mm_macc_ps(dx{I}{J},fscal,fix{I});
965 fiy{I} = _mm_macc_ps(dy{I}{J},fscal,fiy{I});
966 fiz{I} = _mm_macc_ps(dz{I}{J},fscal,fiz{I});
967 /* #define INNERFLOPS INNERFLOPS+6 */
969 /* #if GEOMETRY_I == 'Particle' */
970 /* #if ROUND == 'Loop' */
971 fjptrA = f+j_coord_offsetA;
972 fjptrB = f+j_coord_offsetB;
973 fjptrC = f+j_coord_offsetC;
974 fjptrD = f+j_coord_offsetD;
976 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
977 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
978 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
979 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
981 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
982 _mm_mul_ps(dx{I}{J},fscal),
983 _mm_mul_ps(dy{I}{J},fscal),
984 _mm_mul_ps(dz{I}{J},fscal));
985 /* #define INNERFLOPS INNERFLOPS+3 */
987 fjx{J} = _mm_macc_ps(dx{I}{J},fscal,fjx{J});
988 fjy{J} = _mm_macc_ps(dy{I}{J},fscal,fjy{J});
989 fjz{J} = _mm_macc_ps(dz{I}{J},fscal,fjz{J});
990 /* #define INNERFLOPS INNERFLOPS+3 */
995 /* ## Note special check for TIP4P-TIP4P. Since we are cutting of all hydrogen interactions we also cut the LJ-only O-O interaction */
996 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] or (GEOMETRY_I=='Water4' and GEOMETRY_J=='Water4' and 'exactcutoff' in INTERACTION_FLAGS[1][1]) */
997 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1002 /* ## End of check for the interaction being outside the cutoff */
1005 /* ## End of loop over i-j interaction pairs */
1007 /* #if GEOMETRY_I != 'Particle' */
1008 /* #if ROUND == 'Loop' */
1009 fjptrA = f+j_coord_offsetA;
1010 fjptrB = f+j_coord_offsetB;
1011 fjptrC = f+j_coord_offsetC;
1012 fjptrD = f+j_coord_offsetD;
1014 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1015 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1016 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1017 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1021 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1022 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1023 /* #elif GEOMETRY_J == 'Water3' */
1024 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1025 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1026 /* #define INNERFLOPS INNERFLOPS+9 */
1027 /* #elif GEOMETRY_J == 'Water4' */
1028 /* #if 0 in PARTICLES_J */
1029 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1030 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1031 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1032 /* #define INNERFLOPS INNERFLOPS+12 */
1034 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1035 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1036 /* #define INNERFLOPS INNERFLOPS+9 */
1040 /* Inner loop uses {INNERFLOPS} flops */
1045 /* End of innermost loop */
1047 /* #if 'Force' in KERNEL_VF */
1048 /* #if GEOMETRY_I == 'Particle' */
1049 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
1050 f+i_coord_offset,fshift+i_shift_offset);
1051 /* #define OUTERFLOPS OUTERFLOPS+6 */
1052 /* #elif GEOMETRY_I == 'Water3' */
1053 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1054 f+i_coord_offset,fshift+i_shift_offset);
1055 /* #define OUTERFLOPS OUTERFLOPS+18 */
1056 /* #elif GEOMETRY_I == 'Water4' */
1057 /* #if 0 in PARTICLES_I */
1058 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1059 f+i_coord_offset,fshift+i_shift_offset);
1060 /* #define OUTERFLOPS OUTERFLOPS+24 */
1062 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1063 f+i_coord_offset+DIM,fshift+i_shift_offset);
1064 /* #define OUTERFLOPS OUTERFLOPS+18 */
1069 /* #if 'Potential' in KERNEL_VF */
1071 /* Update potential energies */
1072 /* #if KERNEL_ELEC != 'None' */
1073 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1074 /* #define OUTERFLOPS OUTERFLOPS+1 */
1076 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1077 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
1078 /* #define OUTERFLOPS OUTERFLOPS+1 */
1080 /* #if KERNEL_VDW != 'None' */
1081 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1082 /* #define OUTERFLOPS OUTERFLOPS+1 */
1085 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1086 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai{I},isai{I}));
1087 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
1090 /* Increment number of inner iterations */
1091 inneriter += j_index_end - j_index_start;
1093 /* Outer loop uses {OUTERFLOPS} flops */
1096 /* Increment number of outer iterations */
1099 /* Update outer/inner flops */
1100 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1101 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1102 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1103 /* #if GEOMETRY_I == 'Water3' */
1104 /* #define ISUFFIX '_W3' */
1105 /* #elif GEOMETRY_I == 'Water4' */
1106 /* #define ISUFFIX '_W4' */
1108 /* #define ISUFFIX '' */
1110 /* #if GEOMETRY_J == 'Water3' */
1111 /* #define JSUFFIX 'W3' */
1112 /* #elif GEOMETRY_J == 'Water4' */
1113 /* #define JSUFFIX 'W4' */
1115 /* #define JSUFFIX '' */
1117 /* #if 'PotentialAndForce' in KERNEL_VF */
1118 /* #define VFSUFFIX '_VF' */
1119 /* #elif 'Potential' in KERNEL_VF */
1120 /* #define VFSUFFIX '_V' */
1122 /* #define VFSUFFIX '_F' */
1125 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1126 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1127 /* #elif KERNEL_ELEC != 'None' */
1128 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1130 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});