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 "kernelutil_sparc64_hpc_ace_double.h"
51 /* ## List of variables set by the generating script: */
53 /* ## Setttings that apply to the entire kernel: */
54 /* ## KERNEL_ELEC: String, choice for electrostatic interactions */
55 /* ## KERNEL_VDW: String, choice for van der Waals interactions */
56 /* ## KERNEL_NAME: String, name of this kernel */
57 /* ## KERNEL_VF: String telling if we calculate potential, force, or both */
58 /* ## GEOMETRY_I/GEOMETRY_J: String, name of each geometry, e.g. 'Water3' or '1Particle' */
60 /* ## Setttings that apply to particles in the outer (I) or inner (J) loops: */
61 /* ## PARTICLES_I[]/ Arrays with lists of i/j particles to use in kernel. It is */
62 /* ## PARTICLES_J[]: just [0] for particle geometry, but can be longer for water */
63 /* ## PARTICLES_ELEC_I[]/ Arrays with lists of i/j particle that have electrostatics */
64 /* ## PARTICLES_ELEC_J[]: interactions that should be calculated in this kernel. */
65 /* ## PARTICLES_VDW_I[]/ Arrays with the list of i/j particle that have VdW */
66 /* ## PARTICLES_VDW_J[]: interactions that should be calculated in this kernel. */
68 /* ## Setttings for pairs of interactions (e.g. 2nd i particle against 1st j particle) */
69 /* ## PAIRS_IJ[]: Array with (i,j) tuples of pairs for which interactions */
70 /* ## should be calculated in this kernel. Zero-charge particles */
71 /* ## do not have interactions with particles without vdw, and */
72 /* ## Vdw-only interactions are not evaluated in a no-vdw-kernel. */
73 /* ## INTERACTION_FLAGS[][]: 2D matrix, dimension e.g. 3*3 for water-water interactions. */
74 /* ## For each i-j pair, the element [I][J] is a list of strings */
75 /* ## defining properties/flags of this interaction. Examples */
76 /* ## include 'electrostatics'/'vdw' if that type of interaction */
77 /* ## should be evaluated, 'rsq'/'rinv'/'rinvsq' if those values */
78 /* ## are needed, and 'exactcutoff' or 'shift','switch' to */
79 /* ## decide if the force/potential should be modified. This way */
80 /* ## we only calculate values absolutely needed for each case. */
82 /* ## Calculate the size and offset for (merged/interleaved) table data */
85 * Gromacs nonbonded kernel: {KERNEL_NAME}
86 * Electrostatics interaction: {KERNEL_ELEC}
87 * VdW interaction: {KERNEL_VDW}
88 * Geometry: {GEOMETRY_I}-{GEOMETRY_J}
89 * Calculate force/pot: {KERNEL_VF}
93 (t_nblist * gmx_restrict nlist,
94 rvec * gmx_restrict xx,
95 rvec * gmx_restrict ff,
96 t_forcerec * gmx_restrict fr,
97 t_mdatoms * gmx_restrict mdatoms,
98 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
99 t_nrnb * gmx_restrict nrnb)
101 /* ## Not all variables are used for all kernels, but any optimizing compiler fixes that, */
102 /* ## so there is no point in going to extremes to exclude variables that are not needed. */
103 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
104 * just 0 for non-waters.
105 * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
106 * jnr indices corresponding to data put in the four positions in the SIMD register.
108 int i_shift_offset,i_coord_offset,outeriter,inneriter;
109 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
111 int j_coord_offsetA,j_coord_offsetB;
112 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
114 real *shiftvec,*fshift,*x,*f;
115 _fjsp_v2r8 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
116 /* #for I in PARTICLES_I */
118 _fjsp_v2r8 ix{I},iy{I},iz{I},fix{I},fiy{I},fiz{I},iq{I},isai{I};
120 /* #for J in PARTICLES_J */
121 int vdwjidx{J}A,vdwjidx{J}B;
122 _fjsp_v2r8 jx{J},jy{J},jz{J},fjx{J},fjy{J},fjz{J},jq{J},isaj{J};
124 /* #for I,J in PAIRS_IJ */
125 _fjsp_v2r8 dx{I}{J},dy{I}{J},dz{I}{J},rsq{I}{J},rinv{I}{J},rinvsq{I}{J},r{I}{J},qq{I}{J},c6_{I}{J},c12_{I}{J};
127 /* #if KERNEL_ELEC != 'None' */
128 _fjsp_v2r8 velec,felec,velecsum,facel,crf,krf,krf2;
131 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
132 _fjsp_v2r8 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
133 _fjsp_v2r8 minushalf = gmx_fjsp_set1_v2r8(-0.5);
134 real *invsqrta,*dvda,*gbtab;
136 /* #if KERNEL_VDW != 'None' */
138 _fjsp_v2r8 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
141 _fjsp_v2r8 one_sixth = gmx_fjsp_set1_v2r8(1.0/6.0);
142 _fjsp_v2r8 one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
144 /* #if 'Table' in KERNEL_ELEC or 'GeneralizedBorn' in KERNEL_ELEC or 'Table' in KERNEL_VDW */
145 _fjsp_v2r8 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
148 /* #if 'LJEwald' in KERNEL_VDW */
149 /* #for I,J in PAIRS_IJ */
150 _fjsp_v2r8 c6grid_{I}{J};
153 _fjsp_v2r8 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
154 _fjsp_v2r8 one_half = gmx_fjsp_set1_v2r8(0.5);
155 _fjsp_v2r8 minus_one = gmx_fjsp_set1_v2r8(-1.0);
157 /* #if 'Ewald' in KERNEL_ELEC */
158 _fjsp_v2r8 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
161 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
162 _fjsp_v2r8 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
163 real rswitch_scalar,d_scalar;
166 _fjsp_v2r8 dummy_mask,cutoff_mask;
167 _fjsp_v2r8 one = gmx_fjsp_set1_v2r8(1.0);
168 _fjsp_v2r8 two = gmx_fjsp_set1_v2r8(2.0);
169 union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
176 jindex = nlist->jindex;
178 shiftidx = nlist->shift;
180 shiftvec = fr->shift_vec[0];
181 fshift = fr->fshift[0];
182 /* #if KERNEL_ELEC != 'None' */
183 facel = gmx_fjsp_set1_v2r8(fr->epsfac);
184 charge = mdatoms->chargeA;
185 /* #if 'ReactionField' in KERNEL_ELEC */
186 krf = gmx_fjsp_set1_v2r8(fr->ic->k_rf);
187 krf2 = gmx_fjsp_set1_v2r8(fr->ic->k_rf*2.0);
188 crf = gmx_fjsp_set1_v2r8(fr->ic->c_rf);
191 /* #if KERNEL_VDW != 'None' */
192 nvdwtype = fr->ntype;
194 vdwtype = mdatoms->typeA;
196 /* #if 'LJEwald' in KERNEL_VDW */
197 vdwgridparam = fr->ljpme_c6grid;
198 sh_lj_ewald = gmx_fjsp_set1_v2r8(fr->ic->sh_lj_ewald);
199 ewclj = gmx_fjsp_set1_v2r8(fr->ewaldcoeff_lj);
200 ewclj2 = _fjsp_mul_v2r8(minus_one,_fjsp_mul_v2r8(ewclj,ewclj));
203 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
204 vftab = kernel_data->table_elec_vdw->data;
205 vftabscale = gmx_fjsp_set1_v2r8(kernel_data->table_elec_vdw->scale);
206 /* #elif 'Table' in KERNEL_ELEC */
207 vftab = kernel_data->table_elec->data;
208 vftabscale = gmx_fjsp_set1_v2r8(kernel_data->table_elec->scale);
209 /* #elif 'Table' in KERNEL_VDW */
210 vftab = kernel_data->table_vdw->data;
211 vftabscale = gmx_fjsp_set1_v2r8(kernel_data->table_vdw->scale);
214 /* #if 'Ewald' in KERNEL_ELEC */
215 sh_ewald = gmx_fjsp_set1_v2r8(fr->ic->sh_ewald);
216 /* #if KERNEL_VF=='Force' and KERNEL_MOD_ELEC!='PotentialSwitch' */
217 ewtab = fr->ic->tabq_coul_F;
218 ewtabscale = gmx_fjsp_set1_v2r8(fr->ic->tabq_scale);
219 ewtabhalfspace = gmx_fjsp_set1_v2r8(0.5/fr->ic->tabq_scale);
221 ewtab = fr->ic->tabq_coul_FDV0;
222 ewtabscale = gmx_fjsp_set1_v2r8(fr->ic->tabq_scale);
223 ewtabhalfspace = gmx_fjsp_set1_v2r8(0.5/fr->ic->tabq_scale);
227 /* #if KERNEL_ELEC=='GeneralizedBorn' */
228 invsqrta = fr->invsqrta;
230 gbtabscale = gmx_fjsp_set1_v2r8(fr->gbtab.scale);
231 gbtab = fr->gbtab.data;
232 gbinvepsdiff = gmx_fjsp_set1_v2r8((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
235 /* #if 'Water' in GEOMETRY_I */
236 /* Setup water-specific parameters */
237 inr = nlist->iinr[0];
238 /* #for I in PARTICLES_ELEC_I */
239 iq{I} = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+{I}]));
241 /* #for I in PARTICLES_VDW_I */
242 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
246 /* #if 'Water' in GEOMETRY_J */
247 /* #for J in PARTICLES_ELEC_J */
248 jq{J} = gmx_fjsp_set1_v2r8(charge[inr+{J}]);
250 /* #for J in PARTICLES_VDW_J */
251 vdwjidx{J}A = 2*vdwtype[inr+{J}];
253 /* #for I,J in PAIRS_IJ */
254 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
255 qq{I}{J} = _fjsp_mul_v2r8(iq{I},jq{J});
257 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
258 /* #if 'LJEwald' in KERNEL_VDW */
259 c6_{I}{J} = gmx_fjsp_set1_v2r8(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
260 c12_{I}{J} = gmx_fjsp_set1_v2r8(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
261 c6grid_{I}{J} = gmx_fjsp_set1_v2r8(vdwgridparam[vdwioffset{I}+vdwjidx{J}A]);
263 c6_{I}{J} = gmx_fjsp_set1_v2r8(vdwparam[vdwioffset{I}+vdwjidx{J}A]);
264 c12_{I}{J} = gmx_fjsp_set1_v2r8(vdwparam[vdwioffset{I}+vdwjidx{J}A+1]);
270 /* #if KERNEL_MOD_ELEC!='None' or KERNEL_MOD_VDW!='None' */
271 /* #if KERNEL_ELEC!='None' */
272 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
273 rcutoff_scalar = fr->rcoulomb;
275 rcutoff_scalar = fr->rvdw;
277 rcutoff = gmx_fjsp_set1_v2r8(rcutoff_scalar);
278 rcutoff2 = _fjsp_mul_v2r8(rcutoff,rcutoff);
281 /* #if KERNEL_MOD_VDW=='PotentialShift' */
282 sh_vdw_invrcut6 = gmx_fjsp_set1_v2r8(fr->ic->sh_invrc6);
283 rvdw = gmx_fjsp_set1_v2r8(fr->rvdw);
286 /* #if 'PotentialSwitch' in [KERNEL_MOD_ELEC,KERNEL_MOD_VDW] */
287 /* #if KERNEL_MOD_ELEC=='PotentialSwitch' */
288 rswitch_scalar = fr->rcoulomb_switch;
289 rswitch = gmx_fjsp_set1_v2r8(rswitch_scalar);
291 rswitch_scalar = fr->rvdw_switch;
292 rswitch = gmx_fjsp_set1_v2r8(rswitch_scalar);
294 /* Setup switch parameters */
295 d_scalar = rcutoff_scalar-rswitch_scalar;
296 d = gmx_fjsp_set1_v2r8(d_scalar);
297 swV3 = gmx_fjsp_set1_v2r8(-10.0/(d_scalar*d_scalar*d_scalar));
298 swV4 = gmx_fjsp_set1_v2r8( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
299 swV5 = gmx_fjsp_set1_v2r8( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
300 /* #if 'Force' in KERNEL_VF */
301 swF2 = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar));
302 swF3 = gmx_fjsp_set1_v2r8( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
303 swF4 = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
307 /* Avoid stupid compiler warnings */
312 /* ## Keep track of the floating point operations we issue for reporting! */
313 /* #define OUTERFLOPS 0 */
317 /* Start outer loop over neighborlists */
318 for(iidx=0; iidx<nri; iidx++)
320 /* Load shift vector for this list */
321 i_shift_offset = DIM*shiftidx[iidx];
323 /* Load limits for loop over neighbors */
324 j_index_start = jindex[iidx];
325 j_index_end = jindex[iidx+1];
327 /* Get outer coordinate index */
329 i_coord_offset = DIM*inr;
331 /* Load i particle coords and add shift vector */
332 /* #if GEOMETRY_I == 'Particle' */
333 gmx_fjsp_load_shift_and_1rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
334 /* #elif GEOMETRY_I == 'Water3' */
335 gmx_fjsp_load_shift_and_3rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
336 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
337 /* #elif GEOMETRY_I == 'Water4' */
338 /* #if 0 in PARTICLES_I */
339 gmx_fjsp_load_shift_and_4rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
340 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
342 gmx_fjsp_load_shift_and_3rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
343 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
347 /* #if 'Force' in KERNEL_VF */
348 /* #for I in PARTICLES_I */
349 fix{I} = _fjsp_setzero_v2r8();
350 fiy{I} = _fjsp_setzero_v2r8();
351 fiz{I} = _fjsp_setzero_v2r8();
355 /* ## For water we already preloaded parameters at the start of the kernel */
356 /* #if not 'Water' in GEOMETRY_I */
357 /* Load parameters for i particles */
358 /* #for I in PARTICLES_ELEC_I */
359 iq{I} = _fjsp_mul_v2r8(facel,gmx_fjsp_load1_v2r8(charge+inr+{I}));
360 /* #define OUTERFLOPS OUTERFLOPS+1 */
361 /* #if KERNEL_ELEC=='GeneralizedBorn' */
362 isai{I} = gmx_fjsp_load1_v2r8(invsqrta+inr+{I});
365 /* #for I in PARTICLES_VDW_I */
366 vdwioffset{I} = 2*nvdwtype*vdwtype[inr+{I}];
370 /* #if 'Potential' in KERNEL_VF */
371 /* Reset potential sums */
372 /* #if KERNEL_ELEC != 'None' */
373 velecsum = _fjsp_setzero_v2r8();
375 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
376 vgbsum = _fjsp_setzero_v2r8();
378 /* #if KERNEL_VDW != 'None' */
379 vvdwsum = _fjsp_setzero_v2r8();
382 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
383 dvdasum = _fjsp_setzero_v2r8();
386 /* #for ROUND in ['Loop','Epilogue'] */
388 /* #if ROUND =='Loop' */
389 /* Start inner kernel loop */
390 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
392 /* ## First round is normal loop (next statement resets indentation) */
399 /* ## Second round is epilogue */
401 /* #define INNERFLOPS 0 */
403 /* #if ROUND =='Loop' */
404 /* Get j neighbor index, and coordinate index */
407 j_coord_offsetA = DIM*jnrA;
408 j_coord_offsetB = DIM*jnrB;
410 /* load j atom coordinates */
411 /* #if GEOMETRY_J == 'Particle' */
412 gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
414 /* #elif GEOMETRY_J == 'Water3' */
415 gmx_fjsp_load_3rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
416 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
417 /* #elif GEOMETRY_J == 'Water4' */
418 /* #if 0 in PARTICLES_J */
419 gmx_fjsp_load_4rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
420 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
421 &jy2,&jz2,&jx3,&jy3,&jz3);
423 gmx_fjsp_load_3rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
424 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
429 j_coord_offsetA = DIM*jnrA;
431 /* load j atom coordinates */
432 /* #if GEOMETRY_J == 'Particle' */
433 gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
435 /* #elif GEOMETRY_J == 'Water3' */
436 gmx_fjsp_load_3rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
437 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
438 /* #elif GEOMETRY_J == 'Water4' */
439 /* #if 0 in PARTICLES_J */
440 gmx_fjsp_load_4rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
441 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
442 &jy2,&jz2,&jx3,&jy3,&jz3);
444 gmx_fjsp_load_3rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA+DIM,
445 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
450 /* Calculate displacement vector */
451 /* #for I,J in PAIRS_IJ */
452 dx{I}{J} = _fjsp_sub_v2r8(ix{I},jx{J});
453 dy{I}{J} = _fjsp_sub_v2r8(iy{I},jy{J});
454 dz{I}{J} = _fjsp_sub_v2r8(iz{I},jz{J});
455 /* #define INNERFLOPS INNERFLOPS+3 */
458 /* Calculate squared distance and things based on it */
459 /* #for I,J in PAIRS_IJ */
460 rsq{I}{J} = gmx_fjsp_calc_rsq_v2r8(dx{I}{J},dy{I}{J},dz{I}{J});
461 /* #define INNERFLOPS INNERFLOPS+5 */
464 /* #for I,J in PAIRS_IJ */
465 /* #if 'rinv' in INTERACTION_FLAGS[I][J] */
466 rinv{I}{J} = gmx_fjsp_invsqrt_v2r8(rsq{I}{J});
467 /* #define INNERFLOPS INNERFLOPS+5 */
471 /* #for I,J in PAIRS_IJ */
472 /* #if 'rinvsq' in INTERACTION_FLAGS[I][J] */
473 /* # if 'rinv' not in INTERACTION_FLAGS[I][J] */
474 rinvsq{I}{J} = gmx_fjsp_inv_v2r8(rsq{I}{J});
475 /* #define INNERFLOPS INNERFLOPS+4 */
477 rinvsq{I}{J} = _fjsp_mul_v2r8(rinv{I}{J},rinv{I}{J});
478 /* #define INNERFLOPS INNERFLOPS+1 */
483 /* #if not 'Water' in GEOMETRY_J */
484 /* Load parameters for j particles */
485 /* #for J in PARTICLES_ELEC_J */
486 /* #if ROUND =='Loop' */
487 jq{J} = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+{J},charge+jnrB+{J});
489 jq{J} = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+{J});
491 /* #if KERNEL_ELEC=='GeneralizedBorn' */
492 /* #if ROUND =='Loop' */
493 isaj{J} = gmx_fjsp_load_2real_swizzle_v2r8(invsqrta+jnrA+{J},invsqrta+jnrB+{J});
495 isaj{J} = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),invsqrta+jnrA+{J});
499 /* #for J in PARTICLES_VDW_J */
500 vdwjidx{J}A = 2*vdwtype[jnrA+{J}];
501 /* #if ROUND =='Loop' */
502 vdwjidx{J}B = 2*vdwtype[jnrB+{J}];
507 /* #if 'Force' in KERNEL_VF and not 'Particle' in GEOMETRY_I */
508 /* #for J in PARTICLES_J */
509 fjx{J} = _fjsp_setzero_v2r8();
510 fjy{J} = _fjsp_setzero_v2r8();
511 fjz{J} = _fjsp_setzero_v2r8();
515 /* #for I,J in PAIRS_IJ */
517 /**************************
518 * CALCULATE INTERACTIONS *
519 **************************/
521 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
522 /* ## We always calculate rinv/rinvsq above to enable pipelineing in compilers (performance tested on x86) */
523 if (gmx_fjsp_any_lt_v2r8(rsq{I}{J},rcutoff2))
525 /* #if 0 ## this and the next two lines is a hack to maintain auto-indentation in template file */
528 /* #define INNERFLOPS INNERFLOPS+1 */
531 /* #if 'r' in INTERACTION_FLAGS[I][J] */
532 r{I}{J} = _fjsp_mul_v2r8(rsq{I}{J},rinv{I}{J});
533 /* #define INNERFLOPS INNERFLOPS+1 */
536 /* ## For water geometries we already loaded parameters at the start of the kernel */
537 /* #if not 'Water' in GEOMETRY_J */
538 /* Compute parameters for interactions between i and j atoms */
539 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
540 qq{I}{J} = _fjsp_mul_v2r8(iq{I},jq{J});
541 /* #define INNERFLOPS INNERFLOPS+1 */
543 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
544 /* #if ROUND == 'Loop' */
545 gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset{I}+vdwjidx{J}A,
546 vdwparam+vdwioffset{I}+vdwjidx{J}B,&c6_{I}{J},&c12_{I}{J});
548 /* #if 'LJEwald' in KERNEL_VDW */
549 c6grid_{I}{J} = gmx_fjsp_load_2real_swizzle_v2r8(vdwgridparam+vdwioffset{I}+vdwjidx{J}A,
550 vdwgridparam+vdwioffset{I}+vdwjidx{J}B);
553 gmx_fjsp_load_1pair_swizzle_v2r8(vdwparam+vdwioffset{I}+vdwjidx{J}A,&c6_{I}{J},&c12_{I}{J});
555 /* #if 'LJEwald' in KERNEL_VDW */
556 c6grid_{I}{J} = gmx_fjsp_load_1real_swizzle_v2r8(vdwgridparam+vdwioffset{I}+vdwjidx{J}A);
562 /* #if 'table' in INTERACTION_FLAGS[I][J] */
563 /* Calculate table index by multiplying r with table scale and truncate to integer */
564 rt = _fjsp_mul_v2r8(r{I}{J},vftabscale);
565 itab_tmp = _fjsp_dtox_v2r8(rt);
566 vfeps = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
567 twovfeps = _fjsp_add_v2r8(vfeps,vfeps);
568 _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
570 /* #define INNERFLOPS INNERFLOPS+4 */
571 /* #if 'Table' in KERNEL_ELEC and 'Table' in KERNEL_VDW */
572 /* ## 3 tables, 4 data per point: multiply index by 12 */
575 /* #elif 'Table' in KERNEL_ELEC */
576 /* ## 1 table, 4 data per point: multiply index by 4 */
579 /* #elif 'Table' in KERNEL_VDW */
580 /* ## 2 tables, 4 data per point: multiply index by 8 */
586 /* ## ELECTROSTATIC INTERACTIONS */
587 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
589 /* #if KERNEL_ELEC=='Coulomb' */
591 /* COULOMB ELECTROSTATICS */
592 velec = _fjsp_mul_v2r8(qq{I}{J},rinv{I}{J});
593 /* #define INNERFLOPS INNERFLOPS+1 */
594 /* #if 'Force' in KERNEL_VF */
595 felec = _fjsp_mul_v2r8(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 = _fjsp_mul_v2r8(qq{I}{J},_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq{I}{J},rinv{I}{J}),crf));
604 /* #define INNERFLOPS INNERFLOPS+4 */
606 /* #if 'Force' in KERNEL_VF */
607 felec = _fjsp_mul_v2r8(qq{I}{J},_fjsp_msub_v2r8(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 = _fjsp_mul_v2r8(isai{I},isaj{J});
615 gbqqfactor = _fjsp_neg_v2r8(_fjsp_mul_v2r8(qq{I}{J},_fjsp_mul_v2r8(isaprod,gbinvepsdiff)));
616 gbscale = _fjsp_mul_v2r8(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 = _fjsp_mul_v2r8(r{I}{J},gbscale);
623 itab_tmp = _fjsp_dtox_v2r8(rt);
624 gbeps = _fjsp_sub_v2r8(rt,_fjsp_xtod_v2r8(itab_tmp));
625 _fjsp_store_v2r8(&gbconv.simd,itab_tmp);
627 Y = _fjsp_load_v2r8( gbtab + 4*gbconv.i[0] );
628 /* #if ROUND == 'Loop' */
629 F = _fjsp_load_v2r8( gbtab + 4*gbconv.i[1] );
631 F = _fjsp_setzero_v2r8();
633 GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
634 G = _fjsp_load_v2r8( gbtab + 4*gbconv.i[0] +2);
635 /* #if ROUND == 'Loop' */
636 H = _fjsp_load_v2r8( gbtab + 4*gbconv.i[1] +2);
638 H = _fjsp_setzero_v2r8();
640 GMX_FJSP_TRANSPOSE2_V2R8(G,H);
641 Fp = _fjsp_madd_v2r8(gbeps,_fjsp_madd_v2r8(gbeps,H,G),F);
642 VV = _fjsp_madd_v2r8(gbeps,Fp,Y);
643 vgb = _fjsp_mul_v2r8(gbqqfactor,VV);
644 /* #define INNERFLOPS INNERFLOPS+10 */
646 /* #if 'Force' in KERNEL_VF */
647 twogbeps = _fjsp_add_v2r8(gbeps,gbeps);
648 FF = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twogbeps,H,G),gbeps,Fp);
649 fgb = _fjsp_mul_v2r8(gbqqfactor,_fjsp_mul_v2r8(FF,gbscale));
650 dvdatmp = _fjsp_mul_v2r8(minushalf,_fjsp_madd_v2r8(fgb,r{I}{J},vgb));
651 dvdasum = _fjsp_add_v2r8(dvdasum,dvdatmp);
652 /* #if ROUND == 'Loop' */
653 gmx_fjsp_increment_2real_swizzle_v2r8(dvda+jnrA,dvda+jnrB,_fjsp_mul_v2r8(dvdatmp,_fjsp_mul_v2r8(isaj{J},isaj{J})));
655 gmx_fjsp_increment_1real_v2r8(dvda+jnrA,_fjsp_mul_v2r8(dvdatmp,_fjsp_mul_v2r8(isaj{J},isaj{J})));
657 /* #define INNERFLOPS INNERFLOPS+13 */
659 velec = _fjsp_mul_v2r8(qq{I}{J},rinv{I}{J});
660 /* #define INNERFLOPS INNERFLOPS+1 */
661 /* #if 'Force' in KERNEL_VF */
662 felec = _fjsp_mul_v2r8(_fjsp_msub_v2r8(velec,rinv{I}{J},fgb),rinv{I}{J});
663 /* #define INNERFLOPS INNERFLOPS+3 */
666 /* #elif KERNEL_ELEC=='Ewald' */
667 /* EWALD ELECTROSTATICS */
669 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
670 ewrt = _fjsp_mul_v2r8(r{I}{J},ewtabscale);
671 itab_tmp = _fjsp_dtox_v2r8(ewrt);
672 eweps = _fjsp_sub_v2r8(ewrt,_fjsp_xtod_v2r8(itab_tmp));
673 _fjsp_store_v2r8(&ewconv.simd,itab_tmp);
675 /* #define INNERFLOPS INNERFLOPS+4 */
676 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_ELEC=='PotentialSwitch' */
677 ewtabF = _fjsp_load_v2r8( ewtab + 4*ewconv.i[0] );
678 /* #if ROUND == 'Loop' */
679 ewtabD = _fjsp_load_v2r8( ewtab + 4*ewconv.i[1] );
681 ewtabD = _fjsp_setzero_v2r8();
683 GMX_FJSP_TRANSPOSE2_V2R8(ewtabF,ewtabD);
684 ewtabV = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(), ewtab + 4*ewconv.i[0] +2);
685 /* #if ROUND == 'Loop' */
686 ewtabFn = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(), ewtab + 4*ewconv.i[1] +2);
688 ewtabFn = _fjsp_setzero_v2r8();
690 GMX_FJSP_TRANSPOSE2_V2R8(ewtabV,ewtabFn);
691 felec = _fjsp_madd_v2r8(eweps,ewtabD,ewtabF);
692 /* #define INNERFLOPS INNERFLOPS+2 */
693 /* #if KERNEL_MOD_ELEC=='PotentialShift' */
694 velec = _fjsp_nmsub_v2r8(_fjsp_mul_v2r8(ewtabhalfspace,eweps) ,_fjsp_add_v2r8(ewtabF,felec), ewtabV);
695 velec = _fjsp_mul_v2r8(qq{I}{J},_fjsp_sub_v2r8(_fjsp_sub_v2r8(rinv{I}{J},sh_ewald),velec));
696 /* #define INNERFLOPS INNERFLOPS+7 */
698 velec = _fjsp_nmsub_v2r8(_fjsp_mul_v2r8(ewtabhalfspace,eweps) ,_fjsp_add_v2r8(ewtabF,felec), ewtabV);
699 velec = _fjsp_mul_v2r8(qq{I}{J},_fjsp_sub_v2r8(rinv{I}{J},velec));
700 /* #define INNERFLOPS INNERFLOPS+6 */
702 /* #if 'Force' in KERNEL_VF */
703 felec = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq{I}{J},rinv{I}{J}),_fjsp_sub_v2r8(rinvsq{I}{J},felec));
704 /* #define INNERFLOPS INNERFLOPS+3 */
706 /* #elif KERNEL_VF=='Force' */
707 /* #if ROUND == 'Loop' */
708 gmx_fjsp_load_2pair_swizzle_v2r8(ewtab+ewconv.i[0],ewtab+ewconv.i[1],
711 gmx_fjsp_load_1pair_swizzle_v2r8(ewtab+ewconv.i[0],&ewtabF,&ewtabFn);
713 felec = _fjsp_madd_v2r8(eweps,ewtabFn,_fjsp_nmsub_v2r8(eweps,ewtabF,ewtabF));
714 felec = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq{I}{J},rinv{I}{J}),_fjsp_sub_v2r8(rinvsq{I}{J},felec));
715 /* #define INNERFLOPS INNERFLOPS+7 */
718 /* #elif KERNEL_ELEC=='CubicSplineTable' */
720 /* CUBIC SPLINE TABLE ELECTROSTATICS */
721 Y = _fjsp_load_v2r8( vftab + vfconv.i[0] );
722 /* #if ROUND == 'Loop' */
723 F = _fjsp_load_v2r8( vftab + vfconv.i[1] );
725 F = _fjsp_setzero_v2r8();
727 GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
728 G = _fjsp_load_v2r8( vftab + vfconv.i[0] +2);
729 /* #if ROUND == 'Loop' */
730 H = _fjsp_load_v2r8( vftab + vfconv.i[1] +2);
732 H = _fjsp_setzero_v2r8();
734 GMX_FJSP_TRANSPOSE2_V2R8(G,H);
735 Fp = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(vfeps,H,G),F);
736 /* #define INNERFLOPS INNERFLOPS+4 */
737 /* #if 'Potential' in KERNEL_VF */
738 VV = _fjsp_madd_v2r8(vfeps,Fp,Y);
739 velec = _fjsp_mul_v2r8(qq{I}{J},VV);
740 /* #define INNERFLOPS INNERFLOPS+3 */
742 /* #if 'Force' in KERNEL_VF */
743 FF = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twovfeps,H,G),vfeps,Fp);
744 felec = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_mul_v2r8(qq{I}{J},FF),_fjsp_mul_v2r8(vftabscale,rinv{I}{J})));
745 /* #define INNERFLOPS INNERFLOPS+7 */
748 /* ## End of check for electrostatics interaction forms */
750 /* ## END OF ELECTROSTATIC INTERACTION CHECK FOR PAIR I-J */
752 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
754 /* #if KERNEL_VDW=='LennardJones' */
756 /* LENNARD-JONES DISPERSION/REPULSION */
758 rinvsix = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
759 /* #define INNERFLOPS INNERFLOPS+2 */
760 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
761 vvdw6 = _fjsp_mul_v2r8(c6_{I}{J},rinvsix);
762 vvdw12 = _fjsp_mul_v2r8(c12_{I}{J},_fjsp_mul_v2r8(rinvsix,rinvsix));
763 /* #define INNERFLOPS INNERFLOPS+3 */
764 /* #if KERNEL_MOD_VDW=='PotentialShift' */
765 vvdw = _fjsp_msub_v2r8(_fjsp_nmsub_v2r8(c12_{I}{J},_fjsp_mul_v2r8(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
766 _fjsp_mul_v2r8(_fjsp_nmsub_v2r8( c6_{I}{J},sh_vdw_invrcut6,vvdw6),one_sixth));
767 /* #define INNERFLOPS INNERFLOPS+8 */
769 vvdw = _fjsp_msub_v2r8( vvdw12,one_twelfth, _fjsp_mul_v2r8(vvdw6,one_sixth) );
770 /* #define INNERFLOPS INNERFLOPS+3 */
772 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
773 /* #if 'Force' in KERNEL_VF */
774 fvdw = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq{I}{J});
775 /* #define INNERFLOPS INNERFLOPS+2 */
777 /* #elif KERNEL_VF=='Force' */
778 /* ## Force-only LennardJones makes it possible to save 1 flop (they do add up...) */
779 fvdw = _fjsp_mul_v2r8(_fjsp_msub_v2r8(c12_{I}{J},rinvsix,c6_{I}{J}),_fjsp_mul_v2r8(rinvsix,rinvsq{I}{J}));
780 /* #define INNERFLOPS INNERFLOPS+4 */
783 /* #elif KERNEL_VDW=='CubicSplineTable' */
785 /* CUBIC SPLINE TABLE DISPERSION */
786 /* #if 'Table' in KERNEL_ELEC */
790 Y = _fjsp_load_v2r8( vftab + vfconv.i[0] );
791 /* #if ROUND == 'Loop' */
792 F = _fjsp_load_v2r8( vftab + vfconv.i[1] );
794 F = _fjsp_setzero_v2r8();
796 GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
797 G = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
798 /* #if ROUND == 'Loop' */
799 H = _fjsp_load_v2r8( vftab + vfconv.i[1] + 2 );
801 H = _fjsp_setzero_v2r8();
803 GMX_FJSP_TRANSPOSE2_V2R8(G,H);
804 Fp = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
805 /* #define INNERFLOPS INNERFLOPS+4 */
806 /* #if 'Potential' in KERNEL_VF */
807 VV = _fjsp_madd_v2r8(vfeps,Fp,Y);
808 vvdw6 = _fjsp_mul_v2r8(c6_{I}{J},VV);
809 /* #define INNERFLOPS INNERFLOPS+3 */
811 /* #if 'Force' in KERNEL_VF */
812 FF = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
813 fvdw6 = _fjsp_mul_v2r8(c6_{I}{J},FF);
814 /* #define INNERFLOPS INNERFLOPS+4 */
817 /* CUBIC SPLINE TABLE REPULSION */
818 Y = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
819 /* #if ROUND == 'Loop' */
820 F = _fjsp_load_v2r8( vftab + vfconv.i[1] + 4 );
822 F = _fjsp_setzero_v2r8();
824 GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
825 G = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
826 /* #if ROUND == 'Loop' */
827 H = _fjsp_load_v2r8( vftab + vfconv.i[1] + 6 );
829 H = _fjsp_setzero_v2r8();
831 GMX_FJSP_TRANSPOSE2_V2R8(G,H);
832 Fp = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
833 /* #define INNERFLOPS INNERFLOPS+4 */
834 /* #if 'Potential' in KERNEL_VF */
835 VV = _fjsp_madd_v2r8(vfeps,Fp,Y);
836 vvdw12 = _fjsp_mul_v2r8(c12_{I}{J},VV);
837 /* #define INNERFLOPS INNERFLOPS+3 */
839 /* #if 'Force' in KERNEL_VF */
840 FF = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
841 fvdw12 = _fjsp_mul_v2r8(c12_{I}{J},FF);
842 /* #define INNERFLOPS INNERFLOPS+5 */
844 /* #if 'Potential' in KERNEL_VF */
845 vvdw = _fjsp_add_v2r8(vvdw12,vvdw6);
846 /* #define INNERFLOPS INNERFLOPS+1 */
848 /* #if 'Force' in KERNEL_VF */
849 fvdw = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv{I}{J})));
850 /* #define INNERFLOPS INNERFLOPS+4 */
853 /* #elif KERNEL_VDW=='LJEwald' */
855 /* Analytical LJ-PME */
856 rinvsix = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq{I}{J},rinvsq{I}{J}),rinvsq{I}{J});
857 ewcljrsq = _fjsp_mul_v2r8(ewclj2,rsq{I}{J});
858 ewclj6 = _fjsp_mul_v2r8(ewclj2,_fjsp_mul_v2r8(ewclj2,ewclj2));
859 exponent = gmx_simd_exp_d(-ewcljrsq);
860 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
861 poly = _fjsp_mul_v2r8(exponent,_fjsp_madd_v2r8(_fjsp_mul_v2r8(ewcljrsq,ewcljrsq),one_half,_fjsp_sub_v2r8(one,ewcljrsq)));
862 /* #define INNERFLOPS INNERFLOPS+9 */
863 /* #if 'Potential' in KERNEL_VF or KERNEL_MOD_VDW=='PotentialSwitch' */
864 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
865 vvdw6 = _fjsp_mul_v2r8(_fjsp_madd_v2r8(-c6grid_{I}{J},_fjsp_sub_v2r8(one,poly),c6_{I}{J}),rinvsix);
866 vvdw12 = _fjsp_mul_v2r8(c12_{I}{J},_fjsp_mul_v2r8(rinvsix,rinvsix));
867 /* #define INNERFLOPS INNERFLOPS+5 */
868 /* #if KERNEL_MOD_VDW=='PotentialShift' */
869 vvdw = _fjsp_msub_v2r8(_fjsp_nmsub_v2r8(c12_{I}{J},_fjsp_mul_v2r8(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
870 _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw6,_fjsp_madd_v2r8(c6grid_{I}{J},sh_lj_ewald,_fjsp_mul_v2r8(c6_{I}{J},sh_vdw_invrcut6))),one_sixth));
871 /* #define INNERFLOPS INNERFLOPS+7 */
873 vvdw = _fjsp_msub_v2r8(vvdw12,one_twelfth,_fjsp_mul_v2r8(vvdw6,one_sixth));
874 /* #define INNERFLOPS INNERFLOPS+2 */
876 /* ## Check for force inside potential check, i.e. this means we already did the potential part */
877 /* #if 'Force' in KERNEL_VF */
878 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
879 fvdw = _fjsp_mul_v2r8(_fjsp_add_v2r8(vvdw12,_fjsp_msub_v2r8(_fjsp_mul_v2r8(c6grid_{I}{J},one_sixth),_fjsp_mul_v2r8(exponent,ewclj6),vvdw6)),rinvsq{I}{J});
880 /* #define INNERFLOPS INNERFLOPS+6 */
882 /* #elif KERNEL_VF=='Force' */
883 /* f6A = 6 * C6grid * (1 - poly) */
884 f6A = _fjsp_mul_v2r8(c6grid_{I}{J},_fjsp_msub_v2r8(one,poly));
885 /* f6B = C6grid * exponent * beta^6 */
886 f6B = _fjsp_mul_v2r8(_fjsp_mul_v2r8(c6grid_{I}{J},one_sixth),_fjsp_mul_v2r8(exponent,ewclj6));
887 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
888 fvdw = _fjsp_mul_v2r8(_fjsp_madd_v2r8(_fjsp_msub_v2r8(c12_{I}{J},rinvsix,_fjsp_sub_v2r8(c6_{I}{J},f6A)),rinvsix,f6B),rinvsq{I}{J});
889 /* #define INNERFLOPS INNERFLOPS+12 */
892 /* ## End of check for vdw interaction forms */
894 /* ## END OF VDW INTERACTION CHECK FOR PAIR I-J */
896 /* #if 'switch' in INTERACTION_FLAGS[I][J] */
897 d = _fjsp_sub_v2r8(r{I}{J},rswitch);
898 d = _fjsp_max_v2r8(d,_fjsp_setzero_v2r8());
899 d2 = _fjsp_mul_v2r8(d,d);
900 sw = _fjsp_add_v2r8(one,_fjsp_mul_v2r8(d2,_fjsp_mul_v2r8(d,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swV5,swV4),swV3))));
901 /* #define INNERFLOPS INNERFLOPS+10 */
903 /* #if 'Force' in KERNEL_VF */
904 dsw = _fjsp_mul_v2r8(d2,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swF4,swF3),swF2));
905 /* #define INNERFLOPS INNERFLOPS+5 */
908 /* Evaluate switch function */
909 /* #if 'Force' in KERNEL_VF */
910 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
911 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
912 felec = _fjsp_msub_v2r8( felec,sw , _fjsp_mul_v2r8(rinv{I}{J},_fjsp_mul_v2r8(velec,dsw)) );
913 /* #define INNERFLOPS INNERFLOPS+4 */
915 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
916 fvdw = _fjsp_msub_v2r8( fvdw,sw , _fjsp_mul_v2r8(rinv{I}{J},_fjsp_mul_v2r8(vvdw,dsw)) );
917 /* #define INNERFLOPS INNERFLOPS+4 */
920 /* #if 'Potential' in KERNEL_VF */
921 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_ELEC=='PotentialSwitch' */
922 velec = _fjsp_mul_v2r8(velec,sw);
923 /* #define INNERFLOPS INNERFLOPS+1 */
925 /* #if 'vdw' in INTERACTION_FLAGS[I][J] and KERNEL_MOD_VDW=='PotentialSwitch' */
926 vvdw = _fjsp_mul_v2r8(vvdw,sw);
927 /* #define INNERFLOPS INNERFLOPS+1 */
931 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
932 cutoff_mask = _fjsp_cmplt_v2r8(rsq{I}{J},rcutoff2);
933 /* #define INNERFLOPS INNERFLOPS+1 */
936 /* #if 'Potential' in KERNEL_VF */
937 /* Update potential sum for this i atom from the interaction with this j atom. */
938 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] */
939 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
940 velec = _fjsp_and_v2r8(velec,cutoff_mask);
941 /* #define INNERFLOPS INNERFLOPS+1 */
943 /* #if ROUND == 'Epilogue' */
944 velec = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
946 velecsum = _fjsp_add_v2r8(velecsum,velec);
947 /* #define INNERFLOPS INNERFLOPS+1 */
948 /* #if KERNEL_ELEC=='GeneralizedBorn' */
949 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
950 vgb = _fjsp_and_v2r8(vgb,cutoff_mask);
951 /* #define INNERFLOPS INNERFLOPS+1 */
953 /* #if ROUND == 'Epilogue' */
954 vgb = _fjsp_unpacklo_v2r8(vgb,_fjsp_setzero_v2r8());
956 vgbsum = _fjsp_add_v2r8(vgbsum,vgb);
957 /* #define INNERFLOPS INNERFLOPS+1 */
960 /* #if 'vdw' in INTERACTION_FLAGS[I][J] */
961 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
962 vvdw = _fjsp_and_v2r8(vvdw,cutoff_mask);
963 /* #define INNERFLOPS INNERFLOPS+1 */
965 /* #if ROUND == 'Epilogue' */
966 vvdw = _fjsp_unpacklo_v2r8(vvdw,_fjsp_setzero_v2r8());
968 vvdwsum = _fjsp_add_v2r8(vvdwsum,vvdw);
969 /* #define INNERFLOPS INNERFLOPS+1 */
973 /* #if 'Force' in KERNEL_VF */
975 /* #if 'electrostatics' in INTERACTION_FLAGS[I][J] and 'vdw' in INTERACTION_FLAGS[I][J] */
976 fscal = _fjsp_add_v2r8(felec,fvdw);
977 /* #define INNERFLOPS INNERFLOPS+1 */
978 /* #elif 'electrostatics' in INTERACTION_FLAGS[I][J] */
980 /* #elif 'vdw' in INTERACTION_FLAGS[I][J] */
984 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
985 fscal = _fjsp_and_v2r8(fscal,cutoff_mask);
986 /* #define INNERFLOPS INNERFLOPS+1 */
989 /* #if ROUND == 'Epilogue' */
990 fscal = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
993 /* ## Construction of vectorial force built into FMA instructions now */
994 /* #define INNERFLOPS INNERFLOPS+3 */
996 /* Update vectorial force */
997 fix{I} = _fjsp_madd_v2r8(dx{I}{J},fscal,fix{I});
998 fiy{I} = _fjsp_madd_v2r8(dy{I}{J},fscal,fiy{I});
999 fiz{I} = _fjsp_madd_v2r8(dz{I}{J},fscal,fiz{I});
1000 /* #define INNERFLOPS INNERFLOPS+6 */
1002 /* #if GEOMETRY_I == 'Particle' */
1003 /* #if ROUND == 'Loop' */
1004 gmx_fjsp_decrement_fma_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fscal,dx{I}{J},dy{I}{J},dz{I}{J});
1006 gmx_fjsp_decrement_fma_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fscal,dx{I}{J},dy{I}{J},dz{I}{J});
1008 /* #define INNERFLOPS INNERFLOPS+3 */
1010 fjx{J} = _fjsp_madd_v2r8(dx{I}{J},fscal,fjx{J});
1011 fjy{J} = _fjsp_madd_v2r8(dy{I}{J},fscal,fjy{J});
1012 fjz{J} = _fjsp_madd_v2r8(dz{I}{J},fscal,fjz{J});
1013 /* #define INNERFLOPS INNERFLOPS+3 */
1018 /* #if 'exactcutoff' in INTERACTION_FLAGS[I][J] */
1019 /* #if 0 ## This and next two lines is a hack to maintain indentation in template file */
1024 /* ## End of check for the interaction being outside the cutoff */
1027 /* ## End of loop over i-j interaction pairs */
1029 /* #if 'Water' in GEOMETRY_I and GEOMETRY_J == 'Particle' */
1030 /* #if ROUND == 'Loop' */
1031 gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1033 gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1035 /* #define INNERFLOPS INNERFLOPS+3 */
1036 /* #elif GEOMETRY_J == 'Water3' */
1037 /* #if ROUND == 'Loop' */
1038 gmx_fjsp_decrement_3rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1040 gmx_fjsp_decrement_3rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1042 /* #define INNERFLOPS INNERFLOPS+9 */
1043 /* #elif GEOMETRY_J == 'Water4' */
1044 /* #if 0 in PARTICLES_J */
1045 /* #if ROUND == 'Loop' */
1046 gmx_fjsp_decrement_4rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1048 gmx_fjsp_decrement_4rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1050 /* #define INNERFLOPS INNERFLOPS+12 */
1052 /* #if ROUND == 'Loop' */
1053 gmx_fjsp_decrement_3rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA+DIM,f+j_coord_offsetB+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1055 gmx_fjsp_decrement_3rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA+DIM,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1057 /* #define INNERFLOPS INNERFLOPS+9 */
1061 /* Inner loop uses {INNERFLOPS} flops */
1066 /* End of innermost loop */
1068 /* #if 'Force' in KERNEL_VF */
1069 /* #if GEOMETRY_I == 'Particle' */
1070 gmx_fjsp_update_iforce_1atom_swizzle_v2r8(fix0,fiy0,fiz0,
1071 f+i_coord_offset,fshift+i_shift_offset);
1072 /* #define OUTERFLOPS OUTERFLOPS+6 */
1073 /* #elif GEOMETRY_I == 'Water3' */
1074 gmx_fjsp_update_iforce_3atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1075 f+i_coord_offset,fshift+i_shift_offset);
1076 /* #define OUTERFLOPS OUTERFLOPS+18 */
1077 /* #elif GEOMETRY_I == 'Water4' */
1078 /* #if 0 in PARTICLES_I */
1079 gmx_fjsp_update_iforce_4atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1080 f+i_coord_offset,fshift+i_shift_offset);
1081 /* #define OUTERFLOPS OUTERFLOPS+24 */
1083 gmx_fjsp_update_iforce_3atom_swizzle_v2r8(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1084 f+i_coord_offset+DIM,fshift+i_shift_offset);
1085 /* #define OUTERFLOPS OUTERFLOPS+18 */
1090 /* #if 'Potential' in KERNEL_VF */
1092 /* Update potential energies */
1093 /* #if KERNEL_ELEC != 'None' */
1094 gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
1095 /* #define OUTERFLOPS OUTERFLOPS+1 */
1097 /* #if 'GeneralizedBorn' in KERNEL_ELEC */
1098 gmx_fjsp_update_1pot_v2r8(vgbsum,kernel_data->energygrp_polarization+ggid);
1099 /* #define OUTERFLOPS OUTERFLOPS+1 */
1101 /* #if KERNEL_VDW != 'None' */
1102 gmx_fjsp_update_1pot_v2r8(vvdwsum,kernel_data->energygrp_vdw+ggid);
1103 /* #define OUTERFLOPS OUTERFLOPS+1 */
1106 /* #if 'GeneralizedBorn' in KERNEL_ELEC and 'Force' in KERNEL_VF */
1107 dvdasum = _fjsp_mul_v2r8(dvdasum, _fjsp_mul_v2r8(isai{I},isai{I}));
1108 gmx_fjsp_update_1pot_v2r8(dvdasum,dvda+inr);
1111 /* Increment number of inner iterations */
1112 inneriter += j_index_end - j_index_start;
1114 /* Outer loop uses {OUTERFLOPS} flops */
1117 /* Increment number of outer iterations */
1120 /* Update outer/inner flops */
1121 /* ## NB: This is not important, it just affects the flopcount. However, since our preprocessor is */
1122 /* ## primitive and replaces aggressively even in strings inside these directives, we need to */
1123 /* ## assemble the main part of the name (containing KERNEL/ELEC/VDW) directly in the source. */
1124 /* #if GEOMETRY_I == 'Water3' */
1125 /* #define ISUFFIX '_W3' */
1126 /* #elif GEOMETRY_I == 'Water4' */
1127 /* #define ISUFFIX '_W4' */
1129 /* #define ISUFFIX '' */
1131 /* #if GEOMETRY_J == 'Water3' */
1132 /* #define JSUFFIX 'W3' */
1133 /* #elif GEOMETRY_J == 'Water4' */
1134 /* #define JSUFFIX 'W4' */
1136 /* #define JSUFFIX '' */
1138 /* #if 'PotentialAndForce' in KERNEL_VF */
1139 /* #define VFSUFFIX '_VF' */
1140 /* #elif 'Potential' in KERNEL_VF */
1141 /* #define VFSUFFIX '_V' */
1143 /* #define VFSUFFIX '_F' */
1146 /* #if KERNEL_ELEC != 'None' and KERNEL_VDW != 'None' */
1147 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1148 /* #elif KERNEL_ELEC != 'None' */
1149 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});
1151 inc_nrnb(nrnb,eNR_NBKERNEL_VDW{ISUFFIX}{JSUFFIX}{VFSUFFIX},outeriter*{OUTERFLOPS} + inneriter*{INNERFLOPS});