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_ElecNone_VdwLJSh_GeomP1P1_VF_avx_128_fma_double
54 * Electrostatics interaction: None
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecNone_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;
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);
93 __m128d dummy_mask,cutoff_mask;
94 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
95 __m128d one = _mm_set1_pd(1.0);
96 __m128d two = _mm_set1_pd(2.0);
102 jindex = nlist->jindex;
104 shiftidx = nlist->shift;
106 shiftvec = fr->shift_vec[0];
107 fshift = fr->fshift[0];
108 nvdwtype = fr->ntype;
110 vdwtype = mdatoms->typeA;
112 rcutoff_scalar = fr->rvdw;
113 rcutoff = _mm_set1_pd(rcutoff_scalar);
114 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
116 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
117 rvdw = _mm_set1_pd(fr->rvdw);
119 /* Avoid stupid compiler warnings */
127 /* Start outer loop over neighborlists */
128 for(iidx=0; iidx<nri; iidx++)
130 /* Load shift vector for this list */
131 i_shift_offset = DIM*shiftidx[iidx];
133 /* Load limits for loop over neighbors */
134 j_index_start = jindex[iidx];
135 j_index_end = jindex[iidx+1];
137 /* Get outer coordinate index */
139 i_coord_offset = DIM*inr;
141 /* Load i particle coords and add shift vector */
142 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
144 fix0 = _mm_setzero_pd();
145 fiy0 = _mm_setzero_pd();
146 fiz0 = _mm_setzero_pd();
148 /* Load parameters for i particles */
149 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
151 /* Reset potential sums */
152 vvdwsum = _mm_setzero_pd();
154 /* Start inner kernel loop */
155 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
158 /* Get j neighbor index, and coordinate index */
161 j_coord_offsetA = DIM*jnrA;
162 j_coord_offsetB = DIM*jnrB;
164 /* load j atom coordinates */
165 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
168 /* Calculate displacement vector */
169 dx00 = _mm_sub_pd(ix0,jx0);
170 dy00 = _mm_sub_pd(iy0,jy0);
171 dz00 = _mm_sub_pd(iz0,jz0);
173 /* Calculate squared distance and things based on it */
174 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
176 rinvsq00 = gmx_mm_inv_pd(rsq00);
178 /* Load parameters for j particles */
179 vdwjidx0A = 2*vdwtype[jnrA+0];
180 vdwjidx0B = 2*vdwtype[jnrB+0];
182 /**************************
183 * CALCULATE INTERACTIONS *
184 **************************/
186 if (gmx_mm_any_lt(rsq00,rcutoff2))
189 /* Compute parameters for interactions between i and j atoms */
190 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
191 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
193 /* LENNARD-JONES DISPERSION/REPULSION */
195 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
196 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
197 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
198 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
199 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
200 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
202 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
204 /* Update potential sum for this i atom from the interaction with this j atom. */
205 vvdw = _mm_and_pd(vvdw,cutoff_mask);
206 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
210 fscal = _mm_and_pd(fscal,cutoff_mask);
212 /* Update vectorial force */
213 fix0 = _mm_macc_pd(dx00,fscal,fix0);
214 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
215 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
217 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
218 _mm_mul_pd(dx00,fscal),
219 _mm_mul_pd(dy00,fscal),
220 _mm_mul_pd(dz00,fscal));
224 /* Inner loop uses 44 flops */
231 j_coord_offsetA = DIM*jnrA;
233 /* load j atom coordinates */
234 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
237 /* Calculate displacement vector */
238 dx00 = _mm_sub_pd(ix0,jx0);
239 dy00 = _mm_sub_pd(iy0,jy0);
240 dz00 = _mm_sub_pd(iz0,jz0);
242 /* Calculate squared distance and things based on it */
243 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
245 rinvsq00 = gmx_mm_inv_pd(rsq00);
247 /* Load parameters for j particles */
248 vdwjidx0A = 2*vdwtype[jnrA+0];
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
254 if (gmx_mm_any_lt(rsq00,rcutoff2))
257 /* Compute parameters for interactions between i and j atoms */
258 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
260 /* LENNARD-JONES DISPERSION/REPULSION */
262 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
263 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
264 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
265 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
266 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
267 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
269 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
271 /* Update potential sum for this i atom from the interaction with this j atom. */
272 vvdw = _mm_and_pd(vvdw,cutoff_mask);
273 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
274 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
278 fscal = _mm_and_pd(fscal,cutoff_mask);
280 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
282 /* Update vectorial force */
283 fix0 = _mm_macc_pd(dx00,fscal,fix0);
284 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
285 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
287 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
288 _mm_mul_pd(dx00,fscal),
289 _mm_mul_pd(dy00,fscal),
290 _mm_mul_pd(dz00,fscal));
294 /* Inner loop uses 44 flops */
297 /* End of innermost loop */
299 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
300 f+i_coord_offset,fshift+i_shift_offset);
303 /* Update potential energies */
304 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
306 /* Increment number of inner iterations */
307 inneriter += j_index_end - j_index_start;
309 /* Outer loop uses 7 flops */
312 /* Increment number of outer iterations */
315 /* Update outer/inner flops */
317 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*44);
320 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_avx_128_fma_double
321 * Electrostatics interaction: None
322 * VdW interaction: LennardJones
323 * Geometry: Particle-Particle
324 * Calculate force/pot: Force
327 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_avx_128_fma_double
328 (t_nblist * gmx_restrict nlist,
329 rvec * gmx_restrict xx,
330 rvec * gmx_restrict ff,
331 t_forcerec * gmx_restrict fr,
332 t_mdatoms * gmx_restrict mdatoms,
333 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
334 t_nrnb * gmx_restrict nrnb)
336 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
337 * just 0 for non-waters.
338 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
339 * jnr indices corresponding to data put in the four positions in the SIMD register.
341 int i_shift_offset,i_coord_offset,outeriter,inneriter;
342 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
344 int j_coord_offsetA,j_coord_offsetB;
345 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
347 real *shiftvec,*fshift,*x,*f;
348 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
350 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
351 int vdwjidx0A,vdwjidx0B;
352 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
353 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
355 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
358 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
359 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
360 __m128d dummy_mask,cutoff_mask;
361 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
362 __m128d one = _mm_set1_pd(1.0);
363 __m128d two = _mm_set1_pd(2.0);
369 jindex = nlist->jindex;
371 shiftidx = nlist->shift;
373 shiftvec = fr->shift_vec[0];
374 fshift = fr->fshift[0];
375 nvdwtype = fr->ntype;
377 vdwtype = mdatoms->typeA;
379 rcutoff_scalar = fr->rvdw;
380 rcutoff = _mm_set1_pd(rcutoff_scalar);
381 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
383 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
384 rvdw = _mm_set1_pd(fr->rvdw);
386 /* Avoid stupid compiler warnings */
394 /* Start outer loop over neighborlists */
395 for(iidx=0; iidx<nri; iidx++)
397 /* Load shift vector for this list */
398 i_shift_offset = DIM*shiftidx[iidx];
400 /* Load limits for loop over neighbors */
401 j_index_start = jindex[iidx];
402 j_index_end = jindex[iidx+1];
404 /* Get outer coordinate index */
406 i_coord_offset = DIM*inr;
408 /* Load i particle coords and add shift vector */
409 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
411 fix0 = _mm_setzero_pd();
412 fiy0 = _mm_setzero_pd();
413 fiz0 = _mm_setzero_pd();
415 /* Load parameters for i particles */
416 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
418 /* Start inner kernel loop */
419 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
422 /* Get j neighbor index, and coordinate index */
425 j_coord_offsetA = DIM*jnrA;
426 j_coord_offsetB = DIM*jnrB;
428 /* load j atom coordinates */
429 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
432 /* Calculate displacement vector */
433 dx00 = _mm_sub_pd(ix0,jx0);
434 dy00 = _mm_sub_pd(iy0,jy0);
435 dz00 = _mm_sub_pd(iz0,jz0);
437 /* Calculate squared distance and things based on it */
438 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
440 rinvsq00 = gmx_mm_inv_pd(rsq00);
442 /* Load parameters for j particles */
443 vdwjidx0A = 2*vdwtype[jnrA+0];
444 vdwjidx0B = 2*vdwtype[jnrB+0];
446 /**************************
447 * CALCULATE INTERACTIONS *
448 **************************/
450 if (gmx_mm_any_lt(rsq00,rcutoff2))
453 /* Compute parameters for interactions between i and j atoms */
454 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
455 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
457 /* LENNARD-JONES DISPERSION/REPULSION */
459 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
460 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
462 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
466 fscal = _mm_and_pd(fscal,cutoff_mask);
468 /* Update vectorial force */
469 fix0 = _mm_macc_pd(dx00,fscal,fix0);
470 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
471 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
473 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
474 _mm_mul_pd(dx00,fscal),
475 _mm_mul_pd(dy00,fscal),
476 _mm_mul_pd(dz00,fscal));
480 /* Inner loop uses 33 flops */
487 j_coord_offsetA = DIM*jnrA;
489 /* load j atom coordinates */
490 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
493 /* Calculate displacement vector */
494 dx00 = _mm_sub_pd(ix0,jx0);
495 dy00 = _mm_sub_pd(iy0,jy0);
496 dz00 = _mm_sub_pd(iz0,jz0);
498 /* Calculate squared distance and things based on it */
499 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
501 rinvsq00 = gmx_mm_inv_pd(rsq00);
503 /* Load parameters for j particles */
504 vdwjidx0A = 2*vdwtype[jnrA+0];
506 /**************************
507 * CALCULATE INTERACTIONS *
508 **************************/
510 if (gmx_mm_any_lt(rsq00,rcutoff2))
513 /* Compute parameters for interactions between i and j atoms */
514 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
516 /* LENNARD-JONES DISPERSION/REPULSION */
518 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
519 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
521 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
525 fscal = _mm_and_pd(fscal,cutoff_mask);
527 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
529 /* Update vectorial force */
530 fix0 = _mm_macc_pd(dx00,fscal,fix0);
531 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
532 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
534 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
535 _mm_mul_pd(dx00,fscal),
536 _mm_mul_pd(dy00,fscal),
537 _mm_mul_pd(dz00,fscal));
541 /* Inner loop uses 33 flops */
544 /* End of innermost loop */
546 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
547 f+i_coord_offset,fshift+i_shift_offset);
549 /* Increment number of inner iterations */
550 inneriter += j_index_end - j_index_start;
552 /* Outer loop uses 6 flops */
555 /* Increment number of outer iterations */
558 /* Update outer/inner flops */
560 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*33);