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 "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.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_ElecRF_VdwLJ_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRF_VdwLJ_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);
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 facel = _mm_set1_pd(fr->epsfac);
109 charge = mdatoms->chargeA;
110 krf = _mm_set1_pd(fr->ic->k_rf);
111 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
112 crf = _mm_set1_pd(fr->ic->c_rf);
113 nvdwtype = fr->ntype;
115 vdwtype = mdatoms->typeA;
117 /* Avoid stupid compiler warnings */
125 /* Start outer loop over neighborlists */
126 for(iidx=0; iidx<nri; iidx++)
128 /* Load shift vector for this list */
129 i_shift_offset = DIM*shiftidx[iidx];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
139 /* Load i particle coords and add shift vector */
140 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
142 fix0 = _mm_setzero_pd();
143 fiy0 = _mm_setzero_pd();
144 fiz0 = _mm_setzero_pd();
146 /* Load parameters for i particles */
147 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
148 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
150 /* Reset potential sums */
151 velecsum = _mm_setzero_pd();
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 rinv00 = gmx_mm_invsqrt_pd(rsq00);
178 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
180 /* Load parameters for j particles */
181 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
182 vdwjidx0A = 2*vdwtype[jnrA+0];
183 vdwjidx0B = 2*vdwtype[jnrB+0];
185 /**************************
186 * CALCULATE INTERACTIONS *
187 **************************/
189 /* Compute parameters for interactions between i and j atoms */
190 qq00 = _mm_mul_pd(iq0,jq0);
191 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
192 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
194 /* REACTION-FIELD ELECTROSTATICS */
195 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
196 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
198 /* LENNARD-JONES DISPERSION/REPULSION */
200 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
201 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
202 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
203 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
204 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
206 /* Update potential sum for this i atom from the interaction with this j atom. */
207 velecsum = _mm_add_pd(velecsum,velec);
208 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
210 fscal = _mm_add_pd(felec,fvdw);
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));
222 /* Inner loop uses 47 flops */
229 j_coord_offsetA = DIM*jnrA;
231 /* load j atom coordinates */
232 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
235 /* Calculate displacement vector */
236 dx00 = _mm_sub_pd(ix0,jx0);
237 dy00 = _mm_sub_pd(iy0,jy0);
238 dz00 = _mm_sub_pd(iz0,jz0);
240 /* Calculate squared distance and things based on it */
241 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
243 rinv00 = gmx_mm_invsqrt_pd(rsq00);
245 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
247 /* Load parameters for j particles */
248 jq0 = _mm_load_sd(charge+jnrA+0);
249 vdwjidx0A = 2*vdwtype[jnrA+0];
251 /**************************
252 * CALCULATE INTERACTIONS *
253 **************************/
255 /* Compute parameters for interactions between i and j atoms */
256 qq00 = _mm_mul_pd(iq0,jq0);
257 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
259 /* REACTION-FIELD ELECTROSTATICS */
260 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
261 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
263 /* LENNARD-JONES DISPERSION/REPULSION */
265 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
266 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
267 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
268 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
269 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
271 /* Update potential sum for this i atom from the interaction with this j atom. */
272 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
273 velecsum = _mm_add_pd(velecsum,velec);
274 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
275 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
277 fscal = _mm_add_pd(felec,fvdw);
279 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
281 /* Update vectorial force */
282 fix0 = _mm_macc_pd(dx00,fscal,fix0);
283 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
284 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
286 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
287 _mm_mul_pd(dx00,fscal),
288 _mm_mul_pd(dy00,fscal),
289 _mm_mul_pd(dz00,fscal));
291 /* Inner loop uses 47 flops */
294 /* End of innermost loop */
296 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
297 f+i_coord_offset,fshift+i_shift_offset);
300 /* Update potential energies */
301 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
302 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
304 /* Increment number of inner iterations */
305 inneriter += j_index_end - j_index_start;
307 /* Outer loop uses 9 flops */
310 /* Increment number of outer iterations */
313 /* Update outer/inner flops */
315 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*47);
318 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_avx_128_fma_double
319 * Electrostatics interaction: ReactionField
320 * VdW interaction: LennardJones
321 * Geometry: Particle-Particle
322 * Calculate force/pot: Force
325 nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_avx_128_fma_double
326 (t_nblist * gmx_restrict nlist,
327 rvec * gmx_restrict xx,
328 rvec * gmx_restrict ff,
329 t_forcerec * gmx_restrict fr,
330 t_mdatoms * gmx_restrict mdatoms,
331 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
332 t_nrnb * gmx_restrict nrnb)
334 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
335 * just 0 for non-waters.
336 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
337 * jnr indices corresponding to data put in the four positions in the SIMD register.
339 int i_shift_offset,i_coord_offset,outeriter,inneriter;
340 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
342 int j_coord_offsetA,j_coord_offsetB;
343 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
345 real *shiftvec,*fshift,*x,*f;
346 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
348 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
349 int vdwjidx0A,vdwjidx0B;
350 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
351 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
352 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
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 facel = _mm_set1_pd(fr->epsfac);
376 charge = mdatoms->chargeA;
377 krf = _mm_set1_pd(fr->ic->k_rf);
378 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
379 crf = _mm_set1_pd(fr->ic->c_rf);
380 nvdwtype = fr->ntype;
382 vdwtype = mdatoms->typeA;
384 /* Avoid stupid compiler warnings */
392 /* Start outer loop over neighborlists */
393 for(iidx=0; iidx<nri; iidx++)
395 /* Load shift vector for this list */
396 i_shift_offset = DIM*shiftidx[iidx];
398 /* Load limits for loop over neighbors */
399 j_index_start = jindex[iidx];
400 j_index_end = jindex[iidx+1];
402 /* Get outer coordinate index */
404 i_coord_offset = DIM*inr;
406 /* Load i particle coords and add shift vector */
407 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
409 fix0 = _mm_setzero_pd();
410 fiy0 = _mm_setzero_pd();
411 fiz0 = _mm_setzero_pd();
413 /* Load parameters for i particles */
414 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
415 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
417 /* Start inner kernel loop */
418 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
421 /* Get j neighbor index, and coordinate index */
424 j_coord_offsetA = DIM*jnrA;
425 j_coord_offsetB = DIM*jnrB;
427 /* load j atom coordinates */
428 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
431 /* Calculate displacement vector */
432 dx00 = _mm_sub_pd(ix0,jx0);
433 dy00 = _mm_sub_pd(iy0,jy0);
434 dz00 = _mm_sub_pd(iz0,jz0);
436 /* Calculate squared distance and things based on it */
437 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
439 rinv00 = gmx_mm_invsqrt_pd(rsq00);
441 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
443 /* Load parameters for j particles */
444 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
445 vdwjidx0A = 2*vdwtype[jnrA+0];
446 vdwjidx0B = 2*vdwtype[jnrB+0];
448 /**************************
449 * CALCULATE INTERACTIONS *
450 **************************/
452 /* Compute parameters for interactions between i and j atoms */
453 qq00 = _mm_mul_pd(iq0,jq0);
454 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
455 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
457 /* REACTION-FIELD ELECTROSTATICS */
458 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
460 /* LENNARD-JONES DISPERSION/REPULSION */
462 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
463 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
465 fscal = _mm_add_pd(felec,fvdw);
467 /* Update vectorial force */
468 fix0 = _mm_macc_pd(dx00,fscal,fix0);
469 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
470 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
472 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
473 _mm_mul_pd(dx00,fscal),
474 _mm_mul_pd(dy00,fscal),
475 _mm_mul_pd(dz00,fscal));
477 /* Inner loop uses 37 flops */
484 j_coord_offsetA = DIM*jnrA;
486 /* load j atom coordinates */
487 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
490 /* Calculate displacement vector */
491 dx00 = _mm_sub_pd(ix0,jx0);
492 dy00 = _mm_sub_pd(iy0,jy0);
493 dz00 = _mm_sub_pd(iz0,jz0);
495 /* Calculate squared distance and things based on it */
496 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
498 rinv00 = gmx_mm_invsqrt_pd(rsq00);
500 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
502 /* Load parameters for j particles */
503 jq0 = _mm_load_sd(charge+jnrA+0);
504 vdwjidx0A = 2*vdwtype[jnrA+0];
506 /**************************
507 * CALCULATE INTERACTIONS *
508 **************************/
510 /* Compute parameters for interactions between i and j atoms */
511 qq00 = _mm_mul_pd(iq0,jq0);
512 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
514 /* REACTION-FIELD ELECTROSTATICS */
515 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
517 /* LENNARD-JONES DISPERSION/REPULSION */
519 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
520 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
522 fscal = _mm_add_pd(felec,fvdw);
524 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
526 /* Update vectorial force */
527 fix0 = _mm_macc_pd(dx00,fscal,fix0);
528 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
529 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
531 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
532 _mm_mul_pd(dx00,fscal),
533 _mm_mul_pd(dy00,fscal),
534 _mm_mul_pd(dz00,fscal));
536 /* Inner loop uses 37 flops */
539 /* End of innermost loop */
541 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
542 f+i_coord_offset,fshift+i_shift_offset);
544 /* Increment number of inner iterations */
545 inneriter += j_index_end - j_index_start;
547 /* Outer loop uses 7 flops */
550 /* Increment number of outer iterations */
553 /* Update outer/inner flops */
555 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*37);