2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse2_single
54 * Electrostatics interaction: Coulomb
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse2_single
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,C,D refer to j loop unrolling done with SSE, e.g. for the four 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;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
102 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
105 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
106 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
108 __m128i ifour = _mm_set1_epi32(4);
109 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
111 __m128 dummy_mask,cutoff_mask;
112 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
113 __m128 one = _mm_set1_ps(1.0);
114 __m128 two = _mm_set1_ps(2.0);
120 jindex = nlist->jindex;
122 shiftidx = nlist->shift;
124 shiftvec = fr->shift_vec[0];
125 fshift = fr->fshift[0];
126 facel = _mm_set1_ps(fr->epsfac);
127 charge = mdatoms->chargeA;
128 nvdwtype = fr->ntype;
130 vdwtype = mdatoms->typeA;
132 vftab = kernel_data->table_vdw->data;
133 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
135 /* Setup water-specific parameters */
136 inr = nlist->iinr[0];
137 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
138 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
139 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
140 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
142 /* Avoid stupid compiler warnings */
143 jnrA = jnrB = jnrC = jnrD = 0;
152 for(iidx=0;iidx<4*DIM;iidx++)
157 /* Start outer loop over neighborlists */
158 for(iidx=0; iidx<nri; iidx++)
160 /* Load shift vector for this list */
161 i_shift_offset = DIM*shiftidx[iidx];
163 /* Load limits for loop over neighbors */
164 j_index_start = jindex[iidx];
165 j_index_end = jindex[iidx+1];
167 /* Get outer coordinate index */
169 i_coord_offset = DIM*inr;
171 /* Load i particle coords and add shift vector */
172 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
173 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
175 fix0 = _mm_setzero_ps();
176 fiy0 = _mm_setzero_ps();
177 fiz0 = _mm_setzero_ps();
178 fix1 = _mm_setzero_ps();
179 fiy1 = _mm_setzero_ps();
180 fiz1 = _mm_setzero_ps();
181 fix2 = _mm_setzero_ps();
182 fiy2 = _mm_setzero_ps();
183 fiz2 = _mm_setzero_ps();
184 fix3 = _mm_setzero_ps();
185 fiy3 = _mm_setzero_ps();
186 fiz3 = _mm_setzero_ps();
188 /* Reset potential sums */
189 velecsum = _mm_setzero_ps();
190 vvdwsum = _mm_setzero_ps();
192 /* Start inner kernel loop */
193 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
196 /* Get j neighbor index, and coordinate index */
201 j_coord_offsetA = DIM*jnrA;
202 j_coord_offsetB = DIM*jnrB;
203 j_coord_offsetC = DIM*jnrC;
204 j_coord_offsetD = DIM*jnrD;
206 /* load j atom coordinates */
207 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
208 x+j_coord_offsetC,x+j_coord_offsetD,
211 /* Calculate displacement vector */
212 dx00 = _mm_sub_ps(ix0,jx0);
213 dy00 = _mm_sub_ps(iy0,jy0);
214 dz00 = _mm_sub_ps(iz0,jz0);
215 dx10 = _mm_sub_ps(ix1,jx0);
216 dy10 = _mm_sub_ps(iy1,jy0);
217 dz10 = _mm_sub_ps(iz1,jz0);
218 dx20 = _mm_sub_ps(ix2,jx0);
219 dy20 = _mm_sub_ps(iy2,jy0);
220 dz20 = _mm_sub_ps(iz2,jz0);
221 dx30 = _mm_sub_ps(ix3,jx0);
222 dy30 = _mm_sub_ps(iy3,jy0);
223 dz30 = _mm_sub_ps(iz3,jz0);
225 /* Calculate squared distance and things based on it */
226 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
227 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
228 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
229 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
231 rinv00 = gmx_mm_invsqrt_ps(rsq00);
232 rinv10 = gmx_mm_invsqrt_ps(rsq10);
233 rinv20 = gmx_mm_invsqrt_ps(rsq20);
234 rinv30 = gmx_mm_invsqrt_ps(rsq30);
236 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
237 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
238 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
240 /* Load parameters for j particles */
241 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
242 charge+jnrC+0,charge+jnrD+0);
243 vdwjidx0A = 2*vdwtype[jnrA+0];
244 vdwjidx0B = 2*vdwtype[jnrB+0];
245 vdwjidx0C = 2*vdwtype[jnrC+0];
246 vdwjidx0D = 2*vdwtype[jnrD+0];
248 fjx0 = _mm_setzero_ps();
249 fjy0 = _mm_setzero_ps();
250 fjz0 = _mm_setzero_ps();
252 /**************************
253 * CALCULATE INTERACTIONS *
254 **************************/
256 r00 = _mm_mul_ps(rsq00,rinv00);
258 /* Compute parameters for interactions between i and j atoms */
259 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
260 vdwparam+vdwioffset0+vdwjidx0B,
261 vdwparam+vdwioffset0+vdwjidx0C,
262 vdwparam+vdwioffset0+vdwjidx0D,
265 /* Calculate table index by multiplying r with table scale and truncate to integer */
266 rt = _mm_mul_ps(r00,vftabscale);
267 vfitab = _mm_cvttps_epi32(rt);
268 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
269 vfitab = _mm_slli_epi32(vfitab,3);
271 /* CUBIC SPLINE TABLE DISPERSION */
272 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
273 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
274 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
275 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
276 _MM_TRANSPOSE4_PS(Y,F,G,H);
277 Heps = _mm_mul_ps(vfeps,H);
278 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
279 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
280 vvdw6 = _mm_mul_ps(c6_00,VV);
281 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
282 fvdw6 = _mm_mul_ps(c6_00,FF);
284 /* CUBIC SPLINE TABLE REPULSION */
285 vfitab = _mm_add_epi32(vfitab,ifour);
286 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
287 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
288 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
289 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
290 _MM_TRANSPOSE4_PS(Y,F,G,H);
291 Heps = _mm_mul_ps(vfeps,H);
292 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
293 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
294 vvdw12 = _mm_mul_ps(c12_00,VV);
295 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
296 fvdw12 = _mm_mul_ps(c12_00,FF);
297 vvdw = _mm_add_ps(vvdw12,vvdw6);
298 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
300 /* Update potential sum for this i atom from the interaction with this j atom. */
301 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
305 /* Calculate temporary vectorial force */
306 tx = _mm_mul_ps(fscal,dx00);
307 ty = _mm_mul_ps(fscal,dy00);
308 tz = _mm_mul_ps(fscal,dz00);
310 /* Update vectorial force */
311 fix0 = _mm_add_ps(fix0,tx);
312 fiy0 = _mm_add_ps(fiy0,ty);
313 fiz0 = _mm_add_ps(fiz0,tz);
315 fjx0 = _mm_add_ps(fjx0,tx);
316 fjy0 = _mm_add_ps(fjy0,ty);
317 fjz0 = _mm_add_ps(fjz0,tz);
319 /**************************
320 * CALCULATE INTERACTIONS *
321 **************************/
323 /* Compute parameters for interactions between i and j atoms */
324 qq10 = _mm_mul_ps(iq1,jq0);
326 /* COULOMB ELECTROSTATICS */
327 velec = _mm_mul_ps(qq10,rinv10);
328 felec = _mm_mul_ps(velec,rinvsq10);
330 /* Update potential sum for this i atom from the interaction with this j atom. */
331 velecsum = _mm_add_ps(velecsum,velec);
335 /* Calculate temporary vectorial force */
336 tx = _mm_mul_ps(fscal,dx10);
337 ty = _mm_mul_ps(fscal,dy10);
338 tz = _mm_mul_ps(fscal,dz10);
340 /* Update vectorial force */
341 fix1 = _mm_add_ps(fix1,tx);
342 fiy1 = _mm_add_ps(fiy1,ty);
343 fiz1 = _mm_add_ps(fiz1,tz);
345 fjx0 = _mm_add_ps(fjx0,tx);
346 fjy0 = _mm_add_ps(fjy0,ty);
347 fjz0 = _mm_add_ps(fjz0,tz);
349 /**************************
350 * CALCULATE INTERACTIONS *
351 **************************/
353 /* Compute parameters for interactions between i and j atoms */
354 qq20 = _mm_mul_ps(iq2,jq0);
356 /* COULOMB ELECTROSTATICS */
357 velec = _mm_mul_ps(qq20,rinv20);
358 felec = _mm_mul_ps(velec,rinvsq20);
360 /* Update potential sum for this i atom from the interaction with this j atom. */
361 velecsum = _mm_add_ps(velecsum,velec);
365 /* Calculate temporary vectorial force */
366 tx = _mm_mul_ps(fscal,dx20);
367 ty = _mm_mul_ps(fscal,dy20);
368 tz = _mm_mul_ps(fscal,dz20);
370 /* Update vectorial force */
371 fix2 = _mm_add_ps(fix2,tx);
372 fiy2 = _mm_add_ps(fiy2,ty);
373 fiz2 = _mm_add_ps(fiz2,tz);
375 fjx0 = _mm_add_ps(fjx0,tx);
376 fjy0 = _mm_add_ps(fjy0,ty);
377 fjz0 = _mm_add_ps(fjz0,tz);
379 /**************************
380 * CALCULATE INTERACTIONS *
381 **************************/
383 /* Compute parameters for interactions between i and j atoms */
384 qq30 = _mm_mul_ps(iq3,jq0);
386 /* COULOMB ELECTROSTATICS */
387 velec = _mm_mul_ps(qq30,rinv30);
388 felec = _mm_mul_ps(velec,rinvsq30);
390 /* Update potential sum for this i atom from the interaction with this j atom. */
391 velecsum = _mm_add_ps(velecsum,velec);
395 /* Calculate temporary vectorial force */
396 tx = _mm_mul_ps(fscal,dx30);
397 ty = _mm_mul_ps(fscal,dy30);
398 tz = _mm_mul_ps(fscal,dz30);
400 /* Update vectorial force */
401 fix3 = _mm_add_ps(fix3,tx);
402 fiy3 = _mm_add_ps(fiy3,ty);
403 fiz3 = _mm_add_ps(fiz3,tz);
405 fjx0 = _mm_add_ps(fjx0,tx);
406 fjy0 = _mm_add_ps(fjy0,ty);
407 fjz0 = _mm_add_ps(fjz0,tz);
409 fjptrA = f+j_coord_offsetA;
410 fjptrB = f+j_coord_offsetB;
411 fjptrC = f+j_coord_offsetC;
412 fjptrD = f+j_coord_offsetD;
414 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
416 /* Inner loop uses 140 flops */
422 /* Get j neighbor index, and coordinate index */
423 jnrlistA = jjnr[jidx];
424 jnrlistB = jjnr[jidx+1];
425 jnrlistC = jjnr[jidx+2];
426 jnrlistD = jjnr[jidx+3];
427 /* Sign of each element will be negative for non-real atoms.
428 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
429 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
431 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
432 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
433 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
434 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
435 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
436 j_coord_offsetA = DIM*jnrA;
437 j_coord_offsetB = DIM*jnrB;
438 j_coord_offsetC = DIM*jnrC;
439 j_coord_offsetD = DIM*jnrD;
441 /* load j atom coordinates */
442 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
443 x+j_coord_offsetC,x+j_coord_offsetD,
446 /* Calculate displacement vector */
447 dx00 = _mm_sub_ps(ix0,jx0);
448 dy00 = _mm_sub_ps(iy0,jy0);
449 dz00 = _mm_sub_ps(iz0,jz0);
450 dx10 = _mm_sub_ps(ix1,jx0);
451 dy10 = _mm_sub_ps(iy1,jy0);
452 dz10 = _mm_sub_ps(iz1,jz0);
453 dx20 = _mm_sub_ps(ix2,jx0);
454 dy20 = _mm_sub_ps(iy2,jy0);
455 dz20 = _mm_sub_ps(iz2,jz0);
456 dx30 = _mm_sub_ps(ix3,jx0);
457 dy30 = _mm_sub_ps(iy3,jy0);
458 dz30 = _mm_sub_ps(iz3,jz0);
460 /* Calculate squared distance and things based on it */
461 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
462 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
463 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
464 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
466 rinv00 = gmx_mm_invsqrt_ps(rsq00);
467 rinv10 = gmx_mm_invsqrt_ps(rsq10);
468 rinv20 = gmx_mm_invsqrt_ps(rsq20);
469 rinv30 = gmx_mm_invsqrt_ps(rsq30);
471 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
472 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
473 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
475 /* Load parameters for j particles */
476 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
477 charge+jnrC+0,charge+jnrD+0);
478 vdwjidx0A = 2*vdwtype[jnrA+0];
479 vdwjidx0B = 2*vdwtype[jnrB+0];
480 vdwjidx0C = 2*vdwtype[jnrC+0];
481 vdwjidx0D = 2*vdwtype[jnrD+0];
483 fjx0 = _mm_setzero_ps();
484 fjy0 = _mm_setzero_ps();
485 fjz0 = _mm_setzero_ps();
487 /**************************
488 * CALCULATE INTERACTIONS *
489 **************************/
491 r00 = _mm_mul_ps(rsq00,rinv00);
492 r00 = _mm_andnot_ps(dummy_mask,r00);
494 /* Compute parameters for interactions between i and j atoms */
495 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
496 vdwparam+vdwioffset0+vdwjidx0B,
497 vdwparam+vdwioffset0+vdwjidx0C,
498 vdwparam+vdwioffset0+vdwjidx0D,
501 /* Calculate table index by multiplying r with table scale and truncate to integer */
502 rt = _mm_mul_ps(r00,vftabscale);
503 vfitab = _mm_cvttps_epi32(rt);
504 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
505 vfitab = _mm_slli_epi32(vfitab,3);
507 /* CUBIC SPLINE TABLE DISPERSION */
508 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
509 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
510 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
511 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
512 _MM_TRANSPOSE4_PS(Y,F,G,H);
513 Heps = _mm_mul_ps(vfeps,H);
514 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
515 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
516 vvdw6 = _mm_mul_ps(c6_00,VV);
517 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
518 fvdw6 = _mm_mul_ps(c6_00,FF);
520 /* CUBIC SPLINE TABLE REPULSION */
521 vfitab = _mm_add_epi32(vfitab,ifour);
522 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
523 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
524 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
525 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
526 _MM_TRANSPOSE4_PS(Y,F,G,H);
527 Heps = _mm_mul_ps(vfeps,H);
528 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
529 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
530 vvdw12 = _mm_mul_ps(c12_00,VV);
531 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
532 fvdw12 = _mm_mul_ps(c12_00,FF);
533 vvdw = _mm_add_ps(vvdw12,vvdw6);
534 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
536 /* Update potential sum for this i atom from the interaction with this j atom. */
537 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
538 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
542 fscal = _mm_andnot_ps(dummy_mask,fscal);
544 /* Calculate temporary vectorial force */
545 tx = _mm_mul_ps(fscal,dx00);
546 ty = _mm_mul_ps(fscal,dy00);
547 tz = _mm_mul_ps(fscal,dz00);
549 /* Update vectorial force */
550 fix0 = _mm_add_ps(fix0,tx);
551 fiy0 = _mm_add_ps(fiy0,ty);
552 fiz0 = _mm_add_ps(fiz0,tz);
554 fjx0 = _mm_add_ps(fjx0,tx);
555 fjy0 = _mm_add_ps(fjy0,ty);
556 fjz0 = _mm_add_ps(fjz0,tz);
558 /**************************
559 * CALCULATE INTERACTIONS *
560 **************************/
562 /* Compute parameters for interactions between i and j atoms */
563 qq10 = _mm_mul_ps(iq1,jq0);
565 /* COULOMB ELECTROSTATICS */
566 velec = _mm_mul_ps(qq10,rinv10);
567 felec = _mm_mul_ps(velec,rinvsq10);
569 /* Update potential sum for this i atom from the interaction with this j atom. */
570 velec = _mm_andnot_ps(dummy_mask,velec);
571 velecsum = _mm_add_ps(velecsum,velec);
575 fscal = _mm_andnot_ps(dummy_mask,fscal);
577 /* Calculate temporary vectorial force */
578 tx = _mm_mul_ps(fscal,dx10);
579 ty = _mm_mul_ps(fscal,dy10);
580 tz = _mm_mul_ps(fscal,dz10);
582 /* Update vectorial force */
583 fix1 = _mm_add_ps(fix1,tx);
584 fiy1 = _mm_add_ps(fiy1,ty);
585 fiz1 = _mm_add_ps(fiz1,tz);
587 fjx0 = _mm_add_ps(fjx0,tx);
588 fjy0 = _mm_add_ps(fjy0,ty);
589 fjz0 = _mm_add_ps(fjz0,tz);
591 /**************************
592 * CALCULATE INTERACTIONS *
593 **************************/
595 /* Compute parameters for interactions between i and j atoms */
596 qq20 = _mm_mul_ps(iq2,jq0);
598 /* COULOMB ELECTROSTATICS */
599 velec = _mm_mul_ps(qq20,rinv20);
600 felec = _mm_mul_ps(velec,rinvsq20);
602 /* Update potential sum for this i atom from the interaction with this j atom. */
603 velec = _mm_andnot_ps(dummy_mask,velec);
604 velecsum = _mm_add_ps(velecsum,velec);
608 fscal = _mm_andnot_ps(dummy_mask,fscal);
610 /* Calculate temporary vectorial force */
611 tx = _mm_mul_ps(fscal,dx20);
612 ty = _mm_mul_ps(fscal,dy20);
613 tz = _mm_mul_ps(fscal,dz20);
615 /* Update vectorial force */
616 fix2 = _mm_add_ps(fix2,tx);
617 fiy2 = _mm_add_ps(fiy2,ty);
618 fiz2 = _mm_add_ps(fiz2,tz);
620 fjx0 = _mm_add_ps(fjx0,tx);
621 fjy0 = _mm_add_ps(fjy0,ty);
622 fjz0 = _mm_add_ps(fjz0,tz);
624 /**************************
625 * CALCULATE INTERACTIONS *
626 **************************/
628 /* Compute parameters for interactions between i and j atoms */
629 qq30 = _mm_mul_ps(iq3,jq0);
631 /* COULOMB ELECTROSTATICS */
632 velec = _mm_mul_ps(qq30,rinv30);
633 felec = _mm_mul_ps(velec,rinvsq30);
635 /* Update potential sum for this i atom from the interaction with this j atom. */
636 velec = _mm_andnot_ps(dummy_mask,velec);
637 velecsum = _mm_add_ps(velecsum,velec);
641 fscal = _mm_andnot_ps(dummy_mask,fscal);
643 /* Calculate temporary vectorial force */
644 tx = _mm_mul_ps(fscal,dx30);
645 ty = _mm_mul_ps(fscal,dy30);
646 tz = _mm_mul_ps(fscal,dz30);
648 /* Update vectorial force */
649 fix3 = _mm_add_ps(fix3,tx);
650 fiy3 = _mm_add_ps(fiy3,ty);
651 fiz3 = _mm_add_ps(fiz3,tz);
653 fjx0 = _mm_add_ps(fjx0,tx);
654 fjy0 = _mm_add_ps(fjy0,ty);
655 fjz0 = _mm_add_ps(fjz0,tz);
657 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
658 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
659 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
660 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
662 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
664 /* Inner loop uses 141 flops */
667 /* End of innermost loop */
669 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
670 f+i_coord_offset,fshift+i_shift_offset);
673 /* Update potential energies */
674 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
675 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
677 /* Increment number of inner iterations */
678 inneriter += j_index_end - j_index_start;
680 /* Outer loop uses 26 flops */
683 /* Increment number of outer iterations */
686 /* Update outer/inner flops */
688 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*141);
691 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse2_single
692 * Electrostatics interaction: Coulomb
693 * VdW interaction: CubicSplineTable
694 * Geometry: Water4-Particle
695 * Calculate force/pot: Force
698 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse2_single
699 (t_nblist * gmx_restrict nlist,
700 rvec * gmx_restrict xx,
701 rvec * gmx_restrict ff,
702 t_forcerec * gmx_restrict fr,
703 t_mdatoms * gmx_restrict mdatoms,
704 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
705 t_nrnb * gmx_restrict nrnb)
707 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
708 * just 0 for non-waters.
709 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
710 * jnr indices corresponding to data put in the four positions in the SIMD register.
712 int i_shift_offset,i_coord_offset,outeriter,inneriter;
713 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
714 int jnrA,jnrB,jnrC,jnrD;
715 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
716 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
717 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
719 real *shiftvec,*fshift,*x,*f;
720 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
722 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
724 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
726 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
728 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
730 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
731 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
732 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
733 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
734 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
735 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
736 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
737 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
740 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
743 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
744 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
746 __m128i ifour = _mm_set1_epi32(4);
747 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
749 __m128 dummy_mask,cutoff_mask;
750 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
751 __m128 one = _mm_set1_ps(1.0);
752 __m128 two = _mm_set1_ps(2.0);
758 jindex = nlist->jindex;
760 shiftidx = nlist->shift;
762 shiftvec = fr->shift_vec[0];
763 fshift = fr->fshift[0];
764 facel = _mm_set1_ps(fr->epsfac);
765 charge = mdatoms->chargeA;
766 nvdwtype = fr->ntype;
768 vdwtype = mdatoms->typeA;
770 vftab = kernel_data->table_vdw->data;
771 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
773 /* Setup water-specific parameters */
774 inr = nlist->iinr[0];
775 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
776 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
777 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
778 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
780 /* Avoid stupid compiler warnings */
781 jnrA = jnrB = jnrC = jnrD = 0;
790 for(iidx=0;iidx<4*DIM;iidx++)
795 /* Start outer loop over neighborlists */
796 for(iidx=0; iidx<nri; iidx++)
798 /* Load shift vector for this list */
799 i_shift_offset = DIM*shiftidx[iidx];
801 /* Load limits for loop over neighbors */
802 j_index_start = jindex[iidx];
803 j_index_end = jindex[iidx+1];
805 /* Get outer coordinate index */
807 i_coord_offset = DIM*inr;
809 /* Load i particle coords and add shift vector */
810 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
811 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
813 fix0 = _mm_setzero_ps();
814 fiy0 = _mm_setzero_ps();
815 fiz0 = _mm_setzero_ps();
816 fix1 = _mm_setzero_ps();
817 fiy1 = _mm_setzero_ps();
818 fiz1 = _mm_setzero_ps();
819 fix2 = _mm_setzero_ps();
820 fiy2 = _mm_setzero_ps();
821 fiz2 = _mm_setzero_ps();
822 fix3 = _mm_setzero_ps();
823 fiy3 = _mm_setzero_ps();
824 fiz3 = _mm_setzero_ps();
826 /* Start inner kernel loop */
827 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
830 /* Get j neighbor index, and coordinate index */
835 j_coord_offsetA = DIM*jnrA;
836 j_coord_offsetB = DIM*jnrB;
837 j_coord_offsetC = DIM*jnrC;
838 j_coord_offsetD = DIM*jnrD;
840 /* load j atom coordinates */
841 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
842 x+j_coord_offsetC,x+j_coord_offsetD,
845 /* Calculate displacement vector */
846 dx00 = _mm_sub_ps(ix0,jx0);
847 dy00 = _mm_sub_ps(iy0,jy0);
848 dz00 = _mm_sub_ps(iz0,jz0);
849 dx10 = _mm_sub_ps(ix1,jx0);
850 dy10 = _mm_sub_ps(iy1,jy0);
851 dz10 = _mm_sub_ps(iz1,jz0);
852 dx20 = _mm_sub_ps(ix2,jx0);
853 dy20 = _mm_sub_ps(iy2,jy0);
854 dz20 = _mm_sub_ps(iz2,jz0);
855 dx30 = _mm_sub_ps(ix3,jx0);
856 dy30 = _mm_sub_ps(iy3,jy0);
857 dz30 = _mm_sub_ps(iz3,jz0);
859 /* Calculate squared distance and things based on it */
860 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
861 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
862 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
863 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
865 rinv00 = gmx_mm_invsqrt_ps(rsq00);
866 rinv10 = gmx_mm_invsqrt_ps(rsq10);
867 rinv20 = gmx_mm_invsqrt_ps(rsq20);
868 rinv30 = gmx_mm_invsqrt_ps(rsq30);
870 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
871 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
872 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
874 /* Load parameters for j particles */
875 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
876 charge+jnrC+0,charge+jnrD+0);
877 vdwjidx0A = 2*vdwtype[jnrA+0];
878 vdwjidx0B = 2*vdwtype[jnrB+0];
879 vdwjidx0C = 2*vdwtype[jnrC+0];
880 vdwjidx0D = 2*vdwtype[jnrD+0];
882 fjx0 = _mm_setzero_ps();
883 fjy0 = _mm_setzero_ps();
884 fjz0 = _mm_setzero_ps();
886 /**************************
887 * CALCULATE INTERACTIONS *
888 **************************/
890 r00 = _mm_mul_ps(rsq00,rinv00);
892 /* Compute parameters for interactions between i and j atoms */
893 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
894 vdwparam+vdwioffset0+vdwjidx0B,
895 vdwparam+vdwioffset0+vdwjidx0C,
896 vdwparam+vdwioffset0+vdwjidx0D,
899 /* Calculate table index by multiplying r with table scale and truncate to integer */
900 rt = _mm_mul_ps(r00,vftabscale);
901 vfitab = _mm_cvttps_epi32(rt);
902 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
903 vfitab = _mm_slli_epi32(vfitab,3);
905 /* CUBIC SPLINE TABLE DISPERSION */
906 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
907 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
908 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
909 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
910 _MM_TRANSPOSE4_PS(Y,F,G,H);
911 Heps = _mm_mul_ps(vfeps,H);
912 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
913 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
914 fvdw6 = _mm_mul_ps(c6_00,FF);
916 /* CUBIC SPLINE TABLE REPULSION */
917 vfitab = _mm_add_epi32(vfitab,ifour);
918 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
919 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
920 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
921 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
922 _MM_TRANSPOSE4_PS(Y,F,G,H);
923 Heps = _mm_mul_ps(vfeps,H);
924 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
925 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
926 fvdw12 = _mm_mul_ps(c12_00,FF);
927 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
931 /* Calculate temporary vectorial force */
932 tx = _mm_mul_ps(fscal,dx00);
933 ty = _mm_mul_ps(fscal,dy00);
934 tz = _mm_mul_ps(fscal,dz00);
936 /* Update vectorial force */
937 fix0 = _mm_add_ps(fix0,tx);
938 fiy0 = _mm_add_ps(fiy0,ty);
939 fiz0 = _mm_add_ps(fiz0,tz);
941 fjx0 = _mm_add_ps(fjx0,tx);
942 fjy0 = _mm_add_ps(fjy0,ty);
943 fjz0 = _mm_add_ps(fjz0,tz);
945 /**************************
946 * CALCULATE INTERACTIONS *
947 **************************/
949 /* Compute parameters for interactions between i and j atoms */
950 qq10 = _mm_mul_ps(iq1,jq0);
952 /* COULOMB ELECTROSTATICS */
953 velec = _mm_mul_ps(qq10,rinv10);
954 felec = _mm_mul_ps(velec,rinvsq10);
958 /* Calculate temporary vectorial force */
959 tx = _mm_mul_ps(fscal,dx10);
960 ty = _mm_mul_ps(fscal,dy10);
961 tz = _mm_mul_ps(fscal,dz10);
963 /* Update vectorial force */
964 fix1 = _mm_add_ps(fix1,tx);
965 fiy1 = _mm_add_ps(fiy1,ty);
966 fiz1 = _mm_add_ps(fiz1,tz);
968 fjx0 = _mm_add_ps(fjx0,tx);
969 fjy0 = _mm_add_ps(fjy0,ty);
970 fjz0 = _mm_add_ps(fjz0,tz);
972 /**************************
973 * CALCULATE INTERACTIONS *
974 **************************/
976 /* Compute parameters for interactions between i and j atoms */
977 qq20 = _mm_mul_ps(iq2,jq0);
979 /* COULOMB ELECTROSTATICS */
980 velec = _mm_mul_ps(qq20,rinv20);
981 felec = _mm_mul_ps(velec,rinvsq20);
985 /* Calculate temporary vectorial force */
986 tx = _mm_mul_ps(fscal,dx20);
987 ty = _mm_mul_ps(fscal,dy20);
988 tz = _mm_mul_ps(fscal,dz20);
990 /* Update vectorial force */
991 fix2 = _mm_add_ps(fix2,tx);
992 fiy2 = _mm_add_ps(fiy2,ty);
993 fiz2 = _mm_add_ps(fiz2,tz);
995 fjx0 = _mm_add_ps(fjx0,tx);
996 fjy0 = _mm_add_ps(fjy0,ty);
997 fjz0 = _mm_add_ps(fjz0,tz);
999 /**************************
1000 * CALCULATE INTERACTIONS *
1001 **************************/
1003 /* Compute parameters for interactions between i and j atoms */
1004 qq30 = _mm_mul_ps(iq3,jq0);
1006 /* COULOMB ELECTROSTATICS */
1007 velec = _mm_mul_ps(qq30,rinv30);
1008 felec = _mm_mul_ps(velec,rinvsq30);
1012 /* Calculate temporary vectorial force */
1013 tx = _mm_mul_ps(fscal,dx30);
1014 ty = _mm_mul_ps(fscal,dy30);
1015 tz = _mm_mul_ps(fscal,dz30);
1017 /* Update vectorial force */
1018 fix3 = _mm_add_ps(fix3,tx);
1019 fiy3 = _mm_add_ps(fiy3,ty);
1020 fiz3 = _mm_add_ps(fiz3,tz);
1022 fjx0 = _mm_add_ps(fjx0,tx);
1023 fjy0 = _mm_add_ps(fjy0,ty);
1024 fjz0 = _mm_add_ps(fjz0,tz);
1026 fjptrA = f+j_coord_offsetA;
1027 fjptrB = f+j_coord_offsetB;
1028 fjptrC = f+j_coord_offsetC;
1029 fjptrD = f+j_coord_offsetD;
1031 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1033 /* Inner loop uses 129 flops */
1036 if(jidx<j_index_end)
1039 /* Get j neighbor index, and coordinate index */
1040 jnrlistA = jjnr[jidx];
1041 jnrlistB = jjnr[jidx+1];
1042 jnrlistC = jjnr[jidx+2];
1043 jnrlistD = jjnr[jidx+3];
1044 /* Sign of each element will be negative for non-real atoms.
1045 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1046 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1048 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1049 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1050 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1051 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1052 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1053 j_coord_offsetA = DIM*jnrA;
1054 j_coord_offsetB = DIM*jnrB;
1055 j_coord_offsetC = DIM*jnrC;
1056 j_coord_offsetD = DIM*jnrD;
1058 /* load j atom coordinates */
1059 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1060 x+j_coord_offsetC,x+j_coord_offsetD,
1063 /* Calculate displacement vector */
1064 dx00 = _mm_sub_ps(ix0,jx0);
1065 dy00 = _mm_sub_ps(iy0,jy0);
1066 dz00 = _mm_sub_ps(iz0,jz0);
1067 dx10 = _mm_sub_ps(ix1,jx0);
1068 dy10 = _mm_sub_ps(iy1,jy0);
1069 dz10 = _mm_sub_ps(iz1,jz0);
1070 dx20 = _mm_sub_ps(ix2,jx0);
1071 dy20 = _mm_sub_ps(iy2,jy0);
1072 dz20 = _mm_sub_ps(iz2,jz0);
1073 dx30 = _mm_sub_ps(ix3,jx0);
1074 dy30 = _mm_sub_ps(iy3,jy0);
1075 dz30 = _mm_sub_ps(iz3,jz0);
1077 /* Calculate squared distance and things based on it */
1078 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1079 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1080 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1081 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1083 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1084 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1085 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1086 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1088 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1089 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1090 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1092 /* Load parameters for j particles */
1093 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1094 charge+jnrC+0,charge+jnrD+0);
1095 vdwjidx0A = 2*vdwtype[jnrA+0];
1096 vdwjidx0B = 2*vdwtype[jnrB+0];
1097 vdwjidx0C = 2*vdwtype[jnrC+0];
1098 vdwjidx0D = 2*vdwtype[jnrD+0];
1100 fjx0 = _mm_setzero_ps();
1101 fjy0 = _mm_setzero_ps();
1102 fjz0 = _mm_setzero_ps();
1104 /**************************
1105 * CALCULATE INTERACTIONS *
1106 **************************/
1108 r00 = _mm_mul_ps(rsq00,rinv00);
1109 r00 = _mm_andnot_ps(dummy_mask,r00);
1111 /* Compute parameters for interactions between i and j atoms */
1112 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1113 vdwparam+vdwioffset0+vdwjidx0B,
1114 vdwparam+vdwioffset0+vdwjidx0C,
1115 vdwparam+vdwioffset0+vdwjidx0D,
1118 /* Calculate table index by multiplying r with table scale and truncate to integer */
1119 rt = _mm_mul_ps(r00,vftabscale);
1120 vfitab = _mm_cvttps_epi32(rt);
1121 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1122 vfitab = _mm_slli_epi32(vfitab,3);
1124 /* CUBIC SPLINE TABLE DISPERSION */
1125 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1126 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1127 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1128 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1129 _MM_TRANSPOSE4_PS(Y,F,G,H);
1130 Heps = _mm_mul_ps(vfeps,H);
1131 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1132 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1133 fvdw6 = _mm_mul_ps(c6_00,FF);
1135 /* CUBIC SPLINE TABLE REPULSION */
1136 vfitab = _mm_add_epi32(vfitab,ifour);
1137 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1138 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1139 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1140 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1141 _MM_TRANSPOSE4_PS(Y,F,G,H);
1142 Heps = _mm_mul_ps(vfeps,H);
1143 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1144 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1145 fvdw12 = _mm_mul_ps(c12_00,FF);
1146 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1150 fscal = _mm_andnot_ps(dummy_mask,fscal);
1152 /* Calculate temporary vectorial force */
1153 tx = _mm_mul_ps(fscal,dx00);
1154 ty = _mm_mul_ps(fscal,dy00);
1155 tz = _mm_mul_ps(fscal,dz00);
1157 /* Update vectorial force */
1158 fix0 = _mm_add_ps(fix0,tx);
1159 fiy0 = _mm_add_ps(fiy0,ty);
1160 fiz0 = _mm_add_ps(fiz0,tz);
1162 fjx0 = _mm_add_ps(fjx0,tx);
1163 fjy0 = _mm_add_ps(fjy0,ty);
1164 fjz0 = _mm_add_ps(fjz0,tz);
1166 /**************************
1167 * CALCULATE INTERACTIONS *
1168 **************************/
1170 /* Compute parameters for interactions between i and j atoms */
1171 qq10 = _mm_mul_ps(iq1,jq0);
1173 /* COULOMB ELECTROSTATICS */
1174 velec = _mm_mul_ps(qq10,rinv10);
1175 felec = _mm_mul_ps(velec,rinvsq10);
1179 fscal = _mm_andnot_ps(dummy_mask,fscal);
1181 /* Calculate temporary vectorial force */
1182 tx = _mm_mul_ps(fscal,dx10);
1183 ty = _mm_mul_ps(fscal,dy10);
1184 tz = _mm_mul_ps(fscal,dz10);
1186 /* Update vectorial force */
1187 fix1 = _mm_add_ps(fix1,tx);
1188 fiy1 = _mm_add_ps(fiy1,ty);
1189 fiz1 = _mm_add_ps(fiz1,tz);
1191 fjx0 = _mm_add_ps(fjx0,tx);
1192 fjy0 = _mm_add_ps(fjy0,ty);
1193 fjz0 = _mm_add_ps(fjz0,tz);
1195 /**************************
1196 * CALCULATE INTERACTIONS *
1197 **************************/
1199 /* Compute parameters for interactions between i and j atoms */
1200 qq20 = _mm_mul_ps(iq2,jq0);
1202 /* COULOMB ELECTROSTATICS */
1203 velec = _mm_mul_ps(qq20,rinv20);
1204 felec = _mm_mul_ps(velec,rinvsq20);
1208 fscal = _mm_andnot_ps(dummy_mask,fscal);
1210 /* Calculate temporary vectorial force */
1211 tx = _mm_mul_ps(fscal,dx20);
1212 ty = _mm_mul_ps(fscal,dy20);
1213 tz = _mm_mul_ps(fscal,dz20);
1215 /* Update vectorial force */
1216 fix2 = _mm_add_ps(fix2,tx);
1217 fiy2 = _mm_add_ps(fiy2,ty);
1218 fiz2 = _mm_add_ps(fiz2,tz);
1220 fjx0 = _mm_add_ps(fjx0,tx);
1221 fjy0 = _mm_add_ps(fjy0,ty);
1222 fjz0 = _mm_add_ps(fjz0,tz);
1224 /**************************
1225 * CALCULATE INTERACTIONS *
1226 **************************/
1228 /* Compute parameters for interactions between i and j atoms */
1229 qq30 = _mm_mul_ps(iq3,jq0);
1231 /* COULOMB ELECTROSTATICS */
1232 velec = _mm_mul_ps(qq30,rinv30);
1233 felec = _mm_mul_ps(velec,rinvsq30);
1237 fscal = _mm_andnot_ps(dummy_mask,fscal);
1239 /* Calculate temporary vectorial force */
1240 tx = _mm_mul_ps(fscal,dx30);
1241 ty = _mm_mul_ps(fscal,dy30);
1242 tz = _mm_mul_ps(fscal,dz30);
1244 /* Update vectorial force */
1245 fix3 = _mm_add_ps(fix3,tx);
1246 fiy3 = _mm_add_ps(fiy3,ty);
1247 fiz3 = _mm_add_ps(fiz3,tz);
1249 fjx0 = _mm_add_ps(fjx0,tx);
1250 fjy0 = _mm_add_ps(fjy0,ty);
1251 fjz0 = _mm_add_ps(fjz0,tz);
1253 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1254 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1255 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1256 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1258 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1260 /* Inner loop uses 130 flops */
1263 /* End of innermost loop */
1265 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1266 f+i_coord_offset,fshift+i_shift_offset);
1268 /* Increment number of inner iterations */
1269 inneriter += j_index_end - j_index_start;
1271 /* Outer loop uses 24 flops */
1274 /* Increment number of outer iterations */
1277 /* Update outer/inner flops */
1279 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*130);