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 avx_128_fma_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_avx_128_fma_double
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_avx_128_fma_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 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
90 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
91 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
92 __m128d dummy_mask,cutoff_mask;
93 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94 __m128d one = _mm_set1_pd(1.0);
95 __m128d two = _mm_set1_pd(2.0);
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 facel = _mm_set1_pd(fr->ic->epsfac);
108 charge = mdatoms->chargeA;
109 nvdwtype = fr->ntype;
111 vdwtype = mdatoms->typeA;
113 /* Avoid stupid compiler warnings */
121 /* Start outer loop over neighborlists */
122 for(iidx=0; iidx<nri; iidx++)
124 /* Load shift vector for this list */
125 i_shift_offset = DIM*shiftidx[iidx];
127 /* Load limits for loop over neighbors */
128 j_index_start = jindex[iidx];
129 j_index_end = jindex[iidx+1];
131 /* Get outer coordinate index */
133 i_coord_offset = DIM*inr;
135 /* Load i particle coords and add shift vector */
136 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
138 fix0 = _mm_setzero_pd();
139 fiy0 = _mm_setzero_pd();
140 fiz0 = _mm_setzero_pd();
142 /* Load parameters for i particles */
143 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
144 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
146 /* Reset potential sums */
147 velecsum = _mm_setzero_pd();
148 vvdwsum = _mm_setzero_pd();
150 /* Start inner kernel loop */
151 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
154 /* Get j neighbor index, and coordinate index */
157 j_coord_offsetA = DIM*jnrA;
158 j_coord_offsetB = DIM*jnrB;
160 /* load j atom coordinates */
161 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
164 /* Calculate displacement vector */
165 dx00 = _mm_sub_pd(ix0,jx0);
166 dy00 = _mm_sub_pd(iy0,jy0);
167 dz00 = _mm_sub_pd(iz0,jz0);
169 /* Calculate squared distance and things based on it */
170 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
172 rinv00 = avx128fma_invsqrt_d(rsq00);
174 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
176 /* Load parameters for j particles */
177 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
178 vdwjidx0A = 2*vdwtype[jnrA+0];
179 vdwjidx0B = 2*vdwtype[jnrB+0];
181 /**************************
182 * CALCULATE INTERACTIONS *
183 **************************/
185 /* Compute parameters for interactions between i and j atoms */
186 qq00 = _mm_mul_pd(iq0,jq0);
187 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
188 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
190 /* COULOMB ELECTROSTATICS */
191 velec = _mm_mul_pd(qq00,rinv00);
192 felec = _mm_mul_pd(velec,rinvsq00);
194 /* LENNARD-JONES DISPERSION/REPULSION */
196 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
197 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
198 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
199 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
200 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
202 /* Update potential sum for this i atom from the interaction with this j atom. */
203 velecsum = _mm_add_pd(velecsum,velec);
204 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
206 fscal = _mm_add_pd(felec,fvdw);
208 /* Update vectorial force */
209 fix0 = _mm_macc_pd(dx00,fscal,fix0);
210 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
211 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
213 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
214 _mm_mul_pd(dx00,fscal),
215 _mm_mul_pd(dy00,fscal),
216 _mm_mul_pd(dz00,fscal));
218 /* Inner loop uses 43 flops */
225 j_coord_offsetA = DIM*jnrA;
227 /* load j atom coordinates */
228 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
231 /* Calculate displacement vector */
232 dx00 = _mm_sub_pd(ix0,jx0);
233 dy00 = _mm_sub_pd(iy0,jy0);
234 dz00 = _mm_sub_pd(iz0,jz0);
236 /* Calculate squared distance and things based on it */
237 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
239 rinv00 = avx128fma_invsqrt_d(rsq00);
241 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
243 /* Load parameters for j particles */
244 jq0 = _mm_load_sd(charge+jnrA+0);
245 vdwjidx0A = 2*vdwtype[jnrA+0];
247 /**************************
248 * CALCULATE INTERACTIONS *
249 **************************/
251 /* Compute parameters for interactions between i and j atoms */
252 qq00 = _mm_mul_pd(iq0,jq0);
253 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
255 /* COULOMB ELECTROSTATICS */
256 velec = _mm_mul_pd(qq00,rinv00);
257 felec = _mm_mul_pd(velec,rinvsq00);
259 /* LENNARD-JONES DISPERSION/REPULSION */
261 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
262 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
263 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
264 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
265 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
267 /* Update potential sum for this i atom from the interaction with this j atom. */
268 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
269 velecsum = _mm_add_pd(velecsum,velec);
270 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
271 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
273 fscal = _mm_add_pd(felec,fvdw);
275 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
277 /* Update vectorial force */
278 fix0 = _mm_macc_pd(dx00,fscal,fix0);
279 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
280 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
282 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
283 _mm_mul_pd(dx00,fscal),
284 _mm_mul_pd(dy00,fscal),
285 _mm_mul_pd(dz00,fscal));
287 /* Inner loop uses 43 flops */
290 /* End of innermost loop */
292 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
293 f+i_coord_offset,fshift+i_shift_offset);
296 /* Update potential energies */
297 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
298 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
300 /* Increment number of inner iterations */
301 inneriter += j_index_end - j_index_start;
303 /* Outer loop uses 9 flops */
306 /* Increment number of outer iterations */
309 /* Update outer/inner flops */
311 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*43);
314 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_avx_128_fma_double
315 * Electrostatics interaction: Coulomb
316 * VdW interaction: LennardJones
317 * Geometry: Particle-Particle
318 * Calculate force/pot: Force
321 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_avx_128_fma_double
322 (t_nblist * gmx_restrict nlist,
323 rvec * gmx_restrict xx,
324 rvec * gmx_restrict ff,
325 struct t_forcerec * gmx_restrict fr,
326 t_mdatoms * gmx_restrict mdatoms,
327 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
328 t_nrnb * gmx_restrict nrnb)
330 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
331 * just 0 for non-waters.
332 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
333 * jnr indices corresponding to data put in the four positions in the SIMD register.
335 int i_shift_offset,i_coord_offset,outeriter,inneriter;
336 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
338 int j_coord_offsetA,j_coord_offsetB;
339 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
341 real *shiftvec,*fshift,*x,*f;
342 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
344 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
345 int vdwjidx0A,vdwjidx0B;
346 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
347 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
348 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
351 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
354 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
355 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
356 __m128d dummy_mask,cutoff_mask;
357 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
358 __m128d one = _mm_set1_pd(1.0);
359 __m128d two = _mm_set1_pd(2.0);
365 jindex = nlist->jindex;
367 shiftidx = nlist->shift;
369 shiftvec = fr->shift_vec[0];
370 fshift = fr->fshift[0];
371 facel = _mm_set1_pd(fr->ic->epsfac);
372 charge = mdatoms->chargeA;
373 nvdwtype = fr->ntype;
375 vdwtype = mdatoms->typeA;
377 /* Avoid stupid compiler warnings */
385 /* Start outer loop over neighborlists */
386 for(iidx=0; iidx<nri; iidx++)
388 /* Load shift vector for this list */
389 i_shift_offset = DIM*shiftidx[iidx];
391 /* Load limits for loop over neighbors */
392 j_index_start = jindex[iidx];
393 j_index_end = jindex[iidx+1];
395 /* Get outer coordinate index */
397 i_coord_offset = DIM*inr;
399 /* Load i particle coords and add shift vector */
400 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
402 fix0 = _mm_setzero_pd();
403 fiy0 = _mm_setzero_pd();
404 fiz0 = _mm_setzero_pd();
406 /* Load parameters for i particles */
407 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
408 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
410 /* Start inner kernel loop */
411 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
414 /* Get j neighbor index, and coordinate index */
417 j_coord_offsetA = DIM*jnrA;
418 j_coord_offsetB = DIM*jnrB;
420 /* load j atom coordinates */
421 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
424 /* Calculate displacement vector */
425 dx00 = _mm_sub_pd(ix0,jx0);
426 dy00 = _mm_sub_pd(iy0,jy0);
427 dz00 = _mm_sub_pd(iz0,jz0);
429 /* Calculate squared distance and things based on it */
430 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
432 rinv00 = avx128fma_invsqrt_d(rsq00);
434 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
436 /* Load parameters for j particles */
437 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
438 vdwjidx0A = 2*vdwtype[jnrA+0];
439 vdwjidx0B = 2*vdwtype[jnrB+0];
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 /* Compute parameters for interactions between i and j atoms */
446 qq00 = _mm_mul_pd(iq0,jq0);
447 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
448 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
450 /* COULOMB ELECTROSTATICS */
451 velec = _mm_mul_pd(qq00,rinv00);
452 felec = _mm_mul_pd(velec,rinvsq00);
454 /* LENNARD-JONES DISPERSION/REPULSION */
456 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
457 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
459 fscal = _mm_add_pd(felec,fvdw);
461 /* Update vectorial force */
462 fix0 = _mm_macc_pd(dx00,fscal,fix0);
463 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
464 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
466 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
467 _mm_mul_pd(dx00,fscal),
468 _mm_mul_pd(dy00,fscal),
469 _mm_mul_pd(dz00,fscal));
471 /* Inner loop uses 37 flops */
478 j_coord_offsetA = DIM*jnrA;
480 /* load j atom coordinates */
481 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
484 /* Calculate displacement vector */
485 dx00 = _mm_sub_pd(ix0,jx0);
486 dy00 = _mm_sub_pd(iy0,jy0);
487 dz00 = _mm_sub_pd(iz0,jz0);
489 /* Calculate squared distance and things based on it */
490 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
492 rinv00 = avx128fma_invsqrt_d(rsq00);
494 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
496 /* Load parameters for j particles */
497 jq0 = _mm_load_sd(charge+jnrA+0);
498 vdwjidx0A = 2*vdwtype[jnrA+0];
500 /**************************
501 * CALCULATE INTERACTIONS *
502 **************************/
504 /* Compute parameters for interactions between i and j atoms */
505 qq00 = _mm_mul_pd(iq0,jq0);
506 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
508 /* COULOMB ELECTROSTATICS */
509 velec = _mm_mul_pd(qq00,rinv00);
510 felec = _mm_mul_pd(velec,rinvsq00);
512 /* LENNARD-JONES DISPERSION/REPULSION */
514 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
515 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
517 fscal = _mm_add_pd(felec,fvdw);
519 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
521 /* Update vectorial force */
522 fix0 = _mm_macc_pd(dx00,fscal,fix0);
523 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
524 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
526 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
527 _mm_mul_pd(dx00,fscal),
528 _mm_mul_pd(dy00,fscal),
529 _mm_mul_pd(dz00,fscal));
531 /* Inner loop uses 37 flops */
534 /* End of innermost loop */
536 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
537 f+i_coord_offset,fshift+i_shift_offset);
539 /* Increment number of inner iterations */
540 inneriter += j_index_end - j_index_start;
542 /* Outer loop uses 7 flops */
545 /* Increment number of outer iterations */
548 /* Update outer/inner flops */
550 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*37);