2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse4_1_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4W4_VF_sse4_1_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Water4-Water4
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwNone_GeomW4W4_VF_sse4_1_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
89 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
90 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
91 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
92 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
93 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
94 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
95 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
96 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
97 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
98 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
99 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
100 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
101 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
102 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
103 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
105 __m128 dummy_mask,cutoff_mask;
106 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107 __m128 one = _mm_set1_ps(1.0);
108 __m128 two = _mm_set1_ps(2.0);
114 jindex = nlist->jindex;
116 shiftidx = nlist->shift;
118 shiftvec = fr->shift_vec[0];
119 fshift = fr->fshift[0];
120 facel = _mm_set1_ps(fr->ic->epsfac);
121 charge = mdatoms->chargeA;
122 krf = _mm_set1_ps(fr->ic->k_rf);
123 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
124 crf = _mm_set1_ps(fr->ic->c_rf);
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[0];
128 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
129 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
130 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
132 jq1 = _mm_set1_ps(charge[inr+1]);
133 jq2 = _mm_set1_ps(charge[inr+2]);
134 jq3 = _mm_set1_ps(charge[inr+3]);
135 qq11 = _mm_mul_ps(iq1,jq1);
136 qq12 = _mm_mul_ps(iq1,jq2);
137 qq13 = _mm_mul_ps(iq1,jq3);
138 qq21 = _mm_mul_ps(iq2,jq1);
139 qq22 = _mm_mul_ps(iq2,jq2);
140 qq23 = _mm_mul_ps(iq2,jq3);
141 qq31 = _mm_mul_ps(iq3,jq1);
142 qq32 = _mm_mul_ps(iq3,jq2);
143 qq33 = _mm_mul_ps(iq3,jq3);
145 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
146 rcutoff_scalar = fr->ic->rcoulomb;
147 rcutoff = _mm_set1_ps(rcutoff_scalar);
148 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
150 /* Avoid stupid compiler warnings */
151 jnrA = jnrB = jnrC = jnrD = 0;
160 for(iidx=0;iidx<4*DIM;iidx++)
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];
171 /* Load limits for loop over neighbors */
172 j_index_start = jindex[iidx];
173 j_index_end = jindex[iidx+1];
175 /* Get outer coordinate index */
177 i_coord_offset = DIM*inr;
179 /* Load i particle coords and add shift vector */
180 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
181 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
183 fix1 = _mm_setzero_ps();
184 fiy1 = _mm_setzero_ps();
185 fiz1 = _mm_setzero_ps();
186 fix2 = _mm_setzero_ps();
187 fiy2 = _mm_setzero_ps();
188 fiz2 = _mm_setzero_ps();
189 fix3 = _mm_setzero_ps();
190 fiy3 = _mm_setzero_ps();
191 fiz3 = _mm_setzero_ps();
193 /* Reset potential sums */
194 velecsum = _mm_setzero_ps();
196 /* Start inner kernel loop */
197 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
200 /* Get j neighbor index, and coordinate index */
205 j_coord_offsetA = DIM*jnrA;
206 j_coord_offsetB = DIM*jnrB;
207 j_coord_offsetC = DIM*jnrC;
208 j_coord_offsetD = DIM*jnrD;
210 /* load j atom coordinates */
211 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
212 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
213 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
215 /* Calculate displacement vector */
216 dx11 = _mm_sub_ps(ix1,jx1);
217 dy11 = _mm_sub_ps(iy1,jy1);
218 dz11 = _mm_sub_ps(iz1,jz1);
219 dx12 = _mm_sub_ps(ix1,jx2);
220 dy12 = _mm_sub_ps(iy1,jy2);
221 dz12 = _mm_sub_ps(iz1,jz2);
222 dx13 = _mm_sub_ps(ix1,jx3);
223 dy13 = _mm_sub_ps(iy1,jy3);
224 dz13 = _mm_sub_ps(iz1,jz3);
225 dx21 = _mm_sub_ps(ix2,jx1);
226 dy21 = _mm_sub_ps(iy2,jy1);
227 dz21 = _mm_sub_ps(iz2,jz1);
228 dx22 = _mm_sub_ps(ix2,jx2);
229 dy22 = _mm_sub_ps(iy2,jy2);
230 dz22 = _mm_sub_ps(iz2,jz2);
231 dx23 = _mm_sub_ps(ix2,jx3);
232 dy23 = _mm_sub_ps(iy2,jy3);
233 dz23 = _mm_sub_ps(iz2,jz3);
234 dx31 = _mm_sub_ps(ix3,jx1);
235 dy31 = _mm_sub_ps(iy3,jy1);
236 dz31 = _mm_sub_ps(iz3,jz1);
237 dx32 = _mm_sub_ps(ix3,jx2);
238 dy32 = _mm_sub_ps(iy3,jy2);
239 dz32 = _mm_sub_ps(iz3,jz2);
240 dx33 = _mm_sub_ps(ix3,jx3);
241 dy33 = _mm_sub_ps(iy3,jy3);
242 dz33 = _mm_sub_ps(iz3,jz3);
244 /* Calculate squared distance and things based on it */
245 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
246 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
247 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
248 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
249 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
250 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
251 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
252 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
253 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
255 rinv11 = sse41_invsqrt_f(rsq11);
256 rinv12 = sse41_invsqrt_f(rsq12);
257 rinv13 = sse41_invsqrt_f(rsq13);
258 rinv21 = sse41_invsqrt_f(rsq21);
259 rinv22 = sse41_invsqrt_f(rsq22);
260 rinv23 = sse41_invsqrt_f(rsq23);
261 rinv31 = sse41_invsqrt_f(rsq31);
262 rinv32 = sse41_invsqrt_f(rsq32);
263 rinv33 = sse41_invsqrt_f(rsq33);
265 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
266 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
267 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
268 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
269 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
270 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
271 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
272 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
273 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
275 fjx1 = _mm_setzero_ps();
276 fjy1 = _mm_setzero_ps();
277 fjz1 = _mm_setzero_ps();
278 fjx2 = _mm_setzero_ps();
279 fjy2 = _mm_setzero_ps();
280 fjz2 = _mm_setzero_ps();
281 fjx3 = _mm_setzero_ps();
282 fjy3 = _mm_setzero_ps();
283 fjz3 = _mm_setzero_ps();
285 /**************************
286 * CALCULATE INTERACTIONS *
287 **************************/
289 if (gmx_mm_any_lt(rsq11,rcutoff2))
292 /* REACTION-FIELD ELECTROSTATICS */
293 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
294 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
296 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
298 /* Update potential sum for this i atom from the interaction with this j atom. */
299 velec = _mm_and_ps(velec,cutoff_mask);
300 velecsum = _mm_add_ps(velecsum,velec);
304 fscal = _mm_and_ps(fscal,cutoff_mask);
306 /* Calculate temporary vectorial force */
307 tx = _mm_mul_ps(fscal,dx11);
308 ty = _mm_mul_ps(fscal,dy11);
309 tz = _mm_mul_ps(fscal,dz11);
311 /* Update vectorial force */
312 fix1 = _mm_add_ps(fix1,tx);
313 fiy1 = _mm_add_ps(fiy1,ty);
314 fiz1 = _mm_add_ps(fiz1,tz);
316 fjx1 = _mm_add_ps(fjx1,tx);
317 fjy1 = _mm_add_ps(fjy1,ty);
318 fjz1 = _mm_add_ps(fjz1,tz);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 if (gmx_mm_any_lt(rsq12,rcutoff2))
329 /* REACTION-FIELD ELECTROSTATICS */
330 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
331 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
333 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
335 /* Update potential sum for this i atom from the interaction with this j atom. */
336 velec = _mm_and_ps(velec,cutoff_mask);
337 velecsum = _mm_add_ps(velecsum,velec);
341 fscal = _mm_and_ps(fscal,cutoff_mask);
343 /* Calculate temporary vectorial force */
344 tx = _mm_mul_ps(fscal,dx12);
345 ty = _mm_mul_ps(fscal,dy12);
346 tz = _mm_mul_ps(fscal,dz12);
348 /* Update vectorial force */
349 fix1 = _mm_add_ps(fix1,tx);
350 fiy1 = _mm_add_ps(fiy1,ty);
351 fiz1 = _mm_add_ps(fiz1,tz);
353 fjx2 = _mm_add_ps(fjx2,tx);
354 fjy2 = _mm_add_ps(fjy2,ty);
355 fjz2 = _mm_add_ps(fjz2,tz);
359 /**************************
360 * CALCULATE INTERACTIONS *
361 **************************/
363 if (gmx_mm_any_lt(rsq13,rcutoff2))
366 /* REACTION-FIELD ELECTROSTATICS */
367 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
368 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
370 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
372 /* Update potential sum for this i atom from the interaction with this j atom. */
373 velec = _mm_and_ps(velec,cutoff_mask);
374 velecsum = _mm_add_ps(velecsum,velec);
378 fscal = _mm_and_ps(fscal,cutoff_mask);
380 /* Calculate temporary vectorial force */
381 tx = _mm_mul_ps(fscal,dx13);
382 ty = _mm_mul_ps(fscal,dy13);
383 tz = _mm_mul_ps(fscal,dz13);
385 /* Update vectorial force */
386 fix1 = _mm_add_ps(fix1,tx);
387 fiy1 = _mm_add_ps(fiy1,ty);
388 fiz1 = _mm_add_ps(fiz1,tz);
390 fjx3 = _mm_add_ps(fjx3,tx);
391 fjy3 = _mm_add_ps(fjy3,ty);
392 fjz3 = _mm_add_ps(fjz3,tz);
396 /**************************
397 * CALCULATE INTERACTIONS *
398 **************************/
400 if (gmx_mm_any_lt(rsq21,rcutoff2))
403 /* REACTION-FIELD ELECTROSTATICS */
404 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
405 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
407 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
409 /* Update potential sum for this i atom from the interaction with this j atom. */
410 velec = _mm_and_ps(velec,cutoff_mask);
411 velecsum = _mm_add_ps(velecsum,velec);
415 fscal = _mm_and_ps(fscal,cutoff_mask);
417 /* Calculate temporary vectorial force */
418 tx = _mm_mul_ps(fscal,dx21);
419 ty = _mm_mul_ps(fscal,dy21);
420 tz = _mm_mul_ps(fscal,dz21);
422 /* Update vectorial force */
423 fix2 = _mm_add_ps(fix2,tx);
424 fiy2 = _mm_add_ps(fiy2,ty);
425 fiz2 = _mm_add_ps(fiz2,tz);
427 fjx1 = _mm_add_ps(fjx1,tx);
428 fjy1 = _mm_add_ps(fjy1,ty);
429 fjz1 = _mm_add_ps(fjz1,tz);
433 /**************************
434 * CALCULATE INTERACTIONS *
435 **************************/
437 if (gmx_mm_any_lt(rsq22,rcutoff2))
440 /* REACTION-FIELD ELECTROSTATICS */
441 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
442 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
444 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
446 /* Update potential sum for this i atom from the interaction with this j atom. */
447 velec = _mm_and_ps(velec,cutoff_mask);
448 velecsum = _mm_add_ps(velecsum,velec);
452 fscal = _mm_and_ps(fscal,cutoff_mask);
454 /* Calculate temporary vectorial force */
455 tx = _mm_mul_ps(fscal,dx22);
456 ty = _mm_mul_ps(fscal,dy22);
457 tz = _mm_mul_ps(fscal,dz22);
459 /* Update vectorial force */
460 fix2 = _mm_add_ps(fix2,tx);
461 fiy2 = _mm_add_ps(fiy2,ty);
462 fiz2 = _mm_add_ps(fiz2,tz);
464 fjx2 = _mm_add_ps(fjx2,tx);
465 fjy2 = _mm_add_ps(fjy2,ty);
466 fjz2 = _mm_add_ps(fjz2,tz);
470 /**************************
471 * CALCULATE INTERACTIONS *
472 **************************/
474 if (gmx_mm_any_lt(rsq23,rcutoff2))
477 /* REACTION-FIELD ELECTROSTATICS */
478 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
479 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
481 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
483 /* Update potential sum for this i atom from the interaction with this j atom. */
484 velec = _mm_and_ps(velec,cutoff_mask);
485 velecsum = _mm_add_ps(velecsum,velec);
489 fscal = _mm_and_ps(fscal,cutoff_mask);
491 /* Calculate temporary vectorial force */
492 tx = _mm_mul_ps(fscal,dx23);
493 ty = _mm_mul_ps(fscal,dy23);
494 tz = _mm_mul_ps(fscal,dz23);
496 /* Update vectorial force */
497 fix2 = _mm_add_ps(fix2,tx);
498 fiy2 = _mm_add_ps(fiy2,ty);
499 fiz2 = _mm_add_ps(fiz2,tz);
501 fjx3 = _mm_add_ps(fjx3,tx);
502 fjy3 = _mm_add_ps(fjy3,ty);
503 fjz3 = _mm_add_ps(fjz3,tz);
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 if (gmx_mm_any_lt(rsq31,rcutoff2))
514 /* REACTION-FIELD ELECTROSTATICS */
515 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
516 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
518 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
520 /* Update potential sum for this i atom from the interaction with this j atom. */
521 velec = _mm_and_ps(velec,cutoff_mask);
522 velecsum = _mm_add_ps(velecsum,velec);
526 fscal = _mm_and_ps(fscal,cutoff_mask);
528 /* Calculate temporary vectorial force */
529 tx = _mm_mul_ps(fscal,dx31);
530 ty = _mm_mul_ps(fscal,dy31);
531 tz = _mm_mul_ps(fscal,dz31);
533 /* Update vectorial force */
534 fix3 = _mm_add_ps(fix3,tx);
535 fiy3 = _mm_add_ps(fiy3,ty);
536 fiz3 = _mm_add_ps(fiz3,tz);
538 fjx1 = _mm_add_ps(fjx1,tx);
539 fjy1 = _mm_add_ps(fjy1,ty);
540 fjz1 = _mm_add_ps(fjz1,tz);
544 /**************************
545 * CALCULATE INTERACTIONS *
546 **************************/
548 if (gmx_mm_any_lt(rsq32,rcutoff2))
551 /* REACTION-FIELD ELECTROSTATICS */
552 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
553 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
555 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
557 /* Update potential sum for this i atom from the interaction with this j atom. */
558 velec = _mm_and_ps(velec,cutoff_mask);
559 velecsum = _mm_add_ps(velecsum,velec);
563 fscal = _mm_and_ps(fscal,cutoff_mask);
565 /* Calculate temporary vectorial force */
566 tx = _mm_mul_ps(fscal,dx32);
567 ty = _mm_mul_ps(fscal,dy32);
568 tz = _mm_mul_ps(fscal,dz32);
570 /* Update vectorial force */
571 fix3 = _mm_add_ps(fix3,tx);
572 fiy3 = _mm_add_ps(fiy3,ty);
573 fiz3 = _mm_add_ps(fiz3,tz);
575 fjx2 = _mm_add_ps(fjx2,tx);
576 fjy2 = _mm_add_ps(fjy2,ty);
577 fjz2 = _mm_add_ps(fjz2,tz);
581 /**************************
582 * CALCULATE INTERACTIONS *
583 **************************/
585 if (gmx_mm_any_lt(rsq33,rcutoff2))
588 /* REACTION-FIELD ELECTROSTATICS */
589 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
590 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
592 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
594 /* Update potential sum for this i atom from the interaction with this j atom. */
595 velec = _mm_and_ps(velec,cutoff_mask);
596 velecsum = _mm_add_ps(velecsum,velec);
600 fscal = _mm_and_ps(fscal,cutoff_mask);
602 /* Calculate temporary vectorial force */
603 tx = _mm_mul_ps(fscal,dx33);
604 ty = _mm_mul_ps(fscal,dy33);
605 tz = _mm_mul_ps(fscal,dz33);
607 /* Update vectorial force */
608 fix3 = _mm_add_ps(fix3,tx);
609 fiy3 = _mm_add_ps(fiy3,ty);
610 fiz3 = _mm_add_ps(fiz3,tz);
612 fjx3 = _mm_add_ps(fjx3,tx);
613 fjy3 = _mm_add_ps(fjy3,ty);
614 fjz3 = _mm_add_ps(fjz3,tz);
618 fjptrA = f+j_coord_offsetA;
619 fjptrB = f+j_coord_offsetB;
620 fjptrC = f+j_coord_offsetC;
621 fjptrD = f+j_coord_offsetD;
623 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
624 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
626 /* Inner loop uses 324 flops */
632 /* Get j neighbor index, and coordinate index */
633 jnrlistA = jjnr[jidx];
634 jnrlistB = jjnr[jidx+1];
635 jnrlistC = jjnr[jidx+2];
636 jnrlistD = jjnr[jidx+3];
637 /* Sign of each element will be negative for non-real atoms.
638 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
639 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
641 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
642 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
643 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
644 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
645 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
646 j_coord_offsetA = DIM*jnrA;
647 j_coord_offsetB = DIM*jnrB;
648 j_coord_offsetC = DIM*jnrC;
649 j_coord_offsetD = DIM*jnrD;
651 /* load j atom coordinates */
652 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
653 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
654 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
656 /* Calculate displacement vector */
657 dx11 = _mm_sub_ps(ix1,jx1);
658 dy11 = _mm_sub_ps(iy1,jy1);
659 dz11 = _mm_sub_ps(iz1,jz1);
660 dx12 = _mm_sub_ps(ix1,jx2);
661 dy12 = _mm_sub_ps(iy1,jy2);
662 dz12 = _mm_sub_ps(iz1,jz2);
663 dx13 = _mm_sub_ps(ix1,jx3);
664 dy13 = _mm_sub_ps(iy1,jy3);
665 dz13 = _mm_sub_ps(iz1,jz3);
666 dx21 = _mm_sub_ps(ix2,jx1);
667 dy21 = _mm_sub_ps(iy2,jy1);
668 dz21 = _mm_sub_ps(iz2,jz1);
669 dx22 = _mm_sub_ps(ix2,jx2);
670 dy22 = _mm_sub_ps(iy2,jy2);
671 dz22 = _mm_sub_ps(iz2,jz2);
672 dx23 = _mm_sub_ps(ix2,jx3);
673 dy23 = _mm_sub_ps(iy2,jy3);
674 dz23 = _mm_sub_ps(iz2,jz3);
675 dx31 = _mm_sub_ps(ix3,jx1);
676 dy31 = _mm_sub_ps(iy3,jy1);
677 dz31 = _mm_sub_ps(iz3,jz1);
678 dx32 = _mm_sub_ps(ix3,jx2);
679 dy32 = _mm_sub_ps(iy3,jy2);
680 dz32 = _mm_sub_ps(iz3,jz2);
681 dx33 = _mm_sub_ps(ix3,jx3);
682 dy33 = _mm_sub_ps(iy3,jy3);
683 dz33 = _mm_sub_ps(iz3,jz3);
685 /* Calculate squared distance and things based on it */
686 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
687 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
688 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
689 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
690 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
691 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
692 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
693 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
694 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
696 rinv11 = sse41_invsqrt_f(rsq11);
697 rinv12 = sse41_invsqrt_f(rsq12);
698 rinv13 = sse41_invsqrt_f(rsq13);
699 rinv21 = sse41_invsqrt_f(rsq21);
700 rinv22 = sse41_invsqrt_f(rsq22);
701 rinv23 = sse41_invsqrt_f(rsq23);
702 rinv31 = sse41_invsqrt_f(rsq31);
703 rinv32 = sse41_invsqrt_f(rsq32);
704 rinv33 = sse41_invsqrt_f(rsq33);
706 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
707 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
708 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
709 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
710 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
711 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
712 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
713 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
714 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
716 fjx1 = _mm_setzero_ps();
717 fjy1 = _mm_setzero_ps();
718 fjz1 = _mm_setzero_ps();
719 fjx2 = _mm_setzero_ps();
720 fjy2 = _mm_setzero_ps();
721 fjz2 = _mm_setzero_ps();
722 fjx3 = _mm_setzero_ps();
723 fjy3 = _mm_setzero_ps();
724 fjz3 = _mm_setzero_ps();
726 /**************************
727 * CALCULATE INTERACTIONS *
728 **************************/
730 if (gmx_mm_any_lt(rsq11,rcutoff2))
733 /* REACTION-FIELD ELECTROSTATICS */
734 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
735 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
737 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
739 /* Update potential sum for this i atom from the interaction with this j atom. */
740 velec = _mm_and_ps(velec,cutoff_mask);
741 velec = _mm_andnot_ps(dummy_mask,velec);
742 velecsum = _mm_add_ps(velecsum,velec);
746 fscal = _mm_and_ps(fscal,cutoff_mask);
748 fscal = _mm_andnot_ps(dummy_mask,fscal);
750 /* Calculate temporary vectorial force */
751 tx = _mm_mul_ps(fscal,dx11);
752 ty = _mm_mul_ps(fscal,dy11);
753 tz = _mm_mul_ps(fscal,dz11);
755 /* Update vectorial force */
756 fix1 = _mm_add_ps(fix1,tx);
757 fiy1 = _mm_add_ps(fiy1,ty);
758 fiz1 = _mm_add_ps(fiz1,tz);
760 fjx1 = _mm_add_ps(fjx1,tx);
761 fjy1 = _mm_add_ps(fjy1,ty);
762 fjz1 = _mm_add_ps(fjz1,tz);
766 /**************************
767 * CALCULATE INTERACTIONS *
768 **************************/
770 if (gmx_mm_any_lt(rsq12,rcutoff2))
773 /* REACTION-FIELD ELECTROSTATICS */
774 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
775 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
777 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
779 /* Update potential sum for this i atom from the interaction with this j atom. */
780 velec = _mm_and_ps(velec,cutoff_mask);
781 velec = _mm_andnot_ps(dummy_mask,velec);
782 velecsum = _mm_add_ps(velecsum,velec);
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,dx12);
792 ty = _mm_mul_ps(fscal,dy12);
793 tz = _mm_mul_ps(fscal,dz12);
795 /* Update vectorial force */
796 fix1 = _mm_add_ps(fix1,tx);
797 fiy1 = _mm_add_ps(fiy1,ty);
798 fiz1 = _mm_add_ps(fiz1,tz);
800 fjx2 = _mm_add_ps(fjx2,tx);
801 fjy2 = _mm_add_ps(fjy2,ty);
802 fjz2 = _mm_add_ps(fjz2,tz);
806 /**************************
807 * CALCULATE INTERACTIONS *
808 **************************/
810 if (gmx_mm_any_lt(rsq13,rcutoff2))
813 /* REACTION-FIELD ELECTROSTATICS */
814 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_add_ps(rinv13,_mm_mul_ps(krf,rsq13)),crf));
815 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
817 cutoff_mask = _mm_cmplt_ps(rsq13,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,dx13);
832 ty = _mm_mul_ps(fscal,dy13);
833 tz = _mm_mul_ps(fscal,dz13);
835 /* Update vectorial force */
836 fix1 = _mm_add_ps(fix1,tx);
837 fiy1 = _mm_add_ps(fiy1,ty);
838 fiz1 = _mm_add_ps(fiz1,tz);
840 fjx3 = _mm_add_ps(fjx3,tx);
841 fjy3 = _mm_add_ps(fjy3,ty);
842 fjz3 = _mm_add_ps(fjz3,tz);
846 /**************************
847 * CALCULATE INTERACTIONS *
848 **************************/
850 if (gmx_mm_any_lt(rsq21,rcutoff2))
853 /* REACTION-FIELD ELECTROSTATICS */
854 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
855 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
857 cutoff_mask = _mm_cmplt_ps(rsq21,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,dx21);
872 ty = _mm_mul_ps(fscal,dy21);
873 tz = _mm_mul_ps(fscal,dz21);
875 /* Update vectorial force */
876 fix2 = _mm_add_ps(fix2,tx);
877 fiy2 = _mm_add_ps(fiy2,ty);
878 fiz2 = _mm_add_ps(fiz2,tz);
880 fjx1 = _mm_add_ps(fjx1,tx);
881 fjy1 = _mm_add_ps(fjy1,ty);
882 fjz1 = _mm_add_ps(fjz1,tz);
886 /**************************
887 * CALCULATE INTERACTIONS *
888 **************************/
890 if (gmx_mm_any_lt(rsq22,rcutoff2))
893 /* REACTION-FIELD ELECTROSTATICS */
894 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
895 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
897 cutoff_mask = _mm_cmplt_ps(rsq22,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,dx22);
912 ty = _mm_mul_ps(fscal,dy22);
913 tz = _mm_mul_ps(fscal,dz22);
915 /* Update vectorial force */
916 fix2 = _mm_add_ps(fix2,tx);
917 fiy2 = _mm_add_ps(fiy2,ty);
918 fiz2 = _mm_add_ps(fiz2,tz);
920 fjx2 = _mm_add_ps(fjx2,tx);
921 fjy2 = _mm_add_ps(fjy2,ty);
922 fjz2 = _mm_add_ps(fjz2,tz);
926 /**************************
927 * CALCULATE INTERACTIONS *
928 **************************/
930 if (gmx_mm_any_lt(rsq23,rcutoff2))
933 /* REACTION-FIELD ELECTROSTATICS */
934 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_add_ps(rinv23,_mm_mul_ps(krf,rsq23)),crf));
935 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
937 cutoff_mask = _mm_cmplt_ps(rsq23,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,dx23);
952 ty = _mm_mul_ps(fscal,dy23);
953 tz = _mm_mul_ps(fscal,dz23);
955 /* Update vectorial force */
956 fix2 = _mm_add_ps(fix2,tx);
957 fiy2 = _mm_add_ps(fiy2,ty);
958 fiz2 = _mm_add_ps(fiz2,tz);
960 fjx3 = _mm_add_ps(fjx3,tx);
961 fjy3 = _mm_add_ps(fjy3,ty);
962 fjz3 = _mm_add_ps(fjz3,tz);
966 /**************************
967 * CALCULATE INTERACTIONS *
968 **************************/
970 if (gmx_mm_any_lt(rsq31,rcutoff2))
973 /* REACTION-FIELD ELECTROSTATICS */
974 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_add_ps(rinv31,_mm_mul_ps(krf,rsq31)),crf));
975 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
977 cutoff_mask = _mm_cmplt_ps(rsq31,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,dx31);
992 ty = _mm_mul_ps(fscal,dy31);
993 tz = _mm_mul_ps(fscal,dz31);
995 /* Update vectorial force */
996 fix3 = _mm_add_ps(fix3,tx);
997 fiy3 = _mm_add_ps(fiy3,ty);
998 fiz3 = _mm_add_ps(fiz3,tz);
1000 fjx1 = _mm_add_ps(fjx1,tx);
1001 fjy1 = _mm_add_ps(fjy1,ty);
1002 fjz1 = _mm_add_ps(fjz1,tz);
1006 /**************************
1007 * CALCULATE INTERACTIONS *
1008 **************************/
1010 if (gmx_mm_any_lt(rsq32,rcutoff2))
1013 /* REACTION-FIELD ELECTROSTATICS */
1014 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_add_ps(rinv32,_mm_mul_ps(krf,rsq32)),crf));
1015 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1017 cutoff_mask = _mm_cmplt_ps(rsq32,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,dx32);
1032 ty = _mm_mul_ps(fscal,dy32);
1033 tz = _mm_mul_ps(fscal,dz32);
1035 /* Update vectorial force */
1036 fix3 = _mm_add_ps(fix3,tx);
1037 fiy3 = _mm_add_ps(fiy3,ty);
1038 fiz3 = _mm_add_ps(fiz3,tz);
1040 fjx2 = _mm_add_ps(fjx2,tx);
1041 fjy2 = _mm_add_ps(fjy2,ty);
1042 fjz2 = _mm_add_ps(fjz2,tz);
1046 /**************************
1047 * CALCULATE INTERACTIONS *
1048 **************************/
1050 if (gmx_mm_any_lt(rsq33,rcutoff2))
1053 /* REACTION-FIELD ELECTROSTATICS */
1054 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_add_ps(rinv33,_mm_mul_ps(krf,rsq33)),crf));
1055 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1057 cutoff_mask = _mm_cmplt_ps(rsq33,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,dx33);
1072 ty = _mm_mul_ps(fscal,dy33);
1073 tz = _mm_mul_ps(fscal,dz33);
1075 /* Update vectorial force */
1076 fix3 = _mm_add_ps(fix3,tx);
1077 fiy3 = _mm_add_ps(fiy3,ty);
1078 fiz3 = _mm_add_ps(fiz3,tz);
1080 fjx3 = _mm_add_ps(fjx3,tx);
1081 fjy3 = _mm_add_ps(fjy3,ty);
1082 fjz3 = _mm_add_ps(fjz3,tz);
1086 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1087 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1088 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1089 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1091 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1092 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1094 /* Inner loop uses 324 flops */
1097 /* End of innermost loop */
1099 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1100 f+i_coord_offset+DIM,fshift+i_shift_offset);
1103 /* Update potential energies */
1104 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1106 /* Increment number of inner iterations */
1107 inneriter += j_index_end - j_index_start;
1109 /* Outer loop uses 19 flops */
1112 /* Increment number of outer iterations */
1115 /* Update outer/inner flops */
1117 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_VF,outeriter*19 + inneriter*324);
1120 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4W4_F_sse4_1_single
1121 * Electrostatics interaction: ReactionField
1122 * VdW interaction: None
1123 * Geometry: Water4-Water4
1124 * Calculate force/pot: Force
1127 nb_kernel_ElecRFCut_VdwNone_GeomW4W4_F_sse4_1_single
1128 (t_nblist * gmx_restrict nlist,
1129 rvec * gmx_restrict xx,
1130 rvec * gmx_restrict ff,
1131 struct t_forcerec * gmx_restrict fr,
1132 t_mdatoms * gmx_restrict mdatoms,
1133 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1134 t_nrnb * gmx_restrict nrnb)
1136 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1137 * just 0 for non-waters.
1138 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1139 * jnr indices corresponding to data put in the four positions in the SIMD register.
1141 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1142 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1143 int jnrA,jnrB,jnrC,jnrD;
1144 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1145 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1146 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1147 real rcutoff_scalar;
1148 real *shiftvec,*fshift,*x,*f;
1149 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1150 real scratch[4*DIM];
1151 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1153 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1155 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1157 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1158 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1159 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1160 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1161 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1162 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1163 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1164 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1165 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1166 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1167 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1168 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1169 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1170 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1171 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1172 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1173 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1175 __m128 dummy_mask,cutoff_mask;
1176 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1177 __m128 one = _mm_set1_ps(1.0);
1178 __m128 two = _mm_set1_ps(2.0);
1184 jindex = nlist->jindex;
1186 shiftidx = nlist->shift;
1188 shiftvec = fr->shift_vec[0];
1189 fshift = fr->fshift[0];
1190 facel = _mm_set1_ps(fr->ic->epsfac);
1191 charge = mdatoms->chargeA;
1192 krf = _mm_set1_ps(fr->ic->k_rf);
1193 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1194 crf = _mm_set1_ps(fr->ic->c_rf);
1196 /* Setup water-specific parameters */
1197 inr = nlist->iinr[0];
1198 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1199 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1200 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1202 jq1 = _mm_set1_ps(charge[inr+1]);
1203 jq2 = _mm_set1_ps(charge[inr+2]);
1204 jq3 = _mm_set1_ps(charge[inr+3]);
1205 qq11 = _mm_mul_ps(iq1,jq1);
1206 qq12 = _mm_mul_ps(iq1,jq2);
1207 qq13 = _mm_mul_ps(iq1,jq3);
1208 qq21 = _mm_mul_ps(iq2,jq1);
1209 qq22 = _mm_mul_ps(iq2,jq2);
1210 qq23 = _mm_mul_ps(iq2,jq3);
1211 qq31 = _mm_mul_ps(iq3,jq1);
1212 qq32 = _mm_mul_ps(iq3,jq2);
1213 qq33 = _mm_mul_ps(iq3,jq3);
1215 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1216 rcutoff_scalar = fr->ic->rcoulomb;
1217 rcutoff = _mm_set1_ps(rcutoff_scalar);
1218 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1220 /* Avoid stupid compiler warnings */
1221 jnrA = jnrB = jnrC = jnrD = 0;
1222 j_coord_offsetA = 0;
1223 j_coord_offsetB = 0;
1224 j_coord_offsetC = 0;
1225 j_coord_offsetD = 0;
1230 for(iidx=0;iidx<4*DIM;iidx++)
1232 scratch[iidx] = 0.0;
1235 /* Start outer loop over neighborlists */
1236 for(iidx=0; iidx<nri; iidx++)
1238 /* Load shift vector for this list */
1239 i_shift_offset = DIM*shiftidx[iidx];
1241 /* Load limits for loop over neighbors */
1242 j_index_start = jindex[iidx];
1243 j_index_end = jindex[iidx+1];
1245 /* Get outer coordinate index */
1247 i_coord_offset = DIM*inr;
1249 /* Load i particle coords and add shift vector */
1250 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
1251 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1253 fix1 = _mm_setzero_ps();
1254 fiy1 = _mm_setzero_ps();
1255 fiz1 = _mm_setzero_ps();
1256 fix2 = _mm_setzero_ps();
1257 fiy2 = _mm_setzero_ps();
1258 fiz2 = _mm_setzero_ps();
1259 fix3 = _mm_setzero_ps();
1260 fiy3 = _mm_setzero_ps();
1261 fiz3 = _mm_setzero_ps();
1263 /* Start inner kernel loop */
1264 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1267 /* Get j neighbor index, and coordinate index */
1269 jnrB = jjnr[jidx+1];
1270 jnrC = jjnr[jidx+2];
1271 jnrD = jjnr[jidx+3];
1272 j_coord_offsetA = DIM*jnrA;
1273 j_coord_offsetB = DIM*jnrB;
1274 j_coord_offsetC = DIM*jnrC;
1275 j_coord_offsetD = DIM*jnrD;
1277 /* load j atom coordinates */
1278 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
1279 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
1280 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
1282 /* Calculate displacement vector */
1283 dx11 = _mm_sub_ps(ix1,jx1);
1284 dy11 = _mm_sub_ps(iy1,jy1);
1285 dz11 = _mm_sub_ps(iz1,jz1);
1286 dx12 = _mm_sub_ps(ix1,jx2);
1287 dy12 = _mm_sub_ps(iy1,jy2);
1288 dz12 = _mm_sub_ps(iz1,jz2);
1289 dx13 = _mm_sub_ps(ix1,jx3);
1290 dy13 = _mm_sub_ps(iy1,jy3);
1291 dz13 = _mm_sub_ps(iz1,jz3);
1292 dx21 = _mm_sub_ps(ix2,jx1);
1293 dy21 = _mm_sub_ps(iy2,jy1);
1294 dz21 = _mm_sub_ps(iz2,jz1);
1295 dx22 = _mm_sub_ps(ix2,jx2);
1296 dy22 = _mm_sub_ps(iy2,jy2);
1297 dz22 = _mm_sub_ps(iz2,jz2);
1298 dx23 = _mm_sub_ps(ix2,jx3);
1299 dy23 = _mm_sub_ps(iy2,jy3);
1300 dz23 = _mm_sub_ps(iz2,jz3);
1301 dx31 = _mm_sub_ps(ix3,jx1);
1302 dy31 = _mm_sub_ps(iy3,jy1);
1303 dz31 = _mm_sub_ps(iz3,jz1);
1304 dx32 = _mm_sub_ps(ix3,jx2);
1305 dy32 = _mm_sub_ps(iy3,jy2);
1306 dz32 = _mm_sub_ps(iz3,jz2);
1307 dx33 = _mm_sub_ps(ix3,jx3);
1308 dy33 = _mm_sub_ps(iy3,jy3);
1309 dz33 = _mm_sub_ps(iz3,jz3);
1311 /* Calculate squared distance and things based on it */
1312 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1313 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1314 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1315 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1316 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1317 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1318 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1319 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1320 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1322 rinv11 = sse41_invsqrt_f(rsq11);
1323 rinv12 = sse41_invsqrt_f(rsq12);
1324 rinv13 = sse41_invsqrt_f(rsq13);
1325 rinv21 = sse41_invsqrt_f(rsq21);
1326 rinv22 = sse41_invsqrt_f(rsq22);
1327 rinv23 = sse41_invsqrt_f(rsq23);
1328 rinv31 = sse41_invsqrt_f(rsq31);
1329 rinv32 = sse41_invsqrt_f(rsq32);
1330 rinv33 = sse41_invsqrt_f(rsq33);
1332 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1333 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1334 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1335 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1336 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1337 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1338 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1339 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1340 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1342 fjx1 = _mm_setzero_ps();
1343 fjy1 = _mm_setzero_ps();
1344 fjz1 = _mm_setzero_ps();
1345 fjx2 = _mm_setzero_ps();
1346 fjy2 = _mm_setzero_ps();
1347 fjz2 = _mm_setzero_ps();
1348 fjx3 = _mm_setzero_ps();
1349 fjy3 = _mm_setzero_ps();
1350 fjz3 = _mm_setzero_ps();
1352 /**************************
1353 * CALCULATE INTERACTIONS *
1354 **************************/
1356 if (gmx_mm_any_lt(rsq11,rcutoff2))
1359 /* REACTION-FIELD ELECTROSTATICS */
1360 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1362 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1366 fscal = _mm_and_ps(fscal,cutoff_mask);
1368 /* Calculate temporary vectorial force */
1369 tx = _mm_mul_ps(fscal,dx11);
1370 ty = _mm_mul_ps(fscal,dy11);
1371 tz = _mm_mul_ps(fscal,dz11);
1373 /* Update vectorial force */
1374 fix1 = _mm_add_ps(fix1,tx);
1375 fiy1 = _mm_add_ps(fiy1,ty);
1376 fiz1 = _mm_add_ps(fiz1,tz);
1378 fjx1 = _mm_add_ps(fjx1,tx);
1379 fjy1 = _mm_add_ps(fjy1,ty);
1380 fjz1 = _mm_add_ps(fjz1,tz);
1384 /**************************
1385 * CALCULATE INTERACTIONS *
1386 **************************/
1388 if (gmx_mm_any_lt(rsq12,rcutoff2))
1391 /* REACTION-FIELD ELECTROSTATICS */
1392 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1394 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1398 fscal = _mm_and_ps(fscal,cutoff_mask);
1400 /* Calculate temporary vectorial force */
1401 tx = _mm_mul_ps(fscal,dx12);
1402 ty = _mm_mul_ps(fscal,dy12);
1403 tz = _mm_mul_ps(fscal,dz12);
1405 /* Update vectorial force */
1406 fix1 = _mm_add_ps(fix1,tx);
1407 fiy1 = _mm_add_ps(fiy1,ty);
1408 fiz1 = _mm_add_ps(fiz1,tz);
1410 fjx2 = _mm_add_ps(fjx2,tx);
1411 fjy2 = _mm_add_ps(fjy2,ty);
1412 fjz2 = _mm_add_ps(fjz2,tz);
1416 /**************************
1417 * CALCULATE INTERACTIONS *
1418 **************************/
1420 if (gmx_mm_any_lt(rsq13,rcutoff2))
1423 /* REACTION-FIELD ELECTROSTATICS */
1424 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
1426 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1430 fscal = _mm_and_ps(fscal,cutoff_mask);
1432 /* Calculate temporary vectorial force */
1433 tx = _mm_mul_ps(fscal,dx13);
1434 ty = _mm_mul_ps(fscal,dy13);
1435 tz = _mm_mul_ps(fscal,dz13);
1437 /* Update vectorial force */
1438 fix1 = _mm_add_ps(fix1,tx);
1439 fiy1 = _mm_add_ps(fiy1,ty);
1440 fiz1 = _mm_add_ps(fiz1,tz);
1442 fjx3 = _mm_add_ps(fjx3,tx);
1443 fjy3 = _mm_add_ps(fjy3,ty);
1444 fjz3 = _mm_add_ps(fjz3,tz);
1448 /**************************
1449 * CALCULATE INTERACTIONS *
1450 **************************/
1452 if (gmx_mm_any_lt(rsq21,rcutoff2))
1455 /* REACTION-FIELD ELECTROSTATICS */
1456 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1458 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1462 fscal = _mm_and_ps(fscal,cutoff_mask);
1464 /* Calculate temporary vectorial force */
1465 tx = _mm_mul_ps(fscal,dx21);
1466 ty = _mm_mul_ps(fscal,dy21);
1467 tz = _mm_mul_ps(fscal,dz21);
1469 /* Update vectorial force */
1470 fix2 = _mm_add_ps(fix2,tx);
1471 fiy2 = _mm_add_ps(fiy2,ty);
1472 fiz2 = _mm_add_ps(fiz2,tz);
1474 fjx1 = _mm_add_ps(fjx1,tx);
1475 fjy1 = _mm_add_ps(fjy1,ty);
1476 fjz1 = _mm_add_ps(fjz1,tz);
1480 /**************************
1481 * CALCULATE INTERACTIONS *
1482 **************************/
1484 if (gmx_mm_any_lt(rsq22,rcutoff2))
1487 /* REACTION-FIELD ELECTROSTATICS */
1488 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1490 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1494 fscal = _mm_and_ps(fscal,cutoff_mask);
1496 /* Calculate temporary vectorial force */
1497 tx = _mm_mul_ps(fscal,dx22);
1498 ty = _mm_mul_ps(fscal,dy22);
1499 tz = _mm_mul_ps(fscal,dz22);
1501 /* Update vectorial force */
1502 fix2 = _mm_add_ps(fix2,tx);
1503 fiy2 = _mm_add_ps(fiy2,ty);
1504 fiz2 = _mm_add_ps(fiz2,tz);
1506 fjx2 = _mm_add_ps(fjx2,tx);
1507 fjy2 = _mm_add_ps(fjy2,ty);
1508 fjz2 = _mm_add_ps(fjz2,tz);
1512 /**************************
1513 * CALCULATE INTERACTIONS *
1514 **************************/
1516 if (gmx_mm_any_lt(rsq23,rcutoff2))
1519 /* REACTION-FIELD ELECTROSTATICS */
1520 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1522 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1526 fscal = _mm_and_ps(fscal,cutoff_mask);
1528 /* Calculate temporary vectorial force */
1529 tx = _mm_mul_ps(fscal,dx23);
1530 ty = _mm_mul_ps(fscal,dy23);
1531 tz = _mm_mul_ps(fscal,dz23);
1533 /* Update vectorial force */
1534 fix2 = _mm_add_ps(fix2,tx);
1535 fiy2 = _mm_add_ps(fiy2,ty);
1536 fiz2 = _mm_add_ps(fiz2,tz);
1538 fjx3 = _mm_add_ps(fjx3,tx);
1539 fjy3 = _mm_add_ps(fjy3,ty);
1540 fjz3 = _mm_add_ps(fjz3,tz);
1544 /**************************
1545 * CALCULATE INTERACTIONS *
1546 **************************/
1548 if (gmx_mm_any_lt(rsq31,rcutoff2))
1551 /* REACTION-FIELD ELECTROSTATICS */
1552 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1554 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1558 fscal = _mm_and_ps(fscal,cutoff_mask);
1560 /* Calculate temporary vectorial force */
1561 tx = _mm_mul_ps(fscal,dx31);
1562 ty = _mm_mul_ps(fscal,dy31);
1563 tz = _mm_mul_ps(fscal,dz31);
1565 /* Update vectorial force */
1566 fix3 = _mm_add_ps(fix3,tx);
1567 fiy3 = _mm_add_ps(fiy3,ty);
1568 fiz3 = _mm_add_ps(fiz3,tz);
1570 fjx1 = _mm_add_ps(fjx1,tx);
1571 fjy1 = _mm_add_ps(fjy1,ty);
1572 fjz1 = _mm_add_ps(fjz1,tz);
1576 /**************************
1577 * CALCULATE INTERACTIONS *
1578 **************************/
1580 if (gmx_mm_any_lt(rsq32,rcutoff2))
1583 /* REACTION-FIELD ELECTROSTATICS */
1584 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1586 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1590 fscal = _mm_and_ps(fscal,cutoff_mask);
1592 /* Calculate temporary vectorial force */
1593 tx = _mm_mul_ps(fscal,dx32);
1594 ty = _mm_mul_ps(fscal,dy32);
1595 tz = _mm_mul_ps(fscal,dz32);
1597 /* Update vectorial force */
1598 fix3 = _mm_add_ps(fix3,tx);
1599 fiy3 = _mm_add_ps(fiy3,ty);
1600 fiz3 = _mm_add_ps(fiz3,tz);
1602 fjx2 = _mm_add_ps(fjx2,tx);
1603 fjy2 = _mm_add_ps(fjy2,ty);
1604 fjz2 = _mm_add_ps(fjz2,tz);
1608 /**************************
1609 * CALCULATE INTERACTIONS *
1610 **************************/
1612 if (gmx_mm_any_lt(rsq33,rcutoff2))
1615 /* REACTION-FIELD ELECTROSTATICS */
1616 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
1618 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1622 fscal = _mm_and_ps(fscal,cutoff_mask);
1624 /* Calculate temporary vectorial force */
1625 tx = _mm_mul_ps(fscal,dx33);
1626 ty = _mm_mul_ps(fscal,dy33);
1627 tz = _mm_mul_ps(fscal,dz33);
1629 /* Update vectorial force */
1630 fix3 = _mm_add_ps(fix3,tx);
1631 fiy3 = _mm_add_ps(fiy3,ty);
1632 fiz3 = _mm_add_ps(fiz3,tz);
1634 fjx3 = _mm_add_ps(fjx3,tx);
1635 fjy3 = _mm_add_ps(fjy3,ty);
1636 fjz3 = _mm_add_ps(fjz3,tz);
1640 fjptrA = f+j_coord_offsetA;
1641 fjptrB = f+j_coord_offsetB;
1642 fjptrC = f+j_coord_offsetC;
1643 fjptrD = f+j_coord_offsetD;
1645 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1646 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1648 /* Inner loop uses 270 flops */
1651 if(jidx<j_index_end)
1654 /* Get j neighbor index, and coordinate index */
1655 jnrlistA = jjnr[jidx];
1656 jnrlistB = jjnr[jidx+1];
1657 jnrlistC = jjnr[jidx+2];
1658 jnrlistD = jjnr[jidx+3];
1659 /* Sign of each element will be negative for non-real atoms.
1660 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1661 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1663 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1664 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1665 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1666 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1667 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1668 j_coord_offsetA = DIM*jnrA;
1669 j_coord_offsetB = DIM*jnrB;
1670 j_coord_offsetC = DIM*jnrC;
1671 j_coord_offsetD = DIM*jnrD;
1673 /* load j atom coordinates */
1674 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
1675 x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
1676 &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
1678 /* Calculate displacement vector */
1679 dx11 = _mm_sub_ps(ix1,jx1);
1680 dy11 = _mm_sub_ps(iy1,jy1);
1681 dz11 = _mm_sub_ps(iz1,jz1);
1682 dx12 = _mm_sub_ps(ix1,jx2);
1683 dy12 = _mm_sub_ps(iy1,jy2);
1684 dz12 = _mm_sub_ps(iz1,jz2);
1685 dx13 = _mm_sub_ps(ix1,jx3);
1686 dy13 = _mm_sub_ps(iy1,jy3);
1687 dz13 = _mm_sub_ps(iz1,jz3);
1688 dx21 = _mm_sub_ps(ix2,jx1);
1689 dy21 = _mm_sub_ps(iy2,jy1);
1690 dz21 = _mm_sub_ps(iz2,jz1);
1691 dx22 = _mm_sub_ps(ix2,jx2);
1692 dy22 = _mm_sub_ps(iy2,jy2);
1693 dz22 = _mm_sub_ps(iz2,jz2);
1694 dx23 = _mm_sub_ps(ix2,jx3);
1695 dy23 = _mm_sub_ps(iy2,jy3);
1696 dz23 = _mm_sub_ps(iz2,jz3);
1697 dx31 = _mm_sub_ps(ix3,jx1);
1698 dy31 = _mm_sub_ps(iy3,jy1);
1699 dz31 = _mm_sub_ps(iz3,jz1);
1700 dx32 = _mm_sub_ps(ix3,jx2);
1701 dy32 = _mm_sub_ps(iy3,jy2);
1702 dz32 = _mm_sub_ps(iz3,jz2);
1703 dx33 = _mm_sub_ps(ix3,jx3);
1704 dy33 = _mm_sub_ps(iy3,jy3);
1705 dz33 = _mm_sub_ps(iz3,jz3);
1707 /* Calculate squared distance and things based on it */
1708 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1709 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1710 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1711 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1712 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1713 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1714 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1715 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1716 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1718 rinv11 = sse41_invsqrt_f(rsq11);
1719 rinv12 = sse41_invsqrt_f(rsq12);
1720 rinv13 = sse41_invsqrt_f(rsq13);
1721 rinv21 = sse41_invsqrt_f(rsq21);
1722 rinv22 = sse41_invsqrt_f(rsq22);
1723 rinv23 = sse41_invsqrt_f(rsq23);
1724 rinv31 = sse41_invsqrt_f(rsq31);
1725 rinv32 = sse41_invsqrt_f(rsq32);
1726 rinv33 = sse41_invsqrt_f(rsq33);
1728 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1729 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1730 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1731 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1732 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1733 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1734 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1735 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1736 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1738 fjx1 = _mm_setzero_ps();
1739 fjy1 = _mm_setzero_ps();
1740 fjz1 = _mm_setzero_ps();
1741 fjx2 = _mm_setzero_ps();
1742 fjy2 = _mm_setzero_ps();
1743 fjz2 = _mm_setzero_ps();
1744 fjx3 = _mm_setzero_ps();
1745 fjy3 = _mm_setzero_ps();
1746 fjz3 = _mm_setzero_ps();
1748 /**************************
1749 * CALCULATE INTERACTIONS *
1750 **************************/
1752 if (gmx_mm_any_lt(rsq11,rcutoff2))
1755 /* REACTION-FIELD ELECTROSTATICS */
1756 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1758 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1762 fscal = _mm_and_ps(fscal,cutoff_mask);
1764 fscal = _mm_andnot_ps(dummy_mask,fscal);
1766 /* Calculate temporary vectorial force */
1767 tx = _mm_mul_ps(fscal,dx11);
1768 ty = _mm_mul_ps(fscal,dy11);
1769 tz = _mm_mul_ps(fscal,dz11);
1771 /* Update vectorial force */
1772 fix1 = _mm_add_ps(fix1,tx);
1773 fiy1 = _mm_add_ps(fiy1,ty);
1774 fiz1 = _mm_add_ps(fiz1,tz);
1776 fjx1 = _mm_add_ps(fjx1,tx);
1777 fjy1 = _mm_add_ps(fjy1,ty);
1778 fjz1 = _mm_add_ps(fjz1,tz);
1782 /**************************
1783 * CALCULATE INTERACTIONS *
1784 **************************/
1786 if (gmx_mm_any_lt(rsq12,rcutoff2))
1789 /* REACTION-FIELD ELECTROSTATICS */
1790 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1792 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1796 fscal = _mm_and_ps(fscal,cutoff_mask);
1798 fscal = _mm_andnot_ps(dummy_mask,fscal);
1800 /* Calculate temporary vectorial force */
1801 tx = _mm_mul_ps(fscal,dx12);
1802 ty = _mm_mul_ps(fscal,dy12);
1803 tz = _mm_mul_ps(fscal,dz12);
1805 /* Update vectorial force */
1806 fix1 = _mm_add_ps(fix1,tx);
1807 fiy1 = _mm_add_ps(fiy1,ty);
1808 fiz1 = _mm_add_ps(fiz1,tz);
1810 fjx2 = _mm_add_ps(fjx2,tx);
1811 fjy2 = _mm_add_ps(fjy2,ty);
1812 fjz2 = _mm_add_ps(fjz2,tz);
1816 /**************************
1817 * CALCULATE INTERACTIONS *
1818 **************************/
1820 if (gmx_mm_any_lt(rsq13,rcutoff2))
1823 /* REACTION-FIELD ELECTROSTATICS */
1824 felec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_mul_ps(rinv13,rinvsq13),krf2));
1826 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1830 fscal = _mm_and_ps(fscal,cutoff_mask);
1832 fscal = _mm_andnot_ps(dummy_mask,fscal);
1834 /* Calculate temporary vectorial force */
1835 tx = _mm_mul_ps(fscal,dx13);
1836 ty = _mm_mul_ps(fscal,dy13);
1837 tz = _mm_mul_ps(fscal,dz13);
1839 /* Update vectorial force */
1840 fix1 = _mm_add_ps(fix1,tx);
1841 fiy1 = _mm_add_ps(fiy1,ty);
1842 fiz1 = _mm_add_ps(fiz1,tz);
1844 fjx3 = _mm_add_ps(fjx3,tx);
1845 fjy3 = _mm_add_ps(fjy3,ty);
1846 fjz3 = _mm_add_ps(fjz3,tz);
1850 /**************************
1851 * CALCULATE INTERACTIONS *
1852 **************************/
1854 if (gmx_mm_any_lt(rsq21,rcutoff2))
1857 /* REACTION-FIELD ELECTROSTATICS */
1858 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1860 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1864 fscal = _mm_and_ps(fscal,cutoff_mask);
1866 fscal = _mm_andnot_ps(dummy_mask,fscal);
1868 /* Calculate temporary vectorial force */
1869 tx = _mm_mul_ps(fscal,dx21);
1870 ty = _mm_mul_ps(fscal,dy21);
1871 tz = _mm_mul_ps(fscal,dz21);
1873 /* Update vectorial force */
1874 fix2 = _mm_add_ps(fix2,tx);
1875 fiy2 = _mm_add_ps(fiy2,ty);
1876 fiz2 = _mm_add_ps(fiz2,tz);
1878 fjx1 = _mm_add_ps(fjx1,tx);
1879 fjy1 = _mm_add_ps(fjy1,ty);
1880 fjz1 = _mm_add_ps(fjz1,tz);
1884 /**************************
1885 * CALCULATE INTERACTIONS *
1886 **************************/
1888 if (gmx_mm_any_lt(rsq22,rcutoff2))
1891 /* REACTION-FIELD ELECTROSTATICS */
1892 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1894 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1898 fscal = _mm_and_ps(fscal,cutoff_mask);
1900 fscal = _mm_andnot_ps(dummy_mask,fscal);
1902 /* Calculate temporary vectorial force */
1903 tx = _mm_mul_ps(fscal,dx22);
1904 ty = _mm_mul_ps(fscal,dy22);
1905 tz = _mm_mul_ps(fscal,dz22);
1907 /* Update vectorial force */
1908 fix2 = _mm_add_ps(fix2,tx);
1909 fiy2 = _mm_add_ps(fiy2,ty);
1910 fiz2 = _mm_add_ps(fiz2,tz);
1912 fjx2 = _mm_add_ps(fjx2,tx);
1913 fjy2 = _mm_add_ps(fjy2,ty);
1914 fjz2 = _mm_add_ps(fjz2,tz);
1918 /**************************
1919 * CALCULATE INTERACTIONS *
1920 **************************/
1922 if (gmx_mm_any_lt(rsq23,rcutoff2))
1925 /* REACTION-FIELD ELECTROSTATICS */
1926 felec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_mul_ps(rinv23,rinvsq23),krf2));
1928 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1932 fscal = _mm_and_ps(fscal,cutoff_mask);
1934 fscal = _mm_andnot_ps(dummy_mask,fscal);
1936 /* Calculate temporary vectorial force */
1937 tx = _mm_mul_ps(fscal,dx23);
1938 ty = _mm_mul_ps(fscal,dy23);
1939 tz = _mm_mul_ps(fscal,dz23);
1941 /* Update vectorial force */
1942 fix2 = _mm_add_ps(fix2,tx);
1943 fiy2 = _mm_add_ps(fiy2,ty);
1944 fiz2 = _mm_add_ps(fiz2,tz);
1946 fjx3 = _mm_add_ps(fjx3,tx);
1947 fjy3 = _mm_add_ps(fjy3,ty);
1948 fjz3 = _mm_add_ps(fjz3,tz);
1952 /**************************
1953 * CALCULATE INTERACTIONS *
1954 **************************/
1956 if (gmx_mm_any_lt(rsq31,rcutoff2))
1959 /* REACTION-FIELD ELECTROSTATICS */
1960 felec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_mul_ps(rinv31,rinvsq31),krf2));
1962 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1966 fscal = _mm_and_ps(fscal,cutoff_mask);
1968 fscal = _mm_andnot_ps(dummy_mask,fscal);
1970 /* Calculate temporary vectorial force */
1971 tx = _mm_mul_ps(fscal,dx31);
1972 ty = _mm_mul_ps(fscal,dy31);
1973 tz = _mm_mul_ps(fscal,dz31);
1975 /* Update vectorial force */
1976 fix3 = _mm_add_ps(fix3,tx);
1977 fiy3 = _mm_add_ps(fiy3,ty);
1978 fiz3 = _mm_add_ps(fiz3,tz);
1980 fjx1 = _mm_add_ps(fjx1,tx);
1981 fjy1 = _mm_add_ps(fjy1,ty);
1982 fjz1 = _mm_add_ps(fjz1,tz);
1986 /**************************
1987 * CALCULATE INTERACTIONS *
1988 **************************/
1990 if (gmx_mm_any_lt(rsq32,rcutoff2))
1993 /* REACTION-FIELD ELECTROSTATICS */
1994 felec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_mul_ps(rinv32,rinvsq32),krf2));
1996 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
2000 fscal = _mm_and_ps(fscal,cutoff_mask);
2002 fscal = _mm_andnot_ps(dummy_mask,fscal);
2004 /* Calculate temporary vectorial force */
2005 tx = _mm_mul_ps(fscal,dx32);
2006 ty = _mm_mul_ps(fscal,dy32);
2007 tz = _mm_mul_ps(fscal,dz32);
2009 /* Update vectorial force */
2010 fix3 = _mm_add_ps(fix3,tx);
2011 fiy3 = _mm_add_ps(fiy3,ty);
2012 fiz3 = _mm_add_ps(fiz3,tz);
2014 fjx2 = _mm_add_ps(fjx2,tx);
2015 fjy2 = _mm_add_ps(fjy2,ty);
2016 fjz2 = _mm_add_ps(fjz2,tz);
2020 /**************************
2021 * CALCULATE INTERACTIONS *
2022 **************************/
2024 if (gmx_mm_any_lt(rsq33,rcutoff2))
2027 /* REACTION-FIELD ELECTROSTATICS */
2028 felec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_mul_ps(rinv33,rinvsq33),krf2));
2030 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
2034 fscal = _mm_and_ps(fscal,cutoff_mask);
2036 fscal = _mm_andnot_ps(dummy_mask,fscal);
2038 /* Calculate temporary vectorial force */
2039 tx = _mm_mul_ps(fscal,dx33);
2040 ty = _mm_mul_ps(fscal,dy33);
2041 tz = _mm_mul_ps(fscal,dz33);
2043 /* Update vectorial force */
2044 fix3 = _mm_add_ps(fix3,tx);
2045 fiy3 = _mm_add_ps(fiy3,ty);
2046 fiz3 = _mm_add_ps(fiz3,tz);
2048 fjx3 = _mm_add_ps(fjx3,tx);
2049 fjy3 = _mm_add_ps(fjy3,ty);
2050 fjz3 = _mm_add_ps(fjz3,tz);
2054 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2055 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2056 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2057 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2059 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
2060 fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2062 /* Inner loop uses 270 flops */
2065 /* End of innermost loop */
2067 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2068 f+i_coord_offset+DIM,fshift+i_shift_offset);
2070 /* Increment number of inner iterations */
2071 inneriter += j_index_end - j_index_start;
2073 /* Outer loop uses 18 flops */
2076 /* Increment number of outer iterations */
2079 /* Update outer/inner flops */
2081 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_F,outeriter*18 + inneriter*270);