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_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwNone_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;
87 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
89 __m128d dummy_mask,cutoff_mask;
90 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
91 __m128d one = _mm_set1_pd(1.0);
92 __m128d two = _mm_set1_pd(2.0);
98 jindex = nlist->jindex;
100 shiftidx = nlist->shift;
102 shiftvec = fr->shift_vec[0];
103 fshift = fr->fshift[0];
104 facel = _mm_set1_pd(fr->epsfac);
105 charge = mdatoms->chargeA;
106 krf = _mm_set1_pd(fr->ic->k_rf);
107 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
108 crf = _mm_set1_pd(fr->ic->c_rf);
110 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
111 rcutoff_scalar = fr->rcoulomb;
112 rcutoff = _mm_set1_pd(rcutoff_scalar);
113 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
115 /* Avoid stupid compiler warnings */
123 /* Start outer loop over neighborlists */
124 for(iidx=0; iidx<nri; iidx++)
126 /* Load shift vector for this list */
127 i_shift_offset = DIM*shiftidx[iidx];
129 /* Load limits for loop over neighbors */
130 j_index_start = jindex[iidx];
131 j_index_end = jindex[iidx+1];
133 /* Get outer coordinate index */
135 i_coord_offset = DIM*inr;
137 /* Load i particle coords and add shift vector */
138 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
140 fix0 = _mm_setzero_pd();
141 fiy0 = _mm_setzero_pd();
142 fiz0 = _mm_setzero_pd();
144 /* Load parameters for i particles */
145 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
147 /* Reset potential sums */
148 velecsum = _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 = gmx_mm_invsqrt_pd(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);
179 /**************************
180 * CALCULATE INTERACTIONS *
181 **************************/
183 if (gmx_mm_any_lt(rsq00,rcutoff2))
186 /* Compute parameters for interactions between i and j atoms */
187 qq00 = _mm_mul_pd(iq0,jq0);
189 /* REACTION-FIELD ELECTROSTATICS */
190 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
191 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
193 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
195 /* Update potential sum for this i atom from the interaction with this j atom. */
196 velec = _mm_and_pd(velec,cutoff_mask);
197 velecsum = _mm_add_pd(velecsum,velec);
201 fscal = _mm_and_pd(fscal,cutoff_mask);
203 /* Update vectorial force */
204 fix0 = _mm_macc_pd(dx00,fscal,fix0);
205 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
206 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
208 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
209 _mm_mul_pd(dx00,fscal),
210 _mm_mul_pd(dy00,fscal),
211 _mm_mul_pd(dz00,fscal));
215 /* Inner loop uses 39 flops */
222 j_coord_offsetA = DIM*jnrA;
224 /* load j atom coordinates */
225 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
228 /* Calculate displacement vector */
229 dx00 = _mm_sub_pd(ix0,jx0);
230 dy00 = _mm_sub_pd(iy0,jy0);
231 dz00 = _mm_sub_pd(iz0,jz0);
233 /* Calculate squared distance and things based on it */
234 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
236 rinv00 = gmx_mm_invsqrt_pd(rsq00);
238 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
240 /* Load parameters for j particles */
241 jq0 = _mm_load_sd(charge+jnrA+0);
243 /**************************
244 * CALCULATE INTERACTIONS *
245 **************************/
247 if (gmx_mm_any_lt(rsq00,rcutoff2))
250 /* Compute parameters for interactions between i and j atoms */
251 qq00 = _mm_mul_pd(iq0,jq0);
253 /* REACTION-FIELD ELECTROSTATICS */
254 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
255 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
257 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
259 /* Update potential sum for this i atom from the interaction with this j atom. */
260 velec = _mm_and_pd(velec,cutoff_mask);
261 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
262 velecsum = _mm_add_pd(velecsum,velec);
266 fscal = _mm_and_pd(fscal,cutoff_mask);
268 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
270 /* Update vectorial force */
271 fix0 = _mm_macc_pd(dx00,fscal,fix0);
272 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
273 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
275 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
276 _mm_mul_pd(dx00,fscal),
277 _mm_mul_pd(dy00,fscal),
278 _mm_mul_pd(dz00,fscal));
282 /* Inner loop uses 39 flops */
285 /* End of innermost loop */
287 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
288 f+i_coord_offset,fshift+i_shift_offset);
291 /* Update potential energies */
292 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
294 /* Increment number of inner iterations */
295 inneriter += j_index_end - j_index_start;
297 /* Outer loop uses 8 flops */
300 /* Increment number of outer iterations */
303 /* Update outer/inner flops */
305 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*39);
308 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
309 * Electrostatics interaction: ReactionField
310 * VdW interaction: None
311 * Geometry: Particle-Particle
312 * Calculate force/pot: Force
315 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
316 (t_nblist * gmx_restrict nlist,
317 rvec * gmx_restrict xx,
318 rvec * gmx_restrict ff,
319 t_forcerec * gmx_restrict fr,
320 t_mdatoms * gmx_restrict mdatoms,
321 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
322 t_nrnb * gmx_restrict nrnb)
324 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
325 * just 0 for non-waters.
326 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
327 * jnr indices corresponding to data put in the four positions in the SIMD register.
329 int i_shift_offset,i_coord_offset,outeriter,inneriter;
330 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
332 int j_coord_offsetA,j_coord_offsetB;
333 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
335 real *shiftvec,*fshift,*x,*f;
336 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
338 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
339 int vdwjidx0A,vdwjidx0B;
340 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
341 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
342 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
344 __m128d dummy_mask,cutoff_mask;
345 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
346 __m128d one = _mm_set1_pd(1.0);
347 __m128d two = _mm_set1_pd(2.0);
353 jindex = nlist->jindex;
355 shiftidx = nlist->shift;
357 shiftvec = fr->shift_vec[0];
358 fshift = fr->fshift[0];
359 facel = _mm_set1_pd(fr->epsfac);
360 charge = mdatoms->chargeA;
361 krf = _mm_set1_pd(fr->ic->k_rf);
362 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
363 crf = _mm_set1_pd(fr->ic->c_rf);
365 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
366 rcutoff_scalar = fr->rcoulomb;
367 rcutoff = _mm_set1_pd(rcutoff_scalar);
368 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
370 /* Avoid stupid compiler warnings */
378 /* Start outer loop over neighborlists */
379 for(iidx=0; iidx<nri; iidx++)
381 /* Load shift vector for this list */
382 i_shift_offset = DIM*shiftidx[iidx];
384 /* Load limits for loop over neighbors */
385 j_index_start = jindex[iidx];
386 j_index_end = jindex[iidx+1];
388 /* Get outer coordinate index */
390 i_coord_offset = DIM*inr;
392 /* Load i particle coords and add shift vector */
393 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
395 fix0 = _mm_setzero_pd();
396 fiy0 = _mm_setzero_pd();
397 fiz0 = _mm_setzero_pd();
399 /* Load parameters for i particles */
400 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
402 /* Start inner kernel loop */
403 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
406 /* Get j neighbor index, and coordinate index */
409 j_coord_offsetA = DIM*jnrA;
410 j_coord_offsetB = DIM*jnrB;
412 /* load j atom coordinates */
413 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
416 /* Calculate displacement vector */
417 dx00 = _mm_sub_pd(ix0,jx0);
418 dy00 = _mm_sub_pd(iy0,jy0);
419 dz00 = _mm_sub_pd(iz0,jz0);
421 /* Calculate squared distance and things based on it */
422 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
424 rinv00 = gmx_mm_invsqrt_pd(rsq00);
426 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
428 /* Load parameters for j particles */
429 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
431 /**************************
432 * CALCULATE INTERACTIONS *
433 **************************/
435 if (gmx_mm_any_lt(rsq00,rcutoff2))
438 /* Compute parameters for interactions between i and j atoms */
439 qq00 = _mm_mul_pd(iq0,jq0);
441 /* REACTION-FIELD ELECTROSTATICS */
442 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
444 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
448 fscal = _mm_and_pd(fscal,cutoff_mask);
450 /* Update vectorial force */
451 fix0 = _mm_macc_pd(dx00,fscal,fix0);
452 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
453 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
455 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
456 _mm_mul_pd(dx00,fscal),
457 _mm_mul_pd(dy00,fscal),
458 _mm_mul_pd(dz00,fscal));
462 /* Inner loop uses 33 flops */
469 j_coord_offsetA = DIM*jnrA;
471 /* load j atom coordinates */
472 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
475 /* Calculate displacement vector */
476 dx00 = _mm_sub_pd(ix0,jx0);
477 dy00 = _mm_sub_pd(iy0,jy0);
478 dz00 = _mm_sub_pd(iz0,jz0);
480 /* Calculate squared distance and things based on it */
481 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
483 rinv00 = gmx_mm_invsqrt_pd(rsq00);
485 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
487 /* Load parameters for j particles */
488 jq0 = _mm_load_sd(charge+jnrA+0);
490 /**************************
491 * CALCULATE INTERACTIONS *
492 **************************/
494 if (gmx_mm_any_lt(rsq00,rcutoff2))
497 /* Compute parameters for interactions between i and j atoms */
498 qq00 = _mm_mul_pd(iq0,jq0);
500 /* REACTION-FIELD ELECTROSTATICS */
501 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
503 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
507 fscal = _mm_and_pd(fscal,cutoff_mask);
509 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
511 /* Update vectorial force */
512 fix0 = _mm_macc_pd(dx00,fscal,fix0);
513 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
514 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
516 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
517 _mm_mul_pd(dx00,fscal),
518 _mm_mul_pd(dy00,fscal),
519 _mm_mul_pd(dz00,fscal));
523 /* Inner loop uses 33 flops */
526 /* End of innermost loop */
528 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
529 f+i_coord_offset,fshift+i_shift_offset);
531 /* Increment number of inner iterations */
532 inneriter += j_index_end - j_index_start;
534 /* Outer loop uses 7 flops */
537 /* Increment number of outer iterations */
540 /* Update outer/inner flops */
542 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*33);