2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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 "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4W4_VF_sse2_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water4-Water4
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwCSTab_GeomW4W4_VF_sse2_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 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
93 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
94 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
95 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
96 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
97 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
98 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
99 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
100 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
101 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
102 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
103 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
104 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
105 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
106 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
107 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
108 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
111 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
114 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
115 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
117 __m128i ifour = _mm_set1_epi32(4);
118 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
120 __m128 dummy_mask,cutoff_mask;
121 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
122 __m128 one = _mm_set1_ps(1.0);
123 __m128 two = _mm_set1_ps(2.0);
129 jindex = nlist->jindex;
131 shiftidx = nlist->shift;
133 shiftvec = fr->shift_vec[0];
134 fshift = fr->fshift[0];
135 facel = _mm_set1_ps(fr->ic->epsfac);
136 charge = mdatoms->chargeA;
137 krf = _mm_set1_ps(fr->ic->k_rf);
138 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
139 crf = _mm_set1_ps(fr->ic->c_rf);
140 nvdwtype = fr->ntype;
142 vdwtype = mdatoms->typeA;
144 vftab = kernel_data->table_vdw->data;
145 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
147 /* Setup water-specific parameters */
148 inr = nlist->iinr[0];
149 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
150 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
151 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
152 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
154 jq1 = _mm_set1_ps(charge[inr+1]);
155 jq2 = _mm_set1_ps(charge[inr+2]);
156 jq3 = _mm_set1_ps(charge[inr+3]);
157 vdwjidx0A = 2*vdwtype[inr+0];
158 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
159 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
160 qq11 = _mm_mul_ps(iq1,jq1);
161 qq12 = _mm_mul_ps(iq1,jq2);
162 qq13 = _mm_mul_ps(iq1,jq3);
163 qq21 = _mm_mul_ps(iq2,jq1);
164 qq22 = _mm_mul_ps(iq2,jq2);
165 qq23 = _mm_mul_ps(iq2,jq3);
166 qq31 = _mm_mul_ps(iq3,jq1);
167 qq32 = _mm_mul_ps(iq3,jq2);
168 qq33 = _mm_mul_ps(iq3,jq3);
170 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
171 rcutoff_scalar = fr->ic->rcoulomb;
172 rcutoff = _mm_set1_ps(rcutoff_scalar);
173 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
175 /* Avoid stupid compiler warnings */
176 jnrA = jnrB = jnrC = jnrD = 0;
185 for(iidx=0;iidx<4*DIM;iidx++)
190 /* Start outer loop over neighborlists */
191 for(iidx=0; iidx<nri; iidx++)
193 /* Load shift vector for this list */
194 i_shift_offset = DIM*shiftidx[iidx];
196 /* Load limits for loop over neighbors */
197 j_index_start = jindex[iidx];
198 j_index_end = jindex[iidx+1];
200 /* Get outer coordinate index */
202 i_coord_offset = DIM*inr;
204 /* Load i particle coords and add shift vector */
205 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
206 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
208 fix0 = _mm_setzero_ps();
209 fiy0 = _mm_setzero_ps();
210 fiz0 = _mm_setzero_ps();
211 fix1 = _mm_setzero_ps();
212 fiy1 = _mm_setzero_ps();
213 fiz1 = _mm_setzero_ps();
214 fix2 = _mm_setzero_ps();
215 fiy2 = _mm_setzero_ps();
216 fiz2 = _mm_setzero_ps();
217 fix3 = _mm_setzero_ps();
218 fiy3 = _mm_setzero_ps();
219 fiz3 = _mm_setzero_ps();
221 /* Reset potential sums */
222 velecsum = _mm_setzero_ps();
223 vvdwsum = _mm_setzero_ps();
225 /* Start inner kernel loop */
226 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
229 /* Get j neighbor index, and coordinate index */
234 j_coord_offsetA = DIM*jnrA;
235 j_coord_offsetB = DIM*jnrB;
236 j_coord_offsetC = DIM*jnrC;
237 j_coord_offsetD = DIM*jnrD;
239 /* load j atom coordinates */
240 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
241 x+j_coord_offsetC,x+j_coord_offsetD,
242 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
243 &jy2,&jz2,&jx3,&jy3,&jz3);
245 /* Calculate displacement vector */
246 dx00 = _mm_sub_ps(ix0,jx0);
247 dy00 = _mm_sub_ps(iy0,jy0);
248 dz00 = _mm_sub_ps(iz0,jz0);
249 dx11 = _mm_sub_ps(ix1,jx1);
250 dy11 = _mm_sub_ps(iy1,jy1);
251 dz11 = _mm_sub_ps(iz1,jz1);
252 dx12 = _mm_sub_ps(ix1,jx2);
253 dy12 = _mm_sub_ps(iy1,jy2);
254 dz12 = _mm_sub_ps(iz1,jz2);
255 dx13 = _mm_sub_ps(ix1,jx3);
256 dy13 = _mm_sub_ps(iy1,jy3);
257 dz13 = _mm_sub_ps(iz1,jz3);
258 dx21 = _mm_sub_ps(ix2,jx1);
259 dy21 = _mm_sub_ps(iy2,jy1);
260 dz21 = _mm_sub_ps(iz2,jz1);
261 dx22 = _mm_sub_ps(ix2,jx2);
262 dy22 = _mm_sub_ps(iy2,jy2);
263 dz22 = _mm_sub_ps(iz2,jz2);
264 dx23 = _mm_sub_ps(ix2,jx3);
265 dy23 = _mm_sub_ps(iy2,jy3);
266 dz23 = _mm_sub_ps(iz2,jz3);
267 dx31 = _mm_sub_ps(ix3,jx1);
268 dy31 = _mm_sub_ps(iy3,jy1);
269 dz31 = _mm_sub_ps(iz3,jz1);
270 dx32 = _mm_sub_ps(ix3,jx2);
271 dy32 = _mm_sub_ps(iy3,jy2);
272 dz32 = _mm_sub_ps(iz3,jz2);
273 dx33 = _mm_sub_ps(ix3,jx3);
274 dy33 = _mm_sub_ps(iy3,jy3);
275 dz33 = _mm_sub_ps(iz3,jz3);
277 /* Calculate squared distance and things based on it */
278 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
279 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
280 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
281 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
282 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
283 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
284 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
285 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
286 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
287 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
289 rinv00 = sse2_invsqrt_f(rsq00);
290 rinv11 = sse2_invsqrt_f(rsq11);
291 rinv12 = sse2_invsqrt_f(rsq12);
292 rinv13 = sse2_invsqrt_f(rsq13);
293 rinv21 = sse2_invsqrt_f(rsq21);
294 rinv22 = sse2_invsqrt_f(rsq22);
295 rinv23 = sse2_invsqrt_f(rsq23);
296 rinv31 = sse2_invsqrt_f(rsq31);
297 rinv32 = sse2_invsqrt_f(rsq32);
298 rinv33 = sse2_invsqrt_f(rsq33);
300 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
301 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
302 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
303 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
304 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
305 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
306 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
307 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
308 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
310 fjx0 = _mm_setzero_ps();
311 fjy0 = _mm_setzero_ps();
312 fjz0 = _mm_setzero_ps();
313 fjx1 = _mm_setzero_ps();
314 fjy1 = _mm_setzero_ps();
315 fjz1 = _mm_setzero_ps();
316 fjx2 = _mm_setzero_ps();
317 fjy2 = _mm_setzero_ps();
318 fjz2 = _mm_setzero_ps();
319 fjx3 = _mm_setzero_ps();
320 fjy3 = _mm_setzero_ps();
321 fjz3 = _mm_setzero_ps();
323 /**************************
324 * CALCULATE INTERACTIONS *
325 **************************/
327 if (gmx_mm_any_lt(rsq00,rcutoff2))
330 r00 = _mm_mul_ps(rsq00,rinv00);
332 /* Calculate table index by multiplying r with table scale and truncate to integer */
333 rt = _mm_mul_ps(r00,vftabscale);
334 vfitab = _mm_cvttps_epi32(rt);
335 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
336 vfitab = _mm_slli_epi32(vfitab,3);
338 /* CUBIC SPLINE TABLE DISPERSION */
339 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
340 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
341 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
342 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
343 _MM_TRANSPOSE4_PS(Y,F,G,H);
344 Heps = _mm_mul_ps(vfeps,H);
345 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
346 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
347 vvdw6 = _mm_mul_ps(c6_00,VV);
348 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
349 fvdw6 = _mm_mul_ps(c6_00,FF);
351 /* CUBIC SPLINE TABLE REPULSION */
352 vfitab = _mm_add_epi32(vfitab,ifour);
353 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
354 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
355 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
356 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
357 _MM_TRANSPOSE4_PS(Y,F,G,H);
358 Heps = _mm_mul_ps(vfeps,H);
359 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
360 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
361 vvdw12 = _mm_mul_ps(c12_00,VV);
362 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
363 fvdw12 = _mm_mul_ps(c12_00,FF);
364 vvdw = _mm_add_ps(vvdw12,vvdw6);
365 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
367 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
369 /* Update potential sum for this i atom from the interaction with this j atom. */
370 vvdw = _mm_and_ps(vvdw,cutoff_mask);
371 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
375 fscal = _mm_and_ps(fscal,cutoff_mask);
377 /* Calculate temporary vectorial force */
378 tx = _mm_mul_ps(fscal,dx00);
379 ty = _mm_mul_ps(fscal,dy00);
380 tz = _mm_mul_ps(fscal,dz00);
382 /* Update vectorial force */
383 fix0 = _mm_add_ps(fix0,tx);
384 fiy0 = _mm_add_ps(fiy0,ty);
385 fiz0 = _mm_add_ps(fiz0,tz);
387 fjx0 = _mm_add_ps(fjx0,tx);
388 fjy0 = _mm_add_ps(fjy0,ty);
389 fjz0 = _mm_add_ps(fjz0,tz);
393 /**************************
394 * CALCULATE INTERACTIONS *
395 **************************/
397 if (gmx_mm_any_lt(rsq11,rcutoff2))
400 /* REACTION-FIELD ELECTROSTATICS */
401 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
402 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
404 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
406 /* Update potential sum for this i atom from the interaction with this j atom. */
407 velec = _mm_and_ps(velec,cutoff_mask);
408 velecsum = _mm_add_ps(velecsum,velec);
412 fscal = _mm_and_ps(fscal,cutoff_mask);
414 /* Calculate temporary vectorial force */
415 tx = _mm_mul_ps(fscal,dx11);
416 ty = _mm_mul_ps(fscal,dy11);
417 tz = _mm_mul_ps(fscal,dz11);
419 /* Update vectorial force */
420 fix1 = _mm_add_ps(fix1,tx);
421 fiy1 = _mm_add_ps(fiy1,ty);
422 fiz1 = _mm_add_ps(fiz1,tz);
424 fjx1 = _mm_add_ps(fjx1,tx);
425 fjy1 = _mm_add_ps(fjy1,ty);
426 fjz1 = _mm_add_ps(fjz1,tz);
430 /**************************
431 * CALCULATE INTERACTIONS *
432 **************************/
434 if (gmx_mm_any_lt(rsq12,rcutoff2))
437 /* REACTION-FIELD ELECTROSTATICS */
438 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
439 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
441 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
443 /* Update potential sum for this i atom from the interaction with this j atom. */
444 velec = _mm_and_ps(velec,cutoff_mask);
445 velecsum = _mm_add_ps(velecsum,velec);
449 fscal = _mm_and_ps(fscal,cutoff_mask);
451 /* Calculate temporary vectorial force */
452 tx = _mm_mul_ps(fscal,dx12);
453 ty = _mm_mul_ps(fscal,dy12);
454 tz = _mm_mul_ps(fscal,dz12);
456 /* Update vectorial force */
457 fix1 = _mm_add_ps(fix1,tx);
458 fiy1 = _mm_add_ps(fiy1,ty);
459 fiz1 = _mm_add_ps(fiz1,tz);
461 fjx2 = _mm_add_ps(fjx2,tx);
462 fjy2 = _mm_add_ps(fjy2,ty);
463 fjz2 = _mm_add_ps(fjz2,tz);
467 /**************************
468 * CALCULATE INTERACTIONS *
469 **************************/
471 if (gmx_mm_any_lt(rsq13,rcutoff2))
474 /* REACTION-FIELD ELECTROSTATICS */
475 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
476 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
478 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
480 /* Update potential sum for this i atom from the interaction with this j atom. */
481 velec = _mm_and_ps(velec,cutoff_mask);
482 velecsum = _mm_add_ps(velecsum,velec);
486 fscal = _mm_and_ps(fscal,cutoff_mask);
488 /* Calculate temporary vectorial force */
489 tx = _mm_mul_ps(fscal,dx13);
490 ty = _mm_mul_ps(fscal,dy13);
491 tz = _mm_mul_ps(fscal,dz13);
493 /* Update vectorial force */
494 fix1 = _mm_add_ps(fix1,tx);
495 fiy1 = _mm_add_ps(fiy1,ty);
496 fiz1 = _mm_add_ps(fiz1,tz);
498 fjx3 = _mm_add_ps(fjx3,tx);
499 fjy3 = _mm_add_ps(fjy3,ty);
500 fjz3 = _mm_add_ps(fjz3,tz);
504 /**************************
505 * CALCULATE INTERACTIONS *
506 **************************/
508 if (gmx_mm_any_lt(rsq21,rcutoff2))
511 /* REACTION-FIELD ELECTROSTATICS */
512 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
513 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
515 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
517 /* Update potential sum for this i atom from the interaction with this j atom. */
518 velec = _mm_and_ps(velec,cutoff_mask);
519 velecsum = _mm_add_ps(velecsum,velec);
523 fscal = _mm_and_ps(fscal,cutoff_mask);
525 /* Calculate temporary vectorial force */
526 tx = _mm_mul_ps(fscal,dx21);
527 ty = _mm_mul_ps(fscal,dy21);
528 tz = _mm_mul_ps(fscal,dz21);
530 /* Update vectorial force */
531 fix2 = _mm_add_ps(fix2,tx);
532 fiy2 = _mm_add_ps(fiy2,ty);
533 fiz2 = _mm_add_ps(fiz2,tz);
535 fjx1 = _mm_add_ps(fjx1,tx);
536 fjy1 = _mm_add_ps(fjy1,ty);
537 fjz1 = _mm_add_ps(fjz1,tz);
541 /**************************
542 * CALCULATE INTERACTIONS *
543 **************************/
545 if (gmx_mm_any_lt(rsq22,rcutoff2))
548 /* REACTION-FIELD ELECTROSTATICS */
549 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
550 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
552 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
554 /* Update potential sum for this i atom from the interaction with this j atom. */
555 velec = _mm_and_ps(velec,cutoff_mask);
556 velecsum = _mm_add_ps(velecsum,velec);
560 fscal = _mm_and_ps(fscal,cutoff_mask);
562 /* Calculate temporary vectorial force */
563 tx = _mm_mul_ps(fscal,dx22);
564 ty = _mm_mul_ps(fscal,dy22);
565 tz = _mm_mul_ps(fscal,dz22);
567 /* Update vectorial force */
568 fix2 = _mm_add_ps(fix2,tx);
569 fiy2 = _mm_add_ps(fiy2,ty);
570 fiz2 = _mm_add_ps(fiz2,tz);
572 fjx2 = _mm_add_ps(fjx2,tx);
573 fjy2 = _mm_add_ps(fjy2,ty);
574 fjz2 = _mm_add_ps(fjz2,tz);
578 /**************************
579 * CALCULATE INTERACTIONS *
580 **************************/
582 if (gmx_mm_any_lt(rsq23,rcutoff2))
585 /* REACTION-FIELD ELECTROSTATICS */
586 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
587 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
589 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
591 /* Update potential sum for this i atom from the interaction with this j atom. */
592 velec = _mm_and_ps(velec,cutoff_mask);
593 velecsum = _mm_add_ps(velecsum,velec);
597 fscal = _mm_and_ps(fscal,cutoff_mask);
599 /* Calculate temporary vectorial force */
600 tx = _mm_mul_ps(fscal,dx23);
601 ty = _mm_mul_ps(fscal,dy23);
602 tz = _mm_mul_ps(fscal,dz23);
604 /* Update vectorial force */
605 fix2 = _mm_add_ps(fix2,tx);
606 fiy2 = _mm_add_ps(fiy2,ty);
607 fiz2 = _mm_add_ps(fiz2,tz);
609 fjx3 = _mm_add_ps(fjx3,tx);
610 fjy3 = _mm_add_ps(fjy3,ty);
611 fjz3 = _mm_add_ps(fjz3,tz);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq31,rcutoff2))
622 /* REACTION-FIELD ELECTROSTATICS */
623 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
624 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
626 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
628 /* Update potential sum for this i atom from the interaction with this j atom. */
629 velec = _mm_and_ps(velec,cutoff_mask);
630 velecsum = _mm_add_ps(velecsum,velec);
634 fscal = _mm_and_ps(fscal,cutoff_mask);
636 /* Calculate temporary vectorial force */
637 tx = _mm_mul_ps(fscal,dx31);
638 ty = _mm_mul_ps(fscal,dy31);
639 tz = _mm_mul_ps(fscal,dz31);
641 /* Update vectorial force */
642 fix3 = _mm_add_ps(fix3,tx);
643 fiy3 = _mm_add_ps(fiy3,ty);
644 fiz3 = _mm_add_ps(fiz3,tz);
646 fjx1 = _mm_add_ps(fjx1,tx);
647 fjy1 = _mm_add_ps(fjy1,ty);
648 fjz1 = _mm_add_ps(fjz1,tz);
652 /**************************
653 * CALCULATE INTERACTIONS *
654 **************************/
656 if (gmx_mm_any_lt(rsq32,rcutoff2))
659 /* REACTION-FIELD ELECTROSTATICS */
660 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
661 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
663 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
665 /* Update potential sum for this i atom from the interaction with this j atom. */
666 velec = _mm_and_ps(velec,cutoff_mask);
667 velecsum = _mm_add_ps(velecsum,velec);
671 fscal = _mm_and_ps(fscal,cutoff_mask);
673 /* Calculate temporary vectorial force */
674 tx = _mm_mul_ps(fscal,dx32);
675 ty = _mm_mul_ps(fscal,dy32);
676 tz = _mm_mul_ps(fscal,dz32);
678 /* Update vectorial force */
679 fix3 = _mm_add_ps(fix3,tx);
680 fiy3 = _mm_add_ps(fiy3,ty);
681 fiz3 = _mm_add_ps(fiz3,tz);
683 fjx2 = _mm_add_ps(fjx2,tx);
684 fjy2 = _mm_add_ps(fjy2,ty);
685 fjz2 = _mm_add_ps(fjz2,tz);
689 /**************************
690 * CALCULATE INTERACTIONS *
691 **************************/
693 if (gmx_mm_any_lt(rsq33,rcutoff2))
696 /* REACTION-FIELD ELECTROSTATICS */
697 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
698 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
700 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
702 /* Update potential sum for this i atom from the interaction with this j atom. */
703 velec = _mm_and_ps(velec,cutoff_mask);
704 velecsum = _mm_add_ps(velecsum,velec);
708 fscal = _mm_and_ps(fscal,cutoff_mask);
710 /* Calculate temporary vectorial force */
711 tx = _mm_mul_ps(fscal,dx33);
712 ty = _mm_mul_ps(fscal,dy33);
713 tz = _mm_mul_ps(fscal,dz33);
715 /* Update vectorial force */
716 fix3 = _mm_add_ps(fix3,tx);
717 fiy3 = _mm_add_ps(fiy3,ty);
718 fiz3 = _mm_add_ps(fiz3,tz);
720 fjx3 = _mm_add_ps(fjx3,tx);
721 fjy3 = _mm_add_ps(fjy3,ty);
722 fjz3 = _mm_add_ps(fjz3,tz);
726 fjptrA = f+j_coord_offsetA;
727 fjptrB = f+j_coord_offsetB;
728 fjptrC = f+j_coord_offsetC;
729 fjptrD = f+j_coord_offsetD;
731 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
732 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
733 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
735 /* Inner loop uses 387 flops */
741 /* Get j neighbor index, and coordinate index */
742 jnrlistA = jjnr[jidx];
743 jnrlistB = jjnr[jidx+1];
744 jnrlistC = jjnr[jidx+2];
745 jnrlistD = jjnr[jidx+3];
746 /* Sign of each element will be negative for non-real atoms.
747 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
748 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
750 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
751 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
752 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
753 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
754 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
755 j_coord_offsetA = DIM*jnrA;
756 j_coord_offsetB = DIM*jnrB;
757 j_coord_offsetC = DIM*jnrC;
758 j_coord_offsetD = DIM*jnrD;
760 /* load j atom coordinates */
761 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
762 x+j_coord_offsetC,x+j_coord_offsetD,
763 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
764 &jy2,&jz2,&jx3,&jy3,&jz3);
766 /* Calculate displacement vector */
767 dx00 = _mm_sub_ps(ix0,jx0);
768 dy00 = _mm_sub_ps(iy0,jy0);
769 dz00 = _mm_sub_ps(iz0,jz0);
770 dx11 = _mm_sub_ps(ix1,jx1);
771 dy11 = _mm_sub_ps(iy1,jy1);
772 dz11 = _mm_sub_ps(iz1,jz1);
773 dx12 = _mm_sub_ps(ix1,jx2);
774 dy12 = _mm_sub_ps(iy1,jy2);
775 dz12 = _mm_sub_ps(iz1,jz2);
776 dx13 = _mm_sub_ps(ix1,jx3);
777 dy13 = _mm_sub_ps(iy1,jy3);
778 dz13 = _mm_sub_ps(iz1,jz3);
779 dx21 = _mm_sub_ps(ix2,jx1);
780 dy21 = _mm_sub_ps(iy2,jy1);
781 dz21 = _mm_sub_ps(iz2,jz1);
782 dx22 = _mm_sub_ps(ix2,jx2);
783 dy22 = _mm_sub_ps(iy2,jy2);
784 dz22 = _mm_sub_ps(iz2,jz2);
785 dx23 = _mm_sub_ps(ix2,jx3);
786 dy23 = _mm_sub_ps(iy2,jy3);
787 dz23 = _mm_sub_ps(iz2,jz3);
788 dx31 = _mm_sub_ps(ix3,jx1);
789 dy31 = _mm_sub_ps(iy3,jy1);
790 dz31 = _mm_sub_ps(iz3,jz1);
791 dx32 = _mm_sub_ps(ix3,jx2);
792 dy32 = _mm_sub_ps(iy3,jy2);
793 dz32 = _mm_sub_ps(iz3,jz2);
794 dx33 = _mm_sub_ps(ix3,jx3);
795 dy33 = _mm_sub_ps(iy3,jy3);
796 dz33 = _mm_sub_ps(iz3,jz3);
798 /* Calculate squared distance and things based on it */
799 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
800 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
801 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
802 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
803 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
804 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
805 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
806 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
807 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
808 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
810 rinv00 = sse2_invsqrt_f(rsq00);
811 rinv11 = sse2_invsqrt_f(rsq11);
812 rinv12 = sse2_invsqrt_f(rsq12);
813 rinv13 = sse2_invsqrt_f(rsq13);
814 rinv21 = sse2_invsqrt_f(rsq21);
815 rinv22 = sse2_invsqrt_f(rsq22);
816 rinv23 = sse2_invsqrt_f(rsq23);
817 rinv31 = sse2_invsqrt_f(rsq31);
818 rinv32 = sse2_invsqrt_f(rsq32);
819 rinv33 = sse2_invsqrt_f(rsq33);
821 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
822 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
823 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
824 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
825 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
826 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
827 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
828 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
829 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
831 fjx0 = _mm_setzero_ps();
832 fjy0 = _mm_setzero_ps();
833 fjz0 = _mm_setzero_ps();
834 fjx1 = _mm_setzero_ps();
835 fjy1 = _mm_setzero_ps();
836 fjz1 = _mm_setzero_ps();
837 fjx2 = _mm_setzero_ps();
838 fjy2 = _mm_setzero_ps();
839 fjz2 = _mm_setzero_ps();
840 fjx3 = _mm_setzero_ps();
841 fjy3 = _mm_setzero_ps();
842 fjz3 = _mm_setzero_ps();
844 /**************************
845 * CALCULATE INTERACTIONS *
846 **************************/
848 if (gmx_mm_any_lt(rsq00,rcutoff2))
851 r00 = _mm_mul_ps(rsq00,rinv00);
852 r00 = _mm_andnot_ps(dummy_mask,r00);
854 /* Calculate table index by multiplying r with table scale and truncate to integer */
855 rt = _mm_mul_ps(r00,vftabscale);
856 vfitab = _mm_cvttps_epi32(rt);
857 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
858 vfitab = _mm_slli_epi32(vfitab,3);
860 /* CUBIC SPLINE TABLE DISPERSION */
861 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
862 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
863 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
864 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
865 _MM_TRANSPOSE4_PS(Y,F,G,H);
866 Heps = _mm_mul_ps(vfeps,H);
867 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
868 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
869 vvdw6 = _mm_mul_ps(c6_00,VV);
870 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
871 fvdw6 = _mm_mul_ps(c6_00,FF);
873 /* CUBIC SPLINE TABLE REPULSION */
874 vfitab = _mm_add_epi32(vfitab,ifour);
875 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
876 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
877 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
878 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
879 _MM_TRANSPOSE4_PS(Y,F,G,H);
880 Heps = _mm_mul_ps(vfeps,H);
881 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
882 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
883 vvdw12 = _mm_mul_ps(c12_00,VV);
884 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
885 fvdw12 = _mm_mul_ps(c12_00,FF);
886 vvdw = _mm_add_ps(vvdw12,vvdw6);
887 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
889 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
891 /* Update potential sum for this i atom from the interaction with this j atom. */
892 vvdw = _mm_and_ps(vvdw,cutoff_mask);
893 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
894 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
898 fscal = _mm_and_ps(fscal,cutoff_mask);
900 fscal = _mm_andnot_ps(dummy_mask,fscal);
902 /* Calculate temporary vectorial force */
903 tx = _mm_mul_ps(fscal,dx00);
904 ty = _mm_mul_ps(fscal,dy00);
905 tz = _mm_mul_ps(fscal,dz00);
907 /* Update vectorial force */
908 fix0 = _mm_add_ps(fix0,tx);
909 fiy0 = _mm_add_ps(fiy0,ty);
910 fiz0 = _mm_add_ps(fiz0,tz);
912 fjx0 = _mm_add_ps(fjx0,tx);
913 fjy0 = _mm_add_ps(fjy0,ty);
914 fjz0 = _mm_add_ps(fjz0,tz);
918 /**************************
919 * CALCULATE INTERACTIONS *
920 **************************/
922 if (gmx_mm_any_lt(rsq11,rcutoff2))
925 /* REACTION-FIELD ELECTROSTATICS */
926 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
927 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
929 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
931 /* Update potential sum for this i atom from the interaction with this j atom. */
932 velec = _mm_and_ps(velec,cutoff_mask);
933 velec = _mm_andnot_ps(dummy_mask,velec);
934 velecsum = _mm_add_ps(velecsum,velec);
938 fscal = _mm_and_ps(fscal,cutoff_mask);
940 fscal = _mm_andnot_ps(dummy_mask,fscal);
942 /* Calculate temporary vectorial force */
943 tx = _mm_mul_ps(fscal,dx11);
944 ty = _mm_mul_ps(fscal,dy11);
945 tz = _mm_mul_ps(fscal,dz11);
947 /* Update vectorial force */
948 fix1 = _mm_add_ps(fix1,tx);
949 fiy1 = _mm_add_ps(fiy1,ty);
950 fiz1 = _mm_add_ps(fiz1,tz);
952 fjx1 = _mm_add_ps(fjx1,tx);
953 fjy1 = _mm_add_ps(fjy1,ty);
954 fjz1 = _mm_add_ps(fjz1,tz);
958 /**************************
959 * CALCULATE INTERACTIONS *
960 **************************/
962 if (gmx_mm_any_lt(rsq12,rcutoff2))
965 /* REACTION-FIELD ELECTROSTATICS */
966 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
967 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
969 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
971 /* Update potential sum for this i atom from the interaction with this j atom. */
972 velec = _mm_and_ps(velec,cutoff_mask);
973 velec = _mm_andnot_ps(dummy_mask,velec);
974 velecsum = _mm_add_ps(velecsum,velec);
978 fscal = _mm_and_ps(fscal,cutoff_mask);
980 fscal = _mm_andnot_ps(dummy_mask,fscal);
982 /* Calculate temporary vectorial force */
983 tx = _mm_mul_ps(fscal,dx12);
984 ty = _mm_mul_ps(fscal,dy12);
985 tz = _mm_mul_ps(fscal,dz12);
987 /* Update vectorial force */
988 fix1 = _mm_add_ps(fix1,tx);
989 fiy1 = _mm_add_ps(fiy1,ty);
990 fiz1 = _mm_add_ps(fiz1,tz);
992 fjx2 = _mm_add_ps(fjx2,tx);
993 fjy2 = _mm_add_ps(fjy2,ty);
994 fjz2 = _mm_add_ps(fjz2,tz);
998 /**************************
999 * CALCULATE INTERACTIONS *
1000 **************************/
1002 if (gmx_mm_any_lt(rsq13,rcutoff2))
1005 /* REACTION-FIELD ELECTROSTATICS */
1006 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
1007 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
1009 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1011 /* Update potential sum for this i atom from the interaction with this j atom. */
1012 velec = _mm_and_ps(velec,cutoff_mask);
1013 velec = _mm_andnot_ps(dummy_mask,velec);
1014 velecsum = _mm_add_ps(velecsum,velec);
1018 fscal = _mm_and_ps(fscal,cutoff_mask);
1020 fscal = _mm_andnot_ps(dummy_mask,fscal);
1022 /* Calculate temporary vectorial force */
1023 tx = _mm_mul_ps(fscal,dx13);
1024 ty = _mm_mul_ps(fscal,dy13);
1025 tz = _mm_mul_ps(fscal,dz13);
1027 /* Update vectorial force */
1028 fix1 = _mm_add_ps(fix1,tx);
1029 fiy1 = _mm_add_ps(fiy1,ty);
1030 fiz1 = _mm_add_ps(fiz1,tz);
1032 fjx3 = _mm_add_ps(fjx3,tx);
1033 fjy3 = _mm_add_ps(fjy3,ty);
1034 fjz3 = _mm_add_ps(fjz3,tz);
1038 /**************************
1039 * CALCULATE INTERACTIONS *
1040 **************************/
1042 if (gmx_mm_any_lt(rsq21,rcutoff2))
1045 /* REACTION-FIELD ELECTROSTATICS */
1046 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
1047 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1049 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1051 /* Update potential sum for this i atom from the interaction with this j atom. */
1052 velec = _mm_and_ps(velec,cutoff_mask);
1053 velec = _mm_andnot_ps(dummy_mask,velec);
1054 velecsum = _mm_add_ps(velecsum,velec);
1058 fscal = _mm_and_ps(fscal,cutoff_mask);
1060 fscal = _mm_andnot_ps(dummy_mask,fscal);
1062 /* Calculate temporary vectorial force */
1063 tx = _mm_mul_ps(fscal,dx21);
1064 ty = _mm_mul_ps(fscal,dy21);
1065 tz = _mm_mul_ps(fscal,dz21);
1067 /* Update vectorial force */
1068 fix2 = _mm_add_ps(fix2,tx);
1069 fiy2 = _mm_add_ps(fiy2,ty);
1070 fiz2 = _mm_add_ps(fiz2,tz);
1072 fjx1 = _mm_add_ps(fjx1,tx);
1073 fjy1 = _mm_add_ps(fjy1,ty);
1074 fjz1 = _mm_add_ps(fjz1,tz);
1078 /**************************
1079 * CALCULATE INTERACTIONS *
1080 **************************/
1082 if (gmx_mm_any_lt(rsq22,rcutoff2))
1085 /* REACTION-FIELD ELECTROSTATICS */
1086 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1087 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1089 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1091 /* Update potential sum for this i atom from the interaction with this j atom. */
1092 velec = _mm_and_ps(velec,cutoff_mask);
1093 velec = _mm_andnot_ps(dummy_mask,velec);
1094 velecsum = _mm_add_ps(velecsum,velec);
1098 fscal = _mm_and_ps(fscal,cutoff_mask);
1100 fscal = _mm_andnot_ps(dummy_mask,fscal);
1102 /* Calculate temporary vectorial force */
1103 tx = _mm_mul_ps(fscal,dx22);
1104 ty = _mm_mul_ps(fscal,dy22);
1105 tz = _mm_mul_ps(fscal,dz22);
1107 /* Update vectorial force */
1108 fix2 = _mm_add_ps(fix2,tx);
1109 fiy2 = _mm_add_ps(fiy2,ty);
1110 fiz2 = _mm_add_ps(fiz2,tz);
1112 fjx2 = _mm_add_ps(fjx2,tx);
1113 fjy2 = _mm_add_ps(fjy2,ty);
1114 fjz2 = _mm_add_ps(fjz2,tz);
1118 /**************************
1119 * CALCULATE INTERACTIONS *
1120 **************************/
1122 if (gmx_mm_any_lt(rsq23,rcutoff2))
1125 /* REACTION-FIELD ELECTROSTATICS */
1126 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
1127 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1129 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1131 /* Update potential sum for this i atom from the interaction with this j atom. */
1132 velec = _mm_and_ps(velec,cutoff_mask);
1133 velec = _mm_andnot_ps(dummy_mask,velec);
1134 velecsum = _mm_add_ps(velecsum,velec);
1138 fscal = _mm_and_ps(fscal,cutoff_mask);
1140 fscal = _mm_andnot_ps(dummy_mask,fscal);
1142 /* Calculate temporary vectorial force */
1143 tx = _mm_mul_ps(fscal,dx23);
1144 ty = _mm_mul_ps(fscal,dy23);
1145 tz = _mm_mul_ps(fscal,dz23);
1147 /* Update vectorial force */
1148 fix2 = _mm_add_ps(fix2,tx);
1149 fiy2 = _mm_add_ps(fiy2,ty);
1150 fiz2 = _mm_add_ps(fiz2,tz);
1152 fjx3 = _mm_add_ps(fjx3,tx);
1153 fjy3 = _mm_add_ps(fjy3,ty);
1154 fjz3 = _mm_add_ps(fjz3,tz);
1158 /**************************
1159 * CALCULATE INTERACTIONS *
1160 **************************/
1162 if (gmx_mm_any_lt(rsq31,rcutoff2))
1165 /* REACTION-FIELD ELECTROSTATICS */
1166 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
1167 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1169 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1171 /* Update potential sum for this i atom from the interaction with this j atom. */
1172 velec = _mm_and_ps(velec,cutoff_mask);
1173 velec = _mm_andnot_ps(dummy_mask,velec);
1174 velecsum = _mm_add_ps(velecsum,velec);
1178 fscal = _mm_and_ps(fscal,cutoff_mask);
1180 fscal = _mm_andnot_ps(dummy_mask,fscal);
1182 /* Calculate temporary vectorial force */
1183 tx = _mm_mul_ps(fscal,dx31);
1184 ty = _mm_mul_ps(fscal,dy31);
1185 tz = _mm_mul_ps(fscal,dz31);
1187 /* Update vectorial force */
1188 fix3 = _mm_add_ps(fix3,tx);
1189 fiy3 = _mm_add_ps(fiy3,ty);
1190 fiz3 = _mm_add_ps(fiz3,tz);
1192 fjx1 = _mm_add_ps(fjx1,tx);
1193 fjy1 = _mm_add_ps(fjy1,ty);
1194 fjz1 = _mm_add_ps(fjz1,tz);
1198 /**************************
1199 * CALCULATE INTERACTIONS *
1200 **************************/
1202 if (gmx_mm_any_lt(rsq32,rcutoff2))
1205 /* REACTION-FIELD ELECTROSTATICS */
1206 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
1207 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1209 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1211 /* Update potential sum for this i atom from the interaction with this j atom. */
1212 velec = _mm_and_ps(velec,cutoff_mask);
1213 velec = _mm_andnot_ps(dummy_mask,velec);
1214 velecsum = _mm_add_ps(velecsum,velec);
1218 fscal = _mm_and_ps(fscal,cutoff_mask);
1220 fscal = _mm_andnot_ps(dummy_mask,fscal);
1222 /* Calculate temporary vectorial force */
1223 tx = _mm_mul_ps(fscal,dx32);
1224 ty = _mm_mul_ps(fscal,dy32);
1225 tz = _mm_mul_ps(fscal,dz32);
1227 /* Update vectorial force */
1228 fix3 = _mm_add_ps(fix3,tx);
1229 fiy3 = _mm_add_ps(fiy3,ty);
1230 fiz3 = _mm_add_ps(fiz3,tz);
1232 fjx2 = _mm_add_ps(fjx2,tx);
1233 fjy2 = _mm_add_ps(fjy2,ty);
1234 fjz2 = _mm_add_ps(fjz2,tz);
1238 /**************************
1239 * CALCULATE INTERACTIONS *
1240 **************************/
1242 if (gmx_mm_any_lt(rsq33,rcutoff2))
1245 /* REACTION-FIELD ELECTROSTATICS */
1246 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
1247 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1249 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1251 /* Update potential sum for this i atom from the interaction with this j atom. */
1252 velec = _mm_and_ps(velec,cutoff_mask);
1253 velec = _mm_andnot_ps(dummy_mask,velec);
1254 velecsum = _mm_add_ps(velecsum,velec);
1258 fscal = _mm_and_ps(fscal,cutoff_mask);
1260 fscal = _mm_andnot_ps(dummy_mask,fscal);
1262 /* Calculate temporary vectorial force */
1263 tx = _mm_mul_ps(fscal,dx33);
1264 ty = _mm_mul_ps(fscal,dy33);
1265 tz = _mm_mul_ps(fscal,dz33);
1267 /* Update vectorial force */
1268 fix3 = _mm_add_ps(fix3,tx);
1269 fiy3 = _mm_add_ps(fiy3,ty);
1270 fiz3 = _mm_add_ps(fiz3,tz);
1272 fjx3 = _mm_add_ps(fjx3,tx);
1273 fjy3 = _mm_add_ps(fjy3,ty);
1274 fjz3 = _mm_add_ps(fjz3,tz);
1278 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1279 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1280 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1281 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1283 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1284 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1285 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1287 /* Inner loop uses 388 flops */
1290 /* End of innermost loop */
1292 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1293 f+i_coord_offset,fshift+i_shift_offset);
1296 /* Update potential energies */
1297 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1298 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1300 /* Increment number of inner iterations */
1301 inneriter += j_index_end - j_index_start;
1303 /* Outer loop uses 26 flops */
1306 /* Increment number of outer iterations */
1309 /* Update outer/inner flops */
1311 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*388);
1314 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4W4_F_sse2_single
1315 * Electrostatics interaction: ReactionField
1316 * VdW interaction: CubicSplineTable
1317 * Geometry: Water4-Water4
1318 * Calculate force/pot: Force
1321 nb_kernel_ElecRFCut_VdwCSTab_GeomW4W4_F_sse2_single
1322 (t_nblist * gmx_restrict nlist,
1323 rvec * gmx_restrict xx,
1324 rvec * gmx_restrict ff,
1325 struct t_forcerec * gmx_restrict fr,
1326 t_mdatoms * gmx_restrict mdatoms,
1327 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1328 t_nrnb * gmx_restrict nrnb)
1330 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1331 * just 0 for non-waters.
1332 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1333 * jnr indices corresponding to data put in the four positions in the SIMD register.
1335 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1336 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1337 int jnrA,jnrB,jnrC,jnrD;
1338 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1339 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1340 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1341 real rcutoff_scalar;
1342 real *shiftvec,*fshift,*x,*f;
1343 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1344 real scratch[4*DIM];
1345 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1347 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1349 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1351 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1353 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1354 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1355 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1356 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1357 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1358 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1359 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1360 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1361 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1362 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1363 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1364 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1365 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1366 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1367 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1368 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1369 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1370 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1371 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1372 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1375 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1378 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1379 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1381 __m128i ifour = _mm_set1_epi32(4);
1382 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
1384 __m128 dummy_mask,cutoff_mask;
1385 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1386 __m128 one = _mm_set1_ps(1.0);
1387 __m128 two = _mm_set1_ps(2.0);
1393 jindex = nlist->jindex;
1395 shiftidx = nlist->shift;
1397 shiftvec = fr->shift_vec[0];
1398 fshift = fr->fshift[0];
1399 facel = _mm_set1_ps(fr->ic->epsfac);
1400 charge = mdatoms->chargeA;
1401 krf = _mm_set1_ps(fr->ic->k_rf);
1402 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1403 crf = _mm_set1_ps(fr->ic->c_rf);
1404 nvdwtype = fr->ntype;
1405 vdwparam = fr->nbfp;
1406 vdwtype = mdatoms->typeA;
1408 vftab = kernel_data->table_vdw->data;
1409 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
1411 /* Setup water-specific parameters */
1412 inr = nlist->iinr[0];
1413 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1414 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1415 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1416 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1418 jq1 = _mm_set1_ps(charge[inr+1]);
1419 jq2 = _mm_set1_ps(charge[inr+2]);
1420 jq3 = _mm_set1_ps(charge[inr+3]);
1421 vdwjidx0A = 2*vdwtype[inr+0];
1422 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1423 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1424 qq11 = _mm_mul_ps(iq1,jq1);
1425 qq12 = _mm_mul_ps(iq1,jq2);
1426 qq13 = _mm_mul_ps(iq1,jq3);
1427 qq21 = _mm_mul_ps(iq2,jq1);
1428 qq22 = _mm_mul_ps(iq2,jq2);
1429 qq23 = _mm_mul_ps(iq2,jq3);
1430 qq31 = _mm_mul_ps(iq3,jq1);
1431 qq32 = _mm_mul_ps(iq3,jq2);
1432 qq33 = _mm_mul_ps(iq3,jq3);
1434 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1435 rcutoff_scalar = fr->ic->rcoulomb;
1436 rcutoff = _mm_set1_ps(rcutoff_scalar);
1437 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1439 /* Avoid stupid compiler warnings */
1440 jnrA = jnrB = jnrC = jnrD = 0;
1441 j_coord_offsetA = 0;
1442 j_coord_offsetB = 0;
1443 j_coord_offsetC = 0;
1444 j_coord_offsetD = 0;
1449 for(iidx=0;iidx<4*DIM;iidx++)
1451 scratch[iidx] = 0.0;
1454 /* Start outer loop over neighborlists */
1455 for(iidx=0; iidx<nri; iidx++)
1457 /* Load shift vector for this list */
1458 i_shift_offset = DIM*shiftidx[iidx];
1460 /* Load limits for loop over neighbors */
1461 j_index_start = jindex[iidx];
1462 j_index_end = jindex[iidx+1];
1464 /* Get outer coordinate index */
1466 i_coord_offset = DIM*inr;
1468 /* Load i particle coords and add shift vector */
1469 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1470 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1472 fix0 = _mm_setzero_ps();
1473 fiy0 = _mm_setzero_ps();
1474 fiz0 = _mm_setzero_ps();
1475 fix1 = _mm_setzero_ps();
1476 fiy1 = _mm_setzero_ps();
1477 fiz1 = _mm_setzero_ps();
1478 fix2 = _mm_setzero_ps();
1479 fiy2 = _mm_setzero_ps();
1480 fiz2 = _mm_setzero_ps();
1481 fix3 = _mm_setzero_ps();
1482 fiy3 = _mm_setzero_ps();
1483 fiz3 = _mm_setzero_ps();
1485 /* Start inner kernel loop */
1486 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1489 /* Get j neighbor index, and coordinate index */
1491 jnrB = jjnr[jidx+1];
1492 jnrC = jjnr[jidx+2];
1493 jnrD = jjnr[jidx+3];
1494 j_coord_offsetA = DIM*jnrA;
1495 j_coord_offsetB = DIM*jnrB;
1496 j_coord_offsetC = DIM*jnrC;
1497 j_coord_offsetD = DIM*jnrD;
1499 /* load j atom coordinates */
1500 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1501 x+j_coord_offsetC,x+j_coord_offsetD,
1502 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1503 &jy2,&jz2,&jx3,&jy3,&jz3);
1505 /* Calculate displacement vector */
1506 dx00 = _mm_sub_ps(ix0,jx0);
1507 dy00 = _mm_sub_ps(iy0,jy0);
1508 dz00 = _mm_sub_ps(iz0,jz0);
1509 dx11 = _mm_sub_ps(ix1,jx1);
1510 dy11 = _mm_sub_ps(iy1,jy1);
1511 dz11 = _mm_sub_ps(iz1,jz1);
1512 dx12 = _mm_sub_ps(ix1,jx2);
1513 dy12 = _mm_sub_ps(iy1,jy2);
1514 dz12 = _mm_sub_ps(iz1,jz2);
1515 dx13 = _mm_sub_ps(ix1,jx3);
1516 dy13 = _mm_sub_ps(iy1,jy3);
1517 dz13 = _mm_sub_ps(iz1,jz3);
1518 dx21 = _mm_sub_ps(ix2,jx1);
1519 dy21 = _mm_sub_ps(iy2,jy1);
1520 dz21 = _mm_sub_ps(iz2,jz1);
1521 dx22 = _mm_sub_ps(ix2,jx2);
1522 dy22 = _mm_sub_ps(iy2,jy2);
1523 dz22 = _mm_sub_ps(iz2,jz2);
1524 dx23 = _mm_sub_ps(ix2,jx3);
1525 dy23 = _mm_sub_ps(iy2,jy3);
1526 dz23 = _mm_sub_ps(iz2,jz3);
1527 dx31 = _mm_sub_ps(ix3,jx1);
1528 dy31 = _mm_sub_ps(iy3,jy1);
1529 dz31 = _mm_sub_ps(iz3,jz1);
1530 dx32 = _mm_sub_ps(ix3,jx2);
1531 dy32 = _mm_sub_ps(iy3,jy2);
1532 dz32 = _mm_sub_ps(iz3,jz2);
1533 dx33 = _mm_sub_ps(ix3,jx3);
1534 dy33 = _mm_sub_ps(iy3,jy3);
1535 dz33 = _mm_sub_ps(iz3,jz3);
1537 /* Calculate squared distance and things based on it */
1538 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1539 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1540 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1541 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1542 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1543 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1544 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1545 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1546 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1547 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1549 rinv00 = sse2_invsqrt_f(rsq00);
1550 rinv11 = sse2_invsqrt_f(rsq11);
1551 rinv12 = sse2_invsqrt_f(rsq12);
1552 rinv13 = sse2_invsqrt_f(rsq13);
1553 rinv21 = sse2_invsqrt_f(rsq21);
1554 rinv22 = sse2_invsqrt_f(rsq22);
1555 rinv23 = sse2_invsqrt_f(rsq23);
1556 rinv31 = sse2_invsqrt_f(rsq31);
1557 rinv32 = sse2_invsqrt_f(rsq32);
1558 rinv33 = sse2_invsqrt_f(rsq33);
1560 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1561 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1562 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1563 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1564 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1565 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1566 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1567 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1568 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1570 fjx0 = _mm_setzero_ps();
1571 fjy0 = _mm_setzero_ps();
1572 fjz0 = _mm_setzero_ps();
1573 fjx1 = _mm_setzero_ps();
1574 fjy1 = _mm_setzero_ps();
1575 fjz1 = _mm_setzero_ps();
1576 fjx2 = _mm_setzero_ps();
1577 fjy2 = _mm_setzero_ps();
1578 fjz2 = _mm_setzero_ps();
1579 fjx3 = _mm_setzero_ps();
1580 fjy3 = _mm_setzero_ps();
1581 fjz3 = _mm_setzero_ps();
1583 /**************************
1584 * CALCULATE INTERACTIONS *
1585 **************************/
1587 if (gmx_mm_any_lt(rsq00,rcutoff2))
1590 r00 = _mm_mul_ps(rsq00,rinv00);
1592 /* Calculate table index by multiplying r with table scale and truncate to integer */
1593 rt = _mm_mul_ps(r00,vftabscale);
1594 vfitab = _mm_cvttps_epi32(rt);
1595 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1596 vfitab = _mm_slli_epi32(vfitab,3);
1598 /* CUBIC SPLINE TABLE DISPERSION */
1599 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1600 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1601 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1602 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1603 _MM_TRANSPOSE4_PS(Y,F,G,H);
1604 Heps = _mm_mul_ps(vfeps,H);
1605 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1606 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1607 fvdw6 = _mm_mul_ps(c6_00,FF);
1609 /* CUBIC SPLINE TABLE REPULSION */
1610 vfitab = _mm_add_epi32(vfitab,ifour);
1611 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1612 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1613 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1614 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1615 _MM_TRANSPOSE4_PS(Y,F,G,H);
1616 Heps = _mm_mul_ps(vfeps,H);
1617 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1618 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1619 fvdw12 = _mm_mul_ps(c12_00,FF);
1620 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1622 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1626 fscal = _mm_and_ps(fscal,cutoff_mask);
1628 /* Calculate temporary vectorial force */
1629 tx = _mm_mul_ps(fscal,dx00);
1630 ty = _mm_mul_ps(fscal,dy00);
1631 tz = _mm_mul_ps(fscal,dz00);
1633 /* Update vectorial force */
1634 fix0 = _mm_add_ps(fix0,tx);
1635 fiy0 = _mm_add_ps(fiy0,ty);
1636 fiz0 = _mm_add_ps(fiz0,tz);
1638 fjx0 = _mm_add_ps(fjx0,tx);
1639 fjy0 = _mm_add_ps(fjy0,ty);
1640 fjz0 = _mm_add_ps(fjz0,tz);
1644 /**************************
1645 * CALCULATE INTERACTIONS *
1646 **************************/
1648 if (gmx_mm_any_lt(rsq11,rcutoff2))
1651 /* REACTION-FIELD ELECTROSTATICS */
1652 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1654 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1658 fscal = _mm_and_ps(fscal,cutoff_mask);
1660 /* Calculate temporary vectorial force */
1661 tx = _mm_mul_ps(fscal,dx11);
1662 ty = _mm_mul_ps(fscal,dy11);
1663 tz = _mm_mul_ps(fscal,dz11);
1665 /* Update vectorial force */
1666 fix1 = _mm_add_ps(fix1,tx);
1667 fiy1 = _mm_add_ps(fiy1,ty);
1668 fiz1 = _mm_add_ps(fiz1,tz);
1670 fjx1 = _mm_add_ps(fjx1,tx);
1671 fjy1 = _mm_add_ps(fjy1,ty);
1672 fjz1 = _mm_add_ps(fjz1,tz);
1676 /**************************
1677 * CALCULATE INTERACTIONS *
1678 **************************/
1680 if (gmx_mm_any_lt(rsq12,rcutoff2))
1683 /* REACTION-FIELD ELECTROSTATICS */
1684 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1686 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1690 fscal = _mm_and_ps(fscal,cutoff_mask);
1692 /* Calculate temporary vectorial force */
1693 tx = _mm_mul_ps(fscal,dx12);
1694 ty = _mm_mul_ps(fscal,dy12);
1695 tz = _mm_mul_ps(fscal,dz12);
1697 /* Update vectorial force */
1698 fix1 = _mm_add_ps(fix1,tx);
1699 fiy1 = _mm_add_ps(fiy1,ty);
1700 fiz1 = _mm_add_ps(fiz1,tz);
1702 fjx2 = _mm_add_ps(fjx2,tx);
1703 fjy2 = _mm_add_ps(fjy2,ty);
1704 fjz2 = _mm_add_ps(fjz2,tz);
1708 /**************************
1709 * CALCULATE INTERACTIONS *
1710 **************************/
1712 if (gmx_mm_any_lt(rsq13,rcutoff2))
1715 /* REACTION-FIELD ELECTROSTATICS */
1716 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
1718 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1722 fscal = _mm_and_ps(fscal,cutoff_mask);
1724 /* Calculate temporary vectorial force */
1725 tx = _mm_mul_ps(fscal,dx13);
1726 ty = _mm_mul_ps(fscal,dy13);
1727 tz = _mm_mul_ps(fscal,dz13);
1729 /* Update vectorial force */
1730 fix1 = _mm_add_ps(fix1,tx);
1731 fiy1 = _mm_add_ps(fiy1,ty);
1732 fiz1 = _mm_add_ps(fiz1,tz);
1734 fjx3 = _mm_add_ps(fjx3,tx);
1735 fjy3 = _mm_add_ps(fjy3,ty);
1736 fjz3 = _mm_add_ps(fjz3,tz);
1740 /**************************
1741 * CALCULATE INTERACTIONS *
1742 **************************/
1744 if (gmx_mm_any_lt(rsq21,rcutoff2))
1747 /* REACTION-FIELD ELECTROSTATICS */
1748 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1750 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1754 fscal = _mm_and_ps(fscal,cutoff_mask);
1756 /* Calculate temporary vectorial force */
1757 tx = _mm_mul_ps(fscal,dx21);
1758 ty = _mm_mul_ps(fscal,dy21);
1759 tz = _mm_mul_ps(fscal,dz21);
1761 /* Update vectorial force */
1762 fix2 = _mm_add_ps(fix2,tx);
1763 fiy2 = _mm_add_ps(fiy2,ty);
1764 fiz2 = _mm_add_ps(fiz2,tz);
1766 fjx1 = _mm_add_ps(fjx1,tx);
1767 fjy1 = _mm_add_ps(fjy1,ty);
1768 fjz1 = _mm_add_ps(fjz1,tz);
1772 /**************************
1773 * CALCULATE INTERACTIONS *
1774 **************************/
1776 if (gmx_mm_any_lt(rsq22,rcutoff2))
1779 /* REACTION-FIELD ELECTROSTATICS */
1780 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1782 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1786 fscal = _mm_and_ps(fscal,cutoff_mask);
1788 /* Calculate temporary vectorial force */
1789 tx = _mm_mul_ps(fscal,dx22);
1790 ty = _mm_mul_ps(fscal,dy22);
1791 tz = _mm_mul_ps(fscal,dz22);
1793 /* Update vectorial force */
1794 fix2 = _mm_add_ps(fix2,tx);
1795 fiy2 = _mm_add_ps(fiy2,ty);
1796 fiz2 = _mm_add_ps(fiz2,tz);
1798 fjx2 = _mm_add_ps(fjx2,tx);
1799 fjy2 = _mm_add_ps(fjy2,ty);
1800 fjz2 = _mm_add_ps(fjz2,tz);
1804 /**************************
1805 * CALCULATE INTERACTIONS *
1806 **************************/
1808 if (gmx_mm_any_lt(rsq23,rcutoff2))
1811 /* REACTION-FIELD ELECTROSTATICS */
1812 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1814 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1818 fscal = _mm_and_ps(fscal,cutoff_mask);
1820 /* Calculate temporary vectorial force */
1821 tx = _mm_mul_ps(fscal,dx23);
1822 ty = _mm_mul_ps(fscal,dy23);
1823 tz = _mm_mul_ps(fscal,dz23);
1825 /* Update vectorial force */
1826 fix2 = _mm_add_ps(fix2,tx);
1827 fiy2 = _mm_add_ps(fiy2,ty);
1828 fiz2 = _mm_add_ps(fiz2,tz);
1830 fjx3 = _mm_add_ps(fjx3,tx);
1831 fjy3 = _mm_add_ps(fjy3,ty);
1832 fjz3 = _mm_add_ps(fjz3,tz);
1836 /**************************
1837 * CALCULATE INTERACTIONS *
1838 **************************/
1840 if (gmx_mm_any_lt(rsq31,rcutoff2))
1843 /* REACTION-FIELD ELECTROSTATICS */
1844 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1846 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1850 fscal = _mm_and_ps(fscal,cutoff_mask);
1852 /* Calculate temporary vectorial force */
1853 tx = _mm_mul_ps(fscal,dx31);
1854 ty = _mm_mul_ps(fscal,dy31);
1855 tz = _mm_mul_ps(fscal,dz31);
1857 /* Update vectorial force */
1858 fix3 = _mm_add_ps(fix3,tx);
1859 fiy3 = _mm_add_ps(fiy3,ty);
1860 fiz3 = _mm_add_ps(fiz3,tz);
1862 fjx1 = _mm_add_ps(fjx1,tx);
1863 fjy1 = _mm_add_ps(fjy1,ty);
1864 fjz1 = _mm_add_ps(fjz1,tz);
1868 /**************************
1869 * CALCULATE INTERACTIONS *
1870 **************************/
1872 if (gmx_mm_any_lt(rsq32,rcutoff2))
1875 /* REACTION-FIELD ELECTROSTATICS */
1876 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1878 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1882 fscal = _mm_and_ps(fscal,cutoff_mask);
1884 /* Calculate temporary vectorial force */
1885 tx = _mm_mul_ps(fscal,dx32);
1886 ty = _mm_mul_ps(fscal,dy32);
1887 tz = _mm_mul_ps(fscal,dz32);
1889 /* Update vectorial force */
1890 fix3 = _mm_add_ps(fix3,tx);
1891 fiy3 = _mm_add_ps(fiy3,ty);
1892 fiz3 = _mm_add_ps(fiz3,tz);
1894 fjx2 = _mm_add_ps(fjx2,tx);
1895 fjy2 = _mm_add_ps(fjy2,ty);
1896 fjz2 = _mm_add_ps(fjz2,tz);
1900 /**************************
1901 * CALCULATE INTERACTIONS *
1902 **************************/
1904 if (gmx_mm_any_lt(rsq33,rcutoff2))
1907 /* REACTION-FIELD ELECTROSTATICS */
1908 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1910 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1914 fscal = _mm_and_ps(fscal,cutoff_mask);
1916 /* Calculate temporary vectorial force */
1917 tx = _mm_mul_ps(fscal,dx33);
1918 ty = _mm_mul_ps(fscal,dy33);
1919 tz = _mm_mul_ps(fscal,dz33);
1921 /* Update vectorial force */
1922 fix3 = _mm_add_ps(fix3,tx);
1923 fiy3 = _mm_add_ps(fiy3,ty);
1924 fiz3 = _mm_add_ps(fiz3,tz);
1926 fjx3 = _mm_add_ps(fjx3,tx);
1927 fjy3 = _mm_add_ps(fjy3,ty);
1928 fjz3 = _mm_add_ps(fjz3,tz);
1932 fjptrA = f+j_coord_offsetA;
1933 fjptrB = f+j_coord_offsetB;
1934 fjptrC = f+j_coord_offsetC;
1935 fjptrD = f+j_coord_offsetD;
1937 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1938 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1939 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1941 /* Inner loop uses 324 flops */
1944 if(jidx<j_index_end)
1947 /* Get j neighbor index, and coordinate index */
1948 jnrlistA = jjnr[jidx];
1949 jnrlistB = jjnr[jidx+1];
1950 jnrlistC = jjnr[jidx+2];
1951 jnrlistD = jjnr[jidx+3];
1952 /* Sign of each element will be negative for non-real atoms.
1953 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1954 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1956 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1957 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1958 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1959 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1960 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1961 j_coord_offsetA = DIM*jnrA;
1962 j_coord_offsetB = DIM*jnrB;
1963 j_coord_offsetC = DIM*jnrC;
1964 j_coord_offsetD = DIM*jnrD;
1966 /* load j atom coordinates */
1967 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1968 x+j_coord_offsetC,x+j_coord_offsetD,
1969 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1970 &jy2,&jz2,&jx3,&jy3,&jz3);
1972 /* Calculate displacement vector */
1973 dx00 = _mm_sub_ps(ix0,jx0);
1974 dy00 = _mm_sub_ps(iy0,jy0);
1975 dz00 = _mm_sub_ps(iz0,jz0);
1976 dx11 = _mm_sub_ps(ix1,jx1);
1977 dy11 = _mm_sub_ps(iy1,jy1);
1978 dz11 = _mm_sub_ps(iz1,jz1);
1979 dx12 = _mm_sub_ps(ix1,jx2);
1980 dy12 = _mm_sub_ps(iy1,jy2);
1981 dz12 = _mm_sub_ps(iz1,jz2);
1982 dx13 = _mm_sub_ps(ix1,jx3);
1983 dy13 = _mm_sub_ps(iy1,jy3);
1984 dz13 = _mm_sub_ps(iz1,jz3);
1985 dx21 = _mm_sub_ps(ix2,jx1);
1986 dy21 = _mm_sub_ps(iy2,jy1);
1987 dz21 = _mm_sub_ps(iz2,jz1);
1988 dx22 = _mm_sub_ps(ix2,jx2);
1989 dy22 = _mm_sub_ps(iy2,jy2);
1990 dz22 = _mm_sub_ps(iz2,jz2);
1991 dx23 = _mm_sub_ps(ix2,jx3);
1992 dy23 = _mm_sub_ps(iy2,jy3);
1993 dz23 = _mm_sub_ps(iz2,jz3);
1994 dx31 = _mm_sub_ps(ix3,jx1);
1995 dy31 = _mm_sub_ps(iy3,jy1);
1996 dz31 = _mm_sub_ps(iz3,jz1);
1997 dx32 = _mm_sub_ps(ix3,jx2);
1998 dy32 = _mm_sub_ps(iy3,jy2);
1999 dz32 = _mm_sub_ps(iz3,jz2);
2000 dx33 = _mm_sub_ps(ix3,jx3);
2001 dy33 = _mm_sub_ps(iy3,jy3);
2002 dz33 = _mm_sub_ps(iz3,jz3);
2004 /* Calculate squared distance and things based on it */
2005 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
2006 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
2007 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
2008 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
2009 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
2010 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
2011 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
2012 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
2013 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
2014 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
2016 rinv00 = sse2_invsqrt_f(rsq00);
2017 rinv11 = sse2_invsqrt_f(rsq11);
2018 rinv12 = sse2_invsqrt_f(rsq12);
2019 rinv13 = sse2_invsqrt_f(rsq13);
2020 rinv21 = sse2_invsqrt_f(rsq21);
2021 rinv22 = sse2_invsqrt_f(rsq22);
2022 rinv23 = sse2_invsqrt_f(rsq23);
2023 rinv31 = sse2_invsqrt_f(rsq31);
2024 rinv32 = sse2_invsqrt_f(rsq32);
2025 rinv33 = sse2_invsqrt_f(rsq33);
2027 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
2028 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
2029 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
2030 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
2031 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
2032 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
2033 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
2034 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
2035 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
2037 fjx0 = _mm_setzero_ps();
2038 fjy0 = _mm_setzero_ps();
2039 fjz0 = _mm_setzero_ps();
2040 fjx1 = _mm_setzero_ps();
2041 fjy1 = _mm_setzero_ps();
2042 fjz1 = _mm_setzero_ps();
2043 fjx2 = _mm_setzero_ps();
2044 fjy2 = _mm_setzero_ps();
2045 fjz2 = _mm_setzero_ps();
2046 fjx3 = _mm_setzero_ps();
2047 fjy3 = _mm_setzero_ps();
2048 fjz3 = _mm_setzero_ps();
2050 /**************************
2051 * CALCULATE INTERACTIONS *
2052 **************************/
2054 if (gmx_mm_any_lt(rsq00,rcutoff2))
2057 r00 = _mm_mul_ps(rsq00,rinv00);
2058 r00 = _mm_andnot_ps(dummy_mask,r00);
2060 /* Calculate table index by multiplying r with table scale and truncate to integer */
2061 rt = _mm_mul_ps(r00,vftabscale);
2062 vfitab = _mm_cvttps_epi32(rt);
2063 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
2064 vfitab = _mm_slli_epi32(vfitab,3);
2066 /* CUBIC SPLINE TABLE DISPERSION */
2067 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
2068 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
2069 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
2070 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
2071 _MM_TRANSPOSE4_PS(Y,F,G,H);
2072 Heps = _mm_mul_ps(vfeps,H);
2073 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
2074 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
2075 fvdw6 = _mm_mul_ps(c6_00,FF);
2077 /* CUBIC SPLINE TABLE REPULSION */
2078 vfitab = _mm_add_epi32(vfitab,ifour);
2079 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
2080 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
2081 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
2082 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
2083 _MM_TRANSPOSE4_PS(Y,F,G,H);
2084 Heps = _mm_mul_ps(vfeps,H);
2085 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
2086 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
2087 fvdw12 = _mm_mul_ps(c12_00,FF);
2088 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
2090 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
2094 fscal = _mm_and_ps(fscal,cutoff_mask);
2096 fscal = _mm_andnot_ps(dummy_mask,fscal);
2098 /* Calculate temporary vectorial force */
2099 tx = _mm_mul_ps(fscal,dx00);
2100 ty = _mm_mul_ps(fscal,dy00);
2101 tz = _mm_mul_ps(fscal,dz00);
2103 /* Update vectorial force */
2104 fix0 = _mm_add_ps(fix0,tx);
2105 fiy0 = _mm_add_ps(fiy0,ty);
2106 fiz0 = _mm_add_ps(fiz0,tz);
2108 fjx0 = _mm_add_ps(fjx0,tx);
2109 fjy0 = _mm_add_ps(fjy0,ty);
2110 fjz0 = _mm_add_ps(fjz0,tz);
2114 /**************************
2115 * CALCULATE INTERACTIONS *
2116 **************************/
2118 if (gmx_mm_any_lt(rsq11,rcutoff2))
2121 /* REACTION-FIELD ELECTROSTATICS */
2122 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
2124 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
2128 fscal = _mm_and_ps(fscal,cutoff_mask);
2130 fscal = _mm_andnot_ps(dummy_mask,fscal);
2132 /* Calculate temporary vectorial force */
2133 tx = _mm_mul_ps(fscal,dx11);
2134 ty = _mm_mul_ps(fscal,dy11);
2135 tz = _mm_mul_ps(fscal,dz11);
2137 /* Update vectorial force */
2138 fix1 = _mm_add_ps(fix1,tx);
2139 fiy1 = _mm_add_ps(fiy1,ty);
2140 fiz1 = _mm_add_ps(fiz1,tz);
2142 fjx1 = _mm_add_ps(fjx1,tx);
2143 fjy1 = _mm_add_ps(fjy1,ty);
2144 fjz1 = _mm_add_ps(fjz1,tz);
2148 /**************************
2149 * CALCULATE INTERACTIONS *
2150 **************************/
2152 if (gmx_mm_any_lt(rsq12,rcutoff2))
2155 /* REACTION-FIELD ELECTROSTATICS */
2156 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
2158 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
2162 fscal = _mm_and_ps(fscal,cutoff_mask);
2164 fscal = _mm_andnot_ps(dummy_mask,fscal);
2166 /* Calculate temporary vectorial force */
2167 tx = _mm_mul_ps(fscal,dx12);
2168 ty = _mm_mul_ps(fscal,dy12);
2169 tz = _mm_mul_ps(fscal,dz12);
2171 /* Update vectorial force */
2172 fix1 = _mm_add_ps(fix1,tx);
2173 fiy1 = _mm_add_ps(fiy1,ty);
2174 fiz1 = _mm_add_ps(fiz1,tz);
2176 fjx2 = _mm_add_ps(fjx2,tx);
2177 fjy2 = _mm_add_ps(fjy2,ty);
2178 fjz2 = _mm_add_ps(fjz2,tz);
2182 /**************************
2183 * CALCULATE INTERACTIONS *
2184 **************************/
2186 if (gmx_mm_any_lt(rsq13,rcutoff2))
2189 /* REACTION-FIELD ELECTROSTATICS */
2190 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
2192 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
2196 fscal = _mm_and_ps(fscal,cutoff_mask);
2198 fscal = _mm_andnot_ps(dummy_mask,fscal);
2200 /* Calculate temporary vectorial force */
2201 tx = _mm_mul_ps(fscal,dx13);
2202 ty = _mm_mul_ps(fscal,dy13);
2203 tz = _mm_mul_ps(fscal,dz13);
2205 /* Update vectorial force */
2206 fix1 = _mm_add_ps(fix1,tx);
2207 fiy1 = _mm_add_ps(fiy1,ty);
2208 fiz1 = _mm_add_ps(fiz1,tz);
2210 fjx3 = _mm_add_ps(fjx3,tx);
2211 fjy3 = _mm_add_ps(fjy3,ty);
2212 fjz3 = _mm_add_ps(fjz3,tz);
2216 /**************************
2217 * CALCULATE INTERACTIONS *
2218 **************************/
2220 if (gmx_mm_any_lt(rsq21,rcutoff2))
2223 /* REACTION-FIELD ELECTROSTATICS */
2224 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
2226 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
2230 fscal = _mm_and_ps(fscal,cutoff_mask);
2232 fscal = _mm_andnot_ps(dummy_mask,fscal);
2234 /* Calculate temporary vectorial force */
2235 tx = _mm_mul_ps(fscal,dx21);
2236 ty = _mm_mul_ps(fscal,dy21);
2237 tz = _mm_mul_ps(fscal,dz21);
2239 /* Update vectorial force */
2240 fix2 = _mm_add_ps(fix2,tx);
2241 fiy2 = _mm_add_ps(fiy2,ty);
2242 fiz2 = _mm_add_ps(fiz2,tz);
2244 fjx1 = _mm_add_ps(fjx1,tx);
2245 fjy1 = _mm_add_ps(fjy1,ty);
2246 fjz1 = _mm_add_ps(fjz1,tz);
2250 /**************************
2251 * CALCULATE INTERACTIONS *
2252 **************************/
2254 if (gmx_mm_any_lt(rsq22,rcutoff2))
2257 /* REACTION-FIELD ELECTROSTATICS */
2258 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2260 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
2264 fscal = _mm_and_ps(fscal,cutoff_mask);
2266 fscal = _mm_andnot_ps(dummy_mask,fscal);
2268 /* Calculate temporary vectorial force */
2269 tx = _mm_mul_ps(fscal,dx22);
2270 ty = _mm_mul_ps(fscal,dy22);
2271 tz = _mm_mul_ps(fscal,dz22);
2273 /* Update vectorial force */
2274 fix2 = _mm_add_ps(fix2,tx);
2275 fiy2 = _mm_add_ps(fiy2,ty);
2276 fiz2 = _mm_add_ps(fiz2,tz);
2278 fjx2 = _mm_add_ps(fjx2,tx);
2279 fjy2 = _mm_add_ps(fjy2,ty);
2280 fjz2 = _mm_add_ps(fjz2,tz);
2284 /**************************
2285 * CALCULATE INTERACTIONS *
2286 **************************/
2288 if (gmx_mm_any_lt(rsq23,rcutoff2))
2291 /* REACTION-FIELD ELECTROSTATICS */
2292 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
2294 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
2298 fscal = _mm_and_ps(fscal,cutoff_mask);
2300 fscal = _mm_andnot_ps(dummy_mask,fscal);
2302 /* Calculate temporary vectorial force */
2303 tx = _mm_mul_ps(fscal,dx23);
2304 ty = _mm_mul_ps(fscal,dy23);
2305 tz = _mm_mul_ps(fscal,dz23);
2307 /* Update vectorial force */
2308 fix2 = _mm_add_ps(fix2,tx);
2309 fiy2 = _mm_add_ps(fiy2,ty);
2310 fiz2 = _mm_add_ps(fiz2,tz);
2312 fjx3 = _mm_add_ps(fjx3,tx);
2313 fjy3 = _mm_add_ps(fjy3,ty);
2314 fjz3 = _mm_add_ps(fjz3,tz);
2318 /**************************
2319 * CALCULATE INTERACTIONS *
2320 **************************/
2322 if (gmx_mm_any_lt(rsq31,rcutoff2))
2325 /* REACTION-FIELD ELECTROSTATICS */
2326 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
2328 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
2332 fscal = _mm_and_ps(fscal,cutoff_mask);
2334 fscal = _mm_andnot_ps(dummy_mask,fscal);
2336 /* Calculate temporary vectorial force */
2337 tx = _mm_mul_ps(fscal,dx31);
2338 ty = _mm_mul_ps(fscal,dy31);
2339 tz = _mm_mul_ps(fscal,dz31);
2341 /* Update vectorial force */
2342 fix3 = _mm_add_ps(fix3,tx);
2343 fiy3 = _mm_add_ps(fiy3,ty);
2344 fiz3 = _mm_add_ps(fiz3,tz);
2346 fjx1 = _mm_add_ps(fjx1,tx);
2347 fjy1 = _mm_add_ps(fjy1,ty);
2348 fjz1 = _mm_add_ps(fjz1,tz);
2352 /**************************
2353 * CALCULATE INTERACTIONS *
2354 **************************/
2356 if (gmx_mm_any_lt(rsq32,rcutoff2))
2359 /* REACTION-FIELD ELECTROSTATICS */
2360 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
2362 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
2366 fscal = _mm_and_ps(fscal,cutoff_mask);
2368 fscal = _mm_andnot_ps(dummy_mask,fscal);
2370 /* Calculate temporary vectorial force */
2371 tx = _mm_mul_ps(fscal,dx32);
2372 ty = _mm_mul_ps(fscal,dy32);
2373 tz = _mm_mul_ps(fscal,dz32);
2375 /* Update vectorial force */
2376 fix3 = _mm_add_ps(fix3,tx);
2377 fiy3 = _mm_add_ps(fiy3,ty);
2378 fiz3 = _mm_add_ps(fiz3,tz);
2380 fjx2 = _mm_add_ps(fjx2,tx);
2381 fjy2 = _mm_add_ps(fjy2,ty);
2382 fjz2 = _mm_add_ps(fjz2,tz);
2386 /**************************
2387 * CALCULATE INTERACTIONS *
2388 **************************/
2390 if (gmx_mm_any_lt(rsq33,rcutoff2))
2393 /* REACTION-FIELD ELECTROSTATICS */
2394 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
2396 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
2400 fscal = _mm_and_ps(fscal,cutoff_mask);
2402 fscal = _mm_andnot_ps(dummy_mask,fscal);
2404 /* Calculate temporary vectorial force */
2405 tx = _mm_mul_ps(fscal,dx33);
2406 ty = _mm_mul_ps(fscal,dy33);
2407 tz = _mm_mul_ps(fscal,dz33);
2409 /* Update vectorial force */
2410 fix3 = _mm_add_ps(fix3,tx);
2411 fiy3 = _mm_add_ps(fiy3,ty);
2412 fiz3 = _mm_add_ps(fiz3,tz);
2414 fjx3 = _mm_add_ps(fjx3,tx);
2415 fjy3 = _mm_add_ps(fjy3,ty);
2416 fjz3 = _mm_add_ps(fjz3,tz);
2420 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2421 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2422 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2423 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2425 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2426 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2427 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2429 /* Inner loop uses 325 flops */
2432 /* End of innermost loop */
2434 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2435 f+i_coord_offset,fshift+i_shift_offset);
2437 /* Increment number of inner iterations */
2438 inneriter += j_index_end - j_index_start;
2440 /* Outer loop uses 24 flops */
2443 /* Increment number of outer iterations */
2446 /* Update outer/inner flops */
2448 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*325);