2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
51 * Electrostatics interaction: GeneralizedBorn
52 * VdW interaction: CubicSplineTable
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81 int vdwjidx0A,vdwjidx0B;
82 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
87 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
88 __m128d minushalf = _mm_set1_pd(-0.5);
89 real *invsqrta,*dvda,*gbtab;
91 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
94 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
95 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
97 __m128i ifour = _mm_set1_epi32(4);
98 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
100 __m128d dummy_mask,cutoff_mask;
101 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
102 __m128d one = _mm_set1_pd(1.0);
103 __m128d two = _mm_set1_pd(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_pd(fr->ic->epsfac);
116 charge = mdatoms->chargeA;
117 nvdwtype = fr->ntype;
119 vdwtype = mdatoms->typeA;
121 vftab = kernel_data->table_vdw->data;
122 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
124 invsqrta = fr->invsqrta;
126 gbtabscale = _mm_set1_pd(fr->gbtab->scale);
127 gbtab = fr->gbtab->data;
128 gbinvepsdiff = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
130 /* Avoid stupid compiler warnings */
138 /* Start outer loop over neighborlists */
139 for(iidx=0; iidx<nri; iidx++)
141 /* Load shift vector for this list */
142 i_shift_offset = DIM*shiftidx[iidx];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
155 fix0 = _mm_setzero_pd();
156 fiy0 = _mm_setzero_pd();
157 fiz0 = _mm_setzero_pd();
159 /* Load parameters for i particles */
160 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
161 isai0 = _mm_load1_pd(invsqrta+inr+0);
162 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
164 /* Reset potential sums */
165 velecsum = _mm_setzero_pd();
166 vgbsum = _mm_setzero_pd();
167 vvdwsum = _mm_setzero_pd();
168 dvdasum = _mm_setzero_pd();
170 /* Start inner kernel loop */
171 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
174 /* Get j neighbor index, and coordinate index */
177 j_coord_offsetA = DIM*jnrA;
178 j_coord_offsetB = DIM*jnrB;
180 /* load j atom coordinates */
181 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
184 /* Calculate displacement vector */
185 dx00 = _mm_sub_pd(ix0,jx0);
186 dy00 = _mm_sub_pd(iy0,jy0);
187 dz00 = _mm_sub_pd(iz0,jz0);
189 /* Calculate squared distance and things based on it */
190 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
192 rinv00 = avx128fma_invsqrt_d(rsq00);
194 /* Load parameters for j particles */
195 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
196 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
197 vdwjidx0A = 2*vdwtype[jnrA+0];
198 vdwjidx0B = 2*vdwtype[jnrB+0];
200 /**************************
201 * CALCULATE INTERACTIONS *
202 **************************/
204 r00 = _mm_mul_pd(rsq00,rinv00);
206 /* Compute parameters for interactions between i and j atoms */
207 qq00 = _mm_mul_pd(iq0,jq0);
208 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
209 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
211 /* Calculate table index by multiplying r with table scale and truncate to integer */
212 rt = _mm_mul_pd(r00,vftabscale);
213 vfitab = _mm_cvttpd_epi32(rt);
215 vfeps = _mm_frcz_pd(rt);
217 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
219 twovfeps = _mm_add_pd(vfeps,vfeps);
220 vfitab = _mm_slli_epi32(vfitab,3);
222 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
223 isaprod = _mm_mul_pd(isai0,isaj0);
224 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
225 gbscale = _mm_mul_pd(isaprod,gbtabscale);
227 /* Calculate generalized born table index - this is a separate table from the normal one,
228 * but we use the same procedure by multiplying r with scale and truncating to integer.
230 rt = _mm_mul_pd(r00,gbscale);
231 gbitab = _mm_cvttpd_epi32(rt);
233 gbeps = _mm_frcz_pd(rt);
235 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
237 gbitab = _mm_slli_epi32(gbitab,2);
239 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
240 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
241 GMX_MM_TRANSPOSE2_PD(Y,F);
242 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
243 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
244 GMX_MM_TRANSPOSE2_PD(G,H);
245 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
246 VV = _mm_macc_pd(gbeps,Fp,Y);
247 vgb = _mm_mul_pd(gbqqfactor,VV);
249 twogbeps = _mm_add_pd(gbeps,gbeps);
250 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
251 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
252 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
253 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
254 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
255 velec = _mm_mul_pd(qq00,rinv00);
256 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
258 /* CUBIC SPLINE TABLE DISPERSION */
259 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
260 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
261 GMX_MM_TRANSPOSE2_PD(Y,F);
262 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
263 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
264 GMX_MM_TRANSPOSE2_PD(G,H);
265 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
266 VV = _mm_macc_pd(vfeps,Fp,Y);
267 vvdw6 = _mm_mul_pd(c6_00,VV);
268 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
269 fvdw6 = _mm_mul_pd(c6_00,FF);
271 /* CUBIC SPLINE TABLE REPULSION */
272 vfitab = _mm_add_epi32(vfitab,ifour);
273 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
274 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
275 GMX_MM_TRANSPOSE2_PD(Y,F);
276 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
277 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
278 GMX_MM_TRANSPOSE2_PD(G,H);
279 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
280 VV = _mm_macc_pd(vfeps,Fp,Y);
281 vvdw12 = _mm_mul_pd(c12_00,VV);
282 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
283 fvdw12 = _mm_mul_pd(c12_00,FF);
284 vvdw = _mm_add_pd(vvdw12,vvdw6);
285 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 velecsum = _mm_add_pd(velecsum,velec);
289 vgbsum = _mm_add_pd(vgbsum,vgb);
290 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
292 fscal = _mm_add_pd(felec,fvdw);
294 /* Update vectorial force */
295 fix0 = _mm_macc_pd(dx00,fscal,fix0);
296 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
297 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
299 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
300 _mm_mul_pd(dx00,fscal),
301 _mm_mul_pd(dy00,fscal),
302 _mm_mul_pd(dz00,fscal));
304 /* Inner loop uses 95 flops */
311 j_coord_offsetA = DIM*jnrA;
313 /* load j atom coordinates */
314 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
317 /* Calculate displacement vector */
318 dx00 = _mm_sub_pd(ix0,jx0);
319 dy00 = _mm_sub_pd(iy0,jy0);
320 dz00 = _mm_sub_pd(iz0,jz0);
322 /* Calculate squared distance and things based on it */
323 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
325 rinv00 = avx128fma_invsqrt_d(rsq00);
327 /* Load parameters for j particles */
328 jq0 = _mm_load_sd(charge+jnrA+0);
329 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
330 vdwjidx0A = 2*vdwtype[jnrA+0];
332 /**************************
333 * CALCULATE INTERACTIONS *
334 **************************/
336 r00 = _mm_mul_pd(rsq00,rinv00);
338 /* Compute parameters for interactions between i and j atoms */
339 qq00 = _mm_mul_pd(iq0,jq0);
340 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
342 /* Calculate table index by multiplying r with table scale and truncate to integer */
343 rt = _mm_mul_pd(r00,vftabscale);
344 vfitab = _mm_cvttpd_epi32(rt);
346 vfeps = _mm_frcz_pd(rt);
348 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
350 twovfeps = _mm_add_pd(vfeps,vfeps);
351 vfitab = _mm_slli_epi32(vfitab,3);
353 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
354 isaprod = _mm_mul_pd(isai0,isaj0);
355 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
356 gbscale = _mm_mul_pd(isaprod,gbtabscale);
358 /* Calculate generalized born table index - this is a separate table from the normal one,
359 * but we use the same procedure by multiplying r with scale and truncating to integer.
361 rt = _mm_mul_pd(r00,gbscale);
362 gbitab = _mm_cvttpd_epi32(rt);
364 gbeps = _mm_frcz_pd(rt);
366 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
368 gbitab = _mm_slli_epi32(gbitab,2);
370 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
371 F = _mm_setzero_pd();
372 GMX_MM_TRANSPOSE2_PD(Y,F);
373 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
374 H = _mm_setzero_pd();
375 GMX_MM_TRANSPOSE2_PD(G,H);
376 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
377 VV = _mm_macc_pd(gbeps,Fp,Y);
378 vgb = _mm_mul_pd(gbqqfactor,VV);
380 twogbeps = _mm_add_pd(gbeps,gbeps);
381 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
382 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
383 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
384 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
385 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
386 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
387 velec = _mm_mul_pd(qq00,rinv00);
388 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
390 /* CUBIC SPLINE TABLE DISPERSION */
391 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
392 F = _mm_setzero_pd();
393 GMX_MM_TRANSPOSE2_PD(Y,F);
394 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
395 H = _mm_setzero_pd();
396 GMX_MM_TRANSPOSE2_PD(G,H);
397 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
398 VV = _mm_macc_pd(vfeps,Fp,Y);
399 vvdw6 = _mm_mul_pd(c6_00,VV);
400 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
401 fvdw6 = _mm_mul_pd(c6_00,FF);
403 /* CUBIC SPLINE TABLE REPULSION */
404 vfitab = _mm_add_epi32(vfitab,ifour);
405 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
406 F = _mm_setzero_pd();
407 GMX_MM_TRANSPOSE2_PD(Y,F);
408 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
409 H = _mm_setzero_pd();
410 GMX_MM_TRANSPOSE2_PD(G,H);
411 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
412 VV = _mm_macc_pd(vfeps,Fp,Y);
413 vvdw12 = _mm_mul_pd(c12_00,VV);
414 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
415 fvdw12 = _mm_mul_pd(c12_00,FF);
416 vvdw = _mm_add_pd(vvdw12,vvdw6);
417 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
421 velecsum = _mm_add_pd(velecsum,velec);
422 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
423 vgbsum = _mm_add_pd(vgbsum,vgb);
424 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
425 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
427 fscal = _mm_add_pd(felec,fvdw);
429 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
431 /* Update vectorial force */
432 fix0 = _mm_macc_pd(dx00,fscal,fix0);
433 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
434 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
436 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
437 _mm_mul_pd(dx00,fscal),
438 _mm_mul_pd(dy00,fscal),
439 _mm_mul_pd(dz00,fscal));
441 /* Inner loop uses 95 flops */
444 /* End of innermost loop */
446 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
447 f+i_coord_offset,fshift+i_shift_offset);
450 /* Update potential energies */
451 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
452 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
453 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
454 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
455 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
457 /* Increment number of inner iterations */
458 inneriter += j_index_end - j_index_start;
460 /* Outer loop uses 10 flops */
463 /* Increment number of outer iterations */
466 /* Update outer/inner flops */
468 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*95);
471 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
472 * Electrostatics interaction: GeneralizedBorn
473 * VdW interaction: CubicSplineTable
474 * Geometry: Particle-Particle
475 * Calculate force/pot: Force
478 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
479 (t_nblist * gmx_restrict nlist,
480 rvec * gmx_restrict xx,
481 rvec * gmx_restrict ff,
482 struct t_forcerec * gmx_restrict fr,
483 t_mdatoms * gmx_restrict mdatoms,
484 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
485 t_nrnb * gmx_restrict nrnb)
487 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
488 * just 0 for non-waters.
489 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
490 * jnr indices corresponding to data put in the four positions in the SIMD register.
492 int i_shift_offset,i_coord_offset,outeriter,inneriter;
493 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
495 int j_coord_offsetA,j_coord_offsetB;
496 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
498 real *shiftvec,*fshift,*x,*f;
499 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
501 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
502 int vdwjidx0A,vdwjidx0B;
503 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
504 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
505 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
508 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
509 __m128d minushalf = _mm_set1_pd(-0.5);
510 real *invsqrta,*dvda,*gbtab;
512 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
515 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
516 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
518 __m128i ifour = _mm_set1_epi32(4);
519 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
521 __m128d dummy_mask,cutoff_mask;
522 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
523 __m128d one = _mm_set1_pd(1.0);
524 __m128d two = _mm_set1_pd(2.0);
530 jindex = nlist->jindex;
532 shiftidx = nlist->shift;
534 shiftvec = fr->shift_vec[0];
535 fshift = fr->fshift[0];
536 facel = _mm_set1_pd(fr->ic->epsfac);
537 charge = mdatoms->chargeA;
538 nvdwtype = fr->ntype;
540 vdwtype = mdatoms->typeA;
542 vftab = kernel_data->table_vdw->data;
543 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
545 invsqrta = fr->invsqrta;
547 gbtabscale = _mm_set1_pd(fr->gbtab->scale);
548 gbtab = fr->gbtab->data;
549 gbinvepsdiff = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
551 /* Avoid stupid compiler warnings */
559 /* Start outer loop over neighborlists */
560 for(iidx=0; iidx<nri; iidx++)
562 /* Load shift vector for this list */
563 i_shift_offset = DIM*shiftidx[iidx];
565 /* Load limits for loop over neighbors */
566 j_index_start = jindex[iidx];
567 j_index_end = jindex[iidx+1];
569 /* Get outer coordinate index */
571 i_coord_offset = DIM*inr;
573 /* Load i particle coords and add shift vector */
574 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
576 fix0 = _mm_setzero_pd();
577 fiy0 = _mm_setzero_pd();
578 fiz0 = _mm_setzero_pd();
580 /* Load parameters for i particles */
581 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
582 isai0 = _mm_load1_pd(invsqrta+inr+0);
583 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
585 dvdasum = _mm_setzero_pd();
587 /* Start inner kernel loop */
588 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
591 /* Get j neighbor index, and coordinate index */
594 j_coord_offsetA = DIM*jnrA;
595 j_coord_offsetB = DIM*jnrB;
597 /* load j atom coordinates */
598 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
601 /* Calculate displacement vector */
602 dx00 = _mm_sub_pd(ix0,jx0);
603 dy00 = _mm_sub_pd(iy0,jy0);
604 dz00 = _mm_sub_pd(iz0,jz0);
606 /* Calculate squared distance and things based on it */
607 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
609 rinv00 = avx128fma_invsqrt_d(rsq00);
611 /* Load parameters for j particles */
612 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
613 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
614 vdwjidx0A = 2*vdwtype[jnrA+0];
615 vdwjidx0B = 2*vdwtype[jnrB+0];
617 /**************************
618 * CALCULATE INTERACTIONS *
619 **************************/
621 r00 = _mm_mul_pd(rsq00,rinv00);
623 /* Compute parameters for interactions between i and j atoms */
624 qq00 = _mm_mul_pd(iq0,jq0);
625 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
626 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
628 /* Calculate table index by multiplying r with table scale and truncate to integer */
629 rt = _mm_mul_pd(r00,vftabscale);
630 vfitab = _mm_cvttpd_epi32(rt);
632 vfeps = _mm_frcz_pd(rt);
634 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
636 twovfeps = _mm_add_pd(vfeps,vfeps);
637 vfitab = _mm_slli_epi32(vfitab,3);
639 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
640 isaprod = _mm_mul_pd(isai0,isaj0);
641 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
642 gbscale = _mm_mul_pd(isaprod,gbtabscale);
644 /* Calculate generalized born table index - this is a separate table from the normal one,
645 * but we use the same procedure by multiplying r with scale and truncating to integer.
647 rt = _mm_mul_pd(r00,gbscale);
648 gbitab = _mm_cvttpd_epi32(rt);
650 gbeps = _mm_frcz_pd(rt);
652 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
654 gbitab = _mm_slli_epi32(gbitab,2);
656 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
657 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
658 GMX_MM_TRANSPOSE2_PD(Y,F);
659 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
660 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
661 GMX_MM_TRANSPOSE2_PD(G,H);
662 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
663 VV = _mm_macc_pd(gbeps,Fp,Y);
664 vgb = _mm_mul_pd(gbqqfactor,VV);
666 twogbeps = _mm_add_pd(gbeps,gbeps);
667 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
668 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
669 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
670 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
671 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
672 velec = _mm_mul_pd(qq00,rinv00);
673 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
675 /* CUBIC SPLINE TABLE DISPERSION */
676 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
677 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
678 GMX_MM_TRANSPOSE2_PD(Y,F);
679 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
680 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
681 GMX_MM_TRANSPOSE2_PD(G,H);
682 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
683 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
684 fvdw6 = _mm_mul_pd(c6_00,FF);
686 /* CUBIC SPLINE TABLE REPULSION */
687 vfitab = _mm_add_epi32(vfitab,ifour);
688 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
689 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
690 GMX_MM_TRANSPOSE2_PD(Y,F);
691 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
692 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
693 GMX_MM_TRANSPOSE2_PD(G,H);
694 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
695 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
696 fvdw12 = _mm_mul_pd(c12_00,FF);
697 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
699 fscal = _mm_add_pd(felec,fvdw);
701 /* Update vectorial force */
702 fix0 = _mm_macc_pd(dx00,fscal,fix0);
703 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
704 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
706 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
707 _mm_mul_pd(dx00,fscal),
708 _mm_mul_pd(dy00,fscal),
709 _mm_mul_pd(dz00,fscal));
711 /* Inner loop uses 85 flops */
718 j_coord_offsetA = DIM*jnrA;
720 /* load j atom coordinates */
721 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
724 /* Calculate displacement vector */
725 dx00 = _mm_sub_pd(ix0,jx0);
726 dy00 = _mm_sub_pd(iy0,jy0);
727 dz00 = _mm_sub_pd(iz0,jz0);
729 /* Calculate squared distance and things based on it */
730 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
732 rinv00 = avx128fma_invsqrt_d(rsq00);
734 /* Load parameters for j particles */
735 jq0 = _mm_load_sd(charge+jnrA+0);
736 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
737 vdwjidx0A = 2*vdwtype[jnrA+0];
739 /**************************
740 * CALCULATE INTERACTIONS *
741 **************************/
743 r00 = _mm_mul_pd(rsq00,rinv00);
745 /* Compute parameters for interactions between i and j atoms */
746 qq00 = _mm_mul_pd(iq0,jq0);
747 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
749 /* Calculate table index by multiplying r with table scale and truncate to integer */
750 rt = _mm_mul_pd(r00,vftabscale);
751 vfitab = _mm_cvttpd_epi32(rt);
753 vfeps = _mm_frcz_pd(rt);
755 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
757 twovfeps = _mm_add_pd(vfeps,vfeps);
758 vfitab = _mm_slli_epi32(vfitab,3);
760 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
761 isaprod = _mm_mul_pd(isai0,isaj0);
762 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
763 gbscale = _mm_mul_pd(isaprod,gbtabscale);
765 /* Calculate generalized born table index - this is a separate table from the normal one,
766 * but we use the same procedure by multiplying r with scale and truncating to integer.
768 rt = _mm_mul_pd(r00,gbscale);
769 gbitab = _mm_cvttpd_epi32(rt);
771 gbeps = _mm_frcz_pd(rt);
773 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
775 gbitab = _mm_slli_epi32(gbitab,2);
777 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
778 F = _mm_setzero_pd();
779 GMX_MM_TRANSPOSE2_PD(Y,F);
780 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
781 H = _mm_setzero_pd();
782 GMX_MM_TRANSPOSE2_PD(G,H);
783 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
784 VV = _mm_macc_pd(gbeps,Fp,Y);
785 vgb = _mm_mul_pd(gbqqfactor,VV);
787 twogbeps = _mm_add_pd(gbeps,gbeps);
788 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
789 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
790 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
791 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
792 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
793 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
794 velec = _mm_mul_pd(qq00,rinv00);
795 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
797 /* CUBIC SPLINE TABLE DISPERSION */
798 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
799 F = _mm_setzero_pd();
800 GMX_MM_TRANSPOSE2_PD(Y,F);
801 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
802 H = _mm_setzero_pd();
803 GMX_MM_TRANSPOSE2_PD(G,H);
804 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
805 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
806 fvdw6 = _mm_mul_pd(c6_00,FF);
808 /* CUBIC SPLINE TABLE REPULSION */
809 vfitab = _mm_add_epi32(vfitab,ifour);
810 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
811 F = _mm_setzero_pd();
812 GMX_MM_TRANSPOSE2_PD(Y,F);
813 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
814 H = _mm_setzero_pd();
815 GMX_MM_TRANSPOSE2_PD(G,H);
816 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
817 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
818 fvdw12 = _mm_mul_pd(c12_00,FF);
819 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
821 fscal = _mm_add_pd(felec,fvdw);
823 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
825 /* Update vectorial force */
826 fix0 = _mm_macc_pd(dx00,fscal,fix0);
827 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
828 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
830 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
831 _mm_mul_pd(dx00,fscal),
832 _mm_mul_pd(dy00,fscal),
833 _mm_mul_pd(dz00,fscal));
835 /* Inner loop uses 85 flops */
838 /* End of innermost loop */
840 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
841 f+i_coord_offset,fshift+i_shift_offset);
843 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
844 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
846 /* Increment number of inner iterations */
847 inneriter += j_index_end - j_index_start;
849 /* Outer loop uses 7 flops */
852 /* Increment number of outer iterations */
855 /* Update outer/inner flops */
857 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*85);