2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_double
51 * Electrostatics interaction: Ewald
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_double
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81 int vdwjidx0A,vdwjidx0B;
82 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
87 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
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->ic->epsfac);
105 charge = mdatoms->chargeA;
107 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
108 ewtab = fr->ic->tabq_coul_FDV0;
109 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
110 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
112 /* Avoid stupid compiler warnings */
120 /* Start outer loop over neighborlists */
121 for(iidx=0; iidx<nri; iidx++)
123 /* Load shift vector for this list */
124 i_shift_offset = DIM*shiftidx[iidx];
126 /* Load limits for loop over neighbors */
127 j_index_start = jindex[iidx];
128 j_index_end = jindex[iidx+1];
130 /* Get outer coordinate index */
132 i_coord_offset = DIM*inr;
134 /* Load i particle coords and add shift vector */
135 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
137 fix0 = _mm_setzero_pd();
138 fiy0 = _mm_setzero_pd();
139 fiz0 = _mm_setzero_pd();
141 /* Load parameters for i particles */
142 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
144 /* Reset potential sums */
145 velecsum = _mm_setzero_pd();
147 /* Start inner kernel loop */
148 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
151 /* Get j neighbor index, and coordinate index */
154 j_coord_offsetA = DIM*jnrA;
155 j_coord_offsetB = DIM*jnrB;
157 /* load j atom coordinates */
158 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
161 /* Calculate displacement vector */
162 dx00 = _mm_sub_pd(ix0,jx0);
163 dy00 = _mm_sub_pd(iy0,jy0);
164 dz00 = _mm_sub_pd(iz0,jz0);
166 /* Calculate squared distance and things based on it */
167 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
169 rinv00 = avx128fma_invsqrt_d(rsq00);
171 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
173 /* Load parameters for j particles */
174 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
176 /**************************
177 * CALCULATE INTERACTIONS *
178 **************************/
180 r00 = _mm_mul_pd(rsq00,rinv00);
182 /* Compute parameters for interactions between i and j atoms */
183 qq00 = _mm_mul_pd(iq0,jq0);
185 /* EWALD ELECTROSTATICS */
187 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
188 ewrt = _mm_mul_pd(r00,ewtabscale);
189 ewitab = _mm_cvttpd_epi32(ewrt);
191 eweps = _mm_frcz_pd(ewrt);
193 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
195 twoeweps = _mm_add_pd(eweps,eweps);
196 ewitab = _mm_slli_epi32(ewitab,2);
197 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
198 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
199 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
200 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
201 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
202 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
203 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
204 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
205 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
206 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
208 /* Update potential sum for this i atom from the interaction with this j atom. */
209 velecsum = _mm_add_pd(velecsum,velec);
213 /* Update vectorial force */
214 fix0 = _mm_macc_pd(dx00,fscal,fix0);
215 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
216 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
218 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
219 _mm_mul_pd(dx00,fscal),
220 _mm_mul_pd(dy00,fscal),
221 _mm_mul_pd(dz00,fscal));
223 /* Inner loop uses 44 flops */
230 j_coord_offsetA = DIM*jnrA;
232 /* load j atom coordinates */
233 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
236 /* Calculate displacement vector */
237 dx00 = _mm_sub_pd(ix0,jx0);
238 dy00 = _mm_sub_pd(iy0,jy0);
239 dz00 = _mm_sub_pd(iz0,jz0);
241 /* Calculate squared distance and things based on it */
242 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
244 rinv00 = avx128fma_invsqrt_d(rsq00);
246 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
248 /* Load parameters for j particles */
249 jq0 = _mm_load_sd(charge+jnrA+0);
251 /**************************
252 * CALCULATE INTERACTIONS *
253 **************************/
255 r00 = _mm_mul_pd(rsq00,rinv00);
257 /* Compute parameters for interactions between i and j atoms */
258 qq00 = _mm_mul_pd(iq0,jq0);
260 /* EWALD ELECTROSTATICS */
262 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
263 ewrt = _mm_mul_pd(r00,ewtabscale);
264 ewitab = _mm_cvttpd_epi32(ewrt);
266 eweps = _mm_frcz_pd(ewrt);
268 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
270 twoeweps = _mm_add_pd(eweps,eweps);
271 ewitab = _mm_slli_epi32(ewitab,2);
272 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
273 ewtabD = _mm_setzero_pd();
274 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
275 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
276 ewtabFn = _mm_setzero_pd();
277 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
278 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
279 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
280 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
281 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
283 /* Update potential sum for this i atom from the interaction with this j atom. */
284 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
285 velecsum = _mm_add_pd(velecsum,velec);
289 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
291 /* Update vectorial force */
292 fix0 = _mm_macc_pd(dx00,fscal,fix0);
293 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
294 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
296 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
297 _mm_mul_pd(dx00,fscal),
298 _mm_mul_pd(dy00,fscal),
299 _mm_mul_pd(dz00,fscal));
301 /* Inner loop uses 44 flops */
304 /* End of innermost loop */
306 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
307 f+i_coord_offset,fshift+i_shift_offset);
310 /* Update potential energies */
311 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
313 /* Increment number of inner iterations */
314 inneriter += j_index_end - j_index_start;
316 /* Outer loop uses 8 flops */
319 /* Increment number of outer iterations */
322 /* Update outer/inner flops */
324 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*44);
327 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
328 * Electrostatics interaction: Ewald
329 * VdW interaction: None
330 * Geometry: Particle-Particle
331 * Calculate force/pot: Force
334 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
335 (t_nblist * gmx_restrict nlist,
336 rvec * gmx_restrict xx,
337 rvec * gmx_restrict ff,
338 struct t_forcerec * gmx_restrict fr,
339 t_mdatoms * gmx_restrict mdatoms,
340 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
341 t_nrnb * gmx_restrict nrnb)
343 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
344 * just 0 for non-waters.
345 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
346 * jnr indices corresponding to data put in the four positions in the SIMD register.
348 int i_shift_offset,i_coord_offset,outeriter,inneriter;
349 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
351 int j_coord_offsetA,j_coord_offsetB;
352 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
354 real *shiftvec,*fshift,*x,*f;
355 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
357 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
358 int vdwjidx0A,vdwjidx0B;
359 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
360 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
361 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
364 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
366 __m128d dummy_mask,cutoff_mask;
367 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
368 __m128d one = _mm_set1_pd(1.0);
369 __m128d two = _mm_set1_pd(2.0);
375 jindex = nlist->jindex;
377 shiftidx = nlist->shift;
379 shiftvec = fr->shift_vec[0];
380 fshift = fr->fshift[0];
381 facel = _mm_set1_pd(fr->ic->epsfac);
382 charge = mdatoms->chargeA;
384 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
385 ewtab = fr->ic->tabq_coul_F;
386 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
387 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
389 /* Avoid stupid compiler warnings */
397 /* Start outer loop over neighborlists */
398 for(iidx=0; iidx<nri; iidx++)
400 /* Load shift vector for this list */
401 i_shift_offset = DIM*shiftidx[iidx];
403 /* Load limits for loop over neighbors */
404 j_index_start = jindex[iidx];
405 j_index_end = jindex[iidx+1];
407 /* Get outer coordinate index */
409 i_coord_offset = DIM*inr;
411 /* Load i particle coords and add shift vector */
412 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
414 fix0 = _mm_setzero_pd();
415 fiy0 = _mm_setzero_pd();
416 fiz0 = _mm_setzero_pd();
418 /* Load parameters for i particles */
419 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
421 /* Start inner kernel loop */
422 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
425 /* Get j neighbor index, and coordinate index */
428 j_coord_offsetA = DIM*jnrA;
429 j_coord_offsetB = DIM*jnrB;
431 /* load j atom coordinates */
432 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
435 /* Calculate displacement vector */
436 dx00 = _mm_sub_pd(ix0,jx0);
437 dy00 = _mm_sub_pd(iy0,jy0);
438 dz00 = _mm_sub_pd(iz0,jz0);
440 /* Calculate squared distance and things based on it */
441 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
443 rinv00 = avx128fma_invsqrt_d(rsq00);
445 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
447 /* Load parameters for j particles */
448 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
450 /**************************
451 * CALCULATE INTERACTIONS *
452 **************************/
454 r00 = _mm_mul_pd(rsq00,rinv00);
456 /* Compute parameters for interactions between i and j atoms */
457 qq00 = _mm_mul_pd(iq0,jq0);
459 /* EWALD ELECTROSTATICS */
461 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
462 ewrt = _mm_mul_pd(r00,ewtabscale);
463 ewitab = _mm_cvttpd_epi32(ewrt);
465 eweps = _mm_frcz_pd(ewrt);
467 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
469 twoeweps = _mm_add_pd(eweps,eweps);
470 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
472 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
473 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
477 /* Update vectorial force */
478 fix0 = _mm_macc_pd(dx00,fscal,fix0);
479 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
480 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
482 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
483 _mm_mul_pd(dx00,fscal),
484 _mm_mul_pd(dy00,fscal),
485 _mm_mul_pd(dz00,fscal));
487 /* Inner loop uses 39 flops */
494 j_coord_offsetA = DIM*jnrA;
496 /* load j atom coordinates */
497 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
500 /* Calculate displacement vector */
501 dx00 = _mm_sub_pd(ix0,jx0);
502 dy00 = _mm_sub_pd(iy0,jy0);
503 dz00 = _mm_sub_pd(iz0,jz0);
505 /* Calculate squared distance and things based on it */
506 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
508 rinv00 = avx128fma_invsqrt_d(rsq00);
510 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
512 /* Load parameters for j particles */
513 jq0 = _mm_load_sd(charge+jnrA+0);
515 /**************************
516 * CALCULATE INTERACTIONS *
517 **************************/
519 r00 = _mm_mul_pd(rsq00,rinv00);
521 /* Compute parameters for interactions between i and j atoms */
522 qq00 = _mm_mul_pd(iq0,jq0);
524 /* EWALD ELECTROSTATICS */
526 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
527 ewrt = _mm_mul_pd(r00,ewtabscale);
528 ewitab = _mm_cvttpd_epi32(ewrt);
530 eweps = _mm_frcz_pd(ewrt);
532 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
534 twoeweps = _mm_add_pd(eweps,eweps);
535 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
536 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
537 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
541 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
543 /* Update vectorial force */
544 fix0 = _mm_macc_pd(dx00,fscal,fix0);
545 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
546 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
548 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
549 _mm_mul_pd(dx00,fscal),
550 _mm_mul_pd(dy00,fscal),
551 _mm_mul_pd(dz00,fscal));
553 /* Inner loop uses 39 flops */
556 /* End of innermost loop */
558 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
559 f+i_coord_offset,fshift+i_shift_offset);
561 /* Increment number of inner iterations */
562 inneriter += j_index_end - j_index_start;
564 /* Outer loop uses 7 flops */
567 /* Increment number of outer iterations */
570 /* Update outer/inner flops */
572 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*39);