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 "types/simple.h"
44 #include "gromacs/math/vec.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_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwLJSh_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 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
91 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
92 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
94 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
96 __m128d dummy_mask,cutoff_mask;
97 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
98 __m128d one = _mm_set1_pd(1.0);
99 __m128d two = _mm_set1_pd(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 facel = _mm_set1_pd(fr->epsfac);
112 charge = mdatoms->chargeA;
113 nvdwtype = fr->ntype;
115 vdwtype = mdatoms->typeA;
117 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
118 ewtab = fr->ic->tabq_coul_FDV0;
119 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
120 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
122 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123 rcutoff_scalar = fr->rcoulomb;
124 rcutoff = _mm_set1_pd(rcutoff_scalar);
125 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
127 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
128 rvdw = _mm_set1_pd(fr->rvdw);
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 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
163 /* Reset potential sums */
164 velecsum = _mm_setzero_pd();
165 vvdwsum = _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 = gmx_mm_invsqrt_pd(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 vdwjidx0A = 2*vdwtype[jnrA+0];
196 vdwjidx0B = 2*vdwtype[jnrB+0];
198 /**************************
199 * CALCULATE INTERACTIONS *
200 **************************/
202 if (gmx_mm_any_lt(rsq00,rcutoff2))
205 r00 = _mm_mul_pd(rsq00,rinv00);
207 /* Compute parameters for interactions between i and j atoms */
208 qq00 = _mm_mul_pd(iq0,jq0);
209 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
210 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
212 /* EWALD ELECTROSTATICS */
214 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
215 ewrt = _mm_mul_pd(r00,ewtabscale);
216 ewitab = _mm_cvttpd_epi32(ewrt);
218 eweps = _mm_frcz_pd(ewrt);
220 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
222 twoeweps = _mm_add_pd(eweps,eweps);
223 ewitab = _mm_slli_epi32(ewitab,2);
224 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
225 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
226 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
227 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
228 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
229 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
230 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
231 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
232 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
233 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
235 /* LENNARD-JONES DISPERSION/REPULSION */
237 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
238 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
239 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
240 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
241 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
242 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
244 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
246 /* Update potential sum for this i atom from the interaction with this j atom. */
247 velec = _mm_and_pd(velec,cutoff_mask);
248 velecsum = _mm_add_pd(velecsum,velec);
249 vvdw = _mm_and_pd(vvdw,cutoff_mask);
250 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
252 fscal = _mm_add_pd(felec,fvdw);
254 fscal = _mm_and_pd(fscal,cutoff_mask);
256 /* Update vectorial force */
257 fix0 = _mm_macc_pd(dx00,fscal,fix0);
258 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
259 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
261 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
262 _mm_mul_pd(dx00,fscal),
263 _mm_mul_pd(dy00,fscal),
264 _mm_mul_pd(dz00,fscal));
268 /* Inner loop uses 67 flops */
275 j_coord_offsetA = DIM*jnrA;
277 /* load j atom coordinates */
278 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
281 /* Calculate displacement vector */
282 dx00 = _mm_sub_pd(ix0,jx0);
283 dy00 = _mm_sub_pd(iy0,jy0);
284 dz00 = _mm_sub_pd(iz0,jz0);
286 /* Calculate squared distance and things based on it */
287 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
289 rinv00 = gmx_mm_invsqrt_pd(rsq00);
291 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
293 /* Load parameters for j particles */
294 jq0 = _mm_load_sd(charge+jnrA+0);
295 vdwjidx0A = 2*vdwtype[jnrA+0];
297 /**************************
298 * CALCULATE INTERACTIONS *
299 **************************/
301 if (gmx_mm_any_lt(rsq00,rcutoff2))
304 r00 = _mm_mul_pd(rsq00,rinv00);
306 /* Compute parameters for interactions between i and j atoms */
307 qq00 = _mm_mul_pd(iq0,jq0);
308 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
310 /* EWALD ELECTROSTATICS */
312 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
313 ewrt = _mm_mul_pd(r00,ewtabscale);
314 ewitab = _mm_cvttpd_epi32(ewrt);
316 eweps = _mm_frcz_pd(ewrt);
318 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
320 twoeweps = _mm_add_pd(eweps,eweps);
321 ewitab = _mm_slli_epi32(ewitab,2);
322 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
323 ewtabD = _mm_setzero_pd();
324 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
325 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
326 ewtabFn = _mm_setzero_pd();
327 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
328 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
329 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
330 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
331 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
333 /* LENNARD-JONES DISPERSION/REPULSION */
335 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
336 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
337 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
338 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
339 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
340 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
342 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
344 /* Update potential sum for this i atom from the interaction with this j atom. */
345 velec = _mm_and_pd(velec,cutoff_mask);
346 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
347 velecsum = _mm_add_pd(velecsum,velec);
348 vvdw = _mm_and_pd(vvdw,cutoff_mask);
349 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
350 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
352 fscal = _mm_add_pd(felec,fvdw);
354 fscal = _mm_and_pd(fscal,cutoff_mask);
356 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
358 /* Update vectorial force */
359 fix0 = _mm_macc_pd(dx00,fscal,fix0);
360 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
361 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
363 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
364 _mm_mul_pd(dx00,fscal),
365 _mm_mul_pd(dy00,fscal),
366 _mm_mul_pd(dz00,fscal));
370 /* Inner loop uses 67 flops */
373 /* End of innermost loop */
375 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
376 f+i_coord_offset,fshift+i_shift_offset);
379 /* Update potential energies */
380 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
381 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
383 /* Increment number of inner iterations */
384 inneriter += j_index_end - j_index_start;
386 /* Outer loop uses 9 flops */
389 /* Increment number of outer iterations */
392 /* Update outer/inner flops */
394 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*67);
397 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
398 * Electrostatics interaction: Ewald
399 * VdW interaction: LennardJones
400 * Geometry: Particle-Particle
401 * Calculate force/pot: Force
404 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
405 (t_nblist * gmx_restrict nlist,
406 rvec * gmx_restrict xx,
407 rvec * gmx_restrict ff,
408 t_forcerec * gmx_restrict fr,
409 t_mdatoms * gmx_restrict mdatoms,
410 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
411 t_nrnb * gmx_restrict nrnb)
413 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
414 * just 0 for non-waters.
415 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
416 * jnr indices corresponding to data put in the four positions in the SIMD register.
418 int i_shift_offset,i_coord_offset,outeriter,inneriter;
419 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
421 int j_coord_offsetA,j_coord_offsetB;
422 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
424 real *shiftvec,*fshift,*x,*f;
425 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
427 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
428 int vdwjidx0A,vdwjidx0B;
429 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
430 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
431 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
434 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
437 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
438 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
440 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
442 __m128d dummy_mask,cutoff_mask;
443 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
444 __m128d one = _mm_set1_pd(1.0);
445 __m128d two = _mm_set1_pd(2.0);
451 jindex = nlist->jindex;
453 shiftidx = nlist->shift;
455 shiftvec = fr->shift_vec[0];
456 fshift = fr->fshift[0];
457 facel = _mm_set1_pd(fr->epsfac);
458 charge = mdatoms->chargeA;
459 nvdwtype = fr->ntype;
461 vdwtype = mdatoms->typeA;
463 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
464 ewtab = fr->ic->tabq_coul_F;
465 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
466 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
468 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
469 rcutoff_scalar = fr->rcoulomb;
470 rcutoff = _mm_set1_pd(rcutoff_scalar);
471 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
473 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
474 rvdw = _mm_set1_pd(fr->rvdw);
476 /* Avoid stupid compiler warnings */
484 /* Start outer loop over neighborlists */
485 for(iidx=0; iidx<nri; iidx++)
487 /* Load shift vector for this list */
488 i_shift_offset = DIM*shiftidx[iidx];
490 /* Load limits for loop over neighbors */
491 j_index_start = jindex[iidx];
492 j_index_end = jindex[iidx+1];
494 /* Get outer coordinate index */
496 i_coord_offset = DIM*inr;
498 /* Load i particle coords and add shift vector */
499 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
501 fix0 = _mm_setzero_pd();
502 fiy0 = _mm_setzero_pd();
503 fiz0 = _mm_setzero_pd();
505 /* Load parameters for i particles */
506 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
507 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
509 /* Start inner kernel loop */
510 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
513 /* Get j neighbor index, and coordinate index */
516 j_coord_offsetA = DIM*jnrA;
517 j_coord_offsetB = DIM*jnrB;
519 /* load j atom coordinates */
520 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
523 /* Calculate displacement vector */
524 dx00 = _mm_sub_pd(ix0,jx0);
525 dy00 = _mm_sub_pd(iy0,jy0);
526 dz00 = _mm_sub_pd(iz0,jz0);
528 /* Calculate squared distance and things based on it */
529 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
531 rinv00 = gmx_mm_invsqrt_pd(rsq00);
533 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
535 /* Load parameters for j particles */
536 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
537 vdwjidx0A = 2*vdwtype[jnrA+0];
538 vdwjidx0B = 2*vdwtype[jnrB+0];
540 /**************************
541 * CALCULATE INTERACTIONS *
542 **************************/
544 if (gmx_mm_any_lt(rsq00,rcutoff2))
547 r00 = _mm_mul_pd(rsq00,rinv00);
549 /* Compute parameters for interactions between i and j atoms */
550 qq00 = _mm_mul_pd(iq0,jq0);
551 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
552 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
554 /* EWALD ELECTROSTATICS */
556 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
557 ewrt = _mm_mul_pd(r00,ewtabscale);
558 ewitab = _mm_cvttpd_epi32(ewrt);
560 eweps = _mm_frcz_pd(ewrt);
562 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
564 twoeweps = _mm_add_pd(eweps,eweps);
565 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
567 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
568 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
570 /* LENNARD-JONES DISPERSION/REPULSION */
572 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
573 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
575 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
577 fscal = _mm_add_pd(felec,fvdw);
579 fscal = _mm_and_pd(fscal,cutoff_mask);
581 /* Update vectorial force */
582 fix0 = _mm_macc_pd(dx00,fscal,fix0);
583 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
584 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
586 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
587 _mm_mul_pd(dx00,fscal),
588 _mm_mul_pd(dy00,fscal),
589 _mm_mul_pd(dz00,fscal));
593 /* Inner loop uses 49 flops */
600 j_coord_offsetA = DIM*jnrA;
602 /* load j atom coordinates */
603 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
606 /* Calculate displacement vector */
607 dx00 = _mm_sub_pd(ix0,jx0);
608 dy00 = _mm_sub_pd(iy0,jy0);
609 dz00 = _mm_sub_pd(iz0,jz0);
611 /* Calculate squared distance and things based on it */
612 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
614 rinv00 = gmx_mm_invsqrt_pd(rsq00);
616 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
618 /* Load parameters for j particles */
619 jq0 = _mm_load_sd(charge+jnrA+0);
620 vdwjidx0A = 2*vdwtype[jnrA+0];
622 /**************************
623 * CALCULATE INTERACTIONS *
624 **************************/
626 if (gmx_mm_any_lt(rsq00,rcutoff2))
629 r00 = _mm_mul_pd(rsq00,rinv00);
631 /* Compute parameters for interactions between i and j atoms */
632 qq00 = _mm_mul_pd(iq0,jq0);
633 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
635 /* EWALD ELECTROSTATICS */
637 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
638 ewrt = _mm_mul_pd(r00,ewtabscale);
639 ewitab = _mm_cvttpd_epi32(ewrt);
641 eweps = _mm_frcz_pd(ewrt);
643 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
645 twoeweps = _mm_add_pd(eweps,eweps);
646 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
647 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
648 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
650 /* LENNARD-JONES DISPERSION/REPULSION */
652 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
653 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
655 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
657 fscal = _mm_add_pd(felec,fvdw);
659 fscal = _mm_and_pd(fscal,cutoff_mask);
661 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
663 /* Update vectorial force */
664 fix0 = _mm_macc_pd(dx00,fscal,fix0);
665 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
666 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
668 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
669 _mm_mul_pd(dx00,fscal),
670 _mm_mul_pd(dy00,fscal),
671 _mm_mul_pd(dz00,fscal));
675 /* Inner loop uses 49 flops */
678 /* End of innermost loop */
680 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
681 f+i_coord_offset,fshift+i_shift_offset);
683 /* Increment number of inner iterations */
684 inneriter += j_index_end - j_index_start;
686 /* Outer loop uses 7 flops */
689 /* Increment number of outer iterations */
692 /* Update outer/inner flops */
694 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*49);