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_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEw_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;
88 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
90 __m128d dummy_mask,cutoff_mask;
91 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
92 __m128d one = _mm_set1_pd(1.0);
93 __m128d two = _mm_set1_pd(2.0);
99 jindex = nlist->jindex;
101 shiftidx = nlist->shift;
103 shiftvec = fr->shift_vec[0];
104 fshift = fr->fshift[0];
105 facel = _mm_set1_pd(fr->epsfac);
106 charge = mdatoms->chargeA;
108 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
109 ewtab = fr->ic->tabq_coul_FDV0;
110 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
111 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
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 r00 = _mm_mul_pd(rsq00,rinv00);
183 /* Compute parameters for interactions between i and j atoms */
184 qq00 = _mm_mul_pd(iq0,jq0);
186 /* EWALD ELECTROSTATICS */
188 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
189 ewrt = _mm_mul_pd(r00,ewtabscale);
190 ewitab = _mm_cvttpd_epi32(ewrt);
192 eweps = _mm_frcz_pd(ewrt);
194 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
196 twoeweps = _mm_add_pd(eweps,eweps);
197 ewitab = _mm_slli_epi32(ewitab,2);
198 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
199 ewtabD = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
200 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
201 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
202 ewtabFn = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
203 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
204 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
205 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
206 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
207 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
209 /* Update potential sum for this i atom from the interaction with this j atom. */
210 velecsum = _mm_add_pd(velecsum,velec);
214 /* Update vectorial force */
215 fix0 = _mm_macc_pd(dx00,fscal,fix0);
216 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
217 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
219 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
220 _mm_mul_pd(dx00,fscal),
221 _mm_mul_pd(dy00,fscal),
222 _mm_mul_pd(dz00,fscal));
224 /* Inner loop uses 44 flops */
231 j_coord_offsetA = DIM*jnrA;
233 /* load j atom coordinates */
234 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
237 /* Calculate displacement vector */
238 dx00 = _mm_sub_pd(ix0,jx0);
239 dy00 = _mm_sub_pd(iy0,jy0);
240 dz00 = _mm_sub_pd(iz0,jz0);
242 /* Calculate squared distance and things based on it */
243 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
245 rinv00 = gmx_mm_invsqrt_pd(rsq00);
247 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
249 /* Load parameters for j particles */
250 jq0 = _mm_load_sd(charge+jnrA+0);
252 /**************************
253 * CALCULATE INTERACTIONS *
254 **************************/
256 r00 = _mm_mul_pd(rsq00,rinv00);
258 /* Compute parameters for interactions between i and j atoms */
259 qq00 = _mm_mul_pd(iq0,jq0);
261 /* EWALD ELECTROSTATICS */
263 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
264 ewrt = _mm_mul_pd(r00,ewtabscale);
265 ewitab = _mm_cvttpd_epi32(ewrt);
267 eweps = _mm_frcz_pd(ewrt);
269 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
271 twoeweps = _mm_add_pd(eweps,eweps);
272 ewitab = _mm_slli_epi32(ewitab,2);
273 ewtabF = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
274 ewtabD = _mm_setzero_pd();
275 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
276 ewtabV = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
277 ewtabFn = _mm_setzero_pd();
278 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
279 felec = _mm_macc_pd(eweps,ewtabD,ewtabF);
280 velec = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
281 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
282 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
284 /* Update potential sum for this i atom from the interaction with this j atom. */
285 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
286 velecsum = _mm_add_pd(velecsum,velec);
290 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
292 /* Update vectorial force */
293 fix0 = _mm_macc_pd(dx00,fscal,fix0);
294 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
295 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
297 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
298 _mm_mul_pd(dx00,fscal),
299 _mm_mul_pd(dy00,fscal),
300 _mm_mul_pd(dz00,fscal));
302 /* Inner loop uses 44 flops */
305 /* End of innermost loop */
307 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
308 f+i_coord_offset,fshift+i_shift_offset);
311 /* Update potential energies */
312 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
314 /* Increment number of inner iterations */
315 inneriter += j_index_end - j_index_start;
317 /* Outer loop uses 8 flops */
320 /* Increment number of outer iterations */
323 /* Update outer/inner flops */
325 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*44);
328 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
329 * Electrostatics interaction: Ewald
330 * VdW interaction: None
331 * Geometry: Particle-Particle
332 * Calculate force/pot: Force
335 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_double
336 (t_nblist * gmx_restrict nlist,
337 rvec * gmx_restrict xx,
338 rvec * gmx_restrict ff,
339 t_forcerec * gmx_restrict fr,
340 t_mdatoms * gmx_restrict mdatoms,
341 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
342 t_nrnb * gmx_restrict nrnb)
344 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
345 * just 0 for non-waters.
346 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
347 * jnr indices corresponding to data put in the four positions in the SIMD register.
349 int i_shift_offset,i_coord_offset,outeriter,inneriter;
350 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
352 int j_coord_offsetA,j_coord_offsetB;
353 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
355 real *shiftvec,*fshift,*x,*f;
356 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
358 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
359 int vdwjidx0A,vdwjidx0B;
360 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
361 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
362 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
365 __m128d ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
367 __m128d dummy_mask,cutoff_mask;
368 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
369 __m128d one = _mm_set1_pd(1.0);
370 __m128d two = _mm_set1_pd(2.0);
376 jindex = nlist->jindex;
378 shiftidx = nlist->shift;
380 shiftvec = fr->shift_vec[0];
381 fshift = fr->fshift[0];
382 facel = _mm_set1_pd(fr->epsfac);
383 charge = mdatoms->chargeA;
385 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
386 ewtab = fr->ic->tabq_coul_F;
387 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
388 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
390 /* Avoid stupid compiler warnings */
398 /* Start outer loop over neighborlists */
399 for(iidx=0; iidx<nri; iidx++)
401 /* Load shift vector for this list */
402 i_shift_offset = DIM*shiftidx[iidx];
404 /* Load limits for loop over neighbors */
405 j_index_start = jindex[iidx];
406 j_index_end = jindex[iidx+1];
408 /* Get outer coordinate index */
410 i_coord_offset = DIM*inr;
412 /* Load i particle coords and add shift vector */
413 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
415 fix0 = _mm_setzero_pd();
416 fiy0 = _mm_setzero_pd();
417 fiz0 = _mm_setzero_pd();
419 /* Load parameters for i particles */
420 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
422 /* Start inner kernel loop */
423 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
426 /* Get j neighbor index, and coordinate index */
429 j_coord_offsetA = DIM*jnrA;
430 j_coord_offsetB = DIM*jnrB;
432 /* load j atom coordinates */
433 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
436 /* Calculate displacement vector */
437 dx00 = _mm_sub_pd(ix0,jx0);
438 dy00 = _mm_sub_pd(iy0,jy0);
439 dz00 = _mm_sub_pd(iz0,jz0);
441 /* Calculate squared distance and things based on it */
442 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
444 rinv00 = gmx_mm_invsqrt_pd(rsq00);
446 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
448 /* Load parameters for j particles */
449 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
451 /**************************
452 * CALCULATE INTERACTIONS *
453 **************************/
455 r00 = _mm_mul_pd(rsq00,rinv00);
457 /* Compute parameters for interactions between i and j atoms */
458 qq00 = _mm_mul_pd(iq0,jq0);
460 /* EWALD ELECTROSTATICS */
462 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
463 ewrt = _mm_mul_pd(r00,ewtabscale);
464 ewitab = _mm_cvttpd_epi32(ewrt);
466 eweps = _mm_frcz_pd(ewrt);
468 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
470 twoeweps = _mm_add_pd(eweps,eweps);
471 gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
473 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
474 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
478 /* Update vectorial force */
479 fix0 = _mm_macc_pd(dx00,fscal,fix0);
480 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
481 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
483 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
484 _mm_mul_pd(dx00,fscal),
485 _mm_mul_pd(dy00,fscal),
486 _mm_mul_pd(dz00,fscal));
488 /* Inner loop uses 39 flops */
495 j_coord_offsetA = DIM*jnrA;
497 /* load j atom coordinates */
498 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
501 /* Calculate displacement vector */
502 dx00 = _mm_sub_pd(ix0,jx0);
503 dy00 = _mm_sub_pd(iy0,jy0);
504 dz00 = _mm_sub_pd(iz0,jz0);
506 /* Calculate squared distance and things based on it */
507 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
509 rinv00 = gmx_mm_invsqrt_pd(rsq00);
511 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
513 /* Load parameters for j particles */
514 jq0 = _mm_load_sd(charge+jnrA+0);
516 /**************************
517 * CALCULATE INTERACTIONS *
518 **************************/
520 r00 = _mm_mul_pd(rsq00,rinv00);
522 /* Compute parameters for interactions between i and j atoms */
523 qq00 = _mm_mul_pd(iq0,jq0);
525 /* EWALD ELECTROSTATICS */
527 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
528 ewrt = _mm_mul_pd(r00,ewtabscale);
529 ewitab = _mm_cvttpd_epi32(ewrt);
531 eweps = _mm_frcz_pd(ewrt);
533 eweps = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
535 twoeweps = _mm_add_pd(eweps,eweps);
536 gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
537 felec = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
538 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
542 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
544 /* Update vectorial force */
545 fix0 = _mm_macc_pd(dx00,fscal,fix0);
546 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
547 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
549 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
550 _mm_mul_pd(dx00,fscal),
551 _mm_mul_pd(dy00,fscal),
552 _mm_mul_pd(dz00,fscal));
554 /* Inner loop uses 39 flops */
557 /* End of innermost loop */
559 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
560 f+i_coord_offset,fshift+i_shift_offset);
562 /* Increment number of inner iterations */
563 inneriter += j_index_end - j_index_start;
565 /* Outer loop uses 7 flops */
568 /* Increment number of outer iterations */
571 /* Update outer/inner flops */
573 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*39);