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.
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_sse4_1_double.h"
48 #include "kernelutil_x86_sse4_1_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_VF_sse4_1_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_sse4_1_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;
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);
186 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
187 vfitab = _mm_slli_epi32(vfitab,2);
189 /* CUBIC SPLINE TABLE ELECTROSTATICS */
190 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
191 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
192 GMX_MM_TRANSPOSE2_PD(Y,F);
193 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
194 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
195 GMX_MM_TRANSPOSE2_PD(G,H);
196 Heps = _mm_mul_pd(vfeps,H);
197 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
198 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
199 velec = _mm_mul_pd(qq00,VV);
200 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
201 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
203 /* Update potential sum for this i atom from the interaction with this j atom. */
204 velecsum = _mm_add_pd(velecsum,velec);
208 /* Calculate temporary vectorial force */
209 tx = _mm_mul_pd(fscal,dx00);
210 ty = _mm_mul_pd(fscal,dy00);
211 tz = _mm_mul_pd(fscal,dz00);
213 /* Update vectorial force */
214 fix0 = _mm_add_pd(fix0,tx);
215 fiy0 = _mm_add_pd(fiy0,ty);
216 fiz0 = _mm_add_pd(fiz0,tz);
218 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
220 /* Inner loop uses 43 flops */
227 j_coord_offsetA = DIM*jnrA;
229 /* load j atom coordinates */
230 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
233 /* Calculate displacement vector */
234 dx00 = _mm_sub_pd(ix0,jx0);
235 dy00 = _mm_sub_pd(iy0,jy0);
236 dz00 = _mm_sub_pd(iz0,jz0);
238 /* Calculate squared distance and things based on it */
239 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
241 rinv00 = gmx_mm_invsqrt_pd(rsq00);
243 /* Load parameters for j particles */
244 jq0 = _mm_load_sd(charge+jnrA+0);
246 /**************************
247 * CALCULATE INTERACTIONS *
248 **************************/
250 r00 = _mm_mul_pd(rsq00,rinv00);
252 /* Compute parameters for interactions between i and j atoms */
253 qq00 = _mm_mul_pd(iq0,jq0);
255 /* Calculate table index by multiplying r with table scale and truncate to integer */
256 rt = _mm_mul_pd(r00,vftabscale);
257 vfitab = _mm_cvttpd_epi32(rt);
258 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
259 vfitab = _mm_slli_epi32(vfitab,2);
261 /* CUBIC SPLINE TABLE ELECTROSTATICS */
262 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
263 F = _mm_setzero_pd();
264 GMX_MM_TRANSPOSE2_PD(Y,F);
265 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
266 H = _mm_setzero_pd();
267 GMX_MM_TRANSPOSE2_PD(G,H);
268 Heps = _mm_mul_pd(vfeps,H);
269 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
270 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
271 velec = _mm_mul_pd(qq00,VV);
272 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
273 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
277 velecsum = _mm_add_pd(velecsum,velec);
281 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
283 /* Calculate temporary vectorial force */
284 tx = _mm_mul_pd(fscal,dx00);
285 ty = _mm_mul_pd(fscal,dy00);
286 tz = _mm_mul_pd(fscal,dz00);
288 /* Update vectorial force */
289 fix0 = _mm_add_pd(fix0,tx);
290 fiy0 = _mm_add_pd(fiy0,ty);
291 fiz0 = _mm_add_pd(fiz0,tz);
293 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
295 /* Inner loop uses 43 flops */
298 /* End of innermost loop */
300 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
301 f+i_coord_offset,fshift+i_shift_offset);
304 /* Update potential energies */
305 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
307 /* Increment number of inner iterations */
308 inneriter += j_index_end - j_index_start;
310 /* Outer loop uses 8 flops */
313 /* Increment number of outer iterations */
316 /* Update outer/inner flops */
318 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*43);
321 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse4_1_double
322 * Electrostatics interaction: CubicSplineTable
323 * VdW interaction: None
324 * Geometry: Particle-Particle
325 * Calculate force/pot: Force
328 nb_kernel_ElecCSTab_VdwNone_GeomP1P1_F_sse4_1_double
329 (t_nblist * gmx_restrict nlist,
330 rvec * gmx_restrict xx,
331 rvec * gmx_restrict ff,
332 t_forcerec * gmx_restrict fr,
333 t_mdatoms * gmx_restrict mdatoms,
334 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
335 t_nrnb * gmx_restrict nrnb)
337 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
338 * just 0 for non-waters.
339 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
340 * jnr indices corresponding to data put in the four positions in the SIMD register.
342 int i_shift_offset,i_coord_offset,outeriter,inneriter;
343 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
345 int j_coord_offsetA,j_coord_offsetB;
346 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
348 real *shiftvec,*fshift,*x,*f;
349 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
351 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
352 int vdwjidx0A,vdwjidx0B;
353 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
354 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
355 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
358 __m128i ifour = _mm_set1_epi32(4);
359 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
361 __m128d dummy_mask,cutoff_mask;
362 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
363 __m128d one = _mm_set1_pd(1.0);
364 __m128d two = _mm_set1_pd(2.0);
370 jindex = nlist->jindex;
372 shiftidx = nlist->shift;
374 shiftvec = fr->shift_vec[0];
375 fshift = fr->fshift[0];
376 facel = _mm_set1_pd(fr->epsfac);
377 charge = mdatoms->chargeA;
379 vftab = kernel_data->table_elec->data;
380 vftabscale = _mm_set1_pd(kernel_data->table_elec->scale);
382 /* Avoid stupid compiler warnings */
390 /* Start outer loop over neighborlists */
391 for(iidx=0; iidx<nri; iidx++)
393 /* Load shift vector for this list */
394 i_shift_offset = DIM*shiftidx[iidx];
396 /* Load limits for loop over neighbors */
397 j_index_start = jindex[iidx];
398 j_index_end = jindex[iidx+1];
400 /* Get outer coordinate index */
402 i_coord_offset = DIM*inr;
404 /* Load i particle coords and add shift vector */
405 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
407 fix0 = _mm_setzero_pd();
408 fiy0 = _mm_setzero_pd();
409 fiz0 = _mm_setzero_pd();
411 /* Load parameters for i particles */
412 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
414 /* Start inner kernel loop */
415 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
418 /* Get j neighbor index, and coordinate index */
421 j_coord_offsetA = DIM*jnrA;
422 j_coord_offsetB = DIM*jnrB;
424 /* load j atom coordinates */
425 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
428 /* Calculate displacement vector */
429 dx00 = _mm_sub_pd(ix0,jx0);
430 dy00 = _mm_sub_pd(iy0,jy0);
431 dz00 = _mm_sub_pd(iz0,jz0);
433 /* Calculate squared distance and things based on it */
434 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
436 rinv00 = gmx_mm_invsqrt_pd(rsq00);
438 /* Load parameters for j particles */
439 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 r00 = _mm_mul_pd(rsq00,rinv00);
447 /* Compute parameters for interactions between i and j atoms */
448 qq00 = _mm_mul_pd(iq0,jq0);
450 /* Calculate table index by multiplying r with table scale and truncate to integer */
451 rt = _mm_mul_pd(r00,vftabscale);
452 vfitab = _mm_cvttpd_epi32(rt);
453 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
454 vfitab = _mm_slli_epi32(vfitab,2);
456 /* CUBIC SPLINE TABLE ELECTROSTATICS */
457 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
458 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
459 GMX_MM_TRANSPOSE2_PD(Y,F);
460 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
461 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
462 GMX_MM_TRANSPOSE2_PD(G,H);
463 Heps = _mm_mul_pd(vfeps,H);
464 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
465 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
466 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
470 /* Calculate temporary vectorial force */
471 tx = _mm_mul_pd(fscal,dx00);
472 ty = _mm_mul_pd(fscal,dy00);
473 tz = _mm_mul_pd(fscal,dz00);
475 /* Update vectorial force */
476 fix0 = _mm_add_pd(fix0,tx);
477 fiy0 = _mm_add_pd(fiy0,ty);
478 fiz0 = _mm_add_pd(fiz0,tz);
480 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
482 /* Inner loop uses 39 flops */
489 j_coord_offsetA = DIM*jnrA;
491 /* load j atom coordinates */
492 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
495 /* Calculate displacement vector */
496 dx00 = _mm_sub_pd(ix0,jx0);
497 dy00 = _mm_sub_pd(iy0,jy0);
498 dz00 = _mm_sub_pd(iz0,jz0);
500 /* Calculate squared distance and things based on it */
501 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
503 rinv00 = gmx_mm_invsqrt_pd(rsq00);
505 /* Load parameters for j particles */
506 jq0 = _mm_load_sd(charge+jnrA+0);
508 /**************************
509 * CALCULATE INTERACTIONS *
510 **************************/
512 r00 = _mm_mul_pd(rsq00,rinv00);
514 /* Compute parameters for interactions between i and j atoms */
515 qq00 = _mm_mul_pd(iq0,jq0);
517 /* Calculate table index by multiplying r with table scale and truncate to integer */
518 rt = _mm_mul_pd(r00,vftabscale);
519 vfitab = _mm_cvttpd_epi32(rt);
520 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
521 vfitab = _mm_slli_epi32(vfitab,2);
523 /* CUBIC SPLINE TABLE ELECTROSTATICS */
524 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
525 F = _mm_setzero_pd();
526 GMX_MM_TRANSPOSE2_PD(Y,F);
527 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
528 H = _mm_setzero_pd();
529 GMX_MM_TRANSPOSE2_PD(G,H);
530 Heps = _mm_mul_pd(vfeps,H);
531 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
532 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
533 felec = _mm_xor_pd(signbit,_mm_mul_pd(_mm_mul_pd(qq00,FF),_mm_mul_pd(vftabscale,rinv00)));
537 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
539 /* Calculate temporary vectorial force */
540 tx = _mm_mul_pd(fscal,dx00);
541 ty = _mm_mul_pd(fscal,dy00);
542 tz = _mm_mul_pd(fscal,dz00);
544 /* Update vectorial force */
545 fix0 = _mm_add_pd(fix0,tx);
546 fiy0 = _mm_add_pd(fiy0,ty);
547 fiz0 = _mm_add_pd(fiz0,tz);
549 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
551 /* Inner loop uses 39 flops */
554 /* End of innermost loop */
556 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
557 f+i_coord_offset,fshift+i_shift_offset);
559 /* Increment number of inner iterations */
560 inneriter += j_index_end - j_index_start;
562 /* Outer loop uses 7 flops */
565 /* Increment number of outer iterations */
568 /* Update outer/inner flops */
570 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*39);