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 sse4_1_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_sse4_1_double.h"
50 #include "kernelutil_x86_sse4_1_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_VF_sse4_1_double
54 * Electrostatics interaction: CubicSplineTable
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_VF_sse4_1_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 __m128i ifour = _mm_set1_epi32(4);
91 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
93 __m128d dummy_mask,cutoff_mask;
94 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
95 __m128d one = _mm_set1_pd(1.0);
96 __m128d two = _mm_set1_pd(2.0);
102 jindex = nlist->jindex;
104 shiftidx = nlist->shift;
106 shiftvec = fr->shift_vec[0];
107 fshift = fr->fshift[0];
108 facel = _mm_set1_pd(fr->epsfac);
109 charge = mdatoms->chargeA;
111 vftab = kernel_data->table_elec->data;
112 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
114 /* Avoid stupid compiler warnings */
122 /* Start outer loop over neighborlists */
123 for(iidx=0; iidx<nri; iidx++)
125 /* Load shift vector for this list */
126 i_shift_offset = DIM*shiftidx[iidx];
128 /* Load limits for loop over neighbors */
129 j_index_start = jindex[iidx];
130 j_index_end = jindex[iidx+1];
132 /* Get outer coordinate index */
134 i_coord_offset = DIM*inr;
136 /* Load i particle coords and add shift vector */
137 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
139 fix0 = _mm_setzero_pd();
140 fiy0 = _mm_setzero_pd();
141 fiz0 = _mm_setzero_pd();
143 /* Load parameters for i particles */
144 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
146 /* Reset potential sums */
147 velecsum = _mm_setzero_pd();
149 /* Start inner kernel loop */
150 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
153 /* Get j neighbor index, and coordinate index */
156 j_coord_offsetA = DIM*jnrA;
157 j_coord_offsetB = DIM*jnrB;
159 /* load j atom coordinates */
160 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
163 /* Calculate displacement vector */
164 dx00 = _mm_sub_pd(ix0,jx0);
165 dy00 = _mm_sub_pd(iy0,jy0);
166 dz00 = _mm_sub_pd(iz0,jz0);
168 /* Calculate squared distance and things based on it */
169 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
171 rinv00 = gmx_mm_invsqrt_pd(rsq00);
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 /* Calculate table index by multiplying r with table scale and truncate to integer */
186 rt = _mm_mul_pd(r00,vftabscale);
187 vfitab = _mm_cvttpd_epi32(rt);
188 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
189 vfitab = _mm_slli_epi32(vfitab,2);
191 /* CUBIC SPLINE TABLE ELECTROSTATICS */
192 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
193 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
194 GMX_MM_TRANSPOSE2_PD(Y,F);
195 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
196 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
197 GMX_MM_TRANSPOSE2_PD(G,H);
198 Heps = _mm_mul_pd(vfeps,H);
199 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
200 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
201 velec = _mm_mul_pd(qq00,VV);
202 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
203 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
205 /* Update potential sum for this i atom from the interaction with this j atom. */
206 velecsum = _mm_add_pd(velecsum,velec);
210 /* Calculate temporary vectorial force */
211 tx = _mm_mul_pd(fscal,dx00);
212 ty = _mm_mul_pd(fscal,dy00);
213 tz = _mm_mul_pd(fscal,dz00);
215 /* Update vectorial force */
216 fix0 = _mm_add_pd(fix0,tx);
217 fiy0 = _mm_add_pd(fiy0,ty);
218 fiz0 = _mm_add_pd(fiz0,tz);
220 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
222 /* Inner loop uses 43 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);
260 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
261 vfitab = _mm_slli_epi32(vfitab,2);
263 /* CUBIC SPLINE TABLE ELECTROSTATICS */
264 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
265 F = _mm_setzero_pd();
266 GMX_MM_TRANSPOSE2_PD(Y,F);
267 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
268 H = _mm_setzero_pd();
269 GMX_MM_TRANSPOSE2_PD(G,H);
270 Heps = _mm_mul_pd(vfeps,H);
271 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
272 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
273 velec = _mm_mul_pd(qq00,VV);
274 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
275 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
277 /* Update potential sum for this i atom from the interaction with this j atom. */
278 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
279 velecsum = _mm_add_pd(velecsum,velec);
283 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
285 /* Calculate temporary vectorial force */
286 tx = _mm_mul_pd(fscal,dx00);
287 ty = _mm_mul_pd(fscal,dy00);
288 tz = _mm_mul_pd(fscal,dz00);
290 /* Update vectorial force */
291 fix0 = _mm_add_pd(fix0,tx);
292 fiy0 = _mm_add_pd(fiy0,ty);
293 fiz0 = _mm_add_pd(fiz0,tz);
295 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
297 /* Inner loop uses 43 flops */
300 /* End of innermost loop */
302 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
303 f+i_coord_offset,fshift+i_shift_offset);
306 /* Update potential energies */
307 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
309 /* Increment number of inner iterations */
310 inneriter += j_index_end - j_index_start;
312 /* Outer loop uses 8 flops */
315 /* Increment number of outer iterations */
318 /* Update outer/inner flops */
320 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*43);
323 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse4_1_double
324 * Electrostatics interaction: CubicSplineTable
325 * VdW interaction: None
326 * Geometry: Particle-Particle
327 * Calculate force/pot: Force
330 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse4_1_double
331 (t_nblist * gmx_restrict nlist,
332 rvec * gmx_restrict xx,
333 rvec * gmx_restrict ff,
334 t_forcerec * gmx_restrict fr,
335 t_mdatoms * gmx_restrict mdatoms,
336 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
337 t_nrnb * gmx_restrict nrnb)
339 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
340 * just 0 for non-waters.
341 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
342 * jnr indices corresponding to data put in the four positions in the SIMD register.
344 int i_shift_offset,i_coord_offset,outeriter,inneriter;
345 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
347 int j_coord_offsetA,j_coord_offsetB;
348 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
350 real *shiftvec,*fshift,*x,*f;
351 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
353 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
354 int vdwjidx0A,vdwjidx0B;
355 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
356 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
357 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
360 __m128i ifour = _mm_set1_epi32(4);
361 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
363 __m128d dummy_mask,cutoff_mask;
364 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
365 __m128d one = _mm_set1_pd(1.0);
366 __m128d two = _mm_set1_pd(2.0);
372 jindex = nlist->jindex;
374 shiftidx = nlist->shift;
376 shiftvec = fr->shift_vec[0];
377 fshift = fr->fshift[0];
378 facel = _mm_set1_pd(fr->epsfac);
379 charge = mdatoms->chargeA;
381 vftab = kernel_data->table_elec->data;
382 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
384 /* Avoid stupid compiler warnings */
392 /* Start outer loop over neighborlists */
393 for(iidx=0; iidx<nri; iidx++)
395 /* Load shift vector for this list */
396 i_shift_offset = DIM*shiftidx[iidx];
398 /* Load limits for loop over neighbors */
399 j_index_start = jindex[iidx];
400 j_index_end = jindex[iidx+1];
402 /* Get outer coordinate index */
404 i_coord_offset = DIM*inr;
406 /* Load i particle coords and add shift vector */
407 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
409 fix0 = _mm_setzero_pd();
410 fiy0 = _mm_setzero_pd();
411 fiz0 = _mm_setzero_pd();
413 /* Load parameters for i particles */
414 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
416 /* Start inner kernel loop */
417 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
420 /* Get j neighbor index, and coordinate index */
423 j_coord_offsetA = DIM*jnrA;
424 j_coord_offsetB = DIM*jnrB;
426 /* load j atom coordinates */
427 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
430 /* Calculate displacement vector */
431 dx00 = _mm_sub_pd(ix0,jx0);
432 dy00 = _mm_sub_pd(iy0,jy0);
433 dz00 = _mm_sub_pd(iz0,jz0);
435 /* Calculate squared distance and things based on it */
436 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
438 rinv00 = gmx_mm_invsqrt_pd(rsq00);
440 /* Load parameters for j particles */
441 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
443 /**************************
444 * CALCULATE INTERACTIONS *
445 **************************/
447 r00 = _mm_mul_pd(rsq00,rinv00);
449 /* Compute parameters for interactions between i and j atoms */
450 qq00 = _mm_mul_pd(iq0,jq0);
452 /* Calculate table index by multiplying r with table scale and truncate to integer */
453 rt = _mm_mul_pd(r00,vftabscale);
454 vfitab = _mm_cvttpd_epi32(rt);
455 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
456 vfitab = _mm_slli_epi32(vfitab,2);
458 /* CUBIC SPLINE TABLE ELECTROSTATICS */
459 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
460 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
461 GMX_MM_TRANSPOSE2_PD(Y,F);
462 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
463 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
464 GMX_MM_TRANSPOSE2_PD(G,H);
465 Heps = _mm_mul_pd(vfeps,H);
466 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
467 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
468 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
472 /* Calculate temporary vectorial force */
473 tx = _mm_mul_pd(fscal,dx00);
474 ty = _mm_mul_pd(fscal,dy00);
475 tz = _mm_mul_pd(fscal,dz00);
477 /* Update vectorial force */
478 fix0 = _mm_add_pd(fix0,tx);
479 fiy0 = _mm_add_pd(fiy0,ty);
480 fiz0 = _mm_add_pd(fiz0,tz);
482 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
484 /* Inner loop uses 39 flops */
491 j_coord_offsetA = DIM*jnrA;
493 /* load j atom coordinates */
494 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
497 /* Calculate displacement vector */
498 dx00 = _mm_sub_pd(ix0,jx0);
499 dy00 = _mm_sub_pd(iy0,jy0);
500 dz00 = _mm_sub_pd(iz0,jz0);
502 /* Calculate squared distance and things based on it */
503 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
505 rinv00 = gmx_mm_invsqrt_pd(rsq00);
507 /* Load parameters for j particles */
508 jq0 = _mm_load_sd(charge+jnrA+0);
510 /**************************
511 * CALCULATE INTERACTIONS *
512 **************************/
514 r00 = _mm_mul_pd(rsq00,rinv00);
516 /* Compute parameters for interactions between i and j atoms */
517 qq00 = _mm_mul_pd(iq0,jq0);
519 /* Calculate table index by multiplying r with table scale and truncate to integer */
520 rt = _mm_mul_pd(r00,vftabscale);
521 vfitab = _mm_cvttpd_epi32(rt);
522 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
523 vfitab = _mm_slli_epi32(vfitab,2);
525 /* CUBIC SPLINE TABLE ELECTROSTATICS */
526 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
527 F = _mm_setzero_pd();
528 GMX_MM_TRANSPOSE2_PD(Y,F);
529 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
530 H = _mm_setzero_pd();
531 GMX_MM_TRANSPOSE2_PD(G,H);
532 Heps = _mm_mul_pd(vfeps,H);
533 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
534 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
535 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
539 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
541 /* Calculate temporary vectorial force */
542 tx = _mm_mul_pd(fscal,dx00);
543 ty = _mm_mul_pd(fscal,dy00);
544 tz = _mm_mul_pd(fscal,dz00);
546 /* Update vectorial force */
547 fix0 = _mm_add_pd(fix0,tx);
548 fiy0 = _mm_add_pd(fiy0,ty);
549 fiz0 = _mm_add_pd(fiz0,tz);
551 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
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);