2 * Note: this file was generated by the Gromacs sse2_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_sse2_single.h"
34 #include "kernelutil_x86_sse2_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_VF_sse2_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water4-Water4
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_VF_sse2_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
62 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
63 real shX,shY,shZ,rcutoff_scalar;
64 real *shiftvec,*fshift,*x,*f;
65 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
67 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
69 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
71 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
73 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
74 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
75 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
76 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
77 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
78 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
79 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
80 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
81 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
82 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
83 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
84 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
85 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
86 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
87 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
88 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
89 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
90 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
91 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
92 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
95 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
98 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
99 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
100 __m128 dummy_mask,cutoff_mask;
101 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
102 __m128 one = _mm_set1_ps(1.0);
103 __m128 two = _mm_set1_ps(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_ps(fr->epsfac);
116 charge = mdatoms->chargeA;
117 krf = _mm_set1_ps(fr->ic->k_rf);
118 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
119 crf = _mm_set1_ps(fr->ic->c_rf);
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 /* Setup water-specific parameters */
125 inr = nlist->iinr[0];
126 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
127 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
128 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
129 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
131 jq1 = _mm_set1_ps(charge[inr+1]);
132 jq2 = _mm_set1_ps(charge[inr+2]);
133 jq3 = _mm_set1_ps(charge[inr+3]);
134 vdwjidx0A = 2*vdwtype[inr+0];
135 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
136 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
137 qq11 = _mm_mul_ps(iq1,jq1);
138 qq12 = _mm_mul_ps(iq1,jq2);
139 qq13 = _mm_mul_ps(iq1,jq3);
140 qq21 = _mm_mul_ps(iq2,jq1);
141 qq22 = _mm_mul_ps(iq2,jq2);
142 qq23 = _mm_mul_ps(iq2,jq3);
143 qq31 = _mm_mul_ps(iq3,jq1);
144 qq32 = _mm_mul_ps(iq3,jq2);
145 qq33 = _mm_mul_ps(iq3,jq3);
147 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
148 rcutoff_scalar = fr->rcoulomb;
149 rcutoff = _mm_set1_ps(rcutoff_scalar);
150 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
152 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
153 rvdw = _mm_set1_ps(fr->rvdw);
155 /* Avoid stupid compiler warnings */
156 jnrA = jnrB = jnrC = jnrD = 0;
165 /* Start outer loop over neighborlists */
166 for(iidx=0; iidx<nri; iidx++)
168 /* Load shift vector for this list */
169 i_shift_offset = DIM*shiftidx[iidx];
170 shX = shiftvec[i_shift_offset+XX];
171 shY = shiftvec[i_shift_offset+YY];
172 shZ = shiftvec[i_shift_offset+ZZ];
174 /* Load limits for loop over neighbors */
175 j_index_start = jindex[iidx];
176 j_index_end = jindex[iidx+1];
178 /* Get outer coordinate index */
180 i_coord_offset = DIM*inr;
182 /* Load i particle coords and add shift vector */
183 ix0 = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
184 iy0 = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
185 iz0 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
186 ix1 = _mm_set1_ps(shX + x[i_coord_offset+DIM*1+XX]);
187 iy1 = _mm_set1_ps(shY + x[i_coord_offset+DIM*1+YY]);
188 iz1 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*1+ZZ]);
189 ix2 = _mm_set1_ps(shX + x[i_coord_offset+DIM*2+XX]);
190 iy2 = _mm_set1_ps(shY + x[i_coord_offset+DIM*2+YY]);
191 iz2 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*2+ZZ]);
192 ix3 = _mm_set1_ps(shX + x[i_coord_offset+DIM*3+XX]);
193 iy3 = _mm_set1_ps(shY + x[i_coord_offset+DIM*3+YY]);
194 iz3 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*3+ZZ]);
196 fix0 = _mm_setzero_ps();
197 fiy0 = _mm_setzero_ps();
198 fiz0 = _mm_setzero_ps();
199 fix1 = _mm_setzero_ps();
200 fiy1 = _mm_setzero_ps();
201 fiz1 = _mm_setzero_ps();
202 fix2 = _mm_setzero_ps();
203 fiy2 = _mm_setzero_ps();
204 fiz2 = _mm_setzero_ps();
205 fix3 = _mm_setzero_ps();
206 fiy3 = _mm_setzero_ps();
207 fiz3 = _mm_setzero_ps();
209 /* Reset potential sums */
210 velecsum = _mm_setzero_ps();
211 vvdwsum = _mm_setzero_ps();
213 /* Start inner kernel loop */
214 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
217 /* Get j neighbor index, and coordinate index */
223 j_coord_offsetA = DIM*jnrA;
224 j_coord_offsetB = DIM*jnrB;
225 j_coord_offsetC = DIM*jnrC;
226 j_coord_offsetD = DIM*jnrD;
228 /* load j atom coordinates */
229 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
230 x+j_coord_offsetC,x+j_coord_offsetD,
231 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
232 &jy2,&jz2,&jx3,&jy3,&jz3);
234 /* Calculate displacement vector */
235 dx00 = _mm_sub_ps(ix0,jx0);
236 dy00 = _mm_sub_ps(iy0,jy0);
237 dz00 = _mm_sub_ps(iz0,jz0);
238 dx11 = _mm_sub_ps(ix1,jx1);
239 dy11 = _mm_sub_ps(iy1,jy1);
240 dz11 = _mm_sub_ps(iz1,jz1);
241 dx12 = _mm_sub_ps(ix1,jx2);
242 dy12 = _mm_sub_ps(iy1,jy2);
243 dz12 = _mm_sub_ps(iz1,jz2);
244 dx13 = _mm_sub_ps(ix1,jx3);
245 dy13 = _mm_sub_ps(iy1,jy3);
246 dz13 = _mm_sub_ps(iz1,jz3);
247 dx21 = _mm_sub_ps(ix2,jx1);
248 dy21 = _mm_sub_ps(iy2,jy1);
249 dz21 = _mm_sub_ps(iz2,jz1);
250 dx22 = _mm_sub_ps(ix2,jx2);
251 dy22 = _mm_sub_ps(iy2,jy2);
252 dz22 = _mm_sub_ps(iz2,jz2);
253 dx23 = _mm_sub_ps(ix2,jx3);
254 dy23 = _mm_sub_ps(iy2,jy3);
255 dz23 = _mm_sub_ps(iz2,jz3);
256 dx31 = _mm_sub_ps(ix3,jx1);
257 dy31 = _mm_sub_ps(iy3,jy1);
258 dz31 = _mm_sub_ps(iz3,jz1);
259 dx32 = _mm_sub_ps(ix3,jx2);
260 dy32 = _mm_sub_ps(iy3,jy2);
261 dz32 = _mm_sub_ps(iz3,jz2);
262 dx33 = _mm_sub_ps(ix3,jx3);
263 dy33 = _mm_sub_ps(iy3,jy3);
264 dz33 = _mm_sub_ps(iz3,jz3);
266 /* Calculate squared distance and things based on it */
267 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
268 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
269 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
270 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
271 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
272 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
273 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
274 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
275 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
276 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
278 rinv11 = gmx_mm_invsqrt_ps(rsq11);
279 rinv12 = gmx_mm_invsqrt_ps(rsq12);
280 rinv13 = gmx_mm_invsqrt_ps(rsq13);
281 rinv21 = gmx_mm_invsqrt_ps(rsq21);
282 rinv22 = gmx_mm_invsqrt_ps(rsq22);
283 rinv23 = gmx_mm_invsqrt_ps(rsq23);
284 rinv31 = gmx_mm_invsqrt_ps(rsq31);
285 rinv32 = gmx_mm_invsqrt_ps(rsq32);
286 rinv33 = gmx_mm_invsqrt_ps(rsq33);
288 rinvsq00 = gmx_mm_inv_ps(rsq00);
289 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
290 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
291 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
292 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
293 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
294 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
295 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
296 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
297 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
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();
308 fjx3 = _mm_setzero_ps();
309 fjy3 = _mm_setzero_ps();
310 fjz3 = _mm_setzero_ps();
312 /**************************
313 * CALCULATE INTERACTIONS *
314 **************************/
316 if (gmx_mm_any_lt(rsq00,rcutoff2))
319 /* LENNARD-JONES DISPERSION/REPULSION */
321 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
322 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
323 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
324 vvdw = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
325 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
326 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
328 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
330 /* Update potential sum for this i atom from the interaction with this j atom. */
331 vvdw = _mm_and_ps(vvdw,cutoff_mask);
332 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
336 fscal = _mm_and_ps(fscal,cutoff_mask);
338 /* Calculate temporary vectorial force */
339 tx = _mm_mul_ps(fscal,dx00);
340 ty = _mm_mul_ps(fscal,dy00);
341 tz = _mm_mul_ps(fscal,dz00);
343 /* Update vectorial force */
344 fix0 = _mm_add_ps(fix0,tx);
345 fiy0 = _mm_add_ps(fiy0,ty);
346 fiz0 = _mm_add_ps(fiz0,tz);
348 fjx0 = _mm_add_ps(fjx0,tx);
349 fjy0 = _mm_add_ps(fjy0,ty);
350 fjz0 = _mm_add_ps(fjz0,tz);
354 /**************************
355 * CALCULATE INTERACTIONS *
356 **************************/
358 if (gmx_mm_any_lt(rsq11,rcutoff2))
361 /* REACTION-FIELD ELECTROSTATICS */
362 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
363 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
365 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
367 /* Update potential sum for this i atom from the interaction with this j atom. */
368 velec = _mm_and_ps(velec,cutoff_mask);
369 velecsum = _mm_add_ps(velecsum,velec);
373 fscal = _mm_and_ps(fscal,cutoff_mask);
375 /* Calculate temporary vectorial force */
376 tx = _mm_mul_ps(fscal,dx11);
377 ty = _mm_mul_ps(fscal,dy11);
378 tz = _mm_mul_ps(fscal,dz11);
380 /* Update vectorial force */
381 fix1 = _mm_add_ps(fix1,tx);
382 fiy1 = _mm_add_ps(fiy1,ty);
383 fiz1 = _mm_add_ps(fiz1,tz);
385 fjx1 = _mm_add_ps(fjx1,tx);
386 fjy1 = _mm_add_ps(fjy1,ty);
387 fjz1 = _mm_add_ps(fjz1,tz);
391 /**************************
392 * CALCULATE INTERACTIONS *
393 **************************/
395 if (gmx_mm_any_lt(rsq12,rcutoff2))
398 /* REACTION-FIELD ELECTROSTATICS */
399 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
400 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
402 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
404 /* Update potential sum for this i atom from the interaction with this j atom. */
405 velec = _mm_and_ps(velec,cutoff_mask);
406 velecsum = _mm_add_ps(velecsum,velec);
410 fscal = _mm_and_ps(fscal,cutoff_mask);
412 /* Calculate temporary vectorial force */
413 tx = _mm_mul_ps(fscal,dx12);
414 ty = _mm_mul_ps(fscal,dy12);
415 tz = _mm_mul_ps(fscal,dz12);
417 /* Update vectorial force */
418 fix1 = _mm_add_ps(fix1,tx);
419 fiy1 = _mm_add_ps(fiy1,ty);
420 fiz1 = _mm_add_ps(fiz1,tz);
422 fjx2 = _mm_add_ps(fjx2,tx);
423 fjy2 = _mm_add_ps(fjy2,ty);
424 fjz2 = _mm_add_ps(fjz2,tz);
428 /**************************
429 * CALCULATE INTERACTIONS *
430 **************************/
432 if (gmx_mm_any_lt(rsq13,rcutoff2))
435 /* REACTION-FIELD ELECTROSTATICS */
436 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
437 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
439 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
441 /* Update potential sum for this i atom from the interaction with this j atom. */
442 velec = _mm_and_ps(velec,cutoff_mask);
443 velecsum = _mm_add_ps(velecsum,velec);
447 fscal = _mm_and_ps(fscal,cutoff_mask);
449 /* Calculate temporary vectorial force */
450 tx = _mm_mul_ps(fscal,dx13);
451 ty = _mm_mul_ps(fscal,dy13);
452 tz = _mm_mul_ps(fscal,dz13);
454 /* Update vectorial force */
455 fix1 = _mm_add_ps(fix1,tx);
456 fiy1 = _mm_add_ps(fiy1,ty);
457 fiz1 = _mm_add_ps(fiz1,tz);
459 fjx3 = _mm_add_ps(fjx3,tx);
460 fjy3 = _mm_add_ps(fjy3,ty);
461 fjz3 = _mm_add_ps(fjz3,tz);
465 /**************************
466 * CALCULATE INTERACTIONS *
467 **************************/
469 if (gmx_mm_any_lt(rsq21,rcutoff2))
472 /* REACTION-FIELD ELECTROSTATICS */
473 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
474 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
476 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
478 /* Update potential sum for this i atom from the interaction with this j atom. */
479 velec = _mm_and_ps(velec,cutoff_mask);
480 velecsum = _mm_add_ps(velecsum,velec);
484 fscal = _mm_and_ps(fscal,cutoff_mask);
486 /* Calculate temporary vectorial force */
487 tx = _mm_mul_ps(fscal,dx21);
488 ty = _mm_mul_ps(fscal,dy21);
489 tz = _mm_mul_ps(fscal,dz21);
491 /* Update vectorial force */
492 fix2 = _mm_add_ps(fix2,tx);
493 fiy2 = _mm_add_ps(fiy2,ty);
494 fiz2 = _mm_add_ps(fiz2,tz);
496 fjx1 = _mm_add_ps(fjx1,tx);
497 fjy1 = _mm_add_ps(fjy1,ty);
498 fjz1 = _mm_add_ps(fjz1,tz);
502 /**************************
503 * CALCULATE INTERACTIONS *
504 **************************/
506 if (gmx_mm_any_lt(rsq22,rcutoff2))
509 /* REACTION-FIELD ELECTROSTATICS */
510 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
511 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
513 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
515 /* Update potential sum for this i atom from the interaction with this j atom. */
516 velec = _mm_and_ps(velec,cutoff_mask);
517 velecsum = _mm_add_ps(velecsum,velec);
521 fscal = _mm_and_ps(fscal,cutoff_mask);
523 /* Calculate temporary vectorial force */
524 tx = _mm_mul_ps(fscal,dx22);
525 ty = _mm_mul_ps(fscal,dy22);
526 tz = _mm_mul_ps(fscal,dz22);
528 /* Update vectorial force */
529 fix2 = _mm_add_ps(fix2,tx);
530 fiy2 = _mm_add_ps(fiy2,ty);
531 fiz2 = _mm_add_ps(fiz2,tz);
533 fjx2 = _mm_add_ps(fjx2,tx);
534 fjy2 = _mm_add_ps(fjy2,ty);
535 fjz2 = _mm_add_ps(fjz2,tz);
539 /**************************
540 * CALCULATE INTERACTIONS *
541 **************************/
543 if (gmx_mm_any_lt(rsq23,rcutoff2))
546 /* REACTION-FIELD ELECTROSTATICS */
547 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
548 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
550 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
552 /* Update potential sum for this i atom from the interaction with this j atom. */
553 velec = _mm_and_ps(velec,cutoff_mask);
554 velecsum = _mm_add_ps(velecsum,velec);
558 fscal = _mm_and_ps(fscal,cutoff_mask);
560 /* Calculate temporary vectorial force */
561 tx = _mm_mul_ps(fscal,dx23);
562 ty = _mm_mul_ps(fscal,dy23);
563 tz = _mm_mul_ps(fscal,dz23);
565 /* Update vectorial force */
566 fix2 = _mm_add_ps(fix2,tx);
567 fiy2 = _mm_add_ps(fiy2,ty);
568 fiz2 = _mm_add_ps(fiz2,tz);
570 fjx3 = _mm_add_ps(fjx3,tx);
571 fjy3 = _mm_add_ps(fjy3,ty);
572 fjz3 = _mm_add_ps(fjz3,tz);
576 /**************************
577 * CALCULATE INTERACTIONS *
578 **************************/
580 if (gmx_mm_any_lt(rsq31,rcutoff2))
583 /* REACTION-FIELD ELECTROSTATICS */
584 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
585 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
587 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
589 /* Update potential sum for this i atom from the interaction with this j atom. */
590 velec = _mm_and_ps(velec,cutoff_mask);
591 velecsum = _mm_add_ps(velecsum,velec);
595 fscal = _mm_and_ps(fscal,cutoff_mask);
597 /* Calculate temporary vectorial force */
598 tx = _mm_mul_ps(fscal,dx31);
599 ty = _mm_mul_ps(fscal,dy31);
600 tz = _mm_mul_ps(fscal,dz31);
602 /* Update vectorial force */
603 fix3 = _mm_add_ps(fix3,tx);
604 fiy3 = _mm_add_ps(fiy3,ty);
605 fiz3 = _mm_add_ps(fiz3,tz);
607 fjx1 = _mm_add_ps(fjx1,tx);
608 fjy1 = _mm_add_ps(fjy1,ty);
609 fjz1 = _mm_add_ps(fjz1,tz);
613 /**************************
614 * CALCULATE INTERACTIONS *
615 **************************/
617 if (gmx_mm_any_lt(rsq32,rcutoff2))
620 /* REACTION-FIELD ELECTROSTATICS */
621 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
622 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
624 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
626 /* Update potential sum for this i atom from the interaction with this j atom. */
627 velec = _mm_and_ps(velec,cutoff_mask);
628 velecsum = _mm_add_ps(velecsum,velec);
632 fscal = _mm_and_ps(fscal,cutoff_mask);
634 /* Calculate temporary vectorial force */
635 tx = _mm_mul_ps(fscal,dx32);
636 ty = _mm_mul_ps(fscal,dy32);
637 tz = _mm_mul_ps(fscal,dz32);
639 /* Update vectorial force */
640 fix3 = _mm_add_ps(fix3,tx);
641 fiy3 = _mm_add_ps(fiy3,ty);
642 fiz3 = _mm_add_ps(fiz3,tz);
644 fjx2 = _mm_add_ps(fjx2,tx);
645 fjy2 = _mm_add_ps(fjy2,ty);
646 fjz2 = _mm_add_ps(fjz2,tz);
650 /**************************
651 * CALCULATE INTERACTIONS *
652 **************************/
654 if (gmx_mm_any_lt(rsq33,rcutoff2))
657 /* REACTION-FIELD ELECTROSTATICS */
658 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
659 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
661 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
663 /* Update potential sum for this i atom from the interaction with this j atom. */
664 velec = _mm_and_ps(velec,cutoff_mask);
665 velecsum = _mm_add_ps(velecsum,velec);
669 fscal = _mm_and_ps(fscal,cutoff_mask);
671 /* Calculate temporary vectorial force */
672 tx = _mm_mul_ps(fscal,dx33);
673 ty = _mm_mul_ps(fscal,dy33);
674 tz = _mm_mul_ps(fscal,dz33);
676 /* Update vectorial force */
677 fix3 = _mm_add_ps(fix3,tx);
678 fiy3 = _mm_add_ps(fiy3,ty);
679 fiz3 = _mm_add_ps(fiz3,tz);
681 fjx3 = _mm_add_ps(fjx3,tx);
682 fjy3 = _mm_add_ps(fjy3,ty);
683 fjz3 = _mm_add_ps(fjz3,tz);
687 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
688 f+j_coord_offsetC,f+j_coord_offsetD,
689 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
690 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
692 /* Inner loop uses 368 flops */
698 /* Get j neighbor index, and coordinate index */
704 /* Sign of each element will be negative for non-real atoms.
705 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
706 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
708 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
709 jnrA = (jnrA>=0) ? jnrA : 0;
710 jnrB = (jnrB>=0) ? jnrB : 0;
711 jnrC = (jnrC>=0) ? jnrC : 0;
712 jnrD = (jnrD>=0) ? jnrD : 0;
714 j_coord_offsetA = DIM*jnrA;
715 j_coord_offsetB = DIM*jnrB;
716 j_coord_offsetC = DIM*jnrC;
717 j_coord_offsetD = DIM*jnrD;
719 /* load j atom coordinates */
720 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
721 x+j_coord_offsetC,x+j_coord_offsetD,
722 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
723 &jy2,&jz2,&jx3,&jy3,&jz3);
725 /* Calculate displacement vector */
726 dx00 = _mm_sub_ps(ix0,jx0);
727 dy00 = _mm_sub_ps(iy0,jy0);
728 dz00 = _mm_sub_ps(iz0,jz0);
729 dx11 = _mm_sub_ps(ix1,jx1);
730 dy11 = _mm_sub_ps(iy1,jy1);
731 dz11 = _mm_sub_ps(iz1,jz1);
732 dx12 = _mm_sub_ps(ix1,jx2);
733 dy12 = _mm_sub_ps(iy1,jy2);
734 dz12 = _mm_sub_ps(iz1,jz2);
735 dx13 = _mm_sub_ps(ix1,jx3);
736 dy13 = _mm_sub_ps(iy1,jy3);
737 dz13 = _mm_sub_ps(iz1,jz3);
738 dx21 = _mm_sub_ps(ix2,jx1);
739 dy21 = _mm_sub_ps(iy2,jy1);
740 dz21 = _mm_sub_ps(iz2,jz1);
741 dx22 = _mm_sub_ps(ix2,jx2);
742 dy22 = _mm_sub_ps(iy2,jy2);
743 dz22 = _mm_sub_ps(iz2,jz2);
744 dx23 = _mm_sub_ps(ix2,jx3);
745 dy23 = _mm_sub_ps(iy2,jy3);
746 dz23 = _mm_sub_ps(iz2,jz3);
747 dx31 = _mm_sub_ps(ix3,jx1);
748 dy31 = _mm_sub_ps(iy3,jy1);
749 dz31 = _mm_sub_ps(iz3,jz1);
750 dx32 = _mm_sub_ps(ix3,jx2);
751 dy32 = _mm_sub_ps(iy3,jy2);
752 dz32 = _mm_sub_ps(iz3,jz2);
753 dx33 = _mm_sub_ps(ix3,jx3);
754 dy33 = _mm_sub_ps(iy3,jy3);
755 dz33 = _mm_sub_ps(iz3,jz3);
757 /* Calculate squared distance and things based on it */
758 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
759 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
760 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
761 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
762 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
763 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
764 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
765 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
766 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
767 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
769 rinv11 = gmx_mm_invsqrt_ps(rsq11);
770 rinv12 = gmx_mm_invsqrt_ps(rsq12);
771 rinv13 = gmx_mm_invsqrt_ps(rsq13);
772 rinv21 = gmx_mm_invsqrt_ps(rsq21);
773 rinv22 = gmx_mm_invsqrt_ps(rsq22);
774 rinv23 = gmx_mm_invsqrt_ps(rsq23);
775 rinv31 = gmx_mm_invsqrt_ps(rsq31);
776 rinv32 = gmx_mm_invsqrt_ps(rsq32);
777 rinv33 = gmx_mm_invsqrt_ps(rsq33);
779 rinvsq00 = gmx_mm_inv_ps(rsq00);
780 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
781 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
782 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
783 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
784 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
785 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
786 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
787 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
788 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
790 fjx0 = _mm_setzero_ps();
791 fjy0 = _mm_setzero_ps();
792 fjz0 = _mm_setzero_ps();
793 fjx1 = _mm_setzero_ps();
794 fjy1 = _mm_setzero_ps();
795 fjz1 = _mm_setzero_ps();
796 fjx2 = _mm_setzero_ps();
797 fjy2 = _mm_setzero_ps();
798 fjz2 = _mm_setzero_ps();
799 fjx3 = _mm_setzero_ps();
800 fjy3 = _mm_setzero_ps();
801 fjz3 = _mm_setzero_ps();
803 /**************************
804 * CALCULATE INTERACTIONS *
805 **************************/
807 if (gmx_mm_any_lt(rsq00,rcutoff2))
810 /* LENNARD-JONES DISPERSION/REPULSION */
812 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
813 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
814 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
815 vvdw = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
816 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
817 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
819 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
821 /* Update potential sum for this i atom from the interaction with this j atom. */
822 vvdw = _mm_and_ps(vvdw,cutoff_mask);
823 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
824 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
828 fscal = _mm_and_ps(fscal,cutoff_mask);
830 fscal = _mm_andnot_ps(dummy_mask,fscal);
832 /* Calculate temporary vectorial force */
833 tx = _mm_mul_ps(fscal,dx00);
834 ty = _mm_mul_ps(fscal,dy00);
835 tz = _mm_mul_ps(fscal,dz00);
837 /* Update vectorial force */
838 fix0 = _mm_add_ps(fix0,tx);
839 fiy0 = _mm_add_ps(fiy0,ty);
840 fiz0 = _mm_add_ps(fiz0,tz);
842 fjx0 = _mm_add_ps(fjx0,tx);
843 fjy0 = _mm_add_ps(fjy0,ty);
844 fjz0 = _mm_add_ps(fjz0,tz);
848 /**************************
849 * CALCULATE INTERACTIONS *
850 **************************/
852 if (gmx_mm_any_lt(rsq11,rcutoff2))
855 /* REACTION-FIELD ELECTROSTATICS */
856 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
857 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
859 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
861 /* Update potential sum for this i atom from the interaction with this j atom. */
862 velec = _mm_and_ps(velec,cutoff_mask);
863 velec = _mm_andnot_ps(dummy_mask,velec);
864 velecsum = _mm_add_ps(velecsum,velec);
868 fscal = _mm_and_ps(fscal,cutoff_mask);
870 fscal = _mm_andnot_ps(dummy_mask,fscal);
872 /* Calculate temporary vectorial force */
873 tx = _mm_mul_ps(fscal,dx11);
874 ty = _mm_mul_ps(fscal,dy11);
875 tz = _mm_mul_ps(fscal,dz11);
877 /* Update vectorial force */
878 fix1 = _mm_add_ps(fix1,tx);
879 fiy1 = _mm_add_ps(fiy1,ty);
880 fiz1 = _mm_add_ps(fiz1,tz);
882 fjx1 = _mm_add_ps(fjx1,tx);
883 fjy1 = _mm_add_ps(fjy1,ty);
884 fjz1 = _mm_add_ps(fjz1,tz);
888 /**************************
889 * CALCULATE INTERACTIONS *
890 **************************/
892 if (gmx_mm_any_lt(rsq12,rcutoff2))
895 /* REACTION-FIELD ELECTROSTATICS */
896 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
897 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
899 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
901 /* Update potential sum for this i atom from the interaction with this j atom. */
902 velec = _mm_and_ps(velec,cutoff_mask);
903 velec = _mm_andnot_ps(dummy_mask,velec);
904 velecsum = _mm_add_ps(velecsum,velec);
908 fscal = _mm_and_ps(fscal,cutoff_mask);
910 fscal = _mm_andnot_ps(dummy_mask,fscal);
912 /* Calculate temporary vectorial force */
913 tx = _mm_mul_ps(fscal,dx12);
914 ty = _mm_mul_ps(fscal,dy12);
915 tz = _mm_mul_ps(fscal,dz12);
917 /* Update vectorial force */
918 fix1 = _mm_add_ps(fix1,tx);
919 fiy1 = _mm_add_ps(fiy1,ty);
920 fiz1 = _mm_add_ps(fiz1,tz);
922 fjx2 = _mm_add_ps(fjx2,tx);
923 fjy2 = _mm_add_ps(fjy2,ty);
924 fjz2 = _mm_add_ps(fjz2,tz);
928 /**************************
929 * CALCULATE INTERACTIONS *
930 **************************/
932 if (gmx_mm_any_lt(rsq13,rcutoff2))
935 /* REACTION-FIELD ELECTROSTATICS */
936 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
937 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
939 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
941 /* Update potential sum for this i atom from the interaction with this j atom. */
942 velec = _mm_and_ps(velec,cutoff_mask);
943 velec = _mm_andnot_ps(dummy_mask,velec);
944 velecsum = _mm_add_ps(velecsum,velec);
948 fscal = _mm_and_ps(fscal,cutoff_mask);
950 fscal = _mm_andnot_ps(dummy_mask,fscal);
952 /* Calculate temporary vectorial force */
953 tx = _mm_mul_ps(fscal,dx13);
954 ty = _mm_mul_ps(fscal,dy13);
955 tz = _mm_mul_ps(fscal,dz13);
957 /* Update vectorial force */
958 fix1 = _mm_add_ps(fix1,tx);
959 fiy1 = _mm_add_ps(fiy1,ty);
960 fiz1 = _mm_add_ps(fiz1,tz);
962 fjx3 = _mm_add_ps(fjx3,tx);
963 fjy3 = _mm_add_ps(fjy3,ty);
964 fjz3 = _mm_add_ps(fjz3,tz);
968 /**************************
969 * CALCULATE INTERACTIONS *
970 **************************/
972 if (gmx_mm_any_lt(rsq21,rcutoff2))
975 /* REACTION-FIELD ELECTROSTATICS */
976 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
977 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
979 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
981 /* Update potential sum for this i atom from the interaction with this j atom. */
982 velec = _mm_and_ps(velec,cutoff_mask);
983 velec = _mm_andnot_ps(dummy_mask,velec);
984 velecsum = _mm_add_ps(velecsum,velec);
988 fscal = _mm_and_ps(fscal,cutoff_mask);
990 fscal = _mm_andnot_ps(dummy_mask,fscal);
992 /* Calculate temporary vectorial force */
993 tx = _mm_mul_ps(fscal,dx21);
994 ty = _mm_mul_ps(fscal,dy21);
995 tz = _mm_mul_ps(fscal,dz21);
997 /* Update vectorial force */
998 fix2 = _mm_add_ps(fix2,tx);
999 fiy2 = _mm_add_ps(fiy2,ty);
1000 fiz2 = _mm_add_ps(fiz2,tz);
1002 fjx1 = _mm_add_ps(fjx1,tx);
1003 fjy1 = _mm_add_ps(fjy1,ty);
1004 fjz1 = _mm_add_ps(fjz1,tz);
1008 /**************************
1009 * CALCULATE INTERACTIONS *
1010 **************************/
1012 if (gmx_mm_any_lt(rsq22,rcutoff2))
1015 /* REACTION-FIELD ELECTROSTATICS */
1016 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1017 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1019 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1021 /* Update potential sum for this i atom from the interaction with this j atom. */
1022 velec = _mm_and_ps(velec,cutoff_mask);
1023 velec = _mm_andnot_ps(dummy_mask,velec);
1024 velecsum = _mm_add_ps(velecsum,velec);
1028 fscal = _mm_and_ps(fscal,cutoff_mask);
1030 fscal = _mm_andnot_ps(dummy_mask,fscal);
1032 /* Calculate temporary vectorial force */
1033 tx = _mm_mul_ps(fscal,dx22);
1034 ty = _mm_mul_ps(fscal,dy22);
1035 tz = _mm_mul_ps(fscal,dz22);
1037 /* Update vectorial force */
1038 fix2 = _mm_add_ps(fix2,tx);
1039 fiy2 = _mm_add_ps(fiy2,ty);
1040 fiz2 = _mm_add_ps(fiz2,tz);
1042 fjx2 = _mm_add_ps(fjx2,tx);
1043 fjy2 = _mm_add_ps(fjy2,ty);
1044 fjz2 = _mm_add_ps(fjz2,tz);
1048 /**************************
1049 * CALCULATE INTERACTIONS *
1050 **************************/
1052 if (gmx_mm_any_lt(rsq23,rcutoff2))
1055 /* REACTION-FIELD ELECTROSTATICS */
1056 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
1057 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1059 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1061 /* Update potential sum for this i atom from the interaction with this j atom. */
1062 velec = _mm_and_ps(velec,cutoff_mask);
1063 velec = _mm_andnot_ps(dummy_mask,velec);
1064 velecsum = _mm_add_ps(velecsum,velec);
1068 fscal = _mm_and_ps(fscal,cutoff_mask);
1070 fscal = _mm_andnot_ps(dummy_mask,fscal);
1072 /* Calculate temporary vectorial force */
1073 tx = _mm_mul_ps(fscal,dx23);
1074 ty = _mm_mul_ps(fscal,dy23);
1075 tz = _mm_mul_ps(fscal,dz23);
1077 /* Update vectorial force */
1078 fix2 = _mm_add_ps(fix2,tx);
1079 fiy2 = _mm_add_ps(fiy2,ty);
1080 fiz2 = _mm_add_ps(fiz2,tz);
1082 fjx3 = _mm_add_ps(fjx3,tx);
1083 fjy3 = _mm_add_ps(fjy3,ty);
1084 fjz3 = _mm_add_ps(fjz3,tz);
1088 /**************************
1089 * CALCULATE INTERACTIONS *
1090 **************************/
1092 if (gmx_mm_any_lt(rsq31,rcutoff2))
1095 /* REACTION-FIELD ELECTROSTATICS */
1096 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
1097 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1099 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1101 /* Update potential sum for this i atom from the interaction with this j atom. */
1102 velec = _mm_and_ps(velec,cutoff_mask);
1103 velec = _mm_andnot_ps(dummy_mask,velec);
1104 velecsum = _mm_add_ps(velecsum,velec);
1108 fscal = _mm_and_ps(fscal,cutoff_mask);
1110 fscal = _mm_andnot_ps(dummy_mask,fscal);
1112 /* Calculate temporary vectorial force */
1113 tx = _mm_mul_ps(fscal,dx31);
1114 ty = _mm_mul_ps(fscal,dy31);
1115 tz = _mm_mul_ps(fscal,dz31);
1117 /* Update vectorial force */
1118 fix3 = _mm_add_ps(fix3,tx);
1119 fiy3 = _mm_add_ps(fiy3,ty);
1120 fiz3 = _mm_add_ps(fiz3,tz);
1122 fjx1 = _mm_add_ps(fjx1,tx);
1123 fjy1 = _mm_add_ps(fjy1,ty);
1124 fjz1 = _mm_add_ps(fjz1,tz);
1128 /**************************
1129 * CALCULATE INTERACTIONS *
1130 **************************/
1132 if (gmx_mm_any_lt(rsq32,rcutoff2))
1135 /* REACTION-FIELD ELECTROSTATICS */
1136 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
1137 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1139 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1141 /* Update potential sum for this i atom from the interaction with this j atom. */
1142 velec = _mm_and_ps(velec,cutoff_mask);
1143 velec = _mm_andnot_ps(dummy_mask,velec);
1144 velecsum = _mm_add_ps(velecsum,velec);
1148 fscal = _mm_and_ps(fscal,cutoff_mask);
1150 fscal = _mm_andnot_ps(dummy_mask,fscal);
1152 /* Calculate temporary vectorial force */
1153 tx = _mm_mul_ps(fscal,dx32);
1154 ty = _mm_mul_ps(fscal,dy32);
1155 tz = _mm_mul_ps(fscal,dz32);
1157 /* Update vectorial force */
1158 fix3 = _mm_add_ps(fix3,tx);
1159 fiy3 = _mm_add_ps(fiy3,ty);
1160 fiz3 = _mm_add_ps(fiz3,tz);
1162 fjx2 = _mm_add_ps(fjx2,tx);
1163 fjy2 = _mm_add_ps(fjy2,ty);
1164 fjz2 = _mm_add_ps(fjz2,tz);
1168 /**************************
1169 * CALCULATE INTERACTIONS *
1170 **************************/
1172 if (gmx_mm_any_lt(rsq33,rcutoff2))
1175 /* REACTION-FIELD ELECTROSTATICS */
1176 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
1177 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1179 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1181 /* Update potential sum for this i atom from the interaction with this j atom. */
1182 velec = _mm_and_ps(velec,cutoff_mask);
1183 velec = _mm_andnot_ps(dummy_mask,velec);
1184 velecsum = _mm_add_ps(velecsum,velec);
1188 fscal = _mm_and_ps(fscal,cutoff_mask);
1190 fscal = _mm_andnot_ps(dummy_mask,fscal);
1192 /* Calculate temporary vectorial force */
1193 tx = _mm_mul_ps(fscal,dx33);
1194 ty = _mm_mul_ps(fscal,dy33);
1195 tz = _mm_mul_ps(fscal,dz33);
1197 /* Update vectorial force */
1198 fix3 = _mm_add_ps(fix3,tx);
1199 fiy3 = _mm_add_ps(fiy3,ty);
1200 fiz3 = _mm_add_ps(fiz3,tz);
1202 fjx3 = _mm_add_ps(fjx3,tx);
1203 fjy3 = _mm_add_ps(fjy3,ty);
1204 fjz3 = _mm_add_ps(fjz3,tz);
1208 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
1209 f+j_coord_offsetC,f+j_coord_offsetD,
1210 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1211 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1213 /* Inner loop uses 368 flops */
1216 /* End of innermost loop */
1218 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1219 f+i_coord_offset,fshift+i_shift_offset);
1222 /* Update potential energies */
1223 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1224 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1226 /* Increment number of inner iterations */
1227 inneriter += j_index_end - j_index_start;
1229 /* Outer loop uses 38 flops */
1232 /* Increment number of outer iterations */
1235 /* Update outer/inner flops */
1237 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*38 + inneriter*368);
1240 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_F_sse2_single
1241 * Electrostatics interaction: ReactionField
1242 * VdW interaction: LennardJones
1243 * Geometry: Water4-Water4
1244 * Calculate force/pot: Force
1247 nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_F_sse2_single
1248 (t_nblist * gmx_restrict nlist,
1249 rvec * gmx_restrict xx,
1250 rvec * gmx_restrict ff,
1251 t_forcerec * gmx_restrict fr,
1252 t_mdatoms * gmx_restrict mdatoms,
1253 nb_kernel_data_t * gmx_restrict kernel_data,
1254 t_nrnb * gmx_restrict nrnb)
1256 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1257 * just 0 for non-waters.
1258 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1259 * jnr indices corresponding to data put in the four positions in the SIMD register.
1261 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1262 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1263 int jnrA,jnrB,jnrC,jnrD;
1264 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1265 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1266 real shX,shY,shZ,rcutoff_scalar;
1267 real *shiftvec,*fshift,*x,*f;
1268 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1270 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1272 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1274 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1276 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1277 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1278 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1279 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1280 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1281 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1282 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1283 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1284 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1285 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1286 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1287 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1288 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1289 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1290 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1291 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1292 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1293 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1294 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1295 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1298 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1301 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1302 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1303 __m128 dummy_mask,cutoff_mask;
1304 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1305 __m128 one = _mm_set1_ps(1.0);
1306 __m128 two = _mm_set1_ps(2.0);
1312 jindex = nlist->jindex;
1314 shiftidx = nlist->shift;
1316 shiftvec = fr->shift_vec[0];
1317 fshift = fr->fshift[0];
1318 facel = _mm_set1_ps(fr->epsfac);
1319 charge = mdatoms->chargeA;
1320 krf = _mm_set1_ps(fr->ic->k_rf);
1321 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1322 crf = _mm_set1_ps(fr->ic->c_rf);
1323 nvdwtype = fr->ntype;
1324 vdwparam = fr->nbfp;
1325 vdwtype = mdatoms->typeA;
1327 /* Setup water-specific parameters */
1328 inr = nlist->iinr[0];
1329 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1330 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1331 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1332 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1334 jq1 = _mm_set1_ps(charge[inr+1]);
1335 jq2 = _mm_set1_ps(charge[inr+2]);
1336 jq3 = _mm_set1_ps(charge[inr+3]);
1337 vdwjidx0A = 2*vdwtype[inr+0];
1338 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1339 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1340 qq11 = _mm_mul_ps(iq1,jq1);
1341 qq12 = _mm_mul_ps(iq1,jq2);
1342 qq13 = _mm_mul_ps(iq1,jq3);
1343 qq21 = _mm_mul_ps(iq2,jq1);
1344 qq22 = _mm_mul_ps(iq2,jq2);
1345 qq23 = _mm_mul_ps(iq2,jq3);
1346 qq31 = _mm_mul_ps(iq3,jq1);
1347 qq32 = _mm_mul_ps(iq3,jq2);
1348 qq33 = _mm_mul_ps(iq3,jq3);
1350 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1351 rcutoff_scalar = fr->rcoulomb;
1352 rcutoff = _mm_set1_ps(rcutoff_scalar);
1353 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1355 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1356 rvdw = _mm_set1_ps(fr->rvdw);
1358 /* Avoid stupid compiler warnings */
1359 jnrA = jnrB = jnrC = jnrD = 0;
1360 j_coord_offsetA = 0;
1361 j_coord_offsetB = 0;
1362 j_coord_offsetC = 0;
1363 j_coord_offsetD = 0;
1368 /* Start outer loop over neighborlists */
1369 for(iidx=0; iidx<nri; iidx++)
1371 /* Load shift vector for this list */
1372 i_shift_offset = DIM*shiftidx[iidx];
1373 shX = shiftvec[i_shift_offset+XX];
1374 shY = shiftvec[i_shift_offset+YY];
1375 shZ = shiftvec[i_shift_offset+ZZ];
1377 /* Load limits for loop over neighbors */
1378 j_index_start = jindex[iidx];
1379 j_index_end = jindex[iidx+1];
1381 /* Get outer coordinate index */
1383 i_coord_offset = DIM*inr;
1385 /* Load i particle coords and add shift vector */
1386 ix0 = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
1387 iy0 = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
1388 iz0 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
1389 ix1 = _mm_set1_ps(shX + x[i_coord_offset+DIM*1+XX]);
1390 iy1 = _mm_set1_ps(shY + x[i_coord_offset+DIM*1+YY]);
1391 iz1 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*1+ZZ]);
1392 ix2 = _mm_set1_ps(shX + x[i_coord_offset+DIM*2+XX]);
1393 iy2 = _mm_set1_ps(shY + x[i_coord_offset+DIM*2+YY]);
1394 iz2 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*2+ZZ]);
1395 ix3 = _mm_set1_ps(shX + x[i_coord_offset+DIM*3+XX]);
1396 iy3 = _mm_set1_ps(shY + x[i_coord_offset+DIM*3+YY]);
1397 iz3 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*3+ZZ]);
1399 fix0 = _mm_setzero_ps();
1400 fiy0 = _mm_setzero_ps();
1401 fiz0 = _mm_setzero_ps();
1402 fix1 = _mm_setzero_ps();
1403 fiy1 = _mm_setzero_ps();
1404 fiz1 = _mm_setzero_ps();
1405 fix2 = _mm_setzero_ps();
1406 fiy2 = _mm_setzero_ps();
1407 fiz2 = _mm_setzero_ps();
1408 fix3 = _mm_setzero_ps();
1409 fiy3 = _mm_setzero_ps();
1410 fiz3 = _mm_setzero_ps();
1412 /* Start inner kernel loop */
1413 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1416 /* Get j neighbor index, and coordinate index */
1418 jnrB = jjnr[jidx+1];
1419 jnrC = jjnr[jidx+2];
1420 jnrD = jjnr[jidx+3];
1422 j_coord_offsetA = DIM*jnrA;
1423 j_coord_offsetB = DIM*jnrB;
1424 j_coord_offsetC = DIM*jnrC;
1425 j_coord_offsetD = DIM*jnrD;
1427 /* load j atom coordinates */
1428 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1429 x+j_coord_offsetC,x+j_coord_offsetD,
1430 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1431 &jy2,&jz2,&jx3,&jy3,&jz3);
1433 /* Calculate displacement vector */
1434 dx00 = _mm_sub_ps(ix0,jx0);
1435 dy00 = _mm_sub_ps(iy0,jy0);
1436 dz00 = _mm_sub_ps(iz0,jz0);
1437 dx11 = _mm_sub_ps(ix1,jx1);
1438 dy11 = _mm_sub_ps(iy1,jy1);
1439 dz11 = _mm_sub_ps(iz1,jz1);
1440 dx12 = _mm_sub_ps(ix1,jx2);
1441 dy12 = _mm_sub_ps(iy1,jy2);
1442 dz12 = _mm_sub_ps(iz1,jz2);
1443 dx13 = _mm_sub_ps(ix1,jx3);
1444 dy13 = _mm_sub_ps(iy1,jy3);
1445 dz13 = _mm_sub_ps(iz1,jz3);
1446 dx21 = _mm_sub_ps(ix2,jx1);
1447 dy21 = _mm_sub_ps(iy2,jy1);
1448 dz21 = _mm_sub_ps(iz2,jz1);
1449 dx22 = _mm_sub_ps(ix2,jx2);
1450 dy22 = _mm_sub_ps(iy2,jy2);
1451 dz22 = _mm_sub_ps(iz2,jz2);
1452 dx23 = _mm_sub_ps(ix2,jx3);
1453 dy23 = _mm_sub_ps(iy2,jy3);
1454 dz23 = _mm_sub_ps(iz2,jz3);
1455 dx31 = _mm_sub_ps(ix3,jx1);
1456 dy31 = _mm_sub_ps(iy3,jy1);
1457 dz31 = _mm_sub_ps(iz3,jz1);
1458 dx32 = _mm_sub_ps(ix3,jx2);
1459 dy32 = _mm_sub_ps(iy3,jy2);
1460 dz32 = _mm_sub_ps(iz3,jz2);
1461 dx33 = _mm_sub_ps(ix3,jx3);
1462 dy33 = _mm_sub_ps(iy3,jy3);
1463 dz33 = _mm_sub_ps(iz3,jz3);
1465 /* Calculate squared distance and things based on it */
1466 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1467 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1468 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1469 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1470 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1471 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1472 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1473 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1474 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1475 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1477 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1478 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1479 rinv13 = gmx_mm_invsqrt_ps(rsq13);
1480 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1481 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1482 rinv23 = gmx_mm_invsqrt_ps(rsq23);
1483 rinv31 = gmx_mm_invsqrt_ps(rsq31);
1484 rinv32 = gmx_mm_invsqrt_ps(rsq32);
1485 rinv33 = gmx_mm_invsqrt_ps(rsq33);
1487 rinvsq00 = gmx_mm_inv_ps(rsq00);
1488 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1489 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1490 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1491 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1492 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1493 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1494 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1495 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1496 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1498 fjx0 = _mm_setzero_ps();
1499 fjy0 = _mm_setzero_ps();
1500 fjz0 = _mm_setzero_ps();
1501 fjx1 = _mm_setzero_ps();
1502 fjy1 = _mm_setzero_ps();
1503 fjz1 = _mm_setzero_ps();
1504 fjx2 = _mm_setzero_ps();
1505 fjy2 = _mm_setzero_ps();
1506 fjz2 = _mm_setzero_ps();
1507 fjx3 = _mm_setzero_ps();
1508 fjy3 = _mm_setzero_ps();
1509 fjz3 = _mm_setzero_ps();
1511 /**************************
1512 * CALCULATE INTERACTIONS *
1513 **************************/
1515 if (gmx_mm_any_lt(rsq00,rcutoff2))
1518 /* LENNARD-JONES DISPERSION/REPULSION */
1520 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1521 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1523 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1527 fscal = _mm_and_ps(fscal,cutoff_mask);
1529 /* Calculate temporary vectorial force */
1530 tx = _mm_mul_ps(fscal,dx00);
1531 ty = _mm_mul_ps(fscal,dy00);
1532 tz = _mm_mul_ps(fscal,dz00);
1534 /* Update vectorial force */
1535 fix0 = _mm_add_ps(fix0,tx);
1536 fiy0 = _mm_add_ps(fiy0,ty);
1537 fiz0 = _mm_add_ps(fiz0,tz);
1539 fjx0 = _mm_add_ps(fjx0,tx);
1540 fjy0 = _mm_add_ps(fjy0,ty);
1541 fjz0 = _mm_add_ps(fjz0,tz);
1545 /**************************
1546 * CALCULATE INTERACTIONS *
1547 **************************/
1549 if (gmx_mm_any_lt(rsq11,rcutoff2))
1552 /* REACTION-FIELD ELECTROSTATICS */
1553 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1555 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1559 fscal = _mm_and_ps(fscal,cutoff_mask);
1561 /* Calculate temporary vectorial force */
1562 tx = _mm_mul_ps(fscal,dx11);
1563 ty = _mm_mul_ps(fscal,dy11);
1564 tz = _mm_mul_ps(fscal,dz11);
1566 /* Update vectorial force */
1567 fix1 = _mm_add_ps(fix1,tx);
1568 fiy1 = _mm_add_ps(fiy1,ty);
1569 fiz1 = _mm_add_ps(fiz1,tz);
1571 fjx1 = _mm_add_ps(fjx1,tx);
1572 fjy1 = _mm_add_ps(fjy1,ty);
1573 fjz1 = _mm_add_ps(fjz1,tz);
1577 /**************************
1578 * CALCULATE INTERACTIONS *
1579 **************************/
1581 if (gmx_mm_any_lt(rsq12,rcutoff2))
1584 /* REACTION-FIELD ELECTROSTATICS */
1585 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1587 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1591 fscal = _mm_and_ps(fscal,cutoff_mask);
1593 /* Calculate temporary vectorial force */
1594 tx = _mm_mul_ps(fscal,dx12);
1595 ty = _mm_mul_ps(fscal,dy12);
1596 tz = _mm_mul_ps(fscal,dz12);
1598 /* Update vectorial force */
1599 fix1 = _mm_add_ps(fix1,tx);
1600 fiy1 = _mm_add_ps(fiy1,ty);
1601 fiz1 = _mm_add_ps(fiz1,tz);
1603 fjx2 = _mm_add_ps(fjx2,tx);
1604 fjy2 = _mm_add_ps(fjy2,ty);
1605 fjz2 = _mm_add_ps(fjz2,tz);
1609 /**************************
1610 * CALCULATE INTERACTIONS *
1611 **************************/
1613 if (gmx_mm_any_lt(rsq13,rcutoff2))
1616 /* REACTION-FIELD ELECTROSTATICS */
1617 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
1619 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1623 fscal = _mm_and_ps(fscal,cutoff_mask);
1625 /* Calculate temporary vectorial force */
1626 tx = _mm_mul_ps(fscal,dx13);
1627 ty = _mm_mul_ps(fscal,dy13);
1628 tz = _mm_mul_ps(fscal,dz13);
1630 /* Update vectorial force */
1631 fix1 = _mm_add_ps(fix1,tx);
1632 fiy1 = _mm_add_ps(fiy1,ty);
1633 fiz1 = _mm_add_ps(fiz1,tz);
1635 fjx3 = _mm_add_ps(fjx3,tx);
1636 fjy3 = _mm_add_ps(fjy3,ty);
1637 fjz3 = _mm_add_ps(fjz3,tz);
1641 /**************************
1642 * CALCULATE INTERACTIONS *
1643 **************************/
1645 if (gmx_mm_any_lt(rsq21,rcutoff2))
1648 /* REACTION-FIELD ELECTROSTATICS */
1649 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1651 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1655 fscal = _mm_and_ps(fscal,cutoff_mask);
1657 /* Calculate temporary vectorial force */
1658 tx = _mm_mul_ps(fscal,dx21);
1659 ty = _mm_mul_ps(fscal,dy21);
1660 tz = _mm_mul_ps(fscal,dz21);
1662 /* Update vectorial force */
1663 fix2 = _mm_add_ps(fix2,tx);
1664 fiy2 = _mm_add_ps(fiy2,ty);
1665 fiz2 = _mm_add_ps(fiz2,tz);
1667 fjx1 = _mm_add_ps(fjx1,tx);
1668 fjy1 = _mm_add_ps(fjy1,ty);
1669 fjz1 = _mm_add_ps(fjz1,tz);
1673 /**************************
1674 * CALCULATE INTERACTIONS *
1675 **************************/
1677 if (gmx_mm_any_lt(rsq22,rcutoff2))
1680 /* REACTION-FIELD ELECTROSTATICS */
1681 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1683 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1687 fscal = _mm_and_ps(fscal,cutoff_mask);
1689 /* Calculate temporary vectorial force */
1690 tx = _mm_mul_ps(fscal,dx22);
1691 ty = _mm_mul_ps(fscal,dy22);
1692 tz = _mm_mul_ps(fscal,dz22);
1694 /* Update vectorial force */
1695 fix2 = _mm_add_ps(fix2,tx);
1696 fiy2 = _mm_add_ps(fiy2,ty);
1697 fiz2 = _mm_add_ps(fiz2,tz);
1699 fjx2 = _mm_add_ps(fjx2,tx);
1700 fjy2 = _mm_add_ps(fjy2,ty);
1701 fjz2 = _mm_add_ps(fjz2,tz);
1705 /**************************
1706 * CALCULATE INTERACTIONS *
1707 **************************/
1709 if (gmx_mm_any_lt(rsq23,rcutoff2))
1712 /* REACTION-FIELD ELECTROSTATICS */
1713 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1715 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1719 fscal = _mm_and_ps(fscal,cutoff_mask);
1721 /* Calculate temporary vectorial force */
1722 tx = _mm_mul_ps(fscal,dx23);
1723 ty = _mm_mul_ps(fscal,dy23);
1724 tz = _mm_mul_ps(fscal,dz23);
1726 /* Update vectorial force */
1727 fix2 = _mm_add_ps(fix2,tx);
1728 fiy2 = _mm_add_ps(fiy2,ty);
1729 fiz2 = _mm_add_ps(fiz2,tz);
1731 fjx3 = _mm_add_ps(fjx3,tx);
1732 fjy3 = _mm_add_ps(fjy3,ty);
1733 fjz3 = _mm_add_ps(fjz3,tz);
1737 /**************************
1738 * CALCULATE INTERACTIONS *
1739 **************************/
1741 if (gmx_mm_any_lt(rsq31,rcutoff2))
1744 /* REACTION-FIELD ELECTROSTATICS */
1745 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1747 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1751 fscal = _mm_and_ps(fscal,cutoff_mask);
1753 /* Calculate temporary vectorial force */
1754 tx = _mm_mul_ps(fscal,dx31);
1755 ty = _mm_mul_ps(fscal,dy31);
1756 tz = _mm_mul_ps(fscal,dz31);
1758 /* Update vectorial force */
1759 fix3 = _mm_add_ps(fix3,tx);
1760 fiy3 = _mm_add_ps(fiy3,ty);
1761 fiz3 = _mm_add_ps(fiz3,tz);
1763 fjx1 = _mm_add_ps(fjx1,tx);
1764 fjy1 = _mm_add_ps(fjy1,ty);
1765 fjz1 = _mm_add_ps(fjz1,tz);
1769 /**************************
1770 * CALCULATE INTERACTIONS *
1771 **************************/
1773 if (gmx_mm_any_lt(rsq32,rcutoff2))
1776 /* REACTION-FIELD ELECTROSTATICS */
1777 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1779 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1783 fscal = _mm_and_ps(fscal,cutoff_mask);
1785 /* Calculate temporary vectorial force */
1786 tx = _mm_mul_ps(fscal,dx32);
1787 ty = _mm_mul_ps(fscal,dy32);
1788 tz = _mm_mul_ps(fscal,dz32);
1790 /* Update vectorial force */
1791 fix3 = _mm_add_ps(fix3,tx);
1792 fiy3 = _mm_add_ps(fiy3,ty);
1793 fiz3 = _mm_add_ps(fiz3,tz);
1795 fjx2 = _mm_add_ps(fjx2,tx);
1796 fjy2 = _mm_add_ps(fjy2,ty);
1797 fjz2 = _mm_add_ps(fjz2,tz);
1801 /**************************
1802 * CALCULATE INTERACTIONS *
1803 **************************/
1805 if (gmx_mm_any_lt(rsq33,rcutoff2))
1808 /* REACTION-FIELD ELECTROSTATICS */
1809 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1811 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1815 fscal = _mm_and_ps(fscal,cutoff_mask);
1817 /* Calculate temporary vectorial force */
1818 tx = _mm_mul_ps(fscal,dx33);
1819 ty = _mm_mul_ps(fscal,dy33);
1820 tz = _mm_mul_ps(fscal,dz33);
1822 /* Update vectorial force */
1823 fix3 = _mm_add_ps(fix3,tx);
1824 fiy3 = _mm_add_ps(fiy3,ty);
1825 fiz3 = _mm_add_ps(fiz3,tz);
1827 fjx3 = _mm_add_ps(fjx3,tx);
1828 fjy3 = _mm_add_ps(fjy3,ty);
1829 fjz3 = _mm_add_ps(fjz3,tz);
1833 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
1834 f+j_coord_offsetC,f+j_coord_offsetD,
1835 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1836 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1838 /* Inner loop uses 303 flops */
1841 if(jidx<j_index_end)
1844 /* Get j neighbor index, and coordinate index */
1846 jnrB = jjnr[jidx+1];
1847 jnrC = jjnr[jidx+2];
1848 jnrD = jjnr[jidx+3];
1850 /* Sign of each element will be negative for non-real atoms.
1851 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1852 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1854 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1855 jnrA = (jnrA>=0) ? jnrA : 0;
1856 jnrB = (jnrB>=0) ? jnrB : 0;
1857 jnrC = (jnrC>=0) ? jnrC : 0;
1858 jnrD = (jnrD>=0) ? jnrD : 0;
1860 j_coord_offsetA = DIM*jnrA;
1861 j_coord_offsetB = DIM*jnrB;
1862 j_coord_offsetC = DIM*jnrC;
1863 j_coord_offsetD = DIM*jnrD;
1865 /* load j atom coordinates */
1866 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1867 x+j_coord_offsetC,x+j_coord_offsetD,
1868 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1869 &jy2,&jz2,&jx3,&jy3,&jz3);
1871 /* Calculate displacement vector */
1872 dx00 = _mm_sub_ps(ix0,jx0);
1873 dy00 = _mm_sub_ps(iy0,jy0);
1874 dz00 = _mm_sub_ps(iz0,jz0);
1875 dx11 = _mm_sub_ps(ix1,jx1);
1876 dy11 = _mm_sub_ps(iy1,jy1);
1877 dz11 = _mm_sub_ps(iz1,jz1);
1878 dx12 = _mm_sub_ps(ix1,jx2);
1879 dy12 = _mm_sub_ps(iy1,jy2);
1880 dz12 = _mm_sub_ps(iz1,jz2);
1881 dx13 = _mm_sub_ps(ix1,jx3);
1882 dy13 = _mm_sub_ps(iy1,jy3);
1883 dz13 = _mm_sub_ps(iz1,jz3);
1884 dx21 = _mm_sub_ps(ix2,jx1);
1885 dy21 = _mm_sub_ps(iy2,jy1);
1886 dz21 = _mm_sub_ps(iz2,jz1);
1887 dx22 = _mm_sub_ps(ix2,jx2);
1888 dy22 = _mm_sub_ps(iy2,jy2);
1889 dz22 = _mm_sub_ps(iz2,jz2);
1890 dx23 = _mm_sub_ps(ix2,jx3);
1891 dy23 = _mm_sub_ps(iy2,jy3);
1892 dz23 = _mm_sub_ps(iz2,jz3);
1893 dx31 = _mm_sub_ps(ix3,jx1);
1894 dy31 = _mm_sub_ps(iy3,jy1);
1895 dz31 = _mm_sub_ps(iz3,jz1);
1896 dx32 = _mm_sub_ps(ix3,jx2);
1897 dy32 = _mm_sub_ps(iy3,jy2);
1898 dz32 = _mm_sub_ps(iz3,jz2);
1899 dx33 = _mm_sub_ps(ix3,jx3);
1900 dy33 = _mm_sub_ps(iy3,jy3);
1901 dz33 = _mm_sub_ps(iz3,jz3);
1903 /* Calculate squared distance and things based on it */
1904 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1905 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1906 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1907 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1908 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1909 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1910 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1911 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1912 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1913 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1915 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1916 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1917 rinv13 = gmx_mm_invsqrt_ps(rsq13);
1918 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1919 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1920 rinv23 = gmx_mm_invsqrt_ps(rsq23);
1921 rinv31 = gmx_mm_invsqrt_ps(rsq31);
1922 rinv32 = gmx_mm_invsqrt_ps(rsq32);
1923 rinv33 = gmx_mm_invsqrt_ps(rsq33);
1925 rinvsq00 = gmx_mm_inv_ps(rsq00);
1926 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1927 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1928 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1929 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1930 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1931 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1932 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1933 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1934 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1936 fjx0 = _mm_setzero_ps();
1937 fjy0 = _mm_setzero_ps();
1938 fjz0 = _mm_setzero_ps();
1939 fjx1 = _mm_setzero_ps();
1940 fjy1 = _mm_setzero_ps();
1941 fjz1 = _mm_setzero_ps();
1942 fjx2 = _mm_setzero_ps();
1943 fjy2 = _mm_setzero_ps();
1944 fjz2 = _mm_setzero_ps();
1945 fjx3 = _mm_setzero_ps();
1946 fjy3 = _mm_setzero_ps();
1947 fjz3 = _mm_setzero_ps();
1949 /**************************
1950 * CALCULATE INTERACTIONS *
1951 **************************/
1953 if (gmx_mm_any_lt(rsq00,rcutoff2))
1956 /* LENNARD-JONES DISPERSION/REPULSION */
1958 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1959 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1961 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1965 fscal = _mm_and_ps(fscal,cutoff_mask);
1967 fscal = _mm_andnot_ps(dummy_mask,fscal);
1969 /* Calculate temporary vectorial force */
1970 tx = _mm_mul_ps(fscal,dx00);
1971 ty = _mm_mul_ps(fscal,dy00);
1972 tz = _mm_mul_ps(fscal,dz00);
1974 /* Update vectorial force */
1975 fix0 = _mm_add_ps(fix0,tx);
1976 fiy0 = _mm_add_ps(fiy0,ty);
1977 fiz0 = _mm_add_ps(fiz0,tz);
1979 fjx0 = _mm_add_ps(fjx0,tx);
1980 fjy0 = _mm_add_ps(fjy0,ty);
1981 fjz0 = _mm_add_ps(fjz0,tz);
1985 /**************************
1986 * CALCULATE INTERACTIONS *
1987 **************************/
1989 if (gmx_mm_any_lt(rsq11,rcutoff2))
1992 /* REACTION-FIELD ELECTROSTATICS */
1993 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1995 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1999 fscal = _mm_and_ps(fscal,cutoff_mask);
2001 fscal = _mm_andnot_ps(dummy_mask,fscal);
2003 /* Calculate temporary vectorial force */
2004 tx = _mm_mul_ps(fscal,dx11);
2005 ty = _mm_mul_ps(fscal,dy11);
2006 tz = _mm_mul_ps(fscal,dz11);
2008 /* Update vectorial force */
2009 fix1 = _mm_add_ps(fix1,tx);
2010 fiy1 = _mm_add_ps(fiy1,ty);
2011 fiz1 = _mm_add_ps(fiz1,tz);
2013 fjx1 = _mm_add_ps(fjx1,tx);
2014 fjy1 = _mm_add_ps(fjy1,ty);
2015 fjz1 = _mm_add_ps(fjz1,tz);
2019 /**************************
2020 * CALCULATE INTERACTIONS *
2021 **************************/
2023 if (gmx_mm_any_lt(rsq12,rcutoff2))
2026 /* REACTION-FIELD ELECTROSTATICS */
2027 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
2029 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
2033 fscal = _mm_and_ps(fscal,cutoff_mask);
2035 fscal = _mm_andnot_ps(dummy_mask,fscal);
2037 /* Calculate temporary vectorial force */
2038 tx = _mm_mul_ps(fscal,dx12);
2039 ty = _mm_mul_ps(fscal,dy12);
2040 tz = _mm_mul_ps(fscal,dz12);
2042 /* Update vectorial force */
2043 fix1 = _mm_add_ps(fix1,tx);
2044 fiy1 = _mm_add_ps(fiy1,ty);
2045 fiz1 = _mm_add_ps(fiz1,tz);
2047 fjx2 = _mm_add_ps(fjx2,tx);
2048 fjy2 = _mm_add_ps(fjy2,ty);
2049 fjz2 = _mm_add_ps(fjz2,tz);
2053 /**************************
2054 * CALCULATE INTERACTIONS *
2055 **************************/
2057 if (gmx_mm_any_lt(rsq13,rcutoff2))
2060 /* REACTION-FIELD ELECTROSTATICS */
2061 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
2063 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
2067 fscal = _mm_and_ps(fscal,cutoff_mask);
2069 fscal = _mm_andnot_ps(dummy_mask,fscal);
2071 /* Calculate temporary vectorial force */
2072 tx = _mm_mul_ps(fscal,dx13);
2073 ty = _mm_mul_ps(fscal,dy13);
2074 tz = _mm_mul_ps(fscal,dz13);
2076 /* Update vectorial force */
2077 fix1 = _mm_add_ps(fix1,tx);
2078 fiy1 = _mm_add_ps(fiy1,ty);
2079 fiz1 = _mm_add_ps(fiz1,tz);
2081 fjx3 = _mm_add_ps(fjx3,tx);
2082 fjy3 = _mm_add_ps(fjy3,ty);
2083 fjz3 = _mm_add_ps(fjz3,tz);
2087 /**************************
2088 * CALCULATE INTERACTIONS *
2089 **************************/
2091 if (gmx_mm_any_lt(rsq21,rcutoff2))
2094 /* REACTION-FIELD ELECTROSTATICS */
2095 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
2097 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
2101 fscal = _mm_and_ps(fscal,cutoff_mask);
2103 fscal = _mm_andnot_ps(dummy_mask,fscal);
2105 /* Calculate temporary vectorial force */
2106 tx = _mm_mul_ps(fscal,dx21);
2107 ty = _mm_mul_ps(fscal,dy21);
2108 tz = _mm_mul_ps(fscal,dz21);
2110 /* Update vectorial force */
2111 fix2 = _mm_add_ps(fix2,tx);
2112 fiy2 = _mm_add_ps(fiy2,ty);
2113 fiz2 = _mm_add_ps(fiz2,tz);
2115 fjx1 = _mm_add_ps(fjx1,tx);
2116 fjy1 = _mm_add_ps(fjy1,ty);
2117 fjz1 = _mm_add_ps(fjz1,tz);
2121 /**************************
2122 * CALCULATE INTERACTIONS *
2123 **************************/
2125 if (gmx_mm_any_lt(rsq22,rcutoff2))
2128 /* REACTION-FIELD ELECTROSTATICS */
2129 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2131 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
2135 fscal = _mm_and_ps(fscal,cutoff_mask);
2137 fscal = _mm_andnot_ps(dummy_mask,fscal);
2139 /* Calculate temporary vectorial force */
2140 tx = _mm_mul_ps(fscal,dx22);
2141 ty = _mm_mul_ps(fscal,dy22);
2142 tz = _mm_mul_ps(fscal,dz22);
2144 /* Update vectorial force */
2145 fix2 = _mm_add_ps(fix2,tx);
2146 fiy2 = _mm_add_ps(fiy2,ty);
2147 fiz2 = _mm_add_ps(fiz2,tz);
2149 fjx2 = _mm_add_ps(fjx2,tx);
2150 fjy2 = _mm_add_ps(fjy2,ty);
2151 fjz2 = _mm_add_ps(fjz2,tz);
2155 /**************************
2156 * CALCULATE INTERACTIONS *
2157 **************************/
2159 if (gmx_mm_any_lt(rsq23,rcutoff2))
2162 /* REACTION-FIELD ELECTROSTATICS */
2163 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
2165 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
2169 fscal = _mm_and_ps(fscal,cutoff_mask);
2171 fscal = _mm_andnot_ps(dummy_mask,fscal);
2173 /* Calculate temporary vectorial force */
2174 tx = _mm_mul_ps(fscal,dx23);
2175 ty = _mm_mul_ps(fscal,dy23);
2176 tz = _mm_mul_ps(fscal,dz23);
2178 /* Update vectorial force */
2179 fix2 = _mm_add_ps(fix2,tx);
2180 fiy2 = _mm_add_ps(fiy2,ty);
2181 fiz2 = _mm_add_ps(fiz2,tz);
2183 fjx3 = _mm_add_ps(fjx3,tx);
2184 fjy3 = _mm_add_ps(fjy3,ty);
2185 fjz3 = _mm_add_ps(fjz3,tz);
2189 /**************************
2190 * CALCULATE INTERACTIONS *
2191 **************************/
2193 if (gmx_mm_any_lt(rsq31,rcutoff2))
2196 /* REACTION-FIELD ELECTROSTATICS */
2197 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
2199 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
2203 fscal = _mm_and_ps(fscal,cutoff_mask);
2205 fscal = _mm_andnot_ps(dummy_mask,fscal);
2207 /* Calculate temporary vectorial force */
2208 tx = _mm_mul_ps(fscal,dx31);
2209 ty = _mm_mul_ps(fscal,dy31);
2210 tz = _mm_mul_ps(fscal,dz31);
2212 /* Update vectorial force */
2213 fix3 = _mm_add_ps(fix3,tx);
2214 fiy3 = _mm_add_ps(fiy3,ty);
2215 fiz3 = _mm_add_ps(fiz3,tz);
2217 fjx1 = _mm_add_ps(fjx1,tx);
2218 fjy1 = _mm_add_ps(fjy1,ty);
2219 fjz1 = _mm_add_ps(fjz1,tz);
2223 /**************************
2224 * CALCULATE INTERACTIONS *
2225 **************************/
2227 if (gmx_mm_any_lt(rsq32,rcutoff2))
2230 /* REACTION-FIELD ELECTROSTATICS */
2231 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
2233 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
2237 fscal = _mm_and_ps(fscal,cutoff_mask);
2239 fscal = _mm_andnot_ps(dummy_mask,fscal);
2241 /* Calculate temporary vectorial force */
2242 tx = _mm_mul_ps(fscal,dx32);
2243 ty = _mm_mul_ps(fscal,dy32);
2244 tz = _mm_mul_ps(fscal,dz32);
2246 /* Update vectorial force */
2247 fix3 = _mm_add_ps(fix3,tx);
2248 fiy3 = _mm_add_ps(fiy3,ty);
2249 fiz3 = _mm_add_ps(fiz3,tz);
2251 fjx2 = _mm_add_ps(fjx2,tx);
2252 fjy2 = _mm_add_ps(fjy2,ty);
2253 fjz2 = _mm_add_ps(fjz2,tz);
2257 /**************************
2258 * CALCULATE INTERACTIONS *
2259 **************************/
2261 if (gmx_mm_any_lt(rsq33,rcutoff2))
2264 /* REACTION-FIELD ELECTROSTATICS */
2265 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
2267 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
2271 fscal = _mm_and_ps(fscal,cutoff_mask);
2273 fscal = _mm_andnot_ps(dummy_mask,fscal);
2275 /* Calculate temporary vectorial force */
2276 tx = _mm_mul_ps(fscal,dx33);
2277 ty = _mm_mul_ps(fscal,dy33);
2278 tz = _mm_mul_ps(fscal,dz33);
2280 /* Update vectorial force */
2281 fix3 = _mm_add_ps(fix3,tx);
2282 fiy3 = _mm_add_ps(fiy3,ty);
2283 fiz3 = _mm_add_ps(fiz3,tz);
2285 fjx3 = _mm_add_ps(fjx3,tx);
2286 fjy3 = _mm_add_ps(fjy3,ty);
2287 fjz3 = _mm_add_ps(fjz3,tz);
2291 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
2292 f+j_coord_offsetC,f+j_coord_offsetD,
2293 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2294 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2296 /* Inner loop uses 303 flops */
2299 /* End of innermost loop */
2301 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2302 f+i_coord_offset,fshift+i_shift_offset);
2304 /* Increment number of inner iterations */
2305 inneriter += j_index_end - j_index_start;
2307 /* Outer loop uses 36 flops */
2310 /* Increment number of outer iterations */
2313 /* Update outer/inner flops */
2315 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*36 + inneriter*303);