2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse4_1_single
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_VF_sse4_1_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128i ifour = _mm_set1_epi32(4);
106 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
108 __m128 dummy_mask,cutoff_mask;
109 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
110 __m128 one = _mm_set1_ps(1.0);
111 __m128 two = _mm_set1_ps(2.0);
117 jindex = nlist->jindex;
119 shiftidx = nlist->shift;
121 shiftvec = fr->shift_vec[0];
122 fshift = fr->fshift[0];
123 facel = _mm_set1_ps(fr->ic->epsfac);
124 charge = mdatoms->chargeA;
125 nvdwtype = fr->ntype;
127 vdwtype = mdatoms->typeA;
129 vftab = kernel_data->table_vdw->data;
130 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
132 /* Setup water-specific parameters */
133 inr = nlist->iinr[0];
134 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
135 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
136 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
137 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
139 /* Avoid stupid compiler warnings */
140 jnrA = jnrB = jnrC = jnrD = 0;
149 for(iidx=0;iidx<4*DIM;iidx++)
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
172 fix0 = _mm_setzero_ps();
173 fiy0 = _mm_setzero_ps();
174 fiz0 = _mm_setzero_ps();
175 fix1 = _mm_setzero_ps();
176 fiy1 = _mm_setzero_ps();
177 fiz1 = _mm_setzero_ps();
178 fix2 = _mm_setzero_ps();
179 fiy2 = _mm_setzero_ps();
180 fiz2 = _mm_setzero_ps();
181 fix3 = _mm_setzero_ps();
182 fiy3 = _mm_setzero_ps();
183 fiz3 = _mm_setzero_ps();
185 /* Reset potential sums */
186 velecsum = _mm_setzero_ps();
187 vvdwsum = _mm_setzero_ps();
189 /* Start inner kernel loop */
190 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
193 /* Get j neighbor index, and coordinate index */
198 j_coord_offsetA = DIM*jnrA;
199 j_coord_offsetB = DIM*jnrB;
200 j_coord_offsetC = DIM*jnrC;
201 j_coord_offsetD = DIM*jnrD;
203 /* load j atom coordinates */
204 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
205 x+j_coord_offsetC,x+j_coord_offsetD,
208 /* Calculate displacement vector */
209 dx00 = _mm_sub_ps(ix0,jx0);
210 dy00 = _mm_sub_ps(iy0,jy0);
211 dz00 = _mm_sub_ps(iz0,jz0);
212 dx10 = _mm_sub_ps(ix1,jx0);
213 dy10 = _mm_sub_ps(iy1,jy0);
214 dz10 = _mm_sub_ps(iz1,jz0);
215 dx20 = _mm_sub_ps(ix2,jx0);
216 dy20 = _mm_sub_ps(iy2,jy0);
217 dz20 = _mm_sub_ps(iz2,jz0);
218 dx30 = _mm_sub_ps(ix3,jx0);
219 dy30 = _mm_sub_ps(iy3,jy0);
220 dz30 = _mm_sub_ps(iz3,jz0);
222 /* Calculate squared distance and things based on it */
223 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
224 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
225 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
226 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
228 rinv00 = sse41_invsqrt_f(rsq00);
229 rinv10 = sse41_invsqrt_f(rsq10);
230 rinv20 = sse41_invsqrt_f(rsq20);
231 rinv30 = sse41_invsqrt_f(rsq30);
233 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
234 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
235 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
237 /* Load parameters for j particles */
238 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
239 charge+jnrC+0,charge+jnrD+0);
240 vdwjidx0A = 2*vdwtype[jnrA+0];
241 vdwjidx0B = 2*vdwtype[jnrB+0];
242 vdwjidx0C = 2*vdwtype[jnrC+0];
243 vdwjidx0D = 2*vdwtype[jnrD+0];
245 fjx0 = _mm_setzero_ps();
246 fjy0 = _mm_setzero_ps();
247 fjz0 = _mm_setzero_ps();
249 /**************************
250 * CALCULATE INTERACTIONS *
251 **************************/
253 r00 = _mm_mul_ps(rsq00,rinv00);
255 /* Compute parameters for interactions between i and j atoms */
256 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
257 vdwparam+vdwioffset0+vdwjidx0B,
258 vdwparam+vdwioffset0+vdwjidx0C,
259 vdwparam+vdwioffset0+vdwjidx0D,
262 /* Calculate table index by multiplying r with table scale and truncate to integer */
263 rt = _mm_mul_ps(r00,vftabscale);
264 vfitab = _mm_cvttps_epi32(rt);
265 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
266 vfitab = _mm_slli_epi32(vfitab,3);
268 /* CUBIC SPLINE TABLE DISPERSION */
269 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
270 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
271 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
272 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
273 _MM_TRANSPOSE4_PS(Y,F,G,H);
274 Heps = _mm_mul_ps(vfeps,H);
275 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
276 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
277 vvdw6 = _mm_mul_ps(c6_00,VV);
278 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
279 fvdw6 = _mm_mul_ps(c6_00,FF);
281 /* CUBIC SPLINE TABLE REPULSION */
282 vfitab = _mm_add_epi32(vfitab,ifour);
283 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
284 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
285 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
286 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
287 _MM_TRANSPOSE4_PS(Y,F,G,H);
288 Heps = _mm_mul_ps(vfeps,H);
289 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
290 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
291 vvdw12 = _mm_mul_ps(c12_00,VV);
292 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
293 fvdw12 = _mm_mul_ps(c12_00,FF);
294 vvdw = _mm_add_ps(vvdw12,vvdw6);
295 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
297 /* Update potential sum for this i atom from the interaction with this j atom. */
298 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
302 /* Calculate temporary vectorial force */
303 tx = _mm_mul_ps(fscal,dx00);
304 ty = _mm_mul_ps(fscal,dy00);
305 tz = _mm_mul_ps(fscal,dz00);
307 /* Update vectorial force */
308 fix0 = _mm_add_ps(fix0,tx);
309 fiy0 = _mm_add_ps(fiy0,ty);
310 fiz0 = _mm_add_ps(fiz0,tz);
312 fjx0 = _mm_add_ps(fjx0,tx);
313 fjy0 = _mm_add_ps(fjy0,ty);
314 fjz0 = _mm_add_ps(fjz0,tz);
316 /**************************
317 * CALCULATE INTERACTIONS *
318 **************************/
320 /* Compute parameters for interactions between i and j atoms */
321 qq10 = _mm_mul_ps(iq1,jq0);
323 /* COULOMB ELECTROSTATICS */
324 velec = _mm_mul_ps(qq10,rinv10);
325 felec = _mm_mul_ps(velec,rinvsq10);
327 /* Update potential sum for this i atom from the interaction with this j atom. */
328 velecsum = _mm_add_ps(velecsum,velec);
332 /* Calculate temporary vectorial force */
333 tx = _mm_mul_ps(fscal,dx10);
334 ty = _mm_mul_ps(fscal,dy10);
335 tz = _mm_mul_ps(fscal,dz10);
337 /* Update vectorial force */
338 fix1 = _mm_add_ps(fix1,tx);
339 fiy1 = _mm_add_ps(fiy1,ty);
340 fiz1 = _mm_add_ps(fiz1,tz);
342 fjx0 = _mm_add_ps(fjx0,tx);
343 fjy0 = _mm_add_ps(fjy0,ty);
344 fjz0 = _mm_add_ps(fjz0,tz);
346 /**************************
347 * CALCULATE INTERACTIONS *
348 **************************/
350 /* Compute parameters for interactions between i and j atoms */
351 qq20 = _mm_mul_ps(iq2,jq0);
353 /* COULOMB ELECTROSTATICS */
354 velec = _mm_mul_ps(qq20,rinv20);
355 felec = _mm_mul_ps(velec,rinvsq20);
357 /* Update potential sum for this i atom from the interaction with this j atom. */
358 velecsum = _mm_add_ps(velecsum,velec);
362 /* Calculate temporary vectorial force */
363 tx = _mm_mul_ps(fscal,dx20);
364 ty = _mm_mul_ps(fscal,dy20);
365 tz = _mm_mul_ps(fscal,dz20);
367 /* Update vectorial force */
368 fix2 = _mm_add_ps(fix2,tx);
369 fiy2 = _mm_add_ps(fiy2,ty);
370 fiz2 = _mm_add_ps(fiz2,tz);
372 fjx0 = _mm_add_ps(fjx0,tx);
373 fjy0 = _mm_add_ps(fjy0,ty);
374 fjz0 = _mm_add_ps(fjz0,tz);
376 /**************************
377 * CALCULATE INTERACTIONS *
378 **************************/
380 /* Compute parameters for interactions between i and j atoms */
381 qq30 = _mm_mul_ps(iq3,jq0);
383 /* COULOMB ELECTROSTATICS */
384 velec = _mm_mul_ps(qq30,rinv30);
385 felec = _mm_mul_ps(velec,rinvsq30);
387 /* Update potential sum for this i atom from the interaction with this j atom. */
388 velecsum = _mm_add_ps(velecsum,velec);
392 /* Calculate temporary vectorial force */
393 tx = _mm_mul_ps(fscal,dx30);
394 ty = _mm_mul_ps(fscal,dy30);
395 tz = _mm_mul_ps(fscal,dz30);
397 /* Update vectorial force */
398 fix3 = _mm_add_ps(fix3,tx);
399 fiy3 = _mm_add_ps(fiy3,ty);
400 fiz3 = _mm_add_ps(fiz3,tz);
402 fjx0 = _mm_add_ps(fjx0,tx);
403 fjy0 = _mm_add_ps(fjy0,ty);
404 fjz0 = _mm_add_ps(fjz0,tz);
406 fjptrA = f+j_coord_offsetA;
407 fjptrB = f+j_coord_offsetB;
408 fjptrC = f+j_coord_offsetC;
409 fjptrD = f+j_coord_offsetD;
411 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
413 /* Inner loop uses 140 flops */
419 /* Get j neighbor index, and coordinate index */
420 jnrlistA = jjnr[jidx];
421 jnrlistB = jjnr[jidx+1];
422 jnrlistC = jjnr[jidx+2];
423 jnrlistD = jjnr[jidx+3];
424 /* Sign of each element will be negative for non-real atoms.
425 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
426 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
428 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
429 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
430 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
431 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
432 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
433 j_coord_offsetA = DIM*jnrA;
434 j_coord_offsetB = DIM*jnrB;
435 j_coord_offsetC = DIM*jnrC;
436 j_coord_offsetD = DIM*jnrD;
438 /* load j atom coordinates */
439 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
440 x+j_coord_offsetC,x+j_coord_offsetD,
443 /* Calculate displacement vector */
444 dx00 = _mm_sub_ps(ix0,jx0);
445 dy00 = _mm_sub_ps(iy0,jy0);
446 dz00 = _mm_sub_ps(iz0,jz0);
447 dx10 = _mm_sub_ps(ix1,jx0);
448 dy10 = _mm_sub_ps(iy1,jy0);
449 dz10 = _mm_sub_ps(iz1,jz0);
450 dx20 = _mm_sub_ps(ix2,jx0);
451 dy20 = _mm_sub_ps(iy2,jy0);
452 dz20 = _mm_sub_ps(iz2,jz0);
453 dx30 = _mm_sub_ps(ix3,jx0);
454 dy30 = _mm_sub_ps(iy3,jy0);
455 dz30 = _mm_sub_ps(iz3,jz0);
457 /* Calculate squared distance and things based on it */
458 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
459 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
460 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
461 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
463 rinv00 = sse41_invsqrt_f(rsq00);
464 rinv10 = sse41_invsqrt_f(rsq10);
465 rinv20 = sse41_invsqrt_f(rsq20);
466 rinv30 = sse41_invsqrt_f(rsq30);
468 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
469 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
470 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
472 /* Load parameters for j particles */
473 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
474 charge+jnrC+0,charge+jnrD+0);
475 vdwjidx0A = 2*vdwtype[jnrA+0];
476 vdwjidx0B = 2*vdwtype[jnrB+0];
477 vdwjidx0C = 2*vdwtype[jnrC+0];
478 vdwjidx0D = 2*vdwtype[jnrD+0];
480 fjx0 = _mm_setzero_ps();
481 fjy0 = _mm_setzero_ps();
482 fjz0 = _mm_setzero_ps();
484 /**************************
485 * CALCULATE INTERACTIONS *
486 **************************/
488 r00 = _mm_mul_ps(rsq00,rinv00);
489 r00 = _mm_andnot_ps(dummy_mask,r00);
491 /* Compute parameters for interactions between i and j atoms */
492 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
493 vdwparam+vdwioffset0+vdwjidx0B,
494 vdwparam+vdwioffset0+vdwjidx0C,
495 vdwparam+vdwioffset0+vdwjidx0D,
498 /* Calculate table index by multiplying r with table scale and truncate to integer */
499 rt = _mm_mul_ps(r00,vftabscale);
500 vfitab = _mm_cvttps_epi32(rt);
501 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
502 vfitab = _mm_slli_epi32(vfitab,3);
504 /* CUBIC SPLINE TABLE DISPERSION */
505 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
506 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
507 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
508 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
509 _MM_TRANSPOSE4_PS(Y,F,G,H);
510 Heps = _mm_mul_ps(vfeps,H);
511 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
512 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
513 vvdw6 = _mm_mul_ps(c6_00,VV);
514 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
515 fvdw6 = _mm_mul_ps(c6_00,FF);
517 /* CUBIC SPLINE TABLE REPULSION */
518 vfitab = _mm_add_epi32(vfitab,ifour);
519 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
520 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
521 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
522 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
523 _MM_TRANSPOSE4_PS(Y,F,G,H);
524 Heps = _mm_mul_ps(vfeps,H);
525 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
526 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
527 vvdw12 = _mm_mul_ps(c12_00,VV);
528 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
529 fvdw12 = _mm_mul_ps(c12_00,FF);
530 vvdw = _mm_add_ps(vvdw12,vvdw6);
531 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
533 /* Update potential sum for this i atom from the interaction with this j atom. */
534 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
535 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
539 fscal = _mm_andnot_ps(dummy_mask,fscal);
541 /* Calculate temporary vectorial force */
542 tx = _mm_mul_ps(fscal,dx00);
543 ty = _mm_mul_ps(fscal,dy00);
544 tz = _mm_mul_ps(fscal,dz00);
546 /* Update vectorial force */
547 fix0 = _mm_add_ps(fix0,tx);
548 fiy0 = _mm_add_ps(fiy0,ty);
549 fiz0 = _mm_add_ps(fiz0,tz);
551 fjx0 = _mm_add_ps(fjx0,tx);
552 fjy0 = _mm_add_ps(fjy0,ty);
553 fjz0 = _mm_add_ps(fjz0,tz);
555 /**************************
556 * CALCULATE INTERACTIONS *
557 **************************/
559 /* Compute parameters for interactions between i and j atoms */
560 qq10 = _mm_mul_ps(iq1,jq0);
562 /* COULOMB ELECTROSTATICS */
563 velec = _mm_mul_ps(qq10,rinv10);
564 felec = _mm_mul_ps(velec,rinvsq10);
566 /* Update potential sum for this i atom from the interaction with this j atom. */
567 velec = _mm_andnot_ps(dummy_mask,velec);
568 velecsum = _mm_add_ps(velecsum,velec);
572 fscal = _mm_andnot_ps(dummy_mask,fscal);
574 /* Calculate temporary vectorial force */
575 tx = _mm_mul_ps(fscal,dx10);
576 ty = _mm_mul_ps(fscal,dy10);
577 tz = _mm_mul_ps(fscal,dz10);
579 /* Update vectorial force */
580 fix1 = _mm_add_ps(fix1,tx);
581 fiy1 = _mm_add_ps(fiy1,ty);
582 fiz1 = _mm_add_ps(fiz1,tz);
584 fjx0 = _mm_add_ps(fjx0,tx);
585 fjy0 = _mm_add_ps(fjy0,ty);
586 fjz0 = _mm_add_ps(fjz0,tz);
588 /**************************
589 * CALCULATE INTERACTIONS *
590 **************************/
592 /* Compute parameters for interactions between i and j atoms */
593 qq20 = _mm_mul_ps(iq2,jq0);
595 /* COULOMB ELECTROSTATICS */
596 velec = _mm_mul_ps(qq20,rinv20);
597 felec = _mm_mul_ps(velec,rinvsq20);
599 /* Update potential sum for this i atom from the interaction with this j atom. */
600 velec = _mm_andnot_ps(dummy_mask,velec);
601 velecsum = _mm_add_ps(velecsum,velec);
605 fscal = _mm_andnot_ps(dummy_mask,fscal);
607 /* Calculate temporary vectorial force */
608 tx = _mm_mul_ps(fscal,dx20);
609 ty = _mm_mul_ps(fscal,dy20);
610 tz = _mm_mul_ps(fscal,dz20);
612 /* Update vectorial force */
613 fix2 = _mm_add_ps(fix2,tx);
614 fiy2 = _mm_add_ps(fiy2,ty);
615 fiz2 = _mm_add_ps(fiz2,tz);
617 fjx0 = _mm_add_ps(fjx0,tx);
618 fjy0 = _mm_add_ps(fjy0,ty);
619 fjz0 = _mm_add_ps(fjz0,tz);
621 /**************************
622 * CALCULATE INTERACTIONS *
623 **************************/
625 /* Compute parameters for interactions between i and j atoms */
626 qq30 = _mm_mul_ps(iq3,jq0);
628 /* COULOMB ELECTROSTATICS */
629 velec = _mm_mul_ps(qq30,rinv30);
630 felec = _mm_mul_ps(velec,rinvsq30);
632 /* Update potential sum for this i atom from the interaction with this j atom. */
633 velec = _mm_andnot_ps(dummy_mask,velec);
634 velecsum = _mm_add_ps(velecsum,velec);
638 fscal = _mm_andnot_ps(dummy_mask,fscal);
640 /* Calculate temporary vectorial force */
641 tx = _mm_mul_ps(fscal,dx30);
642 ty = _mm_mul_ps(fscal,dy30);
643 tz = _mm_mul_ps(fscal,dz30);
645 /* Update vectorial force */
646 fix3 = _mm_add_ps(fix3,tx);
647 fiy3 = _mm_add_ps(fiy3,ty);
648 fiz3 = _mm_add_ps(fiz3,tz);
650 fjx0 = _mm_add_ps(fjx0,tx);
651 fjy0 = _mm_add_ps(fjy0,ty);
652 fjz0 = _mm_add_ps(fjz0,tz);
654 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
655 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
656 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
657 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
659 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
661 /* Inner loop uses 141 flops */
664 /* End of innermost loop */
666 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
667 f+i_coord_offset,fshift+i_shift_offset);
670 /* Update potential energies */
671 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
672 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
674 /* Increment number of inner iterations */
675 inneriter += j_index_end - j_index_start;
677 /* Outer loop uses 26 flops */
680 /* Increment number of outer iterations */
683 /* Update outer/inner flops */
685 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*141);
688 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse4_1_single
689 * Electrostatics interaction: Coulomb
690 * VdW interaction: CubicSplineTable
691 * Geometry: Water4-Particle
692 * Calculate force/pot: Force
695 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_sse4_1_single
696 (t_nblist * gmx_restrict nlist,
697 rvec * gmx_restrict xx,
698 rvec * gmx_restrict ff,
699 struct t_forcerec * gmx_restrict fr,
700 t_mdatoms * gmx_restrict mdatoms,
701 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
702 t_nrnb * gmx_restrict nrnb)
704 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
705 * just 0 for non-waters.
706 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
707 * jnr indices corresponding to data put in the four positions in the SIMD register.
709 int i_shift_offset,i_coord_offset,outeriter,inneriter;
710 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
711 int jnrA,jnrB,jnrC,jnrD;
712 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
713 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
714 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
716 real *shiftvec,*fshift,*x,*f;
717 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
719 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
721 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
723 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
725 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
727 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
728 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
729 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
730 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
731 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
732 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
733 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
734 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
737 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
740 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
741 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
743 __m128i ifour = _mm_set1_epi32(4);
744 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
746 __m128 dummy_mask,cutoff_mask;
747 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
748 __m128 one = _mm_set1_ps(1.0);
749 __m128 two = _mm_set1_ps(2.0);
755 jindex = nlist->jindex;
757 shiftidx = nlist->shift;
759 shiftvec = fr->shift_vec[0];
760 fshift = fr->fshift[0];
761 facel = _mm_set1_ps(fr->ic->epsfac);
762 charge = mdatoms->chargeA;
763 nvdwtype = fr->ntype;
765 vdwtype = mdatoms->typeA;
767 vftab = kernel_data->table_vdw->data;
768 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
770 /* Setup water-specific parameters */
771 inr = nlist->iinr[0];
772 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
773 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
774 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
775 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
777 /* Avoid stupid compiler warnings */
778 jnrA = jnrB = jnrC = jnrD = 0;
787 for(iidx=0;iidx<4*DIM;iidx++)
792 /* Start outer loop over neighborlists */
793 for(iidx=0; iidx<nri; iidx++)
795 /* Load shift vector for this list */
796 i_shift_offset = DIM*shiftidx[iidx];
798 /* Load limits for loop over neighbors */
799 j_index_start = jindex[iidx];
800 j_index_end = jindex[iidx+1];
802 /* Get outer coordinate index */
804 i_coord_offset = DIM*inr;
806 /* Load i particle coords and add shift vector */
807 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
808 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
810 fix0 = _mm_setzero_ps();
811 fiy0 = _mm_setzero_ps();
812 fiz0 = _mm_setzero_ps();
813 fix1 = _mm_setzero_ps();
814 fiy1 = _mm_setzero_ps();
815 fiz1 = _mm_setzero_ps();
816 fix2 = _mm_setzero_ps();
817 fiy2 = _mm_setzero_ps();
818 fiz2 = _mm_setzero_ps();
819 fix3 = _mm_setzero_ps();
820 fiy3 = _mm_setzero_ps();
821 fiz3 = _mm_setzero_ps();
823 /* Start inner kernel loop */
824 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
827 /* Get j neighbor index, and coordinate index */
832 j_coord_offsetA = DIM*jnrA;
833 j_coord_offsetB = DIM*jnrB;
834 j_coord_offsetC = DIM*jnrC;
835 j_coord_offsetD = DIM*jnrD;
837 /* load j atom coordinates */
838 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
839 x+j_coord_offsetC,x+j_coord_offsetD,
842 /* Calculate displacement vector */
843 dx00 = _mm_sub_ps(ix0,jx0);
844 dy00 = _mm_sub_ps(iy0,jy0);
845 dz00 = _mm_sub_ps(iz0,jz0);
846 dx10 = _mm_sub_ps(ix1,jx0);
847 dy10 = _mm_sub_ps(iy1,jy0);
848 dz10 = _mm_sub_ps(iz1,jz0);
849 dx20 = _mm_sub_ps(ix2,jx0);
850 dy20 = _mm_sub_ps(iy2,jy0);
851 dz20 = _mm_sub_ps(iz2,jz0);
852 dx30 = _mm_sub_ps(ix3,jx0);
853 dy30 = _mm_sub_ps(iy3,jy0);
854 dz30 = _mm_sub_ps(iz3,jz0);
856 /* Calculate squared distance and things based on it */
857 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
858 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
859 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
860 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
862 rinv00 = sse41_invsqrt_f(rsq00);
863 rinv10 = sse41_invsqrt_f(rsq10);
864 rinv20 = sse41_invsqrt_f(rsq20);
865 rinv30 = sse41_invsqrt_f(rsq30);
867 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
868 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
869 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
871 /* Load parameters for j particles */
872 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
873 charge+jnrC+0,charge+jnrD+0);
874 vdwjidx0A = 2*vdwtype[jnrA+0];
875 vdwjidx0B = 2*vdwtype[jnrB+0];
876 vdwjidx0C = 2*vdwtype[jnrC+0];
877 vdwjidx0D = 2*vdwtype[jnrD+0];
879 fjx0 = _mm_setzero_ps();
880 fjy0 = _mm_setzero_ps();
881 fjz0 = _mm_setzero_ps();
883 /**************************
884 * CALCULATE INTERACTIONS *
885 **************************/
887 r00 = _mm_mul_ps(rsq00,rinv00);
889 /* Compute parameters for interactions between i and j atoms */
890 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
891 vdwparam+vdwioffset0+vdwjidx0B,
892 vdwparam+vdwioffset0+vdwjidx0C,
893 vdwparam+vdwioffset0+vdwjidx0D,
896 /* Calculate table index by multiplying r with table scale and truncate to integer */
897 rt = _mm_mul_ps(r00,vftabscale);
898 vfitab = _mm_cvttps_epi32(rt);
899 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
900 vfitab = _mm_slli_epi32(vfitab,3);
902 /* CUBIC SPLINE TABLE DISPERSION */
903 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
904 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
905 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
906 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
907 _MM_TRANSPOSE4_PS(Y,F,G,H);
908 Heps = _mm_mul_ps(vfeps,H);
909 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
910 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
911 fvdw6 = _mm_mul_ps(c6_00,FF);
913 /* CUBIC SPLINE TABLE REPULSION */
914 vfitab = _mm_add_epi32(vfitab,ifour);
915 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
916 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
917 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
918 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
919 _MM_TRANSPOSE4_PS(Y,F,G,H);
920 Heps = _mm_mul_ps(vfeps,H);
921 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
922 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
923 fvdw12 = _mm_mul_ps(c12_00,FF);
924 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
928 /* Calculate temporary vectorial force */
929 tx = _mm_mul_ps(fscal,dx00);
930 ty = _mm_mul_ps(fscal,dy00);
931 tz = _mm_mul_ps(fscal,dz00);
933 /* Update vectorial force */
934 fix0 = _mm_add_ps(fix0,tx);
935 fiy0 = _mm_add_ps(fiy0,ty);
936 fiz0 = _mm_add_ps(fiz0,tz);
938 fjx0 = _mm_add_ps(fjx0,tx);
939 fjy0 = _mm_add_ps(fjy0,ty);
940 fjz0 = _mm_add_ps(fjz0,tz);
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 /* Compute parameters for interactions between i and j atoms */
947 qq10 = _mm_mul_ps(iq1,jq0);
949 /* COULOMB ELECTROSTATICS */
950 velec = _mm_mul_ps(qq10,rinv10);
951 felec = _mm_mul_ps(velec,rinvsq10);
955 /* Calculate temporary vectorial force */
956 tx = _mm_mul_ps(fscal,dx10);
957 ty = _mm_mul_ps(fscal,dy10);
958 tz = _mm_mul_ps(fscal,dz10);
960 /* Update vectorial force */
961 fix1 = _mm_add_ps(fix1,tx);
962 fiy1 = _mm_add_ps(fiy1,ty);
963 fiz1 = _mm_add_ps(fiz1,tz);
965 fjx0 = _mm_add_ps(fjx0,tx);
966 fjy0 = _mm_add_ps(fjy0,ty);
967 fjz0 = _mm_add_ps(fjz0,tz);
969 /**************************
970 * CALCULATE INTERACTIONS *
971 **************************/
973 /* Compute parameters for interactions between i and j atoms */
974 qq20 = _mm_mul_ps(iq2,jq0);
976 /* COULOMB ELECTROSTATICS */
977 velec = _mm_mul_ps(qq20,rinv20);
978 felec = _mm_mul_ps(velec,rinvsq20);
982 /* Calculate temporary vectorial force */
983 tx = _mm_mul_ps(fscal,dx20);
984 ty = _mm_mul_ps(fscal,dy20);
985 tz = _mm_mul_ps(fscal,dz20);
987 /* Update vectorial force */
988 fix2 = _mm_add_ps(fix2,tx);
989 fiy2 = _mm_add_ps(fiy2,ty);
990 fiz2 = _mm_add_ps(fiz2,tz);
992 fjx0 = _mm_add_ps(fjx0,tx);
993 fjy0 = _mm_add_ps(fjy0,ty);
994 fjz0 = _mm_add_ps(fjz0,tz);
996 /**************************
997 * CALCULATE INTERACTIONS *
998 **************************/
1000 /* Compute parameters for interactions between i and j atoms */
1001 qq30 = _mm_mul_ps(iq3,jq0);
1003 /* COULOMB ELECTROSTATICS */
1004 velec = _mm_mul_ps(qq30,rinv30);
1005 felec = _mm_mul_ps(velec,rinvsq30);
1009 /* Calculate temporary vectorial force */
1010 tx = _mm_mul_ps(fscal,dx30);
1011 ty = _mm_mul_ps(fscal,dy30);
1012 tz = _mm_mul_ps(fscal,dz30);
1014 /* Update vectorial force */
1015 fix3 = _mm_add_ps(fix3,tx);
1016 fiy3 = _mm_add_ps(fiy3,ty);
1017 fiz3 = _mm_add_ps(fiz3,tz);
1019 fjx0 = _mm_add_ps(fjx0,tx);
1020 fjy0 = _mm_add_ps(fjy0,ty);
1021 fjz0 = _mm_add_ps(fjz0,tz);
1023 fjptrA = f+j_coord_offsetA;
1024 fjptrB = f+j_coord_offsetB;
1025 fjptrC = f+j_coord_offsetC;
1026 fjptrD = f+j_coord_offsetD;
1028 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1030 /* Inner loop uses 129 flops */
1033 if(jidx<j_index_end)
1036 /* Get j neighbor index, and coordinate index */
1037 jnrlistA = jjnr[jidx];
1038 jnrlistB = jjnr[jidx+1];
1039 jnrlistC = jjnr[jidx+2];
1040 jnrlistD = jjnr[jidx+3];
1041 /* Sign of each element will be negative for non-real atoms.
1042 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1043 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1045 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1046 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1047 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1048 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1049 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1050 j_coord_offsetA = DIM*jnrA;
1051 j_coord_offsetB = DIM*jnrB;
1052 j_coord_offsetC = DIM*jnrC;
1053 j_coord_offsetD = DIM*jnrD;
1055 /* load j atom coordinates */
1056 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1057 x+j_coord_offsetC,x+j_coord_offsetD,
1060 /* Calculate displacement vector */
1061 dx00 = _mm_sub_ps(ix0,jx0);
1062 dy00 = _mm_sub_ps(iy0,jy0);
1063 dz00 = _mm_sub_ps(iz0,jz0);
1064 dx10 = _mm_sub_ps(ix1,jx0);
1065 dy10 = _mm_sub_ps(iy1,jy0);
1066 dz10 = _mm_sub_ps(iz1,jz0);
1067 dx20 = _mm_sub_ps(ix2,jx0);
1068 dy20 = _mm_sub_ps(iy2,jy0);
1069 dz20 = _mm_sub_ps(iz2,jz0);
1070 dx30 = _mm_sub_ps(ix3,jx0);
1071 dy30 = _mm_sub_ps(iy3,jy0);
1072 dz30 = _mm_sub_ps(iz3,jz0);
1074 /* Calculate squared distance and things based on it */
1075 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1076 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1077 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1078 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1080 rinv00 = sse41_invsqrt_f(rsq00);
1081 rinv10 = sse41_invsqrt_f(rsq10);
1082 rinv20 = sse41_invsqrt_f(rsq20);
1083 rinv30 = sse41_invsqrt_f(rsq30);
1085 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1086 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1087 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1089 /* Load parameters for j particles */
1090 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1091 charge+jnrC+0,charge+jnrD+0);
1092 vdwjidx0A = 2*vdwtype[jnrA+0];
1093 vdwjidx0B = 2*vdwtype[jnrB+0];
1094 vdwjidx0C = 2*vdwtype[jnrC+0];
1095 vdwjidx0D = 2*vdwtype[jnrD+0];
1097 fjx0 = _mm_setzero_ps();
1098 fjy0 = _mm_setzero_ps();
1099 fjz0 = _mm_setzero_ps();
1101 /**************************
1102 * CALCULATE INTERACTIONS *
1103 **************************/
1105 r00 = _mm_mul_ps(rsq00,rinv00);
1106 r00 = _mm_andnot_ps(dummy_mask,r00);
1108 /* Compute parameters for interactions between i and j atoms */
1109 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1110 vdwparam+vdwioffset0+vdwjidx0B,
1111 vdwparam+vdwioffset0+vdwjidx0C,
1112 vdwparam+vdwioffset0+vdwjidx0D,
1115 /* Calculate table index by multiplying r with table scale and truncate to integer */
1116 rt = _mm_mul_ps(r00,vftabscale);
1117 vfitab = _mm_cvttps_epi32(rt);
1118 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1119 vfitab = _mm_slli_epi32(vfitab,3);
1121 /* CUBIC SPLINE TABLE DISPERSION */
1122 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1123 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1124 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1125 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1126 _MM_TRANSPOSE4_PS(Y,F,G,H);
1127 Heps = _mm_mul_ps(vfeps,H);
1128 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1129 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1130 fvdw6 = _mm_mul_ps(c6_00,FF);
1132 /* CUBIC SPLINE TABLE REPULSION */
1133 vfitab = _mm_add_epi32(vfitab,ifour);
1134 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1135 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1136 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1137 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1138 _MM_TRANSPOSE4_PS(Y,F,G,H);
1139 Heps = _mm_mul_ps(vfeps,H);
1140 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1141 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1142 fvdw12 = _mm_mul_ps(c12_00,FF);
1143 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1147 fscal = _mm_andnot_ps(dummy_mask,fscal);
1149 /* Calculate temporary vectorial force */
1150 tx = _mm_mul_ps(fscal,dx00);
1151 ty = _mm_mul_ps(fscal,dy00);
1152 tz = _mm_mul_ps(fscal,dz00);
1154 /* Update vectorial force */
1155 fix0 = _mm_add_ps(fix0,tx);
1156 fiy0 = _mm_add_ps(fiy0,ty);
1157 fiz0 = _mm_add_ps(fiz0,tz);
1159 fjx0 = _mm_add_ps(fjx0,tx);
1160 fjy0 = _mm_add_ps(fjy0,ty);
1161 fjz0 = _mm_add_ps(fjz0,tz);
1163 /**************************
1164 * CALCULATE INTERACTIONS *
1165 **************************/
1167 /* Compute parameters for interactions between i and j atoms */
1168 qq10 = _mm_mul_ps(iq1,jq0);
1170 /* COULOMB ELECTROSTATICS */
1171 velec = _mm_mul_ps(qq10,rinv10);
1172 felec = _mm_mul_ps(velec,rinvsq10);
1176 fscal = _mm_andnot_ps(dummy_mask,fscal);
1178 /* Calculate temporary vectorial force */
1179 tx = _mm_mul_ps(fscal,dx10);
1180 ty = _mm_mul_ps(fscal,dy10);
1181 tz = _mm_mul_ps(fscal,dz10);
1183 /* Update vectorial force */
1184 fix1 = _mm_add_ps(fix1,tx);
1185 fiy1 = _mm_add_ps(fiy1,ty);
1186 fiz1 = _mm_add_ps(fiz1,tz);
1188 fjx0 = _mm_add_ps(fjx0,tx);
1189 fjy0 = _mm_add_ps(fjy0,ty);
1190 fjz0 = _mm_add_ps(fjz0,tz);
1192 /**************************
1193 * CALCULATE INTERACTIONS *
1194 **************************/
1196 /* Compute parameters for interactions between i and j atoms */
1197 qq20 = _mm_mul_ps(iq2,jq0);
1199 /* COULOMB ELECTROSTATICS */
1200 velec = _mm_mul_ps(qq20,rinv20);
1201 felec = _mm_mul_ps(velec,rinvsq20);
1205 fscal = _mm_andnot_ps(dummy_mask,fscal);
1207 /* Calculate temporary vectorial force */
1208 tx = _mm_mul_ps(fscal,dx20);
1209 ty = _mm_mul_ps(fscal,dy20);
1210 tz = _mm_mul_ps(fscal,dz20);
1212 /* Update vectorial force */
1213 fix2 = _mm_add_ps(fix2,tx);
1214 fiy2 = _mm_add_ps(fiy2,ty);
1215 fiz2 = _mm_add_ps(fiz2,tz);
1217 fjx0 = _mm_add_ps(fjx0,tx);
1218 fjy0 = _mm_add_ps(fjy0,ty);
1219 fjz0 = _mm_add_ps(fjz0,tz);
1221 /**************************
1222 * CALCULATE INTERACTIONS *
1223 **************************/
1225 /* Compute parameters for interactions between i and j atoms */
1226 qq30 = _mm_mul_ps(iq3,jq0);
1228 /* COULOMB ELECTROSTATICS */
1229 velec = _mm_mul_ps(qq30,rinv30);
1230 felec = _mm_mul_ps(velec,rinvsq30);
1234 fscal = _mm_andnot_ps(dummy_mask,fscal);
1236 /* Calculate temporary vectorial force */
1237 tx = _mm_mul_ps(fscal,dx30);
1238 ty = _mm_mul_ps(fscal,dy30);
1239 tz = _mm_mul_ps(fscal,dz30);
1241 /* Update vectorial force */
1242 fix3 = _mm_add_ps(fix3,tx);
1243 fiy3 = _mm_add_ps(fiy3,ty);
1244 fiz3 = _mm_add_ps(fiz3,tz);
1246 fjx0 = _mm_add_ps(fjx0,tx);
1247 fjy0 = _mm_add_ps(fjy0,ty);
1248 fjz0 = _mm_add_ps(fjz0,tz);
1250 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1251 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1252 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1253 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1255 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1257 /* Inner loop uses 130 flops */
1260 /* End of innermost loop */
1262 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1263 f+i_coord_offset,fshift+i_shift_offset);
1265 /* Increment number of inner iterations */
1266 inneriter += j_index_end - j_index_start;
1268 /* Outer loop uses 24 flops */
1271 /* Increment number of outer iterations */
1274 /* Update outer/inner flops */
1276 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*130);