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 sse2_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_sse2_double.h"
50 #include "kernelutil_x86_sse2_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_sse2_double
54 * Electrostatics interaction: Ewald
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_sse2_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 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
93 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
94 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
96 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
98 __m128d dummy_mask,cutoff_mask;
99 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
100 __m128d one = _mm_set1_pd(1.0);
101 __m128d two = _mm_set1_pd(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 facel = _mm_set1_pd(fr->epsfac);
114 charge = mdatoms->chargeA;
115 nvdwtype = fr->ntype;
117 vdwtype = mdatoms->typeA;
119 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
120 ewtab = fr->ic->tabq_coul_FDV0;
121 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
122 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
124 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
125 rcutoff_scalar = fr->rcoulomb;
126 rcutoff = _mm_set1_pd(rcutoff_scalar);
127 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
129 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
130 rvdw = _mm_set1_pd(fr->rvdw);
132 /* Avoid stupid compiler warnings */
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
146 /* Load limits for loop over neighbors */
147 j_index_start = jindex[iidx];
148 j_index_end = jindex[iidx+1];
150 /* Get outer coordinate index */
152 i_coord_offset = DIM*inr;
154 /* Load i particle coords and add shift vector */
155 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
157 fix0 = _mm_setzero_pd();
158 fiy0 = _mm_setzero_pd();
159 fiz0 = _mm_setzero_pd();
161 /* Load parameters for i particles */
162 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
163 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
165 /* Reset potential sums */
166 velecsum = _mm_setzero_pd();
167 vvdwsum = _mm_setzero_pd();
169 /* Start inner kernel loop */
170 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
173 /* Get j neighbor index, and coordinate index */
176 j_coord_offsetA = DIM*jnrA;
177 j_coord_offsetB = DIM*jnrB;
179 /* load j atom coordinates */
180 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
183 /* Calculate displacement vector */
184 dx00 = _mm_sub_pd(ix0,jx0);
185 dy00 = _mm_sub_pd(iy0,jy0);
186 dz00 = _mm_sub_pd(iz0,jz0);
188 /* Calculate squared distance and things based on it */
189 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
191 rinv00 = gmx_mm_invsqrt_pd(rsq00);
193 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
195 /* Load parameters for j particles */
196 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
197 vdwjidx0A = 2*vdwtype[jnrA+0];
198 vdwjidx0B = 2*vdwtype[jnrB+0];
200 /**************************
201 * CALCULATE INTERACTIONS *
202 **************************/
204 if (gmx_mm_any_lt(rsq00,rcutoff2))
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 /* EWALD ELECTROSTATICS */
216 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
217 ewrt = _mm_mul_pd(r00,ewtabscale);
218 ewitab = _mm_cvttpd_epi32(ewrt);
219 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
220 ewitab = _mm_slli_epi32(ewitab,2);
221 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
222 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
223 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
224 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
225 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
226 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
227 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
228 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
229 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
230 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
232 /* LENNARD-JONES DISPERSION/REPULSION */
234 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
235 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
236 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
237 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
238 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
239 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
241 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
243 /* Update potential sum for this i atom from the interaction with this j atom. */
244 velec = _mm_and_pd(velec,cutoff_mask);
245 velecsum = _mm_add_pd(velecsum,velec);
246 vvdw = _mm_and_pd(vvdw,cutoff_mask);
247 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
249 fscal = _mm_add_pd(felec,fvdw);
251 fscal = _mm_and_pd(fscal,cutoff_mask);
253 /* Calculate temporary vectorial force */
254 tx = _mm_mul_pd(fscal,dx00);
255 ty = _mm_mul_pd(fscal,dy00);
256 tz = _mm_mul_pd(fscal,dz00);
258 /* Update vectorial force */
259 fix0 = _mm_add_pd(fix0,tx);
260 fiy0 = _mm_add_pd(fiy0,ty);
261 fiz0 = _mm_add_pd(fiz0,tz);
263 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
267 /* Inner loop uses 64 flops */
274 j_coord_offsetA = DIM*jnrA;
276 /* load j atom coordinates */
277 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
280 /* Calculate displacement vector */
281 dx00 = _mm_sub_pd(ix0,jx0);
282 dy00 = _mm_sub_pd(iy0,jy0);
283 dz00 = _mm_sub_pd(iz0,jz0);
285 /* Calculate squared distance and things based on it */
286 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
288 rinv00 = gmx_mm_invsqrt_pd(rsq00);
290 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
292 /* Load parameters for j particles */
293 jq0 = _mm_load_sd(charge+jnrA+0);
294 vdwjidx0A = 2*vdwtype[jnrA+0];
296 /**************************
297 * CALCULATE INTERACTIONS *
298 **************************/
300 if (gmx_mm_any_lt(rsq00,rcutoff2))
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 /* EWALD ELECTROSTATICS */
311 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
312 ewrt = _mm_mul_pd(r00,ewtabscale);
313 ewitab = _mm_cvttpd_epi32(ewrt);
314 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
315 ewitab = _mm_slli_epi32(ewitab,2);
316 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
317 ewtabD = _mm_setzero_pd();
318 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
319 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
320 ewtabFn = _mm_setzero_pd();
321 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
322 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
323 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
324 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
325 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
327 /* LENNARD-JONES DISPERSION/REPULSION */
329 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
330 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
331 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
332 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
333 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
334 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
336 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
338 /* Update potential sum for this i atom from the interaction with this j atom. */
339 velec = _mm_and_pd(velec,cutoff_mask);
340 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
341 velecsum = _mm_add_pd(velecsum,velec);
342 vvdw = _mm_and_pd(vvdw,cutoff_mask);
343 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
344 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
346 fscal = _mm_add_pd(felec,fvdw);
348 fscal = _mm_and_pd(fscal,cutoff_mask);
350 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
352 /* Calculate temporary vectorial force */
353 tx = _mm_mul_pd(fscal,dx00);
354 ty = _mm_mul_pd(fscal,dy00);
355 tz = _mm_mul_pd(fscal,dz00);
357 /* Update vectorial force */
358 fix0 = _mm_add_pd(fix0,tx);
359 fiy0 = _mm_add_pd(fiy0,ty);
360 fiz0 = _mm_add_pd(fiz0,tz);
362 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
366 /* Inner loop uses 64 flops */
369 /* End of innermost loop */
371 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
372 f+i_coord_offset,fshift+i_shift_offset);
375 /* Update potential energies */
376 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
377 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
379 /* Increment number of inner iterations */
380 inneriter += j_index_end - j_index_start;
382 /* Outer loop uses 9 flops */
385 /* Increment number of outer iterations */
388 /* Update outer/inner flops */
390 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*64);
393 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_sse2_double
394 * Electrostatics interaction: Ewald
395 * VdW interaction: LennardJones
396 * Geometry: Particle-Particle
397 * Calculate force/pot: Force
400 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_sse2_double
401 (t_nblist * gmx_restrict nlist,
402 rvec * gmx_restrict xx,
403 rvec * gmx_restrict ff,
404 t_forcerec * gmx_restrict fr,
405 t_mdatoms * gmx_restrict mdatoms,
406 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
407 t_nrnb * gmx_restrict nrnb)
409 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
410 * just 0 for non-waters.
411 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
412 * jnr indices corresponding to data put in the four positions in the SIMD register.
414 int i_shift_offset,i_coord_offset,outeriter,inneriter;
415 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
417 int j_coord_offsetA,j_coord_offsetB;
418 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
420 real *shiftvec,*fshift,*x,*f;
421 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
423 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
424 int vdwjidx0A,vdwjidx0B;
425 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
426 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
427 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
430 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
433 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
434 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
436 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
438 __m128d dummy_mask,cutoff_mask;
439 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
440 __m128d one = _mm_set1_pd(1.0);
441 __m128d two = _mm_set1_pd(2.0);
447 jindex = nlist->jindex;
449 shiftidx = nlist->shift;
451 shiftvec = fr->shift_vec[0];
452 fshift = fr->fshift[0];
453 facel = _mm_set1_pd(fr->epsfac);
454 charge = mdatoms->chargeA;
455 nvdwtype = fr->ntype;
457 vdwtype = mdatoms->typeA;
459 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
460 ewtab = fr->ic->tabq_coul_F;
461 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
462 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
464 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
465 rcutoff_scalar = fr->rcoulomb;
466 rcutoff = _mm_set1_pd(rcutoff_scalar);
467 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
469 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
470 rvdw = _mm_set1_pd(fr->rvdw);
472 /* Avoid stupid compiler warnings */
480 /* Start outer loop over neighborlists */
481 for(iidx=0; iidx<nri; iidx++)
483 /* Load shift vector for this list */
484 i_shift_offset = DIM*shiftidx[iidx];
486 /* Load limits for loop over neighbors */
487 j_index_start = jindex[iidx];
488 j_index_end = jindex[iidx+1];
490 /* Get outer coordinate index */
492 i_coord_offset = DIM*inr;
494 /* Load i particle coords and add shift vector */
495 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
497 fix0 = _mm_setzero_pd();
498 fiy0 = _mm_setzero_pd();
499 fiz0 = _mm_setzero_pd();
501 /* Load parameters for i particles */
502 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
503 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
505 /* Start inner kernel loop */
506 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
509 /* Get j neighbor index, and coordinate index */
512 j_coord_offsetA = DIM*jnrA;
513 j_coord_offsetB = DIM*jnrB;
515 /* load j atom coordinates */
516 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
519 /* Calculate displacement vector */
520 dx00 = _mm_sub_pd(ix0,jx0);
521 dy00 = _mm_sub_pd(iy0,jy0);
522 dz00 = _mm_sub_pd(iz0,jz0);
524 /* Calculate squared distance and things based on it */
525 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
527 rinv00 = gmx_mm_invsqrt_pd(rsq00);
529 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
531 /* Load parameters for j particles */
532 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
533 vdwjidx0A = 2*vdwtype[jnrA+0];
534 vdwjidx0B = 2*vdwtype[jnrB+0];
536 /**************************
537 * CALCULATE INTERACTIONS *
538 **************************/
540 if (gmx_mm_any_lt(rsq00,rcutoff2))
543 r00 = _mm_mul_pd(rsq00,rinv00);
545 /* Compute parameters for interactions between i and j atoms */
546 qq00 = _mm_mul_pd(iq0,jq0);
547 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
548 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
550 /* EWALD ELECTROSTATICS */
552 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
553 ewrt = _mm_mul_pd(r00,ewtabscale);
554 ewitab = _mm_cvttpd_epi32(ewrt);
555 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
556 gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
558 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
559 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
561 /* LENNARD-JONES DISPERSION/REPULSION */
563 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
564 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
566 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
568 fscal = _mm_add_pd(felec,fvdw);
570 fscal = _mm_and_pd(fscal,cutoff_mask);
572 /* Calculate temporary vectorial force */
573 tx = _mm_mul_pd(fscal,dx00);
574 ty = _mm_mul_pd(fscal,dy00);
575 tz = _mm_mul_pd(fscal,dz00);
577 /* Update vectorial force */
578 fix0 = _mm_add_pd(fix0,tx);
579 fiy0 = _mm_add_pd(fiy0,ty);
580 fiz0 = _mm_add_pd(fiz0,tz);
582 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
586 /* Inner loop uses 46 flops */
593 j_coord_offsetA = DIM*jnrA;
595 /* load j atom coordinates */
596 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
599 /* Calculate displacement vector */
600 dx00 = _mm_sub_pd(ix0,jx0);
601 dy00 = _mm_sub_pd(iy0,jy0);
602 dz00 = _mm_sub_pd(iz0,jz0);
604 /* Calculate squared distance and things based on it */
605 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
607 rinv00 = gmx_mm_invsqrt_pd(rsq00);
609 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
611 /* Load parameters for j particles */
612 jq0 = _mm_load_sd(charge+jnrA+0);
613 vdwjidx0A = 2*vdwtype[jnrA+0];
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq00,rcutoff2))
622 r00 = _mm_mul_pd(rsq00,rinv00);
624 /* Compute parameters for interactions between i and j atoms */
625 qq00 = _mm_mul_pd(iq0,jq0);
626 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
628 /* EWALD ELECTROSTATICS */
630 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
631 ewrt = _mm_mul_pd(r00,ewtabscale);
632 ewitab = _mm_cvttpd_epi32(ewrt);
633 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
634 gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
635 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
636 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
638 /* LENNARD-JONES DISPERSION/REPULSION */
640 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
641 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
643 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
645 fscal = _mm_add_pd(felec,fvdw);
647 fscal = _mm_and_pd(fscal,cutoff_mask);
649 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
651 /* Calculate temporary vectorial force */
652 tx = _mm_mul_pd(fscal,dx00);
653 ty = _mm_mul_pd(fscal,dy00);
654 tz = _mm_mul_pd(fscal,dz00);
656 /* Update vectorial force */
657 fix0 = _mm_add_pd(fix0,tx);
658 fiy0 = _mm_add_pd(fiy0,ty);
659 fiz0 = _mm_add_pd(fiz0,tz);
661 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
665 /* Inner loop uses 46 flops */
668 /* End of innermost loop */
670 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
671 f+i_coord_offset,fshift+i_shift_offset);
673 /* Increment number of inner iterations */
674 inneriter += j_index_end - j_index_start;
676 /* Outer loop uses 7 flops */
679 /* Increment number of outer iterations */
682 /* Update outer/inner flops */
684 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*46);