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 sse2_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_VF_sse2_double
51 * Electrostatics interaction: CubicSplineTable
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_VF_sse2_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 __m128i ifour = _mm_set1_epi32(4);
88 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
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->ic->epsfac);
106 charge = mdatoms->chargeA;
108 vftab = kernel_data->table_elec->data;
109 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
111 /* Avoid stupid compiler warnings */
119 /* Start outer loop over neighborlists */
120 for(iidx=0; iidx<nri; iidx++)
122 /* Load shift vector for this list */
123 i_shift_offset = DIM*shiftidx[iidx];
125 /* Load limits for loop over neighbors */
126 j_index_start = jindex[iidx];
127 j_index_end = jindex[iidx+1];
129 /* Get outer coordinate index */
131 i_coord_offset = DIM*inr;
133 /* Load i particle coords and add shift vector */
134 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
136 fix0 = _mm_setzero_pd();
137 fiy0 = _mm_setzero_pd();
138 fiz0 = _mm_setzero_pd();
140 /* Load parameters for i particles */
141 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
143 /* Reset potential sums */
144 velecsum = _mm_setzero_pd();
146 /* Start inner kernel loop */
147 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
150 /* Get j neighbor index, and coordinate index */
153 j_coord_offsetA = DIM*jnrA;
154 j_coord_offsetB = DIM*jnrB;
156 /* load j atom coordinates */
157 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
160 /* Calculate displacement vector */
161 dx00 = _mm_sub_pd(ix0,jx0);
162 dy00 = _mm_sub_pd(iy0,jy0);
163 dz00 = _mm_sub_pd(iz0,jz0);
165 /* Calculate squared distance and things based on it */
166 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
168 rinv00 = sse2_invsqrt_d(rsq00);
170 /* Load parameters for j particles */
171 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
173 /**************************
174 * CALCULATE INTERACTIONS *
175 **************************/
177 r00 = _mm_mul_pd(rsq00,rinv00);
179 /* Compute parameters for interactions between i and j atoms */
180 qq00 = _mm_mul_pd(iq0,jq0);
182 /* Calculate table index by multiplying r with table scale and truncate to integer */
183 rt = _mm_mul_pd(r00,vftabscale);
184 vfitab = _mm_cvttpd_epi32(rt);
185 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
186 vfitab = _mm_slli_epi32(vfitab,2);
188 /* CUBIC SPLINE TABLE ELECTROSTATICS */
189 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
190 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
191 GMX_MM_TRANSPOSE2_PD(Y,F);
192 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
193 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
194 GMX_MM_TRANSPOSE2_PD(G,H);
195 Heps = _mm_mul_pd(vfeps,H);
196 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
197 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
198 velec = _mm_mul_pd(qq00,VV);
199 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
200 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
202 /* Update potential sum for this i atom from the interaction with this j atom. */
203 velecsum = _mm_add_pd(velecsum,velec);
207 /* Calculate temporary vectorial force */
208 tx = _mm_mul_pd(fscal,dx00);
209 ty = _mm_mul_pd(fscal,dy00);
210 tz = _mm_mul_pd(fscal,dz00);
212 /* Update vectorial force */
213 fix0 = _mm_add_pd(fix0,tx);
214 fiy0 = _mm_add_pd(fiy0,ty);
215 fiz0 = _mm_add_pd(fiz0,tz);
217 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
219 /* Inner loop uses 43 flops */
226 j_coord_offsetA = DIM*jnrA;
228 /* load j atom coordinates */
229 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
232 /* Calculate displacement vector */
233 dx00 = _mm_sub_pd(ix0,jx0);
234 dy00 = _mm_sub_pd(iy0,jy0);
235 dz00 = _mm_sub_pd(iz0,jz0);
237 /* Calculate squared distance and things based on it */
238 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
240 rinv00 = sse2_invsqrt_d(rsq00);
242 /* Load parameters for j particles */
243 jq0 = _mm_load_sd(charge+jnrA+0);
245 /**************************
246 * CALCULATE INTERACTIONS *
247 **************************/
249 r00 = _mm_mul_pd(rsq00,rinv00);
251 /* Compute parameters for interactions between i and j atoms */
252 qq00 = _mm_mul_pd(iq0,jq0);
254 /* Calculate table index by multiplying r with table scale and truncate to integer */
255 rt = _mm_mul_pd(r00,vftabscale);
256 vfitab = _mm_cvttpd_epi32(rt);
257 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
258 vfitab = _mm_slli_epi32(vfitab,2);
260 /* CUBIC SPLINE TABLE ELECTROSTATICS */
261 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
262 F = _mm_setzero_pd();
263 GMX_MM_TRANSPOSE2_PD(Y,F);
264 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
265 H = _mm_setzero_pd();
266 GMX_MM_TRANSPOSE2_PD(G,H);
267 Heps = _mm_mul_pd(vfeps,H);
268 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
269 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
270 velec = _mm_mul_pd(qq00,VV);
271 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
272 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
274 /* Update potential sum for this i atom from the interaction with this j atom. */
275 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
276 velecsum = _mm_add_pd(velecsum,velec);
280 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
282 /* Calculate temporary vectorial force */
283 tx = _mm_mul_pd(fscal,dx00);
284 ty = _mm_mul_pd(fscal,dy00);
285 tz = _mm_mul_pd(fscal,dz00);
287 /* Update vectorial force */
288 fix0 = _mm_add_pd(fix0,tx);
289 fiy0 = _mm_add_pd(fiy0,ty);
290 fiz0 = _mm_add_pd(fiz0,tz);
292 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
294 /* Inner loop uses 43 flops */
297 /* End of innermost loop */
299 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
300 f+i_coord_offset,fshift+i_shift_offset);
303 /* Update potential energies */
304 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
306 /* Increment number of inner iterations */
307 inneriter += j_index_end - j_index_start;
309 /* Outer loop uses 8 flops */
312 /* Increment number of outer iterations */
315 /* Update outer/inner flops */
317 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*43);
320 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse2_double
321 * Electrostatics interaction: CubicSplineTable
322 * VdW interaction: None
323 * Geometry: Particle-Particle
324 * Calculate force/pot: Force
327 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse2_double
328 (t_nblist * gmx_restrict nlist,
329 rvec * gmx_restrict xx,
330 rvec * gmx_restrict ff,
331 struct t_forcerec * gmx_restrict fr,
332 t_mdatoms * gmx_restrict mdatoms,
333 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
334 t_nrnb * gmx_restrict nrnb)
336 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
337 * just 0 for non-waters.
338 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
339 * jnr indices corresponding to data put in the four positions in the SIMD register.
341 int i_shift_offset,i_coord_offset,outeriter,inneriter;
342 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
344 int j_coord_offsetA,j_coord_offsetB;
345 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
347 real *shiftvec,*fshift,*x,*f;
348 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
350 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
351 int vdwjidx0A,vdwjidx0B;
352 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
353 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
354 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
357 __m128i ifour = _mm_set1_epi32(4);
358 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
360 __m128d dummy_mask,cutoff_mask;
361 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
362 __m128d one = _mm_set1_pd(1.0);
363 __m128d two = _mm_set1_pd(2.0);
369 jindex = nlist->jindex;
371 shiftidx = nlist->shift;
373 shiftvec = fr->shift_vec[0];
374 fshift = fr->fshift[0];
375 facel = _mm_set1_pd(fr->ic->epsfac);
376 charge = mdatoms->chargeA;
378 vftab = kernel_data->table_elec->data;
379 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
381 /* Avoid stupid compiler warnings */
389 /* Start outer loop over neighborlists */
390 for(iidx=0; iidx<nri; iidx++)
392 /* Load shift vector for this list */
393 i_shift_offset = DIM*shiftidx[iidx];
395 /* Load limits for loop over neighbors */
396 j_index_start = jindex[iidx];
397 j_index_end = jindex[iidx+1];
399 /* Get outer coordinate index */
401 i_coord_offset = DIM*inr;
403 /* Load i particle coords and add shift vector */
404 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
406 fix0 = _mm_setzero_pd();
407 fiy0 = _mm_setzero_pd();
408 fiz0 = _mm_setzero_pd();
410 /* Load parameters for i particles */
411 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
413 /* Start inner kernel loop */
414 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
417 /* Get j neighbor index, and coordinate index */
420 j_coord_offsetA = DIM*jnrA;
421 j_coord_offsetB = DIM*jnrB;
423 /* load j atom coordinates */
424 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
427 /* Calculate displacement vector */
428 dx00 = _mm_sub_pd(ix0,jx0);
429 dy00 = _mm_sub_pd(iy0,jy0);
430 dz00 = _mm_sub_pd(iz0,jz0);
432 /* Calculate squared distance and things based on it */
433 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
435 rinv00 = sse2_invsqrt_d(rsq00);
437 /* Load parameters for j particles */
438 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
440 /**************************
441 * CALCULATE INTERACTIONS *
442 **************************/
444 r00 = _mm_mul_pd(rsq00,rinv00);
446 /* Compute parameters for interactions between i and j atoms */
447 qq00 = _mm_mul_pd(iq0,jq0);
449 /* Calculate table index by multiplying r with table scale and truncate to integer */
450 rt = _mm_mul_pd(r00,vftabscale);
451 vfitab = _mm_cvttpd_epi32(rt);
452 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
453 vfitab = _mm_slli_epi32(vfitab,2);
455 /* CUBIC SPLINE TABLE ELECTROSTATICS */
456 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
457 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
458 GMX_MM_TRANSPOSE2_PD(Y,F);
459 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
460 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
461 GMX_MM_TRANSPOSE2_PD(G,H);
462 Heps = _mm_mul_pd(vfeps,H);
463 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
464 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
465 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
469 /* Calculate temporary vectorial force */
470 tx = _mm_mul_pd(fscal,dx00);
471 ty = _mm_mul_pd(fscal,dy00);
472 tz = _mm_mul_pd(fscal,dz00);
474 /* Update vectorial force */
475 fix0 = _mm_add_pd(fix0,tx);
476 fiy0 = _mm_add_pd(fiy0,ty);
477 fiz0 = _mm_add_pd(fiz0,tz);
479 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
481 /* Inner loop uses 39 flops */
488 j_coord_offsetA = DIM*jnrA;
490 /* load j atom coordinates */
491 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
494 /* Calculate displacement vector */
495 dx00 = _mm_sub_pd(ix0,jx0);
496 dy00 = _mm_sub_pd(iy0,jy0);
497 dz00 = _mm_sub_pd(iz0,jz0);
499 /* Calculate squared distance and things based on it */
500 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
502 rinv00 = sse2_invsqrt_d(rsq00);
504 /* Load parameters for j particles */
505 jq0 = _mm_load_sd(charge+jnrA+0);
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 r00 = _mm_mul_pd(rsq00,rinv00);
513 /* Compute parameters for interactions between i and j atoms */
514 qq00 = _mm_mul_pd(iq0,jq0);
516 /* Calculate table index by multiplying r with table scale and truncate to integer */
517 rt = _mm_mul_pd(r00,vftabscale);
518 vfitab = _mm_cvttpd_epi32(rt);
519 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
520 vfitab = _mm_slli_epi32(vfitab,2);
522 /* CUBIC SPLINE TABLE ELECTROSTATICS */
523 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
524 F = _mm_setzero_pd();
525 GMX_MM_TRANSPOSE2_PD(Y,F);
526 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
527 H = _mm_setzero_pd();
528 GMX_MM_TRANSPOSE2_PD(G,H);
529 Heps = _mm_mul_pd(vfeps,H);
530 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
531 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
532 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
536 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
538 /* Calculate temporary vectorial force */
539 tx = _mm_mul_pd(fscal,dx00);
540 ty = _mm_mul_pd(fscal,dy00);
541 tz = _mm_mul_pd(fscal,dz00);
543 /* Update vectorial force */
544 fix0 = _mm_add_pd(fix0,tx);
545 fiy0 = _mm_add_pd(fiy0,ty);
546 fiz0 = _mm_add_pd(fiz0,tz);
548 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
550 /* Inner loop uses 39 flops */
553 /* End of innermost loop */
555 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
556 f+i_coord_offset,fshift+i_shift_offset);
558 /* Increment number of inner iterations */
559 inneriter += j_index_end - j_index_start;
561 /* Outer loop uses 7 flops */
564 /* Increment number of outer iterations */
567 /* Update outer/inner flops */
569 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*39);