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_single 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_single.h"
48 #include "kernelutil_x86_sse4_1_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse4_1_single
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse4_1_single
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,C,D refer to j loop unrolling done with SSE, e.g. for the four 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;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
94 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
95 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
96 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
97 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
100 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
106 __m128i ifour = _mm_set1_epi32(4);
107 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
109 __m128 dummy_mask,cutoff_mask;
110 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
111 __m128 one = _mm_set1_ps(1.0);
112 __m128 two = _mm_set1_ps(2.0);
118 jindex = nlist->jindex;
120 shiftidx = nlist->shift;
122 shiftvec = fr->shift_vec[0];
123 fshift = fr->fshift[0];
124 facel = _mm_set1_ps(fr->epsfac);
125 charge = mdatoms->chargeA;
126 nvdwtype = fr->ntype;
128 vdwtype = mdatoms->typeA;
130 vftab = kernel_data->table_vdw->data;
131 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
133 /* Setup water-specific parameters */
134 inr = nlist->iinr[0];
135 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
136 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
137 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
138 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
140 /* Avoid stupid compiler warnings */
141 jnrA = jnrB = jnrC = jnrD = 0;
150 for(iidx=0;iidx<4*DIM;iidx++)
155 /* Start outer loop over neighborlists */
156 for(iidx=0; iidx<nri; iidx++)
158 /* Load shift vector for this list */
159 i_shift_offset = DIM*shiftidx[iidx];
161 /* Load limits for loop over neighbors */
162 j_index_start = jindex[iidx];
163 j_index_end = jindex[iidx+1];
165 /* Get outer coordinate index */
167 i_coord_offset = DIM*inr;
169 /* Load i particle coords and add shift vector */
170 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
171 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
173 fix0 = _mm_setzero_ps();
174 fiy0 = _mm_setzero_ps();
175 fiz0 = _mm_setzero_ps();
176 fix1 = _mm_setzero_ps();
177 fiy1 = _mm_setzero_ps();
178 fiz1 = _mm_setzero_ps();
179 fix2 = _mm_setzero_ps();
180 fiy2 = _mm_setzero_ps();
181 fiz2 = _mm_setzero_ps();
182 fix3 = _mm_setzero_ps();
183 fiy3 = _mm_setzero_ps();
184 fiz3 = _mm_setzero_ps();
186 /* Reset potential sums */
187 velecsum = _mm_setzero_ps();
188 vvdwsum = _mm_setzero_ps();
190 /* Start inner kernel loop */
191 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
194 /* Get j neighbor index, and coordinate index */
199 j_coord_offsetA = DIM*jnrA;
200 j_coord_offsetB = DIM*jnrB;
201 j_coord_offsetC = DIM*jnrC;
202 j_coord_offsetD = DIM*jnrD;
204 /* load j atom coordinates */
205 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
206 x+j_coord_offsetC,x+j_coord_offsetD,
209 /* Calculate displacement vector */
210 dx00 = _mm_sub_ps(ix0,jx0);
211 dy00 = _mm_sub_ps(iy0,jy0);
212 dz00 = _mm_sub_ps(iz0,jz0);
213 dx10 = _mm_sub_ps(ix1,jx0);
214 dy10 = _mm_sub_ps(iy1,jy0);
215 dz10 = _mm_sub_ps(iz1,jz0);
216 dx20 = _mm_sub_ps(ix2,jx0);
217 dy20 = _mm_sub_ps(iy2,jy0);
218 dz20 = _mm_sub_ps(iz2,jz0);
219 dx30 = _mm_sub_ps(ix3,jx0);
220 dy30 = _mm_sub_ps(iy3,jy0);
221 dz30 = _mm_sub_ps(iz3,jz0);
223 /* Calculate squared distance and things based on it */
224 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
225 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
226 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
227 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
229 rinv00 = gmx_mm_invsqrt_ps(rsq00);
230 rinv10 = gmx_mm_invsqrt_ps(rsq10);
231 rinv20 = gmx_mm_invsqrt_ps(rsq20);
232 rinv30 = gmx_mm_invsqrt_ps(rsq30);
234 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
235 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
236 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
238 /* Load parameters for j particles */
239 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
240 charge+jnrC+0,charge+jnrD+0);
241 vdwjidx0A = 2*vdwtype[jnrA+0];
242 vdwjidx0B = 2*vdwtype[jnrB+0];
243 vdwjidx0C = 2*vdwtype[jnrC+0];
244 vdwjidx0D = 2*vdwtype[jnrD+0];
246 fjx0 = _mm_setzero_ps();
247 fjy0 = _mm_setzero_ps();
248 fjz0 = _mm_setzero_ps();
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
254 r00 = _mm_mul_ps(rsq00,rinv00);
256 /* Compute parameters for interactions between i and j atoms */
257 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
258 vdwparam+vdwioffset0+vdwjidx0B,
259 vdwparam+vdwioffset0+vdwjidx0C,
260 vdwparam+vdwioffset0+vdwjidx0D,
263 /* Calculate table index by multiplying r with table scale and truncate to integer */
264 rt = _mm_mul_ps(r00,vftabscale);
265 vfitab = _mm_cvttps_epi32(rt);
266 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
267 vfitab = _mm_slli_epi32(vfitab,3);
269 /* CUBIC SPLINE TABLE DISPERSION */
270 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
271 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
272 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
273 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
274 _MM_TRANSPOSE4_PS(Y,F,G,H);
275 Heps = _mm_mul_ps(vfeps,H);
276 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
277 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
278 vvdw6 = _mm_mul_ps(c6_00,VV);
279 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
280 fvdw6 = _mm_mul_ps(c6_00,FF);
282 /* CUBIC SPLINE TABLE REPULSION */
283 vfitab = _mm_add_epi32(vfitab,ifour);
284 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
285 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
286 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
287 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
288 _MM_TRANSPOSE4_PS(Y,F,G,H);
289 Heps = _mm_mul_ps(vfeps,H);
290 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
291 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
292 vvdw12 = _mm_mul_ps(c12_00,VV);
293 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
294 fvdw12 = _mm_mul_ps(c12_00,FF);
295 vvdw = _mm_add_ps(vvdw12,vvdw6);
296 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
298 /* Update potential sum for this i atom from the interaction with this j atom. */
299 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
303 /* Calculate temporary vectorial force */
304 tx = _mm_mul_ps(fscal,dx00);
305 ty = _mm_mul_ps(fscal,dy00);
306 tz = _mm_mul_ps(fscal,dz00);
308 /* Update vectorial force */
309 fix0 = _mm_add_ps(fix0,tx);
310 fiy0 = _mm_add_ps(fiy0,ty);
311 fiz0 = _mm_add_ps(fiz0,tz);
313 fjx0 = _mm_add_ps(fjx0,tx);
314 fjy0 = _mm_add_ps(fjy0,ty);
315 fjz0 = _mm_add_ps(fjz0,tz);
317 /**************************
318 * CALCULATE INTERACTIONS *
319 **************************/
321 /* Compute parameters for interactions between i and j atoms */
322 qq10 = _mm_mul_ps(iq1,jq0);
324 /* COULOMB ELECTROSTATICS */
325 velec = _mm_mul_ps(qq10,rinv10);
326 felec = _mm_mul_ps(velec,rinvsq10);
328 /* Update potential sum for this i atom from the interaction with this j atom. */
329 velecsum = _mm_add_ps(velecsum,velec);
333 /* Calculate temporary vectorial force */
334 tx = _mm_mul_ps(fscal,dx10);
335 ty = _mm_mul_ps(fscal,dy10);
336 tz = _mm_mul_ps(fscal,dz10);
338 /* Update vectorial force */
339 fix1 = _mm_add_ps(fix1,tx);
340 fiy1 = _mm_add_ps(fiy1,ty);
341 fiz1 = _mm_add_ps(fiz1,tz);
343 fjx0 = _mm_add_ps(fjx0,tx);
344 fjy0 = _mm_add_ps(fjy0,ty);
345 fjz0 = _mm_add_ps(fjz0,tz);
347 /**************************
348 * CALCULATE INTERACTIONS *
349 **************************/
351 /* Compute parameters for interactions between i and j atoms */
352 qq20 = _mm_mul_ps(iq2,jq0);
354 /* COULOMB ELECTROSTATICS */
355 velec = _mm_mul_ps(qq20,rinv20);
356 felec = _mm_mul_ps(velec,rinvsq20);
358 /* Update potential sum for this i atom from the interaction with this j atom. */
359 velecsum = _mm_add_ps(velecsum,velec);
363 /* Calculate temporary vectorial force */
364 tx = _mm_mul_ps(fscal,dx20);
365 ty = _mm_mul_ps(fscal,dy20);
366 tz = _mm_mul_ps(fscal,dz20);
368 /* Update vectorial force */
369 fix2 = _mm_add_ps(fix2,tx);
370 fiy2 = _mm_add_ps(fiy2,ty);
371 fiz2 = _mm_add_ps(fiz2,tz);
373 fjx0 = _mm_add_ps(fjx0,tx);
374 fjy0 = _mm_add_ps(fjy0,ty);
375 fjz0 = _mm_add_ps(fjz0,tz);
377 /**************************
378 * CALCULATE INTERACTIONS *
379 **************************/
381 /* Compute parameters for interactions between i and j atoms */
382 qq30 = _mm_mul_ps(iq3,jq0);
384 /* COULOMB ELECTROSTATICS */
385 velec = _mm_mul_ps(qq30,rinv30);
386 felec = _mm_mul_ps(velec,rinvsq30);
388 /* Update potential sum for this i atom from the interaction with this j atom. */
389 velecsum = _mm_add_ps(velecsum,velec);
393 /* Calculate temporary vectorial force */
394 tx = _mm_mul_ps(fscal,dx30);
395 ty = _mm_mul_ps(fscal,dy30);
396 tz = _mm_mul_ps(fscal,dz30);
398 /* Update vectorial force */
399 fix3 = _mm_add_ps(fix3,tx);
400 fiy3 = _mm_add_ps(fiy3,ty);
401 fiz3 = _mm_add_ps(fiz3,tz);
403 fjx0 = _mm_add_ps(fjx0,tx);
404 fjy0 = _mm_add_ps(fjy0,ty);
405 fjz0 = _mm_add_ps(fjz0,tz);
407 fjptrA = f+j_coord_offsetA;
408 fjptrB = f+j_coord_offsetB;
409 fjptrC = f+j_coord_offsetC;
410 fjptrD = f+j_coord_offsetD;
412 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
414 /* Inner loop uses 140 flops */
420 /* Get j neighbor index, and coordinate index */
421 jnrlistA = jjnr[jidx];
422 jnrlistB = jjnr[jidx+1];
423 jnrlistC = jjnr[jidx+2];
424 jnrlistD = jjnr[jidx+3];
425 /* Sign of each element will be negative for non-real atoms.
426 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
427 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
429 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
430 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
431 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
432 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
433 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
434 j_coord_offsetA = DIM*jnrA;
435 j_coord_offsetB = DIM*jnrB;
436 j_coord_offsetC = DIM*jnrC;
437 j_coord_offsetD = DIM*jnrD;
439 /* load j atom coordinates */
440 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
441 x+j_coord_offsetC,x+j_coord_offsetD,
444 /* Calculate displacement vector */
445 dx00 = _mm_sub_ps(ix0,jx0);
446 dy00 = _mm_sub_ps(iy0,jy0);
447 dz00 = _mm_sub_ps(iz0,jz0);
448 dx10 = _mm_sub_ps(ix1,jx0);
449 dy10 = _mm_sub_ps(iy1,jy0);
450 dz10 = _mm_sub_ps(iz1,jz0);
451 dx20 = _mm_sub_ps(ix2,jx0);
452 dy20 = _mm_sub_ps(iy2,jy0);
453 dz20 = _mm_sub_ps(iz2,jz0);
454 dx30 = _mm_sub_ps(ix3,jx0);
455 dy30 = _mm_sub_ps(iy3,jy0);
456 dz30 = _mm_sub_ps(iz3,jz0);
458 /* Calculate squared distance and things based on it */
459 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
460 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
461 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
462 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
464 rinv00 = gmx_mm_invsqrt_ps(rsq00);
465 rinv10 = gmx_mm_invsqrt_ps(rsq10);
466 rinv20 = gmx_mm_invsqrt_ps(rsq20);
467 rinv30 = gmx_mm_invsqrt_ps(rsq30);
469 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
470 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
471 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
473 /* Load parameters for j particles */
474 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
475 charge+jnrC+0,charge+jnrD+0);
476 vdwjidx0A = 2*vdwtype[jnrA+0];
477 vdwjidx0B = 2*vdwtype[jnrB+0];
478 vdwjidx0C = 2*vdwtype[jnrC+0];
479 vdwjidx0D = 2*vdwtype[jnrD+0];
481 fjx0 = _mm_setzero_ps();
482 fjy0 = _mm_setzero_ps();
483 fjz0 = _mm_setzero_ps();
485 /**************************
486 * CALCULATE INTERACTIONS *
487 **************************/
489 r00 = _mm_mul_ps(rsq00,rinv00);
490 r00 = _mm_andnot_ps(dummy_mask,r00);
492 /* Compute parameters for interactions between i and j atoms */
493 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
494 vdwparam+vdwioffset0+vdwjidx0B,
495 vdwparam+vdwioffset0+vdwjidx0C,
496 vdwparam+vdwioffset0+vdwjidx0D,
499 /* Calculate table index by multiplying r with table scale and truncate to integer */
500 rt = _mm_mul_ps(r00,vftabscale);
501 vfitab = _mm_cvttps_epi32(rt);
502 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
503 vfitab = _mm_slli_epi32(vfitab,3);
505 /* CUBIC SPLINE TABLE DISPERSION */
506 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
507 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
508 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
509 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
510 _MM_TRANSPOSE4_PS(Y,F,G,H);
511 Heps = _mm_mul_ps(vfeps,H);
512 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
513 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
514 vvdw6 = _mm_mul_ps(c6_00,VV);
515 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
516 fvdw6 = _mm_mul_ps(c6_00,FF);
518 /* CUBIC SPLINE TABLE REPULSION */
519 vfitab = _mm_add_epi32(vfitab,ifour);
520 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
521 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
522 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
523 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
524 _MM_TRANSPOSE4_PS(Y,F,G,H);
525 Heps = _mm_mul_ps(vfeps,H);
526 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
527 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
528 vvdw12 = _mm_mul_ps(c12_00,VV);
529 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
530 fvdw12 = _mm_mul_ps(c12_00,FF);
531 vvdw = _mm_add_ps(vvdw12,vvdw6);
532 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
534 /* Update potential sum for this i atom from the interaction with this j atom. */
535 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
536 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
540 fscal = _mm_andnot_ps(dummy_mask,fscal);
542 /* Calculate temporary vectorial force */
543 tx = _mm_mul_ps(fscal,dx00);
544 ty = _mm_mul_ps(fscal,dy00);
545 tz = _mm_mul_ps(fscal,dz00);
547 /* Update vectorial force */
548 fix0 = _mm_add_ps(fix0,tx);
549 fiy0 = _mm_add_ps(fiy0,ty);
550 fiz0 = _mm_add_ps(fiz0,tz);
552 fjx0 = _mm_add_ps(fjx0,tx);
553 fjy0 = _mm_add_ps(fjy0,ty);
554 fjz0 = _mm_add_ps(fjz0,tz);
556 /**************************
557 * CALCULATE INTERACTIONS *
558 **************************/
560 /* Compute parameters for interactions between i and j atoms */
561 qq10 = _mm_mul_ps(iq1,jq0);
563 /* COULOMB ELECTROSTATICS */
564 velec = _mm_mul_ps(qq10,rinv10);
565 felec = _mm_mul_ps(velec,rinvsq10);
567 /* Update potential sum for this i atom from the interaction with this j atom. */
568 velec = _mm_andnot_ps(dummy_mask,velec);
569 velecsum = _mm_add_ps(velecsum,velec);
573 fscal = _mm_andnot_ps(dummy_mask,fscal);
575 /* Calculate temporary vectorial force */
576 tx = _mm_mul_ps(fscal,dx10);
577 ty = _mm_mul_ps(fscal,dy10);
578 tz = _mm_mul_ps(fscal,dz10);
580 /* Update vectorial force */
581 fix1 = _mm_add_ps(fix1,tx);
582 fiy1 = _mm_add_ps(fiy1,ty);
583 fiz1 = _mm_add_ps(fiz1,tz);
585 fjx0 = _mm_add_ps(fjx0,tx);
586 fjy0 = _mm_add_ps(fjy0,ty);
587 fjz0 = _mm_add_ps(fjz0,tz);
589 /**************************
590 * CALCULATE INTERACTIONS *
591 **************************/
593 /* Compute parameters for interactions between i and j atoms */
594 qq20 = _mm_mul_ps(iq2,jq0);
596 /* COULOMB ELECTROSTATICS */
597 velec = _mm_mul_ps(qq20,rinv20);
598 felec = _mm_mul_ps(velec,rinvsq20);
600 /* Update potential sum for this i atom from the interaction with this j atom. */
601 velec = _mm_andnot_ps(dummy_mask,velec);
602 velecsum = _mm_add_ps(velecsum,velec);
606 fscal = _mm_andnot_ps(dummy_mask,fscal);
608 /* Calculate temporary vectorial force */
609 tx = _mm_mul_ps(fscal,dx20);
610 ty = _mm_mul_ps(fscal,dy20);
611 tz = _mm_mul_ps(fscal,dz20);
613 /* Update vectorial force */
614 fix2 = _mm_add_ps(fix2,tx);
615 fiy2 = _mm_add_ps(fiy2,ty);
616 fiz2 = _mm_add_ps(fiz2,tz);
618 fjx0 = _mm_add_ps(fjx0,tx);
619 fjy0 = _mm_add_ps(fjy0,ty);
620 fjz0 = _mm_add_ps(fjz0,tz);
622 /**************************
623 * CALCULATE INTERACTIONS *
624 **************************/
626 /* Compute parameters for interactions between i and j atoms */
627 qq30 = _mm_mul_ps(iq3,jq0);
629 /* COULOMB ELECTROSTATICS */
630 velec = _mm_mul_ps(qq30,rinv30);
631 felec = _mm_mul_ps(velec,rinvsq30);
633 /* Update potential sum for this i atom from the interaction with this j atom. */
634 velec = _mm_andnot_ps(dummy_mask,velec);
635 velecsum = _mm_add_ps(velecsum,velec);
639 fscal = _mm_andnot_ps(dummy_mask,fscal);
641 /* Calculate temporary vectorial force */
642 tx = _mm_mul_ps(fscal,dx30);
643 ty = _mm_mul_ps(fscal,dy30);
644 tz = _mm_mul_ps(fscal,dz30);
646 /* Update vectorial force */
647 fix3 = _mm_add_ps(fix3,tx);
648 fiy3 = _mm_add_ps(fiy3,ty);
649 fiz3 = _mm_add_ps(fiz3,tz);
651 fjx0 = _mm_add_ps(fjx0,tx);
652 fjy0 = _mm_add_ps(fjy0,ty);
653 fjz0 = _mm_add_ps(fjz0,tz);
655 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
656 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
657 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
658 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
660 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
662 /* Inner loop uses 141 flops */
665 /* End of innermost loop */
667 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
668 f+i_coord_offset,fshift+i_shift_offset);
671 /* Update potential energies */
672 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
673 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
675 /* Increment number of inner iterations */
676 inneriter += j_index_end - j_index_start;
678 /* Outer loop uses 26 flops */
681 /* Increment number of outer iterations */
684 /* Update outer/inner flops */
686 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*141);
689 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse4_1_single
690 * Electrostatics interaction: Coulomb
691 * VdW interaction: CubicSplineTable
692 * Geometry: Water4-Particle
693 * Calculate force/pot: Force
696 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse4_1_single
697 (t_nblist * gmx_restrict nlist,
698 rvec * gmx_restrict xx,
699 rvec * gmx_restrict ff,
700 t_forcerec * gmx_restrict fr,
701 t_mdatoms * gmx_restrict mdatoms,
702 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
703 t_nrnb * gmx_restrict nrnb)
705 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
706 * just 0 for non-waters.
707 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
708 * jnr indices corresponding to data put in the four positions in the SIMD register.
710 int i_shift_offset,i_coord_offset,outeriter,inneriter;
711 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
712 int jnrA,jnrB,jnrC,jnrD;
713 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
714 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
715 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
717 real *shiftvec,*fshift,*x,*f;
718 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
720 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
722 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
724 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
726 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
728 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
729 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
730 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
731 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
732 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
733 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
734 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
735 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
738 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
741 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
742 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
744 __m128i ifour = _mm_set1_epi32(4);
745 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
747 __m128 dummy_mask,cutoff_mask;
748 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
749 __m128 one = _mm_set1_ps(1.0);
750 __m128 two = _mm_set1_ps(2.0);
756 jindex = nlist->jindex;
758 shiftidx = nlist->shift;
760 shiftvec = fr->shift_vec[0];
761 fshift = fr->fshift[0];
762 facel = _mm_set1_ps(fr->epsfac);
763 charge = mdatoms->chargeA;
764 nvdwtype = fr->ntype;
766 vdwtype = mdatoms->typeA;
768 vftab = kernel_data->table_vdw->data;
769 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
771 /* Setup water-specific parameters */
772 inr = nlist->iinr[0];
773 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
774 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
775 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
776 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
778 /* Avoid stupid compiler warnings */
779 jnrA = jnrB = jnrC = jnrD = 0;
788 for(iidx=0;iidx<4*DIM;iidx++)
793 /* Start outer loop over neighborlists */
794 for(iidx=0; iidx<nri; iidx++)
796 /* Load shift vector for this list */
797 i_shift_offset = DIM*shiftidx[iidx];
799 /* Load limits for loop over neighbors */
800 j_index_start = jindex[iidx];
801 j_index_end = jindex[iidx+1];
803 /* Get outer coordinate index */
805 i_coord_offset = DIM*inr;
807 /* Load i particle coords and add shift vector */
808 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
809 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
811 fix0 = _mm_setzero_ps();
812 fiy0 = _mm_setzero_ps();
813 fiz0 = _mm_setzero_ps();
814 fix1 = _mm_setzero_ps();
815 fiy1 = _mm_setzero_ps();
816 fiz1 = _mm_setzero_ps();
817 fix2 = _mm_setzero_ps();
818 fiy2 = _mm_setzero_ps();
819 fiz2 = _mm_setzero_ps();
820 fix3 = _mm_setzero_ps();
821 fiy3 = _mm_setzero_ps();
822 fiz3 = _mm_setzero_ps();
824 /* Start inner kernel loop */
825 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
828 /* Get j neighbor index, and coordinate index */
833 j_coord_offsetA = DIM*jnrA;
834 j_coord_offsetB = DIM*jnrB;
835 j_coord_offsetC = DIM*jnrC;
836 j_coord_offsetD = DIM*jnrD;
838 /* load j atom coordinates */
839 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
840 x+j_coord_offsetC,x+j_coord_offsetD,
843 /* Calculate displacement vector */
844 dx00 = _mm_sub_ps(ix0,jx0);
845 dy00 = _mm_sub_ps(iy0,jy0);
846 dz00 = _mm_sub_ps(iz0,jz0);
847 dx10 = _mm_sub_ps(ix1,jx0);
848 dy10 = _mm_sub_ps(iy1,jy0);
849 dz10 = _mm_sub_ps(iz1,jz0);
850 dx20 = _mm_sub_ps(ix2,jx0);
851 dy20 = _mm_sub_ps(iy2,jy0);
852 dz20 = _mm_sub_ps(iz2,jz0);
853 dx30 = _mm_sub_ps(ix3,jx0);
854 dy30 = _mm_sub_ps(iy3,jy0);
855 dz30 = _mm_sub_ps(iz3,jz0);
857 /* Calculate squared distance and things based on it */
858 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
859 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
860 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
861 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
863 rinv00 = gmx_mm_invsqrt_ps(rsq00);
864 rinv10 = gmx_mm_invsqrt_ps(rsq10);
865 rinv20 = gmx_mm_invsqrt_ps(rsq20);
866 rinv30 = gmx_mm_invsqrt_ps(rsq30);
868 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
869 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
870 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
872 /* Load parameters for j particles */
873 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
874 charge+jnrC+0,charge+jnrD+0);
875 vdwjidx0A = 2*vdwtype[jnrA+0];
876 vdwjidx0B = 2*vdwtype[jnrB+0];
877 vdwjidx0C = 2*vdwtype[jnrC+0];
878 vdwjidx0D = 2*vdwtype[jnrD+0];
880 fjx0 = _mm_setzero_ps();
881 fjy0 = _mm_setzero_ps();
882 fjz0 = _mm_setzero_ps();
884 /**************************
885 * CALCULATE INTERACTIONS *
886 **************************/
888 r00 = _mm_mul_ps(rsq00,rinv00);
890 /* Compute parameters for interactions between i and j atoms */
891 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
892 vdwparam+vdwioffset0+vdwjidx0B,
893 vdwparam+vdwioffset0+vdwjidx0C,
894 vdwparam+vdwioffset0+vdwjidx0D,
897 /* Calculate table index by multiplying r with table scale and truncate to integer */
898 rt = _mm_mul_ps(r00,vftabscale);
899 vfitab = _mm_cvttps_epi32(rt);
900 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
901 vfitab = _mm_slli_epi32(vfitab,3);
903 /* CUBIC SPLINE TABLE DISPERSION */
904 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
905 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
906 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
907 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
908 _MM_TRANSPOSE4_PS(Y,F,G,H);
909 Heps = _mm_mul_ps(vfeps,H);
910 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
911 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
912 fvdw6 = _mm_mul_ps(c6_00,FF);
914 /* CUBIC SPLINE TABLE REPULSION */
915 vfitab = _mm_add_epi32(vfitab,ifour);
916 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
917 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
918 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
919 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
920 _MM_TRANSPOSE4_PS(Y,F,G,H);
921 Heps = _mm_mul_ps(vfeps,H);
922 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
923 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
924 fvdw12 = _mm_mul_ps(c12_00,FF);
925 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
929 /* Calculate temporary vectorial force */
930 tx = _mm_mul_ps(fscal,dx00);
931 ty = _mm_mul_ps(fscal,dy00);
932 tz = _mm_mul_ps(fscal,dz00);
934 /* Update vectorial force */
935 fix0 = _mm_add_ps(fix0,tx);
936 fiy0 = _mm_add_ps(fiy0,ty);
937 fiz0 = _mm_add_ps(fiz0,tz);
939 fjx0 = _mm_add_ps(fjx0,tx);
940 fjy0 = _mm_add_ps(fjy0,ty);
941 fjz0 = _mm_add_ps(fjz0,tz);
943 /**************************
944 * CALCULATE INTERACTIONS *
945 **************************/
947 /* Compute parameters for interactions between i and j atoms */
948 qq10 = _mm_mul_ps(iq1,jq0);
950 /* COULOMB ELECTROSTATICS */
951 velec = _mm_mul_ps(qq10,rinv10);
952 felec = _mm_mul_ps(velec,rinvsq10);
956 /* Calculate temporary vectorial force */
957 tx = _mm_mul_ps(fscal,dx10);
958 ty = _mm_mul_ps(fscal,dy10);
959 tz = _mm_mul_ps(fscal,dz10);
961 /* Update vectorial force */
962 fix1 = _mm_add_ps(fix1,tx);
963 fiy1 = _mm_add_ps(fiy1,ty);
964 fiz1 = _mm_add_ps(fiz1,tz);
966 fjx0 = _mm_add_ps(fjx0,tx);
967 fjy0 = _mm_add_ps(fjy0,ty);
968 fjz0 = _mm_add_ps(fjz0,tz);
970 /**************************
971 * CALCULATE INTERACTIONS *
972 **************************/
974 /* Compute parameters for interactions between i and j atoms */
975 qq20 = _mm_mul_ps(iq2,jq0);
977 /* COULOMB ELECTROSTATICS */
978 velec = _mm_mul_ps(qq20,rinv20);
979 felec = _mm_mul_ps(velec,rinvsq20);
983 /* Calculate temporary vectorial force */
984 tx = _mm_mul_ps(fscal,dx20);
985 ty = _mm_mul_ps(fscal,dy20);
986 tz = _mm_mul_ps(fscal,dz20);
988 /* Update vectorial force */
989 fix2 = _mm_add_ps(fix2,tx);
990 fiy2 = _mm_add_ps(fiy2,ty);
991 fiz2 = _mm_add_ps(fiz2,tz);
993 fjx0 = _mm_add_ps(fjx0,tx);
994 fjy0 = _mm_add_ps(fjy0,ty);
995 fjz0 = _mm_add_ps(fjz0,tz);
997 /**************************
998 * CALCULATE INTERACTIONS *
999 **************************/
1001 /* Compute parameters for interactions between i and j atoms */
1002 qq30 = _mm_mul_ps(iq3,jq0);
1004 /* COULOMB ELECTROSTATICS */
1005 velec = _mm_mul_ps(qq30,rinv30);
1006 felec = _mm_mul_ps(velec,rinvsq30);
1010 /* Calculate temporary vectorial force */
1011 tx = _mm_mul_ps(fscal,dx30);
1012 ty = _mm_mul_ps(fscal,dy30);
1013 tz = _mm_mul_ps(fscal,dz30);
1015 /* Update vectorial force */
1016 fix3 = _mm_add_ps(fix3,tx);
1017 fiy3 = _mm_add_ps(fiy3,ty);
1018 fiz3 = _mm_add_ps(fiz3,tz);
1020 fjx0 = _mm_add_ps(fjx0,tx);
1021 fjy0 = _mm_add_ps(fjy0,ty);
1022 fjz0 = _mm_add_ps(fjz0,tz);
1024 fjptrA = f+j_coord_offsetA;
1025 fjptrB = f+j_coord_offsetB;
1026 fjptrC = f+j_coord_offsetC;
1027 fjptrD = f+j_coord_offsetD;
1029 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1031 /* Inner loop uses 129 flops */
1034 if(jidx<j_index_end)
1037 /* Get j neighbor index, and coordinate index */
1038 jnrlistA = jjnr[jidx];
1039 jnrlistB = jjnr[jidx+1];
1040 jnrlistC = jjnr[jidx+2];
1041 jnrlistD = jjnr[jidx+3];
1042 /* Sign of each element will be negative for non-real atoms.
1043 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1044 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1046 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1047 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1048 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1049 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1050 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1051 j_coord_offsetA = DIM*jnrA;
1052 j_coord_offsetB = DIM*jnrB;
1053 j_coord_offsetC = DIM*jnrC;
1054 j_coord_offsetD = DIM*jnrD;
1056 /* load j atom coordinates */
1057 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1058 x+j_coord_offsetC,x+j_coord_offsetD,
1061 /* Calculate displacement vector */
1062 dx00 = _mm_sub_ps(ix0,jx0);
1063 dy00 = _mm_sub_ps(iy0,jy0);
1064 dz00 = _mm_sub_ps(iz0,jz0);
1065 dx10 = _mm_sub_ps(ix1,jx0);
1066 dy10 = _mm_sub_ps(iy1,jy0);
1067 dz10 = _mm_sub_ps(iz1,jz0);
1068 dx20 = _mm_sub_ps(ix2,jx0);
1069 dy20 = _mm_sub_ps(iy2,jy0);
1070 dz20 = _mm_sub_ps(iz2,jz0);
1071 dx30 = _mm_sub_ps(ix3,jx0);
1072 dy30 = _mm_sub_ps(iy3,jy0);
1073 dz30 = _mm_sub_ps(iz3,jz0);
1075 /* Calculate squared distance and things based on it */
1076 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1077 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1078 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1079 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1081 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1082 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1083 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1084 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1086 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1087 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1088 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1090 /* Load parameters for j particles */
1091 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1092 charge+jnrC+0,charge+jnrD+0);
1093 vdwjidx0A = 2*vdwtype[jnrA+0];
1094 vdwjidx0B = 2*vdwtype[jnrB+0];
1095 vdwjidx0C = 2*vdwtype[jnrC+0];
1096 vdwjidx0D = 2*vdwtype[jnrD+0];
1098 fjx0 = _mm_setzero_ps();
1099 fjy0 = _mm_setzero_ps();
1100 fjz0 = _mm_setzero_ps();
1102 /**************************
1103 * CALCULATE INTERACTIONS *
1104 **************************/
1106 r00 = _mm_mul_ps(rsq00,rinv00);
1107 r00 = _mm_andnot_ps(dummy_mask,r00);
1109 /* Compute parameters for interactions between i and j atoms */
1110 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1111 vdwparam+vdwioffset0+vdwjidx0B,
1112 vdwparam+vdwioffset0+vdwjidx0C,
1113 vdwparam+vdwioffset0+vdwjidx0D,
1116 /* Calculate table index by multiplying r with table scale and truncate to integer */
1117 rt = _mm_mul_ps(r00,vftabscale);
1118 vfitab = _mm_cvttps_epi32(rt);
1119 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1120 vfitab = _mm_slli_epi32(vfitab,3);
1122 /* CUBIC SPLINE TABLE DISPERSION */
1123 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1124 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1125 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1126 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1127 _MM_TRANSPOSE4_PS(Y,F,G,H);
1128 Heps = _mm_mul_ps(vfeps,H);
1129 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1130 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1131 fvdw6 = _mm_mul_ps(c6_00,FF);
1133 /* CUBIC SPLINE TABLE REPULSION */
1134 vfitab = _mm_add_epi32(vfitab,ifour);
1135 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1136 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1137 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1138 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1139 _MM_TRANSPOSE4_PS(Y,F,G,H);
1140 Heps = _mm_mul_ps(vfeps,H);
1141 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1142 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1143 fvdw12 = _mm_mul_ps(c12_00,FF);
1144 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1148 fscal = _mm_andnot_ps(dummy_mask,fscal);
1150 /* Calculate temporary vectorial force */
1151 tx = _mm_mul_ps(fscal,dx00);
1152 ty = _mm_mul_ps(fscal,dy00);
1153 tz = _mm_mul_ps(fscal,dz00);
1155 /* Update vectorial force */
1156 fix0 = _mm_add_ps(fix0,tx);
1157 fiy0 = _mm_add_ps(fiy0,ty);
1158 fiz0 = _mm_add_ps(fiz0,tz);
1160 fjx0 = _mm_add_ps(fjx0,tx);
1161 fjy0 = _mm_add_ps(fjy0,ty);
1162 fjz0 = _mm_add_ps(fjz0,tz);
1164 /**************************
1165 * CALCULATE INTERACTIONS *
1166 **************************/
1168 /* Compute parameters for interactions between i and j atoms */
1169 qq10 = _mm_mul_ps(iq1,jq0);
1171 /* COULOMB ELECTROSTATICS */
1172 velec = _mm_mul_ps(qq10,rinv10);
1173 felec = _mm_mul_ps(velec,rinvsq10);
1177 fscal = _mm_andnot_ps(dummy_mask,fscal);
1179 /* Calculate temporary vectorial force */
1180 tx = _mm_mul_ps(fscal,dx10);
1181 ty = _mm_mul_ps(fscal,dy10);
1182 tz = _mm_mul_ps(fscal,dz10);
1184 /* Update vectorial force */
1185 fix1 = _mm_add_ps(fix1,tx);
1186 fiy1 = _mm_add_ps(fiy1,ty);
1187 fiz1 = _mm_add_ps(fiz1,tz);
1189 fjx0 = _mm_add_ps(fjx0,tx);
1190 fjy0 = _mm_add_ps(fjy0,ty);
1191 fjz0 = _mm_add_ps(fjz0,tz);
1193 /**************************
1194 * CALCULATE INTERACTIONS *
1195 **************************/
1197 /* Compute parameters for interactions between i and j atoms */
1198 qq20 = _mm_mul_ps(iq2,jq0);
1200 /* COULOMB ELECTROSTATICS */
1201 velec = _mm_mul_ps(qq20,rinv20);
1202 felec = _mm_mul_ps(velec,rinvsq20);
1206 fscal = _mm_andnot_ps(dummy_mask,fscal);
1208 /* Calculate temporary vectorial force */
1209 tx = _mm_mul_ps(fscal,dx20);
1210 ty = _mm_mul_ps(fscal,dy20);
1211 tz = _mm_mul_ps(fscal,dz20);
1213 /* Update vectorial force */
1214 fix2 = _mm_add_ps(fix2,tx);
1215 fiy2 = _mm_add_ps(fiy2,ty);
1216 fiz2 = _mm_add_ps(fiz2,tz);
1218 fjx0 = _mm_add_ps(fjx0,tx);
1219 fjy0 = _mm_add_ps(fjy0,ty);
1220 fjz0 = _mm_add_ps(fjz0,tz);
1222 /**************************
1223 * CALCULATE INTERACTIONS *
1224 **************************/
1226 /* Compute parameters for interactions between i and j atoms */
1227 qq30 = _mm_mul_ps(iq3,jq0);
1229 /* COULOMB ELECTROSTATICS */
1230 velec = _mm_mul_ps(qq30,rinv30);
1231 felec = _mm_mul_ps(velec,rinvsq30);
1235 fscal = _mm_andnot_ps(dummy_mask,fscal);
1237 /* Calculate temporary vectorial force */
1238 tx = _mm_mul_ps(fscal,dx30);
1239 ty = _mm_mul_ps(fscal,dy30);
1240 tz = _mm_mul_ps(fscal,dz30);
1242 /* Update vectorial force */
1243 fix3 = _mm_add_ps(fix3,tx);
1244 fiy3 = _mm_add_ps(fiy3,ty);
1245 fiz3 = _mm_add_ps(fiz3,tz);
1247 fjx0 = _mm_add_ps(fjx0,tx);
1248 fjy0 = _mm_add_ps(fjy0,ty);
1249 fjz0 = _mm_add_ps(fjz0,tz);
1251 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1252 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1253 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1254 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1256 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1258 /* Inner loop uses 130 flops */
1261 /* End of innermost loop */
1263 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1264 f+i_coord_offset,fshift+i_shift_offset);
1266 /* Increment number of inner iterations */
1267 inneriter += j_index_end - j_index_start;
1269 /* Outer loop uses 24 flops */
1272 /* Increment number of outer iterations */
1275 /* Update outer/inner flops */
1277 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*130);