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 sse2_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_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_VF_sse2_double
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_VF_sse2_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;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 int vdwjidx0A,vdwjidx0B;
87 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
90 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
91 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
94 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
98 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
100 __m128i ifour = _mm_set1_epi32(4);
101 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
103 __m128d dummy_mask,cutoff_mask;
104 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
105 __m128d one = _mm_set1_pd(1.0);
106 __m128d two = _mm_set1_pd(2.0);
112 jindex = nlist->jindex;
114 shiftidx = nlist->shift;
116 shiftvec = fr->shift_vec[0];
117 fshift = fr->fshift[0];
118 facel = _mm_set1_pd(fr->epsfac);
119 charge = mdatoms->chargeA;
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 vftab = kernel_data->table_vdw->data;
125 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
127 /* Setup water-specific parameters */
128 inr = nlist->iinr[0];
129 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
130 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
131 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
132 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
134 /* Avoid stupid compiler warnings */
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
158 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
160 fix0 = _mm_setzero_pd();
161 fiy0 = _mm_setzero_pd();
162 fiz0 = _mm_setzero_pd();
163 fix1 = _mm_setzero_pd();
164 fiy1 = _mm_setzero_pd();
165 fiz1 = _mm_setzero_pd();
166 fix2 = _mm_setzero_pd();
167 fiy2 = _mm_setzero_pd();
168 fiz2 = _mm_setzero_pd();
170 /* Reset potential sums */
171 velecsum = _mm_setzero_pd();
172 vvdwsum = _mm_setzero_pd();
174 /* Start inner kernel loop */
175 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
178 /* Get j neighbor index, and coordinate index */
181 j_coord_offsetA = DIM*jnrA;
182 j_coord_offsetB = DIM*jnrB;
184 /* load j atom coordinates */
185 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
188 /* Calculate displacement vector */
189 dx00 = _mm_sub_pd(ix0,jx0);
190 dy00 = _mm_sub_pd(iy0,jy0);
191 dz00 = _mm_sub_pd(iz0,jz0);
192 dx10 = _mm_sub_pd(ix1,jx0);
193 dy10 = _mm_sub_pd(iy1,jy0);
194 dz10 = _mm_sub_pd(iz1,jz0);
195 dx20 = _mm_sub_pd(ix2,jx0);
196 dy20 = _mm_sub_pd(iy2,jy0);
197 dz20 = _mm_sub_pd(iz2,jz0);
199 /* Calculate squared distance and things based on it */
200 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
201 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
202 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
204 rinv00 = gmx_mm_invsqrt_pd(rsq00);
205 rinv10 = gmx_mm_invsqrt_pd(rsq10);
206 rinv20 = gmx_mm_invsqrt_pd(rsq20);
208 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
209 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
210 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
212 /* Load parameters for j particles */
213 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
214 vdwjidx0A = 2*vdwtype[jnrA+0];
215 vdwjidx0B = 2*vdwtype[jnrB+0];
217 fjx0 = _mm_setzero_pd();
218 fjy0 = _mm_setzero_pd();
219 fjz0 = _mm_setzero_pd();
221 /**************************
222 * CALCULATE INTERACTIONS *
223 **************************/
225 r00 = _mm_mul_pd(rsq00,rinv00);
227 /* Compute parameters for interactions between i and j atoms */
228 qq00 = _mm_mul_pd(iq0,jq0);
229 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
230 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
232 /* Calculate table index by multiplying r with table scale and truncate to integer */
233 rt = _mm_mul_pd(r00,vftabscale);
234 vfitab = _mm_cvttpd_epi32(rt);
235 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
236 vfitab = _mm_slli_epi32(vfitab,3);
238 /* COULOMB ELECTROSTATICS */
239 velec = _mm_mul_pd(qq00,rinv00);
240 felec = _mm_mul_pd(velec,rinvsq00);
242 /* CUBIC SPLINE TABLE DISPERSION */
243 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
244 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
245 GMX_MM_TRANSPOSE2_PD(Y,F);
246 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
247 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
248 GMX_MM_TRANSPOSE2_PD(G,H);
249 Heps = _mm_mul_pd(vfeps,H);
250 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
251 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
252 vvdw6 = _mm_mul_pd(c6_00,VV);
253 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
254 fvdw6 = _mm_mul_pd(c6_00,FF);
256 /* CUBIC SPLINE TABLE REPULSION */
257 vfitab = _mm_add_epi32(vfitab,ifour);
258 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
259 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
260 GMX_MM_TRANSPOSE2_PD(Y,F);
261 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
262 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
263 GMX_MM_TRANSPOSE2_PD(G,H);
264 Heps = _mm_mul_pd(vfeps,H);
265 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
266 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
267 vvdw12 = _mm_mul_pd(c12_00,VV);
268 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
269 fvdw12 = _mm_mul_pd(c12_00,FF);
270 vvdw = _mm_add_pd(vvdw12,vvdw6);
271 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
273 /* Update potential sum for this i atom from the interaction with this j atom. */
274 velecsum = _mm_add_pd(velecsum,velec);
275 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
277 fscal = _mm_add_pd(felec,fvdw);
279 /* Calculate temporary vectorial force */
280 tx = _mm_mul_pd(fscal,dx00);
281 ty = _mm_mul_pd(fscal,dy00);
282 tz = _mm_mul_pd(fscal,dz00);
284 /* Update vectorial force */
285 fix0 = _mm_add_pd(fix0,tx);
286 fiy0 = _mm_add_pd(fiy0,ty);
287 fiz0 = _mm_add_pd(fiz0,tz);
289 fjx0 = _mm_add_pd(fjx0,tx);
290 fjy0 = _mm_add_pd(fjy0,ty);
291 fjz0 = _mm_add_pd(fjz0,tz);
293 /**************************
294 * CALCULATE INTERACTIONS *
295 **************************/
297 /* Compute parameters for interactions between i and j atoms */
298 qq10 = _mm_mul_pd(iq1,jq0);
300 /* COULOMB ELECTROSTATICS */
301 velec = _mm_mul_pd(qq10,rinv10);
302 felec = _mm_mul_pd(velec,rinvsq10);
304 /* Update potential sum for this i atom from the interaction with this j atom. */
305 velecsum = _mm_add_pd(velecsum,velec);
309 /* Calculate temporary vectorial force */
310 tx = _mm_mul_pd(fscal,dx10);
311 ty = _mm_mul_pd(fscal,dy10);
312 tz = _mm_mul_pd(fscal,dz10);
314 /* Update vectorial force */
315 fix1 = _mm_add_pd(fix1,tx);
316 fiy1 = _mm_add_pd(fiy1,ty);
317 fiz1 = _mm_add_pd(fiz1,tz);
319 fjx0 = _mm_add_pd(fjx0,tx);
320 fjy0 = _mm_add_pd(fjy0,ty);
321 fjz0 = _mm_add_pd(fjz0,tz);
323 /**************************
324 * CALCULATE INTERACTIONS *
325 **************************/
327 /* Compute parameters for interactions between i and j atoms */
328 qq20 = _mm_mul_pd(iq2,jq0);
330 /* COULOMB ELECTROSTATICS */
331 velec = _mm_mul_pd(qq20,rinv20);
332 felec = _mm_mul_pd(velec,rinvsq20);
334 /* Update potential sum for this i atom from the interaction with this j atom. */
335 velecsum = _mm_add_pd(velecsum,velec);
339 /* Calculate temporary vectorial force */
340 tx = _mm_mul_pd(fscal,dx20);
341 ty = _mm_mul_pd(fscal,dy20);
342 tz = _mm_mul_pd(fscal,dz20);
344 /* Update vectorial force */
345 fix2 = _mm_add_pd(fix2,tx);
346 fiy2 = _mm_add_pd(fiy2,ty);
347 fiz2 = _mm_add_pd(fiz2,tz);
349 fjx0 = _mm_add_pd(fjx0,tx);
350 fjy0 = _mm_add_pd(fjy0,ty);
351 fjz0 = _mm_add_pd(fjz0,tz);
353 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
355 /* Inner loop uses 122 flops */
362 j_coord_offsetA = DIM*jnrA;
364 /* load j atom coordinates */
365 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
368 /* Calculate displacement vector */
369 dx00 = _mm_sub_pd(ix0,jx0);
370 dy00 = _mm_sub_pd(iy0,jy0);
371 dz00 = _mm_sub_pd(iz0,jz0);
372 dx10 = _mm_sub_pd(ix1,jx0);
373 dy10 = _mm_sub_pd(iy1,jy0);
374 dz10 = _mm_sub_pd(iz1,jz0);
375 dx20 = _mm_sub_pd(ix2,jx0);
376 dy20 = _mm_sub_pd(iy2,jy0);
377 dz20 = _mm_sub_pd(iz2,jz0);
379 /* Calculate squared distance and things based on it */
380 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
381 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
382 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
384 rinv00 = gmx_mm_invsqrt_pd(rsq00);
385 rinv10 = gmx_mm_invsqrt_pd(rsq10);
386 rinv20 = gmx_mm_invsqrt_pd(rsq20);
388 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
389 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
390 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
392 /* Load parameters for j particles */
393 jq0 = _mm_load_sd(charge+jnrA+0);
394 vdwjidx0A = 2*vdwtype[jnrA+0];
396 fjx0 = _mm_setzero_pd();
397 fjy0 = _mm_setzero_pd();
398 fjz0 = _mm_setzero_pd();
400 /**************************
401 * CALCULATE INTERACTIONS *
402 **************************/
404 r00 = _mm_mul_pd(rsq00,rinv00);
406 /* Compute parameters for interactions between i and j atoms */
407 qq00 = _mm_mul_pd(iq0,jq0);
408 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
410 /* Calculate table index by multiplying r with table scale and truncate to integer */
411 rt = _mm_mul_pd(r00,vftabscale);
412 vfitab = _mm_cvttpd_epi32(rt);
413 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
414 vfitab = _mm_slli_epi32(vfitab,3);
416 /* COULOMB ELECTROSTATICS */
417 velec = _mm_mul_pd(qq00,rinv00);
418 felec = _mm_mul_pd(velec,rinvsq00);
420 /* CUBIC SPLINE TABLE DISPERSION */
421 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
422 F = _mm_setzero_pd();
423 GMX_MM_TRANSPOSE2_PD(Y,F);
424 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
425 H = _mm_setzero_pd();
426 GMX_MM_TRANSPOSE2_PD(G,H);
427 Heps = _mm_mul_pd(vfeps,H);
428 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
429 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
430 vvdw6 = _mm_mul_pd(c6_00,VV);
431 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
432 fvdw6 = _mm_mul_pd(c6_00,FF);
434 /* CUBIC SPLINE TABLE REPULSION */
435 vfitab = _mm_add_epi32(vfitab,ifour);
436 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
437 F = _mm_setzero_pd();
438 GMX_MM_TRANSPOSE2_PD(Y,F);
439 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
440 H = _mm_setzero_pd();
441 GMX_MM_TRANSPOSE2_PD(G,H);
442 Heps = _mm_mul_pd(vfeps,H);
443 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
444 VV = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
445 vvdw12 = _mm_mul_pd(c12_00,VV);
446 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
447 fvdw12 = _mm_mul_pd(c12_00,FF);
448 vvdw = _mm_add_pd(vvdw12,vvdw6);
449 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
451 /* Update potential sum for this i atom from the interaction with this j atom. */
452 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
453 velecsum = _mm_add_pd(velecsum,velec);
454 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
455 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
457 fscal = _mm_add_pd(felec,fvdw);
459 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
461 /* Calculate temporary vectorial force */
462 tx = _mm_mul_pd(fscal,dx00);
463 ty = _mm_mul_pd(fscal,dy00);
464 tz = _mm_mul_pd(fscal,dz00);
466 /* Update vectorial force */
467 fix0 = _mm_add_pd(fix0,tx);
468 fiy0 = _mm_add_pd(fiy0,ty);
469 fiz0 = _mm_add_pd(fiz0,tz);
471 fjx0 = _mm_add_pd(fjx0,tx);
472 fjy0 = _mm_add_pd(fjy0,ty);
473 fjz0 = _mm_add_pd(fjz0,tz);
475 /**************************
476 * CALCULATE INTERACTIONS *
477 **************************/
479 /* Compute parameters for interactions between i and j atoms */
480 qq10 = _mm_mul_pd(iq1,jq0);
482 /* COULOMB ELECTROSTATICS */
483 velec = _mm_mul_pd(qq10,rinv10);
484 felec = _mm_mul_pd(velec,rinvsq10);
486 /* Update potential sum for this i atom from the interaction with this j atom. */
487 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
488 velecsum = _mm_add_pd(velecsum,velec);
492 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
494 /* Calculate temporary vectorial force */
495 tx = _mm_mul_pd(fscal,dx10);
496 ty = _mm_mul_pd(fscal,dy10);
497 tz = _mm_mul_pd(fscal,dz10);
499 /* Update vectorial force */
500 fix1 = _mm_add_pd(fix1,tx);
501 fiy1 = _mm_add_pd(fiy1,ty);
502 fiz1 = _mm_add_pd(fiz1,tz);
504 fjx0 = _mm_add_pd(fjx0,tx);
505 fjy0 = _mm_add_pd(fjy0,ty);
506 fjz0 = _mm_add_pd(fjz0,tz);
508 /**************************
509 * CALCULATE INTERACTIONS *
510 **************************/
512 /* Compute parameters for interactions between i and j atoms */
513 qq20 = _mm_mul_pd(iq2,jq0);
515 /* COULOMB ELECTROSTATICS */
516 velec = _mm_mul_pd(qq20,rinv20);
517 felec = _mm_mul_pd(velec,rinvsq20);
519 /* Update potential sum for this i atom from the interaction with this j atom. */
520 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
521 velecsum = _mm_add_pd(velecsum,velec);
525 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
527 /* Calculate temporary vectorial force */
528 tx = _mm_mul_pd(fscal,dx20);
529 ty = _mm_mul_pd(fscal,dy20);
530 tz = _mm_mul_pd(fscal,dz20);
532 /* Update vectorial force */
533 fix2 = _mm_add_pd(fix2,tx);
534 fiy2 = _mm_add_pd(fiy2,ty);
535 fiz2 = _mm_add_pd(fiz2,tz);
537 fjx0 = _mm_add_pd(fjx0,tx);
538 fjy0 = _mm_add_pd(fjy0,ty);
539 fjz0 = _mm_add_pd(fjz0,tz);
541 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
543 /* Inner loop uses 122 flops */
546 /* End of innermost loop */
548 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
549 f+i_coord_offset,fshift+i_shift_offset);
552 /* Update potential energies */
553 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
554 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
556 /* Increment number of inner iterations */
557 inneriter += j_index_end - j_index_start;
559 /* Outer loop uses 20 flops */
562 /* Increment number of outer iterations */
565 /* Update outer/inner flops */
567 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*122);
570 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_F_sse2_double
571 * Electrostatics interaction: Coulomb
572 * VdW interaction: CubicSplineTable
573 * Geometry: Water3-Particle
574 * Calculate force/pot: Force
577 nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_F_sse2_double
578 (t_nblist * gmx_restrict nlist,
579 rvec * gmx_restrict xx,
580 rvec * gmx_restrict ff,
581 t_forcerec * gmx_restrict fr,
582 t_mdatoms * gmx_restrict mdatoms,
583 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
584 t_nrnb * gmx_restrict nrnb)
586 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
587 * just 0 for non-waters.
588 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
589 * jnr indices corresponding to data put in the four positions in the SIMD register.
591 int i_shift_offset,i_coord_offset,outeriter,inneriter;
592 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
594 int j_coord_offsetA,j_coord_offsetB;
595 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
597 real *shiftvec,*fshift,*x,*f;
598 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
600 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
602 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
604 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
605 int vdwjidx0A,vdwjidx0B;
606 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
607 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
608 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
609 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
610 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
613 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
616 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
617 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
619 __m128i ifour = _mm_set1_epi32(4);
620 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
622 __m128d dummy_mask,cutoff_mask;
623 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
624 __m128d one = _mm_set1_pd(1.0);
625 __m128d two = _mm_set1_pd(2.0);
631 jindex = nlist->jindex;
633 shiftidx = nlist->shift;
635 shiftvec = fr->shift_vec[0];
636 fshift = fr->fshift[0];
637 facel = _mm_set1_pd(fr->epsfac);
638 charge = mdatoms->chargeA;
639 nvdwtype = fr->ntype;
641 vdwtype = mdatoms->typeA;
643 vftab = kernel_data->table_vdw->data;
644 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
646 /* Setup water-specific parameters */
647 inr = nlist->iinr[0];
648 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
649 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
650 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
651 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
653 /* Avoid stupid compiler warnings */
661 /* Start outer loop over neighborlists */
662 for(iidx=0; iidx<nri; iidx++)
664 /* Load shift vector for this list */
665 i_shift_offset = DIM*shiftidx[iidx];
667 /* Load limits for loop over neighbors */
668 j_index_start = jindex[iidx];
669 j_index_end = jindex[iidx+1];
671 /* Get outer coordinate index */
673 i_coord_offset = DIM*inr;
675 /* Load i particle coords and add shift vector */
676 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
677 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
679 fix0 = _mm_setzero_pd();
680 fiy0 = _mm_setzero_pd();
681 fiz0 = _mm_setzero_pd();
682 fix1 = _mm_setzero_pd();
683 fiy1 = _mm_setzero_pd();
684 fiz1 = _mm_setzero_pd();
685 fix2 = _mm_setzero_pd();
686 fiy2 = _mm_setzero_pd();
687 fiz2 = _mm_setzero_pd();
689 /* Start inner kernel loop */
690 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
693 /* Get j neighbor index, and coordinate index */
696 j_coord_offsetA = DIM*jnrA;
697 j_coord_offsetB = DIM*jnrB;
699 /* load j atom coordinates */
700 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
703 /* Calculate displacement vector */
704 dx00 = _mm_sub_pd(ix0,jx0);
705 dy00 = _mm_sub_pd(iy0,jy0);
706 dz00 = _mm_sub_pd(iz0,jz0);
707 dx10 = _mm_sub_pd(ix1,jx0);
708 dy10 = _mm_sub_pd(iy1,jy0);
709 dz10 = _mm_sub_pd(iz1,jz0);
710 dx20 = _mm_sub_pd(ix2,jx0);
711 dy20 = _mm_sub_pd(iy2,jy0);
712 dz20 = _mm_sub_pd(iz2,jz0);
714 /* Calculate squared distance and things based on it */
715 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
716 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
717 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
719 rinv00 = gmx_mm_invsqrt_pd(rsq00);
720 rinv10 = gmx_mm_invsqrt_pd(rsq10);
721 rinv20 = gmx_mm_invsqrt_pd(rsq20);
723 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
724 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
725 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
727 /* Load parameters for j particles */
728 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
729 vdwjidx0A = 2*vdwtype[jnrA+0];
730 vdwjidx0B = 2*vdwtype[jnrB+0];
732 fjx0 = _mm_setzero_pd();
733 fjy0 = _mm_setzero_pd();
734 fjz0 = _mm_setzero_pd();
736 /**************************
737 * CALCULATE INTERACTIONS *
738 **************************/
740 r00 = _mm_mul_pd(rsq00,rinv00);
742 /* Compute parameters for interactions between i and j atoms */
743 qq00 = _mm_mul_pd(iq0,jq0);
744 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
745 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
747 /* Calculate table index by multiplying r with table scale and truncate to integer */
748 rt = _mm_mul_pd(r00,vftabscale);
749 vfitab = _mm_cvttpd_epi32(rt);
750 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
751 vfitab = _mm_slli_epi32(vfitab,3);
753 /* COULOMB ELECTROSTATICS */
754 velec = _mm_mul_pd(qq00,rinv00);
755 felec = _mm_mul_pd(velec,rinvsq00);
757 /* CUBIC SPLINE TABLE DISPERSION */
758 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
759 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
760 GMX_MM_TRANSPOSE2_PD(Y,F);
761 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
762 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
763 GMX_MM_TRANSPOSE2_PD(G,H);
764 Heps = _mm_mul_pd(vfeps,H);
765 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
766 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
767 fvdw6 = _mm_mul_pd(c6_00,FF);
769 /* CUBIC SPLINE TABLE REPULSION */
770 vfitab = _mm_add_epi32(vfitab,ifour);
771 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
772 F = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
773 GMX_MM_TRANSPOSE2_PD(Y,F);
774 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
775 H = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
776 GMX_MM_TRANSPOSE2_PD(G,H);
777 Heps = _mm_mul_pd(vfeps,H);
778 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
779 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
780 fvdw12 = _mm_mul_pd(c12_00,FF);
781 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
783 fscal = _mm_add_pd(felec,fvdw);
785 /* Calculate temporary vectorial force */
786 tx = _mm_mul_pd(fscal,dx00);
787 ty = _mm_mul_pd(fscal,dy00);
788 tz = _mm_mul_pd(fscal,dz00);
790 /* Update vectorial force */
791 fix0 = _mm_add_pd(fix0,tx);
792 fiy0 = _mm_add_pd(fiy0,ty);
793 fiz0 = _mm_add_pd(fiz0,tz);
795 fjx0 = _mm_add_pd(fjx0,tx);
796 fjy0 = _mm_add_pd(fjy0,ty);
797 fjz0 = _mm_add_pd(fjz0,tz);
799 /**************************
800 * CALCULATE INTERACTIONS *
801 **************************/
803 /* Compute parameters for interactions between i and j atoms */
804 qq10 = _mm_mul_pd(iq1,jq0);
806 /* COULOMB ELECTROSTATICS */
807 velec = _mm_mul_pd(qq10,rinv10);
808 felec = _mm_mul_pd(velec,rinvsq10);
812 /* Calculate temporary vectorial force */
813 tx = _mm_mul_pd(fscal,dx10);
814 ty = _mm_mul_pd(fscal,dy10);
815 tz = _mm_mul_pd(fscal,dz10);
817 /* Update vectorial force */
818 fix1 = _mm_add_pd(fix1,tx);
819 fiy1 = _mm_add_pd(fiy1,ty);
820 fiz1 = _mm_add_pd(fiz1,tz);
822 fjx0 = _mm_add_pd(fjx0,tx);
823 fjy0 = _mm_add_pd(fjy0,ty);
824 fjz0 = _mm_add_pd(fjz0,tz);
826 /**************************
827 * CALCULATE INTERACTIONS *
828 **************************/
830 /* Compute parameters for interactions between i and j atoms */
831 qq20 = _mm_mul_pd(iq2,jq0);
833 /* COULOMB ELECTROSTATICS */
834 velec = _mm_mul_pd(qq20,rinv20);
835 felec = _mm_mul_pd(velec,rinvsq20);
839 /* Calculate temporary vectorial force */
840 tx = _mm_mul_pd(fscal,dx20);
841 ty = _mm_mul_pd(fscal,dy20);
842 tz = _mm_mul_pd(fscal,dz20);
844 /* Update vectorial force */
845 fix2 = _mm_add_pd(fix2,tx);
846 fiy2 = _mm_add_pd(fiy2,ty);
847 fiz2 = _mm_add_pd(fiz2,tz);
849 fjx0 = _mm_add_pd(fjx0,tx);
850 fjy0 = _mm_add_pd(fjy0,ty);
851 fjz0 = _mm_add_pd(fjz0,tz);
853 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
855 /* Inner loop uses 111 flops */
862 j_coord_offsetA = DIM*jnrA;
864 /* load j atom coordinates */
865 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
868 /* Calculate displacement vector */
869 dx00 = _mm_sub_pd(ix0,jx0);
870 dy00 = _mm_sub_pd(iy0,jy0);
871 dz00 = _mm_sub_pd(iz0,jz0);
872 dx10 = _mm_sub_pd(ix1,jx0);
873 dy10 = _mm_sub_pd(iy1,jy0);
874 dz10 = _mm_sub_pd(iz1,jz0);
875 dx20 = _mm_sub_pd(ix2,jx0);
876 dy20 = _mm_sub_pd(iy2,jy0);
877 dz20 = _mm_sub_pd(iz2,jz0);
879 /* Calculate squared distance and things based on it */
880 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
881 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
882 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
884 rinv00 = gmx_mm_invsqrt_pd(rsq00);
885 rinv10 = gmx_mm_invsqrt_pd(rsq10);
886 rinv20 = gmx_mm_invsqrt_pd(rsq20);
888 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
889 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
890 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
892 /* Load parameters for j particles */
893 jq0 = _mm_load_sd(charge+jnrA+0);
894 vdwjidx0A = 2*vdwtype[jnrA+0];
896 fjx0 = _mm_setzero_pd();
897 fjy0 = _mm_setzero_pd();
898 fjz0 = _mm_setzero_pd();
900 /**************************
901 * CALCULATE INTERACTIONS *
902 **************************/
904 r00 = _mm_mul_pd(rsq00,rinv00);
906 /* Compute parameters for interactions between i and j atoms */
907 qq00 = _mm_mul_pd(iq0,jq0);
908 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
910 /* Calculate table index by multiplying r with table scale and truncate to integer */
911 rt = _mm_mul_pd(r00,vftabscale);
912 vfitab = _mm_cvttpd_epi32(rt);
913 vfeps = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
914 vfitab = _mm_slli_epi32(vfitab,3);
916 /* COULOMB ELECTROSTATICS */
917 velec = _mm_mul_pd(qq00,rinv00);
918 felec = _mm_mul_pd(velec,rinvsq00);
920 /* CUBIC SPLINE TABLE DISPERSION */
921 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
922 F = _mm_setzero_pd();
923 GMX_MM_TRANSPOSE2_PD(Y,F);
924 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
925 H = _mm_setzero_pd();
926 GMX_MM_TRANSPOSE2_PD(G,H);
927 Heps = _mm_mul_pd(vfeps,H);
928 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
929 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
930 fvdw6 = _mm_mul_pd(c6_00,FF);
932 /* CUBIC SPLINE TABLE REPULSION */
933 vfitab = _mm_add_epi32(vfitab,ifour);
934 Y = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
935 F = _mm_setzero_pd();
936 GMX_MM_TRANSPOSE2_PD(Y,F);
937 G = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
938 H = _mm_setzero_pd();
939 GMX_MM_TRANSPOSE2_PD(G,H);
940 Heps = _mm_mul_pd(vfeps,H);
941 Fp = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
942 FF = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
943 fvdw12 = _mm_mul_pd(c12_00,FF);
944 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
946 fscal = _mm_add_pd(felec,fvdw);
948 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
950 /* Calculate temporary vectorial force */
951 tx = _mm_mul_pd(fscal,dx00);
952 ty = _mm_mul_pd(fscal,dy00);
953 tz = _mm_mul_pd(fscal,dz00);
955 /* Update vectorial force */
956 fix0 = _mm_add_pd(fix0,tx);
957 fiy0 = _mm_add_pd(fiy0,ty);
958 fiz0 = _mm_add_pd(fiz0,tz);
960 fjx0 = _mm_add_pd(fjx0,tx);
961 fjy0 = _mm_add_pd(fjy0,ty);
962 fjz0 = _mm_add_pd(fjz0,tz);
964 /**************************
965 * CALCULATE INTERACTIONS *
966 **************************/
968 /* Compute parameters for interactions between i and j atoms */
969 qq10 = _mm_mul_pd(iq1,jq0);
971 /* COULOMB ELECTROSTATICS */
972 velec = _mm_mul_pd(qq10,rinv10);
973 felec = _mm_mul_pd(velec,rinvsq10);
977 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
979 /* Calculate temporary vectorial force */
980 tx = _mm_mul_pd(fscal,dx10);
981 ty = _mm_mul_pd(fscal,dy10);
982 tz = _mm_mul_pd(fscal,dz10);
984 /* Update vectorial force */
985 fix1 = _mm_add_pd(fix1,tx);
986 fiy1 = _mm_add_pd(fiy1,ty);
987 fiz1 = _mm_add_pd(fiz1,tz);
989 fjx0 = _mm_add_pd(fjx0,tx);
990 fjy0 = _mm_add_pd(fjy0,ty);
991 fjz0 = _mm_add_pd(fjz0,tz);
993 /**************************
994 * CALCULATE INTERACTIONS *
995 **************************/
997 /* Compute parameters for interactions between i and j atoms */
998 qq20 = _mm_mul_pd(iq2,jq0);
1000 /* COULOMB ELECTROSTATICS */
1001 velec = _mm_mul_pd(qq20,rinv20);
1002 felec = _mm_mul_pd(velec,rinvsq20);
1006 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1008 /* Calculate temporary vectorial force */
1009 tx = _mm_mul_pd(fscal,dx20);
1010 ty = _mm_mul_pd(fscal,dy20);
1011 tz = _mm_mul_pd(fscal,dz20);
1013 /* Update vectorial force */
1014 fix2 = _mm_add_pd(fix2,tx);
1015 fiy2 = _mm_add_pd(fiy2,ty);
1016 fiz2 = _mm_add_pd(fiz2,tz);
1018 fjx0 = _mm_add_pd(fjx0,tx);
1019 fjy0 = _mm_add_pd(fjy0,ty);
1020 fjz0 = _mm_add_pd(fjz0,tz);
1022 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1024 /* Inner loop uses 111 flops */
1027 /* End of innermost loop */
1029 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1030 f+i_coord_offset,fshift+i_shift_offset);
1032 /* Increment number of inner iterations */
1033 inneriter += j_index_end - j_index_start;
1035 /* Outer loop uses 18 flops */
1038 /* Increment number of outer iterations */
1041 /* Update outer/inner flops */
1043 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*111);