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.
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_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_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_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 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,twoeweps,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);
220 eweps = _mm_frcz_pd(ewrt);
222 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
224 twoeweps = _mm_add_pd(eweps,eweps);
225 ewitab = _mm_slli_epi32(ewitab,2);
226 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
227 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
228 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
229 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
230 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
231 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
232 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
233 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
234 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
235 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
237 /* LENNARD-JONES DISPERSION/REPULSION */
239 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
240 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
241 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
242 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
243 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
244 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
246 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
248 /* Update potential sum for this i atom from the interaction with this j atom. */
249 velec = _mm_and_pd(velec,cutoff_mask);
250 velecsum = _mm_add_pd(velecsum,velec);
251 vvdw = _mm_and_pd(vvdw,cutoff_mask);
252 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
254 fscal = _mm_add_pd(felec,fvdw);
256 fscal = _mm_and_pd(fscal,cutoff_mask);
258 /* Update vectorial force */
259 fix0 = _mm_macc_pd(dx00,fscal,fix0);
260 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
261 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
263 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
264 _mm_mul_pd(dx00,fscal),
265 _mm_mul_pd(dy00,fscal),
266 _mm_mul_pd(dz00,fscal));
270 /* Inner loop uses 67 flops */
277 j_coord_offsetA = DIM*jnrA;
279 /* load j atom coordinates */
280 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
283 /* Calculate displacement vector */
284 dx00 = _mm_sub_pd(ix0,jx0);
285 dy00 = _mm_sub_pd(iy0,jy0);
286 dz00 = _mm_sub_pd(iz0,jz0);
288 /* Calculate squared distance and things based on it */
289 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
291 rinv00 = gmx_mm_invsqrt_pd(rsq00);
293 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
295 /* Load parameters for j particles */
296 jq0 = _mm_load_sd(charge+jnrA+0);
297 vdwjidx0A = 2*vdwtype[jnrA+0];
299 /**************************
300 * CALCULATE INTERACTIONS *
301 **************************/
303 if (gmx_mm_any_lt(rsq00,rcutoff2))
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 /* EWALD ELECTROSTATICS */
314 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
315 ewrt = _mm_mul_pd(r00,ewtabscale);
316 ewitab = _mm_cvttpd_epi32(ewrt);
318 eweps = _mm_frcz_pd(ewrt);
320 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
322 twoeweps = _mm_add_pd(eweps,eweps);
323 ewitab = _mm_slli_epi32(ewitab,2);
324 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
325 ewtabD = _mm_setzero_pd();
326 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
327 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
328 ewtabFn = _mm_setzero_pd();
329 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
330 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
331 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
332 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
333 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
335 /* LENNARD-JONES DISPERSION/REPULSION */
337 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
338 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
339 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
340 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
341 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
342 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
344 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
346 /* Update potential sum for this i atom from the interaction with this j atom. */
347 velec = _mm_and_pd(velec,cutoff_mask);
348 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
349 velecsum = _mm_add_pd(velecsum,velec);
350 vvdw = _mm_and_pd(vvdw,cutoff_mask);
351 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
352 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
354 fscal = _mm_add_pd(felec,fvdw);
356 fscal = _mm_and_pd(fscal,cutoff_mask);
358 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
360 /* Update vectorial force */
361 fix0 = _mm_macc_pd(dx00,fscal,fix0);
362 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
363 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
365 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
366 _mm_mul_pd(dx00,fscal),
367 _mm_mul_pd(dy00,fscal),
368 _mm_mul_pd(dz00,fscal));
372 /* Inner loop uses 67 flops */
375 /* End of innermost loop */
377 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
378 f+i_coord_offset,fshift+i_shift_offset);
381 /* Update potential energies */
382 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
383 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
385 /* Increment number of inner iterations */
386 inneriter += j_index_end - j_index_start;
388 /* Outer loop uses 9 flops */
391 /* Increment number of outer iterations */
394 /* Update outer/inner flops */
396 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*67);
399 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
400 * Electrostatics interaction: Ewald
401 * VdW interaction: LennardJones
402 * Geometry: Particle-Particle
403 * Calculate force/pot: Force
406 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
407 (t_nblist * gmx_restrict nlist,
408 rvec * gmx_restrict xx,
409 rvec * gmx_restrict ff,
410 t_forcerec * gmx_restrict fr,
411 t_mdatoms * gmx_restrict mdatoms,
412 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
413 t_nrnb * gmx_restrict nrnb)
415 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
416 * just 0 for non-waters.
417 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
418 * jnr indices corresponding to data put in the four positions in the SIMD register.
420 int i_shift_offset,i_coord_offset,outeriter,inneriter;
421 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
423 int j_coord_offsetA,j_coord_offsetB;
424 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
426 real *shiftvec,*fshift,*x,*f;
427 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
429 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
430 int vdwjidx0A,vdwjidx0B;
431 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
432 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
433 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
436 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
439 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
440 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
442 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
444 __m128d dummy_mask,cutoff_mask;
445 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
446 __m128d one = _mm_set1_pd(1.0);
447 __m128d two = _mm_set1_pd(2.0);
453 jindex = nlist->jindex;
455 shiftidx = nlist->shift;
457 shiftvec = fr->shift_vec[0];
458 fshift = fr->fshift[0];
459 facel = _mm_set1_pd(fr->epsfac);
460 charge = mdatoms->chargeA;
461 nvdwtype = fr->ntype;
463 vdwtype = mdatoms->typeA;
465 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
466 ewtab = fr->ic->tabq_coul_F;
467 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
468 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
470 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
471 rcutoff_scalar = fr->rcoulomb;
472 rcutoff = _mm_set1_pd(rcutoff_scalar);
473 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
475 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
476 rvdw = _mm_set1_pd(fr->rvdw);
478 /* Avoid stupid compiler warnings */
486 /* Start outer loop over neighborlists */
487 for(iidx=0; iidx<nri; iidx++)
489 /* Load shift vector for this list */
490 i_shift_offset = DIM*shiftidx[iidx];
492 /* Load limits for loop over neighbors */
493 j_index_start = jindex[iidx];
494 j_index_end = jindex[iidx+1];
496 /* Get outer coordinate index */
498 i_coord_offset = DIM*inr;
500 /* Load i particle coords and add shift vector */
501 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
503 fix0 = _mm_setzero_pd();
504 fiy0 = _mm_setzero_pd();
505 fiz0 = _mm_setzero_pd();
507 /* Load parameters for i particles */
508 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
509 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
511 /* Start inner kernel loop */
512 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
515 /* Get j neighbor index, and coordinate index */
518 j_coord_offsetA = DIM*jnrA;
519 j_coord_offsetB = DIM*jnrB;
521 /* load j atom coordinates */
522 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
525 /* Calculate displacement vector */
526 dx00 = _mm_sub_pd(ix0,jx0);
527 dy00 = _mm_sub_pd(iy0,jy0);
528 dz00 = _mm_sub_pd(iz0,jz0);
530 /* Calculate squared distance and things based on it */
531 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
533 rinv00 = gmx_mm_invsqrt_pd(rsq00);
535 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
537 /* Load parameters for j particles */
538 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
539 vdwjidx0A = 2*vdwtype[jnrA+0];
540 vdwjidx0B = 2*vdwtype[jnrB+0];
542 /**************************
543 * CALCULATE INTERACTIONS *
544 **************************/
546 if (gmx_mm_any_lt(rsq00,rcutoff2))
549 r00 = _mm_mul_pd(rsq00,rinv00);
551 /* Compute parameters for interactions between i and j atoms */
552 qq00 = _mm_mul_pd(iq0,jq0);
553 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
554 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
556 /* EWALD ELECTROSTATICS */
558 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
559 ewrt = _mm_mul_pd(r00,ewtabscale);
560 ewitab = _mm_cvttpd_epi32(ewrt);
562 eweps = _mm_frcz_pd(ewrt);
564 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
566 twoeweps = _mm_add_pd(eweps,eweps);
567 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
569 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
570 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
572 /* LENNARD-JONES DISPERSION/REPULSION */
574 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
575 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
577 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
579 fscal = _mm_add_pd(felec,fvdw);
581 fscal = _mm_and_pd(fscal,cutoff_mask);
583 /* Update vectorial force */
584 fix0 = _mm_macc_pd(dx00,fscal,fix0);
585 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
586 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
588 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
589 _mm_mul_pd(dx00,fscal),
590 _mm_mul_pd(dy00,fscal),
591 _mm_mul_pd(dz00,fscal));
595 /* Inner loop uses 49 flops */
602 j_coord_offsetA = DIM*jnrA;
604 /* load j atom coordinates */
605 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
608 /* Calculate displacement vector */
609 dx00 = _mm_sub_pd(ix0,jx0);
610 dy00 = _mm_sub_pd(iy0,jy0);
611 dz00 = _mm_sub_pd(iz0,jz0);
613 /* Calculate squared distance and things based on it */
614 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
616 rinv00 = gmx_mm_invsqrt_pd(rsq00);
618 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
620 /* Load parameters for j particles */
621 jq0 = _mm_load_sd(charge+jnrA+0);
622 vdwjidx0A = 2*vdwtype[jnrA+0];
624 /**************************
625 * CALCULATE INTERACTIONS *
626 **************************/
628 if (gmx_mm_any_lt(rsq00,rcutoff2))
631 r00 = _mm_mul_pd(rsq00,rinv00);
633 /* Compute parameters for interactions between i and j atoms */
634 qq00 = _mm_mul_pd(iq0,jq0);
635 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
637 /* EWALD ELECTROSTATICS */
639 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
640 ewrt = _mm_mul_pd(r00,ewtabscale);
641 ewitab = _mm_cvttpd_epi32(ewrt);
643 eweps = _mm_frcz_pd(ewrt);
645 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
647 twoeweps = _mm_add_pd(eweps,eweps);
648 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
649 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
650 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
652 /* LENNARD-JONES DISPERSION/REPULSION */
654 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
655 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
657 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
659 fscal = _mm_add_pd(felec,fvdw);
661 fscal = _mm_and_pd(fscal,cutoff_mask);
663 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
665 /* Update vectorial force */
666 fix0 = _mm_macc_pd(dx00,fscal,fix0);
667 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
668 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
670 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
671 _mm_mul_pd(dx00,fscal),
672 _mm_mul_pd(dy00,fscal),
673 _mm_mul_pd(dz00,fscal));
677 /* Inner loop uses 49 flops */
680 /* End of innermost loop */
682 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
683 f+i_coord_offset,fshift+i_shift_offset);
685 /* Increment number of inner iterations */
686 inneriter += j_index_end - j_index_start;
688 /* Outer loop uses 7 flops */
691 /* Increment number of outer iterations */
694 /* Update outer/inner flops */
696 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*49);