2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_sse2_single.h"
48 #include "kernelutil_x86_sse2_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_sse2_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Water3-Water3
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_sse2_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
92 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
93 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
94 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
95 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
97 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
98 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
99 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
100 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
101 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
102 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
103 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
104 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
106 __m128 dummy_mask,cutoff_mask;
107 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
108 __m128 one = _mm_set1_ps(1.0);
109 __m128 two = _mm_set1_ps(2.0);
115 jindex = nlist->jindex;
117 shiftidx = nlist->shift;
119 shiftvec = fr->shift_vec[0];
120 fshift = fr->fshift[0];
121 facel = _mm_set1_ps(fr->epsfac);
122 charge = mdatoms->chargeA;
123 krf = _mm_set1_ps(fr->ic->k_rf);
124 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
125 crf = _mm_set1_ps(fr->ic->c_rf);
127 /* Setup water-specific parameters */
128 inr = nlist->iinr[0];
129 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
130 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
131 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
133 jq0 = _mm_set1_ps(charge[inr+0]);
134 jq1 = _mm_set1_ps(charge[inr+1]);
135 jq2 = _mm_set1_ps(charge[inr+2]);
136 qq00 = _mm_mul_ps(iq0,jq0);
137 qq01 = _mm_mul_ps(iq0,jq1);
138 qq02 = _mm_mul_ps(iq0,jq2);
139 qq10 = _mm_mul_ps(iq1,jq0);
140 qq11 = _mm_mul_ps(iq1,jq1);
141 qq12 = _mm_mul_ps(iq1,jq2);
142 qq20 = _mm_mul_ps(iq2,jq0);
143 qq21 = _mm_mul_ps(iq2,jq1);
144 qq22 = _mm_mul_ps(iq2,jq2);
146 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
147 rcutoff_scalar = fr->rcoulomb;
148 rcutoff = _mm_set1_ps(rcutoff_scalar);
149 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
151 /* Avoid stupid compiler warnings */
152 jnrA = jnrB = jnrC = jnrD = 0;
161 for(iidx=0;iidx<4*DIM;iidx++)
166 /* Start outer loop over neighborlists */
167 for(iidx=0; iidx<nri; iidx++)
169 /* Load shift vector for this list */
170 i_shift_offset = DIM*shiftidx[iidx];
172 /* Load limits for loop over neighbors */
173 j_index_start = jindex[iidx];
174 j_index_end = jindex[iidx+1];
176 /* Get outer coordinate index */
178 i_coord_offset = DIM*inr;
180 /* Load i particle coords and add shift vector */
181 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
182 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
184 fix0 = _mm_setzero_ps();
185 fiy0 = _mm_setzero_ps();
186 fiz0 = _mm_setzero_ps();
187 fix1 = _mm_setzero_ps();
188 fiy1 = _mm_setzero_ps();
189 fiz1 = _mm_setzero_ps();
190 fix2 = _mm_setzero_ps();
191 fiy2 = _mm_setzero_ps();
192 fiz2 = _mm_setzero_ps();
194 /* Reset potential sums */
195 velecsum = _mm_setzero_ps();
197 /* Start inner kernel loop */
198 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
201 /* Get j neighbor index, and coordinate index */
206 j_coord_offsetA = DIM*jnrA;
207 j_coord_offsetB = DIM*jnrB;
208 j_coord_offsetC = DIM*jnrC;
209 j_coord_offsetD = DIM*jnrD;
211 /* load j atom coordinates */
212 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
213 x+j_coord_offsetC,x+j_coord_offsetD,
214 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
216 /* Calculate displacement vector */
217 dx00 = _mm_sub_ps(ix0,jx0);
218 dy00 = _mm_sub_ps(iy0,jy0);
219 dz00 = _mm_sub_ps(iz0,jz0);
220 dx01 = _mm_sub_ps(ix0,jx1);
221 dy01 = _mm_sub_ps(iy0,jy1);
222 dz01 = _mm_sub_ps(iz0,jz1);
223 dx02 = _mm_sub_ps(ix0,jx2);
224 dy02 = _mm_sub_ps(iy0,jy2);
225 dz02 = _mm_sub_ps(iz0,jz2);
226 dx10 = _mm_sub_ps(ix1,jx0);
227 dy10 = _mm_sub_ps(iy1,jy0);
228 dz10 = _mm_sub_ps(iz1,jz0);
229 dx11 = _mm_sub_ps(ix1,jx1);
230 dy11 = _mm_sub_ps(iy1,jy1);
231 dz11 = _mm_sub_ps(iz1,jz1);
232 dx12 = _mm_sub_ps(ix1,jx2);
233 dy12 = _mm_sub_ps(iy1,jy2);
234 dz12 = _mm_sub_ps(iz1,jz2);
235 dx20 = _mm_sub_ps(ix2,jx0);
236 dy20 = _mm_sub_ps(iy2,jy0);
237 dz20 = _mm_sub_ps(iz2,jz0);
238 dx21 = _mm_sub_ps(ix2,jx1);
239 dy21 = _mm_sub_ps(iy2,jy1);
240 dz21 = _mm_sub_ps(iz2,jz1);
241 dx22 = _mm_sub_ps(ix2,jx2);
242 dy22 = _mm_sub_ps(iy2,jy2);
243 dz22 = _mm_sub_ps(iz2,jz2);
245 /* Calculate squared distance and things based on it */
246 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
247 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
248 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
249 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
250 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
251 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
252 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
253 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
254 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
256 rinv00 = gmx_mm_invsqrt_ps(rsq00);
257 rinv01 = gmx_mm_invsqrt_ps(rsq01);
258 rinv02 = gmx_mm_invsqrt_ps(rsq02);
259 rinv10 = gmx_mm_invsqrt_ps(rsq10);
260 rinv11 = gmx_mm_invsqrt_ps(rsq11);
261 rinv12 = gmx_mm_invsqrt_ps(rsq12);
262 rinv20 = gmx_mm_invsqrt_ps(rsq20);
263 rinv21 = gmx_mm_invsqrt_ps(rsq21);
264 rinv22 = gmx_mm_invsqrt_ps(rsq22);
266 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
267 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
268 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
269 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
270 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
271 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
272 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
273 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
274 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
276 fjx0 = _mm_setzero_ps();
277 fjy0 = _mm_setzero_ps();
278 fjz0 = _mm_setzero_ps();
279 fjx1 = _mm_setzero_ps();
280 fjy1 = _mm_setzero_ps();
281 fjz1 = _mm_setzero_ps();
282 fjx2 = _mm_setzero_ps();
283 fjy2 = _mm_setzero_ps();
284 fjz2 = _mm_setzero_ps();
286 /**************************
287 * CALCULATE INTERACTIONS *
288 **************************/
290 if (gmx_mm_any_lt(rsq00,rcutoff2))
293 /* REACTION-FIELD ELECTROSTATICS */
294 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
295 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
297 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
299 /* Update potential sum for this i atom from the interaction with this j atom. */
300 velec = _mm_and_ps(velec,cutoff_mask);
301 velecsum = _mm_add_ps(velecsum,velec);
305 fscal = _mm_and_ps(fscal,cutoff_mask);
307 /* Calculate temporary vectorial force */
308 tx = _mm_mul_ps(fscal,dx00);
309 ty = _mm_mul_ps(fscal,dy00);
310 tz = _mm_mul_ps(fscal,dz00);
312 /* Update vectorial force */
313 fix0 = _mm_add_ps(fix0,tx);
314 fiy0 = _mm_add_ps(fiy0,ty);
315 fiz0 = _mm_add_ps(fiz0,tz);
317 fjx0 = _mm_add_ps(fjx0,tx);
318 fjy0 = _mm_add_ps(fjy0,ty);
319 fjz0 = _mm_add_ps(fjz0,tz);
323 /**************************
324 * CALCULATE INTERACTIONS *
325 **************************/
327 if (gmx_mm_any_lt(rsq01,rcutoff2))
330 /* REACTION-FIELD ELECTROSTATICS */
331 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
332 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
334 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
336 /* Update potential sum for this i atom from the interaction with this j atom. */
337 velec = _mm_and_ps(velec,cutoff_mask);
338 velecsum = _mm_add_ps(velecsum,velec);
342 fscal = _mm_and_ps(fscal,cutoff_mask);
344 /* Calculate temporary vectorial force */
345 tx = _mm_mul_ps(fscal,dx01);
346 ty = _mm_mul_ps(fscal,dy01);
347 tz = _mm_mul_ps(fscal,dz01);
349 /* Update vectorial force */
350 fix0 = _mm_add_ps(fix0,tx);
351 fiy0 = _mm_add_ps(fiy0,ty);
352 fiz0 = _mm_add_ps(fiz0,tz);
354 fjx1 = _mm_add_ps(fjx1,tx);
355 fjy1 = _mm_add_ps(fjy1,ty);
356 fjz1 = _mm_add_ps(fjz1,tz);
360 /**************************
361 * CALCULATE INTERACTIONS *
362 **************************/
364 if (gmx_mm_any_lt(rsq02,rcutoff2))
367 /* REACTION-FIELD ELECTROSTATICS */
368 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
369 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
371 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
373 /* Update potential sum for this i atom from the interaction with this j atom. */
374 velec = _mm_and_ps(velec,cutoff_mask);
375 velecsum = _mm_add_ps(velecsum,velec);
379 fscal = _mm_and_ps(fscal,cutoff_mask);
381 /* Calculate temporary vectorial force */
382 tx = _mm_mul_ps(fscal,dx02);
383 ty = _mm_mul_ps(fscal,dy02);
384 tz = _mm_mul_ps(fscal,dz02);
386 /* Update vectorial force */
387 fix0 = _mm_add_ps(fix0,tx);
388 fiy0 = _mm_add_ps(fiy0,ty);
389 fiz0 = _mm_add_ps(fiz0,tz);
391 fjx2 = _mm_add_ps(fjx2,tx);
392 fjy2 = _mm_add_ps(fjy2,ty);
393 fjz2 = _mm_add_ps(fjz2,tz);
397 /**************************
398 * CALCULATE INTERACTIONS *
399 **************************/
401 if (gmx_mm_any_lt(rsq10,rcutoff2))
404 /* REACTION-FIELD ELECTROSTATICS */
405 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
406 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
408 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
410 /* Update potential sum for this i atom from the interaction with this j atom. */
411 velec = _mm_and_ps(velec,cutoff_mask);
412 velecsum = _mm_add_ps(velecsum,velec);
416 fscal = _mm_and_ps(fscal,cutoff_mask);
418 /* Calculate temporary vectorial force */
419 tx = _mm_mul_ps(fscal,dx10);
420 ty = _mm_mul_ps(fscal,dy10);
421 tz = _mm_mul_ps(fscal,dz10);
423 /* Update vectorial force */
424 fix1 = _mm_add_ps(fix1,tx);
425 fiy1 = _mm_add_ps(fiy1,ty);
426 fiz1 = _mm_add_ps(fiz1,tz);
428 fjx0 = _mm_add_ps(fjx0,tx);
429 fjy0 = _mm_add_ps(fjy0,ty);
430 fjz0 = _mm_add_ps(fjz0,tz);
434 /**************************
435 * CALCULATE INTERACTIONS *
436 **************************/
438 if (gmx_mm_any_lt(rsq11,rcutoff2))
441 /* REACTION-FIELD ELECTROSTATICS */
442 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
443 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
445 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
447 /* Update potential sum for this i atom from the interaction with this j atom. */
448 velec = _mm_and_ps(velec,cutoff_mask);
449 velecsum = _mm_add_ps(velecsum,velec);
453 fscal = _mm_and_ps(fscal,cutoff_mask);
455 /* Calculate temporary vectorial force */
456 tx = _mm_mul_ps(fscal,dx11);
457 ty = _mm_mul_ps(fscal,dy11);
458 tz = _mm_mul_ps(fscal,dz11);
460 /* Update vectorial force */
461 fix1 = _mm_add_ps(fix1,tx);
462 fiy1 = _mm_add_ps(fiy1,ty);
463 fiz1 = _mm_add_ps(fiz1,tz);
465 fjx1 = _mm_add_ps(fjx1,tx);
466 fjy1 = _mm_add_ps(fjy1,ty);
467 fjz1 = _mm_add_ps(fjz1,tz);
471 /**************************
472 * CALCULATE INTERACTIONS *
473 **************************/
475 if (gmx_mm_any_lt(rsq12,rcutoff2))
478 /* REACTION-FIELD ELECTROSTATICS */
479 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
480 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
482 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
484 /* Update potential sum for this i atom from the interaction with this j atom. */
485 velec = _mm_and_ps(velec,cutoff_mask);
486 velecsum = _mm_add_ps(velecsum,velec);
490 fscal = _mm_and_ps(fscal,cutoff_mask);
492 /* Calculate temporary vectorial force */
493 tx = _mm_mul_ps(fscal,dx12);
494 ty = _mm_mul_ps(fscal,dy12);
495 tz = _mm_mul_ps(fscal,dz12);
497 /* Update vectorial force */
498 fix1 = _mm_add_ps(fix1,tx);
499 fiy1 = _mm_add_ps(fiy1,ty);
500 fiz1 = _mm_add_ps(fiz1,tz);
502 fjx2 = _mm_add_ps(fjx2,tx);
503 fjy2 = _mm_add_ps(fjy2,ty);
504 fjz2 = _mm_add_ps(fjz2,tz);
508 /**************************
509 * CALCULATE INTERACTIONS *
510 **************************/
512 if (gmx_mm_any_lt(rsq20,rcutoff2))
515 /* REACTION-FIELD ELECTROSTATICS */
516 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
517 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
519 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
521 /* Update potential sum for this i atom from the interaction with this j atom. */
522 velec = _mm_and_ps(velec,cutoff_mask);
523 velecsum = _mm_add_ps(velecsum,velec);
527 fscal = _mm_and_ps(fscal,cutoff_mask);
529 /* Calculate temporary vectorial force */
530 tx = _mm_mul_ps(fscal,dx20);
531 ty = _mm_mul_ps(fscal,dy20);
532 tz = _mm_mul_ps(fscal,dz20);
534 /* Update vectorial force */
535 fix2 = _mm_add_ps(fix2,tx);
536 fiy2 = _mm_add_ps(fiy2,ty);
537 fiz2 = _mm_add_ps(fiz2,tz);
539 fjx0 = _mm_add_ps(fjx0,tx);
540 fjy0 = _mm_add_ps(fjy0,ty);
541 fjz0 = _mm_add_ps(fjz0,tz);
545 /**************************
546 * CALCULATE INTERACTIONS *
547 **************************/
549 if (gmx_mm_any_lt(rsq21,rcutoff2))
552 /* REACTION-FIELD ELECTROSTATICS */
553 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
554 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
556 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
558 /* Update potential sum for this i atom from the interaction with this j atom. */
559 velec = _mm_and_ps(velec,cutoff_mask);
560 velecsum = _mm_add_ps(velecsum,velec);
564 fscal = _mm_and_ps(fscal,cutoff_mask);
566 /* Calculate temporary vectorial force */
567 tx = _mm_mul_ps(fscal,dx21);
568 ty = _mm_mul_ps(fscal,dy21);
569 tz = _mm_mul_ps(fscal,dz21);
571 /* Update vectorial force */
572 fix2 = _mm_add_ps(fix2,tx);
573 fiy2 = _mm_add_ps(fiy2,ty);
574 fiz2 = _mm_add_ps(fiz2,tz);
576 fjx1 = _mm_add_ps(fjx1,tx);
577 fjy1 = _mm_add_ps(fjy1,ty);
578 fjz1 = _mm_add_ps(fjz1,tz);
582 /**************************
583 * CALCULATE INTERACTIONS *
584 **************************/
586 if (gmx_mm_any_lt(rsq22,rcutoff2))
589 /* REACTION-FIELD ELECTROSTATICS */
590 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
591 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
593 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
595 /* Update potential sum for this i atom from the interaction with this j atom. */
596 velec = _mm_and_ps(velec,cutoff_mask);
597 velecsum = _mm_add_ps(velecsum,velec);
601 fscal = _mm_and_ps(fscal,cutoff_mask);
603 /* Calculate temporary vectorial force */
604 tx = _mm_mul_ps(fscal,dx22);
605 ty = _mm_mul_ps(fscal,dy22);
606 tz = _mm_mul_ps(fscal,dz22);
608 /* Update vectorial force */
609 fix2 = _mm_add_ps(fix2,tx);
610 fiy2 = _mm_add_ps(fiy2,ty);
611 fiz2 = _mm_add_ps(fiz2,tz);
613 fjx2 = _mm_add_ps(fjx2,tx);
614 fjy2 = _mm_add_ps(fjy2,ty);
615 fjz2 = _mm_add_ps(fjz2,tz);
619 fjptrA = f+j_coord_offsetA;
620 fjptrB = f+j_coord_offsetB;
621 fjptrC = f+j_coord_offsetC;
622 fjptrD = f+j_coord_offsetD;
624 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
625 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
627 /* Inner loop uses 324 flops */
633 /* Get j neighbor index, and coordinate index */
634 jnrlistA = jjnr[jidx];
635 jnrlistB = jjnr[jidx+1];
636 jnrlistC = jjnr[jidx+2];
637 jnrlistD = jjnr[jidx+3];
638 /* Sign of each element will be negative for non-real atoms.
639 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
640 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
642 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
643 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
644 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
645 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
646 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
647 j_coord_offsetA = DIM*jnrA;
648 j_coord_offsetB = DIM*jnrB;
649 j_coord_offsetC = DIM*jnrC;
650 j_coord_offsetD = DIM*jnrD;
652 /* load j atom coordinates */
653 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
654 x+j_coord_offsetC,x+j_coord_offsetD,
655 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
657 /* Calculate displacement vector */
658 dx00 = _mm_sub_ps(ix0,jx0);
659 dy00 = _mm_sub_ps(iy0,jy0);
660 dz00 = _mm_sub_ps(iz0,jz0);
661 dx01 = _mm_sub_ps(ix0,jx1);
662 dy01 = _mm_sub_ps(iy0,jy1);
663 dz01 = _mm_sub_ps(iz0,jz1);
664 dx02 = _mm_sub_ps(ix0,jx2);
665 dy02 = _mm_sub_ps(iy0,jy2);
666 dz02 = _mm_sub_ps(iz0,jz2);
667 dx10 = _mm_sub_ps(ix1,jx0);
668 dy10 = _mm_sub_ps(iy1,jy0);
669 dz10 = _mm_sub_ps(iz1,jz0);
670 dx11 = _mm_sub_ps(ix1,jx1);
671 dy11 = _mm_sub_ps(iy1,jy1);
672 dz11 = _mm_sub_ps(iz1,jz1);
673 dx12 = _mm_sub_ps(ix1,jx2);
674 dy12 = _mm_sub_ps(iy1,jy2);
675 dz12 = _mm_sub_ps(iz1,jz2);
676 dx20 = _mm_sub_ps(ix2,jx0);
677 dy20 = _mm_sub_ps(iy2,jy0);
678 dz20 = _mm_sub_ps(iz2,jz0);
679 dx21 = _mm_sub_ps(ix2,jx1);
680 dy21 = _mm_sub_ps(iy2,jy1);
681 dz21 = _mm_sub_ps(iz2,jz1);
682 dx22 = _mm_sub_ps(ix2,jx2);
683 dy22 = _mm_sub_ps(iy2,jy2);
684 dz22 = _mm_sub_ps(iz2,jz2);
686 /* Calculate squared distance and things based on it */
687 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
688 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
689 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
690 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
691 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
692 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
693 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
694 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
695 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
697 rinv00 = gmx_mm_invsqrt_ps(rsq00);
698 rinv01 = gmx_mm_invsqrt_ps(rsq01);
699 rinv02 = gmx_mm_invsqrt_ps(rsq02);
700 rinv10 = gmx_mm_invsqrt_ps(rsq10);
701 rinv11 = gmx_mm_invsqrt_ps(rsq11);
702 rinv12 = gmx_mm_invsqrt_ps(rsq12);
703 rinv20 = gmx_mm_invsqrt_ps(rsq20);
704 rinv21 = gmx_mm_invsqrt_ps(rsq21);
705 rinv22 = gmx_mm_invsqrt_ps(rsq22);
707 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
708 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
709 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
710 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
711 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
712 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
713 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
714 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
715 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
717 fjx0 = _mm_setzero_ps();
718 fjy0 = _mm_setzero_ps();
719 fjz0 = _mm_setzero_ps();
720 fjx1 = _mm_setzero_ps();
721 fjy1 = _mm_setzero_ps();
722 fjz1 = _mm_setzero_ps();
723 fjx2 = _mm_setzero_ps();
724 fjy2 = _mm_setzero_ps();
725 fjz2 = _mm_setzero_ps();
727 /**************************
728 * CALCULATE INTERACTIONS *
729 **************************/
731 if (gmx_mm_any_lt(rsq00,rcutoff2))
734 /* REACTION-FIELD ELECTROSTATICS */
735 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
736 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
738 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
740 /* Update potential sum for this i atom from the interaction with this j atom. */
741 velec = _mm_and_ps(velec,cutoff_mask);
742 velec = _mm_andnot_ps(dummy_mask,velec);
743 velecsum = _mm_add_ps(velecsum,velec);
747 fscal = _mm_and_ps(fscal,cutoff_mask);
749 fscal = _mm_andnot_ps(dummy_mask,fscal);
751 /* Calculate temporary vectorial force */
752 tx = _mm_mul_ps(fscal,dx00);
753 ty = _mm_mul_ps(fscal,dy00);
754 tz = _mm_mul_ps(fscal,dz00);
756 /* Update vectorial force */
757 fix0 = _mm_add_ps(fix0,tx);
758 fiy0 = _mm_add_ps(fiy0,ty);
759 fiz0 = _mm_add_ps(fiz0,tz);
761 fjx0 = _mm_add_ps(fjx0,tx);
762 fjy0 = _mm_add_ps(fjy0,ty);
763 fjz0 = _mm_add_ps(fjz0,tz);
767 /**************************
768 * CALCULATE INTERACTIONS *
769 **************************/
771 if (gmx_mm_any_lt(rsq01,rcutoff2))
774 /* REACTION-FIELD ELECTROSTATICS */
775 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
776 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
778 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
780 /* Update potential sum for this i atom from the interaction with this j atom. */
781 velec = _mm_and_ps(velec,cutoff_mask);
782 velec = _mm_andnot_ps(dummy_mask,velec);
783 velecsum = _mm_add_ps(velecsum,velec);
787 fscal = _mm_and_ps(fscal,cutoff_mask);
789 fscal = _mm_andnot_ps(dummy_mask,fscal);
791 /* Calculate temporary vectorial force */
792 tx = _mm_mul_ps(fscal,dx01);
793 ty = _mm_mul_ps(fscal,dy01);
794 tz = _mm_mul_ps(fscal,dz01);
796 /* Update vectorial force */
797 fix0 = _mm_add_ps(fix0,tx);
798 fiy0 = _mm_add_ps(fiy0,ty);
799 fiz0 = _mm_add_ps(fiz0,tz);
801 fjx1 = _mm_add_ps(fjx1,tx);
802 fjy1 = _mm_add_ps(fjy1,ty);
803 fjz1 = _mm_add_ps(fjz1,tz);
807 /**************************
808 * CALCULATE INTERACTIONS *
809 **************************/
811 if (gmx_mm_any_lt(rsq02,rcutoff2))
814 /* REACTION-FIELD ELECTROSTATICS */
815 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
816 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
818 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
820 /* Update potential sum for this i atom from the interaction with this j atom. */
821 velec = _mm_and_ps(velec,cutoff_mask);
822 velec = _mm_andnot_ps(dummy_mask,velec);
823 velecsum = _mm_add_ps(velecsum,velec);
827 fscal = _mm_and_ps(fscal,cutoff_mask);
829 fscal = _mm_andnot_ps(dummy_mask,fscal);
831 /* Calculate temporary vectorial force */
832 tx = _mm_mul_ps(fscal,dx02);
833 ty = _mm_mul_ps(fscal,dy02);
834 tz = _mm_mul_ps(fscal,dz02);
836 /* Update vectorial force */
837 fix0 = _mm_add_ps(fix0,tx);
838 fiy0 = _mm_add_ps(fiy0,ty);
839 fiz0 = _mm_add_ps(fiz0,tz);
841 fjx2 = _mm_add_ps(fjx2,tx);
842 fjy2 = _mm_add_ps(fjy2,ty);
843 fjz2 = _mm_add_ps(fjz2,tz);
847 /**************************
848 * CALCULATE INTERACTIONS *
849 **************************/
851 if (gmx_mm_any_lt(rsq10,rcutoff2))
854 /* REACTION-FIELD ELECTROSTATICS */
855 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
856 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
858 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
860 /* Update potential sum for this i atom from the interaction with this j atom. */
861 velec = _mm_and_ps(velec,cutoff_mask);
862 velec = _mm_andnot_ps(dummy_mask,velec);
863 velecsum = _mm_add_ps(velecsum,velec);
867 fscal = _mm_and_ps(fscal,cutoff_mask);
869 fscal = _mm_andnot_ps(dummy_mask,fscal);
871 /* Calculate temporary vectorial force */
872 tx = _mm_mul_ps(fscal,dx10);
873 ty = _mm_mul_ps(fscal,dy10);
874 tz = _mm_mul_ps(fscal,dz10);
876 /* Update vectorial force */
877 fix1 = _mm_add_ps(fix1,tx);
878 fiy1 = _mm_add_ps(fiy1,ty);
879 fiz1 = _mm_add_ps(fiz1,tz);
881 fjx0 = _mm_add_ps(fjx0,tx);
882 fjy0 = _mm_add_ps(fjy0,ty);
883 fjz0 = _mm_add_ps(fjz0,tz);
887 /**************************
888 * CALCULATE INTERACTIONS *
889 **************************/
891 if (gmx_mm_any_lt(rsq11,rcutoff2))
894 /* REACTION-FIELD ELECTROSTATICS */
895 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
896 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
898 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
900 /* Update potential sum for this i atom from the interaction with this j atom. */
901 velec = _mm_and_ps(velec,cutoff_mask);
902 velec = _mm_andnot_ps(dummy_mask,velec);
903 velecsum = _mm_add_ps(velecsum,velec);
907 fscal = _mm_and_ps(fscal,cutoff_mask);
909 fscal = _mm_andnot_ps(dummy_mask,fscal);
911 /* Calculate temporary vectorial force */
912 tx = _mm_mul_ps(fscal,dx11);
913 ty = _mm_mul_ps(fscal,dy11);
914 tz = _mm_mul_ps(fscal,dz11);
916 /* Update vectorial force */
917 fix1 = _mm_add_ps(fix1,tx);
918 fiy1 = _mm_add_ps(fiy1,ty);
919 fiz1 = _mm_add_ps(fiz1,tz);
921 fjx1 = _mm_add_ps(fjx1,tx);
922 fjy1 = _mm_add_ps(fjy1,ty);
923 fjz1 = _mm_add_ps(fjz1,tz);
927 /**************************
928 * CALCULATE INTERACTIONS *
929 **************************/
931 if (gmx_mm_any_lt(rsq12,rcutoff2))
934 /* REACTION-FIELD ELECTROSTATICS */
935 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
936 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
938 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
940 /* Update potential sum for this i atom from the interaction with this j atom. */
941 velec = _mm_and_ps(velec,cutoff_mask);
942 velec = _mm_andnot_ps(dummy_mask,velec);
943 velecsum = _mm_add_ps(velecsum,velec);
947 fscal = _mm_and_ps(fscal,cutoff_mask);
949 fscal = _mm_andnot_ps(dummy_mask,fscal);
951 /* Calculate temporary vectorial force */
952 tx = _mm_mul_ps(fscal,dx12);
953 ty = _mm_mul_ps(fscal,dy12);
954 tz = _mm_mul_ps(fscal,dz12);
956 /* Update vectorial force */
957 fix1 = _mm_add_ps(fix1,tx);
958 fiy1 = _mm_add_ps(fiy1,ty);
959 fiz1 = _mm_add_ps(fiz1,tz);
961 fjx2 = _mm_add_ps(fjx2,tx);
962 fjy2 = _mm_add_ps(fjy2,ty);
963 fjz2 = _mm_add_ps(fjz2,tz);
967 /**************************
968 * CALCULATE INTERACTIONS *
969 **************************/
971 if (gmx_mm_any_lt(rsq20,rcutoff2))
974 /* REACTION-FIELD ELECTROSTATICS */
975 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
976 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
978 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
980 /* Update potential sum for this i atom from the interaction with this j atom. */
981 velec = _mm_and_ps(velec,cutoff_mask);
982 velec = _mm_andnot_ps(dummy_mask,velec);
983 velecsum = _mm_add_ps(velecsum,velec);
987 fscal = _mm_and_ps(fscal,cutoff_mask);
989 fscal = _mm_andnot_ps(dummy_mask,fscal);
991 /* Calculate temporary vectorial force */
992 tx = _mm_mul_ps(fscal,dx20);
993 ty = _mm_mul_ps(fscal,dy20);
994 tz = _mm_mul_ps(fscal,dz20);
996 /* Update vectorial force */
997 fix2 = _mm_add_ps(fix2,tx);
998 fiy2 = _mm_add_ps(fiy2,ty);
999 fiz2 = _mm_add_ps(fiz2,tz);
1001 fjx0 = _mm_add_ps(fjx0,tx);
1002 fjy0 = _mm_add_ps(fjy0,ty);
1003 fjz0 = _mm_add_ps(fjz0,tz);
1007 /**************************
1008 * CALCULATE INTERACTIONS *
1009 **************************/
1011 if (gmx_mm_any_lt(rsq21,rcutoff2))
1014 /* REACTION-FIELD ELECTROSTATICS */
1015 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
1016 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1018 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1020 /* Update potential sum for this i atom from the interaction with this j atom. */
1021 velec = _mm_and_ps(velec,cutoff_mask);
1022 velec = _mm_andnot_ps(dummy_mask,velec);
1023 velecsum = _mm_add_ps(velecsum,velec);
1027 fscal = _mm_and_ps(fscal,cutoff_mask);
1029 fscal = _mm_andnot_ps(dummy_mask,fscal);
1031 /* Calculate temporary vectorial force */
1032 tx = _mm_mul_ps(fscal,dx21);
1033 ty = _mm_mul_ps(fscal,dy21);
1034 tz = _mm_mul_ps(fscal,dz21);
1036 /* Update vectorial force */
1037 fix2 = _mm_add_ps(fix2,tx);
1038 fiy2 = _mm_add_ps(fiy2,ty);
1039 fiz2 = _mm_add_ps(fiz2,tz);
1041 fjx1 = _mm_add_ps(fjx1,tx);
1042 fjy1 = _mm_add_ps(fjy1,ty);
1043 fjz1 = _mm_add_ps(fjz1,tz);
1047 /**************************
1048 * CALCULATE INTERACTIONS *
1049 **************************/
1051 if (gmx_mm_any_lt(rsq22,rcutoff2))
1054 /* REACTION-FIELD ELECTROSTATICS */
1055 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1056 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1058 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1060 /* Update potential sum for this i atom from the interaction with this j atom. */
1061 velec = _mm_and_ps(velec,cutoff_mask);
1062 velec = _mm_andnot_ps(dummy_mask,velec);
1063 velecsum = _mm_add_ps(velecsum,velec);
1067 fscal = _mm_and_ps(fscal,cutoff_mask);
1069 fscal = _mm_andnot_ps(dummy_mask,fscal);
1071 /* Calculate temporary vectorial force */
1072 tx = _mm_mul_ps(fscal,dx22);
1073 ty = _mm_mul_ps(fscal,dy22);
1074 tz = _mm_mul_ps(fscal,dz22);
1076 /* Update vectorial force */
1077 fix2 = _mm_add_ps(fix2,tx);
1078 fiy2 = _mm_add_ps(fiy2,ty);
1079 fiz2 = _mm_add_ps(fiz2,tz);
1081 fjx2 = _mm_add_ps(fjx2,tx);
1082 fjy2 = _mm_add_ps(fjy2,ty);
1083 fjz2 = _mm_add_ps(fjz2,tz);
1087 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1088 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1089 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1090 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1092 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1093 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1095 /* Inner loop uses 324 flops */
1098 /* End of innermost loop */
1100 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1101 f+i_coord_offset,fshift+i_shift_offset);
1104 /* Update potential energies */
1105 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1107 /* Increment number of inner iterations */
1108 inneriter += j_index_end - j_index_start;
1110 /* Outer loop uses 19 flops */
1113 /* Increment number of outer iterations */
1116 /* Update outer/inner flops */
1118 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_VF,outeriter*19 + inneriter*324);
1121 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_sse2_single
1122 * Electrostatics interaction: ReactionField
1123 * VdW interaction: None
1124 * Geometry: Water3-Water3
1125 * Calculate force/pot: Force
1128 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_sse2_single
1129 (t_nblist * gmx_restrict nlist,
1130 rvec * gmx_restrict xx,
1131 rvec * gmx_restrict ff,
1132 t_forcerec * gmx_restrict fr,
1133 t_mdatoms * gmx_restrict mdatoms,
1134 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1135 t_nrnb * gmx_restrict nrnb)
1137 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1138 * just 0 for non-waters.
1139 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1140 * jnr indices corresponding to data put in the four positions in the SIMD register.
1142 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1143 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1144 int jnrA,jnrB,jnrC,jnrD;
1145 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1146 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1147 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1148 real rcutoff_scalar;
1149 real *shiftvec,*fshift,*x,*f;
1150 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1151 real scratch[4*DIM];
1152 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1154 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1156 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1158 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1159 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1160 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1161 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1162 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1163 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1164 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1165 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1166 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1167 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1168 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1169 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1170 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1171 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1172 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1173 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1174 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1176 __m128 dummy_mask,cutoff_mask;
1177 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1178 __m128 one = _mm_set1_ps(1.0);
1179 __m128 two = _mm_set1_ps(2.0);
1185 jindex = nlist->jindex;
1187 shiftidx = nlist->shift;
1189 shiftvec = fr->shift_vec[0];
1190 fshift = fr->fshift[0];
1191 facel = _mm_set1_ps(fr->epsfac);
1192 charge = mdatoms->chargeA;
1193 krf = _mm_set1_ps(fr->ic->k_rf);
1194 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1195 crf = _mm_set1_ps(fr->ic->c_rf);
1197 /* Setup water-specific parameters */
1198 inr = nlist->iinr[0];
1199 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1200 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1201 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1203 jq0 = _mm_set1_ps(charge[inr+0]);
1204 jq1 = _mm_set1_ps(charge[inr+1]);
1205 jq2 = _mm_set1_ps(charge[inr+2]);
1206 qq00 = _mm_mul_ps(iq0,jq0);
1207 qq01 = _mm_mul_ps(iq0,jq1);
1208 qq02 = _mm_mul_ps(iq0,jq2);
1209 qq10 = _mm_mul_ps(iq1,jq0);
1210 qq11 = _mm_mul_ps(iq1,jq1);
1211 qq12 = _mm_mul_ps(iq1,jq2);
1212 qq20 = _mm_mul_ps(iq2,jq0);
1213 qq21 = _mm_mul_ps(iq2,jq1);
1214 qq22 = _mm_mul_ps(iq2,jq2);
1216 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1217 rcutoff_scalar = fr->rcoulomb;
1218 rcutoff = _mm_set1_ps(rcutoff_scalar);
1219 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1221 /* Avoid stupid compiler warnings */
1222 jnrA = jnrB = jnrC = jnrD = 0;
1223 j_coord_offsetA = 0;
1224 j_coord_offsetB = 0;
1225 j_coord_offsetC = 0;
1226 j_coord_offsetD = 0;
1231 for(iidx=0;iidx<4*DIM;iidx++)
1233 scratch[iidx] = 0.0;
1236 /* Start outer loop over neighborlists */
1237 for(iidx=0; iidx<nri; iidx++)
1239 /* Load shift vector for this list */
1240 i_shift_offset = DIM*shiftidx[iidx];
1242 /* Load limits for loop over neighbors */
1243 j_index_start = jindex[iidx];
1244 j_index_end = jindex[iidx+1];
1246 /* Get outer coordinate index */
1248 i_coord_offset = DIM*inr;
1250 /* Load i particle coords and add shift vector */
1251 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1252 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1254 fix0 = _mm_setzero_ps();
1255 fiy0 = _mm_setzero_ps();
1256 fiz0 = _mm_setzero_ps();
1257 fix1 = _mm_setzero_ps();
1258 fiy1 = _mm_setzero_ps();
1259 fiz1 = _mm_setzero_ps();
1260 fix2 = _mm_setzero_ps();
1261 fiy2 = _mm_setzero_ps();
1262 fiz2 = _mm_setzero_ps();
1264 /* Start inner kernel loop */
1265 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1268 /* Get j neighbor index, and coordinate index */
1270 jnrB = jjnr[jidx+1];
1271 jnrC = jjnr[jidx+2];
1272 jnrD = jjnr[jidx+3];
1273 j_coord_offsetA = DIM*jnrA;
1274 j_coord_offsetB = DIM*jnrB;
1275 j_coord_offsetC = DIM*jnrC;
1276 j_coord_offsetD = DIM*jnrD;
1278 /* load j atom coordinates */
1279 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1280 x+j_coord_offsetC,x+j_coord_offsetD,
1281 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1283 /* Calculate displacement vector */
1284 dx00 = _mm_sub_ps(ix0,jx0);
1285 dy00 = _mm_sub_ps(iy0,jy0);
1286 dz00 = _mm_sub_ps(iz0,jz0);
1287 dx01 = _mm_sub_ps(ix0,jx1);
1288 dy01 = _mm_sub_ps(iy0,jy1);
1289 dz01 = _mm_sub_ps(iz0,jz1);
1290 dx02 = _mm_sub_ps(ix0,jx2);
1291 dy02 = _mm_sub_ps(iy0,jy2);
1292 dz02 = _mm_sub_ps(iz0,jz2);
1293 dx10 = _mm_sub_ps(ix1,jx0);
1294 dy10 = _mm_sub_ps(iy1,jy0);
1295 dz10 = _mm_sub_ps(iz1,jz0);
1296 dx11 = _mm_sub_ps(ix1,jx1);
1297 dy11 = _mm_sub_ps(iy1,jy1);
1298 dz11 = _mm_sub_ps(iz1,jz1);
1299 dx12 = _mm_sub_ps(ix1,jx2);
1300 dy12 = _mm_sub_ps(iy1,jy2);
1301 dz12 = _mm_sub_ps(iz1,jz2);
1302 dx20 = _mm_sub_ps(ix2,jx0);
1303 dy20 = _mm_sub_ps(iy2,jy0);
1304 dz20 = _mm_sub_ps(iz2,jz0);
1305 dx21 = _mm_sub_ps(ix2,jx1);
1306 dy21 = _mm_sub_ps(iy2,jy1);
1307 dz21 = _mm_sub_ps(iz2,jz1);
1308 dx22 = _mm_sub_ps(ix2,jx2);
1309 dy22 = _mm_sub_ps(iy2,jy2);
1310 dz22 = _mm_sub_ps(iz2,jz2);
1312 /* Calculate squared distance and things based on it */
1313 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1314 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1315 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1316 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1317 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1318 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1319 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1320 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1321 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1323 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1324 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1325 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1326 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1327 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1328 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1329 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1330 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1331 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1333 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1334 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1335 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1336 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1337 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1338 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1339 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1340 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1341 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1343 fjx0 = _mm_setzero_ps();
1344 fjy0 = _mm_setzero_ps();
1345 fjz0 = _mm_setzero_ps();
1346 fjx1 = _mm_setzero_ps();
1347 fjy1 = _mm_setzero_ps();
1348 fjz1 = _mm_setzero_ps();
1349 fjx2 = _mm_setzero_ps();
1350 fjy2 = _mm_setzero_ps();
1351 fjz2 = _mm_setzero_ps();
1353 /**************************
1354 * CALCULATE INTERACTIONS *
1355 **************************/
1357 if (gmx_mm_any_lt(rsq00,rcutoff2))
1360 /* REACTION-FIELD ELECTROSTATICS */
1361 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1363 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1367 fscal = _mm_and_ps(fscal,cutoff_mask);
1369 /* Calculate temporary vectorial force */
1370 tx = _mm_mul_ps(fscal,dx00);
1371 ty = _mm_mul_ps(fscal,dy00);
1372 tz = _mm_mul_ps(fscal,dz00);
1374 /* Update vectorial force */
1375 fix0 = _mm_add_ps(fix0,tx);
1376 fiy0 = _mm_add_ps(fiy0,ty);
1377 fiz0 = _mm_add_ps(fiz0,tz);
1379 fjx0 = _mm_add_ps(fjx0,tx);
1380 fjy0 = _mm_add_ps(fjy0,ty);
1381 fjz0 = _mm_add_ps(fjz0,tz);
1385 /**************************
1386 * CALCULATE INTERACTIONS *
1387 **************************/
1389 if (gmx_mm_any_lt(rsq01,rcutoff2))
1392 /* REACTION-FIELD ELECTROSTATICS */
1393 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1395 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1399 fscal = _mm_and_ps(fscal,cutoff_mask);
1401 /* Calculate temporary vectorial force */
1402 tx = _mm_mul_ps(fscal,dx01);
1403 ty = _mm_mul_ps(fscal,dy01);
1404 tz = _mm_mul_ps(fscal,dz01);
1406 /* Update vectorial force */
1407 fix0 = _mm_add_ps(fix0,tx);
1408 fiy0 = _mm_add_ps(fiy0,ty);
1409 fiz0 = _mm_add_ps(fiz0,tz);
1411 fjx1 = _mm_add_ps(fjx1,tx);
1412 fjy1 = _mm_add_ps(fjy1,ty);
1413 fjz1 = _mm_add_ps(fjz1,tz);
1417 /**************************
1418 * CALCULATE INTERACTIONS *
1419 **************************/
1421 if (gmx_mm_any_lt(rsq02,rcutoff2))
1424 /* REACTION-FIELD ELECTROSTATICS */
1425 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1427 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1431 fscal = _mm_and_ps(fscal,cutoff_mask);
1433 /* Calculate temporary vectorial force */
1434 tx = _mm_mul_ps(fscal,dx02);
1435 ty = _mm_mul_ps(fscal,dy02);
1436 tz = _mm_mul_ps(fscal,dz02);
1438 /* Update vectorial force */
1439 fix0 = _mm_add_ps(fix0,tx);
1440 fiy0 = _mm_add_ps(fiy0,ty);
1441 fiz0 = _mm_add_ps(fiz0,tz);
1443 fjx2 = _mm_add_ps(fjx2,tx);
1444 fjy2 = _mm_add_ps(fjy2,ty);
1445 fjz2 = _mm_add_ps(fjz2,tz);
1449 /**************************
1450 * CALCULATE INTERACTIONS *
1451 **************************/
1453 if (gmx_mm_any_lt(rsq10,rcutoff2))
1456 /* REACTION-FIELD ELECTROSTATICS */
1457 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1459 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1463 fscal = _mm_and_ps(fscal,cutoff_mask);
1465 /* Calculate temporary vectorial force */
1466 tx = _mm_mul_ps(fscal,dx10);
1467 ty = _mm_mul_ps(fscal,dy10);
1468 tz = _mm_mul_ps(fscal,dz10);
1470 /* Update vectorial force */
1471 fix1 = _mm_add_ps(fix1,tx);
1472 fiy1 = _mm_add_ps(fiy1,ty);
1473 fiz1 = _mm_add_ps(fiz1,tz);
1475 fjx0 = _mm_add_ps(fjx0,tx);
1476 fjy0 = _mm_add_ps(fjy0,ty);
1477 fjz0 = _mm_add_ps(fjz0,tz);
1481 /**************************
1482 * CALCULATE INTERACTIONS *
1483 **************************/
1485 if (gmx_mm_any_lt(rsq11,rcutoff2))
1488 /* REACTION-FIELD ELECTROSTATICS */
1489 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1491 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1495 fscal = _mm_and_ps(fscal,cutoff_mask);
1497 /* Calculate temporary vectorial force */
1498 tx = _mm_mul_ps(fscal,dx11);
1499 ty = _mm_mul_ps(fscal,dy11);
1500 tz = _mm_mul_ps(fscal,dz11);
1502 /* Update vectorial force */
1503 fix1 = _mm_add_ps(fix1,tx);
1504 fiy1 = _mm_add_ps(fiy1,ty);
1505 fiz1 = _mm_add_ps(fiz1,tz);
1507 fjx1 = _mm_add_ps(fjx1,tx);
1508 fjy1 = _mm_add_ps(fjy1,ty);
1509 fjz1 = _mm_add_ps(fjz1,tz);
1513 /**************************
1514 * CALCULATE INTERACTIONS *
1515 **************************/
1517 if (gmx_mm_any_lt(rsq12,rcutoff2))
1520 /* REACTION-FIELD ELECTROSTATICS */
1521 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1523 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1527 fscal = _mm_and_ps(fscal,cutoff_mask);
1529 /* Calculate temporary vectorial force */
1530 tx = _mm_mul_ps(fscal,dx12);
1531 ty = _mm_mul_ps(fscal,dy12);
1532 tz = _mm_mul_ps(fscal,dz12);
1534 /* Update vectorial force */
1535 fix1 = _mm_add_ps(fix1,tx);
1536 fiy1 = _mm_add_ps(fiy1,ty);
1537 fiz1 = _mm_add_ps(fiz1,tz);
1539 fjx2 = _mm_add_ps(fjx2,tx);
1540 fjy2 = _mm_add_ps(fjy2,ty);
1541 fjz2 = _mm_add_ps(fjz2,tz);
1545 /**************************
1546 * CALCULATE INTERACTIONS *
1547 **************************/
1549 if (gmx_mm_any_lt(rsq20,rcutoff2))
1552 /* REACTION-FIELD ELECTROSTATICS */
1553 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1555 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1559 fscal = _mm_and_ps(fscal,cutoff_mask);
1561 /* Calculate temporary vectorial force */
1562 tx = _mm_mul_ps(fscal,dx20);
1563 ty = _mm_mul_ps(fscal,dy20);
1564 tz = _mm_mul_ps(fscal,dz20);
1566 /* Update vectorial force */
1567 fix2 = _mm_add_ps(fix2,tx);
1568 fiy2 = _mm_add_ps(fiy2,ty);
1569 fiz2 = _mm_add_ps(fiz2,tz);
1571 fjx0 = _mm_add_ps(fjx0,tx);
1572 fjy0 = _mm_add_ps(fjy0,ty);
1573 fjz0 = _mm_add_ps(fjz0,tz);
1577 /**************************
1578 * CALCULATE INTERACTIONS *
1579 **************************/
1581 if (gmx_mm_any_lt(rsq21,rcutoff2))
1584 /* REACTION-FIELD ELECTROSTATICS */
1585 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1587 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1591 fscal = _mm_and_ps(fscal,cutoff_mask);
1593 /* Calculate temporary vectorial force */
1594 tx = _mm_mul_ps(fscal,dx21);
1595 ty = _mm_mul_ps(fscal,dy21);
1596 tz = _mm_mul_ps(fscal,dz21);
1598 /* Update vectorial force */
1599 fix2 = _mm_add_ps(fix2,tx);
1600 fiy2 = _mm_add_ps(fiy2,ty);
1601 fiz2 = _mm_add_ps(fiz2,tz);
1603 fjx1 = _mm_add_ps(fjx1,tx);
1604 fjy1 = _mm_add_ps(fjy1,ty);
1605 fjz1 = _mm_add_ps(fjz1,tz);
1609 /**************************
1610 * CALCULATE INTERACTIONS *
1611 **************************/
1613 if (gmx_mm_any_lt(rsq22,rcutoff2))
1616 /* REACTION-FIELD ELECTROSTATICS */
1617 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1619 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1623 fscal = _mm_and_ps(fscal,cutoff_mask);
1625 /* Calculate temporary vectorial force */
1626 tx = _mm_mul_ps(fscal,dx22);
1627 ty = _mm_mul_ps(fscal,dy22);
1628 tz = _mm_mul_ps(fscal,dz22);
1630 /* Update vectorial force */
1631 fix2 = _mm_add_ps(fix2,tx);
1632 fiy2 = _mm_add_ps(fiy2,ty);
1633 fiz2 = _mm_add_ps(fiz2,tz);
1635 fjx2 = _mm_add_ps(fjx2,tx);
1636 fjy2 = _mm_add_ps(fjy2,ty);
1637 fjz2 = _mm_add_ps(fjz2,tz);
1641 fjptrA = f+j_coord_offsetA;
1642 fjptrB = f+j_coord_offsetB;
1643 fjptrC = f+j_coord_offsetC;
1644 fjptrD = f+j_coord_offsetD;
1646 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1647 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1649 /* Inner loop uses 270 flops */
1652 if(jidx<j_index_end)
1655 /* Get j neighbor index, and coordinate index */
1656 jnrlistA = jjnr[jidx];
1657 jnrlistB = jjnr[jidx+1];
1658 jnrlistC = jjnr[jidx+2];
1659 jnrlistD = jjnr[jidx+3];
1660 /* Sign of each element will be negative for non-real atoms.
1661 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1662 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1664 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1665 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1666 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1667 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1668 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1669 j_coord_offsetA = DIM*jnrA;
1670 j_coord_offsetB = DIM*jnrB;
1671 j_coord_offsetC = DIM*jnrC;
1672 j_coord_offsetD = DIM*jnrD;
1674 /* load j atom coordinates */
1675 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1676 x+j_coord_offsetC,x+j_coord_offsetD,
1677 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1679 /* Calculate displacement vector */
1680 dx00 = _mm_sub_ps(ix0,jx0);
1681 dy00 = _mm_sub_ps(iy0,jy0);
1682 dz00 = _mm_sub_ps(iz0,jz0);
1683 dx01 = _mm_sub_ps(ix0,jx1);
1684 dy01 = _mm_sub_ps(iy0,jy1);
1685 dz01 = _mm_sub_ps(iz0,jz1);
1686 dx02 = _mm_sub_ps(ix0,jx2);
1687 dy02 = _mm_sub_ps(iy0,jy2);
1688 dz02 = _mm_sub_ps(iz0,jz2);
1689 dx10 = _mm_sub_ps(ix1,jx0);
1690 dy10 = _mm_sub_ps(iy1,jy0);
1691 dz10 = _mm_sub_ps(iz1,jz0);
1692 dx11 = _mm_sub_ps(ix1,jx1);
1693 dy11 = _mm_sub_ps(iy1,jy1);
1694 dz11 = _mm_sub_ps(iz1,jz1);
1695 dx12 = _mm_sub_ps(ix1,jx2);
1696 dy12 = _mm_sub_ps(iy1,jy2);
1697 dz12 = _mm_sub_ps(iz1,jz2);
1698 dx20 = _mm_sub_ps(ix2,jx0);
1699 dy20 = _mm_sub_ps(iy2,jy0);
1700 dz20 = _mm_sub_ps(iz2,jz0);
1701 dx21 = _mm_sub_ps(ix2,jx1);
1702 dy21 = _mm_sub_ps(iy2,jy1);
1703 dz21 = _mm_sub_ps(iz2,jz1);
1704 dx22 = _mm_sub_ps(ix2,jx2);
1705 dy22 = _mm_sub_ps(iy2,jy2);
1706 dz22 = _mm_sub_ps(iz2,jz2);
1708 /* Calculate squared distance and things based on it */
1709 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1710 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1711 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1712 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1713 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1714 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1715 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1716 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1717 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1719 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1720 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1721 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1722 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1723 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1724 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1725 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1726 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1727 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1729 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1730 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1731 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1732 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1733 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1734 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1735 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1736 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1737 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1739 fjx0 = _mm_setzero_ps();
1740 fjy0 = _mm_setzero_ps();
1741 fjz0 = _mm_setzero_ps();
1742 fjx1 = _mm_setzero_ps();
1743 fjy1 = _mm_setzero_ps();
1744 fjz1 = _mm_setzero_ps();
1745 fjx2 = _mm_setzero_ps();
1746 fjy2 = _mm_setzero_ps();
1747 fjz2 = _mm_setzero_ps();
1749 /**************************
1750 * CALCULATE INTERACTIONS *
1751 **************************/
1753 if (gmx_mm_any_lt(rsq00,rcutoff2))
1756 /* REACTION-FIELD ELECTROSTATICS */
1757 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1759 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1763 fscal = _mm_and_ps(fscal,cutoff_mask);
1765 fscal = _mm_andnot_ps(dummy_mask,fscal);
1767 /* Calculate temporary vectorial force */
1768 tx = _mm_mul_ps(fscal,dx00);
1769 ty = _mm_mul_ps(fscal,dy00);
1770 tz = _mm_mul_ps(fscal,dz00);
1772 /* Update vectorial force */
1773 fix0 = _mm_add_ps(fix0,tx);
1774 fiy0 = _mm_add_ps(fiy0,ty);
1775 fiz0 = _mm_add_ps(fiz0,tz);
1777 fjx0 = _mm_add_ps(fjx0,tx);
1778 fjy0 = _mm_add_ps(fjy0,ty);
1779 fjz0 = _mm_add_ps(fjz0,tz);
1783 /**************************
1784 * CALCULATE INTERACTIONS *
1785 **************************/
1787 if (gmx_mm_any_lt(rsq01,rcutoff2))
1790 /* REACTION-FIELD ELECTROSTATICS */
1791 felec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1793 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1797 fscal = _mm_and_ps(fscal,cutoff_mask);
1799 fscal = _mm_andnot_ps(dummy_mask,fscal);
1801 /* Calculate temporary vectorial force */
1802 tx = _mm_mul_ps(fscal,dx01);
1803 ty = _mm_mul_ps(fscal,dy01);
1804 tz = _mm_mul_ps(fscal,dz01);
1806 /* Update vectorial force */
1807 fix0 = _mm_add_ps(fix0,tx);
1808 fiy0 = _mm_add_ps(fiy0,ty);
1809 fiz0 = _mm_add_ps(fiz0,tz);
1811 fjx1 = _mm_add_ps(fjx1,tx);
1812 fjy1 = _mm_add_ps(fjy1,ty);
1813 fjz1 = _mm_add_ps(fjz1,tz);
1817 /**************************
1818 * CALCULATE INTERACTIONS *
1819 **************************/
1821 if (gmx_mm_any_lt(rsq02,rcutoff2))
1824 /* REACTION-FIELD ELECTROSTATICS */
1825 felec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1827 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1831 fscal = _mm_and_ps(fscal,cutoff_mask);
1833 fscal = _mm_andnot_ps(dummy_mask,fscal);
1835 /* Calculate temporary vectorial force */
1836 tx = _mm_mul_ps(fscal,dx02);
1837 ty = _mm_mul_ps(fscal,dy02);
1838 tz = _mm_mul_ps(fscal,dz02);
1840 /* Update vectorial force */
1841 fix0 = _mm_add_ps(fix0,tx);
1842 fiy0 = _mm_add_ps(fiy0,ty);
1843 fiz0 = _mm_add_ps(fiz0,tz);
1845 fjx2 = _mm_add_ps(fjx2,tx);
1846 fjy2 = _mm_add_ps(fjy2,ty);
1847 fjz2 = _mm_add_ps(fjz2,tz);
1851 /**************************
1852 * CALCULATE INTERACTIONS *
1853 **************************/
1855 if (gmx_mm_any_lt(rsq10,rcutoff2))
1858 /* REACTION-FIELD ELECTROSTATICS */
1859 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1861 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1865 fscal = _mm_and_ps(fscal,cutoff_mask);
1867 fscal = _mm_andnot_ps(dummy_mask,fscal);
1869 /* Calculate temporary vectorial force */
1870 tx = _mm_mul_ps(fscal,dx10);
1871 ty = _mm_mul_ps(fscal,dy10);
1872 tz = _mm_mul_ps(fscal,dz10);
1874 /* Update vectorial force */
1875 fix1 = _mm_add_ps(fix1,tx);
1876 fiy1 = _mm_add_ps(fiy1,ty);
1877 fiz1 = _mm_add_ps(fiz1,tz);
1879 fjx0 = _mm_add_ps(fjx0,tx);
1880 fjy0 = _mm_add_ps(fjy0,ty);
1881 fjz0 = _mm_add_ps(fjz0,tz);
1885 /**************************
1886 * CALCULATE INTERACTIONS *
1887 **************************/
1889 if (gmx_mm_any_lt(rsq11,rcutoff2))
1892 /* REACTION-FIELD ELECTROSTATICS */
1893 felec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1895 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1899 fscal = _mm_and_ps(fscal,cutoff_mask);
1901 fscal = _mm_andnot_ps(dummy_mask,fscal);
1903 /* Calculate temporary vectorial force */
1904 tx = _mm_mul_ps(fscal,dx11);
1905 ty = _mm_mul_ps(fscal,dy11);
1906 tz = _mm_mul_ps(fscal,dz11);
1908 /* Update vectorial force */
1909 fix1 = _mm_add_ps(fix1,tx);
1910 fiy1 = _mm_add_ps(fiy1,ty);
1911 fiz1 = _mm_add_ps(fiz1,tz);
1913 fjx1 = _mm_add_ps(fjx1,tx);
1914 fjy1 = _mm_add_ps(fjy1,ty);
1915 fjz1 = _mm_add_ps(fjz1,tz);
1919 /**************************
1920 * CALCULATE INTERACTIONS *
1921 **************************/
1923 if (gmx_mm_any_lt(rsq12,rcutoff2))
1926 /* REACTION-FIELD ELECTROSTATICS */
1927 felec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1929 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1933 fscal = _mm_and_ps(fscal,cutoff_mask);
1935 fscal = _mm_andnot_ps(dummy_mask,fscal);
1937 /* Calculate temporary vectorial force */
1938 tx = _mm_mul_ps(fscal,dx12);
1939 ty = _mm_mul_ps(fscal,dy12);
1940 tz = _mm_mul_ps(fscal,dz12);
1942 /* Update vectorial force */
1943 fix1 = _mm_add_ps(fix1,tx);
1944 fiy1 = _mm_add_ps(fiy1,ty);
1945 fiz1 = _mm_add_ps(fiz1,tz);
1947 fjx2 = _mm_add_ps(fjx2,tx);
1948 fjy2 = _mm_add_ps(fjy2,ty);
1949 fjz2 = _mm_add_ps(fjz2,tz);
1953 /**************************
1954 * CALCULATE INTERACTIONS *
1955 **************************/
1957 if (gmx_mm_any_lt(rsq20,rcutoff2))
1960 /* REACTION-FIELD ELECTROSTATICS */
1961 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1963 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1967 fscal = _mm_and_ps(fscal,cutoff_mask);
1969 fscal = _mm_andnot_ps(dummy_mask,fscal);
1971 /* Calculate temporary vectorial force */
1972 tx = _mm_mul_ps(fscal,dx20);
1973 ty = _mm_mul_ps(fscal,dy20);
1974 tz = _mm_mul_ps(fscal,dz20);
1976 /* Update vectorial force */
1977 fix2 = _mm_add_ps(fix2,tx);
1978 fiy2 = _mm_add_ps(fiy2,ty);
1979 fiz2 = _mm_add_ps(fiz2,tz);
1981 fjx0 = _mm_add_ps(fjx0,tx);
1982 fjy0 = _mm_add_ps(fjy0,ty);
1983 fjz0 = _mm_add_ps(fjz0,tz);
1987 /**************************
1988 * CALCULATE INTERACTIONS *
1989 **************************/
1991 if (gmx_mm_any_lt(rsq21,rcutoff2))
1994 /* REACTION-FIELD ELECTROSTATICS */
1995 felec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1997 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
2001 fscal = _mm_and_ps(fscal,cutoff_mask);
2003 fscal = _mm_andnot_ps(dummy_mask,fscal);
2005 /* Calculate temporary vectorial force */
2006 tx = _mm_mul_ps(fscal,dx21);
2007 ty = _mm_mul_ps(fscal,dy21);
2008 tz = _mm_mul_ps(fscal,dz21);
2010 /* Update vectorial force */
2011 fix2 = _mm_add_ps(fix2,tx);
2012 fiy2 = _mm_add_ps(fiy2,ty);
2013 fiz2 = _mm_add_ps(fiz2,tz);
2015 fjx1 = _mm_add_ps(fjx1,tx);
2016 fjy1 = _mm_add_ps(fjy1,ty);
2017 fjz1 = _mm_add_ps(fjz1,tz);
2021 /**************************
2022 * CALCULATE INTERACTIONS *
2023 **************************/
2025 if (gmx_mm_any_lt(rsq22,rcutoff2))
2028 /* REACTION-FIELD ELECTROSTATICS */
2029 felec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2031 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
2035 fscal = _mm_and_ps(fscal,cutoff_mask);
2037 fscal = _mm_andnot_ps(dummy_mask,fscal);
2039 /* Calculate temporary vectorial force */
2040 tx = _mm_mul_ps(fscal,dx22);
2041 ty = _mm_mul_ps(fscal,dy22);
2042 tz = _mm_mul_ps(fscal,dz22);
2044 /* Update vectorial force */
2045 fix2 = _mm_add_ps(fix2,tx);
2046 fiy2 = _mm_add_ps(fiy2,ty);
2047 fiz2 = _mm_add_ps(fiz2,tz);
2049 fjx2 = _mm_add_ps(fjx2,tx);
2050 fjy2 = _mm_add_ps(fjy2,ty);
2051 fjz2 = _mm_add_ps(fjz2,tz);
2055 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2056 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2057 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2058 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2060 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2061 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2063 /* Inner loop uses 270 flops */
2066 /* End of innermost loop */
2068 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2069 f+i_coord_offset,fshift+i_shift_offset);
2071 /* Increment number of inner iterations */
2072 inneriter += j_index_end - j_index_start;
2074 /* Outer loop uses 18 flops */
2077 /* Increment number of outer iterations */
2080 /* Update outer/inner flops */
2082 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_F,outeriter*18 + inneriter*270);