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_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwNone_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;
87 __m128d dummy_mask,cutoff_mask;
88 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
89 __m128d one = _mm_set1_pd(1.0);
90 __m128d two = _mm_set1_pd(2.0);
96 jindex = nlist->jindex;
98 shiftidx = nlist->shift;
100 shiftvec = fr->shift_vec[0];
101 fshift = fr->fshift[0];
102 facel = _mm_set1_pd(fr->epsfac);
103 charge = mdatoms->chargeA;
104 krf = _mm_set1_pd(fr->ic->k_rf);
105 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
106 crf = _mm_set1_pd(fr->ic->c_rf);
108 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
109 rcutoff_scalar = fr->rcoulomb;
110 rcutoff = _mm_set1_pd(rcutoff_scalar);
111 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
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));
145 /* Reset potential sums */
146 velecsum = _mm_setzero_pd();
148 /* Start inner kernel loop */
149 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
152 /* Get j neighbor index, and coordinate index */
155 j_coord_offsetA = DIM*jnrA;
156 j_coord_offsetB = DIM*jnrB;
158 /* load j atom coordinates */
159 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
162 /* Calculate displacement vector */
163 dx00 = _mm_sub_pd(ix0,jx0);
164 dy00 = _mm_sub_pd(iy0,jy0);
165 dz00 = _mm_sub_pd(iz0,jz0);
167 /* Calculate squared distance and things based on it */
168 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
170 rinv00 = gmx_mm_invsqrt_pd(rsq00);
172 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
174 /* Load parameters for j particles */
175 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
177 /**************************
178 * CALCULATE INTERACTIONS *
179 **************************/
181 if (gmx_mm_any_lt(rsq00,rcutoff2))
184 /* Compute parameters for interactions between i and j atoms */
185 qq00 = _mm_mul_pd(iq0,jq0);
187 /* REACTION-FIELD ELECTROSTATICS */
188 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
189 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
191 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
193 /* Update potential sum for this i atom from the interaction with this j atom. */
194 velec = _mm_and_pd(velec,cutoff_mask);
195 velecsum = _mm_add_pd(velecsum,velec);
199 fscal = _mm_and_pd(fscal,cutoff_mask);
201 /* Update vectorial force */
202 fix0 = _mm_macc_pd(dx00,fscal,fix0);
203 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
204 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
206 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
207 _mm_mul_pd(dx00,fscal),
208 _mm_mul_pd(dy00,fscal),
209 _mm_mul_pd(dz00,fscal));
213 /* Inner loop uses 39 flops */
220 j_coord_offsetA = DIM*jnrA;
222 /* load j atom coordinates */
223 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
226 /* Calculate displacement vector */
227 dx00 = _mm_sub_pd(ix0,jx0);
228 dy00 = _mm_sub_pd(iy0,jy0);
229 dz00 = _mm_sub_pd(iz0,jz0);
231 /* Calculate squared distance and things based on it */
232 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
234 rinv00 = gmx_mm_invsqrt_pd(rsq00);
236 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
238 /* Load parameters for j particles */
239 jq0 = _mm_load_sd(charge+jnrA+0);
241 /**************************
242 * CALCULATE INTERACTIONS *
243 **************************/
245 if (gmx_mm_any_lt(rsq00,rcutoff2))
248 /* Compute parameters for interactions between i and j atoms */
249 qq00 = _mm_mul_pd(iq0,jq0);
251 /* REACTION-FIELD ELECTROSTATICS */
252 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
253 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
255 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
257 /* Update potential sum for this i atom from the interaction with this j atom. */
258 velec = _mm_and_pd(velec,cutoff_mask);
259 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
260 velecsum = _mm_add_pd(velecsum,velec);
264 fscal = _mm_and_pd(fscal,cutoff_mask);
266 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
268 /* Update vectorial force */
269 fix0 = _mm_macc_pd(dx00,fscal,fix0);
270 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
271 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
273 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
274 _mm_mul_pd(dx00,fscal),
275 _mm_mul_pd(dy00,fscal),
276 _mm_mul_pd(dz00,fscal));
280 /* Inner loop uses 39 flops */
283 /* End of innermost loop */
285 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
286 f+i_coord_offset,fshift+i_shift_offset);
289 /* Update potential energies */
290 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
292 /* Increment number of inner iterations */
293 inneriter += j_index_end - j_index_start;
295 /* Outer loop uses 8 flops */
298 /* Increment number of outer iterations */
301 /* Update outer/inner flops */
303 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*39);
306 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
307 * Electrostatics interaction: ReactionField
308 * VdW interaction: None
309 * Geometry: Particle-Particle
310 * Calculate force/pot: Force
313 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
314 (t_nblist * gmx_restrict nlist,
315 rvec * gmx_restrict xx,
316 rvec * gmx_restrict ff,
317 t_forcerec * gmx_restrict fr,
318 t_mdatoms * gmx_restrict mdatoms,
319 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
320 t_nrnb * gmx_restrict nrnb)
322 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
323 * just 0 for non-waters.
324 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
325 * jnr indices corresponding to data put in the four positions in the SIMD register.
327 int i_shift_offset,i_coord_offset,outeriter,inneriter;
328 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
330 int j_coord_offsetA,j_coord_offsetB;
331 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
333 real *shiftvec,*fshift,*x,*f;
334 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
336 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
337 int vdwjidx0A,vdwjidx0B;
338 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
339 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
340 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
342 __m128d dummy_mask,cutoff_mask;
343 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
344 __m128d one = _mm_set1_pd(1.0);
345 __m128d two = _mm_set1_pd(2.0);
351 jindex = nlist->jindex;
353 shiftidx = nlist->shift;
355 shiftvec = fr->shift_vec[0];
356 fshift = fr->fshift[0];
357 facel = _mm_set1_pd(fr->epsfac);
358 charge = mdatoms->chargeA;
359 krf = _mm_set1_pd(fr->ic->k_rf);
360 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
361 crf = _mm_set1_pd(fr->ic->c_rf);
363 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
364 rcutoff_scalar = fr->rcoulomb;
365 rcutoff = _mm_set1_pd(rcutoff_scalar);
366 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
368 /* Avoid stupid compiler warnings */
376 /* Start outer loop over neighborlists */
377 for(iidx=0; iidx<nri; iidx++)
379 /* Load shift vector for this list */
380 i_shift_offset = DIM*shiftidx[iidx];
382 /* Load limits for loop over neighbors */
383 j_index_start = jindex[iidx];
384 j_index_end = jindex[iidx+1];
386 /* Get outer coordinate index */
388 i_coord_offset = DIM*inr;
390 /* Load i particle coords and add shift vector */
391 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
393 fix0 = _mm_setzero_pd();
394 fiy0 = _mm_setzero_pd();
395 fiz0 = _mm_setzero_pd();
397 /* Load parameters for i particles */
398 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
400 /* Start inner kernel loop */
401 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
404 /* Get j neighbor index, and coordinate index */
407 j_coord_offsetA = DIM*jnrA;
408 j_coord_offsetB = DIM*jnrB;
410 /* load j atom coordinates */
411 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
414 /* Calculate displacement vector */
415 dx00 = _mm_sub_pd(ix0,jx0);
416 dy00 = _mm_sub_pd(iy0,jy0);
417 dz00 = _mm_sub_pd(iz0,jz0);
419 /* Calculate squared distance and things based on it */
420 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
422 rinv00 = gmx_mm_invsqrt_pd(rsq00);
424 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
426 /* Load parameters for j particles */
427 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
429 /**************************
430 * CALCULATE INTERACTIONS *
431 **************************/
433 if (gmx_mm_any_lt(rsq00,rcutoff2))
436 /* Compute parameters for interactions between i and j atoms */
437 qq00 = _mm_mul_pd(iq0,jq0);
439 /* REACTION-FIELD ELECTROSTATICS */
440 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
442 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
446 fscal = _mm_and_pd(fscal,cutoff_mask);
448 /* Update vectorial force */
449 fix0 = _mm_macc_pd(dx00,fscal,fix0);
450 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
451 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
453 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
454 _mm_mul_pd(dx00,fscal),
455 _mm_mul_pd(dy00,fscal),
456 _mm_mul_pd(dz00,fscal));
460 /* Inner loop uses 33 flops */
467 j_coord_offsetA = DIM*jnrA;
469 /* load j atom coordinates */
470 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
473 /* Calculate displacement vector */
474 dx00 = _mm_sub_pd(ix0,jx0);
475 dy00 = _mm_sub_pd(iy0,jy0);
476 dz00 = _mm_sub_pd(iz0,jz0);
478 /* Calculate squared distance and things based on it */
479 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
481 rinv00 = gmx_mm_invsqrt_pd(rsq00);
483 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
485 /* Load parameters for j particles */
486 jq0 = _mm_load_sd(charge+jnrA+0);
488 /**************************
489 * CALCULATE INTERACTIONS *
490 **************************/
492 if (gmx_mm_any_lt(rsq00,rcutoff2))
495 /* Compute parameters for interactions between i and j atoms */
496 qq00 = _mm_mul_pd(iq0,jq0);
498 /* REACTION-FIELD ELECTROSTATICS */
499 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
501 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
505 fscal = _mm_and_pd(fscal,cutoff_mask);
507 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
509 /* Update vectorial force */
510 fix0 = _mm_macc_pd(dx00,fscal,fix0);
511 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
512 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
514 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
515 _mm_mul_pd(dx00,fscal),
516 _mm_mul_pd(dy00,fscal),
517 _mm_mul_pd(dz00,fscal));
521 /* Inner loop uses 33 flops */
524 /* End of innermost loop */
526 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
527 f+i_coord_offset,fshift+i_shift_offset);
529 /* Increment number of inner iterations */
530 inneriter += j_index_end - j_index_start;
532 /* Outer loop uses 7 flops */
535 /* Increment number of outer iterations */
538 /* Update outer/inner flops */
540 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*33);