2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_sse2_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_sse2_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
94 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
95 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
96 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
97 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
98 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
99 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
100 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
101 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
102 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
103 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
104 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
105 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
106 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
109 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
112 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
113 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
115 __m128i ifour = _mm_set1_epi32(4);
116 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
118 __m128 dummy_mask,cutoff_mask;
119 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
120 __m128 one = _mm_set1_ps(1.0);
121 __m128 two = _mm_set1_ps(2.0);
127 jindex = nlist->jindex;
129 shiftidx = nlist->shift;
131 shiftvec = fr->shift_vec[0];
132 fshift = fr->fshift[0];
133 facel = _mm_set1_ps(fr->epsfac);
134 charge = mdatoms->chargeA;
135 krf = _mm_set1_ps(fr->ic->k_rf);
136 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
137 crf = _mm_set1_ps(fr->ic->c_rf);
138 nvdwtype = fr->ntype;
140 vdwtype = mdatoms->typeA;
142 vftab = kernel_data->table_vdw->data;
143 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
145 /* Setup water-specific parameters */
146 inr = nlist->iinr[0];
147 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
148 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
149 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
150 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
152 jq0 = _mm_set1_ps(charge[inr+0]);
153 jq1 = _mm_set1_ps(charge[inr+1]);
154 jq2 = _mm_set1_ps(charge[inr+2]);
155 vdwjidx0A = 2*vdwtype[inr+0];
156 qq00 = _mm_mul_ps(iq0,jq0);
157 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
158 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
159 qq01 = _mm_mul_ps(iq0,jq1);
160 qq02 = _mm_mul_ps(iq0,jq2);
161 qq10 = _mm_mul_ps(iq1,jq0);
162 qq11 = _mm_mul_ps(iq1,jq1);
163 qq12 = _mm_mul_ps(iq1,jq2);
164 qq20 = _mm_mul_ps(iq2,jq0);
165 qq21 = _mm_mul_ps(iq2,jq1);
166 qq22 = _mm_mul_ps(iq2,jq2);
168 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
169 rcutoff_scalar = fr->rcoulomb;
170 rcutoff = _mm_set1_ps(rcutoff_scalar);
171 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
173 /* Avoid stupid compiler warnings */
174 jnrA = jnrB = jnrC = jnrD = 0;
183 for(iidx=0;iidx<4*DIM;iidx++)
188 /* Start outer loop over neighborlists */
189 for(iidx=0; iidx<nri; iidx++)
191 /* Load shift vector for this list */
192 i_shift_offset = DIM*shiftidx[iidx];
194 /* Load limits for loop over neighbors */
195 j_index_start = jindex[iidx];
196 j_index_end = jindex[iidx+1];
198 /* Get outer coordinate index */
200 i_coord_offset = DIM*inr;
202 /* Load i particle coords and add shift vector */
203 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
204 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
206 fix0 = _mm_setzero_ps();
207 fiy0 = _mm_setzero_ps();
208 fiz0 = _mm_setzero_ps();
209 fix1 = _mm_setzero_ps();
210 fiy1 = _mm_setzero_ps();
211 fiz1 = _mm_setzero_ps();
212 fix2 = _mm_setzero_ps();
213 fiy2 = _mm_setzero_ps();
214 fiz2 = _mm_setzero_ps();
216 /* Reset potential sums */
217 velecsum = _mm_setzero_ps();
218 vvdwsum = _mm_setzero_ps();
220 /* Start inner kernel loop */
221 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
224 /* Get j neighbor index, and coordinate index */
229 j_coord_offsetA = DIM*jnrA;
230 j_coord_offsetB = DIM*jnrB;
231 j_coord_offsetC = DIM*jnrC;
232 j_coord_offsetD = DIM*jnrD;
234 /* load j atom coordinates */
235 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
236 x+j_coord_offsetC,x+j_coord_offsetD,
237 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
239 /* Calculate displacement vector */
240 dx00 = _mm_sub_ps(ix0,jx0);
241 dy00 = _mm_sub_ps(iy0,jy0);
242 dz00 = _mm_sub_ps(iz0,jz0);
243 dx01 = _mm_sub_ps(ix0,jx1);
244 dy01 = _mm_sub_ps(iy0,jy1);
245 dz01 = _mm_sub_ps(iz0,jz1);
246 dx02 = _mm_sub_ps(ix0,jx2);
247 dy02 = _mm_sub_ps(iy0,jy2);
248 dz02 = _mm_sub_ps(iz0,jz2);
249 dx10 = _mm_sub_ps(ix1,jx0);
250 dy10 = _mm_sub_ps(iy1,jy0);
251 dz10 = _mm_sub_ps(iz1,jz0);
252 dx11 = _mm_sub_ps(ix1,jx1);
253 dy11 = _mm_sub_ps(iy1,jy1);
254 dz11 = _mm_sub_ps(iz1,jz1);
255 dx12 = _mm_sub_ps(ix1,jx2);
256 dy12 = _mm_sub_ps(iy1,jy2);
257 dz12 = _mm_sub_ps(iz1,jz2);
258 dx20 = _mm_sub_ps(ix2,jx0);
259 dy20 = _mm_sub_ps(iy2,jy0);
260 dz20 = _mm_sub_ps(iz2,jz0);
261 dx21 = _mm_sub_ps(ix2,jx1);
262 dy21 = _mm_sub_ps(iy2,jy1);
263 dz21 = _mm_sub_ps(iz2,jz1);
264 dx22 = _mm_sub_ps(ix2,jx2);
265 dy22 = _mm_sub_ps(iy2,jy2);
266 dz22 = _mm_sub_ps(iz2,jz2);
268 /* Calculate squared distance and things based on it */
269 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
270 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
271 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
272 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
273 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
274 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
275 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
276 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
277 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
279 rinv00 = gmx_mm_invsqrt_ps(rsq00);
280 rinv01 = gmx_mm_invsqrt_ps(rsq01);
281 rinv02 = gmx_mm_invsqrt_ps(rsq02);
282 rinv10 = gmx_mm_invsqrt_ps(rsq10);
283 rinv11 = gmx_mm_invsqrt_ps(rsq11);
284 rinv12 = gmx_mm_invsqrt_ps(rsq12);
285 rinv20 = gmx_mm_invsqrt_ps(rsq20);
286 rinv21 = gmx_mm_invsqrt_ps(rsq21);
287 rinv22 = gmx_mm_invsqrt_ps(rsq22);
289 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
290 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
291 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
292 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
293 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
294 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
295 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
296 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
297 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
299 fjx0 = _mm_setzero_ps();
300 fjy0 = _mm_setzero_ps();
301 fjz0 = _mm_setzero_ps();
302 fjx1 = _mm_setzero_ps();
303 fjy1 = _mm_setzero_ps();
304 fjz1 = _mm_setzero_ps();
305 fjx2 = _mm_setzero_ps();
306 fjy2 = _mm_setzero_ps();
307 fjz2 = _mm_setzero_ps();
309 /**************************
310 * CALCULATE INTERACTIONS *
311 **************************/
313 if (gmx_mm_any_lt(rsq00,rcutoff2))
316 r00 = _mm_mul_ps(rsq00,rinv00);
318 /* Calculate table index by multiplying r with table scale and truncate to integer */
319 rt = _mm_mul_ps(r00,vftabscale);
320 vfitab = _mm_cvttps_epi32(rt);
321 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
322 vfitab = _mm_slli_epi32(vfitab,3);
324 /* REACTION-FIELD ELECTROSTATICS */
325 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
326 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
328 /* CUBIC SPLINE TABLE DISPERSION */
329 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
330 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
331 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
332 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
333 _MM_TRANSPOSE4_PS(Y,F,G,H);
334 Heps = _mm_mul_ps(vfeps,H);
335 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
336 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
337 vvdw6 = _mm_mul_ps(c6_00,VV);
338 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
339 fvdw6 = _mm_mul_ps(c6_00,FF);
341 /* CUBIC SPLINE TABLE REPULSION */
342 vfitab = _mm_add_epi32(vfitab,ifour);
343 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
344 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
345 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
346 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
347 _MM_TRANSPOSE4_PS(Y,F,G,H);
348 Heps = _mm_mul_ps(vfeps,H);
349 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
350 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
351 vvdw12 = _mm_mul_ps(c12_00,VV);
352 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
353 fvdw12 = _mm_mul_ps(c12_00,FF);
354 vvdw = _mm_add_ps(vvdw12,vvdw6);
355 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
357 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 velec = _mm_and_ps(velec,cutoff_mask);
361 velecsum = _mm_add_ps(velecsum,velec);
362 vvdw = _mm_and_ps(vvdw,cutoff_mask);
363 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
365 fscal = _mm_add_ps(felec,fvdw);
367 fscal = _mm_and_ps(fscal,cutoff_mask);
369 /* Calculate temporary vectorial force */
370 tx = _mm_mul_ps(fscal,dx00);
371 ty = _mm_mul_ps(fscal,dy00);
372 tz = _mm_mul_ps(fscal,dz00);
374 /* Update vectorial force */
375 fix0 = _mm_add_ps(fix0,tx);
376 fiy0 = _mm_add_ps(fiy0,ty);
377 fiz0 = _mm_add_ps(fiz0,tz);
379 fjx0 = _mm_add_ps(fjx0,tx);
380 fjy0 = _mm_add_ps(fjy0,ty);
381 fjz0 = _mm_add_ps(fjz0,tz);
385 /**************************
386 * CALCULATE INTERACTIONS *
387 **************************/
389 if (gmx_mm_any_lt(rsq01,rcutoff2))
392 /* REACTION-FIELD ELECTROSTATICS */
393 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
394 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
396 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
398 /* Update potential sum for this i atom from the interaction with this j atom. */
399 velec = _mm_and_ps(velec,cutoff_mask);
400 velecsum = _mm_add_ps(velecsum,velec);
404 fscal = _mm_and_ps(fscal,cutoff_mask);
406 /* Calculate temporary vectorial force */
407 tx = _mm_mul_ps(fscal,dx01);
408 ty = _mm_mul_ps(fscal,dy01);
409 tz = _mm_mul_ps(fscal,dz01);
411 /* Update vectorial force */
412 fix0 = _mm_add_ps(fix0,tx);
413 fiy0 = _mm_add_ps(fiy0,ty);
414 fiz0 = _mm_add_ps(fiz0,tz);
416 fjx1 = _mm_add_ps(fjx1,tx);
417 fjy1 = _mm_add_ps(fjy1,ty);
418 fjz1 = _mm_add_ps(fjz1,tz);
422 /**************************
423 * CALCULATE INTERACTIONS *
424 **************************/
426 if (gmx_mm_any_lt(rsq02,rcutoff2))
429 /* REACTION-FIELD ELECTROSTATICS */
430 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
431 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
433 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
435 /* Update potential sum for this i atom from the interaction with this j atom. */
436 velec = _mm_and_ps(velec,cutoff_mask);
437 velecsum = _mm_add_ps(velecsum,velec);
441 fscal = _mm_and_ps(fscal,cutoff_mask);
443 /* Calculate temporary vectorial force */
444 tx = _mm_mul_ps(fscal,dx02);
445 ty = _mm_mul_ps(fscal,dy02);
446 tz = _mm_mul_ps(fscal,dz02);
448 /* Update vectorial force */
449 fix0 = _mm_add_ps(fix0,tx);
450 fiy0 = _mm_add_ps(fiy0,ty);
451 fiz0 = _mm_add_ps(fiz0,tz);
453 fjx2 = _mm_add_ps(fjx2,tx);
454 fjy2 = _mm_add_ps(fjy2,ty);
455 fjz2 = _mm_add_ps(fjz2,tz);
459 /**************************
460 * CALCULATE INTERACTIONS *
461 **************************/
463 if (gmx_mm_any_lt(rsq10,rcutoff2))
466 /* REACTION-FIELD ELECTROSTATICS */
467 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
468 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
470 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
472 /* Update potential sum for this i atom from the interaction with this j atom. */
473 velec = _mm_and_ps(velec,cutoff_mask);
474 velecsum = _mm_add_ps(velecsum,velec);
478 fscal = _mm_and_ps(fscal,cutoff_mask);
480 /* Calculate temporary vectorial force */
481 tx = _mm_mul_ps(fscal,dx10);
482 ty = _mm_mul_ps(fscal,dy10);
483 tz = _mm_mul_ps(fscal,dz10);
485 /* Update vectorial force */
486 fix1 = _mm_add_ps(fix1,tx);
487 fiy1 = _mm_add_ps(fiy1,ty);
488 fiz1 = _mm_add_ps(fiz1,tz);
490 fjx0 = _mm_add_ps(fjx0,tx);
491 fjy0 = _mm_add_ps(fjy0,ty);
492 fjz0 = _mm_add_ps(fjz0,tz);
496 /**************************
497 * CALCULATE INTERACTIONS *
498 **************************/
500 if (gmx_mm_any_lt(rsq11,rcutoff2))
503 /* REACTION-FIELD ELECTROSTATICS */
504 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
505 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
507 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
509 /* Update potential sum for this i atom from the interaction with this j atom. */
510 velec = _mm_and_ps(velec,cutoff_mask);
511 velecsum = _mm_add_ps(velecsum,velec);
515 fscal = _mm_and_ps(fscal,cutoff_mask);
517 /* Calculate temporary vectorial force */
518 tx = _mm_mul_ps(fscal,dx11);
519 ty = _mm_mul_ps(fscal,dy11);
520 tz = _mm_mul_ps(fscal,dz11);
522 /* Update vectorial force */
523 fix1 = _mm_add_ps(fix1,tx);
524 fiy1 = _mm_add_ps(fiy1,ty);
525 fiz1 = _mm_add_ps(fiz1,tz);
527 fjx1 = _mm_add_ps(fjx1,tx);
528 fjy1 = _mm_add_ps(fjy1,ty);
529 fjz1 = _mm_add_ps(fjz1,tz);
533 /**************************
534 * CALCULATE INTERACTIONS *
535 **************************/
537 if (gmx_mm_any_lt(rsq12,rcutoff2))
540 /* REACTION-FIELD ELECTROSTATICS */
541 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
542 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
544 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
546 /* Update potential sum for this i atom from the interaction with this j atom. */
547 velec = _mm_and_ps(velec,cutoff_mask);
548 velecsum = _mm_add_ps(velecsum,velec);
552 fscal = _mm_and_ps(fscal,cutoff_mask);
554 /* Calculate temporary vectorial force */
555 tx = _mm_mul_ps(fscal,dx12);
556 ty = _mm_mul_ps(fscal,dy12);
557 tz = _mm_mul_ps(fscal,dz12);
559 /* Update vectorial force */
560 fix1 = _mm_add_ps(fix1,tx);
561 fiy1 = _mm_add_ps(fiy1,ty);
562 fiz1 = _mm_add_ps(fiz1,tz);
564 fjx2 = _mm_add_ps(fjx2,tx);
565 fjy2 = _mm_add_ps(fjy2,ty);
566 fjz2 = _mm_add_ps(fjz2,tz);
570 /**************************
571 * CALCULATE INTERACTIONS *
572 **************************/
574 if (gmx_mm_any_lt(rsq20,rcutoff2))
577 /* REACTION-FIELD ELECTROSTATICS */
578 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
579 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
581 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
583 /* Update potential sum for this i atom from the interaction with this j atom. */
584 velec = _mm_and_ps(velec,cutoff_mask);
585 velecsum = _mm_add_ps(velecsum,velec);
589 fscal = _mm_and_ps(fscal,cutoff_mask);
591 /* Calculate temporary vectorial force */
592 tx = _mm_mul_ps(fscal,dx20);
593 ty = _mm_mul_ps(fscal,dy20);
594 tz = _mm_mul_ps(fscal,dz20);
596 /* Update vectorial force */
597 fix2 = _mm_add_ps(fix2,tx);
598 fiy2 = _mm_add_ps(fiy2,ty);
599 fiz2 = _mm_add_ps(fiz2,tz);
601 fjx0 = _mm_add_ps(fjx0,tx);
602 fjy0 = _mm_add_ps(fjy0,ty);
603 fjz0 = _mm_add_ps(fjz0,tz);
607 /**************************
608 * CALCULATE INTERACTIONS *
609 **************************/
611 if (gmx_mm_any_lt(rsq21,rcutoff2))
614 /* REACTION-FIELD ELECTROSTATICS */
615 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
616 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
618 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
620 /* Update potential sum for this i atom from the interaction with this j atom. */
621 velec = _mm_and_ps(velec,cutoff_mask);
622 velecsum = _mm_add_ps(velecsum,velec);
626 fscal = _mm_and_ps(fscal,cutoff_mask);
628 /* Calculate temporary vectorial force */
629 tx = _mm_mul_ps(fscal,dx21);
630 ty = _mm_mul_ps(fscal,dy21);
631 tz = _mm_mul_ps(fscal,dz21);
633 /* Update vectorial force */
634 fix2 = _mm_add_ps(fix2,tx);
635 fiy2 = _mm_add_ps(fiy2,ty);
636 fiz2 = _mm_add_ps(fiz2,tz);
638 fjx1 = _mm_add_ps(fjx1,tx);
639 fjy1 = _mm_add_ps(fjy1,ty);
640 fjz1 = _mm_add_ps(fjz1,tz);
644 /**************************
645 * CALCULATE INTERACTIONS *
646 **************************/
648 if (gmx_mm_any_lt(rsq22,rcutoff2))
651 /* REACTION-FIELD ELECTROSTATICS */
652 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
653 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
655 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
657 /* Update potential sum for this i atom from the interaction with this j atom. */
658 velec = _mm_and_ps(velec,cutoff_mask);
659 velecsum = _mm_add_ps(velecsum,velec);
663 fscal = _mm_and_ps(fscal,cutoff_mask);
665 /* Calculate temporary vectorial force */
666 tx = _mm_mul_ps(fscal,dx22);
667 ty = _mm_mul_ps(fscal,dy22);
668 tz = _mm_mul_ps(fscal,dz22);
670 /* Update vectorial force */
671 fix2 = _mm_add_ps(fix2,tx);
672 fiy2 = _mm_add_ps(fiy2,ty);
673 fiz2 = _mm_add_ps(fiz2,tz);
675 fjx2 = _mm_add_ps(fjx2,tx);
676 fjy2 = _mm_add_ps(fjy2,ty);
677 fjz2 = _mm_add_ps(fjz2,tz);
681 fjptrA = f+j_coord_offsetA;
682 fjptrB = f+j_coord_offsetB;
683 fjptrC = f+j_coord_offsetC;
684 fjptrD = f+j_coord_offsetD;
686 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
687 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
689 /* Inner loop uses 360 flops */
695 /* Get j neighbor index, and coordinate index */
696 jnrlistA = jjnr[jidx];
697 jnrlistB = jjnr[jidx+1];
698 jnrlistC = jjnr[jidx+2];
699 jnrlistD = jjnr[jidx+3];
700 /* Sign of each element will be negative for non-real atoms.
701 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
702 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
704 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
705 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
706 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
707 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
708 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
709 j_coord_offsetA = DIM*jnrA;
710 j_coord_offsetB = DIM*jnrB;
711 j_coord_offsetC = DIM*jnrC;
712 j_coord_offsetD = DIM*jnrD;
714 /* load j atom coordinates */
715 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
716 x+j_coord_offsetC,x+j_coord_offsetD,
717 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
719 /* Calculate displacement vector */
720 dx00 = _mm_sub_ps(ix0,jx0);
721 dy00 = _mm_sub_ps(iy0,jy0);
722 dz00 = _mm_sub_ps(iz0,jz0);
723 dx01 = _mm_sub_ps(ix0,jx1);
724 dy01 = _mm_sub_ps(iy0,jy1);
725 dz01 = _mm_sub_ps(iz0,jz1);
726 dx02 = _mm_sub_ps(ix0,jx2);
727 dy02 = _mm_sub_ps(iy0,jy2);
728 dz02 = _mm_sub_ps(iz0,jz2);
729 dx10 = _mm_sub_ps(ix1,jx0);
730 dy10 = _mm_sub_ps(iy1,jy0);
731 dz10 = _mm_sub_ps(iz1,jz0);
732 dx11 = _mm_sub_ps(ix1,jx1);
733 dy11 = _mm_sub_ps(iy1,jy1);
734 dz11 = _mm_sub_ps(iz1,jz1);
735 dx12 = _mm_sub_ps(ix1,jx2);
736 dy12 = _mm_sub_ps(iy1,jy2);
737 dz12 = _mm_sub_ps(iz1,jz2);
738 dx20 = _mm_sub_ps(ix2,jx0);
739 dy20 = _mm_sub_ps(iy2,jy0);
740 dz20 = _mm_sub_ps(iz2,jz0);
741 dx21 = _mm_sub_ps(ix2,jx1);
742 dy21 = _mm_sub_ps(iy2,jy1);
743 dz21 = _mm_sub_ps(iz2,jz1);
744 dx22 = _mm_sub_ps(ix2,jx2);
745 dy22 = _mm_sub_ps(iy2,jy2);
746 dz22 = _mm_sub_ps(iz2,jz2);
748 /* Calculate squared distance and things based on it */
749 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
750 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
751 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
752 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
753 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
754 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
755 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
756 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
757 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
759 rinv00 = gmx_mm_invsqrt_ps(rsq00);
760 rinv01 = gmx_mm_invsqrt_ps(rsq01);
761 rinv02 = gmx_mm_invsqrt_ps(rsq02);
762 rinv10 = gmx_mm_invsqrt_ps(rsq10);
763 rinv11 = gmx_mm_invsqrt_ps(rsq11);
764 rinv12 = gmx_mm_invsqrt_ps(rsq12);
765 rinv20 = gmx_mm_invsqrt_ps(rsq20);
766 rinv21 = gmx_mm_invsqrt_ps(rsq21);
767 rinv22 = gmx_mm_invsqrt_ps(rsq22);
769 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
770 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
771 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
772 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
773 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
774 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
775 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
776 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
777 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
779 fjx0 = _mm_setzero_ps();
780 fjy0 = _mm_setzero_ps();
781 fjz0 = _mm_setzero_ps();
782 fjx1 = _mm_setzero_ps();
783 fjy1 = _mm_setzero_ps();
784 fjz1 = _mm_setzero_ps();
785 fjx2 = _mm_setzero_ps();
786 fjy2 = _mm_setzero_ps();
787 fjz2 = _mm_setzero_ps();
789 /**************************
790 * CALCULATE INTERACTIONS *
791 **************************/
793 if (gmx_mm_any_lt(rsq00,rcutoff2))
796 r00 = _mm_mul_ps(rsq00,rinv00);
797 r00 = _mm_andnot_ps(dummy_mask,r00);
799 /* Calculate table index by multiplying r with table scale and truncate to integer */
800 rt = _mm_mul_ps(r00,vftabscale);
801 vfitab = _mm_cvttps_epi32(rt);
802 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
803 vfitab = _mm_slli_epi32(vfitab,3);
805 /* REACTION-FIELD ELECTROSTATICS */
806 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
807 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
809 /* CUBIC SPLINE TABLE DISPERSION */
810 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
811 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
812 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
813 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
814 _MM_TRANSPOSE4_PS(Y,F,G,H);
815 Heps = _mm_mul_ps(vfeps,H);
816 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
817 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
818 vvdw6 = _mm_mul_ps(c6_00,VV);
819 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
820 fvdw6 = _mm_mul_ps(c6_00,FF);
822 /* CUBIC SPLINE TABLE REPULSION */
823 vfitab = _mm_add_epi32(vfitab,ifour);
824 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
825 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
826 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
827 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
828 _MM_TRANSPOSE4_PS(Y,F,G,H);
829 Heps = _mm_mul_ps(vfeps,H);
830 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
831 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
832 vvdw12 = _mm_mul_ps(c12_00,VV);
833 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
834 fvdw12 = _mm_mul_ps(c12_00,FF);
835 vvdw = _mm_add_ps(vvdw12,vvdw6);
836 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
838 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
840 /* Update potential sum for this i atom from the interaction with this j atom. */
841 velec = _mm_and_ps(velec,cutoff_mask);
842 velec = _mm_andnot_ps(dummy_mask,velec);
843 velecsum = _mm_add_ps(velecsum,velec);
844 vvdw = _mm_and_ps(vvdw,cutoff_mask);
845 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
846 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
848 fscal = _mm_add_ps(felec,fvdw);
850 fscal = _mm_and_ps(fscal,cutoff_mask);
852 fscal = _mm_andnot_ps(dummy_mask,fscal);
854 /* Calculate temporary vectorial force */
855 tx = _mm_mul_ps(fscal,dx00);
856 ty = _mm_mul_ps(fscal,dy00);
857 tz = _mm_mul_ps(fscal,dz00);
859 /* Update vectorial force */
860 fix0 = _mm_add_ps(fix0,tx);
861 fiy0 = _mm_add_ps(fiy0,ty);
862 fiz0 = _mm_add_ps(fiz0,tz);
864 fjx0 = _mm_add_ps(fjx0,tx);
865 fjy0 = _mm_add_ps(fjy0,ty);
866 fjz0 = _mm_add_ps(fjz0,tz);
870 /**************************
871 * CALCULATE INTERACTIONS *
872 **************************/
874 if (gmx_mm_any_lt(rsq01,rcutoff2))
877 /* REACTION-FIELD ELECTROSTATICS */
878 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
879 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
881 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
883 /* Update potential sum for this i atom from the interaction with this j atom. */
884 velec = _mm_and_ps(velec,cutoff_mask);
885 velec = _mm_andnot_ps(dummy_mask,velec);
886 velecsum = _mm_add_ps(velecsum,velec);
890 fscal = _mm_and_ps(fscal,cutoff_mask);
892 fscal = _mm_andnot_ps(dummy_mask,fscal);
894 /* Calculate temporary vectorial force */
895 tx = _mm_mul_ps(fscal,dx01);
896 ty = _mm_mul_ps(fscal,dy01);
897 tz = _mm_mul_ps(fscal,dz01);
899 /* Update vectorial force */
900 fix0 = _mm_add_ps(fix0,tx);
901 fiy0 = _mm_add_ps(fiy0,ty);
902 fiz0 = _mm_add_ps(fiz0,tz);
904 fjx1 = _mm_add_ps(fjx1,tx);
905 fjy1 = _mm_add_ps(fjy1,ty);
906 fjz1 = _mm_add_ps(fjz1,tz);
910 /**************************
911 * CALCULATE INTERACTIONS *
912 **************************/
914 if (gmx_mm_any_lt(rsq02,rcutoff2))
917 /* REACTION-FIELD ELECTROSTATICS */
918 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
919 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
921 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
923 /* Update potential sum for this i atom from the interaction with this j atom. */
924 velec = _mm_and_ps(velec,cutoff_mask);
925 velec = _mm_andnot_ps(dummy_mask,velec);
926 velecsum = _mm_add_ps(velecsum,velec);
930 fscal = _mm_and_ps(fscal,cutoff_mask);
932 fscal = _mm_andnot_ps(dummy_mask,fscal);
934 /* Calculate temporary vectorial force */
935 tx = _mm_mul_ps(fscal,dx02);
936 ty = _mm_mul_ps(fscal,dy02);
937 tz = _mm_mul_ps(fscal,dz02);
939 /* Update vectorial force */
940 fix0 = _mm_add_ps(fix0,tx);
941 fiy0 = _mm_add_ps(fiy0,ty);
942 fiz0 = _mm_add_ps(fiz0,tz);
944 fjx2 = _mm_add_ps(fjx2,tx);
945 fjy2 = _mm_add_ps(fjy2,ty);
946 fjz2 = _mm_add_ps(fjz2,tz);
950 /**************************
951 * CALCULATE INTERACTIONS *
952 **************************/
954 if (gmx_mm_any_lt(rsq10,rcutoff2))
957 /* REACTION-FIELD ELECTROSTATICS */
958 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
959 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
961 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
963 /* Update potential sum for this i atom from the interaction with this j atom. */
964 velec = _mm_and_ps(velec,cutoff_mask);
965 velec = _mm_andnot_ps(dummy_mask,velec);
966 velecsum = _mm_add_ps(velecsum,velec);
970 fscal = _mm_and_ps(fscal,cutoff_mask);
972 fscal = _mm_andnot_ps(dummy_mask,fscal);
974 /* Calculate temporary vectorial force */
975 tx = _mm_mul_ps(fscal,dx10);
976 ty = _mm_mul_ps(fscal,dy10);
977 tz = _mm_mul_ps(fscal,dz10);
979 /* Update vectorial force */
980 fix1 = _mm_add_ps(fix1,tx);
981 fiy1 = _mm_add_ps(fiy1,ty);
982 fiz1 = _mm_add_ps(fiz1,tz);
984 fjx0 = _mm_add_ps(fjx0,tx);
985 fjy0 = _mm_add_ps(fjy0,ty);
986 fjz0 = _mm_add_ps(fjz0,tz);
990 /**************************
991 * CALCULATE INTERACTIONS *
992 **************************/
994 if (gmx_mm_any_lt(rsq11,rcutoff2))
997 /* REACTION-FIELD ELECTROSTATICS */
998 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
999 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1001 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1003 /* Update potential sum for this i atom from the interaction with this j atom. */
1004 velec = _mm_and_ps(velec,cutoff_mask);
1005 velec = _mm_andnot_ps(dummy_mask,velec);
1006 velecsum = _mm_add_ps(velecsum,velec);
1010 fscal = _mm_and_ps(fscal,cutoff_mask);
1012 fscal = _mm_andnot_ps(dummy_mask,fscal);
1014 /* Calculate temporary vectorial force */
1015 tx = _mm_mul_ps(fscal,dx11);
1016 ty = _mm_mul_ps(fscal,dy11);
1017 tz = _mm_mul_ps(fscal,dz11);
1019 /* Update vectorial force */
1020 fix1 = _mm_add_ps(fix1,tx);
1021 fiy1 = _mm_add_ps(fiy1,ty);
1022 fiz1 = _mm_add_ps(fiz1,tz);
1024 fjx1 = _mm_add_ps(fjx1,tx);
1025 fjy1 = _mm_add_ps(fjy1,ty);
1026 fjz1 = _mm_add_ps(fjz1,tz);
1030 /**************************
1031 * CALCULATE INTERACTIONS *
1032 **************************/
1034 if (gmx_mm_any_lt(rsq12,rcutoff2))
1037 /* REACTION-FIELD ELECTROSTATICS */
1038 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
1039 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1041 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1043 /* Update potential sum for this i atom from the interaction with this j atom. */
1044 velec = _mm_and_ps(velec,cutoff_mask);
1045 velec = _mm_andnot_ps(dummy_mask,velec);
1046 velecsum = _mm_add_ps(velecsum,velec);
1050 fscal = _mm_and_ps(fscal,cutoff_mask);
1052 fscal = _mm_andnot_ps(dummy_mask,fscal);
1054 /* Calculate temporary vectorial force */
1055 tx = _mm_mul_ps(fscal,dx12);
1056 ty = _mm_mul_ps(fscal,dy12);
1057 tz = _mm_mul_ps(fscal,dz12);
1059 /* Update vectorial force */
1060 fix1 = _mm_add_ps(fix1,tx);
1061 fiy1 = _mm_add_ps(fiy1,ty);
1062 fiz1 = _mm_add_ps(fiz1,tz);
1064 fjx2 = _mm_add_ps(fjx2,tx);
1065 fjy2 = _mm_add_ps(fjy2,ty);
1066 fjz2 = _mm_add_ps(fjz2,tz);
1070 /**************************
1071 * CALCULATE INTERACTIONS *
1072 **************************/
1074 if (gmx_mm_any_lt(rsq20,rcutoff2))
1077 /* REACTION-FIELD ELECTROSTATICS */
1078 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
1079 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1081 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1083 /* Update potential sum for this i atom from the interaction with this j atom. */
1084 velec = _mm_and_ps(velec,cutoff_mask);
1085 velec = _mm_andnot_ps(dummy_mask,velec);
1086 velecsum = _mm_add_ps(velecsum,velec);
1090 fscal = _mm_and_ps(fscal,cutoff_mask);
1092 fscal = _mm_andnot_ps(dummy_mask,fscal);
1094 /* Calculate temporary vectorial force */
1095 tx = _mm_mul_ps(fscal,dx20);
1096 ty = _mm_mul_ps(fscal,dy20);
1097 tz = _mm_mul_ps(fscal,dz20);
1099 /* Update vectorial force */
1100 fix2 = _mm_add_ps(fix2,tx);
1101 fiy2 = _mm_add_ps(fiy2,ty);
1102 fiz2 = _mm_add_ps(fiz2,tz);
1104 fjx0 = _mm_add_ps(fjx0,tx);
1105 fjy0 = _mm_add_ps(fjy0,ty);
1106 fjz0 = _mm_add_ps(fjz0,tz);
1110 /**************************
1111 * CALCULATE INTERACTIONS *
1112 **************************/
1114 if (gmx_mm_any_lt(rsq21,rcutoff2))
1117 /* REACTION-FIELD ELECTROSTATICS */
1118 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
1119 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1121 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1123 /* Update potential sum for this i atom from the interaction with this j atom. */
1124 velec = _mm_and_ps(velec,cutoff_mask);
1125 velec = _mm_andnot_ps(dummy_mask,velec);
1126 velecsum = _mm_add_ps(velecsum,velec);
1130 fscal = _mm_and_ps(fscal,cutoff_mask);
1132 fscal = _mm_andnot_ps(dummy_mask,fscal);
1134 /* Calculate temporary vectorial force */
1135 tx = _mm_mul_ps(fscal,dx21);
1136 ty = _mm_mul_ps(fscal,dy21);
1137 tz = _mm_mul_ps(fscal,dz21);
1139 /* Update vectorial force */
1140 fix2 = _mm_add_ps(fix2,tx);
1141 fiy2 = _mm_add_ps(fiy2,ty);
1142 fiz2 = _mm_add_ps(fiz2,tz);
1144 fjx1 = _mm_add_ps(fjx1,tx);
1145 fjy1 = _mm_add_ps(fjy1,ty);
1146 fjz1 = _mm_add_ps(fjz1,tz);
1150 /**************************
1151 * CALCULATE INTERACTIONS *
1152 **************************/
1154 if (gmx_mm_any_lt(rsq22,rcutoff2))
1157 /* REACTION-FIELD ELECTROSTATICS */
1158 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1159 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1161 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1163 /* Update potential sum for this i atom from the interaction with this j atom. */
1164 velec = _mm_and_ps(velec,cutoff_mask);
1165 velec = _mm_andnot_ps(dummy_mask,velec);
1166 velecsum = _mm_add_ps(velecsum,velec);
1170 fscal = _mm_and_ps(fscal,cutoff_mask);
1172 fscal = _mm_andnot_ps(dummy_mask,fscal);
1174 /* Calculate temporary vectorial force */
1175 tx = _mm_mul_ps(fscal,dx22);
1176 ty = _mm_mul_ps(fscal,dy22);
1177 tz = _mm_mul_ps(fscal,dz22);
1179 /* Update vectorial force */
1180 fix2 = _mm_add_ps(fix2,tx);
1181 fiy2 = _mm_add_ps(fiy2,ty);
1182 fiz2 = _mm_add_ps(fiz2,tz);
1184 fjx2 = _mm_add_ps(fjx2,tx);
1185 fjy2 = _mm_add_ps(fjy2,ty);
1186 fjz2 = _mm_add_ps(fjz2,tz);
1190 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1191 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1192 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1193 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1195 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1196 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1198 /* Inner loop uses 361 flops */
1201 /* End of innermost loop */
1203 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1204 f+i_coord_offset,fshift+i_shift_offset);
1207 /* Update potential energies */
1208 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1209 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1211 /* Increment number of inner iterations */
1212 inneriter += j_index_end - j_index_start;
1214 /* Outer loop uses 20 flops */
1217 /* Increment number of outer iterations */
1220 /* Update outer/inner flops */
1222 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*361);
1225 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_sse2_single
1226 * Electrostatics interaction: ReactionField
1227 * VdW interaction: CubicSplineTable
1228 * Geometry: Water3-Water3
1229 * Calculate force/pot: Force
1232 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_sse2_single
1233 (t_nblist * gmx_restrict nlist,
1234 rvec * gmx_restrict xx,
1235 rvec * gmx_restrict ff,
1236 t_forcerec * gmx_restrict fr,
1237 t_mdatoms * gmx_restrict mdatoms,
1238 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1239 t_nrnb * gmx_restrict nrnb)
1241 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1242 * just 0 for non-waters.
1243 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1244 * jnr indices corresponding to data put in the four positions in the SIMD register.
1246 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1247 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1248 int jnrA,jnrB,jnrC,jnrD;
1249 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1250 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1251 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1252 real rcutoff_scalar;
1253 real *shiftvec,*fshift,*x,*f;
1254 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1255 real scratch[4*DIM];
1256 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1258 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1260 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1262 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1263 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1264 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1265 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1266 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1267 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1268 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1269 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1270 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1271 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1272 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1273 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1274 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1275 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1276 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1277 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1278 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1281 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1284 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1285 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1287 __m128i ifour = _mm_set1_epi32(4);
1288 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
1290 __m128 dummy_mask,cutoff_mask;
1291 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1292 __m128 one = _mm_set1_ps(1.0);
1293 __m128 two = _mm_set1_ps(2.0);
1299 jindex = nlist->jindex;
1301 shiftidx = nlist->shift;
1303 shiftvec = fr->shift_vec[0];
1304 fshift = fr->fshift[0];
1305 facel = _mm_set1_ps(fr->epsfac);
1306 charge = mdatoms->chargeA;
1307 krf = _mm_set1_ps(fr->ic->k_rf);
1308 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1309 crf = _mm_set1_ps(fr->ic->c_rf);
1310 nvdwtype = fr->ntype;
1311 vdwparam = fr->nbfp;
1312 vdwtype = mdatoms->typeA;
1314 vftab = kernel_data->table_vdw->data;
1315 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
1317 /* Setup water-specific parameters */
1318 inr = nlist->iinr[0];
1319 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1320 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1321 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1322 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1324 jq0 = _mm_set1_ps(charge[inr+0]);
1325 jq1 = _mm_set1_ps(charge[inr+1]);
1326 jq2 = _mm_set1_ps(charge[inr+2]);
1327 vdwjidx0A = 2*vdwtype[inr+0];
1328 qq00 = _mm_mul_ps(iq0,jq0);
1329 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1330 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1331 qq01 = _mm_mul_ps(iq0,jq1);
1332 qq02 = _mm_mul_ps(iq0,jq2);
1333 qq10 = _mm_mul_ps(iq1,jq0);
1334 qq11 = _mm_mul_ps(iq1,jq1);
1335 qq12 = _mm_mul_ps(iq1,jq2);
1336 qq20 = _mm_mul_ps(iq2,jq0);
1337 qq21 = _mm_mul_ps(iq2,jq1);
1338 qq22 = _mm_mul_ps(iq2,jq2);
1340 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1341 rcutoff_scalar = fr->rcoulomb;
1342 rcutoff = _mm_set1_ps(rcutoff_scalar);
1343 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1345 /* Avoid stupid compiler warnings */
1346 jnrA = jnrB = jnrC = jnrD = 0;
1347 j_coord_offsetA = 0;
1348 j_coord_offsetB = 0;
1349 j_coord_offsetC = 0;
1350 j_coord_offsetD = 0;
1355 for(iidx=0;iidx<4*DIM;iidx++)
1357 scratch[iidx] = 0.0;
1360 /* Start outer loop over neighborlists */
1361 for(iidx=0; iidx<nri; iidx++)
1363 /* Load shift vector for this list */
1364 i_shift_offset = DIM*shiftidx[iidx];
1366 /* Load limits for loop over neighbors */
1367 j_index_start = jindex[iidx];
1368 j_index_end = jindex[iidx+1];
1370 /* Get outer coordinate index */
1372 i_coord_offset = DIM*inr;
1374 /* Load i particle coords and add shift vector */
1375 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1376 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1378 fix0 = _mm_setzero_ps();
1379 fiy0 = _mm_setzero_ps();
1380 fiz0 = _mm_setzero_ps();
1381 fix1 = _mm_setzero_ps();
1382 fiy1 = _mm_setzero_ps();
1383 fiz1 = _mm_setzero_ps();
1384 fix2 = _mm_setzero_ps();
1385 fiy2 = _mm_setzero_ps();
1386 fiz2 = _mm_setzero_ps();
1388 /* Start inner kernel loop */
1389 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1392 /* Get j neighbor index, and coordinate index */
1394 jnrB = jjnr[jidx+1];
1395 jnrC = jjnr[jidx+2];
1396 jnrD = jjnr[jidx+3];
1397 j_coord_offsetA = DIM*jnrA;
1398 j_coord_offsetB = DIM*jnrB;
1399 j_coord_offsetC = DIM*jnrC;
1400 j_coord_offsetD = DIM*jnrD;
1402 /* load j atom coordinates */
1403 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1404 x+j_coord_offsetC,x+j_coord_offsetD,
1405 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1407 /* Calculate displacement vector */
1408 dx00 = _mm_sub_ps(ix0,jx0);
1409 dy00 = _mm_sub_ps(iy0,jy0);
1410 dz00 = _mm_sub_ps(iz0,jz0);
1411 dx01 = _mm_sub_ps(ix0,jx1);
1412 dy01 = _mm_sub_ps(iy0,jy1);
1413 dz01 = _mm_sub_ps(iz0,jz1);
1414 dx02 = _mm_sub_ps(ix0,jx2);
1415 dy02 = _mm_sub_ps(iy0,jy2);
1416 dz02 = _mm_sub_ps(iz0,jz2);
1417 dx10 = _mm_sub_ps(ix1,jx0);
1418 dy10 = _mm_sub_ps(iy1,jy0);
1419 dz10 = _mm_sub_ps(iz1,jz0);
1420 dx11 = _mm_sub_ps(ix1,jx1);
1421 dy11 = _mm_sub_ps(iy1,jy1);
1422 dz11 = _mm_sub_ps(iz1,jz1);
1423 dx12 = _mm_sub_ps(ix1,jx2);
1424 dy12 = _mm_sub_ps(iy1,jy2);
1425 dz12 = _mm_sub_ps(iz1,jz2);
1426 dx20 = _mm_sub_ps(ix2,jx0);
1427 dy20 = _mm_sub_ps(iy2,jy0);
1428 dz20 = _mm_sub_ps(iz2,jz0);
1429 dx21 = _mm_sub_ps(ix2,jx1);
1430 dy21 = _mm_sub_ps(iy2,jy1);
1431 dz21 = _mm_sub_ps(iz2,jz1);
1432 dx22 = _mm_sub_ps(ix2,jx2);
1433 dy22 = _mm_sub_ps(iy2,jy2);
1434 dz22 = _mm_sub_ps(iz2,jz2);
1436 /* Calculate squared distance and things based on it */
1437 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1438 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1439 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1440 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1441 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1442 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1443 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1444 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1445 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1447 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1448 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1449 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1450 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1451 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1452 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1453 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1454 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1455 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1457 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1458 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1459 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1460 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1461 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1462 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1463 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1464 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1465 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1467 fjx0 = _mm_setzero_ps();
1468 fjy0 = _mm_setzero_ps();
1469 fjz0 = _mm_setzero_ps();
1470 fjx1 = _mm_setzero_ps();
1471 fjy1 = _mm_setzero_ps();
1472 fjz1 = _mm_setzero_ps();
1473 fjx2 = _mm_setzero_ps();
1474 fjy2 = _mm_setzero_ps();
1475 fjz2 = _mm_setzero_ps();
1477 /**************************
1478 * CALCULATE INTERACTIONS *
1479 **************************/
1481 if (gmx_mm_any_lt(rsq00,rcutoff2))
1484 r00 = _mm_mul_ps(rsq00,rinv00);
1486 /* Calculate table index by multiplying r with table scale and truncate to integer */
1487 rt = _mm_mul_ps(r00,vftabscale);
1488 vfitab = _mm_cvttps_epi32(rt);
1489 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1490 vfitab = _mm_slli_epi32(vfitab,3);
1492 /* REACTION-FIELD ELECTROSTATICS */
1493 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1495 /* CUBIC SPLINE TABLE DISPERSION */
1496 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1497 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1498 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1499 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1500 _MM_TRANSPOSE4_PS(Y,F,G,H);
1501 Heps = _mm_mul_ps(vfeps,H);
1502 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1503 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1504 fvdw6 = _mm_mul_ps(c6_00,FF);
1506 /* CUBIC SPLINE TABLE REPULSION */
1507 vfitab = _mm_add_epi32(vfitab,ifour);
1508 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1509 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1510 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1511 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1512 _MM_TRANSPOSE4_PS(Y,F,G,H);
1513 Heps = _mm_mul_ps(vfeps,H);
1514 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1515 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1516 fvdw12 = _mm_mul_ps(c12_00,FF);
1517 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1519 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1521 fscal = _mm_add_ps(felec,fvdw);
1523 fscal = _mm_and_ps(fscal,cutoff_mask);
1525 /* Calculate temporary vectorial force */
1526 tx = _mm_mul_ps(fscal,dx00);
1527 ty = _mm_mul_ps(fscal,dy00);
1528 tz = _mm_mul_ps(fscal,dz00);
1530 /* Update vectorial force */
1531 fix0 = _mm_add_ps(fix0,tx);
1532 fiy0 = _mm_add_ps(fiy0,ty);
1533 fiz0 = _mm_add_ps(fiz0,tz);
1535 fjx0 = _mm_add_ps(fjx0,tx);
1536 fjy0 = _mm_add_ps(fjy0,ty);
1537 fjz0 = _mm_add_ps(fjz0,tz);
1541 /**************************
1542 * CALCULATE INTERACTIONS *
1543 **************************/
1545 if (gmx_mm_any_lt(rsq01,rcutoff2))
1548 /* REACTION-FIELD ELECTROSTATICS */
1549 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1551 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1555 fscal = _mm_and_ps(fscal,cutoff_mask);
1557 /* Calculate temporary vectorial force */
1558 tx = _mm_mul_ps(fscal,dx01);
1559 ty = _mm_mul_ps(fscal,dy01);
1560 tz = _mm_mul_ps(fscal,dz01);
1562 /* Update vectorial force */
1563 fix0 = _mm_add_ps(fix0,tx);
1564 fiy0 = _mm_add_ps(fiy0,ty);
1565 fiz0 = _mm_add_ps(fiz0,tz);
1567 fjx1 = _mm_add_ps(fjx1,tx);
1568 fjy1 = _mm_add_ps(fjy1,ty);
1569 fjz1 = _mm_add_ps(fjz1,tz);
1573 /**************************
1574 * CALCULATE INTERACTIONS *
1575 **************************/
1577 if (gmx_mm_any_lt(rsq02,rcutoff2))
1580 /* REACTION-FIELD ELECTROSTATICS */
1581 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1583 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1587 fscal = _mm_and_ps(fscal,cutoff_mask);
1589 /* Calculate temporary vectorial force */
1590 tx = _mm_mul_ps(fscal,dx02);
1591 ty = _mm_mul_ps(fscal,dy02);
1592 tz = _mm_mul_ps(fscal,dz02);
1594 /* Update vectorial force */
1595 fix0 = _mm_add_ps(fix0,tx);
1596 fiy0 = _mm_add_ps(fiy0,ty);
1597 fiz0 = _mm_add_ps(fiz0,tz);
1599 fjx2 = _mm_add_ps(fjx2,tx);
1600 fjy2 = _mm_add_ps(fjy2,ty);
1601 fjz2 = _mm_add_ps(fjz2,tz);
1605 /**************************
1606 * CALCULATE INTERACTIONS *
1607 **************************/
1609 if (gmx_mm_any_lt(rsq10,rcutoff2))
1612 /* REACTION-FIELD ELECTROSTATICS */
1613 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1615 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1619 fscal = _mm_and_ps(fscal,cutoff_mask);
1621 /* Calculate temporary vectorial force */
1622 tx = _mm_mul_ps(fscal,dx10);
1623 ty = _mm_mul_ps(fscal,dy10);
1624 tz = _mm_mul_ps(fscal,dz10);
1626 /* Update vectorial force */
1627 fix1 = _mm_add_ps(fix1,tx);
1628 fiy1 = _mm_add_ps(fiy1,ty);
1629 fiz1 = _mm_add_ps(fiz1,tz);
1631 fjx0 = _mm_add_ps(fjx0,tx);
1632 fjy0 = _mm_add_ps(fjy0,ty);
1633 fjz0 = _mm_add_ps(fjz0,tz);
1637 /**************************
1638 * CALCULATE INTERACTIONS *
1639 **************************/
1641 if (gmx_mm_any_lt(rsq11,rcutoff2))
1644 /* REACTION-FIELD ELECTROSTATICS */
1645 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1647 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1651 fscal = _mm_and_ps(fscal,cutoff_mask);
1653 /* Calculate temporary vectorial force */
1654 tx = _mm_mul_ps(fscal,dx11);
1655 ty = _mm_mul_ps(fscal,dy11);
1656 tz = _mm_mul_ps(fscal,dz11);
1658 /* Update vectorial force */
1659 fix1 = _mm_add_ps(fix1,tx);
1660 fiy1 = _mm_add_ps(fiy1,ty);
1661 fiz1 = _mm_add_ps(fiz1,tz);
1663 fjx1 = _mm_add_ps(fjx1,tx);
1664 fjy1 = _mm_add_ps(fjy1,ty);
1665 fjz1 = _mm_add_ps(fjz1,tz);
1669 /**************************
1670 * CALCULATE INTERACTIONS *
1671 **************************/
1673 if (gmx_mm_any_lt(rsq12,rcutoff2))
1676 /* REACTION-FIELD ELECTROSTATICS */
1677 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1679 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1683 fscal = _mm_and_ps(fscal,cutoff_mask);
1685 /* Calculate temporary vectorial force */
1686 tx = _mm_mul_ps(fscal,dx12);
1687 ty = _mm_mul_ps(fscal,dy12);
1688 tz = _mm_mul_ps(fscal,dz12);
1690 /* Update vectorial force */
1691 fix1 = _mm_add_ps(fix1,tx);
1692 fiy1 = _mm_add_ps(fiy1,ty);
1693 fiz1 = _mm_add_ps(fiz1,tz);
1695 fjx2 = _mm_add_ps(fjx2,tx);
1696 fjy2 = _mm_add_ps(fjy2,ty);
1697 fjz2 = _mm_add_ps(fjz2,tz);
1701 /**************************
1702 * CALCULATE INTERACTIONS *
1703 **************************/
1705 if (gmx_mm_any_lt(rsq20,rcutoff2))
1708 /* REACTION-FIELD ELECTROSTATICS */
1709 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1711 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1715 fscal = _mm_and_ps(fscal,cutoff_mask);
1717 /* Calculate temporary vectorial force */
1718 tx = _mm_mul_ps(fscal,dx20);
1719 ty = _mm_mul_ps(fscal,dy20);
1720 tz = _mm_mul_ps(fscal,dz20);
1722 /* Update vectorial force */
1723 fix2 = _mm_add_ps(fix2,tx);
1724 fiy2 = _mm_add_ps(fiy2,ty);
1725 fiz2 = _mm_add_ps(fiz2,tz);
1727 fjx0 = _mm_add_ps(fjx0,tx);
1728 fjy0 = _mm_add_ps(fjy0,ty);
1729 fjz0 = _mm_add_ps(fjz0,tz);
1733 /**************************
1734 * CALCULATE INTERACTIONS *
1735 **************************/
1737 if (gmx_mm_any_lt(rsq21,rcutoff2))
1740 /* REACTION-FIELD ELECTROSTATICS */
1741 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1743 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1747 fscal = _mm_and_ps(fscal,cutoff_mask);
1749 /* Calculate temporary vectorial force */
1750 tx = _mm_mul_ps(fscal,dx21);
1751 ty = _mm_mul_ps(fscal,dy21);
1752 tz = _mm_mul_ps(fscal,dz21);
1754 /* Update vectorial force */
1755 fix2 = _mm_add_ps(fix2,tx);
1756 fiy2 = _mm_add_ps(fiy2,ty);
1757 fiz2 = _mm_add_ps(fiz2,tz);
1759 fjx1 = _mm_add_ps(fjx1,tx);
1760 fjy1 = _mm_add_ps(fjy1,ty);
1761 fjz1 = _mm_add_ps(fjz1,tz);
1765 /**************************
1766 * CALCULATE INTERACTIONS *
1767 **************************/
1769 if (gmx_mm_any_lt(rsq22,rcutoff2))
1772 /* REACTION-FIELD ELECTROSTATICS */
1773 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1775 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1779 fscal = _mm_and_ps(fscal,cutoff_mask);
1781 /* Calculate temporary vectorial force */
1782 tx = _mm_mul_ps(fscal,dx22);
1783 ty = _mm_mul_ps(fscal,dy22);
1784 tz = _mm_mul_ps(fscal,dz22);
1786 /* Update vectorial force */
1787 fix2 = _mm_add_ps(fix2,tx);
1788 fiy2 = _mm_add_ps(fiy2,ty);
1789 fiz2 = _mm_add_ps(fiz2,tz);
1791 fjx2 = _mm_add_ps(fjx2,tx);
1792 fjy2 = _mm_add_ps(fjy2,ty);
1793 fjz2 = _mm_add_ps(fjz2,tz);
1797 fjptrA = f+j_coord_offsetA;
1798 fjptrB = f+j_coord_offsetB;
1799 fjptrC = f+j_coord_offsetC;
1800 fjptrD = f+j_coord_offsetD;
1802 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1803 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1805 /* Inner loop uses 297 flops */
1808 if(jidx<j_index_end)
1811 /* Get j neighbor index, and coordinate index */
1812 jnrlistA = jjnr[jidx];
1813 jnrlistB = jjnr[jidx+1];
1814 jnrlistC = jjnr[jidx+2];
1815 jnrlistD = jjnr[jidx+3];
1816 /* Sign of each element will be negative for non-real atoms.
1817 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1818 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1820 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1821 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1822 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1823 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1824 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1825 j_coord_offsetA = DIM*jnrA;
1826 j_coord_offsetB = DIM*jnrB;
1827 j_coord_offsetC = DIM*jnrC;
1828 j_coord_offsetD = DIM*jnrD;
1830 /* load j atom coordinates */
1831 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1832 x+j_coord_offsetC,x+j_coord_offsetD,
1833 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1835 /* Calculate displacement vector */
1836 dx00 = _mm_sub_ps(ix0,jx0);
1837 dy00 = _mm_sub_ps(iy0,jy0);
1838 dz00 = _mm_sub_ps(iz0,jz0);
1839 dx01 = _mm_sub_ps(ix0,jx1);
1840 dy01 = _mm_sub_ps(iy0,jy1);
1841 dz01 = _mm_sub_ps(iz0,jz1);
1842 dx02 = _mm_sub_ps(ix0,jx2);
1843 dy02 = _mm_sub_ps(iy0,jy2);
1844 dz02 = _mm_sub_ps(iz0,jz2);
1845 dx10 = _mm_sub_ps(ix1,jx0);
1846 dy10 = _mm_sub_ps(iy1,jy0);
1847 dz10 = _mm_sub_ps(iz1,jz0);
1848 dx11 = _mm_sub_ps(ix1,jx1);
1849 dy11 = _mm_sub_ps(iy1,jy1);
1850 dz11 = _mm_sub_ps(iz1,jz1);
1851 dx12 = _mm_sub_ps(ix1,jx2);
1852 dy12 = _mm_sub_ps(iy1,jy2);
1853 dz12 = _mm_sub_ps(iz1,jz2);
1854 dx20 = _mm_sub_ps(ix2,jx0);
1855 dy20 = _mm_sub_ps(iy2,jy0);
1856 dz20 = _mm_sub_ps(iz2,jz0);
1857 dx21 = _mm_sub_ps(ix2,jx1);
1858 dy21 = _mm_sub_ps(iy2,jy1);
1859 dz21 = _mm_sub_ps(iz2,jz1);
1860 dx22 = _mm_sub_ps(ix2,jx2);
1861 dy22 = _mm_sub_ps(iy2,jy2);
1862 dz22 = _mm_sub_ps(iz2,jz2);
1864 /* Calculate squared distance and things based on it */
1865 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1866 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1867 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1868 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1869 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1870 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1871 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1872 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1873 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1875 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1876 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1877 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1878 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1879 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1880 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1881 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1882 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1883 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1885 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1886 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1887 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1888 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1889 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1890 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1891 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1892 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1893 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1895 fjx0 = _mm_setzero_ps();
1896 fjy0 = _mm_setzero_ps();
1897 fjz0 = _mm_setzero_ps();
1898 fjx1 = _mm_setzero_ps();
1899 fjy1 = _mm_setzero_ps();
1900 fjz1 = _mm_setzero_ps();
1901 fjx2 = _mm_setzero_ps();
1902 fjy2 = _mm_setzero_ps();
1903 fjz2 = _mm_setzero_ps();
1905 /**************************
1906 * CALCULATE INTERACTIONS *
1907 **************************/
1909 if (gmx_mm_any_lt(rsq00,rcutoff2))
1912 r00 = _mm_mul_ps(rsq00,rinv00);
1913 r00 = _mm_andnot_ps(dummy_mask,r00);
1915 /* Calculate table index by multiplying r with table scale and truncate to integer */
1916 rt = _mm_mul_ps(r00,vftabscale);
1917 vfitab = _mm_cvttps_epi32(rt);
1918 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1919 vfitab = _mm_slli_epi32(vfitab,3);
1921 /* REACTION-FIELD ELECTROSTATICS */
1922 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1924 /* CUBIC SPLINE TABLE DISPERSION */
1925 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1926 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1927 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1928 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1929 _MM_TRANSPOSE4_PS(Y,F,G,H);
1930 Heps = _mm_mul_ps(vfeps,H);
1931 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1932 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1933 fvdw6 = _mm_mul_ps(c6_00,FF);
1935 /* CUBIC SPLINE TABLE REPULSION */
1936 vfitab = _mm_add_epi32(vfitab,ifour);
1937 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1938 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1939 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1940 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1941 _MM_TRANSPOSE4_PS(Y,F,G,H);
1942 Heps = _mm_mul_ps(vfeps,H);
1943 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1944 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1945 fvdw12 = _mm_mul_ps(c12_00,FF);
1946 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1948 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1950 fscal = _mm_add_ps(felec,fvdw);
1952 fscal = _mm_and_ps(fscal,cutoff_mask);
1954 fscal = _mm_andnot_ps(dummy_mask,fscal);
1956 /* Calculate temporary vectorial force */
1957 tx = _mm_mul_ps(fscal,dx00);
1958 ty = _mm_mul_ps(fscal,dy00);
1959 tz = _mm_mul_ps(fscal,dz00);
1961 /* Update vectorial force */
1962 fix0 = _mm_add_ps(fix0,tx);
1963 fiy0 = _mm_add_ps(fiy0,ty);
1964 fiz0 = _mm_add_ps(fiz0,tz);
1966 fjx0 = _mm_add_ps(fjx0,tx);
1967 fjy0 = _mm_add_ps(fjy0,ty);
1968 fjz0 = _mm_add_ps(fjz0,tz);
1972 /**************************
1973 * CALCULATE INTERACTIONS *
1974 **************************/
1976 if (gmx_mm_any_lt(rsq01,rcutoff2))
1979 /* REACTION-FIELD ELECTROSTATICS */
1980 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1982 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1986 fscal = _mm_and_ps(fscal,cutoff_mask);
1988 fscal = _mm_andnot_ps(dummy_mask,fscal);
1990 /* Calculate temporary vectorial force */
1991 tx = _mm_mul_ps(fscal,dx01);
1992 ty = _mm_mul_ps(fscal,dy01);
1993 tz = _mm_mul_ps(fscal,dz01);
1995 /* Update vectorial force */
1996 fix0 = _mm_add_ps(fix0,tx);
1997 fiy0 = _mm_add_ps(fiy0,ty);
1998 fiz0 = _mm_add_ps(fiz0,tz);
2000 fjx1 = _mm_add_ps(fjx1,tx);
2001 fjy1 = _mm_add_ps(fjy1,ty);
2002 fjz1 = _mm_add_ps(fjz1,tz);
2006 /**************************
2007 * CALCULATE INTERACTIONS *
2008 **************************/
2010 if (gmx_mm_any_lt(rsq02,rcutoff2))
2013 /* REACTION-FIELD ELECTROSTATICS */
2014 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
2016 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
2020 fscal = _mm_and_ps(fscal,cutoff_mask);
2022 fscal = _mm_andnot_ps(dummy_mask,fscal);
2024 /* Calculate temporary vectorial force */
2025 tx = _mm_mul_ps(fscal,dx02);
2026 ty = _mm_mul_ps(fscal,dy02);
2027 tz = _mm_mul_ps(fscal,dz02);
2029 /* Update vectorial force */
2030 fix0 = _mm_add_ps(fix0,tx);
2031 fiy0 = _mm_add_ps(fiy0,ty);
2032 fiz0 = _mm_add_ps(fiz0,tz);
2034 fjx2 = _mm_add_ps(fjx2,tx);
2035 fjy2 = _mm_add_ps(fjy2,ty);
2036 fjz2 = _mm_add_ps(fjz2,tz);
2040 /**************************
2041 * CALCULATE INTERACTIONS *
2042 **************************/
2044 if (gmx_mm_any_lt(rsq10,rcutoff2))
2047 /* REACTION-FIELD ELECTROSTATICS */
2048 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
2050 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
2054 fscal = _mm_and_ps(fscal,cutoff_mask);
2056 fscal = _mm_andnot_ps(dummy_mask,fscal);
2058 /* Calculate temporary vectorial force */
2059 tx = _mm_mul_ps(fscal,dx10);
2060 ty = _mm_mul_ps(fscal,dy10);
2061 tz = _mm_mul_ps(fscal,dz10);
2063 /* Update vectorial force */
2064 fix1 = _mm_add_ps(fix1,tx);
2065 fiy1 = _mm_add_ps(fiy1,ty);
2066 fiz1 = _mm_add_ps(fiz1,tz);
2068 fjx0 = _mm_add_ps(fjx0,tx);
2069 fjy0 = _mm_add_ps(fjy0,ty);
2070 fjz0 = _mm_add_ps(fjz0,tz);
2074 /**************************
2075 * CALCULATE INTERACTIONS *
2076 **************************/
2078 if (gmx_mm_any_lt(rsq11,rcutoff2))
2081 /* REACTION-FIELD ELECTROSTATICS */
2082 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
2084 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
2088 fscal = _mm_and_ps(fscal,cutoff_mask);
2090 fscal = _mm_andnot_ps(dummy_mask,fscal);
2092 /* Calculate temporary vectorial force */
2093 tx = _mm_mul_ps(fscal,dx11);
2094 ty = _mm_mul_ps(fscal,dy11);
2095 tz = _mm_mul_ps(fscal,dz11);
2097 /* Update vectorial force */
2098 fix1 = _mm_add_ps(fix1,tx);
2099 fiy1 = _mm_add_ps(fiy1,ty);
2100 fiz1 = _mm_add_ps(fiz1,tz);
2102 fjx1 = _mm_add_ps(fjx1,tx);
2103 fjy1 = _mm_add_ps(fjy1,ty);
2104 fjz1 = _mm_add_ps(fjz1,tz);
2108 /**************************
2109 * CALCULATE INTERACTIONS *
2110 **************************/
2112 if (gmx_mm_any_lt(rsq12,rcutoff2))
2115 /* REACTION-FIELD ELECTROSTATICS */
2116 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
2118 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
2122 fscal = _mm_and_ps(fscal,cutoff_mask);
2124 fscal = _mm_andnot_ps(dummy_mask,fscal);
2126 /* Calculate temporary vectorial force */
2127 tx = _mm_mul_ps(fscal,dx12);
2128 ty = _mm_mul_ps(fscal,dy12);
2129 tz = _mm_mul_ps(fscal,dz12);
2131 /* Update vectorial force */
2132 fix1 = _mm_add_ps(fix1,tx);
2133 fiy1 = _mm_add_ps(fiy1,ty);
2134 fiz1 = _mm_add_ps(fiz1,tz);
2136 fjx2 = _mm_add_ps(fjx2,tx);
2137 fjy2 = _mm_add_ps(fjy2,ty);
2138 fjz2 = _mm_add_ps(fjz2,tz);
2142 /**************************
2143 * CALCULATE INTERACTIONS *
2144 **************************/
2146 if (gmx_mm_any_lt(rsq20,rcutoff2))
2149 /* REACTION-FIELD ELECTROSTATICS */
2150 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
2152 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
2156 fscal = _mm_and_ps(fscal,cutoff_mask);
2158 fscal = _mm_andnot_ps(dummy_mask,fscal);
2160 /* Calculate temporary vectorial force */
2161 tx = _mm_mul_ps(fscal,dx20);
2162 ty = _mm_mul_ps(fscal,dy20);
2163 tz = _mm_mul_ps(fscal,dz20);
2165 /* Update vectorial force */
2166 fix2 = _mm_add_ps(fix2,tx);
2167 fiy2 = _mm_add_ps(fiy2,ty);
2168 fiz2 = _mm_add_ps(fiz2,tz);
2170 fjx0 = _mm_add_ps(fjx0,tx);
2171 fjy0 = _mm_add_ps(fjy0,ty);
2172 fjz0 = _mm_add_ps(fjz0,tz);
2176 /**************************
2177 * CALCULATE INTERACTIONS *
2178 **************************/
2180 if (gmx_mm_any_lt(rsq21,rcutoff2))
2183 /* REACTION-FIELD ELECTROSTATICS */
2184 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
2186 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
2190 fscal = _mm_and_ps(fscal,cutoff_mask);
2192 fscal = _mm_andnot_ps(dummy_mask,fscal);
2194 /* Calculate temporary vectorial force */
2195 tx = _mm_mul_ps(fscal,dx21);
2196 ty = _mm_mul_ps(fscal,dy21);
2197 tz = _mm_mul_ps(fscal,dz21);
2199 /* Update vectorial force */
2200 fix2 = _mm_add_ps(fix2,tx);
2201 fiy2 = _mm_add_ps(fiy2,ty);
2202 fiz2 = _mm_add_ps(fiz2,tz);
2204 fjx1 = _mm_add_ps(fjx1,tx);
2205 fjy1 = _mm_add_ps(fjy1,ty);
2206 fjz1 = _mm_add_ps(fjz1,tz);
2210 /**************************
2211 * CALCULATE INTERACTIONS *
2212 **************************/
2214 if (gmx_mm_any_lt(rsq22,rcutoff2))
2217 /* REACTION-FIELD ELECTROSTATICS */
2218 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2220 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
2224 fscal = _mm_and_ps(fscal,cutoff_mask);
2226 fscal = _mm_andnot_ps(dummy_mask,fscal);
2228 /* Calculate temporary vectorial force */
2229 tx = _mm_mul_ps(fscal,dx22);
2230 ty = _mm_mul_ps(fscal,dy22);
2231 tz = _mm_mul_ps(fscal,dz22);
2233 /* Update vectorial force */
2234 fix2 = _mm_add_ps(fix2,tx);
2235 fiy2 = _mm_add_ps(fiy2,ty);
2236 fiz2 = _mm_add_ps(fiz2,tz);
2238 fjx2 = _mm_add_ps(fjx2,tx);
2239 fjy2 = _mm_add_ps(fjy2,ty);
2240 fjz2 = _mm_add_ps(fjz2,tz);
2244 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2245 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2246 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2247 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2249 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2250 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2252 /* Inner loop uses 298 flops */
2255 /* End of innermost loop */
2257 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2258 f+i_coord_offset,fshift+i_shift_offset);
2260 /* Increment number of inner iterations */
2261 inneriter += j_index_end - j_index_start;
2263 /* Outer loop uses 18 flops */
2266 /* Increment number of outer iterations */
2269 /* Update outer/inner flops */
2271 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);