2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_sse2_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Water3
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_sse2_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
91 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
93 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
96 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
97 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
98 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
99 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
100 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
101 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
102 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
103 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
106 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
109 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
110 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
111 __m128 dummy_mask,cutoff_mask;
112 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
113 __m128 one = _mm_set1_ps(1.0);
114 __m128 two = _mm_set1_ps(2.0);
120 jindex = nlist->jindex;
122 shiftidx = nlist->shift;
124 shiftvec = fr->shift_vec[0];
125 fshift = fr->fshift[0];
126 facel = _mm_set1_ps(fr->ic->epsfac);
127 charge = mdatoms->chargeA;
128 krf = _mm_set1_ps(fr->ic->k_rf);
129 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
130 crf = _mm_set1_ps(fr->ic->c_rf);
131 nvdwtype = fr->ntype;
133 vdwtype = mdatoms->typeA;
135 /* Setup water-specific parameters */
136 inr = nlist->iinr[0];
137 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
138 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
139 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
140 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
142 jq0 = _mm_set1_ps(charge[inr+0]);
143 jq1 = _mm_set1_ps(charge[inr+1]);
144 jq2 = _mm_set1_ps(charge[inr+2]);
145 vdwjidx0A = 2*vdwtype[inr+0];
146 qq00 = _mm_mul_ps(iq0,jq0);
147 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
148 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
149 qq01 = _mm_mul_ps(iq0,jq1);
150 qq02 = _mm_mul_ps(iq0,jq2);
151 qq10 = _mm_mul_ps(iq1,jq0);
152 qq11 = _mm_mul_ps(iq1,jq1);
153 qq12 = _mm_mul_ps(iq1,jq2);
154 qq20 = _mm_mul_ps(iq2,jq0);
155 qq21 = _mm_mul_ps(iq2,jq1);
156 qq22 = _mm_mul_ps(iq2,jq2);
158 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
159 rcutoff_scalar = fr->ic->rcoulomb;
160 rcutoff = _mm_set1_ps(rcutoff_scalar);
161 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
163 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
164 rvdw = _mm_set1_ps(fr->ic->rvdw);
166 /* Avoid stupid compiler warnings */
167 jnrA = jnrB = jnrC = jnrD = 0;
176 for(iidx=0;iidx<4*DIM;iidx++)
181 /* Start outer loop over neighborlists */
182 for(iidx=0; iidx<nri; iidx++)
184 /* Load shift vector for this list */
185 i_shift_offset = DIM*shiftidx[iidx];
187 /* Load limits for loop over neighbors */
188 j_index_start = jindex[iidx];
189 j_index_end = jindex[iidx+1];
191 /* Get outer coordinate index */
193 i_coord_offset = DIM*inr;
195 /* Load i particle coords and add shift vector */
196 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
197 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
199 fix0 = _mm_setzero_ps();
200 fiy0 = _mm_setzero_ps();
201 fiz0 = _mm_setzero_ps();
202 fix1 = _mm_setzero_ps();
203 fiy1 = _mm_setzero_ps();
204 fiz1 = _mm_setzero_ps();
205 fix2 = _mm_setzero_ps();
206 fiy2 = _mm_setzero_ps();
207 fiz2 = _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 */
222 j_coord_offsetA = DIM*jnrA;
223 j_coord_offsetB = DIM*jnrB;
224 j_coord_offsetC = DIM*jnrC;
225 j_coord_offsetD = DIM*jnrD;
227 /* load j atom coordinates */
228 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
229 x+j_coord_offsetC,x+j_coord_offsetD,
230 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
232 /* Calculate displacement vector */
233 dx00 = _mm_sub_ps(ix0,jx0);
234 dy00 = _mm_sub_ps(iy0,jy0);
235 dz00 = _mm_sub_ps(iz0,jz0);
236 dx01 = _mm_sub_ps(ix0,jx1);
237 dy01 = _mm_sub_ps(iy0,jy1);
238 dz01 = _mm_sub_ps(iz0,jz1);
239 dx02 = _mm_sub_ps(ix0,jx2);
240 dy02 = _mm_sub_ps(iy0,jy2);
241 dz02 = _mm_sub_ps(iz0,jz2);
242 dx10 = _mm_sub_ps(ix1,jx0);
243 dy10 = _mm_sub_ps(iy1,jy0);
244 dz10 = _mm_sub_ps(iz1,jz0);
245 dx11 = _mm_sub_ps(ix1,jx1);
246 dy11 = _mm_sub_ps(iy1,jy1);
247 dz11 = _mm_sub_ps(iz1,jz1);
248 dx12 = _mm_sub_ps(ix1,jx2);
249 dy12 = _mm_sub_ps(iy1,jy2);
250 dz12 = _mm_sub_ps(iz1,jz2);
251 dx20 = _mm_sub_ps(ix2,jx0);
252 dy20 = _mm_sub_ps(iy2,jy0);
253 dz20 = _mm_sub_ps(iz2,jz0);
254 dx21 = _mm_sub_ps(ix2,jx1);
255 dy21 = _mm_sub_ps(iy2,jy1);
256 dz21 = _mm_sub_ps(iz2,jz1);
257 dx22 = _mm_sub_ps(ix2,jx2);
258 dy22 = _mm_sub_ps(iy2,jy2);
259 dz22 = _mm_sub_ps(iz2,jz2);
261 /* Calculate squared distance and things based on it */
262 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
263 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
264 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
265 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
266 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
267 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
268 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
269 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
270 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
272 rinv00 = sse2_invsqrt_f(rsq00);
273 rinv01 = sse2_invsqrt_f(rsq01);
274 rinv02 = sse2_invsqrt_f(rsq02);
275 rinv10 = sse2_invsqrt_f(rsq10);
276 rinv11 = sse2_invsqrt_f(rsq11);
277 rinv12 = sse2_invsqrt_f(rsq12);
278 rinv20 = sse2_invsqrt_f(rsq20);
279 rinv21 = sse2_invsqrt_f(rsq21);
280 rinv22 = sse2_invsqrt_f(rsq22);
282 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
283 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
284 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
285 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
286 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
287 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
288 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
289 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
290 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
292 fjx0 = _mm_setzero_ps();
293 fjy0 = _mm_setzero_ps();
294 fjz0 = _mm_setzero_ps();
295 fjx1 = _mm_setzero_ps();
296 fjy1 = _mm_setzero_ps();
297 fjz1 = _mm_setzero_ps();
298 fjx2 = _mm_setzero_ps();
299 fjy2 = _mm_setzero_ps();
300 fjz2 = _mm_setzero_ps();
302 /**************************
303 * CALCULATE INTERACTIONS *
304 **************************/
306 if (gmx_mm_any_lt(rsq00,rcutoff2))
309 /* REACTION-FIELD ELECTROSTATICS */
310 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
311 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
313 /* LENNARD-JONES DISPERSION/REPULSION */
315 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
316 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
317 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
318 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) ,
319 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
320 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
322 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
324 /* Update potential sum for this i atom from the interaction with this j atom. */
325 velec = _mm_and_ps(velec,cutoff_mask);
326 velecsum = _mm_add_ps(velecsum,velec);
327 vvdw = _mm_and_ps(vvdw,cutoff_mask);
328 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
330 fscal = _mm_add_ps(felec,fvdw);
332 fscal = _mm_and_ps(fscal,cutoff_mask);
334 /* Calculate temporary vectorial force */
335 tx = _mm_mul_ps(fscal,dx00);
336 ty = _mm_mul_ps(fscal,dy00);
337 tz = _mm_mul_ps(fscal,dz00);
339 /* Update vectorial force */
340 fix0 = _mm_add_ps(fix0,tx);
341 fiy0 = _mm_add_ps(fiy0,ty);
342 fiz0 = _mm_add_ps(fiz0,tz);
344 fjx0 = _mm_add_ps(fjx0,tx);
345 fjy0 = _mm_add_ps(fjy0,ty);
346 fjz0 = _mm_add_ps(fjz0,tz);
350 /**************************
351 * CALCULATE INTERACTIONS *
352 **************************/
354 if (gmx_mm_any_lt(rsq01,rcutoff2))
357 /* REACTION-FIELD ELECTROSTATICS */
358 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
359 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
361 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
363 /* Update potential sum for this i atom from the interaction with this j atom. */
364 velec = _mm_and_ps(velec,cutoff_mask);
365 velecsum = _mm_add_ps(velecsum,velec);
369 fscal = _mm_and_ps(fscal,cutoff_mask);
371 /* Calculate temporary vectorial force */
372 tx = _mm_mul_ps(fscal,dx01);
373 ty = _mm_mul_ps(fscal,dy01);
374 tz = _mm_mul_ps(fscal,dz01);
376 /* Update vectorial force */
377 fix0 = _mm_add_ps(fix0,tx);
378 fiy0 = _mm_add_ps(fiy0,ty);
379 fiz0 = _mm_add_ps(fiz0,tz);
381 fjx1 = _mm_add_ps(fjx1,tx);
382 fjy1 = _mm_add_ps(fjy1,ty);
383 fjz1 = _mm_add_ps(fjz1,tz);
387 /**************************
388 * CALCULATE INTERACTIONS *
389 **************************/
391 if (gmx_mm_any_lt(rsq02,rcutoff2))
394 /* REACTION-FIELD ELECTROSTATICS */
395 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
396 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
398 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
400 /* Update potential sum for this i atom from the interaction with this j atom. */
401 velec = _mm_and_ps(velec,cutoff_mask);
402 velecsum = _mm_add_ps(velecsum,velec);
406 fscal = _mm_and_ps(fscal,cutoff_mask);
408 /* Calculate temporary vectorial force */
409 tx = _mm_mul_ps(fscal,dx02);
410 ty = _mm_mul_ps(fscal,dy02);
411 tz = _mm_mul_ps(fscal,dz02);
413 /* Update vectorial force */
414 fix0 = _mm_add_ps(fix0,tx);
415 fiy0 = _mm_add_ps(fiy0,ty);
416 fiz0 = _mm_add_ps(fiz0,tz);
418 fjx2 = _mm_add_ps(fjx2,tx);
419 fjy2 = _mm_add_ps(fjy2,ty);
420 fjz2 = _mm_add_ps(fjz2,tz);
424 /**************************
425 * CALCULATE INTERACTIONS *
426 **************************/
428 if (gmx_mm_any_lt(rsq10,rcutoff2))
431 /* REACTION-FIELD ELECTROSTATICS */
432 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
433 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
435 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
437 /* Update potential sum for this i atom from the interaction with this j atom. */
438 velec = _mm_and_ps(velec,cutoff_mask);
439 velecsum = _mm_add_ps(velecsum,velec);
443 fscal = _mm_and_ps(fscal,cutoff_mask);
445 /* Calculate temporary vectorial force */
446 tx = _mm_mul_ps(fscal,dx10);
447 ty = _mm_mul_ps(fscal,dy10);
448 tz = _mm_mul_ps(fscal,dz10);
450 /* Update vectorial force */
451 fix1 = _mm_add_ps(fix1,tx);
452 fiy1 = _mm_add_ps(fiy1,ty);
453 fiz1 = _mm_add_ps(fiz1,tz);
455 fjx0 = _mm_add_ps(fjx0,tx);
456 fjy0 = _mm_add_ps(fjy0,ty);
457 fjz0 = _mm_add_ps(fjz0,tz);
461 /**************************
462 * CALCULATE INTERACTIONS *
463 **************************/
465 if (gmx_mm_any_lt(rsq11,rcutoff2))
468 /* REACTION-FIELD ELECTROSTATICS */
469 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
470 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
472 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
474 /* Update potential sum for this i atom from the interaction with this j atom. */
475 velec = _mm_and_ps(velec,cutoff_mask);
476 velecsum = _mm_add_ps(velecsum,velec);
480 fscal = _mm_and_ps(fscal,cutoff_mask);
482 /* Calculate temporary vectorial force */
483 tx = _mm_mul_ps(fscal,dx11);
484 ty = _mm_mul_ps(fscal,dy11);
485 tz = _mm_mul_ps(fscal,dz11);
487 /* Update vectorial force */
488 fix1 = _mm_add_ps(fix1,tx);
489 fiy1 = _mm_add_ps(fiy1,ty);
490 fiz1 = _mm_add_ps(fiz1,tz);
492 fjx1 = _mm_add_ps(fjx1,tx);
493 fjy1 = _mm_add_ps(fjy1,ty);
494 fjz1 = _mm_add_ps(fjz1,tz);
498 /**************************
499 * CALCULATE INTERACTIONS *
500 **************************/
502 if (gmx_mm_any_lt(rsq12,rcutoff2))
505 /* REACTION-FIELD ELECTROSTATICS */
506 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
507 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
509 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
511 /* Update potential sum for this i atom from the interaction with this j atom. */
512 velec = _mm_and_ps(velec,cutoff_mask);
513 velecsum = _mm_add_ps(velecsum,velec);
517 fscal = _mm_and_ps(fscal,cutoff_mask);
519 /* Calculate temporary vectorial force */
520 tx = _mm_mul_ps(fscal,dx12);
521 ty = _mm_mul_ps(fscal,dy12);
522 tz = _mm_mul_ps(fscal,dz12);
524 /* Update vectorial force */
525 fix1 = _mm_add_ps(fix1,tx);
526 fiy1 = _mm_add_ps(fiy1,ty);
527 fiz1 = _mm_add_ps(fiz1,tz);
529 fjx2 = _mm_add_ps(fjx2,tx);
530 fjy2 = _mm_add_ps(fjy2,ty);
531 fjz2 = _mm_add_ps(fjz2,tz);
535 /**************************
536 * CALCULATE INTERACTIONS *
537 **************************/
539 if (gmx_mm_any_lt(rsq20,rcutoff2))
542 /* REACTION-FIELD ELECTROSTATICS */
543 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
544 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
546 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
548 /* Update potential sum for this i atom from the interaction with this j atom. */
549 velec = _mm_and_ps(velec,cutoff_mask);
550 velecsum = _mm_add_ps(velecsum,velec);
554 fscal = _mm_and_ps(fscal,cutoff_mask);
556 /* Calculate temporary vectorial force */
557 tx = _mm_mul_ps(fscal,dx20);
558 ty = _mm_mul_ps(fscal,dy20);
559 tz = _mm_mul_ps(fscal,dz20);
561 /* Update vectorial force */
562 fix2 = _mm_add_ps(fix2,tx);
563 fiy2 = _mm_add_ps(fiy2,ty);
564 fiz2 = _mm_add_ps(fiz2,tz);
566 fjx0 = _mm_add_ps(fjx0,tx);
567 fjy0 = _mm_add_ps(fjy0,ty);
568 fjz0 = _mm_add_ps(fjz0,tz);
572 /**************************
573 * CALCULATE INTERACTIONS *
574 **************************/
576 if (gmx_mm_any_lt(rsq21,rcutoff2))
579 /* REACTION-FIELD ELECTROSTATICS */
580 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
581 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
583 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
585 /* Update potential sum for this i atom from the interaction with this j atom. */
586 velec = _mm_and_ps(velec,cutoff_mask);
587 velecsum = _mm_add_ps(velecsum,velec);
591 fscal = _mm_and_ps(fscal,cutoff_mask);
593 /* Calculate temporary vectorial force */
594 tx = _mm_mul_ps(fscal,dx21);
595 ty = _mm_mul_ps(fscal,dy21);
596 tz = _mm_mul_ps(fscal,dz21);
598 /* Update vectorial force */
599 fix2 = _mm_add_ps(fix2,tx);
600 fiy2 = _mm_add_ps(fiy2,ty);
601 fiz2 = _mm_add_ps(fiz2,tz);
603 fjx1 = _mm_add_ps(fjx1,tx);
604 fjy1 = _mm_add_ps(fjy1,ty);
605 fjz1 = _mm_add_ps(fjz1,tz);
609 /**************************
610 * CALCULATE INTERACTIONS *
611 **************************/
613 if (gmx_mm_any_lt(rsq22,rcutoff2))
616 /* REACTION-FIELD ELECTROSTATICS */
617 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
618 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
620 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
622 /* Update potential sum for this i atom from the interaction with this j atom. */
623 velec = _mm_and_ps(velec,cutoff_mask);
624 velecsum = _mm_add_ps(velecsum,velec);
628 fscal = _mm_and_ps(fscal,cutoff_mask);
630 /* Calculate temporary vectorial force */
631 tx = _mm_mul_ps(fscal,dx22);
632 ty = _mm_mul_ps(fscal,dy22);
633 tz = _mm_mul_ps(fscal,dz22);
635 /* Update vectorial force */
636 fix2 = _mm_add_ps(fix2,tx);
637 fiy2 = _mm_add_ps(fiy2,ty);
638 fiz2 = _mm_add_ps(fiz2,tz);
640 fjx2 = _mm_add_ps(fjx2,tx);
641 fjy2 = _mm_add_ps(fjy2,ty);
642 fjz2 = _mm_add_ps(fjz2,tz);
646 fjptrA = f+j_coord_offsetA;
647 fjptrB = f+j_coord_offsetB;
648 fjptrC = f+j_coord_offsetC;
649 fjptrD = f+j_coord_offsetD;
651 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
652 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
654 /* Inner loop uses 342 flops */
660 /* Get j neighbor index, and coordinate index */
661 jnrlistA = jjnr[jidx];
662 jnrlistB = jjnr[jidx+1];
663 jnrlistC = jjnr[jidx+2];
664 jnrlistD = jjnr[jidx+3];
665 /* Sign of each element will be negative for non-real atoms.
666 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
667 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
669 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
670 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
671 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
672 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
673 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
674 j_coord_offsetA = DIM*jnrA;
675 j_coord_offsetB = DIM*jnrB;
676 j_coord_offsetC = DIM*jnrC;
677 j_coord_offsetD = DIM*jnrD;
679 /* load j atom coordinates */
680 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
681 x+j_coord_offsetC,x+j_coord_offsetD,
682 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
684 /* Calculate displacement vector */
685 dx00 = _mm_sub_ps(ix0,jx0);
686 dy00 = _mm_sub_ps(iy0,jy0);
687 dz00 = _mm_sub_ps(iz0,jz0);
688 dx01 = _mm_sub_ps(ix0,jx1);
689 dy01 = _mm_sub_ps(iy0,jy1);
690 dz01 = _mm_sub_ps(iz0,jz1);
691 dx02 = _mm_sub_ps(ix0,jx2);
692 dy02 = _mm_sub_ps(iy0,jy2);
693 dz02 = _mm_sub_ps(iz0,jz2);
694 dx10 = _mm_sub_ps(ix1,jx0);
695 dy10 = _mm_sub_ps(iy1,jy0);
696 dz10 = _mm_sub_ps(iz1,jz0);
697 dx11 = _mm_sub_ps(ix1,jx1);
698 dy11 = _mm_sub_ps(iy1,jy1);
699 dz11 = _mm_sub_ps(iz1,jz1);
700 dx12 = _mm_sub_ps(ix1,jx2);
701 dy12 = _mm_sub_ps(iy1,jy2);
702 dz12 = _mm_sub_ps(iz1,jz2);
703 dx20 = _mm_sub_ps(ix2,jx0);
704 dy20 = _mm_sub_ps(iy2,jy0);
705 dz20 = _mm_sub_ps(iz2,jz0);
706 dx21 = _mm_sub_ps(ix2,jx1);
707 dy21 = _mm_sub_ps(iy2,jy1);
708 dz21 = _mm_sub_ps(iz2,jz1);
709 dx22 = _mm_sub_ps(ix2,jx2);
710 dy22 = _mm_sub_ps(iy2,jy2);
711 dz22 = _mm_sub_ps(iz2,jz2);
713 /* Calculate squared distance and things based on it */
714 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
715 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
716 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
717 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
718 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
719 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
720 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
721 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
722 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
724 rinv00 = sse2_invsqrt_f(rsq00);
725 rinv01 = sse2_invsqrt_f(rsq01);
726 rinv02 = sse2_invsqrt_f(rsq02);
727 rinv10 = sse2_invsqrt_f(rsq10);
728 rinv11 = sse2_invsqrt_f(rsq11);
729 rinv12 = sse2_invsqrt_f(rsq12);
730 rinv20 = sse2_invsqrt_f(rsq20);
731 rinv21 = sse2_invsqrt_f(rsq21);
732 rinv22 = sse2_invsqrt_f(rsq22);
734 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
735 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
736 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
737 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
738 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
739 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
740 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
741 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
742 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
744 fjx0 = _mm_setzero_ps();
745 fjy0 = _mm_setzero_ps();
746 fjz0 = _mm_setzero_ps();
747 fjx1 = _mm_setzero_ps();
748 fjy1 = _mm_setzero_ps();
749 fjz1 = _mm_setzero_ps();
750 fjx2 = _mm_setzero_ps();
751 fjy2 = _mm_setzero_ps();
752 fjz2 = _mm_setzero_ps();
754 /**************************
755 * CALCULATE INTERACTIONS *
756 **************************/
758 if (gmx_mm_any_lt(rsq00,rcutoff2))
761 /* REACTION-FIELD ELECTROSTATICS */
762 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
763 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
765 /* LENNARD-JONES DISPERSION/REPULSION */
767 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
768 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
769 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
770 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) ,
771 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
772 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
774 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
776 /* Update potential sum for this i atom from the interaction with this j atom. */
777 velec = _mm_and_ps(velec,cutoff_mask);
778 velec = _mm_andnot_ps(dummy_mask,velec);
779 velecsum = _mm_add_ps(velecsum,velec);
780 vvdw = _mm_and_ps(vvdw,cutoff_mask);
781 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
782 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
784 fscal = _mm_add_ps(felec,fvdw);
786 fscal = _mm_and_ps(fscal,cutoff_mask);
788 fscal = _mm_andnot_ps(dummy_mask,fscal);
790 /* Calculate temporary vectorial force */
791 tx = _mm_mul_ps(fscal,dx00);
792 ty = _mm_mul_ps(fscal,dy00);
793 tz = _mm_mul_ps(fscal,dz00);
795 /* Update vectorial force */
796 fix0 = _mm_add_ps(fix0,tx);
797 fiy0 = _mm_add_ps(fiy0,ty);
798 fiz0 = _mm_add_ps(fiz0,tz);
800 fjx0 = _mm_add_ps(fjx0,tx);
801 fjy0 = _mm_add_ps(fjy0,ty);
802 fjz0 = _mm_add_ps(fjz0,tz);
806 /**************************
807 * CALCULATE INTERACTIONS *
808 **************************/
810 if (gmx_mm_any_lt(rsq01,rcutoff2))
813 /* REACTION-FIELD ELECTROSTATICS */
814 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
815 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
817 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
819 /* Update potential sum for this i atom from the interaction with this j atom. */
820 velec = _mm_and_ps(velec,cutoff_mask);
821 velec = _mm_andnot_ps(dummy_mask,velec);
822 velecsum = _mm_add_ps(velecsum,velec);
826 fscal = _mm_and_ps(fscal,cutoff_mask);
828 fscal = _mm_andnot_ps(dummy_mask,fscal);
830 /* Calculate temporary vectorial force */
831 tx = _mm_mul_ps(fscal,dx01);
832 ty = _mm_mul_ps(fscal,dy01);
833 tz = _mm_mul_ps(fscal,dz01);
835 /* Update vectorial force */
836 fix0 = _mm_add_ps(fix0,tx);
837 fiy0 = _mm_add_ps(fiy0,ty);
838 fiz0 = _mm_add_ps(fiz0,tz);
840 fjx1 = _mm_add_ps(fjx1,tx);
841 fjy1 = _mm_add_ps(fjy1,ty);
842 fjz1 = _mm_add_ps(fjz1,tz);
846 /**************************
847 * CALCULATE INTERACTIONS *
848 **************************/
850 if (gmx_mm_any_lt(rsq02,rcutoff2))
853 /* REACTION-FIELD ELECTROSTATICS */
854 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
855 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
857 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
859 /* Update potential sum for this i atom from the interaction with this j atom. */
860 velec = _mm_and_ps(velec,cutoff_mask);
861 velec = _mm_andnot_ps(dummy_mask,velec);
862 velecsum = _mm_add_ps(velecsum,velec);
866 fscal = _mm_and_ps(fscal,cutoff_mask);
868 fscal = _mm_andnot_ps(dummy_mask,fscal);
870 /* Calculate temporary vectorial force */
871 tx = _mm_mul_ps(fscal,dx02);
872 ty = _mm_mul_ps(fscal,dy02);
873 tz = _mm_mul_ps(fscal,dz02);
875 /* Update vectorial force */
876 fix0 = _mm_add_ps(fix0,tx);
877 fiy0 = _mm_add_ps(fiy0,ty);
878 fiz0 = _mm_add_ps(fiz0,tz);
880 fjx2 = _mm_add_ps(fjx2,tx);
881 fjy2 = _mm_add_ps(fjy2,ty);
882 fjz2 = _mm_add_ps(fjz2,tz);
886 /**************************
887 * CALCULATE INTERACTIONS *
888 **************************/
890 if (gmx_mm_any_lt(rsq10,rcutoff2))
893 /* REACTION-FIELD ELECTROSTATICS */
894 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
895 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
897 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
899 /* Update potential sum for this i atom from the interaction with this j atom. */
900 velec = _mm_and_ps(velec,cutoff_mask);
901 velec = _mm_andnot_ps(dummy_mask,velec);
902 velecsum = _mm_add_ps(velecsum,velec);
906 fscal = _mm_and_ps(fscal,cutoff_mask);
908 fscal = _mm_andnot_ps(dummy_mask,fscal);
910 /* Calculate temporary vectorial force */
911 tx = _mm_mul_ps(fscal,dx10);
912 ty = _mm_mul_ps(fscal,dy10);
913 tz = _mm_mul_ps(fscal,dz10);
915 /* Update vectorial force */
916 fix1 = _mm_add_ps(fix1,tx);
917 fiy1 = _mm_add_ps(fiy1,ty);
918 fiz1 = _mm_add_ps(fiz1,tz);
920 fjx0 = _mm_add_ps(fjx0,tx);
921 fjy0 = _mm_add_ps(fjy0,ty);
922 fjz0 = _mm_add_ps(fjz0,tz);
926 /**************************
927 * CALCULATE INTERACTIONS *
928 **************************/
930 if (gmx_mm_any_lt(rsq11,rcutoff2))
933 /* REACTION-FIELD ELECTROSTATICS */
934 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
935 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
937 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
939 /* Update potential sum for this i atom from the interaction with this j atom. */
940 velec = _mm_and_ps(velec,cutoff_mask);
941 velec = _mm_andnot_ps(dummy_mask,velec);
942 velecsum = _mm_add_ps(velecsum,velec);
946 fscal = _mm_and_ps(fscal,cutoff_mask);
948 fscal = _mm_andnot_ps(dummy_mask,fscal);
950 /* Calculate temporary vectorial force */
951 tx = _mm_mul_ps(fscal,dx11);
952 ty = _mm_mul_ps(fscal,dy11);
953 tz = _mm_mul_ps(fscal,dz11);
955 /* Update vectorial force */
956 fix1 = _mm_add_ps(fix1,tx);
957 fiy1 = _mm_add_ps(fiy1,ty);
958 fiz1 = _mm_add_ps(fiz1,tz);
960 fjx1 = _mm_add_ps(fjx1,tx);
961 fjy1 = _mm_add_ps(fjy1,ty);
962 fjz1 = _mm_add_ps(fjz1,tz);
966 /**************************
967 * CALCULATE INTERACTIONS *
968 **************************/
970 if (gmx_mm_any_lt(rsq12,rcutoff2))
973 /* REACTION-FIELD ELECTROSTATICS */
974 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
975 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
977 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
979 /* Update potential sum for this i atom from the interaction with this j atom. */
980 velec = _mm_and_ps(velec,cutoff_mask);
981 velec = _mm_andnot_ps(dummy_mask,velec);
982 velecsum = _mm_add_ps(velecsum,velec);
986 fscal = _mm_and_ps(fscal,cutoff_mask);
988 fscal = _mm_andnot_ps(dummy_mask,fscal);
990 /* Calculate temporary vectorial force */
991 tx = _mm_mul_ps(fscal,dx12);
992 ty = _mm_mul_ps(fscal,dy12);
993 tz = _mm_mul_ps(fscal,dz12);
995 /* Update vectorial force */
996 fix1 = _mm_add_ps(fix1,tx);
997 fiy1 = _mm_add_ps(fiy1,ty);
998 fiz1 = _mm_add_ps(fiz1,tz);
1000 fjx2 = _mm_add_ps(fjx2,tx);
1001 fjy2 = _mm_add_ps(fjy2,ty);
1002 fjz2 = _mm_add_ps(fjz2,tz);
1006 /**************************
1007 * CALCULATE INTERACTIONS *
1008 **************************/
1010 if (gmx_mm_any_lt(rsq20,rcutoff2))
1013 /* REACTION-FIELD ELECTROSTATICS */
1014 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
1015 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1017 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1019 /* Update potential sum for this i atom from the interaction with this j atom. */
1020 velec = _mm_and_ps(velec,cutoff_mask);
1021 velec = _mm_andnot_ps(dummy_mask,velec);
1022 velecsum = _mm_add_ps(velecsum,velec);
1026 fscal = _mm_and_ps(fscal,cutoff_mask);
1028 fscal = _mm_andnot_ps(dummy_mask,fscal);
1030 /* Calculate temporary vectorial force */
1031 tx = _mm_mul_ps(fscal,dx20);
1032 ty = _mm_mul_ps(fscal,dy20);
1033 tz = _mm_mul_ps(fscal,dz20);
1035 /* Update vectorial force */
1036 fix2 = _mm_add_ps(fix2,tx);
1037 fiy2 = _mm_add_ps(fiy2,ty);
1038 fiz2 = _mm_add_ps(fiz2,tz);
1040 fjx0 = _mm_add_ps(fjx0,tx);
1041 fjy0 = _mm_add_ps(fjy0,ty);
1042 fjz0 = _mm_add_ps(fjz0,tz);
1046 /**************************
1047 * CALCULATE INTERACTIONS *
1048 **************************/
1050 if (gmx_mm_any_lt(rsq21,rcutoff2))
1053 /* REACTION-FIELD ELECTROSTATICS */
1054 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
1055 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1057 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1059 /* Update potential sum for this i atom from the interaction with this j atom. */
1060 velec = _mm_and_ps(velec,cutoff_mask);
1061 velec = _mm_andnot_ps(dummy_mask,velec);
1062 velecsum = _mm_add_ps(velecsum,velec);
1066 fscal = _mm_and_ps(fscal,cutoff_mask);
1068 fscal = _mm_andnot_ps(dummy_mask,fscal);
1070 /* Calculate temporary vectorial force */
1071 tx = _mm_mul_ps(fscal,dx21);
1072 ty = _mm_mul_ps(fscal,dy21);
1073 tz = _mm_mul_ps(fscal,dz21);
1075 /* Update vectorial force */
1076 fix2 = _mm_add_ps(fix2,tx);
1077 fiy2 = _mm_add_ps(fiy2,ty);
1078 fiz2 = _mm_add_ps(fiz2,tz);
1080 fjx1 = _mm_add_ps(fjx1,tx);
1081 fjy1 = _mm_add_ps(fjy1,ty);
1082 fjz1 = _mm_add_ps(fjz1,tz);
1086 /**************************
1087 * CALCULATE INTERACTIONS *
1088 **************************/
1090 if (gmx_mm_any_lt(rsq22,rcutoff2))
1093 /* REACTION-FIELD ELECTROSTATICS */
1094 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1095 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1097 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1099 /* Update potential sum for this i atom from the interaction with this j atom. */
1100 velec = _mm_and_ps(velec,cutoff_mask);
1101 velec = _mm_andnot_ps(dummy_mask,velec);
1102 velecsum = _mm_add_ps(velecsum,velec);
1106 fscal = _mm_and_ps(fscal,cutoff_mask);
1108 fscal = _mm_andnot_ps(dummy_mask,fscal);
1110 /* Calculate temporary vectorial force */
1111 tx = _mm_mul_ps(fscal,dx22);
1112 ty = _mm_mul_ps(fscal,dy22);
1113 tz = _mm_mul_ps(fscal,dz22);
1115 /* Update vectorial force */
1116 fix2 = _mm_add_ps(fix2,tx);
1117 fiy2 = _mm_add_ps(fiy2,ty);
1118 fiz2 = _mm_add_ps(fiz2,tz);
1120 fjx2 = _mm_add_ps(fjx2,tx);
1121 fjy2 = _mm_add_ps(fjy2,ty);
1122 fjz2 = _mm_add_ps(fjz2,tz);
1126 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1127 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1128 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1129 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1131 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1132 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1134 /* Inner loop uses 342 flops */
1137 /* End of innermost loop */
1139 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1140 f+i_coord_offset,fshift+i_shift_offset);
1143 /* Update potential energies */
1144 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1145 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1147 /* Increment number of inner iterations */
1148 inneriter += j_index_end - j_index_start;
1150 /* Outer loop uses 20 flops */
1153 /* Increment number of outer iterations */
1156 /* Update outer/inner flops */
1158 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*342);
1161 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_sse2_single
1162 * Electrostatics interaction: ReactionField
1163 * VdW interaction: LennardJones
1164 * Geometry: Water3-Water3
1165 * Calculate force/pot: Force
1168 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_sse2_single
1169 (t_nblist * gmx_restrict nlist,
1170 rvec * gmx_restrict xx,
1171 rvec * gmx_restrict ff,
1172 struct t_forcerec * gmx_restrict fr,
1173 t_mdatoms * gmx_restrict mdatoms,
1174 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1175 t_nrnb * gmx_restrict nrnb)
1177 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1178 * just 0 for non-waters.
1179 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1180 * jnr indices corresponding to data put in the four positions in the SIMD register.
1182 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1183 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1184 int jnrA,jnrB,jnrC,jnrD;
1185 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1186 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1187 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1188 real rcutoff_scalar;
1189 real *shiftvec,*fshift,*x,*f;
1190 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1191 real scratch[4*DIM];
1192 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1194 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1196 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1198 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1199 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1200 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1201 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1202 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1203 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1204 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1205 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1206 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1207 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1208 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1209 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1210 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1211 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1212 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1213 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1214 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1217 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1220 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1221 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1222 __m128 dummy_mask,cutoff_mask;
1223 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1224 __m128 one = _mm_set1_ps(1.0);
1225 __m128 two = _mm_set1_ps(2.0);
1231 jindex = nlist->jindex;
1233 shiftidx = nlist->shift;
1235 shiftvec = fr->shift_vec[0];
1236 fshift = fr->fshift[0];
1237 facel = _mm_set1_ps(fr->ic->epsfac);
1238 charge = mdatoms->chargeA;
1239 krf = _mm_set1_ps(fr->ic->k_rf);
1240 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1241 crf = _mm_set1_ps(fr->ic->c_rf);
1242 nvdwtype = fr->ntype;
1243 vdwparam = fr->nbfp;
1244 vdwtype = mdatoms->typeA;
1246 /* Setup water-specific parameters */
1247 inr = nlist->iinr[0];
1248 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1249 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1250 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1251 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1253 jq0 = _mm_set1_ps(charge[inr+0]);
1254 jq1 = _mm_set1_ps(charge[inr+1]);
1255 jq2 = _mm_set1_ps(charge[inr+2]);
1256 vdwjidx0A = 2*vdwtype[inr+0];
1257 qq00 = _mm_mul_ps(iq0,jq0);
1258 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1259 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1260 qq01 = _mm_mul_ps(iq0,jq1);
1261 qq02 = _mm_mul_ps(iq0,jq2);
1262 qq10 = _mm_mul_ps(iq1,jq0);
1263 qq11 = _mm_mul_ps(iq1,jq1);
1264 qq12 = _mm_mul_ps(iq1,jq2);
1265 qq20 = _mm_mul_ps(iq2,jq0);
1266 qq21 = _mm_mul_ps(iq2,jq1);
1267 qq22 = _mm_mul_ps(iq2,jq2);
1269 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1270 rcutoff_scalar = fr->ic->rcoulomb;
1271 rcutoff = _mm_set1_ps(rcutoff_scalar);
1272 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1274 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1275 rvdw = _mm_set1_ps(fr->ic->rvdw);
1277 /* Avoid stupid compiler warnings */
1278 jnrA = jnrB = jnrC = jnrD = 0;
1279 j_coord_offsetA = 0;
1280 j_coord_offsetB = 0;
1281 j_coord_offsetC = 0;
1282 j_coord_offsetD = 0;
1287 for(iidx=0;iidx<4*DIM;iidx++)
1289 scratch[iidx] = 0.0;
1292 /* Start outer loop over neighborlists */
1293 for(iidx=0; iidx<nri; iidx++)
1295 /* Load shift vector for this list */
1296 i_shift_offset = DIM*shiftidx[iidx];
1298 /* Load limits for loop over neighbors */
1299 j_index_start = jindex[iidx];
1300 j_index_end = jindex[iidx+1];
1302 /* Get outer coordinate index */
1304 i_coord_offset = DIM*inr;
1306 /* Load i particle coords and add shift vector */
1307 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1308 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1310 fix0 = _mm_setzero_ps();
1311 fiy0 = _mm_setzero_ps();
1312 fiz0 = _mm_setzero_ps();
1313 fix1 = _mm_setzero_ps();
1314 fiy1 = _mm_setzero_ps();
1315 fiz1 = _mm_setzero_ps();
1316 fix2 = _mm_setzero_ps();
1317 fiy2 = _mm_setzero_ps();
1318 fiz2 = _mm_setzero_ps();
1320 /* Start inner kernel loop */
1321 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1324 /* Get j neighbor index, and coordinate index */
1326 jnrB = jjnr[jidx+1];
1327 jnrC = jjnr[jidx+2];
1328 jnrD = jjnr[jidx+3];
1329 j_coord_offsetA = DIM*jnrA;
1330 j_coord_offsetB = DIM*jnrB;
1331 j_coord_offsetC = DIM*jnrC;
1332 j_coord_offsetD = DIM*jnrD;
1334 /* load j atom coordinates */
1335 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1336 x+j_coord_offsetC,x+j_coord_offsetD,
1337 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1339 /* Calculate displacement vector */
1340 dx00 = _mm_sub_ps(ix0,jx0);
1341 dy00 = _mm_sub_ps(iy0,jy0);
1342 dz00 = _mm_sub_ps(iz0,jz0);
1343 dx01 = _mm_sub_ps(ix0,jx1);
1344 dy01 = _mm_sub_ps(iy0,jy1);
1345 dz01 = _mm_sub_ps(iz0,jz1);
1346 dx02 = _mm_sub_ps(ix0,jx2);
1347 dy02 = _mm_sub_ps(iy0,jy2);
1348 dz02 = _mm_sub_ps(iz0,jz2);
1349 dx10 = _mm_sub_ps(ix1,jx0);
1350 dy10 = _mm_sub_ps(iy1,jy0);
1351 dz10 = _mm_sub_ps(iz1,jz0);
1352 dx11 = _mm_sub_ps(ix1,jx1);
1353 dy11 = _mm_sub_ps(iy1,jy1);
1354 dz11 = _mm_sub_ps(iz1,jz1);
1355 dx12 = _mm_sub_ps(ix1,jx2);
1356 dy12 = _mm_sub_ps(iy1,jy2);
1357 dz12 = _mm_sub_ps(iz1,jz2);
1358 dx20 = _mm_sub_ps(ix2,jx0);
1359 dy20 = _mm_sub_ps(iy2,jy0);
1360 dz20 = _mm_sub_ps(iz2,jz0);
1361 dx21 = _mm_sub_ps(ix2,jx1);
1362 dy21 = _mm_sub_ps(iy2,jy1);
1363 dz21 = _mm_sub_ps(iz2,jz1);
1364 dx22 = _mm_sub_ps(ix2,jx2);
1365 dy22 = _mm_sub_ps(iy2,jy2);
1366 dz22 = _mm_sub_ps(iz2,jz2);
1368 /* Calculate squared distance and things based on it */
1369 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1370 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1371 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1372 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1373 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1374 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1375 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1376 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1377 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1379 rinv00 = sse2_invsqrt_f(rsq00);
1380 rinv01 = sse2_invsqrt_f(rsq01);
1381 rinv02 = sse2_invsqrt_f(rsq02);
1382 rinv10 = sse2_invsqrt_f(rsq10);
1383 rinv11 = sse2_invsqrt_f(rsq11);
1384 rinv12 = sse2_invsqrt_f(rsq12);
1385 rinv20 = sse2_invsqrt_f(rsq20);
1386 rinv21 = sse2_invsqrt_f(rsq21);
1387 rinv22 = sse2_invsqrt_f(rsq22);
1389 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1390 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1391 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1392 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1393 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1394 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1395 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1396 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1397 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1399 fjx0 = _mm_setzero_ps();
1400 fjy0 = _mm_setzero_ps();
1401 fjz0 = _mm_setzero_ps();
1402 fjx1 = _mm_setzero_ps();
1403 fjy1 = _mm_setzero_ps();
1404 fjz1 = _mm_setzero_ps();
1405 fjx2 = _mm_setzero_ps();
1406 fjy2 = _mm_setzero_ps();
1407 fjz2 = _mm_setzero_ps();
1409 /**************************
1410 * CALCULATE INTERACTIONS *
1411 **************************/
1413 if (gmx_mm_any_lt(rsq00,rcutoff2))
1416 /* REACTION-FIELD ELECTROSTATICS */
1417 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1419 /* LENNARD-JONES DISPERSION/REPULSION */
1421 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1422 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1424 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1426 fscal = _mm_add_ps(felec,fvdw);
1428 fscal = _mm_and_ps(fscal,cutoff_mask);
1430 /* Calculate temporary vectorial force */
1431 tx = _mm_mul_ps(fscal,dx00);
1432 ty = _mm_mul_ps(fscal,dy00);
1433 tz = _mm_mul_ps(fscal,dz00);
1435 /* Update vectorial force */
1436 fix0 = _mm_add_ps(fix0,tx);
1437 fiy0 = _mm_add_ps(fiy0,ty);
1438 fiz0 = _mm_add_ps(fiz0,tz);
1440 fjx0 = _mm_add_ps(fjx0,tx);
1441 fjy0 = _mm_add_ps(fjy0,ty);
1442 fjz0 = _mm_add_ps(fjz0,tz);
1446 /**************************
1447 * CALCULATE INTERACTIONS *
1448 **************************/
1450 if (gmx_mm_any_lt(rsq01,rcutoff2))
1453 /* REACTION-FIELD ELECTROSTATICS */
1454 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1456 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1460 fscal = _mm_and_ps(fscal,cutoff_mask);
1462 /* Calculate temporary vectorial force */
1463 tx = _mm_mul_ps(fscal,dx01);
1464 ty = _mm_mul_ps(fscal,dy01);
1465 tz = _mm_mul_ps(fscal,dz01);
1467 /* Update vectorial force */
1468 fix0 = _mm_add_ps(fix0,tx);
1469 fiy0 = _mm_add_ps(fiy0,ty);
1470 fiz0 = _mm_add_ps(fiz0,tz);
1472 fjx1 = _mm_add_ps(fjx1,tx);
1473 fjy1 = _mm_add_ps(fjy1,ty);
1474 fjz1 = _mm_add_ps(fjz1,tz);
1478 /**************************
1479 * CALCULATE INTERACTIONS *
1480 **************************/
1482 if (gmx_mm_any_lt(rsq02,rcutoff2))
1485 /* REACTION-FIELD ELECTROSTATICS */
1486 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1488 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1492 fscal = _mm_and_ps(fscal,cutoff_mask);
1494 /* Calculate temporary vectorial force */
1495 tx = _mm_mul_ps(fscal,dx02);
1496 ty = _mm_mul_ps(fscal,dy02);
1497 tz = _mm_mul_ps(fscal,dz02);
1499 /* Update vectorial force */
1500 fix0 = _mm_add_ps(fix0,tx);
1501 fiy0 = _mm_add_ps(fiy0,ty);
1502 fiz0 = _mm_add_ps(fiz0,tz);
1504 fjx2 = _mm_add_ps(fjx2,tx);
1505 fjy2 = _mm_add_ps(fjy2,ty);
1506 fjz2 = _mm_add_ps(fjz2,tz);
1510 /**************************
1511 * CALCULATE INTERACTIONS *
1512 **************************/
1514 if (gmx_mm_any_lt(rsq10,rcutoff2))
1517 /* REACTION-FIELD ELECTROSTATICS */
1518 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1520 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1524 fscal = _mm_and_ps(fscal,cutoff_mask);
1526 /* Calculate temporary vectorial force */
1527 tx = _mm_mul_ps(fscal,dx10);
1528 ty = _mm_mul_ps(fscal,dy10);
1529 tz = _mm_mul_ps(fscal,dz10);
1531 /* Update vectorial force */
1532 fix1 = _mm_add_ps(fix1,tx);
1533 fiy1 = _mm_add_ps(fiy1,ty);
1534 fiz1 = _mm_add_ps(fiz1,tz);
1536 fjx0 = _mm_add_ps(fjx0,tx);
1537 fjy0 = _mm_add_ps(fjy0,ty);
1538 fjz0 = _mm_add_ps(fjz0,tz);
1542 /**************************
1543 * CALCULATE INTERACTIONS *
1544 **************************/
1546 if (gmx_mm_any_lt(rsq11,rcutoff2))
1549 /* REACTION-FIELD ELECTROSTATICS */
1550 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1552 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1556 fscal = _mm_and_ps(fscal,cutoff_mask);
1558 /* Calculate temporary vectorial force */
1559 tx = _mm_mul_ps(fscal,dx11);
1560 ty = _mm_mul_ps(fscal,dy11);
1561 tz = _mm_mul_ps(fscal,dz11);
1563 /* Update vectorial force */
1564 fix1 = _mm_add_ps(fix1,tx);
1565 fiy1 = _mm_add_ps(fiy1,ty);
1566 fiz1 = _mm_add_ps(fiz1,tz);
1568 fjx1 = _mm_add_ps(fjx1,tx);
1569 fjy1 = _mm_add_ps(fjy1,ty);
1570 fjz1 = _mm_add_ps(fjz1,tz);
1574 /**************************
1575 * CALCULATE INTERACTIONS *
1576 **************************/
1578 if (gmx_mm_any_lt(rsq12,rcutoff2))
1581 /* REACTION-FIELD ELECTROSTATICS */
1582 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1584 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1588 fscal = _mm_and_ps(fscal,cutoff_mask);
1590 /* Calculate temporary vectorial force */
1591 tx = _mm_mul_ps(fscal,dx12);
1592 ty = _mm_mul_ps(fscal,dy12);
1593 tz = _mm_mul_ps(fscal,dz12);
1595 /* Update vectorial force */
1596 fix1 = _mm_add_ps(fix1,tx);
1597 fiy1 = _mm_add_ps(fiy1,ty);
1598 fiz1 = _mm_add_ps(fiz1,tz);
1600 fjx2 = _mm_add_ps(fjx2,tx);
1601 fjy2 = _mm_add_ps(fjy2,ty);
1602 fjz2 = _mm_add_ps(fjz2,tz);
1606 /**************************
1607 * CALCULATE INTERACTIONS *
1608 **************************/
1610 if (gmx_mm_any_lt(rsq20,rcutoff2))
1613 /* REACTION-FIELD ELECTROSTATICS */
1614 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1616 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1620 fscal = _mm_and_ps(fscal,cutoff_mask);
1622 /* Calculate temporary vectorial force */
1623 tx = _mm_mul_ps(fscal,dx20);
1624 ty = _mm_mul_ps(fscal,dy20);
1625 tz = _mm_mul_ps(fscal,dz20);
1627 /* Update vectorial force */
1628 fix2 = _mm_add_ps(fix2,tx);
1629 fiy2 = _mm_add_ps(fiy2,ty);
1630 fiz2 = _mm_add_ps(fiz2,tz);
1632 fjx0 = _mm_add_ps(fjx0,tx);
1633 fjy0 = _mm_add_ps(fjy0,ty);
1634 fjz0 = _mm_add_ps(fjz0,tz);
1638 /**************************
1639 * CALCULATE INTERACTIONS *
1640 **************************/
1642 if (gmx_mm_any_lt(rsq21,rcutoff2))
1645 /* REACTION-FIELD ELECTROSTATICS */
1646 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1648 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1652 fscal = _mm_and_ps(fscal,cutoff_mask);
1654 /* Calculate temporary vectorial force */
1655 tx = _mm_mul_ps(fscal,dx21);
1656 ty = _mm_mul_ps(fscal,dy21);
1657 tz = _mm_mul_ps(fscal,dz21);
1659 /* Update vectorial force */
1660 fix2 = _mm_add_ps(fix2,tx);
1661 fiy2 = _mm_add_ps(fiy2,ty);
1662 fiz2 = _mm_add_ps(fiz2,tz);
1664 fjx1 = _mm_add_ps(fjx1,tx);
1665 fjy1 = _mm_add_ps(fjy1,ty);
1666 fjz1 = _mm_add_ps(fjz1,tz);
1670 /**************************
1671 * CALCULATE INTERACTIONS *
1672 **************************/
1674 if (gmx_mm_any_lt(rsq22,rcutoff2))
1677 /* REACTION-FIELD ELECTROSTATICS */
1678 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1680 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1684 fscal = _mm_and_ps(fscal,cutoff_mask);
1686 /* Calculate temporary vectorial force */
1687 tx = _mm_mul_ps(fscal,dx22);
1688 ty = _mm_mul_ps(fscal,dy22);
1689 tz = _mm_mul_ps(fscal,dz22);
1691 /* Update vectorial force */
1692 fix2 = _mm_add_ps(fix2,tx);
1693 fiy2 = _mm_add_ps(fiy2,ty);
1694 fiz2 = _mm_add_ps(fiz2,tz);
1696 fjx2 = _mm_add_ps(fjx2,tx);
1697 fjy2 = _mm_add_ps(fjy2,ty);
1698 fjz2 = _mm_add_ps(fjz2,tz);
1702 fjptrA = f+j_coord_offsetA;
1703 fjptrB = f+j_coord_offsetB;
1704 fjptrC = f+j_coord_offsetC;
1705 fjptrD = f+j_coord_offsetD;
1707 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1708 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1710 /* Inner loop uses 277 flops */
1713 if(jidx<j_index_end)
1716 /* Get j neighbor index, and coordinate index */
1717 jnrlistA = jjnr[jidx];
1718 jnrlistB = jjnr[jidx+1];
1719 jnrlistC = jjnr[jidx+2];
1720 jnrlistD = jjnr[jidx+3];
1721 /* Sign of each element will be negative for non-real atoms.
1722 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1723 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1725 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1726 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1727 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1728 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1729 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1730 j_coord_offsetA = DIM*jnrA;
1731 j_coord_offsetB = DIM*jnrB;
1732 j_coord_offsetC = DIM*jnrC;
1733 j_coord_offsetD = DIM*jnrD;
1735 /* load j atom coordinates */
1736 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1737 x+j_coord_offsetC,x+j_coord_offsetD,
1738 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1740 /* Calculate displacement vector */
1741 dx00 = _mm_sub_ps(ix0,jx0);
1742 dy00 = _mm_sub_ps(iy0,jy0);
1743 dz00 = _mm_sub_ps(iz0,jz0);
1744 dx01 = _mm_sub_ps(ix0,jx1);
1745 dy01 = _mm_sub_ps(iy0,jy1);
1746 dz01 = _mm_sub_ps(iz0,jz1);
1747 dx02 = _mm_sub_ps(ix0,jx2);
1748 dy02 = _mm_sub_ps(iy0,jy2);
1749 dz02 = _mm_sub_ps(iz0,jz2);
1750 dx10 = _mm_sub_ps(ix1,jx0);
1751 dy10 = _mm_sub_ps(iy1,jy0);
1752 dz10 = _mm_sub_ps(iz1,jz0);
1753 dx11 = _mm_sub_ps(ix1,jx1);
1754 dy11 = _mm_sub_ps(iy1,jy1);
1755 dz11 = _mm_sub_ps(iz1,jz1);
1756 dx12 = _mm_sub_ps(ix1,jx2);
1757 dy12 = _mm_sub_ps(iy1,jy2);
1758 dz12 = _mm_sub_ps(iz1,jz2);
1759 dx20 = _mm_sub_ps(ix2,jx0);
1760 dy20 = _mm_sub_ps(iy2,jy0);
1761 dz20 = _mm_sub_ps(iz2,jz0);
1762 dx21 = _mm_sub_ps(ix2,jx1);
1763 dy21 = _mm_sub_ps(iy2,jy1);
1764 dz21 = _mm_sub_ps(iz2,jz1);
1765 dx22 = _mm_sub_ps(ix2,jx2);
1766 dy22 = _mm_sub_ps(iy2,jy2);
1767 dz22 = _mm_sub_ps(iz2,jz2);
1769 /* Calculate squared distance and things based on it */
1770 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1771 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1772 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1773 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1774 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1775 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1776 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1777 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1778 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1780 rinv00 = sse2_invsqrt_f(rsq00);
1781 rinv01 = sse2_invsqrt_f(rsq01);
1782 rinv02 = sse2_invsqrt_f(rsq02);
1783 rinv10 = sse2_invsqrt_f(rsq10);
1784 rinv11 = sse2_invsqrt_f(rsq11);
1785 rinv12 = sse2_invsqrt_f(rsq12);
1786 rinv20 = sse2_invsqrt_f(rsq20);
1787 rinv21 = sse2_invsqrt_f(rsq21);
1788 rinv22 = sse2_invsqrt_f(rsq22);
1790 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1791 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1792 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1793 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1794 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1795 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1796 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1797 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1798 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1800 fjx0 = _mm_setzero_ps();
1801 fjy0 = _mm_setzero_ps();
1802 fjz0 = _mm_setzero_ps();
1803 fjx1 = _mm_setzero_ps();
1804 fjy1 = _mm_setzero_ps();
1805 fjz1 = _mm_setzero_ps();
1806 fjx2 = _mm_setzero_ps();
1807 fjy2 = _mm_setzero_ps();
1808 fjz2 = _mm_setzero_ps();
1810 /**************************
1811 * CALCULATE INTERACTIONS *
1812 **************************/
1814 if (gmx_mm_any_lt(rsq00,rcutoff2))
1817 /* REACTION-FIELD ELECTROSTATICS */
1818 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1820 /* LENNARD-JONES DISPERSION/REPULSION */
1822 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1823 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1825 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1827 fscal = _mm_add_ps(felec,fvdw);
1829 fscal = _mm_and_ps(fscal,cutoff_mask);
1831 fscal = _mm_andnot_ps(dummy_mask,fscal);
1833 /* Calculate temporary vectorial force */
1834 tx = _mm_mul_ps(fscal,dx00);
1835 ty = _mm_mul_ps(fscal,dy00);
1836 tz = _mm_mul_ps(fscal,dz00);
1838 /* Update vectorial force */
1839 fix0 = _mm_add_ps(fix0,tx);
1840 fiy0 = _mm_add_ps(fiy0,ty);
1841 fiz0 = _mm_add_ps(fiz0,tz);
1843 fjx0 = _mm_add_ps(fjx0,tx);
1844 fjy0 = _mm_add_ps(fjy0,ty);
1845 fjz0 = _mm_add_ps(fjz0,tz);
1849 /**************************
1850 * CALCULATE INTERACTIONS *
1851 **************************/
1853 if (gmx_mm_any_lt(rsq01,rcutoff2))
1856 /* REACTION-FIELD ELECTROSTATICS */
1857 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1859 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1863 fscal = _mm_and_ps(fscal,cutoff_mask);
1865 fscal = _mm_andnot_ps(dummy_mask,fscal);
1867 /* Calculate temporary vectorial force */
1868 tx = _mm_mul_ps(fscal,dx01);
1869 ty = _mm_mul_ps(fscal,dy01);
1870 tz = _mm_mul_ps(fscal,dz01);
1872 /* Update vectorial force */
1873 fix0 = _mm_add_ps(fix0,tx);
1874 fiy0 = _mm_add_ps(fiy0,ty);
1875 fiz0 = _mm_add_ps(fiz0,tz);
1877 fjx1 = _mm_add_ps(fjx1,tx);
1878 fjy1 = _mm_add_ps(fjy1,ty);
1879 fjz1 = _mm_add_ps(fjz1,tz);
1883 /**************************
1884 * CALCULATE INTERACTIONS *
1885 **************************/
1887 if (gmx_mm_any_lt(rsq02,rcutoff2))
1890 /* REACTION-FIELD ELECTROSTATICS */
1891 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1893 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1897 fscal = _mm_and_ps(fscal,cutoff_mask);
1899 fscal = _mm_andnot_ps(dummy_mask,fscal);
1901 /* Calculate temporary vectorial force */
1902 tx = _mm_mul_ps(fscal,dx02);
1903 ty = _mm_mul_ps(fscal,dy02);
1904 tz = _mm_mul_ps(fscal,dz02);
1906 /* Update vectorial force */
1907 fix0 = _mm_add_ps(fix0,tx);
1908 fiy0 = _mm_add_ps(fiy0,ty);
1909 fiz0 = _mm_add_ps(fiz0,tz);
1911 fjx2 = _mm_add_ps(fjx2,tx);
1912 fjy2 = _mm_add_ps(fjy2,ty);
1913 fjz2 = _mm_add_ps(fjz2,tz);
1917 /**************************
1918 * CALCULATE INTERACTIONS *
1919 **************************/
1921 if (gmx_mm_any_lt(rsq10,rcutoff2))
1924 /* REACTION-FIELD ELECTROSTATICS */
1925 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1927 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1931 fscal = _mm_and_ps(fscal,cutoff_mask);
1933 fscal = _mm_andnot_ps(dummy_mask,fscal);
1935 /* Calculate temporary vectorial force */
1936 tx = _mm_mul_ps(fscal,dx10);
1937 ty = _mm_mul_ps(fscal,dy10);
1938 tz = _mm_mul_ps(fscal,dz10);
1940 /* Update vectorial force */
1941 fix1 = _mm_add_ps(fix1,tx);
1942 fiy1 = _mm_add_ps(fiy1,ty);
1943 fiz1 = _mm_add_ps(fiz1,tz);
1945 fjx0 = _mm_add_ps(fjx0,tx);
1946 fjy0 = _mm_add_ps(fjy0,ty);
1947 fjz0 = _mm_add_ps(fjz0,tz);
1951 /**************************
1952 * CALCULATE INTERACTIONS *
1953 **************************/
1955 if (gmx_mm_any_lt(rsq11,rcutoff2))
1958 /* REACTION-FIELD ELECTROSTATICS */
1959 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1961 cutoff_mask = _mm_cmplt_ps(rsq11,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,dx11);
1971 ty = _mm_mul_ps(fscal,dy11);
1972 tz = _mm_mul_ps(fscal,dz11);
1974 /* Update vectorial force */
1975 fix1 = _mm_add_ps(fix1,tx);
1976 fiy1 = _mm_add_ps(fiy1,ty);
1977 fiz1 = _mm_add_ps(fiz1,tz);
1979 fjx1 = _mm_add_ps(fjx1,tx);
1980 fjy1 = _mm_add_ps(fjy1,ty);
1981 fjz1 = _mm_add_ps(fjz1,tz);
1985 /**************************
1986 * CALCULATE INTERACTIONS *
1987 **************************/
1989 if (gmx_mm_any_lt(rsq12,rcutoff2))
1992 /* REACTION-FIELD ELECTROSTATICS */
1993 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1995 cutoff_mask = _mm_cmplt_ps(rsq12,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,dx12);
2005 ty = _mm_mul_ps(fscal,dy12);
2006 tz = _mm_mul_ps(fscal,dz12);
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 fjx2 = _mm_add_ps(fjx2,tx);
2014 fjy2 = _mm_add_ps(fjy2,ty);
2015 fjz2 = _mm_add_ps(fjz2,tz);
2019 /**************************
2020 * CALCULATE INTERACTIONS *
2021 **************************/
2023 if (gmx_mm_any_lt(rsq20,rcutoff2))
2026 /* REACTION-FIELD ELECTROSTATICS */
2027 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
2029 cutoff_mask = _mm_cmplt_ps(rsq20,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,dx20);
2039 ty = _mm_mul_ps(fscal,dy20);
2040 tz = _mm_mul_ps(fscal,dz20);
2042 /* Update vectorial force */
2043 fix2 = _mm_add_ps(fix2,tx);
2044 fiy2 = _mm_add_ps(fiy2,ty);
2045 fiz2 = _mm_add_ps(fiz2,tz);
2047 fjx0 = _mm_add_ps(fjx0,tx);
2048 fjy0 = _mm_add_ps(fjy0,ty);
2049 fjz0 = _mm_add_ps(fjz0,tz);
2053 /**************************
2054 * CALCULATE INTERACTIONS *
2055 **************************/
2057 if (gmx_mm_any_lt(rsq21,rcutoff2))
2060 /* REACTION-FIELD ELECTROSTATICS */
2061 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
2063 cutoff_mask = _mm_cmplt_ps(rsq21,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,dx21);
2073 ty = _mm_mul_ps(fscal,dy21);
2074 tz = _mm_mul_ps(fscal,dz21);
2076 /* Update vectorial force */
2077 fix2 = _mm_add_ps(fix2,tx);
2078 fiy2 = _mm_add_ps(fiy2,ty);
2079 fiz2 = _mm_add_ps(fiz2,tz);
2081 fjx1 = _mm_add_ps(fjx1,tx);
2082 fjy1 = _mm_add_ps(fjy1,ty);
2083 fjz1 = _mm_add_ps(fjz1,tz);
2087 /**************************
2088 * CALCULATE INTERACTIONS *
2089 **************************/
2091 if (gmx_mm_any_lt(rsq22,rcutoff2))
2094 /* REACTION-FIELD ELECTROSTATICS */
2095 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2097 cutoff_mask = _mm_cmplt_ps(rsq22,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,dx22);
2107 ty = _mm_mul_ps(fscal,dy22);
2108 tz = _mm_mul_ps(fscal,dz22);
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 fjx2 = _mm_add_ps(fjx2,tx);
2116 fjy2 = _mm_add_ps(fjy2,ty);
2117 fjz2 = _mm_add_ps(fjz2,tz);
2121 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2122 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2123 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2124 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2126 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2127 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2129 /* Inner loop uses 277 flops */
2132 /* End of innermost loop */
2134 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2135 f+i_coord_offset,fshift+i_shift_offset);
2137 /* Increment number of inner iterations */
2138 inneriter += j_index_end - j_index_start;
2140 /* Outer loop uses 18 flops */
2143 /* Increment number of outer iterations */
2146 /* Update outer/inner flops */
2148 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*277);