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 sse2_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_double
51 * Electrostatics interaction: GeneralizedBorn
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_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,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;
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 invsqrta = fr->invsqrta;
123 gbtabscale = _mm_set1_pd(fr->gbtab->scale);
124 gbtab = fr->gbtab->data;
125 gbinvepsdiff = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
127 /* Avoid stupid compiler warnings */
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
152 fix0 = _mm_setzero_pd();
153 fiy0 = _mm_setzero_pd();
154 fiz0 = _mm_setzero_pd();
156 /* Load parameters for i particles */
157 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
158 isai0 = _mm_load1_pd(invsqrta+inr+0);
159 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
161 /* Reset potential sums */
162 velecsum = _mm_setzero_pd();
163 vgbsum = _mm_setzero_pd();
164 vvdwsum = _mm_setzero_pd();
165 dvdasum = _mm_setzero_pd();
167 /* Start inner kernel loop */
168 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
171 /* Get j neighbor index, and coordinate index */
174 j_coord_offsetA = DIM*jnrA;
175 j_coord_offsetB = DIM*jnrB;
177 /* load j atom coordinates */
178 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
181 /* Calculate displacement vector */
182 dx00 = _mm_sub_pd(ix0,jx0);
183 dy00 = _mm_sub_pd(iy0,jy0);
184 dz00 = _mm_sub_pd(iz0,jz0);
186 /* Calculate squared distance and things based on it */
187 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
189 rinv00 = sse2_invsqrt_d(rsq00);
191 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
193 /* Load parameters for j particles */
194 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
195 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
196 vdwjidx0A = 2*vdwtype[jnrA+0];
197 vdwjidx0B = 2*vdwtype[jnrB+0];
199 /**************************
200 * CALCULATE INTERACTIONS *
201 **************************/
203 r00 = _mm_mul_pd(rsq00,rinv00);
205 /* Compute parameters for interactions between i and j atoms */
206 qq00 = _mm_mul_pd(iq0,jq0);
207 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
208 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
210 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
211 isaprod = _mm_mul_pd(isai0,isaj0);
212 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
213 gbscale = _mm_mul_pd(isaprod,gbtabscale);
215 /* Calculate generalized born table index - this is a separate table from the normal one,
216 * but we use the same procedure by multiplying r with scale and truncating to integer.
218 rt = _mm_mul_pd(r00,gbscale);
219 gbitab = _mm_cvttpd_epi32(rt);
220 gbeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(gbitab));
221 gbitab = _mm_slli_epi32(gbitab,2);
223 Y = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) );
224 F = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) );
225 GMX_MM_TRANSPOSE2_PD(Y,F);
226 G = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) +2);
227 H = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) +2);
228 GMX_MM_TRANSPOSE2_PD(G,H);
229 Heps = _mm_mul_pd(gbeps,H);
230 Fp = _mm_add_pd(F,_mm_mul_pd(gbeps,_mm_add_pd(G,Heps)));
231 VV = _mm_add_pd(Y,_mm_mul_pd(gbeps,Fp));
232 vgb = _mm_mul_pd(gbqqfactor,VV);
234 FF = _mm_add_pd(Fp,_mm_mul_pd(gbeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
235 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
236 dvdatmp = _mm_mul_pd(minushalf,_mm_add_pd(vgb,_mm_mul_pd(fgb,r00)));
237 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
238 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
239 velec = _mm_mul_pd(qq00,rinv00);
240 felec = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec,rinv00),fgb),rinv00);
242 /* LENNARD-JONES DISPERSION/REPULSION */
244 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
245 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
246 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
247 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
248 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
250 /* Update potential sum for this i atom from the interaction with this j atom. */
251 velecsum = _mm_add_pd(velecsum,velec);
252 vgbsum = _mm_add_pd(vgbsum,vgb);
253 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
255 fscal = _mm_add_pd(felec,fvdw);
257 /* Calculate temporary vectorial force */
258 tx = _mm_mul_pd(fscal,dx00);
259 ty = _mm_mul_pd(fscal,dy00);
260 tz = _mm_mul_pd(fscal,dz00);
262 /* Update vectorial force */
263 fix0 = _mm_add_pd(fix0,tx);
264 fiy0 = _mm_add_pd(fiy0,ty);
265 fiz0 = _mm_add_pd(fiz0,tz);
267 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
269 /* Inner loop uses 71 flops */
276 j_coord_offsetA = DIM*jnrA;
278 /* load j atom coordinates */
279 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
282 /* Calculate displacement vector */
283 dx00 = _mm_sub_pd(ix0,jx0);
284 dy00 = _mm_sub_pd(iy0,jy0);
285 dz00 = _mm_sub_pd(iz0,jz0);
287 /* Calculate squared distance and things based on it */
288 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
290 rinv00 = sse2_invsqrt_d(rsq00);
292 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
294 /* Load parameters for j particles */
295 jq0 = _mm_load_sd(charge+jnrA+0);
296 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
297 vdwjidx0A = 2*vdwtype[jnrA+0];
299 /**************************
300 * CALCULATE INTERACTIONS *
301 **************************/
303 r00 = _mm_mul_pd(rsq00,rinv00);
305 /* Compute parameters for interactions between i and j atoms */
306 qq00 = _mm_mul_pd(iq0,jq0);
307 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
309 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
310 isaprod = _mm_mul_pd(isai0,isaj0);
311 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
312 gbscale = _mm_mul_pd(isaprod,gbtabscale);
314 /* Calculate generalized born table index - this is a separate table from the normal one,
315 * but we use the same procedure by multiplying r with scale and truncating to integer.
317 rt = _mm_mul_pd(r00,gbscale);
318 gbitab = _mm_cvttpd_epi32(rt);
319 gbeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(gbitab));
320 gbitab = _mm_slli_epi32(gbitab,2);
322 Y = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) );
323 F = _mm_setzero_pd();
324 GMX_MM_TRANSPOSE2_PD(Y,F);
325 G = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) +2);
326 H = _mm_setzero_pd();
327 GMX_MM_TRANSPOSE2_PD(G,H);
328 Heps = _mm_mul_pd(gbeps,H);
329 Fp = _mm_add_pd(F,_mm_mul_pd(gbeps,_mm_add_pd(G,Heps)));
330 VV = _mm_add_pd(Y,_mm_mul_pd(gbeps,Fp));
331 vgb = _mm_mul_pd(gbqqfactor,VV);
333 FF = _mm_add_pd(Fp,_mm_mul_pd(gbeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
334 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
335 dvdatmp = _mm_mul_pd(minushalf,_mm_add_pd(vgb,_mm_mul_pd(fgb,r00)));
336 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
337 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
338 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
339 velec = _mm_mul_pd(qq00,rinv00);
340 felec = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec,rinv00),fgb),rinv00);
342 /* LENNARD-JONES DISPERSION/REPULSION */
344 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
345 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
346 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
347 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
348 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
350 /* Update potential sum for this i atom from the interaction with this j atom. */
351 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
352 velecsum = _mm_add_pd(velecsum,velec);
353 vgb = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
354 vgbsum = _mm_add_pd(vgbsum,vgb);
355 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
356 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
358 fscal = _mm_add_pd(felec,fvdw);
360 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
362 /* Calculate temporary vectorial force */
363 tx = _mm_mul_pd(fscal,dx00);
364 ty = _mm_mul_pd(fscal,dy00);
365 tz = _mm_mul_pd(fscal,dz00);
367 /* Update vectorial force */
368 fix0 = _mm_add_pd(fix0,tx);
369 fiy0 = _mm_add_pd(fiy0,ty);
370 fiz0 = _mm_add_pd(fiz0,tz);
372 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
374 /* Inner loop uses 71 flops */
377 /* End of innermost loop */
379 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
380 f+i_coord_offset,fshift+i_shift_offset);
383 /* Update potential energies */
384 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
385 gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
386 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
387 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
388 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
390 /* Increment number of inner iterations */
391 inneriter += j_index_end - j_index_start;
393 /* Outer loop uses 10 flops */
396 /* Increment number of outer iterations */
399 /* Update outer/inner flops */
401 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*71);
404 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_double
405 * Electrostatics interaction: GeneralizedBorn
406 * VdW interaction: LennardJones
407 * Geometry: Particle-Particle
408 * Calculate force/pot: Force
411 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_double
412 (t_nblist * gmx_restrict nlist,
413 rvec * gmx_restrict xx,
414 rvec * gmx_restrict ff,
415 struct t_forcerec * gmx_restrict fr,
416 t_mdatoms * gmx_restrict mdatoms,
417 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
418 t_nrnb * gmx_restrict nrnb)
420 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
421 * just 0 for non-waters.
422 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
423 * jnr indices corresponding to data put in the four positions in the SIMD register.
425 int i_shift_offset,i_coord_offset,outeriter,inneriter;
426 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
428 int j_coord_offsetA,j_coord_offsetB;
429 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
431 real *shiftvec,*fshift,*x,*f;
432 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
434 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
435 int vdwjidx0A,vdwjidx0B;
436 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
437 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
438 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
441 __m128d vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,dvdatmp;
442 __m128d minushalf = _mm_set1_pd(-0.5);
443 real *invsqrta,*dvda,*gbtab;
445 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
448 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
449 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
451 __m128i ifour = _mm_set1_epi32(4);
452 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
454 __m128d dummy_mask,cutoff_mask;
455 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
456 __m128d one = _mm_set1_pd(1.0);
457 __m128d two = _mm_set1_pd(2.0);
463 jindex = nlist->jindex;
465 shiftidx = nlist->shift;
467 shiftvec = fr->shift_vec[0];
468 fshift = fr->fshift[0];
469 facel = _mm_set1_pd(fr->ic->epsfac);
470 charge = mdatoms->chargeA;
471 nvdwtype = fr->ntype;
473 vdwtype = mdatoms->typeA;
475 invsqrta = fr->invsqrta;
477 gbtabscale = _mm_set1_pd(fr->gbtab->scale);
478 gbtab = fr->gbtab->data;
479 gbinvepsdiff = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
481 /* Avoid stupid compiler warnings */
489 /* Start outer loop over neighborlists */
490 for(iidx=0; iidx<nri; iidx++)
492 /* Load shift vector for this list */
493 i_shift_offset = DIM*shiftidx[iidx];
495 /* Load limits for loop over neighbors */
496 j_index_start = jindex[iidx];
497 j_index_end = jindex[iidx+1];
499 /* Get outer coordinate index */
501 i_coord_offset = DIM*inr;
503 /* Load i particle coords and add shift vector */
504 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
506 fix0 = _mm_setzero_pd();
507 fiy0 = _mm_setzero_pd();
508 fiz0 = _mm_setzero_pd();
510 /* Load parameters for i particles */
511 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
512 isai0 = _mm_load1_pd(invsqrta+inr+0);
513 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
515 dvdasum = _mm_setzero_pd();
517 /* Start inner kernel loop */
518 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
521 /* Get j neighbor index, and coordinate index */
524 j_coord_offsetA = DIM*jnrA;
525 j_coord_offsetB = DIM*jnrB;
527 /* load j atom coordinates */
528 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
531 /* Calculate displacement vector */
532 dx00 = _mm_sub_pd(ix0,jx0);
533 dy00 = _mm_sub_pd(iy0,jy0);
534 dz00 = _mm_sub_pd(iz0,jz0);
536 /* Calculate squared distance and things based on it */
537 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
539 rinv00 = sse2_invsqrt_d(rsq00);
541 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
543 /* Load parameters for j particles */
544 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
545 isaj0 = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
546 vdwjidx0A = 2*vdwtype[jnrA+0];
547 vdwjidx0B = 2*vdwtype[jnrB+0];
549 /**************************
550 * CALCULATE INTERACTIONS *
551 **************************/
553 r00 = _mm_mul_pd(rsq00,rinv00);
555 /* Compute parameters for interactions between i and j atoms */
556 qq00 = _mm_mul_pd(iq0,jq0);
557 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
558 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
560 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
561 isaprod = _mm_mul_pd(isai0,isaj0);
562 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
563 gbscale = _mm_mul_pd(isaprod,gbtabscale);
565 /* Calculate generalized born table index - this is a separate table from the normal one,
566 * but we use the same procedure by multiplying r with scale and truncating to integer.
568 rt = _mm_mul_pd(r00,gbscale);
569 gbitab = _mm_cvttpd_epi32(rt);
570 gbeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(gbitab));
571 gbitab = _mm_slli_epi32(gbitab,2);
573 Y = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) );
574 F = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) );
575 GMX_MM_TRANSPOSE2_PD(Y,F);
576 G = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) +2);
577 H = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,1) +2);
578 GMX_MM_TRANSPOSE2_PD(G,H);
579 Heps = _mm_mul_pd(gbeps,H);
580 Fp = _mm_add_pd(F,_mm_mul_pd(gbeps,_mm_add_pd(G,Heps)));
581 VV = _mm_add_pd(Y,_mm_mul_pd(gbeps,Fp));
582 vgb = _mm_mul_pd(gbqqfactor,VV);
584 FF = _mm_add_pd(Fp,_mm_mul_pd(gbeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
585 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
586 dvdatmp = _mm_mul_pd(minushalf,_mm_add_pd(vgb,_mm_mul_pd(fgb,r00)));
587 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
588 gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
589 velec = _mm_mul_pd(qq00,rinv00);
590 felec = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec,rinv00),fgb),rinv00);
592 /* LENNARD-JONES DISPERSION/REPULSION */
594 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
595 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
597 fscal = _mm_add_pd(felec,fvdw);
599 /* Calculate temporary vectorial force */
600 tx = _mm_mul_pd(fscal,dx00);
601 ty = _mm_mul_pd(fscal,dy00);
602 tz = _mm_mul_pd(fscal,dz00);
604 /* Update vectorial force */
605 fix0 = _mm_add_pd(fix0,tx);
606 fiy0 = _mm_add_pd(fiy0,ty);
607 fiz0 = _mm_add_pd(fiz0,tz);
609 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
611 /* Inner loop uses 64 flops */
618 j_coord_offsetA = DIM*jnrA;
620 /* load j atom coordinates */
621 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
624 /* Calculate displacement vector */
625 dx00 = _mm_sub_pd(ix0,jx0);
626 dy00 = _mm_sub_pd(iy0,jy0);
627 dz00 = _mm_sub_pd(iz0,jz0);
629 /* Calculate squared distance and things based on it */
630 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
632 rinv00 = sse2_invsqrt_d(rsq00);
634 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
636 /* Load parameters for j particles */
637 jq0 = _mm_load_sd(charge+jnrA+0);
638 isaj0 = _mm_load_sd(invsqrta+jnrA+0);
639 vdwjidx0A = 2*vdwtype[jnrA+0];
641 /**************************
642 * CALCULATE INTERACTIONS *
643 **************************/
645 r00 = _mm_mul_pd(rsq00,rinv00);
647 /* Compute parameters for interactions between i and j atoms */
648 qq00 = _mm_mul_pd(iq0,jq0);
649 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
651 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
652 isaprod = _mm_mul_pd(isai0,isaj0);
653 gbqqfactor = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
654 gbscale = _mm_mul_pd(isaprod,gbtabscale);
656 /* Calculate generalized born table index - this is a separate table from the normal one,
657 * but we use the same procedure by multiplying r with scale and truncating to integer.
659 rt = _mm_mul_pd(r00,gbscale);
660 gbitab = _mm_cvttpd_epi32(rt);
661 gbeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(gbitab));
662 gbitab = _mm_slli_epi32(gbitab,2);
664 Y = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) );
665 F = _mm_setzero_pd();
666 GMX_MM_TRANSPOSE2_PD(Y,F);
667 G = _mm_load_pd( gbtab + gmx_mm_extract_epi32(gbitab,0) +2);
668 H = _mm_setzero_pd();
669 GMX_MM_TRANSPOSE2_PD(G,H);
670 Heps = _mm_mul_pd(gbeps,H);
671 Fp = _mm_add_pd(F,_mm_mul_pd(gbeps,_mm_add_pd(G,Heps)));
672 VV = _mm_add_pd(Y,_mm_mul_pd(gbeps,Fp));
673 vgb = _mm_mul_pd(gbqqfactor,VV);
675 FF = _mm_add_pd(Fp,_mm_mul_pd(gbeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
676 fgb = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
677 dvdatmp = _mm_mul_pd(minushalf,_mm_add_pd(vgb,_mm_mul_pd(fgb,r00)));
678 dvdatmp = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
679 dvdasum = _mm_add_pd(dvdasum,dvdatmp);
680 gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
681 velec = _mm_mul_pd(qq00,rinv00);
682 felec = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec,rinv00),fgb),rinv00);
684 /* LENNARD-JONES DISPERSION/REPULSION */
686 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
687 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
689 fscal = _mm_add_pd(felec,fvdw);
691 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
693 /* Calculate temporary vectorial force */
694 tx = _mm_mul_pd(fscal,dx00);
695 ty = _mm_mul_pd(fscal,dy00);
696 tz = _mm_mul_pd(fscal,dz00);
698 /* Update vectorial force */
699 fix0 = _mm_add_pd(fix0,tx);
700 fiy0 = _mm_add_pd(fiy0,ty);
701 fiz0 = _mm_add_pd(fiz0,tz);
703 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
705 /* Inner loop uses 64 flops */
708 /* End of innermost loop */
710 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
711 f+i_coord_offset,fshift+i_shift_offset);
713 dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
714 gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
716 /* Increment number of inner iterations */
717 inneriter += j_index_end - j_index_start;
719 /* Outer loop uses 7 flops */
722 /* Increment number of outer iterations */
725 /* Update outer/inner flops */
727 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*64);