2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 "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_VdwLJ_GeomP1P1_VF_avx_128_fma_double
54 * Electrostatics interaction: GeneralizedBorn
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecGB_VdwLJ_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_unused * 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 invsqrta = fr->invsqrta;
126 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
127 gbtab = fr->gbtab.data;
128 gbinvepsdiff = _mm_set1_pd((1.0/fr->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 = gmx_mm_invsqrt_pd(rsq00);
194 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
196 /* Load parameters for j particles */
197 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
198 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
199 vdwjidx0A = 2*vdwtype[jnrA+0];
200 vdwjidx0B = 2*vdwtype[jnrB+0];
202 /**************************
203 * CALCULATE INTERACTIONS *
204 **************************/
206 r00 = _mm_mul_pd(rsq00,rinv00);
208 /* Compute parameters for interactions between i and j atoms */
209 qq00 = _mm_mul_pd(iq0,jq0);
210 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
211 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
213 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
214 isaprod = _mm_mul_pd(isai0,isaj0);
215 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
216 gbscale = _mm_mul_pd(isaprod,gbtabscale);
218 /* Calculate generalized born table index - this is a separate table from the normal one,
219 * but we use the same procedure by multiplying r with scale and truncating to integer.
221 rt = _mm_mul_pd(r00,gbscale);
222 gbitab = _mm_cvttpd_epi32(rt);
224 gbeps = _mm_frcz_pd(rt);
226 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
228 gbitab = _mm_slli_epi32(gbitab,2);
230 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
231 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
232 GMX_MM_TRANSPOSE2_PD(Y,F);
233 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
234 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
235 GMX_MM_TRANSPOSE2_PD(G,H);
236 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
237 VV = _mm_macc_pd(gbeps,Fp,Y);
238 vgb = _mm_mul_pd(gbqqfactor,VV);
240 twogbeps = _mm_add_pd(gbeps,gbeps);
241 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
242 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
243 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
244 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
245 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
246 velec = _mm_mul_pd(qq00,rinv00);
247 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
249 /* LENNARD-JONES DISPERSION/REPULSION */
251 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
252 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
253 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
254 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
255 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
257 /* Update potential sum for this i atom from the interaction with this j atom. */
258 velecsum = _mm_add_pd(velecsum,velec);
259 vgbsum = _mm_add_pd(vgbsum,vgb);
260 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
262 fscal = _mm_add_pd(felec,fvdw);
264 /* Update vectorial force */
265 fix0 = _mm_macc_pd(dx00,fscal,fix0);
266 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
267 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
269 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
270 _mm_mul_pd(dx00,fscal),
271 _mm_mul_pd(dy00,fscal),
272 _mm_mul_pd(dz00,fscal));
274 /* Inner loop uses 74 flops */
281 j_coord_offsetA = DIM*jnrA;
283 /* load j atom coordinates */
284 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
287 /* Calculate displacement vector */
288 dx00 = _mm_sub_pd(ix0,jx0);
289 dy00 = _mm_sub_pd(iy0,jy0);
290 dz00 = _mm_sub_pd(iz0,jz0);
292 /* Calculate squared distance and things based on it */
293 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
295 rinv00 = gmx_mm_invsqrt_pd(rsq00);
297 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
299 /* Load parameters for j particles */
300 jq0 = _mm_load_sd(charge+jnrA+0);
301 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
302 vdwjidx0A = 2*vdwtype[jnrA+0];
304 /**************************
305 * CALCULATE INTERACTIONS *
306 **************************/
308 r00 = _mm_mul_pd(rsq00,rinv00);
310 /* Compute parameters for interactions between i and j atoms */
311 qq00 = _mm_mul_pd(iq0,jq0);
312 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
314 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
315 isaprod = _mm_mul_pd(isai0,isaj0);
316 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
317 gbscale = _mm_mul_pd(isaprod,gbtabscale);
319 /* Calculate generalized born table index - this is a separate table from the normal one,
320 * but we use the same procedure by multiplying r with scale and truncating to integer.
322 rt = _mm_mul_pd(r00,gbscale);
323 gbitab = _mm_cvttpd_epi32(rt);
325 gbeps = _mm_frcz_pd(rt);
327 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
329 gbitab = _mm_slli_epi32(gbitab,2);
331 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
332 F = _mm_setzero_pd();
333 GMX_MM_TRANSPOSE2_PD(Y,F);
334 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
335 H = _mm_setzero_pd();
336 GMX_MM_TRANSPOSE2_PD(G,H);
337 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
338 VV = _mm_macc_pd(gbeps,Fp,Y);
339 vgb = _mm_mul_pd(gbqqfactor,VV);
341 twogbeps = _mm_add_pd(gbeps,gbeps);
342 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
343 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
344 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
345 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
346 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
347 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
348 velec = _mm_mul_pd(qq00,rinv00);
349 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
351 /* LENNARD-JONES DISPERSION/REPULSION */
353 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
354 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
355 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
356 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
357 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
361 velecsum = _mm_add_pd(velecsum,velec);
362 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
363 vgbsum = _mm_add_pd(vgbsum,vgb);
364 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
365 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
367 fscal = _mm_add_pd(felec,fvdw);
369 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
371 /* Update vectorial force */
372 fix0 = _mm_macc_pd(dx00,fscal,fix0);
373 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
374 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
376 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
377 _mm_mul_pd(dx00,fscal),
378 _mm_mul_pd(dy00,fscal),
379 _mm_mul_pd(dz00,fscal));
381 /* Inner loop uses 74 flops */
384 /* End of innermost loop */
386 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
387 f+i_coord_offset,fshift+i_shift_offset);
390 /* Update potential energies */
391 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
392 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
393 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
394 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
395 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
397 /* Increment number of inner iterations */
398 inneriter += j_index_end - j_index_start;
400 /* Outer loop uses 10 flops */
403 /* Increment number of outer iterations */
406 /* Update outer/inner flops */
408 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*74);
411 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_double
412 * Electrostatics interaction: GeneralizedBorn
413 * VdW interaction: LennardJones
414 * Geometry: Particle-Particle
415 * Calculate force/pot: Force
418 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_double
419 (t_nblist * gmx_restrict nlist,
420 rvec * gmx_restrict xx,
421 rvec * gmx_restrict ff,
422 t_forcerec * gmx_restrict fr,
423 t_mdatoms * gmx_restrict mdatoms,
424 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
425 t_nrnb * gmx_restrict nrnb)
427 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
428 * just 0 for non-waters.
429 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
430 * jnr indices corresponding to data put in the four positions in the SIMD register.
432 int i_shift_offset,i_coord_offset,outeriter,inneriter;
433 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
435 int j_coord_offsetA,j_coord_offsetB;
436 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
438 real *shiftvec,*fshift,*x,*f;
439 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
441 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
442 int vdwjidx0A,vdwjidx0B;
443 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
444 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
445 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
448 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
449 __m128d minushalf = _mm_set1_pd(-0.5);
450 real *invsqrta,*dvda,*gbtab;
452 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
455 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
456 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
458 __m128i ifour = _mm_set1_epi32(4);
459 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
461 __m128d dummy_mask,cutoff_mask;
462 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
463 __m128d one = _mm_set1_pd(1.0);
464 __m128d two = _mm_set1_pd(2.0);
470 jindex = nlist->jindex;
472 shiftidx = nlist->shift;
474 shiftvec = fr->shift_vec[0];
475 fshift = fr->fshift[0];
476 facel = _mm_set1_pd(fr->epsfac);
477 charge = mdatoms->chargeA;
478 nvdwtype = fr->ntype;
480 vdwtype = mdatoms->typeA;
482 invsqrta = fr->invsqrta;
484 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
485 gbtab = fr->gbtab.data;
486 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
488 /* Avoid stupid compiler warnings */
496 /* Start outer loop over neighborlists */
497 for(iidx=0; iidx<nri; iidx++)
499 /* Load shift vector for this list */
500 i_shift_offset = DIM*shiftidx[iidx];
502 /* Load limits for loop over neighbors */
503 j_index_start = jindex[iidx];
504 j_index_end = jindex[iidx+1];
506 /* Get outer coordinate index */
508 i_coord_offset = DIM*inr;
510 /* Load i particle coords and add shift vector */
511 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
513 fix0 = _mm_setzero_pd();
514 fiy0 = _mm_setzero_pd();
515 fiz0 = _mm_setzero_pd();
517 /* Load parameters for i particles */
518 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
519 isai0 = _mm_load1_pd(invsqrta+inr+0);
520 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
522 dvdasum = _mm_setzero_pd();
524 /* Start inner kernel loop */
525 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
528 /* Get j neighbor index, and coordinate index */
531 j_coord_offsetA = DIM*jnrA;
532 j_coord_offsetB = DIM*jnrB;
534 /* load j atom coordinates */
535 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
538 /* Calculate displacement vector */
539 dx00 = _mm_sub_pd(ix0,jx0);
540 dy00 = _mm_sub_pd(iy0,jy0);
541 dz00 = _mm_sub_pd(iz0,jz0);
543 /* Calculate squared distance and things based on it */
544 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
546 rinv00 = gmx_mm_invsqrt_pd(rsq00);
548 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
550 /* Load parameters for j particles */
551 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
552 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
553 vdwjidx0A = 2*vdwtype[jnrA+0];
554 vdwjidx0B = 2*vdwtype[jnrB+0];
556 /**************************
557 * CALCULATE INTERACTIONS *
558 **************************/
560 r00 = _mm_mul_pd(rsq00,rinv00);
562 /* Compute parameters for interactions between i and j atoms */
563 qq00 = _mm_mul_pd(iq0,jq0);
564 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
565 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
567 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
568 isaprod = _mm_mul_pd(isai0,isaj0);
569 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
570 gbscale = _mm_mul_pd(isaprod,gbtabscale);
572 /* Calculate generalized born table index - this is a separate table from the normal one,
573 * but we use the same procedure by multiplying r with scale and truncating to integer.
575 rt = _mm_mul_pd(r00,gbscale);
576 gbitab = _mm_cvttpd_epi32(rt);
578 gbeps = _mm_frcz_pd(rt);
580 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
582 gbitab = _mm_slli_epi32(gbitab,2);
584 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
585 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
586 GMX_MM_TRANSPOSE2_PD(Y,F);
587 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
588 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
589 GMX_MM_TRANSPOSE2_PD(G,H);
590 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
591 VV = _mm_macc_pd(gbeps,Fp,Y);
592 vgb = _mm_mul_pd(gbqqfactor,VV);
594 twogbeps = _mm_add_pd(gbeps,gbeps);
595 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
596 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
597 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
598 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
599 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
600 velec = _mm_mul_pd(qq00,rinv00);
601 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
603 /* LENNARD-JONES DISPERSION/REPULSION */
605 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
606 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
608 fscal = _mm_add_pd(felec,fvdw);
610 /* Update vectorial force */
611 fix0 = _mm_macc_pd(dx00,fscal,fix0);
612 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
613 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
615 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
616 _mm_mul_pd(dx00,fscal),
617 _mm_mul_pd(dy00,fscal),
618 _mm_mul_pd(dz00,fscal));
620 /* Inner loop uses 67 flops */
627 j_coord_offsetA = DIM*jnrA;
629 /* load j atom coordinates */
630 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
633 /* Calculate displacement vector */
634 dx00 = _mm_sub_pd(ix0,jx0);
635 dy00 = _mm_sub_pd(iy0,jy0);
636 dz00 = _mm_sub_pd(iz0,jz0);
638 /* Calculate squared distance and things based on it */
639 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
641 rinv00 = gmx_mm_invsqrt_pd(rsq00);
643 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
645 /* Load parameters for j particles */
646 jq0 = _mm_load_sd(charge+jnrA+0);
647 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
648 vdwjidx0A = 2*vdwtype[jnrA+0];
650 /**************************
651 * CALCULATE INTERACTIONS *
652 **************************/
654 r00 = _mm_mul_pd(rsq00,rinv00);
656 /* Compute parameters for interactions between i and j atoms */
657 qq00 = _mm_mul_pd(iq0,jq0);
658 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
660 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
661 isaprod = _mm_mul_pd(isai0,isaj0);
662 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
663 gbscale = _mm_mul_pd(isaprod,gbtabscale);
665 /* Calculate generalized born table index - this is a separate table from the normal one,
666 * but we use the same procedure by multiplying r with scale and truncating to integer.
668 rt = _mm_mul_pd(r00,gbscale);
669 gbitab = _mm_cvttpd_epi32(rt);
671 gbeps = _mm_frcz_pd(rt);
673 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
675 gbitab = _mm_slli_epi32(gbitab,2);
677 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
678 F = _mm_setzero_pd();
679 GMX_MM_TRANSPOSE2_PD(Y,F);
680 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
681 H = _mm_setzero_pd();
682 GMX_MM_TRANSPOSE2_PD(G,H);
683 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
684 VV = _mm_macc_pd(gbeps,Fp,Y);
685 vgb = _mm_mul_pd(gbqqfactor,VV);
687 twogbeps = _mm_add_pd(gbeps,gbeps);
688 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
689 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
690 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
691 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
692 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
693 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
694 velec = _mm_mul_pd(qq00,rinv00);
695 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
697 /* LENNARD-JONES DISPERSION/REPULSION */
699 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
700 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
702 fscal = _mm_add_pd(felec,fvdw);
704 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
706 /* Update vectorial force */
707 fix0 = _mm_macc_pd(dx00,fscal,fix0);
708 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
709 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
711 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
712 _mm_mul_pd(dx00,fscal),
713 _mm_mul_pd(dy00,fscal),
714 _mm_mul_pd(dz00,fscal));
716 /* Inner loop uses 67 flops */
719 /* End of innermost loop */
721 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
722 f+i_coord_offset,fshift+i_shift_offset);
724 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
725 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
727 /* Increment number of inner iterations */
728 inneriter += j_index_end - j_index_start;
730 /* Outer loop uses 7 flops */
733 /* Increment number of outer iterations */
736 /* Update outer/inner flops */
738 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*67);