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 "types/simple.h"
44 #include "gromacs/math/vec.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_ElecCSTab_VdwNone_GeomP1P1_VF_avx_128_fma_double
52 * Electrostatics interaction: CubicSplineTable
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCSTab_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 __m128i ifour = _mm_set1_epi32(4);
89 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
91 __m128d dummy_mask,cutoff_mask;
92 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
93 __m128d one = _mm_set1_pd(1.0);
94 __m128d two = _mm_set1_pd(2.0);
100 jindex = nlist->jindex;
102 shiftidx = nlist->shift;
104 shiftvec = fr->shift_vec[0];
105 fshift = fr->fshift[0];
106 facel = _mm_set1_pd(fr->epsfac);
107 charge = mdatoms->chargeA;
109 vftab = kernel_data->table_elec->data;
110 vftabscale = _mm_set1_pd(kernel_data->table_elec->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 = gmx_mm_invsqrt_pd(rsq00);
171 /* Load parameters for j particles */
172 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
174 /**************************
175 * CALCULATE INTERACTIONS *
176 **************************/
178 r00 = _mm_mul_pd(rsq00,rinv00);
180 /* Compute parameters for interactions between i and j atoms */
181 qq00 = _mm_mul_pd(iq0,jq0);
183 /* Calculate table index by multiplying r with table scale and truncate to integer */
184 rt = _mm_mul_pd(r00,vftabscale);
185 vfitab = _mm_cvttpd_epi32(rt);
187 vfeps = _mm_frcz_pd(rt);
189 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
191 twovfeps = _mm_add_pd(vfeps,vfeps);
192 vfitab = _mm_slli_epi32(vfitab,2);
194 /* CUBIC SPLINE TABLE ELECTROSTATICS */
195 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
196 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
197 GMX_MM_TRANSPOSE2_PD(Y,F);
198 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
199 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
200 GMX_MM_TRANSPOSE2_PD(G,H);
201 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
202 VV = _mm_macc_pd(vfeps,Fp,Y);
203 velec = _mm_mul_pd(qq00,VV);
204 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
205 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
207 /* Update potential sum for this i atom from the interaction with this j atom. */
208 velecsum = _mm_add_pd(velecsum,velec);
212 /* Update vectorial force */
213 fix0 = _mm_macc_pd(dx00,fscal,fix0);
214 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
215 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
217 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
218 _mm_mul_pd(dx00,fscal),
219 _mm_mul_pd(dy00,fscal),
220 _mm_mul_pd(dz00,fscal));
222 /* Inner loop uses 46 flops */
229 j_coord_offsetA = DIM*jnrA;
231 /* load j atom coordinates */
232 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
235 /* Calculate displacement vector */
236 dx00 = _mm_sub_pd(ix0,jx0);
237 dy00 = _mm_sub_pd(iy0,jy0);
238 dz00 = _mm_sub_pd(iz0,jz0);
240 /* Calculate squared distance and things based on it */
241 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
243 rinv00 = gmx_mm_invsqrt_pd(rsq00);
245 /* Load parameters for j particles */
246 jq0 = _mm_load_sd(charge+jnrA+0);
248 /**************************
249 * CALCULATE INTERACTIONS *
250 **************************/
252 r00 = _mm_mul_pd(rsq00,rinv00);
254 /* Compute parameters for interactions between i and j atoms */
255 qq00 = _mm_mul_pd(iq0,jq0);
257 /* Calculate table index by multiplying r with table scale and truncate to integer */
258 rt = _mm_mul_pd(r00,vftabscale);
259 vfitab = _mm_cvttpd_epi32(rt);
261 vfeps = _mm_frcz_pd(rt);
263 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
265 twovfeps = _mm_add_pd(vfeps,vfeps);
266 vfitab = _mm_slli_epi32(vfitab,2);
268 /* CUBIC SPLINE TABLE ELECTROSTATICS */
269 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
270 F = _mm_setzero_pd();
271 GMX_MM_TRANSPOSE2_PD(Y,F);
272 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
273 H = _mm_setzero_pd();
274 GMX_MM_TRANSPOSE2_PD(G,H);
275 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
276 VV = _mm_macc_pd(vfeps,Fp,Y);
277 velec = _mm_mul_pd(qq00,VV);
278 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
279 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
281 /* Update potential sum for this i atom from the interaction with this j atom. */
282 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
283 velecsum = _mm_add_pd(velecsum,velec);
287 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
289 /* Update vectorial force */
290 fix0 = _mm_macc_pd(dx00,fscal,fix0);
291 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
292 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
294 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
295 _mm_mul_pd(dx00,fscal),
296 _mm_mul_pd(dy00,fscal),
297 _mm_mul_pd(dz00,fscal));
299 /* Inner loop uses 46 flops */
302 /* End of innermost loop */
304 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
305 f+i_coord_offset,fshift+i_shift_offset);
308 /* Update potential energies */
309 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
311 /* Increment number of inner iterations */
312 inneriter += j_index_end - j_index_start;
314 /* Outer loop uses 8 flops */
317 /* Increment number of outer iterations */
320 /* Update outer/inner flops */
322 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*46);
325 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_avx_128_fma_double
326 * Electrostatics interaction: CubicSplineTable
327 * VdW interaction: None
328 * Geometry: Particle-Particle
329 * Calculate force/pot: Force
332 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_avx_128_fma_double
333 (t_nblist * gmx_restrict nlist,
334 rvec * gmx_restrict xx,
335 rvec * gmx_restrict ff,
336 t_forcerec * gmx_restrict fr,
337 t_mdatoms * gmx_restrict mdatoms,
338 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
339 t_nrnb * gmx_restrict nrnb)
341 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
342 * just 0 for non-waters.
343 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
344 * jnr indices corresponding to data put in the four positions in the SIMD register.
346 int i_shift_offset,i_coord_offset,outeriter,inneriter;
347 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
349 int j_coord_offsetA,j_coord_offsetB;
350 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
352 real *shiftvec,*fshift,*x,*f;
353 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
355 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
356 int vdwjidx0A,vdwjidx0B;
357 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
358 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
359 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
362 __m128i ifour = _mm_set1_epi32(4);
363 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
365 __m128d dummy_mask,cutoff_mask;
366 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
367 __m128d one = _mm_set1_pd(1.0);
368 __m128d two = _mm_set1_pd(2.0);
374 jindex = nlist->jindex;
376 shiftidx = nlist->shift;
378 shiftvec = fr->shift_vec[0];
379 fshift = fr->fshift[0];
380 facel = _mm_set1_pd(fr->epsfac);
381 charge = mdatoms->chargeA;
383 vftab = kernel_data->table_elec->data;
384 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
386 /* Avoid stupid compiler warnings */
394 /* Start outer loop over neighborlists */
395 for(iidx=0; iidx<nri; iidx++)
397 /* Load shift vector for this list */
398 i_shift_offset = DIM*shiftidx[iidx];
400 /* Load limits for loop over neighbors */
401 j_index_start = jindex[iidx];
402 j_index_end = jindex[iidx+1];
404 /* Get outer coordinate index */
406 i_coord_offset = DIM*inr;
408 /* Load i particle coords and add shift vector */
409 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
411 fix0 = _mm_setzero_pd();
412 fiy0 = _mm_setzero_pd();
413 fiz0 = _mm_setzero_pd();
415 /* Load parameters for i particles */
416 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
418 /* Start inner kernel loop */
419 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
422 /* Get j neighbor index, and coordinate index */
425 j_coord_offsetA = DIM*jnrA;
426 j_coord_offsetB = DIM*jnrB;
428 /* load j atom coordinates */
429 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
432 /* Calculate displacement vector */
433 dx00 = _mm_sub_pd(ix0,jx0);
434 dy00 = _mm_sub_pd(iy0,jy0);
435 dz00 = _mm_sub_pd(iz0,jz0);
437 /* Calculate squared distance and things based on it */
438 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
440 rinv00 = gmx_mm_invsqrt_pd(rsq00);
442 /* Load parameters for j particles */
443 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
445 /**************************
446 * CALCULATE INTERACTIONS *
447 **************************/
449 r00 = _mm_mul_pd(rsq00,rinv00);
451 /* Compute parameters for interactions between i and j atoms */
452 qq00 = _mm_mul_pd(iq0,jq0);
454 /* Calculate table index by multiplying r with table scale and truncate to integer */
455 rt = _mm_mul_pd(r00,vftabscale);
456 vfitab = _mm_cvttpd_epi32(rt);
458 vfeps = _mm_frcz_pd(rt);
460 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
462 twovfeps = _mm_add_pd(vfeps,vfeps);
463 vfitab = _mm_slli_epi32(vfitab,2);
465 /* CUBIC SPLINE TABLE ELECTROSTATICS */
466 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
467 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
468 GMX_MM_TRANSPOSE2_PD(Y,F);
469 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
470 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
471 GMX_MM_TRANSPOSE2_PD(G,H);
472 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
473 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
474 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
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 42 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 /* Load parameters for j particles */
512 jq0 = _mm_load_sd(charge+jnrA+0);
514 /**************************
515 * CALCULATE INTERACTIONS *
516 **************************/
518 r00 = _mm_mul_pd(rsq00,rinv00);
520 /* Compute parameters for interactions between i and j atoms */
521 qq00 = _mm_mul_pd(iq0,jq0);
523 /* Calculate table index by multiplying r with table scale and truncate to integer */
524 rt = _mm_mul_pd(r00,vftabscale);
525 vfitab = _mm_cvttpd_epi32(rt);
527 vfeps = _mm_frcz_pd(rt);
529 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
531 twovfeps = _mm_add_pd(vfeps,vfeps);
532 vfitab = _mm_slli_epi32(vfitab,2);
534 /* CUBIC SPLINE TABLE ELECTROSTATICS */
535 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
536 F = _mm_setzero_pd();
537 GMX_MM_TRANSPOSE2_PD(Y,F);
538 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
539 H = _mm_setzero_pd();
540 GMX_MM_TRANSPOSE2_PD(G,H);
541 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(vfeps,H,G),F);
542 FF = _mm_macc_pd(_mm_macc_pd(twovfeps,H,G),vfeps,Fp);
543 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
547 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
549 /* Update vectorial force */
550 fix0 = _mm_macc_pd(dx00,fscal,fix0);
551 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
552 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
554 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
555 _mm_mul_pd(dx00,fscal),
556 _mm_mul_pd(dy00,fscal),
557 _mm_mul_pd(dz00,fscal));
559 /* Inner loop uses 42 flops */
562 /* End of innermost loop */
564 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
565 f+i_coord_offset,fshift+i_shift_offset);
567 /* Increment number of inner iterations */
568 inneriter += j_index_end - j_index_start;
570 /* Outer loop uses 7 flops */
573 /* Increment number of outer iterations */
576 /* Update outer/inner flops */
578 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*42);