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_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_double
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEw_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;
90 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
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->epsfac);
108 charge = mdatoms->chargeA;
110 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
111 ewtab = fr->ic->tabq_coul_FDV0;
112 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
113 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
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 r00 = _mm_mul_pd(rsq00,rinv00);
185 /* Compute parameters for interactions between i and j atoms */
186 qq00 = _mm_mul_pd(iq0,jq0);
188 /* EWALD ELECTROSTATICS */
190 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
191 ewrt = _mm_mul_pd(r00,ewtabscale);
192 ewitab = _mm_cvttpd_epi32(ewrt);
194 eweps = _mm_frcz_pd(ewrt);
196 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
198 twoeweps = _mm_add_pd(eweps,eweps);
199 ewitab = _mm_slli_epi32(ewitab,2);
200 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
201 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
202 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
203 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
204 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
205 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
206 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
207 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
208 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
209 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
211 /* Update potential sum for this i atom from the interaction with this j atom. */
212 velecsum = _mm_add_pd(velecsum,velec);
216 /* Update vectorial force */
217 fix0 = _mm_macc_pd(dx00,fscal,fix0);
218 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
219 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
221 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
222 _mm_mul_pd(dx00,fscal),
223 _mm_mul_pd(dy00,fscal),
224 _mm_mul_pd(dz00,fscal));
226 /* Inner loop uses 44 flops */
233 j_coord_offsetA = DIM*jnrA;
235 /* load j atom coordinates */
236 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
239 /* Calculate displacement vector */
240 dx00 = _mm_sub_pd(ix0,jx0);
241 dy00 = _mm_sub_pd(iy0,jy0);
242 dz00 = _mm_sub_pd(iz0,jz0);
244 /* Calculate squared distance and things based on it */
245 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
247 rinv00 = gmx_mm_invsqrt_pd(rsq00);
249 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
251 /* Load parameters for j particles */
252 jq0 = _mm_load_sd(charge+jnrA+0);
254 /**************************
255 * CALCULATE INTERACTIONS *
256 **************************/
258 r00 = _mm_mul_pd(rsq00,rinv00);
260 /* Compute parameters for interactions between i and j atoms */
261 qq00 = _mm_mul_pd(iq0,jq0);
263 /* EWALD ELECTROSTATICS */
265 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
266 ewrt = _mm_mul_pd(r00,ewtabscale);
267 ewitab = _mm_cvttpd_epi32(ewrt);
269 eweps = _mm_frcz_pd(ewrt);
271 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
273 twoeweps = _mm_add_pd(eweps,eweps);
274 ewitab = _mm_slli_epi32(ewitab,2);
275 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
276 ewtabD = _mm_setzero_pd();
277 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
278 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
279 ewtabFn = _mm_setzero_pd();
280 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
281 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
282 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
283 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
284 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
286 /* Update potential sum for this i atom from the interaction with this j atom. */
287 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
288 velecsum = _mm_add_pd(velecsum,velec);
292 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
294 /* Update vectorial force */
295 fix0 = _mm_macc_pd(dx00,fscal,fix0);
296 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
297 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
299 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
300 _mm_mul_pd(dx00,fscal),
301 _mm_mul_pd(dy00,fscal),
302 _mm_mul_pd(dz00,fscal));
304 /* Inner loop uses 44 flops */
307 /* End of innermost loop */
309 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
310 f+i_coord_offset,fshift+i_shift_offset);
313 /* Update potential energies */
314 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
316 /* Increment number of inner iterations */
317 inneriter += j_index_end - j_index_start;
319 /* Outer loop uses 8 flops */
322 /* Increment number of outer iterations */
325 /* Update outer/inner flops */
327 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*44);
330 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
331 * Electrostatics interaction: Ewald
332 * VdW interaction: None
333 * Geometry: Particle-Particle
334 * Calculate force/pot: Force
337 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
338 (t_nblist * gmx_restrict nlist,
339 rvec * gmx_restrict xx,
340 rvec * gmx_restrict ff,
341 t_forcerec * gmx_restrict fr,
342 t_mdatoms * gmx_restrict mdatoms,
343 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
344 t_nrnb * gmx_restrict nrnb)
346 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
347 * just 0 for non-waters.
348 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
349 * jnr indices corresponding to data put in the four positions in the SIMD register.
351 int i_shift_offset,i_coord_offset,outeriter,inneriter;
352 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
354 int j_coord_offsetA,j_coord_offsetB;
355 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
357 real *shiftvec,*fshift,*x,*f;
358 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
360 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
361 int vdwjidx0A,vdwjidx0B;
362 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
363 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
364 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
367 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
369 __m128d dummy_mask,cutoff_mask;
370 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
371 __m128d one = _mm_set1_pd(1.0);
372 __m128d two = _mm_set1_pd(2.0);
378 jindex = nlist->jindex;
380 shiftidx = nlist->shift;
382 shiftvec = fr->shift_vec[0];
383 fshift = fr->fshift[0];
384 facel = _mm_set1_pd(fr->epsfac);
385 charge = mdatoms->chargeA;
387 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
388 ewtab = fr->ic->tabq_coul_F;
389 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
390 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
392 /* Avoid stupid compiler warnings */
400 /* Start outer loop over neighborlists */
401 for(iidx=0; iidx<nri; iidx++)
403 /* Load shift vector for this list */
404 i_shift_offset = DIM*shiftidx[iidx];
406 /* Load limits for loop over neighbors */
407 j_index_start = jindex[iidx];
408 j_index_end = jindex[iidx+1];
410 /* Get outer coordinate index */
412 i_coord_offset = DIM*inr;
414 /* Load i particle coords and add shift vector */
415 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
417 fix0 = _mm_setzero_pd();
418 fiy0 = _mm_setzero_pd();
419 fiz0 = _mm_setzero_pd();
421 /* Load parameters for i particles */
422 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
424 /* Start inner kernel loop */
425 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
428 /* Get j neighbor index, and coordinate index */
431 j_coord_offsetA = DIM*jnrA;
432 j_coord_offsetB = DIM*jnrB;
434 /* load j atom coordinates */
435 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
438 /* Calculate displacement vector */
439 dx00 = _mm_sub_pd(ix0,jx0);
440 dy00 = _mm_sub_pd(iy0,jy0);
441 dz00 = _mm_sub_pd(iz0,jz0);
443 /* Calculate squared distance and things based on it */
444 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
446 rinv00 = gmx_mm_invsqrt_pd(rsq00);
448 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
450 /* Load parameters for j particles */
451 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
453 /**************************
454 * CALCULATE INTERACTIONS *
455 **************************/
457 r00 = _mm_mul_pd(rsq00,rinv00);
459 /* Compute parameters for interactions between i and j atoms */
460 qq00 = _mm_mul_pd(iq0,jq0);
462 /* EWALD ELECTROSTATICS */
464 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
465 ewrt = _mm_mul_pd(r00,ewtabscale);
466 ewitab = _mm_cvttpd_epi32(ewrt);
468 eweps = _mm_frcz_pd(ewrt);
470 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
472 twoeweps = _mm_add_pd(eweps,eweps);
473 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
475 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
476 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
480 /* Update vectorial force */
481 fix0 = _mm_macc_pd(dx00,fscal,fix0);
482 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
483 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
485 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
486 _mm_mul_pd(dx00,fscal),
487 _mm_mul_pd(dy00,fscal),
488 _mm_mul_pd(dz00,fscal));
490 /* Inner loop uses 39 flops */
497 j_coord_offsetA = DIM*jnrA;
499 /* load j atom coordinates */
500 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
503 /* Calculate displacement vector */
504 dx00 = _mm_sub_pd(ix0,jx0);
505 dy00 = _mm_sub_pd(iy0,jy0);
506 dz00 = _mm_sub_pd(iz0,jz0);
508 /* Calculate squared distance and things based on it */
509 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
511 rinv00 = gmx_mm_invsqrt_pd(rsq00);
513 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
515 /* Load parameters for j particles */
516 jq0 = _mm_load_sd(charge+jnrA+0);
518 /**************************
519 * CALCULATE INTERACTIONS *
520 **************************/
522 r00 = _mm_mul_pd(rsq00,rinv00);
524 /* Compute parameters for interactions between i and j atoms */
525 qq00 = _mm_mul_pd(iq0,jq0);
527 /* EWALD ELECTROSTATICS */
529 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
530 ewrt = _mm_mul_pd(r00,ewtabscale);
531 ewitab = _mm_cvttpd_epi32(ewrt);
533 eweps = _mm_frcz_pd(ewrt);
535 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
537 twoeweps = _mm_add_pd(eweps,eweps);
538 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
539 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
540 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
544 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
546 /* Update vectorial force */
547 fix0 = _mm_macc_pd(dx00,fscal,fix0);
548 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
549 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
551 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
552 _mm_mul_pd(dx00,fscal),
553 _mm_mul_pd(dy00,fscal),
554 _mm_mul_pd(dz00,fscal));
556 /* Inner loop uses 39 flops */
559 /* End of innermost loop */
561 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
562 f+i_coord_offset,fshift+i_shift_offset);
564 /* Increment number of inner iterations */
565 inneriter += j_index_end - j_index_start;
567 /* Outer loop uses 7 flops */
570 /* Increment number of outer iterations */
573 /* Update outer/inner flops */
575 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*39);