2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: GeneralizedBorn
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_avx_128_fma_double
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 int vdwjidx0A,vdwjidx0B;
83 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
88 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
89 __m128d minushalf = _mm_set1_pd(-0.5);
90 real *invsqrta,*dvda,*gbtab;
92 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
95 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
96 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
98 __m128i ifour = _mm_set1_epi32(4);
99 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
101 __m128d dummy_mask,cutoff_mask;
102 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
103 __m128d one = _mm_set1_pd(1.0);
104 __m128d two = _mm_set1_pd(2.0);
110 jindex = nlist->jindex;
112 shiftidx = nlist->shift;
114 shiftvec = fr->shift_vec[0];
115 fshift = fr->fshift[0];
116 facel = _mm_set1_pd(fr->epsfac);
117 charge = mdatoms->chargeA;
118 nvdwtype = fr->ntype;
120 vdwtype = mdatoms->typeA;
122 invsqrta = fr->invsqrta;
124 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
125 gbtab = fr->gbtab.data;
126 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
128 /* Avoid stupid compiler warnings */
136 /* Start outer loop over neighborlists */
137 for(iidx=0; iidx<nri; iidx++)
139 /* Load shift vector for this list */
140 i_shift_offset = DIM*shiftidx[iidx];
142 /* Load limits for loop over neighbors */
143 j_index_start = jindex[iidx];
144 j_index_end = jindex[iidx+1];
146 /* Get outer coordinate index */
148 i_coord_offset = DIM*inr;
150 /* Load i particle coords and add shift vector */
151 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
153 fix0 = _mm_setzero_pd();
154 fiy0 = _mm_setzero_pd();
155 fiz0 = _mm_setzero_pd();
157 /* Load parameters for i particles */
158 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
159 isai0 = _mm_load1_pd(invsqrta+inr+0);
160 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
162 /* Reset potential sums */
163 velecsum = _mm_setzero_pd();
164 vgbsum = _mm_setzero_pd();
165 vvdwsum = _mm_setzero_pd();
166 dvdasum = _mm_setzero_pd();
168 /* Start inner kernel loop */
169 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
172 /* Get j neighbor index, and coordinate index */
175 j_coord_offsetA = DIM*jnrA;
176 j_coord_offsetB = DIM*jnrB;
178 /* load j atom coordinates */
179 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
182 /* Calculate displacement vector */
183 dx00 = _mm_sub_pd(ix0,jx0);
184 dy00 = _mm_sub_pd(iy0,jy0);
185 dz00 = _mm_sub_pd(iz0,jz0);
187 /* Calculate squared distance and things based on it */
188 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
190 rinv00 = gmx_mm_invsqrt_pd(rsq00);
192 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
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 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
212 isaprod = _mm_mul_pd(isai0,isaj0);
213 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
214 gbscale = _mm_mul_pd(isaprod,gbtabscale);
216 /* Calculate generalized born table index - this is a separate table from the normal one,
217 * but we use the same procedure by multiplying r with scale and truncating to integer.
219 rt = _mm_mul_pd(r00,gbscale);
220 gbitab = _mm_cvttpd_epi32(rt);
222 gbeps = _mm_frcz_pd(rt);
224 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
226 gbitab = _mm_slli_epi32(gbitab,2);
228 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
229 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
230 GMX_MM_TRANSPOSE2_PD(Y,F);
231 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
232 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
233 GMX_MM_TRANSPOSE2_PD(G,H);
234 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
235 VV = _mm_macc_pd(gbeps,Fp,Y);
236 vgb = _mm_mul_pd(gbqqfactor,VV);
238 twogbeps = _mm_add_pd(gbeps,gbeps);
239 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
240 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
241 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
242 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
243 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
244 velec = _mm_mul_pd(qq00,rinv00);
245 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
247 /* LENNARD-JONES DISPERSION/REPULSION */
249 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
250 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
251 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
252 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
253 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
255 /* Update potential sum for this i atom from the interaction with this j atom. */
256 velecsum = _mm_add_pd(velecsum,velec);
257 vgbsum = _mm_add_pd(vgbsum,vgb);
258 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
260 fscal = _mm_add_pd(felec,fvdw);
262 /* Update vectorial force */
263 fix0 = _mm_macc_pd(dx00,fscal,fix0);
264 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
265 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
267 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
268 _mm_mul_pd(dx00,fscal),
269 _mm_mul_pd(dy00,fscal),
270 _mm_mul_pd(dz00,fscal));
272 /* Inner loop uses 74 flops */
279 j_coord_offsetA = DIM*jnrA;
281 /* load j atom coordinates */
282 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
285 /* Calculate displacement vector */
286 dx00 = _mm_sub_pd(ix0,jx0);
287 dy00 = _mm_sub_pd(iy0,jy0);
288 dz00 = _mm_sub_pd(iz0,jz0);
290 /* Calculate squared distance and things based on it */
291 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
293 rinv00 = gmx_mm_invsqrt_pd(rsq00);
295 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
297 /* Load parameters for j particles */
298 jq0 = _mm_load_sd(charge+jnrA+0);
299 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
300 vdwjidx0A = 2*vdwtype[jnrA+0];
302 /**************************
303 * CALCULATE INTERACTIONS *
304 **************************/
306 r00 = _mm_mul_pd(rsq00,rinv00);
308 /* Compute parameters for interactions between i and j atoms */
309 qq00 = _mm_mul_pd(iq0,jq0);
310 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
312 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
313 isaprod = _mm_mul_pd(isai0,isaj0);
314 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
315 gbscale = _mm_mul_pd(isaprod,gbtabscale);
317 /* Calculate generalized born table index - this is a separate table from the normal one,
318 * but we use the same procedure by multiplying r with scale and truncating to integer.
320 rt = _mm_mul_pd(r00,gbscale);
321 gbitab = _mm_cvttpd_epi32(rt);
323 gbeps = _mm_frcz_pd(rt);
325 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
327 gbitab = _mm_slli_epi32(gbitab,2);
329 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
330 F = _mm_setzero_pd();
331 GMX_MM_TRANSPOSE2_PD(Y,F);
332 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
333 H = _mm_setzero_pd();
334 GMX_MM_TRANSPOSE2_PD(G,H);
335 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
336 VV = _mm_macc_pd(gbeps,Fp,Y);
337 vgb = _mm_mul_pd(gbqqfactor,VV);
339 twogbeps = _mm_add_pd(gbeps,gbeps);
340 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
341 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
342 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
343 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
344 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
345 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
346 velec = _mm_mul_pd(qq00,rinv00);
347 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
349 /* LENNARD-JONES DISPERSION/REPULSION */
351 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
352 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
353 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
354 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
355 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
357 /* Update potential sum for this i atom from the interaction with this j atom. */
358 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
359 velecsum = _mm_add_pd(velecsum,velec);
360 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
361 vgbsum = _mm_add_pd(vgbsum,vgb);
362 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
363 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
365 fscal = _mm_add_pd(felec,fvdw);
367 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
369 /* Update vectorial force */
370 fix0 = _mm_macc_pd(dx00,fscal,fix0);
371 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
372 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
374 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
375 _mm_mul_pd(dx00,fscal),
376 _mm_mul_pd(dy00,fscal),
377 _mm_mul_pd(dz00,fscal));
379 /* Inner loop uses 74 flops */
382 /* End of innermost loop */
384 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
385 f+i_coord_offset,fshift+i_shift_offset);
388 /* Update potential energies */
389 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
390 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
391 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
392 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
393 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
395 /* Increment number of inner iterations */
396 inneriter += j_index_end - j_index_start;
398 /* Outer loop uses 10 flops */
401 /* Increment number of outer iterations */
404 /* Update outer/inner flops */
406 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*74);
409 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_double
410 * Electrostatics interaction: GeneralizedBorn
411 * VdW interaction: LennardJones
412 * Geometry: Particle-Particle
413 * Calculate force/pot: Force
416 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_double
417 (t_nblist * gmx_restrict nlist,
418 rvec * gmx_restrict xx,
419 rvec * gmx_restrict ff,
420 t_forcerec * gmx_restrict fr,
421 t_mdatoms * gmx_restrict mdatoms,
422 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
423 t_nrnb * gmx_restrict nrnb)
425 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
426 * just 0 for non-waters.
427 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
428 * jnr indices corresponding to data put in the four positions in the SIMD register.
430 int i_shift_offset,i_coord_offset,outeriter,inneriter;
431 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
433 int j_coord_offsetA,j_coord_offsetB;
434 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
436 real *shiftvec,*fshift,*x,*f;
437 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
439 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
440 int vdwjidx0A,vdwjidx0B;
441 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
442 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
443 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
446 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
447 __m128d minushalf = _mm_set1_pd(-0.5);
448 real *invsqrta,*dvda,*gbtab;
450 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
453 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
454 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
456 __m128i ifour = _mm_set1_epi32(4);
457 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
459 __m128d dummy_mask,cutoff_mask;
460 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
461 __m128d one = _mm_set1_pd(1.0);
462 __m128d two = _mm_set1_pd(2.0);
468 jindex = nlist->jindex;
470 shiftidx = nlist->shift;
472 shiftvec = fr->shift_vec[0];
473 fshift = fr->fshift[0];
474 facel = _mm_set1_pd(fr->epsfac);
475 charge = mdatoms->chargeA;
476 nvdwtype = fr->ntype;
478 vdwtype = mdatoms->typeA;
480 invsqrta = fr->invsqrta;
482 gbtabscale = _mm_set1_pd(fr->gbtab.scale);
483 gbtab = fr->gbtab.data;
484 gbinvepsdiff = _mm_set1_pd((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
486 /* Avoid stupid compiler warnings */
494 /* Start outer loop over neighborlists */
495 for(iidx=0; iidx<nri; iidx++)
497 /* Load shift vector for this list */
498 i_shift_offset = DIM*shiftidx[iidx];
500 /* Load limits for loop over neighbors */
501 j_index_start = jindex[iidx];
502 j_index_end = jindex[iidx+1];
504 /* Get outer coordinate index */
506 i_coord_offset = DIM*inr;
508 /* Load i particle coords and add shift vector */
509 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
511 fix0 = _mm_setzero_pd();
512 fiy0 = _mm_setzero_pd();
513 fiz0 = _mm_setzero_pd();
515 /* Load parameters for i particles */
516 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
517 isai0 = _mm_load1_pd(invsqrta+inr+0);
518 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
520 dvdasum = _mm_setzero_pd();
522 /* Start inner kernel loop */
523 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
526 /* Get j neighbor index, and coordinate index */
529 j_coord_offsetA = DIM*jnrA;
530 j_coord_offsetB = DIM*jnrB;
532 /* load j atom coordinates */
533 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
536 /* Calculate displacement vector */
537 dx00 = _mm_sub_pd(ix0,jx0);
538 dy00 = _mm_sub_pd(iy0,jy0);
539 dz00 = _mm_sub_pd(iz0,jz0);
541 /* Calculate squared distance and things based on it */
542 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
544 rinv00 = gmx_mm_invsqrt_pd(rsq00);
546 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
548 /* Load parameters for j particles */
549 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
550 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
551 vdwjidx0A = 2*vdwtype[jnrA+0];
552 vdwjidx0B = 2*vdwtype[jnrB+0];
554 /**************************
555 * CALCULATE INTERACTIONS *
556 **************************/
558 r00 = _mm_mul_pd(rsq00,rinv00);
560 /* Compute parameters for interactions between i and j atoms */
561 qq00 = _mm_mul_pd(iq0,jq0);
562 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
563 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
565 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
566 isaprod = _mm_mul_pd(isai0,isaj0);
567 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
568 gbscale = _mm_mul_pd(isaprod,gbtabscale);
570 /* Calculate generalized born table index - this is a separate table from the normal one,
571 * but we use the same procedure by multiplying r with scale and truncating to integer.
573 rt = _mm_mul_pd(r00,gbscale);
574 gbitab = _mm_cvttpd_epi32(rt);
576 gbeps = _mm_frcz_pd(rt);
578 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
580 gbitab = _mm_slli_epi32(gbitab,2);
582 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
583 F = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
584 GMX_MM_TRANSPOSE2_PD(Y,F);
585 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
586 H = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
587 GMX_MM_TRANSPOSE2_PD(G,H);
588 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
589 VV = _mm_macc_pd(gbeps,Fp,Y);
590 vgb = _mm_mul_pd(gbqqfactor,VV);
592 twogbeps = _mm_add_pd(gbeps,gbeps);
593 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
594 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
595 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
596 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
597 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
598 velec = _mm_mul_pd(qq00,rinv00);
599 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
601 /* LENNARD-JONES DISPERSION/REPULSION */
603 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
604 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
606 fscal = _mm_add_pd(felec,fvdw);
608 /* Update vectorial force */
609 fix0 = _mm_macc_pd(dx00,fscal,fix0);
610 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
611 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
613 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
614 _mm_mul_pd(dx00,fscal),
615 _mm_mul_pd(dy00,fscal),
616 _mm_mul_pd(dz00,fscal));
618 /* Inner loop uses 67 flops */
625 j_coord_offsetA = DIM*jnrA;
627 /* load j atom coordinates */
628 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
631 /* Calculate displacement vector */
632 dx00 = _mm_sub_pd(ix0,jx0);
633 dy00 = _mm_sub_pd(iy0,jy0);
634 dz00 = _mm_sub_pd(iz0,jz0);
636 /* Calculate squared distance and things based on it */
637 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
639 rinv00 = gmx_mm_invsqrt_pd(rsq00);
641 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
643 /* Load parameters for j particles */
644 jq0 = _mm_load_sd(charge+jnrA+0);
645 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
646 vdwjidx0A = 2*vdwtype[jnrA+0];
648 /**************************
649 * CALCULATE INTERACTIONS *
650 **************************/
652 r00 = _mm_mul_pd(rsq00,rinv00);
654 /* Compute parameters for interactions between i and j atoms */
655 qq00 = _mm_mul_pd(iq0,jq0);
656 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
658 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
659 isaprod = _mm_mul_pd(isai0,isaj0);
660 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
661 gbscale = _mm_mul_pd(isaprod,gbtabscale);
663 /* Calculate generalized born table index - this is a separate table from the normal one,
664 * but we use the same procedure by multiplying r with scale and truncating to integer.
666 rt = _mm_mul_pd(r00,gbscale);
667 gbitab = _mm_cvttpd_epi32(rt);
669 gbeps = _mm_frcz_pd(rt);
671 gbeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
673 gbitab = _mm_slli_epi32(gbitab,2);
675 Y = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
676 F = _mm_setzero_pd();
677 GMX_MM_TRANSPOSE2_PD(Y,F);
678 G = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
679 H = _mm_setzero_pd();
680 GMX_MM_TRANSPOSE2_PD(G,H);
681 Fp = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
682 VV = _mm_macc_pd(gbeps,Fp,Y);
683 vgb = _mm_mul_pd(gbqqfactor,VV);
685 twogbeps = _mm_add_pd(gbeps,gbeps);
686 FF = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
687 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
688 dvdatmp = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
689 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
690 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
691 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
692 velec = _mm_mul_pd(qq00,rinv00);
693 felec = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
695 /* LENNARD-JONES DISPERSION/REPULSION */
697 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
698 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
700 fscal = _mm_add_pd(felec,fvdw);
702 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
704 /* Update vectorial force */
705 fix0 = _mm_macc_pd(dx00,fscal,fix0);
706 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
707 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
709 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
710 _mm_mul_pd(dx00,fscal),
711 _mm_mul_pd(dy00,fscal),
712 _mm_mul_pd(dz00,fscal));
714 /* Inner loop uses 67 flops */
717 /* End of innermost loop */
719 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
720 f+i_coord_offset,fshift+i_shift_offset);
722 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
723 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
725 /* Increment number of inner iterations */
726 inneriter += j_index_end - j_index_start;
728 /* Outer loop uses 7 flops */
731 /* Increment number of outer iterations */
734 /* Update outer/inner flops */
736 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*67);