2 * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water3-Water3
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
78 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
79 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
80 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
81 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
82 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
83 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
84 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
85 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
86 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
87 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
88 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
89 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
96 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
97 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
98 __m128 dummy_mask,cutoff_mask;
99 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
100 __m128 one = _mm_set1_ps(1.0);
101 __m128 two = _mm_set1_ps(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 facel = _mm_set1_ps(fr->epsfac);
114 charge = mdatoms->chargeA;
115 krf = _mm_set1_ps(fr->ic->k_rf);
116 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
117 crf = _mm_set1_ps(fr->ic->c_rf);
118 nvdwtype = fr->ntype;
120 vdwtype = mdatoms->typeA;
122 /* Setup water-specific parameters */
123 inr = nlist->iinr[0];
124 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
125 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
126 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
127 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
129 jq0 = _mm_set1_ps(charge[inr+0]);
130 jq1 = _mm_set1_ps(charge[inr+1]);
131 jq2 = _mm_set1_ps(charge[inr+2]);
132 vdwjidx0A = 2*vdwtype[inr+0];
133 qq00 = _mm_mul_ps(iq0,jq0);
134 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
135 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
136 qq01 = _mm_mul_ps(iq0,jq1);
137 qq02 = _mm_mul_ps(iq0,jq2);
138 qq10 = _mm_mul_ps(iq1,jq0);
139 qq11 = _mm_mul_ps(iq1,jq1);
140 qq12 = _mm_mul_ps(iq1,jq2);
141 qq20 = _mm_mul_ps(iq2,jq0);
142 qq21 = _mm_mul_ps(iq2,jq1);
143 qq22 = _mm_mul_ps(iq2,jq2);
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->rcoulomb;
147 rcutoff = _mm_set1_ps(rcutoff_scalar);
148 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
150 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
151 rvdw = _mm_set1_ps(fr->rvdw);
153 /* Avoid stupid compiler warnings */
154 jnrA = jnrB = jnrC = jnrD = 0;
163 for(iidx=0;iidx<4*DIM;iidx++)
168 /* Start outer loop over neighborlists */
169 for(iidx=0; iidx<nri; iidx++)
171 /* Load shift vector for this list */
172 i_shift_offset = DIM*shiftidx[iidx];
174 /* Load limits for loop over neighbors */
175 j_index_start = jindex[iidx];
176 j_index_end = jindex[iidx+1];
178 /* Get outer coordinate index */
180 i_coord_offset = DIM*inr;
182 /* Load i particle coords and add shift vector */
183 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
184 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
186 fix0 = _mm_setzero_ps();
187 fiy0 = _mm_setzero_ps();
188 fiz0 = _mm_setzero_ps();
189 fix1 = _mm_setzero_ps();
190 fiy1 = _mm_setzero_ps();
191 fiz1 = _mm_setzero_ps();
192 fix2 = _mm_setzero_ps();
193 fiy2 = _mm_setzero_ps();
194 fiz2 = _mm_setzero_ps();
196 /* Reset potential sums */
197 velecsum = _mm_setzero_ps();
198 vvdwsum = _mm_setzero_ps();
200 /* Start inner kernel loop */
201 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
204 /* Get j neighbor index, and coordinate index */
209 j_coord_offsetA = DIM*jnrA;
210 j_coord_offsetB = DIM*jnrB;
211 j_coord_offsetC = DIM*jnrC;
212 j_coord_offsetD = DIM*jnrD;
214 /* load j atom coordinates */
215 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
216 x+j_coord_offsetC,x+j_coord_offsetD,
217 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
219 /* Calculate displacement vector */
220 dx00 = _mm_sub_ps(ix0,jx0);
221 dy00 = _mm_sub_ps(iy0,jy0);
222 dz00 = _mm_sub_ps(iz0,jz0);
223 dx01 = _mm_sub_ps(ix0,jx1);
224 dy01 = _mm_sub_ps(iy0,jy1);
225 dz01 = _mm_sub_ps(iz0,jz1);
226 dx02 = _mm_sub_ps(ix0,jx2);
227 dy02 = _mm_sub_ps(iy0,jy2);
228 dz02 = _mm_sub_ps(iz0,jz2);
229 dx10 = _mm_sub_ps(ix1,jx0);
230 dy10 = _mm_sub_ps(iy1,jy0);
231 dz10 = _mm_sub_ps(iz1,jz0);
232 dx11 = _mm_sub_ps(ix1,jx1);
233 dy11 = _mm_sub_ps(iy1,jy1);
234 dz11 = _mm_sub_ps(iz1,jz1);
235 dx12 = _mm_sub_ps(ix1,jx2);
236 dy12 = _mm_sub_ps(iy1,jy2);
237 dz12 = _mm_sub_ps(iz1,jz2);
238 dx20 = _mm_sub_ps(ix2,jx0);
239 dy20 = _mm_sub_ps(iy2,jy0);
240 dz20 = _mm_sub_ps(iz2,jz0);
241 dx21 = _mm_sub_ps(ix2,jx1);
242 dy21 = _mm_sub_ps(iy2,jy1);
243 dz21 = _mm_sub_ps(iz2,jz1);
244 dx22 = _mm_sub_ps(ix2,jx2);
245 dy22 = _mm_sub_ps(iy2,jy2);
246 dz22 = _mm_sub_ps(iz2,jz2);
248 /* Calculate squared distance and things based on it */
249 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
250 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
251 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
252 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
253 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
254 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
255 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
256 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
257 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
259 rinv00 = gmx_mm_invsqrt_ps(rsq00);
260 rinv01 = gmx_mm_invsqrt_ps(rsq01);
261 rinv02 = gmx_mm_invsqrt_ps(rsq02);
262 rinv10 = gmx_mm_invsqrt_ps(rsq10);
263 rinv11 = gmx_mm_invsqrt_ps(rsq11);
264 rinv12 = gmx_mm_invsqrt_ps(rsq12);
265 rinv20 = gmx_mm_invsqrt_ps(rsq20);
266 rinv21 = gmx_mm_invsqrt_ps(rsq21);
267 rinv22 = gmx_mm_invsqrt_ps(rsq22);
269 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
270 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
271 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
272 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
273 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
274 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
275 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
276 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
277 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
279 fjx0 = _mm_setzero_ps();
280 fjy0 = _mm_setzero_ps();
281 fjz0 = _mm_setzero_ps();
282 fjx1 = _mm_setzero_ps();
283 fjy1 = _mm_setzero_ps();
284 fjz1 = _mm_setzero_ps();
285 fjx2 = _mm_setzero_ps();
286 fjy2 = _mm_setzero_ps();
287 fjz2 = _mm_setzero_ps();
289 /**************************
290 * CALCULATE INTERACTIONS *
291 **************************/
293 if (gmx_mm_any_lt(rsq00,rcutoff2))
296 /* REACTION-FIELD ELECTROSTATICS */
297 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
298 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
300 /* LENNARD-JONES DISPERSION/REPULSION */
302 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
303 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
304 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
305 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
306 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
307 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
309 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
311 /* Update potential sum for this i atom from the interaction with this j atom. */
312 velec = _mm_and_ps(velec,cutoff_mask);
313 velecsum = _mm_add_ps(velecsum,velec);
314 vvdw = _mm_and_ps(vvdw,cutoff_mask);
315 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
317 fscal = _mm_add_ps(felec,fvdw);
319 fscal = _mm_and_ps(fscal,cutoff_mask);
321 /* Update vectorial force */
322 fix0 = _mm_macc_ps(dx00,fscal,fix0);
323 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
324 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
326 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
327 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
328 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
332 /**************************
333 * CALCULATE INTERACTIONS *
334 **************************/
336 if (gmx_mm_any_lt(rsq01,rcutoff2))
339 /* REACTION-FIELD ELECTROSTATICS */
340 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
341 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
343 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
345 /* Update potential sum for this i atom from the interaction with this j atom. */
346 velec = _mm_and_ps(velec,cutoff_mask);
347 velecsum = _mm_add_ps(velecsum,velec);
351 fscal = _mm_and_ps(fscal,cutoff_mask);
353 /* Update vectorial force */
354 fix0 = _mm_macc_ps(dx01,fscal,fix0);
355 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
356 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
358 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
359 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
360 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
364 /**************************
365 * CALCULATE INTERACTIONS *
366 **************************/
368 if (gmx_mm_any_lt(rsq02,rcutoff2))
371 /* REACTION-FIELD ELECTROSTATICS */
372 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
373 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
375 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
377 /* Update potential sum for this i atom from the interaction with this j atom. */
378 velec = _mm_and_ps(velec,cutoff_mask);
379 velecsum = _mm_add_ps(velecsum,velec);
383 fscal = _mm_and_ps(fscal,cutoff_mask);
385 /* Update vectorial force */
386 fix0 = _mm_macc_ps(dx02,fscal,fix0);
387 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
388 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
390 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
391 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
392 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
396 /**************************
397 * CALCULATE INTERACTIONS *
398 **************************/
400 if (gmx_mm_any_lt(rsq10,rcutoff2))
403 /* REACTION-FIELD ELECTROSTATICS */
404 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
405 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
407 cutoff_mask = _mm_cmplt_ps(rsq10,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 /* Update vectorial force */
418 fix1 = _mm_macc_ps(dx10,fscal,fix1);
419 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
420 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
422 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
423 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
424 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
428 /**************************
429 * CALCULATE INTERACTIONS *
430 **************************/
432 if (gmx_mm_any_lt(rsq11,rcutoff2))
435 /* REACTION-FIELD ELECTROSTATICS */
436 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
437 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
439 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
441 /* Update potential sum for this i atom from the interaction with this j atom. */
442 velec = _mm_and_ps(velec,cutoff_mask);
443 velecsum = _mm_add_ps(velecsum,velec);
447 fscal = _mm_and_ps(fscal,cutoff_mask);
449 /* Update vectorial force */
450 fix1 = _mm_macc_ps(dx11,fscal,fix1);
451 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
452 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
454 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
455 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
456 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
460 /**************************
461 * CALCULATE INTERACTIONS *
462 **************************/
464 if (gmx_mm_any_lt(rsq12,rcutoff2))
467 /* REACTION-FIELD ELECTROSTATICS */
468 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
469 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
471 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
473 /* Update potential sum for this i atom from the interaction with this j atom. */
474 velec = _mm_and_ps(velec,cutoff_mask);
475 velecsum = _mm_add_ps(velecsum,velec);
479 fscal = _mm_and_ps(fscal,cutoff_mask);
481 /* Update vectorial force */
482 fix1 = _mm_macc_ps(dx12,fscal,fix1);
483 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
484 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
486 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
487 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
488 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
492 /**************************
493 * CALCULATE INTERACTIONS *
494 **************************/
496 if (gmx_mm_any_lt(rsq20,rcutoff2))
499 /* REACTION-FIELD ELECTROSTATICS */
500 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
501 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
503 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
505 /* Update potential sum for this i atom from the interaction with this j atom. */
506 velec = _mm_and_ps(velec,cutoff_mask);
507 velecsum = _mm_add_ps(velecsum,velec);
511 fscal = _mm_and_ps(fscal,cutoff_mask);
513 /* Update vectorial force */
514 fix2 = _mm_macc_ps(dx20,fscal,fix2);
515 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
516 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
518 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
519 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
520 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
524 /**************************
525 * CALCULATE INTERACTIONS *
526 **************************/
528 if (gmx_mm_any_lt(rsq21,rcutoff2))
531 /* REACTION-FIELD ELECTROSTATICS */
532 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
533 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
535 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
537 /* Update potential sum for this i atom from the interaction with this j atom. */
538 velec = _mm_and_ps(velec,cutoff_mask);
539 velecsum = _mm_add_ps(velecsum,velec);
543 fscal = _mm_and_ps(fscal,cutoff_mask);
545 /* Update vectorial force */
546 fix2 = _mm_macc_ps(dx21,fscal,fix2);
547 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
548 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
550 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
551 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
552 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
556 /**************************
557 * CALCULATE INTERACTIONS *
558 **************************/
560 if (gmx_mm_any_lt(rsq22,rcutoff2))
563 /* REACTION-FIELD ELECTROSTATICS */
564 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
565 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
567 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
569 /* Update potential sum for this i atom from the interaction with this j atom. */
570 velec = _mm_and_ps(velec,cutoff_mask);
571 velecsum = _mm_add_ps(velecsum,velec);
575 fscal = _mm_and_ps(fscal,cutoff_mask);
577 /* Update vectorial force */
578 fix2 = _mm_macc_ps(dx22,fscal,fix2);
579 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
580 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
582 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
583 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
584 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
588 fjptrA = f+j_coord_offsetA;
589 fjptrB = f+j_coord_offsetB;
590 fjptrC = f+j_coord_offsetC;
591 fjptrD = f+j_coord_offsetD;
593 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
594 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
596 /* Inner loop uses 369 flops */
602 /* Get j neighbor index, and coordinate index */
603 jnrlistA = jjnr[jidx];
604 jnrlistB = jjnr[jidx+1];
605 jnrlistC = jjnr[jidx+2];
606 jnrlistD = jjnr[jidx+3];
607 /* Sign of each element will be negative for non-real atoms.
608 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
609 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
611 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
612 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
613 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
614 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
615 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
616 j_coord_offsetA = DIM*jnrA;
617 j_coord_offsetB = DIM*jnrB;
618 j_coord_offsetC = DIM*jnrC;
619 j_coord_offsetD = DIM*jnrD;
621 /* load j atom coordinates */
622 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
623 x+j_coord_offsetC,x+j_coord_offsetD,
624 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
626 /* Calculate displacement vector */
627 dx00 = _mm_sub_ps(ix0,jx0);
628 dy00 = _mm_sub_ps(iy0,jy0);
629 dz00 = _mm_sub_ps(iz0,jz0);
630 dx01 = _mm_sub_ps(ix0,jx1);
631 dy01 = _mm_sub_ps(iy0,jy1);
632 dz01 = _mm_sub_ps(iz0,jz1);
633 dx02 = _mm_sub_ps(ix0,jx2);
634 dy02 = _mm_sub_ps(iy0,jy2);
635 dz02 = _mm_sub_ps(iz0,jz2);
636 dx10 = _mm_sub_ps(ix1,jx0);
637 dy10 = _mm_sub_ps(iy1,jy0);
638 dz10 = _mm_sub_ps(iz1,jz0);
639 dx11 = _mm_sub_ps(ix1,jx1);
640 dy11 = _mm_sub_ps(iy1,jy1);
641 dz11 = _mm_sub_ps(iz1,jz1);
642 dx12 = _mm_sub_ps(ix1,jx2);
643 dy12 = _mm_sub_ps(iy1,jy2);
644 dz12 = _mm_sub_ps(iz1,jz2);
645 dx20 = _mm_sub_ps(ix2,jx0);
646 dy20 = _mm_sub_ps(iy2,jy0);
647 dz20 = _mm_sub_ps(iz2,jz0);
648 dx21 = _mm_sub_ps(ix2,jx1);
649 dy21 = _mm_sub_ps(iy2,jy1);
650 dz21 = _mm_sub_ps(iz2,jz1);
651 dx22 = _mm_sub_ps(ix2,jx2);
652 dy22 = _mm_sub_ps(iy2,jy2);
653 dz22 = _mm_sub_ps(iz2,jz2);
655 /* Calculate squared distance and things based on it */
656 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
657 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
658 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
659 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
660 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
661 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
662 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
663 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
664 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
666 rinv00 = gmx_mm_invsqrt_ps(rsq00);
667 rinv01 = gmx_mm_invsqrt_ps(rsq01);
668 rinv02 = gmx_mm_invsqrt_ps(rsq02);
669 rinv10 = gmx_mm_invsqrt_ps(rsq10);
670 rinv11 = gmx_mm_invsqrt_ps(rsq11);
671 rinv12 = gmx_mm_invsqrt_ps(rsq12);
672 rinv20 = gmx_mm_invsqrt_ps(rsq20);
673 rinv21 = gmx_mm_invsqrt_ps(rsq21);
674 rinv22 = gmx_mm_invsqrt_ps(rsq22);
676 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
677 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
678 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
679 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
680 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
681 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
682 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
683 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
684 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
686 fjx0 = _mm_setzero_ps();
687 fjy0 = _mm_setzero_ps();
688 fjz0 = _mm_setzero_ps();
689 fjx1 = _mm_setzero_ps();
690 fjy1 = _mm_setzero_ps();
691 fjz1 = _mm_setzero_ps();
692 fjx2 = _mm_setzero_ps();
693 fjy2 = _mm_setzero_ps();
694 fjz2 = _mm_setzero_ps();
696 /**************************
697 * CALCULATE INTERACTIONS *
698 **************************/
700 if (gmx_mm_any_lt(rsq00,rcutoff2))
703 /* REACTION-FIELD ELECTROSTATICS */
704 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
705 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
707 /* LENNARD-JONES DISPERSION/REPULSION */
709 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
710 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
711 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
712 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
713 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
714 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
716 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
718 /* Update potential sum for this i atom from the interaction with this j atom. */
719 velec = _mm_and_ps(velec,cutoff_mask);
720 velec = _mm_andnot_ps(dummy_mask,velec);
721 velecsum = _mm_add_ps(velecsum,velec);
722 vvdw = _mm_and_ps(vvdw,cutoff_mask);
723 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
724 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
726 fscal = _mm_add_ps(felec,fvdw);
728 fscal = _mm_and_ps(fscal,cutoff_mask);
730 fscal = _mm_andnot_ps(dummy_mask,fscal);
732 /* Update vectorial force */
733 fix0 = _mm_macc_ps(dx00,fscal,fix0);
734 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
735 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
737 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
738 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
739 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
743 /**************************
744 * CALCULATE INTERACTIONS *
745 **************************/
747 if (gmx_mm_any_lt(rsq01,rcutoff2))
750 /* REACTION-FIELD ELECTROSTATICS */
751 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
752 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
754 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
756 /* Update potential sum for this i atom from the interaction with this j atom. */
757 velec = _mm_and_ps(velec,cutoff_mask);
758 velec = _mm_andnot_ps(dummy_mask,velec);
759 velecsum = _mm_add_ps(velecsum,velec);
763 fscal = _mm_and_ps(fscal,cutoff_mask);
765 fscal = _mm_andnot_ps(dummy_mask,fscal);
767 /* Update vectorial force */
768 fix0 = _mm_macc_ps(dx01,fscal,fix0);
769 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
770 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
772 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
773 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
774 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
778 /**************************
779 * CALCULATE INTERACTIONS *
780 **************************/
782 if (gmx_mm_any_lt(rsq02,rcutoff2))
785 /* REACTION-FIELD ELECTROSTATICS */
786 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
787 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
789 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
791 /* Update potential sum for this i atom from the interaction with this j atom. */
792 velec = _mm_and_ps(velec,cutoff_mask);
793 velec = _mm_andnot_ps(dummy_mask,velec);
794 velecsum = _mm_add_ps(velecsum,velec);
798 fscal = _mm_and_ps(fscal,cutoff_mask);
800 fscal = _mm_andnot_ps(dummy_mask,fscal);
802 /* Update vectorial force */
803 fix0 = _mm_macc_ps(dx02,fscal,fix0);
804 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
805 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
807 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
808 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
809 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
813 /**************************
814 * CALCULATE INTERACTIONS *
815 **************************/
817 if (gmx_mm_any_lt(rsq10,rcutoff2))
820 /* REACTION-FIELD ELECTROSTATICS */
821 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
822 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
824 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
826 /* Update potential sum for this i atom from the interaction with this j atom. */
827 velec = _mm_and_ps(velec,cutoff_mask);
828 velec = _mm_andnot_ps(dummy_mask,velec);
829 velecsum = _mm_add_ps(velecsum,velec);
833 fscal = _mm_and_ps(fscal,cutoff_mask);
835 fscal = _mm_andnot_ps(dummy_mask,fscal);
837 /* Update vectorial force */
838 fix1 = _mm_macc_ps(dx10,fscal,fix1);
839 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
840 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
842 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
843 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
844 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
848 /**************************
849 * CALCULATE INTERACTIONS *
850 **************************/
852 if (gmx_mm_any_lt(rsq11,rcutoff2))
855 /* REACTION-FIELD ELECTROSTATICS */
856 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
857 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
859 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
861 /* Update potential sum for this i atom from the interaction with this j atom. */
862 velec = _mm_and_ps(velec,cutoff_mask);
863 velec = _mm_andnot_ps(dummy_mask,velec);
864 velecsum = _mm_add_ps(velecsum,velec);
868 fscal = _mm_and_ps(fscal,cutoff_mask);
870 fscal = _mm_andnot_ps(dummy_mask,fscal);
872 /* Update vectorial force */
873 fix1 = _mm_macc_ps(dx11,fscal,fix1);
874 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
875 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
877 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
878 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
879 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
883 /**************************
884 * CALCULATE INTERACTIONS *
885 **************************/
887 if (gmx_mm_any_lt(rsq12,rcutoff2))
890 /* REACTION-FIELD ELECTROSTATICS */
891 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
892 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
894 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
896 /* Update potential sum for this i atom from the interaction with this j atom. */
897 velec = _mm_and_ps(velec,cutoff_mask);
898 velec = _mm_andnot_ps(dummy_mask,velec);
899 velecsum = _mm_add_ps(velecsum,velec);
903 fscal = _mm_and_ps(fscal,cutoff_mask);
905 fscal = _mm_andnot_ps(dummy_mask,fscal);
907 /* Update vectorial force */
908 fix1 = _mm_macc_ps(dx12,fscal,fix1);
909 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
910 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
912 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
913 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
914 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
918 /**************************
919 * CALCULATE INTERACTIONS *
920 **************************/
922 if (gmx_mm_any_lt(rsq20,rcutoff2))
925 /* REACTION-FIELD ELECTROSTATICS */
926 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
927 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
929 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
931 /* Update potential sum for this i atom from the interaction with this j atom. */
932 velec = _mm_and_ps(velec,cutoff_mask);
933 velec = _mm_andnot_ps(dummy_mask,velec);
934 velecsum = _mm_add_ps(velecsum,velec);
938 fscal = _mm_and_ps(fscal,cutoff_mask);
940 fscal = _mm_andnot_ps(dummy_mask,fscal);
942 /* Update vectorial force */
943 fix2 = _mm_macc_ps(dx20,fscal,fix2);
944 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
945 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
947 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
948 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
949 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
953 /**************************
954 * CALCULATE INTERACTIONS *
955 **************************/
957 if (gmx_mm_any_lt(rsq21,rcutoff2))
960 /* REACTION-FIELD ELECTROSTATICS */
961 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
962 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
964 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
966 /* Update potential sum for this i atom from the interaction with this j atom. */
967 velec = _mm_and_ps(velec,cutoff_mask);
968 velec = _mm_andnot_ps(dummy_mask,velec);
969 velecsum = _mm_add_ps(velecsum,velec);
973 fscal = _mm_and_ps(fscal,cutoff_mask);
975 fscal = _mm_andnot_ps(dummy_mask,fscal);
977 /* Update vectorial force */
978 fix2 = _mm_macc_ps(dx21,fscal,fix2);
979 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
980 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
982 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
983 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
984 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
988 /**************************
989 * CALCULATE INTERACTIONS *
990 **************************/
992 if (gmx_mm_any_lt(rsq22,rcutoff2))
995 /* REACTION-FIELD ELECTROSTATICS */
996 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
997 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
999 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1001 /* Update potential sum for this i atom from the interaction with this j atom. */
1002 velec = _mm_and_ps(velec,cutoff_mask);
1003 velec = _mm_andnot_ps(dummy_mask,velec);
1004 velecsum = _mm_add_ps(velecsum,velec);
1008 fscal = _mm_and_ps(fscal,cutoff_mask);
1010 fscal = _mm_andnot_ps(dummy_mask,fscal);
1012 /* Update vectorial force */
1013 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1014 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1015 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1017 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1018 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1019 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1023 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1024 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1025 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1026 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1028 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1029 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1031 /* Inner loop uses 369 flops */
1034 /* End of innermost loop */
1036 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1037 f+i_coord_offset,fshift+i_shift_offset);
1040 /* Update potential energies */
1041 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1042 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1044 /* Increment number of inner iterations */
1045 inneriter += j_index_end - j_index_start;
1047 /* Outer loop uses 20 flops */
1050 /* Increment number of outer iterations */
1053 /* Update outer/inner flops */
1055 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*369);
1058 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1059 * Electrostatics interaction: ReactionField
1060 * VdW interaction: LennardJones
1061 * Geometry: Water3-Water3
1062 * Calculate force/pot: Force
1065 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1066 (t_nblist * gmx_restrict nlist,
1067 rvec * gmx_restrict xx,
1068 rvec * gmx_restrict ff,
1069 t_forcerec * gmx_restrict fr,
1070 t_mdatoms * gmx_restrict mdatoms,
1071 nb_kernel_data_t * gmx_restrict kernel_data,
1072 t_nrnb * gmx_restrict nrnb)
1074 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1075 * just 0 for non-waters.
1076 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1077 * jnr indices corresponding to data put in the four positions in the SIMD register.
1079 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1080 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1081 int jnrA,jnrB,jnrC,jnrD;
1082 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1083 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1084 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1085 real rcutoff_scalar;
1086 real *shiftvec,*fshift,*x,*f;
1087 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1088 real scratch[4*DIM];
1089 __m128 fscal,rcutoff,rcutoff2,jidxall;
1091 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1093 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1095 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1096 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1097 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1098 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1099 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1100 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1101 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1102 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1103 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1104 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1105 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1106 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1107 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1108 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1109 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1110 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1111 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1114 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1117 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1118 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1119 __m128 dummy_mask,cutoff_mask;
1120 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1121 __m128 one = _mm_set1_ps(1.0);
1122 __m128 two = _mm_set1_ps(2.0);
1128 jindex = nlist->jindex;
1130 shiftidx = nlist->shift;
1132 shiftvec = fr->shift_vec[0];
1133 fshift = fr->fshift[0];
1134 facel = _mm_set1_ps(fr->epsfac);
1135 charge = mdatoms->chargeA;
1136 krf = _mm_set1_ps(fr->ic->k_rf);
1137 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1138 crf = _mm_set1_ps(fr->ic->c_rf);
1139 nvdwtype = fr->ntype;
1140 vdwparam = fr->nbfp;
1141 vdwtype = mdatoms->typeA;
1143 /* Setup water-specific parameters */
1144 inr = nlist->iinr[0];
1145 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1146 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1147 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1148 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1150 jq0 = _mm_set1_ps(charge[inr+0]);
1151 jq1 = _mm_set1_ps(charge[inr+1]);
1152 jq2 = _mm_set1_ps(charge[inr+2]);
1153 vdwjidx0A = 2*vdwtype[inr+0];
1154 qq00 = _mm_mul_ps(iq0,jq0);
1155 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1156 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1157 qq01 = _mm_mul_ps(iq0,jq1);
1158 qq02 = _mm_mul_ps(iq0,jq2);
1159 qq10 = _mm_mul_ps(iq1,jq0);
1160 qq11 = _mm_mul_ps(iq1,jq1);
1161 qq12 = _mm_mul_ps(iq1,jq2);
1162 qq20 = _mm_mul_ps(iq2,jq0);
1163 qq21 = _mm_mul_ps(iq2,jq1);
1164 qq22 = _mm_mul_ps(iq2,jq2);
1166 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1167 rcutoff_scalar = fr->rcoulomb;
1168 rcutoff = _mm_set1_ps(rcutoff_scalar);
1169 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1171 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1172 rvdw = _mm_set1_ps(fr->rvdw);
1174 /* Avoid stupid compiler warnings */
1175 jnrA = jnrB = jnrC = jnrD = 0;
1176 j_coord_offsetA = 0;
1177 j_coord_offsetB = 0;
1178 j_coord_offsetC = 0;
1179 j_coord_offsetD = 0;
1184 for(iidx=0;iidx<4*DIM;iidx++)
1186 scratch[iidx] = 0.0;
1189 /* Start outer loop over neighborlists */
1190 for(iidx=0; iidx<nri; iidx++)
1192 /* Load shift vector for this list */
1193 i_shift_offset = DIM*shiftidx[iidx];
1195 /* Load limits for loop over neighbors */
1196 j_index_start = jindex[iidx];
1197 j_index_end = jindex[iidx+1];
1199 /* Get outer coordinate index */
1201 i_coord_offset = DIM*inr;
1203 /* Load i particle coords and add shift vector */
1204 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1205 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1207 fix0 = _mm_setzero_ps();
1208 fiy0 = _mm_setzero_ps();
1209 fiz0 = _mm_setzero_ps();
1210 fix1 = _mm_setzero_ps();
1211 fiy1 = _mm_setzero_ps();
1212 fiz1 = _mm_setzero_ps();
1213 fix2 = _mm_setzero_ps();
1214 fiy2 = _mm_setzero_ps();
1215 fiz2 = _mm_setzero_ps();
1217 /* Start inner kernel loop */
1218 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1221 /* Get j neighbor index, and coordinate index */
1223 jnrB = jjnr[jidx+1];
1224 jnrC = jjnr[jidx+2];
1225 jnrD = jjnr[jidx+3];
1226 j_coord_offsetA = DIM*jnrA;
1227 j_coord_offsetB = DIM*jnrB;
1228 j_coord_offsetC = DIM*jnrC;
1229 j_coord_offsetD = DIM*jnrD;
1231 /* load j atom coordinates */
1232 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1233 x+j_coord_offsetC,x+j_coord_offsetD,
1234 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1236 /* Calculate displacement vector */
1237 dx00 = _mm_sub_ps(ix0,jx0);
1238 dy00 = _mm_sub_ps(iy0,jy0);
1239 dz00 = _mm_sub_ps(iz0,jz0);
1240 dx01 = _mm_sub_ps(ix0,jx1);
1241 dy01 = _mm_sub_ps(iy0,jy1);
1242 dz01 = _mm_sub_ps(iz0,jz1);
1243 dx02 = _mm_sub_ps(ix0,jx2);
1244 dy02 = _mm_sub_ps(iy0,jy2);
1245 dz02 = _mm_sub_ps(iz0,jz2);
1246 dx10 = _mm_sub_ps(ix1,jx0);
1247 dy10 = _mm_sub_ps(iy1,jy0);
1248 dz10 = _mm_sub_ps(iz1,jz0);
1249 dx11 = _mm_sub_ps(ix1,jx1);
1250 dy11 = _mm_sub_ps(iy1,jy1);
1251 dz11 = _mm_sub_ps(iz1,jz1);
1252 dx12 = _mm_sub_ps(ix1,jx2);
1253 dy12 = _mm_sub_ps(iy1,jy2);
1254 dz12 = _mm_sub_ps(iz1,jz2);
1255 dx20 = _mm_sub_ps(ix2,jx0);
1256 dy20 = _mm_sub_ps(iy2,jy0);
1257 dz20 = _mm_sub_ps(iz2,jz0);
1258 dx21 = _mm_sub_ps(ix2,jx1);
1259 dy21 = _mm_sub_ps(iy2,jy1);
1260 dz21 = _mm_sub_ps(iz2,jz1);
1261 dx22 = _mm_sub_ps(ix2,jx2);
1262 dy22 = _mm_sub_ps(iy2,jy2);
1263 dz22 = _mm_sub_ps(iz2,jz2);
1265 /* Calculate squared distance and things based on it */
1266 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1267 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1268 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1269 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1270 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1271 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1272 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1273 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1274 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1276 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1277 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1278 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1279 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1280 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1281 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1282 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1283 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1284 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1286 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1287 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1288 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1289 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1290 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1291 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1292 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1293 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1294 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1296 fjx0 = _mm_setzero_ps();
1297 fjy0 = _mm_setzero_ps();
1298 fjz0 = _mm_setzero_ps();
1299 fjx1 = _mm_setzero_ps();
1300 fjy1 = _mm_setzero_ps();
1301 fjz1 = _mm_setzero_ps();
1302 fjx2 = _mm_setzero_ps();
1303 fjy2 = _mm_setzero_ps();
1304 fjz2 = _mm_setzero_ps();
1306 /**************************
1307 * CALCULATE INTERACTIONS *
1308 **************************/
1310 if (gmx_mm_any_lt(rsq00,rcutoff2))
1313 /* REACTION-FIELD ELECTROSTATICS */
1314 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1316 /* LENNARD-JONES DISPERSION/REPULSION */
1318 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1319 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1321 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1323 fscal = _mm_add_ps(felec,fvdw);
1325 fscal = _mm_and_ps(fscal,cutoff_mask);
1327 /* Update vectorial force */
1328 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1329 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1330 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1332 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1333 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1334 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1338 /**************************
1339 * CALCULATE INTERACTIONS *
1340 **************************/
1342 if (gmx_mm_any_lt(rsq01,rcutoff2))
1345 /* REACTION-FIELD ELECTROSTATICS */
1346 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1348 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1352 fscal = _mm_and_ps(fscal,cutoff_mask);
1354 /* Update vectorial force */
1355 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1356 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1357 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1359 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1360 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1361 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1365 /**************************
1366 * CALCULATE INTERACTIONS *
1367 **************************/
1369 if (gmx_mm_any_lt(rsq02,rcutoff2))
1372 /* REACTION-FIELD ELECTROSTATICS */
1373 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1375 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1379 fscal = _mm_and_ps(fscal,cutoff_mask);
1381 /* Update vectorial force */
1382 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1383 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1384 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1386 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1387 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1388 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1392 /**************************
1393 * CALCULATE INTERACTIONS *
1394 **************************/
1396 if (gmx_mm_any_lt(rsq10,rcutoff2))
1399 /* REACTION-FIELD ELECTROSTATICS */
1400 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1402 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1406 fscal = _mm_and_ps(fscal,cutoff_mask);
1408 /* Update vectorial force */
1409 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1410 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1411 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1413 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1414 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1415 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1419 /**************************
1420 * CALCULATE INTERACTIONS *
1421 **************************/
1423 if (gmx_mm_any_lt(rsq11,rcutoff2))
1426 /* REACTION-FIELD ELECTROSTATICS */
1427 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1429 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1433 fscal = _mm_and_ps(fscal,cutoff_mask);
1435 /* Update vectorial force */
1436 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1437 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1438 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1440 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1441 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1442 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1446 /**************************
1447 * CALCULATE INTERACTIONS *
1448 **************************/
1450 if (gmx_mm_any_lt(rsq12,rcutoff2))
1453 /* REACTION-FIELD ELECTROSTATICS */
1454 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1456 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1460 fscal = _mm_and_ps(fscal,cutoff_mask);
1462 /* Update vectorial force */
1463 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1464 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1465 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1467 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1468 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1469 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1473 /**************************
1474 * CALCULATE INTERACTIONS *
1475 **************************/
1477 if (gmx_mm_any_lt(rsq20,rcutoff2))
1480 /* REACTION-FIELD ELECTROSTATICS */
1481 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1483 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1487 fscal = _mm_and_ps(fscal,cutoff_mask);
1489 /* Update vectorial force */
1490 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1491 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1492 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1494 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1495 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1496 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1500 /**************************
1501 * CALCULATE INTERACTIONS *
1502 **************************/
1504 if (gmx_mm_any_lt(rsq21,rcutoff2))
1507 /* REACTION-FIELD ELECTROSTATICS */
1508 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1510 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1514 fscal = _mm_and_ps(fscal,cutoff_mask);
1516 /* Update vectorial force */
1517 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1518 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1519 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1521 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1522 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1523 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1527 /**************************
1528 * CALCULATE INTERACTIONS *
1529 **************************/
1531 if (gmx_mm_any_lt(rsq22,rcutoff2))
1534 /* REACTION-FIELD ELECTROSTATICS */
1535 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1537 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1541 fscal = _mm_and_ps(fscal,cutoff_mask);
1543 /* Update vectorial force */
1544 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1545 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1546 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1548 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1549 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1550 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1554 fjptrA = f+j_coord_offsetA;
1555 fjptrB = f+j_coord_offsetB;
1556 fjptrC = f+j_coord_offsetC;
1557 fjptrD = f+j_coord_offsetD;
1559 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1560 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1562 /* Inner loop uses 304 flops */
1565 if(jidx<j_index_end)
1568 /* Get j neighbor index, and coordinate index */
1569 jnrlistA = jjnr[jidx];
1570 jnrlistB = jjnr[jidx+1];
1571 jnrlistC = jjnr[jidx+2];
1572 jnrlistD = jjnr[jidx+3];
1573 /* Sign of each element will be negative for non-real atoms.
1574 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1575 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1577 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1578 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1579 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1580 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1581 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1582 j_coord_offsetA = DIM*jnrA;
1583 j_coord_offsetB = DIM*jnrB;
1584 j_coord_offsetC = DIM*jnrC;
1585 j_coord_offsetD = DIM*jnrD;
1587 /* load j atom coordinates */
1588 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1589 x+j_coord_offsetC,x+j_coord_offsetD,
1590 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1592 /* Calculate displacement vector */
1593 dx00 = _mm_sub_ps(ix0,jx0);
1594 dy00 = _mm_sub_ps(iy0,jy0);
1595 dz00 = _mm_sub_ps(iz0,jz0);
1596 dx01 = _mm_sub_ps(ix0,jx1);
1597 dy01 = _mm_sub_ps(iy0,jy1);
1598 dz01 = _mm_sub_ps(iz0,jz1);
1599 dx02 = _mm_sub_ps(ix0,jx2);
1600 dy02 = _mm_sub_ps(iy0,jy2);
1601 dz02 = _mm_sub_ps(iz0,jz2);
1602 dx10 = _mm_sub_ps(ix1,jx0);
1603 dy10 = _mm_sub_ps(iy1,jy0);
1604 dz10 = _mm_sub_ps(iz1,jz0);
1605 dx11 = _mm_sub_ps(ix1,jx1);
1606 dy11 = _mm_sub_ps(iy1,jy1);
1607 dz11 = _mm_sub_ps(iz1,jz1);
1608 dx12 = _mm_sub_ps(ix1,jx2);
1609 dy12 = _mm_sub_ps(iy1,jy2);
1610 dz12 = _mm_sub_ps(iz1,jz2);
1611 dx20 = _mm_sub_ps(ix2,jx0);
1612 dy20 = _mm_sub_ps(iy2,jy0);
1613 dz20 = _mm_sub_ps(iz2,jz0);
1614 dx21 = _mm_sub_ps(ix2,jx1);
1615 dy21 = _mm_sub_ps(iy2,jy1);
1616 dz21 = _mm_sub_ps(iz2,jz1);
1617 dx22 = _mm_sub_ps(ix2,jx2);
1618 dy22 = _mm_sub_ps(iy2,jy2);
1619 dz22 = _mm_sub_ps(iz2,jz2);
1621 /* Calculate squared distance and things based on it */
1622 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1623 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1624 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1625 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1626 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1627 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1628 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1629 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1630 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1632 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1633 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1634 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1635 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1636 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1637 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1638 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1639 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1640 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1642 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1643 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1644 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1645 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1646 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1647 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1648 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1649 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1650 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1652 fjx0 = _mm_setzero_ps();
1653 fjy0 = _mm_setzero_ps();
1654 fjz0 = _mm_setzero_ps();
1655 fjx1 = _mm_setzero_ps();
1656 fjy1 = _mm_setzero_ps();
1657 fjz1 = _mm_setzero_ps();
1658 fjx2 = _mm_setzero_ps();
1659 fjy2 = _mm_setzero_ps();
1660 fjz2 = _mm_setzero_ps();
1662 /**************************
1663 * CALCULATE INTERACTIONS *
1664 **************************/
1666 if (gmx_mm_any_lt(rsq00,rcutoff2))
1669 /* REACTION-FIELD ELECTROSTATICS */
1670 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1672 /* LENNARD-JONES DISPERSION/REPULSION */
1674 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1675 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1677 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1679 fscal = _mm_add_ps(felec,fvdw);
1681 fscal = _mm_and_ps(fscal,cutoff_mask);
1683 fscal = _mm_andnot_ps(dummy_mask,fscal);
1685 /* Update vectorial force */
1686 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1687 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1688 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1690 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1691 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1692 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1696 /**************************
1697 * CALCULATE INTERACTIONS *
1698 **************************/
1700 if (gmx_mm_any_lt(rsq01,rcutoff2))
1703 /* REACTION-FIELD ELECTROSTATICS */
1704 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1706 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1710 fscal = _mm_and_ps(fscal,cutoff_mask);
1712 fscal = _mm_andnot_ps(dummy_mask,fscal);
1714 /* Update vectorial force */
1715 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1716 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1717 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1719 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1720 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1721 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1725 /**************************
1726 * CALCULATE INTERACTIONS *
1727 **************************/
1729 if (gmx_mm_any_lt(rsq02,rcutoff2))
1732 /* REACTION-FIELD ELECTROSTATICS */
1733 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1735 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1739 fscal = _mm_and_ps(fscal,cutoff_mask);
1741 fscal = _mm_andnot_ps(dummy_mask,fscal);
1743 /* Update vectorial force */
1744 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1745 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1746 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1748 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1749 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1750 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1754 /**************************
1755 * CALCULATE INTERACTIONS *
1756 **************************/
1758 if (gmx_mm_any_lt(rsq10,rcutoff2))
1761 /* REACTION-FIELD ELECTROSTATICS */
1762 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1764 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1768 fscal = _mm_and_ps(fscal,cutoff_mask);
1770 fscal = _mm_andnot_ps(dummy_mask,fscal);
1772 /* Update vectorial force */
1773 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1774 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1775 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1777 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1778 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1779 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1783 /**************************
1784 * CALCULATE INTERACTIONS *
1785 **************************/
1787 if (gmx_mm_any_lt(rsq11,rcutoff2))
1790 /* REACTION-FIELD ELECTROSTATICS */
1791 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1793 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1797 fscal = _mm_and_ps(fscal,cutoff_mask);
1799 fscal = _mm_andnot_ps(dummy_mask,fscal);
1801 /* Update vectorial force */
1802 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1803 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1804 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1806 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1807 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1808 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1812 /**************************
1813 * CALCULATE INTERACTIONS *
1814 **************************/
1816 if (gmx_mm_any_lt(rsq12,rcutoff2))
1819 /* REACTION-FIELD ELECTROSTATICS */
1820 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1822 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1826 fscal = _mm_and_ps(fscal,cutoff_mask);
1828 fscal = _mm_andnot_ps(dummy_mask,fscal);
1830 /* Update vectorial force */
1831 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1832 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1833 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1835 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1836 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1837 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1841 /**************************
1842 * CALCULATE INTERACTIONS *
1843 **************************/
1845 if (gmx_mm_any_lt(rsq20,rcutoff2))
1848 /* REACTION-FIELD ELECTROSTATICS */
1849 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1851 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1855 fscal = _mm_and_ps(fscal,cutoff_mask);
1857 fscal = _mm_andnot_ps(dummy_mask,fscal);
1859 /* Update vectorial force */
1860 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1861 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1862 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1864 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1865 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1866 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1870 /**************************
1871 * CALCULATE INTERACTIONS *
1872 **************************/
1874 if (gmx_mm_any_lt(rsq21,rcutoff2))
1877 /* REACTION-FIELD ELECTROSTATICS */
1878 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1880 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1884 fscal = _mm_and_ps(fscal,cutoff_mask);
1886 fscal = _mm_andnot_ps(dummy_mask,fscal);
1888 /* Update vectorial force */
1889 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1890 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1891 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1893 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1894 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1895 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1899 /**************************
1900 * CALCULATE INTERACTIONS *
1901 **************************/
1903 if (gmx_mm_any_lt(rsq22,rcutoff2))
1906 /* REACTION-FIELD ELECTROSTATICS */
1907 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1909 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1913 fscal = _mm_and_ps(fscal,cutoff_mask);
1915 fscal = _mm_andnot_ps(dummy_mask,fscal);
1917 /* Update vectorial force */
1918 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1919 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1920 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1922 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1923 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1924 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1928 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1929 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1930 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1931 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1933 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1934 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1936 /* Inner loop uses 304 flops */
1939 /* End of innermost loop */
1941 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1942 f+i_coord_offset,fshift+i_shift_offset);
1944 /* Increment number of inner iterations */
1945 inneriter += j_index_end - j_index_start;
1947 /* Outer loop uses 18 flops */
1950 /* Increment number of outer iterations */
1953 /* Update outer/inner flops */
1955 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*304);