2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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 "types/simple.h"
49 #include "gmx_math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
54 * Electrostatics interaction: GeneralizedBorn
55 * VdW interaction: CubicSplineTable
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B;
85 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
91 __m128d minushalf = _mm_set1_pd(-0.5);
92 real *invsqrta,*dvda,*gbtab;
94 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
98 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
100 __m128i ifour = _mm_set1_epi32(4);
101 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
103 __m128d dummy_mask,cutoff_mask;
104 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
105 __m128d one = _mm_set1_pd(1.0);
106 __m128d two = _mm_set1_pd(2.0);
112 jindex = nlist->jindex;
114 shiftidx = nlist->shift;
116 shiftvec = fr->shift_vec[0];
117 fshift = fr->fshift[0];
118 facel = _mm_set1_pd(fr->epsfac);
119 charge = mdatoms->chargeA;
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 vftab = kernel_data->table_vdw->data;
125 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
127 invsqrta = fr->invsqrta;
129 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
130 gbtab = fr->gbtab.data;
131 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
133 /* Avoid stupid compiler warnings */
141 /* Start outer loop over neighborlists */
142 for(iidx=0; iidx<nri; iidx++)
144 /* Load shift vector for this list */
145 i_shift_offset = DIM*shiftidx[iidx];
147 /* Load limits for loop over neighbors */
148 j_index_start = jindex[iidx];
149 j_index_end = jindex[iidx+1];
151 /* Get outer coordinate index */
153 i_coord_offset = DIM*inr;
155 /* Load i particle coords and add shift vector */
156 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
158 fix0 = _mm_setzero_pd();
159 fiy0 = _mm_setzero_pd();
160 fiz0 = _mm_setzero_pd();
162 /* Load parameters for i particles */
163 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
164 isai0 = _mm_load1_pd(invsqrta+inr+0);
165 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
167 /* Reset potential sums */
168 velecsum = _mm_setzero_pd();
169 vgbsum = _mm_setzero_pd();
170 vvdwsum = _mm_setzero_pd();
171 dvdasum = _mm_setzero_pd();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
177 /* Get j neighbor index, and coordinate index */
180 j_coord_offsetA = DIM*jnrA;
181 j_coord_offsetB = DIM*jnrB;
183 /* load j atom coordinates */
184 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
187 /* Calculate displacement vector */
188 dx00 = _mm_sub_pd(ix0,jx0);
189 dy00 = _mm_sub_pd(iy0,jy0);
190 dz00 = _mm_sub_pd(iz0,jz0);
192 /* Calculate squared distance and things based on it */
193 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
195 rinv00 = gmx_mm_invsqrt_pd(rsq00);
197 /* Load parameters for j particles */
198 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
199 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
200 vdwjidx0A = 2*vdwtype[jnrA+0];
201 vdwjidx0B = 2*vdwtype[jnrB+0];
203 /**************************
204 * CALCULATE INTERACTIONS *
205 **************************/
207 r00 = _mm_mul_pd(rsq00,rinv00);
209 /* Compute parameters for interactions between i and j atoms */
210 qq00 = _mm_mul_pd(iq0,jq0);
211 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
212 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
214 /* Calculate table index by multiplying r with table scale and truncate to integer */
215 rt = _mm_mul_pd(r00,vftabscale);
216 vfitab = _mm_cvttpd_epi32(rt);
218 vfeps = _mm_frcz_pd(rt);
220 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
222 twovfeps = _mm_add_pd(vfeps,vfeps);
223 vfitab = _mm_slli_epi32(vfitab,3);
225 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
226 isaprod = _mm_mul_pd(isai0,isaj0);
227 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
228 gbscale = _mm_mul_pd(isaprod,gbtabscale);
230 /* Calculate generalized born table index - this is a separate table from the normal one,
231 * but we use the same procedure by multiplying r with scale and truncating to integer.
233 rt = _mm_mul_pd(r00,gbscale);
234 gbitab = _mm_cvttpd_epi32(rt);
236 gbeps = _mm_frcz_pd(rt);
238 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
240 gbitab = _mm_slli_epi32(gbitab,2);
242 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
243 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
244 GMX_MM_TRANSPOSE2_PD(Y,F);
245 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
246 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
247 GMX_MM_TRANSPOSE2_PD(G,H);
248 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
249 VV = _mm_macc_pd(gbeps,Fp,Y);
250 vgb = _mm_mul_pd(gbqqfactor,VV);
252 twogbeps = _mm_add_pd(gbeps,gbeps);
253 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
254 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
255 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
256 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
257 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
258 velec = _mm_mul_pd(qq00,rinv00);
259 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
261 /* CUBIC SPLINE TABLE DISPERSION */
262 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
263 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
264 GMX_MM_TRANSPOSE2_PD(Y,F);
265 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
266 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
267 GMX_MM_TRANSPOSE2_PD(G,H);
268 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
269 VV = _mm_macc_pd(vfeps,Fp,Y);
270 vvdw6 = _mm_mul_pd(c6_00,VV);
271 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
272 fvdw6 = _mm_mul_pd(c6_00,FF);
274 /* CUBIC SPLINE TABLE REPULSION */
275 vfitab = _mm_add_epi32(vfitab,ifour);
276 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
277 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
278 GMX_MM_TRANSPOSE2_PD(Y,F);
279 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
280 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
281 GMX_MM_TRANSPOSE2_PD(G,H);
282 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
283 VV = _mm_macc_pd(vfeps,Fp,Y);
284 vvdw12 = _mm_mul_pd(c12_00,VV);
285 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
286 fvdw12 = _mm_mul_pd(c12_00,FF);
287 vvdw = _mm_add_pd(vvdw12,vvdw6);
288 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
290 /* Update potential sum for this i atom from the interaction with this j atom. */
291 velecsum = _mm_add_pd(velecsum,velec);
292 vgbsum = _mm_add_pd(vgbsum,vgb);
293 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
295 fscal = _mm_add_pd(felec,fvdw);
297 /* Update vectorial force */
298 fix0 = _mm_macc_pd(dx00,fscal,fix0);
299 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
300 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
302 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
303 _mm_mul_pd(dx00,fscal),
304 _mm_mul_pd(dy00,fscal),
305 _mm_mul_pd(dz00,fscal));
307 /* Inner loop uses 95 flops */
314 j_coord_offsetA = DIM*jnrA;
316 /* load j atom coordinates */
317 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
320 /* Calculate displacement vector */
321 dx00 = _mm_sub_pd(ix0,jx0);
322 dy00 = _mm_sub_pd(iy0,jy0);
323 dz00 = _mm_sub_pd(iz0,jz0);
325 /* Calculate squared distance and things based on it */
326 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
328 rinv00 = gmx_mm_invsqrt_pd(rsq00);
330 /* Load parameters for j particles */
331 jq0 = _mm_load_sd(charge+jnrA+0);
332 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
333 vdwjidx0A = 2*vdwtype[jnrA+0];
335 /**************************
336 * CALCULATE INTERACTIONS *
337 **************************/
339 r00 = _mm_mul_pd(rsq00,rinv00);
341 /* Compute parameters for interactions between i and j atoms */
342 qq00 = _mm_mul_pd(iq0,jq0);
343 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
345 /* Calculate table index by multiplying r with table scale and truncate to integer */
346 rt = _mm_mul_pd(r00,vftabscale);
347 vfitab = _mm_cvttpd_epi32(rt);
349 vfeps = _mm_frcz_pd(rt);
351 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
353 twovfeps = _mm_add_pd(vfeps,vfeps);
354 vfitab = _mm_slli_epi32(vfitab,3);
356 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
357 isaprod = _mm_mul_pd(isai0,isaj0);
358 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
359 gbscale = _mm_mul_pd(isaprod,gbtabscale);
361 /* Calculate generalized born table index - this is a separate table from the normal one,
362 * but we use the same procedure by multiplying r with scale and truncating to integer.
364 rt = _mm_mul_pd(r00,gbscale);
365 gbitab = _mm_cvttpd_epi32(rt);
367 gbeps = _mm_frcz_pd(rt);
369 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
371 gbitab = _mm_slli_epi32(gbitab,2);
373 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
374 F = _mm_setzero_pd();
375 GMX_MM_TRANSPOSE2_PD(Y,F);
376 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
377 H = _mm_setzero_pd();
378 GMX_MM_TRANSPOSE2_PD(G,H);
379 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
380 VV = _mm_macc_pd(gbeps,Fp,Y);
381 vgb = _mm_mul_pd(gbqqfactor,VV);
383 twogbeps = _mm_add_pd(gbeps,gbeps);
384 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
385 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
386 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
387 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
388 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
389 velec = _mm_mul_pd(qq00,rinv00);
390 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
392 /* CUBIC SPLINE TABLE DISPERSION */
393 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
394 F = _mm_setzero_pd();
395 GMX_MM_TRANSPOSE2_PD(Y,F);
396 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
397 H = _mm_setzero_pd();
398 GMX_MM_TRANSPOSE2_PD(G,H);
399 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
400 VV = _mm_macc_pd(vfeps,Fp,Y);
401 vvdw6 = _mm_mul_pd(c6_00,VV);
402 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
403 fvdw6 = _mm_mul_pd(c6_00,FF);
405 /* CUBIC SPLINE TABLE REPULSION */
406 vfitab = _mm_add_epi32(vfitab,ifour);
407 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
408 F = _mm_setzero_pd();
409 GMX_MM_TRANSPOSE2_PD(Y,F);
410 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
411 H = _mm_setzero_pd();
412 GMX_MM_TRANSPOSE2_PD(G,H);
413 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
414 VV = _mm_macc_pd(vfeps,Fp,Y);
415 vvdw12 = _mm_mul_pd(c12_00,VV);
416 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
417 fvdw12 = _mm_mul_pd(c12_00,FF);
418 vvdw = _mm_add_pd(vvdw12,vvdw6);
419 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
421 /* Update potential sum for this i atom from the interaction with this j atom. */
422 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
423 velecsum = _mm_add_pd(velecsum,velec);
424 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
425 vgbsum = _mm_add_pd(vgbsum,vgb);
426 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
427 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
429 fscal = _mm_add_pd(felec,fvdw);
431 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
433 /* Update vectorial force */
434 fix0 = _mm_macc_pd(dx00,fscal,fix0);
435 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
436 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
438 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
439 _mm_mul_pd(dx00,fscal),
440 _mm_mul_pd(dy00,fscal),
441 _mm_mul_pd(dz00,fscal));
443 /* Inner loop uses 95 flops */
446 /* End of innermost loop */
448 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
449 f+i_coord_offset,fshift+i_shift_offset);
452 /* Update potential energies */
453 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
454 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
455 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
456 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
457 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
459 /* Increment number of inner iterations */
460 inneriter += j_index_end - j_index_start;
462 /* Outer loop uses 10 flops */
465 /* Increment number of outer iterations */
468 /* Update outer/inner flops */
470 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*95);
473 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
474 * Electrostatics interaction: GeneralizedBorn
475 * VdW interaction: CubicSplineTable
476 * Geometry: Particle-Particle
477 * Calculate force/pot: Force
480 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
481 (t_nblist * gmx_restrict nlist,
482 rvec * gmx_restrict xx,
483 rvec * gmx_restrict ff,
484 t_forcerec * gmx_restrict fr,
485 t_mdatoms * gmx_restrict mdatoms,
486 nb_kernel_data_t * gmx_restrict kernel_data,
487 t_nrnb * gmx_restrict nrnb)
489 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
490 * just 0 for non-waters.
491 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
492 * jnr indices corresponding to data put in the four positions in the SIMD register.
494 int i_shift_offset,i_coord_offset,outeriter,inneriter;
495 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
497 int j_coord_offsetA,j_coord_offsetB;
498 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
500 real *shiftvec,*fshift,*x,*f;
501 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
503 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
504 int vdwjidx0A,vdwjidx0B;
505 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
506 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
507 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
510 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
511 __m128d minushalf = _mm_set1_pd(-0.5);
512 real *invsqrta,*dvda,*gbtab;
514 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
517 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
518 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
520 __m128i ifour = _mm_set1_epi32(4);
521 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
523 __m128d dummy_mask,cutoff_mask;
524 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
525 __m128d one = _mm_set1_pd(1.0);
526 __m128d two = _mm_set1_pd(2.0);
532 jindex = nlist->jindex;
534 shiftidx = nlist->shift;
536 shiftvec = fr->shift_vec[0];
537 fshift = fr->fshift[0];
538 facel = _mm_set1_pd(fr->epsfac);
539 charge = mdatoms->chargeA;
540 nvdwtype = fr->ntype;
542 vdwtype = mdatoms->typeA;
544 vftab = kernel_data->table_vdw->data;
545 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
547 invsqrta = fr->invsqrta;
549 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
550 gbtab = fr->gbtab.data;
551 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
553 /* Avoid stupid compiler warnings */
561 /* Start outer loop over neighborlists */
562 for(iidx=0; iidx<nri; iidx++)
564 /* Load shift vector for this list */
565 i_shift_offset = DIM*shiftidx[iidx];
567 /* Load limits for loop over neighbors */
568 j_index_start = jindex[iidx];
569 j_index_end = jindex[iidx+1];
571 /* Get outer coordinate index */
573 i_coord_offset = DIM*inr;
575 /* Load i particle coords and add shift vector */
576 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
578 fix0 = _mm_setzero_pd();
579 fiy0 = _mm_setzero_pd();
580 fiz0 = _mm_setzero_pd();
582 /* Load parameters for i particles */
583 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
584 isai0 = _mm_load1_pd(invsqrta+inr+0);
585 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
587 dvdasum = _mm_setzero_pd();
589 /* Start inner kernel loop */
590 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
593 /* Get j neighbor index, and coordinate index */
596 j_coord_offsetA = DIM*jnrA;
597 j_coord_offsetB = DIM*jnrB;
599 /* load j atom coordinates */
600 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
603 /* Calculate displacement vector */
604 dx00 = _mm_sub_pd(ix0,jx0);
605 dy00 = _mm_sub_pd(iy0,jy0);
606 dz00 = _mm_sub_pd(iz0,jz0);
608 /* Calculate squared distance and things based on it */
609 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
611 rinv00 = gmx_mm_invsqrt_pd(rsq00);
613 /* Load parameters for j particles */
614 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
615 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
616 vdwjidx0A = 2*vdwtype[jnrA+0];
617 vdwjidx0B = 2*vdwtype[jnrB+0];
619 /**************************
620 * CALCULATE INTERACTIONS *
621 **************************/
623 r00 = _mm_mul_pd(rsq00,rinv00);
625 /* Compute parameters for interactions between i and j atoms */
626 qq00 = _mm_mul_pd(iq0,jq0);
627 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
628 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
630 /* Calculate table index by multiplying r with table scale and truncate to integer */
631 rt = _mm_mul_pd(r00,vftabscale);
632 vfitab = _mm_cvttpd_epi32(rt);
634 vfeps = _mm_frcz_pd(rt);
636 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
638 twovfeps = _mm_add_pd(vfeps,vfeps);
639 vfitab = _mm_slli_epi32(vfitab,3);
641 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
642 isaprod = _mm_mul_pd(isai0,isaj0);
643 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
644 gbscale = _mm_mul_pd(isaprod,gbtabscale);
646 /* Calculate generalized born table index - this is a separate table from the normal one,
647 * but we use the same procedure by multiplying r with scale and truncating to integer.
649 rt = _mm_mul_pd(r00,gbscale);
650 gbitab = _mm_cvttpd_epi32(rt);
652 gbeps = _mm_frcz_pd(rt);
654 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
656 gbitab = _mm_slli_epi32(gbitab,2);
658 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
659 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
660 GMX_MM_TRANSPOSE2_PD(Y,F);
661 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
662 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
663 GMX_MM_TRANSPOSE2_PD(G,H);
664 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
665 VV = _mm_macc_pd(gbeps,Fp,Y);
666 vgb = _mm_mul_pd(gbqqfactor,VV);
668 twogbeps = _mm_add_pd(gbeps,gbeps);
669 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
670 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
671 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
672 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
673 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
674 velec = _mm_mul_pd(qq00,rinv00);
675 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
677 /* CUBIC SPLINE TABLE DISPERSION */
678 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
679 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
680 GMX_MM_TRANSPOSE2_PD(Y,F);
681 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
682 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
683 GMX_MM_TRANSPOSE2_PD(G,H);
684 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
685 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
686 fvdw6 = _mm_mul_pd(c6_00,FF);
688 /* CUBIC SPLINE TABLE REPULSION */
689 vfitab = _mm_add_epi32(vfitab,ifour);
690 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
691 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
692 GMX_MM_TRANSPOSE2_PD(Y,F);
693 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
694 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
695 GMX_MM_TRANSPOSE2_PD(G,H);
696 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
697 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
698 fvdw12 = _mm_mul_pd(c12_00,FF);
699 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
701 fscal = _mm_add_pd(felec,fvdw);
703 /* Update vectorial force */
704 fix0 = _mm_macc_pd(dx00,fscal,fix0);
705 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
706 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
708 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
709 _mm_mul_pd(dx00,fscal),
710 _mm_mul_pd(dy00,fscal),
711 _mm_mul_pd(dz00,fscal));
713 /* Inner loop uses 85 flops */
720 j_coord_offsetA = DIM*jnrA;
722 /* load j atom coordinates */
723 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
726 /* Calculate displacement vector */
727 dx00 = _mm_sub_pd(ix0,jx0);
728 dy00 = _mm_sub_pd(iy0,jy0);
729 dz00 = _mm_sub_pd(iz0,jz0);
731 /* Calculate squared distance and things based on it */
732 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
734 rinv00 = gmx_mm_invsqrt_pd(rsq00);
736 /* Load parameters for j particles */
737 jq0 = _mm_load_sd(charge+jnrA+0);
738 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
739 vdwjidx0A = 2*vdwtype[jnrA+0];
741 /**************************
742 * CALCULATE INTERACTIONS *
743 **************************/
745 r00 = _mm_mul_pd(rsq00,rinv00);
747 /* Compute parameters for interactions between i and j atoms */
748 qq00 = _mm_mul_pd(iq0,jq0);
749 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
751 /* Calculate table index by multiplying r with table scale and truncate to integer */
752 rt = _mm_mul_pd(r00,vftabscale);
753 vfitab = _mm_cvttpd_epi32(rt);
755 vfeps = _mm_frcz_pd(rt);
757 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
759 twovfeps = _mm_add_pd(vfeps,vfeps);
760 vfitab = _mm_slli_epi32(vfitab,3);
762 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
763 isaprod = _mm_mul_pd(isai0,isaj0);
764 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
765 gbscale = _mm_mul_pd(isaprod,gbtabscale);
767 /* Calculate generalized born table index - this is a separate table from the normal one,
768 * but we use the same procedure by multiplying r with scale and truncating to integer.
770 rt = _mm_mul_pd(r00,gbscale);
771 gbitab = _mm_cvttpd_epi32(rt);
773 gbeps = _mm_frcz_pd(rt);
775 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
777 gbitab = _mm_slli_epi32(gbitab,2);
779 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
780 F = _mm_setzero_pd();
781 GMX_MM_TRANSPOSE2_PD(Y,F);
782 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
783 H = _mm_setzero_pd();
784 GMX_MM_TRANSPOSE2_PD(G,H);
785 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
786 VV = _mm_macc_pd(gbeps,Fp,Y);
787 vgb = _mm_mul_pd(gbqqfactor,VV);
789 twogbeps = _mm_add_pd(gbeps,gbeps);
790 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
791 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
792 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
793 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
794 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
795 velec = _mm_mul_pd(qq00,rinv00);
796 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
798 /* CUBIC SPLINE TABLE DISPERSION */
799 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
800 F = _mm_setzero_pd();
801 GMX_MM_TRANSPOSE2_PD(Y,F);
802 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
803 H = _mm_setzero_pd();
804 GMX_MM_TRANSPOSE2_PD(G,H);
805 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
806 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
807 fvdw6 = _mm_mul_pd(c6_00,FF);
809 /* CUBIC SPLINE TABLE REPULSION */
810 vfitab = _mm_add_epi32(vfitab,ifour);
811 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
812 F = _mm_setzero_pd();
813 GMX_MM_TRANSPOSE2_PD(Y,F);
814 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
815 H = _mm_setzero_pd();
816 GMX_MM_TRANSPOSE2_PD(G,H);
817 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
818 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
819 fvdw12 = _mm_mul_pd(c12_00,FF);
820 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
822 fscal = _mm_add_pd(felec,fvdw);
824 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
826 /* Update vectorial force */
827 fix0 = _mm_macc_pd(dx00,fscal,fix0);
828 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
829 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
831 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
832 _mm_mul_pd(dx00,fscal),
833 _mm_mul_pd(dy00,fscal),
834 _mm_mul_pd(dz00,fscal));
836 /* Inner loop uses 85 flops */
839 /* End of innermost loop */
841 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
842 f+i_coord_offset,fshift+i_shift_offset);
844 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
845 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
847 /* Increment number of inner iterations */
848 inneriter += j_index_end - j_index_start;
850 /* Outer loop uses 7 flops */
853 /* Increment number of outer iterations */
856 /* Update outer/inner flops */
858 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*85);