2 * Note: this file was generated by the Gromacs avx_256_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_256_single.h"
34 #include "kernelutil_x86_avx_256_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water4-Water4
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_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,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight 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 jnrE,jnrF,jnrG,jnrH;
62 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
63 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
64 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
65 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
66 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
68 real *shiftvec,*fshift,*x,*f;
69 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
71 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
72 real * vdwioffsetptr0;
73 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
74 real * vdwioffsetptr1;
75 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
76 real * vdwioffsetptr2;
77 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
78 real * vdwioffsetptr3;
79 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
80 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
81 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
82 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
83 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
84 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
85 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
86 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
87 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
88 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
90 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
91 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
92 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
93 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
94 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
95 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
96 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
97 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
98 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
101 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
104 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
105 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
106 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
107 real rswitch_scalar,d_scalar;
108 __m256 dummy_mask,cutoff_mask;
109 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
110 __m256 one = _mm256_set1_ps(1.0);
111 __m256 two = _mm256_set1_ps(2.0);
117 jindex = nlist->jindex;
119 shiftidx = nlist->shift;
121 shiftvec = fr->shift_vec[0];
122 fshift = fr->fshift[0];
123 facel = _mm256_set1_ps(fr->epsfac);
124 charge = mdatoms->chargeA;
125 krf = _mm256_set1_ps(fr->ic->k_rf);
126 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
127 crf = _mm256_set1_ps(fr->ic->c_rf);
128 nvdwtype = fr->ntype;
130 vdwtype = mdatoms->typeA;
132 /* Setup water-specific parameters */
133 inr = nlist->iinr[0];
134 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
135 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
136 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
137 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
139 jq1 = _mm256_set1_ps(charge[inr+1]);
140 jq2 = _mm256_set1_ps(charge[inr+2]);
141 jq3 = _mm256_set1_ps(charge[inr+3]);
142 vdwjidx0A = 2*vdwtype[inr+0];
143 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
144 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
145 qq11 = _mm256_mul_ps(iq1,jq1);
146 qq12 = _mm256_mul_ps(iq1,jq2);
147 qq13 = _mm256_mul_ps(iq1,jq3);
148 qq21 = _mm256_mul_ps(iq2,jq1);
149 qq22 = _mm256_mul_ps(iq2,jq2);
150 qq23 = _mm256_mul_ps(iq2,jq3);
151 qq31 = _mm256_mul_ps(iq3,jq1);
152 qq32 = _mm256_mul_ps(iq3,jq2);
153 qq33 = _mm256_mul_ps(iq3,jq3);
155 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
156 rcutoff_scalar = fr->rcoulomb;
157 rcutoff = _mm256_set1_ps(rcutoff_scalar);
158 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
160 rswitch_scalar = fr->rvdw_switch;
161 rswitch = _mm256_set1_ps(rswitch_scalar);
162 /* Setup switch parameters */
163 d_scalar = rcutoff_scalar-rswitch_scalar;
164 d = _mm256_set1_ps(d_scalar);
165 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
166 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
167 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
168 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
169 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
170 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
172 /* Avoid stupid compiler warnings */
173 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
186 for(iidx=0;iidx<4*DIM;iidx++)
191 /* Start outer loop over neighborlists */
192 for(iidx=0; iidx<nri; iidx++)
194 /* Load shift vector for this list */
195 i_shift_offset = DIM*shiftidx[iidx];
197 /* Load limits for loop over neighbors */
198 j_index_start = jindex[iidx];
199 j_index_end = jindex[iidx+1];
201 /* Get outer coordinate index */
203 i_coord_offset = DIM*inr;
205 /* Load i particle coords and add shift vector */
206 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
207 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
209 fix0 = _mm256_setzero_ps();
210 fiy0 = _mm256_setzero_ps();
211 fiz0 = _mm256_setzero_ps();
212 fix1 = _mm256_setzero_ps();
213 fiy1 = _mm256_setzero_ps();
214 fiz1 = _mm256_setzero_ps();
215 fix2 = _mm256_setzero_ps();
216 fiy2 = _mm256_setzero_ps();
217 fiz2 = _mm256_setzero_ps();
218 fix3 = _mm256_setzero_ps();
219 fiy3 = _mm256_setzero_ps();
220 fiz3 = _mm256_setzero_ps();
222 /* Reset potential sums */
223 velecsum = _mm256_setzero_ps();
224 vvdwsum = _mm256_setzero_ps();
226 /* Start inner kernel loop */
227 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
230 /* Get j neighbor index, and coordinate index */
239 j_coord_offsetA = DIM*jnrA;
240 j_coord_offsetB = DIM*jnrB;
241 j_coord_offsetC = DIM*jnrC;
242 j_coord_offsetD = DIM*jnrD;
243 j_coord_offsetE = DIM*jnrE;
244 j_coord_offsetF = DIM*jnrF;
245 j_coord_offsetG = DIM*jnrG;
246 j_coord_offsetH = DIM*jnrH;
248 /* load j atom coordinates */
249 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
250 x+j_coord_offsetC,x+j_coord_offsetD,
251 x+j_coord_offsetE,x+j_coord_offsetF,
252 x+j_coord_offsetG,x+j_coord_offsetH,
253 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
254 &jy2,&jz2,&jx3,&jy3,&jz3);
256 /* Calculate displacement vector */
257 dx00 = _mm256_sub_ps(ix0,jx0);
258 dy00 = _mm256_sub_ps(iy0,jy0);
259 dz00 = _mm256_sub_ps(iz0,jz0);
260 dx11 = _mm256_sub_ps(ix1,jx1);
261 dy11 = _mm256_sub_ps(iy1,jy1);
262 dz11 = _mm256_sub_ps(iz1,jz1);
263 dx12 = _mm256_sub_ps(ix1,jx2);
264 dy12 = _mm256_sub_ps(iy1,jy2);
265 dz12 = _mm256_sub_ps(iz1,jz2);
266 dx13 = _mm256_sub_ps(ix1,jx3);
267 dy13 = _mm256_sub_ps(iy1,jy3);
268 dz13 = _mm256_sub_ps(iz1,jz3);
269 dx21 = _mm256_sub_ps(ix2,jx1);
270 dy21 = _mm256_sub_ps(iy2,jy1);
271 dz21 = _mm256_sub_ps(iz2,jz1);
272 dx22 = _mm256_sub_ps(ix2,jx2);
273 dy22 = _mm256_sub_ps(iy2,jy2);
274 dz22 = _mm256_sub_ps(iz2,jz2);
275 dx23 = _mm256_sub_ps(ix2,jx3);
276 dy23 = _mm256_sub_ps(iy2,jy3);
277 dz23 = _mm256_sub_ps(iz2,jz3);
278 dx31 = _mm256_sub_ps(ix3,jx1);
279 dy31 = _mm256_sub_ps(iy3,jy1);
280 dz31 = _mm256_sub_ps(iz3,jz1);
281 dx32 = _mm256_sub_ps(ix3,jx2);
282 dy32 = _mm256_sub_ps(iy3,jy2);
283 dz32 = _mm256_sub_ps(iz3,jz2);
284 dx33 = _mm256_sub_ps(ix3,jx3);
285 dy33 = _mm256_sub_ps(iy3,jy3);
286 dz33 = _mm256_sub_ps(iz3,jz3);
288 /* Calculate squared distance and things based on it */
289 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
290 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
291 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
292 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
293 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
294 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
295 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
296 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
297 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
298 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
300 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
301 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
302 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
303 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
304 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
305 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
306 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
307 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
308 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
309 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
311 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
312 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
313 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
314 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
315 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
316 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
317 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
318 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
319 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
320 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
322 fjx0 = _mm256_setzero_ps();
323 fjy0 = _mm256_setzero_ps();
324 fjz0 = _mm256_setzero_ps();
325 fjx1 = _mm256_setzero_ps();
326 fjy1 = _mm256_setzero_ps();
327 fjz1 = _mm256_setzero_ps();
328 fjx2 = _mm256_setzero_ps();
329 fjy2 = _mm256_setzero_ps();
330 fjz2 = _mm256_setzero_ps();
331 fjx3 = _mm256_setzero_ps();
332 fjy3 = _mm256_setzero_ps();
333 fjz3 = _mm256_setzero_ps();
335 /**************************
336 * CALCULATE INTERACTIONS *
337 **************************/
339 if (gmx_mm256_any_lt(rsq00,rcutoff2))
342 r00 = _mm256_mul_ps(rsq00,rinv00);
344 /* LENNARD-JONES DISPERSION/REPULSION */
346 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
347 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
348 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
349 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
350 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
352 d = _mm256_sub_ps(r00,rswitch);
353 d = _mm256_max_ps(d,_mm256_setzero_ps());
354 d2 = _mm256_mul_ps(d,d);
355 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
357 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
359 /* Evaluate switch function */
360 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
361 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
362 vvdw = _mm256_mul_ps(vvdw,sw);
363 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
365 /* Update potential sum for this i atom from the interaction with this j atom. */
366 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
367 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
371 fscal = _mm256_and_ps(fscal,cutoff_mask);
373 /* Calculate temporary vectorial force */
374 tx = _mm256_mul_ps(fscal,dx00);
375 ty = _mm256_mul_ps(fscal,dy00);
376 tz = _mm256_mul_ps(fscal,dz00);
378 /* Update vectorial force */
379 fix0 = _mm256_add_ps(fix0,tx);
380 fiy0 = _mm256_add_ps(fiy0,ty);
381 fiz0 = _mm256_add_ps(fiz0,tz);
383 fjx0 = _mm256_add_ps(fjx0,tx);
384 fjy0 = _mm256_add_ps(fjy0,ty);
385 fjz0 = _mm256_add_ps(fjz0,tz);
389 /**************************
390 * CALCULATE INTERACTIONS *
391 **************************/
393 if (gmx_mm256_any_lt(rsq11,rcutoff2))
396 /* REACTION-FIELD ELECTROSTATICS */
397 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
398 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
400 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
402 /* Update potential sum for this i atom from the interaction with this j atom. */
403 velec = _mm256_and_ps(velec,cutoff_mask);
404 velecsum = _mm256_add_ps(velecsum,velec);
408 fscal = _mm256_and_ps(fscal,cutoff_mask);
410 /* Calculate temporary vectorial force */
411 tx = _mm256_mul_ps(fscal,dx11);
412 ty = _mm256_mul_ps(fscal,dy11);
413 tz = _mm256_mul_ps(fscal,dz11);
415 /* Update vectorial force */
416 fix1 = _mm256_add_ps(fix1,tx);
417 fiy1 = _mm256_add_ps(fiy1,ty);
418 fiz1 = _mm256_add_ps(fiz1,tz);
420 fjx1 = _mm256_add_ps(fjx1,tx);
421 fjy1 = _mm256_add_ps(fjy1,ty);
422 fjz1 = _mm256_add_ps(fjz1,tz);
426 /**************************
427 * CALCULATE INTERACTIONS *
428 **************************/
430 if (gmx_mm256_any_lt(rsq12,rcutoff2))
433 /* REACTION-FIELD ELECTROSTATICS */
434 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
435 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
437 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
439 /* Update potential sum for this i atom from the interaction with this j atom. */
440 velec = _mm256_and_ps(velec,cutoff_mask);
441 velecsum = _mm256_add_ps(velecsum,velec);
445 fscal = _mm256_and_ps(fscal,cutoff_mask);
447 /* Calculate temporary vectorial force */
448 tx = _mm256_mul_ps(fscal,dx12);
449 ty = _mm256_mul_ps(fscal,dy12);
450 tz = _mm256_mul_ps(fscal,dz12);
452 /* Update vectorial force */
453 fix1 = _mm256_add_ps(fix1,tx);
454 fiy1 = _mm256_add_ps(fiy1,ty);
455 fiz1 = _mm256_add_ps(fiz1,tz);
457 fjx2 = _mm256_add_ps(fjx2,tx);
458 fjy2 = _mm256_add_ps(fjy2,ty);
459 fjz2 = _mm256_add_ps(fjz2,tz);
463 /**************************
464 * CALCULATE INTERACTIONS *
465 **************************/
467 if (gmx_mm256_any_lt(rsq13,rcutoff2))
470 /* REACTION-FIELD ELECTROSTATICS */
471 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
472 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
474 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
476 /* Update potential sum for this i atom from the interaction with this j atom. */
477 velec = _mm256_and_ps(velec,cutoff_mask);
478 velecsum = _mm256_add_ps(velecsum,velec);
482 fscal = _mm256_and_ps(fscal,cutoff_mask);
484 /* Calculate temporary vectorial force */
485 tx = _mm256_mul_ps(fscal,dx13);
486 ty = _mm256_mul_ps(fscal,dy13);
487 tz = _mm256_mul_ps(fscal,dz13);
489 /* Update vectorial force */
490 fix1 = _mm256_add_ps(fix1,tx);
491 fiy1 = _mm256_add_ps(fiy1,ty);
492 fiz1 = _mm256_add_ps(fiz1,tz);
494 fjx3 = _mm256_add_ps(fjx3,tx);
495 fjy3 = _mm256_add_ps(fjy3,ty);
496 fjz3 = _mm256_add_ps(fjz3,tz);
500 /**************************
501 * CALCULATE INTERACTIONS *
502 **************************/
504 if (gmx_mm256_any_lt(rsq21,rcutoff2))
507 /* REACTION-FIELD ELECTROSTATICS */
508 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
509 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
511 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
513 /* Update potential sum for this i atom from the interaction with this j atom. */
514 velec = _mm256_and_ps(velec,cutoff_mask);
515 velecsum = _mm256_add_ps(velecsum,velec);
519 fscal = _mm256_and_ps(fscal,cutoff_mask);
521 /* Calculate temporary vectorial force */
522 tx = _mm256_mul_ps(fscal,dx21);
523 ty = _mm256_mul_ps(fscal,dy21);
524 tz = _mm256_mul_ps(fscal,dz21);
526 /* Update vectorial force */
527 fix2 = _mm256_add_ps(fix2,tx);
528 fiy2 = _mm256_add_ps(fiy2,ty);
529 fiz2 = _mm256_add_ps(fiz2,tz);
531 fjx1 = _mm256_add_ps(fjx1,tx);
532 fjy1 = _mm256_add_ps(fjy1,ty);
533 fjz1 = _mm256_add_ps(fjz1,tz);
537 /**************************
538 * CALCULATE INTERACTIONS *
539 **************************/
541 if (gmx_mm256_any_lt(rsq22,rcutoff2))
544 /* REACTION-FIELD ELECTROSTATICS */
545 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
546 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
548 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
550 /* Update potential sum for this i atom from the interaction with this j atom. */
551 velec = _mm256_and_ps(velec,cutoff_mask);
552 velecsum = _mm256_add_ps(velecsum,velec);
556 fscal = _mm256_and_ps(fscal,cutoff_mask);
558 /* Calculate temporary vectorial force */
559 tx = _mm256_mul_ps(fscal,dx22);
560 ty = _mm256_mul_ps(fscal,dy22);
561 tz = _mm256_mul_ps(fscal,dz22);
563 /* Update vectorial force */
564 fix2 = _mm256_add_ps(fix2,tx);
565 fiy2 = _mm256_add_ps(fiy2,ty);
566 fiz2 = _mm256_add_ps(fiz2,tz);
568 fjx2 = _mm256_add_ps(fjx2,tx);
569 fjy2 = _mm256_add_ps(fjy2,ty);
570 fjz2 = _mm256_add_ps(fjz2,tz);
574 /**************************
575 * CALCULATE INTERACTIONS *
576 **************************/
578 if (gmx_mm256_any_lt(rsq23,rcutoff2))
581 /* REACTION-FIELD ELECTROSTATICS */
582 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
583 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
585 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
587 /* Update potential sum for this i atom from the interaction with this j atom. */
588 velec = _mm256_and_ps(velec,cutoff_mask);
589 velecsum = _mm256_add_ps(velecsum,velec);
593 fscal = _mm256_and_ps(fscal,cutoff_mask);
595 /* Calculate temporary vectorial force */
596 tx = _mm256_mul_ps(fscal,dx23);
597 ty = _mm256_mul_ps(fscal,dy23);
598 tz = _mm256_mul_ps(fscal,dz23);
600 /* Update vectorial force */
601 fix2 = _mm256_add_ps(fix2,tx);
602 fiy2 = _mm256_add_ps(fiy2,ty);
603 fiz2 = _mm256_add_ps(fiz2,tz);
605 fjx3 = _mm256_add_ps(fjx3,tx);
606 fjy3 = _mm256_add_ps(fjy3,ty);
607 fjz3 = _mm256_add_ps(fjz3,tz);
611 /**************************
612 * CALCULATE INTERACTIONS *
613 **************************/
615 if (gmx_mm256_any_lt(rsq31,rcutoff2))
618 /* REACTION-FIELD ELECTROSTATICS */
619 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
620 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
622 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
624 /* Update potential sum for this i atom from the interaction with this j atom. */
625 velec = _mm256_and_ps(velec,cutoff_mask);
626 velecsum = _mm256_add_ps(velecsum,velec);
630 fscal = _mm256_and_ps(fscal,cutoff_mask);
632 /* Calculate temporary vectorial force */
633 tx = _mm256_mul_ps(fscal,dx31);
634 ty = _mm256_mul_ps(fscal,dy31);
635 tz = _mm256_mul_ps(fscal,dz31);
637 /* Update vectorial force */
638 fix3 = _mm256_add_ps(fix3,tx);
639 fiy3 = _mm256_add_ps(fiy3,ty);
640 fiz3 = _mm256_add_ps(fiz3,tz);
642 fjx1 = _mm256_add_ps(fjx1,tx);
643 fjy1 = _mm256_add_ps(fjy1,ty);
644 fjz1 = _mm256_add_ps(fjz1,tz);
648 /**************************
649 * CALCULATE INTERACTIONS *
650 **************************/
652 if (gmx_mm256_any_lt(rsq32,rcutoff2))
655 /* REACTION-FIELD ELECTROSTATICS */
656 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
657 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
659 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
661 /* Update potential sum for this i atom from the interaction with this j atom. */
662 velec = _mm256_and_ps(velec,cutoff_mask);
663 velecsum = _mm256_add_ps(velecsum,velec);
667 fscal = _mm256_and_ps(fscal,cutoff_mask);
669 /* Calculate temporary vectorial force */
670 tx = _mm256_mul_ps(fscal,dx32);
671 ty = _mm256_mul_ps(fscal,dy32);
672 tz = _mm256_mul_ps(fscal,dz32);
674 /* Update vectorial force */
675 fix3 = _mm256_add_ps(fix3,tx);
676 fiy3 = _mm256_add_ps(fiy3,ty);
677 fiz3 = _mm256_add_ps(fiz3,tz);
679 fjx2 = _mm256_add_ps(fjx2,tx);
680 fjy2 = _mm256_add_ps(fjy2,ty);
681 fjz2 = _mm256_add_ps(fjz2,tz);
685 /**************************
686 * CALCULATE INTERACTIONS *
687 **************************/
689 if (gmx_mm256_any_lt(rsq33,rcutoff2))
692 /* REACTION-FIELD ELECTROSTATICS */
693 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
694 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
696 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
698 /* Update potential sum for this i atom from the interaction with this j atom. */
699 velec = _mm256_and_ps(velec,cutoff_mask);
700 velecsum = _mm256_add_ps(velecsum,velec);
704 fscal = _mm256_and_ps(fscal,cutoff_mask);
706 /* Calculate temporary vectorial force */
707 tx = _mm256_mul_ps(fscal,dx33);
708 ty = _mm256_mul_ps(fscal,dy33);
709 tz = _mm256_mul_ps(fscal,dz33);
711 /* Update vectorial force */
712 fix3 = _mm256_add_ps(fix3,tx);
713 fiy3 = _mm256_add_ps(fiy3,ty);
714 fiz3 = _mm256_add_ps(fiz3,tz);
716 fjx3 = _mm256_add_ps(fjx3,tx);
717 fjy3 = _mm256_add_ps(fjy3,ty);
718 fjz3 = _mm256_add_ps(fjz3,tz);
722 fjptrA = f+j_coord_offsetA;
723 fjptrB = f+j_coord_offsetB;
724 fjptrC = f+j_coord_offsetC;
725 fjptrD = f+j_coord_offsetD;
726 fjptrE = f+j_coord_offsetE;
727 fjptrF = f+j_coord_offsetF;
728 fjptrG = f+j_coord_offsetG;
729 fjptrH = f+j_coord_offsetH;
731 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
732 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
733 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
735 /* Inner loop uses 386 flops */
741 /* Get j neighbor index, and coordinate index */
742 jnrlistA = jjnr[jidx];
743 jnrlistB = jjnr[jidx+1];
744 jnrlistC = jjnr[jidx+2];
745 jnrlistD = jjnr[jidx+3];
746 jnrlistE = jjnr[jidx+4];
747 jnrlistF = jjnr[jidx+5];
748 jnrlistG = jjnr[jidx+6];
749 jnrlistH = jjnr[jidx+7];
750 /* Sign of each element will be negative for non-real atoms.
751 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
752 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
754 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
755 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
757 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
758 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
759 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
760 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
761 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
762 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
763 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
764 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
765 j_coord_offsetA = DIM*jnrA;
766 j_coord_offsetB = DIM*jnrB;
767 j_coord_offsetC = DIM*jnrC;
768 j_coord_offsetD = DIM*jnrD;
769 j_coord_offsetE = DIM*jnrE;
770 j_coord_offsetF = DIM*jnrF;
771 j_coord_offsetG = DIM*jnrG;
772 j_coord_offsetH = DIM*jnrH;
774 /* load j atom coordinates */
775 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
776 x+j_coord_offsetC,x+j_coord_offsetD,
777 x+j_coord_offsetE,x+j_coord_offsetF,
778 x+j_coord_offsetG,x+j_coord_offsetH,
779 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
780 &jy2,&jz2,&jx3,&jy3,&jz3);
782 /* Calculate displacement vector */
783 dx00 = _mm256_sub_ps(ix0,jx0);
784 dy00 = _mm256_sub_ps(iy0,jy0);
785 dz00 = _mm256_sub_ps(iz0,jz0);
786 dx11 = _mm256_sub_ps(ix1,jx1);
787 dy11 = _mm256_sub_ps(iy1,jy1);
788 dz11 = _mm256_sub_ps(iz1,jz1);
789 dx12 = _mm256_sub_ps(ix1,jx2);
790 dy12 = _mm256_sub_ps(iy1,jy2);
791 dz12 = _mm256_sub_ps(iz1,jz2);
792 dx13 = _mm256_sub_ps(ix1,jx3);
793 dy13 = _mm256_sub_ps(iy1,jy3);
794 dz13 = _mm256_sub_ps(iz1,jz3);
795 dx21 = _mm256_sub_ps(ix2,jx1);
796 dy21 = _mm256_sub_ps(iy2,jy1);
797 dz21 = _mm256_sub_ps(iz2,jz1);
798 dx22 = _mm256_sub_ps(ix2,jx2);
799 dy22 = _mm256_sub_ps(iy2,jy2);
800 dz22 = _mm256_sub_ps(iz2,jz2);
801 dx23 = _mm256_sub_ps(ix2,jx3);
802 dy23 = _mm256_sub_ps(iy2,jy3);
803 dz23 = _mm256_sub_ps(iz2,jz3);
804 dx31 = _mm256_sub_ps(ix3,jx1);
805 dy31 = _mm256_sub_ps(iy3,jy1);
806 dz31 = _mm256_sub_ps(iz3,jz1);
807 dx32 = _mm256_sub_ps(ix3,jx2);
808 dy32 = _mm256_sub_ps(iy3,jy2);
809 dz32 = _mm256_sub_ps(iz3,jz2);
810 dx33 = _mm256_sub_ps(ix3,jx3);
811 dy33 = _mm256_sub_ps(iy3,jy3);
812 dz33 = _mm256_sub_ps(iz3,jz3);
814 /* Calculate squared distance and things based on it */
815 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
816 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
817 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
818 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
819 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
820 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
821 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
822 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
823 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
824 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
826 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
827 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
828 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
829 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
830 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
831 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
832 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
833 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
834 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
835 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
837 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
838 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
839 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
840 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
841 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
842 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
843 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
844 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
845 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
846 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
848 fjx0 = _mm256_setzero_ps();
849 fjy0 = _mm256_setzero_ps();
850 fjz0 = _mm256_setzero_ps();
851 fjx1 = _mm256_setzero_ps();
852 fjy1 = _mm256_setzero_ps();
853 fjz1 = _mm256_setzero_ps();
854 fjx2 = _mm256_setzero_ps();
855 fjy2 = _mm256_setzero_ps();
856 fjz2 = _mm256_setzero_ps();
857 fjx3 = _mm256_setzero_ps();
858 fjy3 = _mm256_setzero_ps();
859 fjz3 = _mm256_setzero_ps();
861 /**************************
862 * CALCULATE INTERACTIONS *
863 **************************/
865 if (gmx_mm256_any_lt(rsq00,rcutoff2))
868 r00 = _mm256_mul_ps(rsq00,rinv00);
869 r00 = _mm256_andnot_ps(dummy_mask,r00);
871 /* LENNARD-JONES DISPERSION/REPULSION */
873 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
874 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
875 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
876 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
877 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
879 d = _mm256_sub_ps(r00,rswitch);
880 d = _mm256_max_ps(d,_mm256_setzero_ps());
881 d2 = _mm256_mul_ps(d,d);
882 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
884 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
886 /* Evaluate switch function */
887 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
888 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
889 vvdw = _mm256_mul_ps(vvdw,sw);
890 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
892 /* Update potential sum for this i atom from the interaction with this j atom. */
893 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
894 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
895 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
899 fscal = _mm256_and_ps(fscal,cutoff_mask);
901 fscal = _mm256_andnot_ps(dummy_mask,fscal);
903 /* Calculate temporary vectorial force */
904 tx = _mm256_mul_ps(fscal,dx00);
905 ty = _mm256_mul_ps(fscal,dy00);
906 tz = _mm256_mul_ps(fscal,dz00);
908 /* Update vectorial force */
909 fix0 = _mm256_add_ps(fix0,tx);
910 fiy0 = _mm256_add_ps(fiy0,ty);
911 fiz0 = _mm256_add_ps(fiz0,tz);
913 fjx0 = _mm256_add_ps(fjx0,tx);
914 fjy0 = _mm256_add_ps(fjy0,ty);
915 fjz0 = _mm256_add_ps(fjz0,tz);
919 /**************************
920 * CALCULATE INTERACTIONS *
921 **************************/
923 if (gmx_mm256_any_lt(rsq11,rcutoff2))
926 /* REACTION-FIELD ELECTROSTATICS */
927 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
928 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
930 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
932 /* Update potential sum for this i atom from the interaction with this j atom. */
933 velec = _mm256_and_ps(velec,cutoff_mask);
934 velec = _mm256_andnot_ps(dummy_mask,velec);
935 velecsum = _mm256_add_ps(velecsum,velec);
939 fscal = _mm256_and_ps(fscal,cutoff_mask);
941 fscal = _mm256_andnot_ps(dummy_mask,fscal);
943 /* Calculate temporary vectorial force */
944 tx = _mm256_mul_ps(fscal,dx11);
945 ty = _mm256_mul_ps(fscal,dy11);
946 tz = _mm256_mul_ps(fscal,dz11);
948 /* Update vectorial force */
949 fix1 = _mm256_add_ps(fix1,tx);
950 fiy1 = _mm256_add_ps(fiy1,ty);
951 fiz1 = _mm256_add_ps(fiz1,tz);
953 fjx1 = _mm256_add_ps(fjx1,tx);
954 fjy1 = _mm256_add_ps(fjy1,ty);
955 fjz1 = _mm256_add_ps(fjz1,tz);
959 /**************************
960 * CALCULATE INTERACTIONS *
961 **************************/
963 if (gmx_mm256_any_lt(rsq12,rcutoff2))
966 /* REACTION-FIELD ELECTROSTATICS */
967 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
968 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
970 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
972 /* Update potential sum for this i atom from the interaction with this j atom. */
973 velec = _mm256_and_ps(velec,cutoff_mask);
974 velec = _mm256_andnot_ps(dummy_mask,velec);
975 velecsum = _mm256_add_ps(velecsum,velec);
979 fscal = _mm256_and_ps(fscal,cutoff_mask);
981 fscal = _mm256_andnot_ps(dummy_mask,fscal);
983 /* Calculate temporary vectorial force */
984 tx = _mm256_mul_ps(fscal,dx12);
985 ty = _mm256_mul_ps(fscal,dy12);
986 tz = _mm256_mul_ps(fscal,dz12);
988 /* Update vectorial force */
989 fix1 = _mm256_add_ps(fix1,tx);
990 fiy1 = _mm256_add_ps(fiy1,ty);
991 fiz1 = _mm256_add_ps(fiz1,tz);
993 fjx2 = _mm256_add_ps(fjx2,tx);
994 fjy2 = _mm256_add_ps(fjy2,ty);
995 fjz2 = _mm256_add_ps(fjz2,tz);
999 /**************************
1000 * CALCULATE INTERACTIONS *
1001 **************************/
1003 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1006 /* REACTION-FIELD ELECTROSTATICS */
1007 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
1008 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1010 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1012 /* Update potential sum for this i atom from the interaction with this j atom. */
1013 velec = _mm256_and_ps(velec,cutoff_mask);
1014 velec = _mm256_andnot_ps(dummy_mask,velec);
1015 velecsum = _mm256_add_ps(velecsum,velec);
1019 fscal = _mm256_and_ps(fscal,cutoff_mask);
1021 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1023 /* Calculate temporary vectorial force */
1024 tx = _mm256_mul_ps(fscal,dx13);
1025 ty = _mm256_mul_ps(fscal,dy13);
1026 tz = _mm256_mul_ps(fscal,dz13);
1028 /* Update vectorial force */
1029 fix1 = _mm256_add_ps(fix1,tx);
1030 fiy1 = _mm256_add_ps(fiy1,ty);
1031 fiz1 = _mm256_add_ps(fiz1,tz);
1033 fjx3 = _mm256_add_ps(fjx3,tx);
1034 fjy3 = _mm256_add_ps(fjy3,ty);
1035 fjz3 = _mm256_add_ps(fjz3,tz);
1039 /**************************
1040 * CALCULATE INTERACTIONS *
1041 **************************/
1043 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1046 /* REACTION-FIELD ELECTROSTATICS */
1047 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1048 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1050 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1052 /* Update potential sum for this i atom from the interaction with this j atom. */
1053 velec = _mm256_and_ps(velec,cutoff_mask);
1054 velec = _mm256_andnot_ps(dummy_mask,velec);
1055 velecsum = _mm256_add_ps(velecsum,velec);
1059 fscal = _mm256_and_ps(fscal,cutoff_mask);
1061 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1063 /* Calculate temporary vectorial force */
1064 tx = _mm256_mul_ps(fscal,dx21);
1065 ty = _mm256_mul_ps(fscal,dy21);
1066 tz = _mm256_mul_ps(fscal,dz21);
1068 /* Update vectorial force */
1069 fix2 = _mm256_add_ps(fix2,tx);
1070 fiy2 = _mm256_add_ps(fiy2,ty);
1071 fiz2 = _mm256_add_ps(fiz2,tz);
1073 fjx1 = _mm256_add_ps(fjx1,tx);
1074 fjy1 = _mm256_add_ps(fjy1,ty);
1075 fjz1 = _mm256_add_ps(fjz1,tz);
1079 /**************************
1080 * CALCULATE INTERACTIONS *
1081 **************************/
1083 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1086 /* REACTION-FIELD ELECTROSTATICS */
1087 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1088 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1090 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1092 /* Update potential sum for this i atom from the interaction with this j atom. */
1093 velec = _mm256_and_ps(velec,cutoff_mask);
1094 velec = _mm256_andnot_ps(dummy_mask,velec);
1095 velecsum = _mm256_add_ps(velecsum,velec);
1099 fscal = _mm256_and_ps(fscal,cutoff_mask);
1101 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1103 /* Calculate temporary vectorial force */
1104 tx = _mm256_mul_ps(fscal,dx22);
1105 ty = _mm256_mul_ps(fscal,dy22);
1106 tz = _mm256_mul_ps(fscal,dz22);
1108 /* Update vectorial force */
1109 fix2 = _mm256_add_ps(fix2,tx);
1110 fiy2 = _mm256_add_ps(fiy2,ty);
1111 fiz2 = _mm256_add_ps(fiz2,tz);
1113 fjx2 = _mm256_add_ps(fjx2,tx);
1114 fjy2 = _mm256_add_ps(fjy2,ty);
1115 fjz2 = _mm256_add_ps(fjz2,tz);
1119 /**************************
1120 * CALCULATE INTERACTIONS *
1121 **************************/
1123 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1126 /* REACTION-FIELD ELECTROSTATICS */
1127 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
1128 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1130 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1132 /* Update potential sum for this i atom from the interaction with this j atom. */
1133 velec = _mm256_and_ps(velec,cutoff_mask);
1134 velec = _mm256_andnot_ps(dummy_mask,velec);
1135 velecsum = _mm256_add_ps(velecsum,velec);
1139 fscal = _mm256_and_ps(fscal,cutoff_mask);
1141 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1143 /* Calculate temporary vectorial force */
1144 tx = _mm256_mul_ps(fscal,dx23);
1145 ty = _mm256_mul_ps(fscal,dy23);
1146 tz = _mm256_mul_ps(fscal,dz23);
1148 /* Update vectorial force */
1149 fix2 = _mm256_add_ps(fix2,tx);
1150 fiy2 = _mm256_add_ps(fiy2,ty);
1151 fiz2 = _mm256_add_ps(fiz2,tz);
1153 fjx3 = _mm256_add_ps(fjx3,tx);
1154 fjy3 = _mm256_add_ps(fjy3,ty);
1155 fjz3 = _mm256_add_ps(fjz3,tz);
1159 /**************************
1160 * CALCULATE INTERACTIONS *
1161 **************************/
1163 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1166 /* REACTION-FIELD ELECTROSTATICS */
1167 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
1168 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1170 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1172 /* Update potential sum for this i atom from the interaction with this j atom. */
1173 velec = _mm256_and_ps(velec,cutoff_mask);
1174 velec = _mm256_andnot_ps(dummy_mask,velec);
1175 velecsum = _mm256_add_ps(velecsum,velec);
1179 fscal = _mm256_and_ps(fscal,cutoff_mask);
1181 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1183 /* Calculate temporary vectorial force */
1184 tx = _mm256_mul_ps(fscal,dx31);
1185 ty = _mm256_mul_ps(fscal,dy31);
1186 tz = _mm256_mul_ps(fscal,dz31);
1188 /* Update vectorial force */
1189 fix3 = _mm256_add_ps(fix3,tx);
1190 fiy3 = _mm256_add_ps(fiy3,ty);
1191 fiz3 = _mm256_add_ps(fiz3,tz);
1193 fjx1 = _mm256_add_ps(fjx1,tx);
1194 fjy1 = _mm256_add_ps(fjy1,ty);
1195 fjz1 = _mm256_add_ps(fjz1,tz);
1199 /**************************
1200 * CALCULATE INTERACTIONS *
1201 **************************/
1203 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1206 /* REACTION-FIELD ELECTROSTATICS */
1207 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
1208 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1210 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1212 /* Update potential sum for this i atom from the interaction with this j atom. */
1213 velec = _mm256_and_ps(velec,cutoff_mask);
1214 velec = _mm256_andnot_ps(dummy_mask,velec);
1215 velecsum = _mm256_add_ps(velecsum,velec);
1219 fscal = _mm256_and_ps(fscal,cutoff_mask);
1221 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1223 /* Calculate temporary vectorial force */
1224 tx = _mm256_mul_ps(fscal,dx32);
1225 ty = _mm256_mul_ps(fscal,dy32);
1226 tz = _mm256_mul_ps(fscal,dz32);
1228 /* Update vectorial force */
1229 fix3 = _mm256_add_ps(fix3,tx);
1230 fiy3 = _mm256_add_ps(fiy3,ty);
1231 fiz3 = _mm256_add_ps(fiz3,tz);
1233 fjx2 = _mm256_add_ps(fjx2,tx);
1234 fjy2 = _mm256_add_ps(fjy2,ty);
1235 fjz2 = _mm256_add_ps(fjz2,tz);
1239 /**************************
1240 * CALCULATE INTERACTIONS *
1241 **************************/
1243 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1246 /* REACTION-FIELD ELECTROSTATICS */
1247 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
1248 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1250 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1252 /* Update potential sum for this i atom from the interaction with this j atom. */
1253 velec = _mm256_and_ps(velec,cutoff_mask);
1254 velec = _mm256_andnot_ps(dummy_mask,velec);
1255 velecsum = _mm256_add_ps(velecsum,velec);
1259 fscal = _mm256_and_ps(fscal,cutoff_mask);
1261 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1263 /* Calculate temporary vectorial force */
1264 tx = _mm256_mul_ps(fscal,dx33);
1265 ty = _mm256_mul_ps(fscal,dy33);
1266 tz = _mm256_mul_ps(fscal,dz33);
1268 /* Update vectorial force */
1269 fix3 = _mm256_add_ps(fix3,tx);
1270 fiy3 = _mm256_add_ps(fiy3,ty);
1271 fiz3 = _mm256_add_ps(fiz3,tz);
1273 fjx3 = _mm256_add_ps(fjx3,tx);
1274 fjy3 = _mm256_add_ps(fjy3,ty);
1275 fjz3 = _mm256_add_ps(fjz3,tz);
1279 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1280 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1281 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1282 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1283 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1284 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1285 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1286 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1288 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1289 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1290 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1292 /* Inner loop uses 387 flops */
1295 /* End of innermost loop */
1297 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1298 f+i_coord_offset,fshift+i_shift_offset);
1301 /* Update potential energies */
1302 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1303 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1305 /* Increment number of inner iterations */
1306 inneriter += j_index_end - j_index_start;
1308 /* Outer loop uses 26 flops */
1311 /* Increment number of outer iterations */
1314 /* Update outer/inner flops */
1316 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*387);
1319 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1320 * Electrostatics interaction: ReactionField
1321 * VdW interaction: LennardJones
1322 * Geometry: Water4-Water4
1323 * Calculate force/pot: Force
1326 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1327 (t_nblist * gmx_restrict nlist,
1328 rvec * gmx_restrict xx,
1329 rvec * gmx_restrict ff,
1330 t_forcerec * gmx_restrict fr,
1331 t_mdatoms * gmx_restrict mdatoms,
1332 nb_kernel_data_t * gmx_restrict kernel_data,
1333 t_nrnb * gmx_restrict nrnb)
1335 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1336 * just 0 for non-waters.
1337 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1338 * jnr indices corresponding to data put in the four positions in the SIMD register.
1340 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1341 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1342 int jnrA,jnrB,jnrC,jnrD;
1343 int jnrE,jnrF,jnrG,jnrH;
1344 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1345 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1346 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1347 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1348 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1349 real rcutoff_scalar;
1350 real *shiftvec,*fshift,*x,*f;
1351 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1352 real scratch[4*DIM];
1353 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1354 real * vdwioffsetptr0;
1355 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1356 real * vdwioffsetptr1;
1357 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1358 real * vdwioffsetptr2;
1359 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1360 real * vdwioffsetptr3;
1361 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1362 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1363 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1364 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1365 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1366 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1367 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1368 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
1369 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1370 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1371 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1372 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1373 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1374 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1375 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1376 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1377 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1378 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1379 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1380 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1383 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1386 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1387 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1388 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
1389 real rswitch_scalar,d_scalar;
1390 __m256 dummy_mask,cutoff_mask;
1391 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1392 __m256 one = _mm256_set1_ps(1.0);
1393 __m256 two = _mm256_set1_ps(2.0);
1399 jindex = nlist->jindex;
1401 shiftidx = nlist->shift;
1403 shiftvec = fr->shift_vec[0];
1404 fshift = fr->fshift[0];
1405 facel = _mm256_set1_ps(fr->epsfac);
1406 charge = mdatoms->chargeA;
1407 krf = _mm256_set1_ps(fr->ic->k_rf);
1408 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1409 crf = _mm256_set1_ps(fr->ic->c_rf);
1410 nvdwtype = fr->ntype;
1411 vdwparam = fr->nbfp;
1412 vdwtype = mdatoms->typeA;
1414 /* Setup water-specific parameters */
1415 inr = nlist->iinr[0];
1416 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1417 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1418 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
1419 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1421 jq1 = _mm256_set1_ps(charge[inr+1]);
1422 jq2 = _mm256_set1_ps(charge[inr+2]);
1423 jq3 = _mm256_set1_ps(charge[inr+3]);
1424 vdwjidx0A = 2*vdwtype[inr+0];
1425 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1426 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1427 qq11 = _mm256_mul_ps(iq1,jq1);
1428 qq12 = _mm256_mul_ps(iq1,jq2);
1429 qq13 = _mm256_mul_ps(iq1,jq3);
1430 qq21 = _mm256_mul_ps(iq2,jq1);
1431 qq22 = _mm256_mul_ps(iq2,jq2);
1432 qq23 = _mm256_mul_ps(iq2,jq3);
1433 qq31 = _mm256_mul_ps(iq3,jq1);
1434 qq32 = _mm256_mul_ps(iq3,jq2);
1435 qq33 = _mm256_mul_ps(iq3,jq3);
1437 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1438 rcutoff_scalar = fr->rcoulomb;
1439 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1440 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1442 rswitch_scalar = fr->rvdw_switch;
1443 rswitch = _mm256_set1_ps(rswitch_scalar);
1444 /* Setup switch parameters */
1445 d_scalar = rcutoff_scalar-rswitch_scalar;
1446 d = _mm256_set1_ps(d_scalar);
1447 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
1448 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1449 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1450 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
1451 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1452 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1454 /* Avoid stupid compiler warnings */
1455 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1456 j_coord_offsetA = 0;
1457 j_coord_offsetB = 0;
1458 j_coord_offsetC = 0;
1459 j_coord_offsetD = 0;
1460 j_coord_offsetE = 0;
1461 j_coord_offsetF = 0;
1462 j_coord_offsetG = 0;
1463 j_coord_offsetH = 0;
1468 for(iidx=0;iidx<4*DIM;iidx++)
1470 scratch[iidx] = 0.0;
1473 /* Start outer loop over neighborlists */
1474 for(iidx=0; iidx<nri; iidx++)
1476 /* Load shift vector for this list */
1477 i_shift_offset = DIM*shiftidx[iidx];
1479 /* Load limits for loop over neighbors */
1480 j_index_start = jindex[iidx];
1481 j_index_end = jindex[iidx+1];
1483 /* Get outer coordinate index */
1485 i_coord_offset = DIM*inr;
1487 /* Load i particle coords and add shift vector */
1488 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1489 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1491 fix0 = _mm256_setzero_ps();
1492 fiy0 = _mm256_setzero_ps();
1493 fiz0 = _mm256_setzero_ps();
1494 fix1 = _mm256_setzero_ps();
1495 fiy1 = _mm256_setzero_ps();
1496 fiz1 = _mm256_setzero_ps();
1497 fix2 = _mm256_setzero_ps();
1498 fiy2 = _mm256_setzero_ps();
1499 fiz2 = _mm256_setzero_ps();
1500 fix3 = _mm256_setzero_ps();
1501 fiy3 = _mm256_setzero_ps();
1502 fiz3 = _mm256_setzero_ps();
1504 /* Start inner kernel loop */
1505 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1508 /* Get j neighbor index, and coordinate index */
1510 jnrB = jjnr[jidx+1];
1511 jnrC = jjnr[jidx+2];
1512 jnrD = jjnr[jidx+3];
1513 jnrE = jjnr[jidx+4];
1514 jnrF = jjnr[jidx+5];
1515 jnrG = jjnr[jidx+6];
1516 jnrH = jjnr[jidx+7];
1517 j_coord_offsetA = DIM*jnrA;
1518 j_coord_offsetB = DIM*jnrB;
1519 j_coord_offsetC = DIM*jnrC;
1520 j_coord_offsetD = DIM*jnrD;
1521 j_coord_offsetE = DIM*jnrE;
1522 j_coord_offsetF = DIM*jnrF;
1523 j_coord_offsetG = DIM*jnrG;
1524 j_coord_offsetH = DIM*jnrH;
1526 /* load j atom coordinates */
1527 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1528 x+j_coord_offsetC,x+j_coord_offsetD,
1529 x+j_coord_offsetE,x+j_coord_offsetF,
1530 x+j_coord_offsetG,x+j_coord_offsetH,
1531 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1532 &jy2,&jz2,&jx3,&jy3,&jz3);
1534 /* Calculate displacement vector */
1535 dx00 = _mm256_sub_ps(ix0,jx0);
1536 dy00 = _mm256_sub_ps(iy0,jy0);
1537 dz00 = _mm256_sub_ps(iz0,jz0);
1538 dx11 = _mm256_sub_ps(ix1,jx1);
1539 dy11 = _mm256_sub_ps(iy1,jy1);
1540 dz11 = _mm256_sub_ps(iz1,jz1);
1541 dx12 = _mm256_sub_ps(ix1,jx2);
1542 dy12 = _mm256_sub_ps(iy1,jy2);
1543 dz12 = _mm256_sub_ps(iz1,jz2);
1544 dx13 = _mm256_sub_ps(ix1,jx3);
1545 dy13 = _mm256_sub_ps(iy1,jy3);
1546 dz13 = _mm256_sub_ps(iz1,jz3);
1547 dx21 = _mm256_sub_ps(ix2,jx1);
1548 dy21 = _mm256_sub_ps(iy2,jy1);
1549 dz21 = _mm256_sub_ps(iz2,jz1);
1550 dx22 = _mm256_sub_ps(ix2,jx2);
1551 dy22 = _mm256_sub_ps(iy2,jy2);
1552 dz22 = _mm256_sub_ps(iz2,jz2);
1553 dx23 = _mm256_sub_ps(ix2,jx3);
1554 dy23 = _mm256_sub_ps(iy2,jy3);
1555 dz23 = _mm256_sub_ps(iz2,jz3);
1556 dx31 = _mm256_sub_ps(ix3,jx1);
1557 dy31 = _mm256_sub_ps(iy3,jy1);
1558 dz31 = _mm256_sub_ps(iz3,jz1);
1559 dx32 = _mm256_sub_ps(ix3,jx2);
1560 dy32 = _mm256_sub_ps(iy3,jy2);
1561 dz32 = _mm256_sub_ps(iz3,jz2);
1562 dx33 = _mm256_sub_ps(ix3,jx3);
1563 dy33 = _mm256_sub_ps(iy3,jy3);
1564 dz33 = _mm256_sub_ps(iz3,jz3);
1566 /* Calculate squared distance and things based on it */
1567 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1568 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1569 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1570 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
1571 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1572 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1573 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
1574 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
1575 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
1576 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
1578 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1579 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1580 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1581 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
1582 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1583 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1584 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
1585 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
1586 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
1587 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
1589 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1590 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1591 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1592 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
1593 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1594 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1595 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
1596 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
1597 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
1598 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
1600 fjx0 = _mm256_setzero_ps();
1601 fjy0 = _mm256_setzero_ps();
1602 fjz0 = _mm256_setzero_ps();
1603 fjx1 = _mm256_setzero_ps();
1604 fjy1 = _mm256_setzero_ps();
1605 fjz1 = _mm256_setzero_ps();
1606 fjx2 = _mm256_setzero_ps();
1607 fjy2 = _mm256_setzero_ps();
1608 fjz2 = _mm256_setzero_ps();
1609 fjx3 = _mm256_setzero_ps();
1610 fjy3 = _mm256_setzero_ps();
1611 fjz3 = _mm256_setzero_ps();
1613 /**************************
1614 * CALCULATE INTERACTIONS *
1615 **************************/
1617 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1620 r00 = _mm256_mul_ps(rsq00,rinv00);
1622 /* LENNARD-JONES DISPERSION/REPULSION */
1624 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1625 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
1626 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
1627 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
1628 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
1630 d = _mm256_sub_ps(r00,rswitch);
1631 d = _mm256_max_ps(d,_mm256_setzero_ps());
1632 d2 = _mm256_mul_ps(d,d);
1633 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
1635 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
1637 /* Evaluate switch function */
1638 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1639 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
1640 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1644 fscal = _mm256_and_ps(fscal,cutoff_mask);
1646 /* Calculate temporary vectorial force */
1647 tx = _mm256_mul_ps(fscal,dx00);
1648 ty = _mm256_mul_ps(fscal,dy00);
1649 tz = _mm256_mul_ps(fscal,dz00);
1651 /* Update vectorial force */
1652 fix0 = _mm256_add_ps(fix0,tx);
1653 fiy0 = _mm256_add_ps(fiy0,ty);
1654 fiz0 = _mm256_add_ps(fiz0,tz);
1656 fjx0 = _mm256_add_ps(fjx0,tx);
1657 fjy0 = _mm256_add_ps(fjy0,ty);
1658 fjz0 = _mm256_add_ps(fjz0,tz);
1662 /**************************
1663 * CALCULATE INTERACTIONS *
1664 **************************/
1666 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1669 /* REACTION-FIELD ELECTROSTATICS */
1670 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1672 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1676 fscal = _mm256_and_ps(fscal,cutoff_mask);
1678 /* Calculate temporary vectorial force */
1679 tx = _mm256_mul_ps(fscal,dx11);
1680 ty = _mm256_mul_ps(fscal,dy11);
1681 tz = _mm256_mul_ps(fscal,dz11);
1683 /* Update vectorial force */
1684 fix1 = _mm256_add_ps(fix1,tx);
1685 fiy1 = _mm256_add_ps(fiy1,ty);
1686 fiz1 = _mm256_add_ps(fiz1,tz);
1688 fjx1 = _mm256_add_ps(fjx1,tx);
1689 fjy1 = _mm256_add_ps(fjy1,ty);
1690 fjz1 = _mm256_add_ps(fjz1,tz);
1694 /**************************
1695 * CALCULATE INTERACTIONS *
1696 **************************/
1698 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1701 /* REACTION-FIELD ELECTROSTATICS */
1702 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1704 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1708 fscal = _mm256_and_ps(fscal,cutoff_mask);
1710 /* Calculate temporary vectorial force */
1711 tx = _mm256_mul_ps(fscal,dx12);
1712 ty = _mm256_mul_ps(fscal,dy12);
1713 tz = _mm256_mul_ps(fscal,dz12);
1715 /* Update vectorial force */
1716 fix1 = _mm256_add_ps(fix1,tx);
1717 fiy1 = _mm256_add_ps(fiy1,ty);
1718 fiz1 = _mm256_add_ps(fiz1,tz);
1720 fjx2 = _mm256_add_ps(fjx2,tx);
1721 fjy2 = _mm256_add_ps(fjy2,ty);
1722 fjz2 = _mm256_add_ps(fjz2,tz);
1726 /**************************
1727 * CALCULATE INTERACTIONS *
1728 **************************/
1730 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1733 /* REACTION-FIELD ELECTROSTATICS */
1734 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1736 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1740 fscal = _mm256_and_ps(fscal,cutoff_mask);
1742 /* Calculate temporary vectorial force */
1743 tx = _mm256_mul_ps(fscal,dx13);
1744 ty = _mm256_mul_ps(fscal,dy13);
1745 tz = _mm256_mul_ps(fscal,dz13);
1747 /* Update vectorial force */
1748 fix1 = _mm256_add_ps(fix1,tx);
1749 fiy1 = _mm256_add_ps(fiy1,ty);
1750 fiz1 = _mm256_add_ps(fiz1,tz);
1752 fjx3 = _mm256_add_ps(fjx3,tx);
1753 fjy3 = _mm256_add_ps(fjy3,ty);
1754 fjz3 = _mm256_add_ps(fjz3,tz);
1758 /**************************
1759 * CALCULATE INTERACTIONS *
1760 **************************/
1762 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1765 /* REACTION-FIELD ELECTROSTATICS */
1766 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1768 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1772 fscal = _mm256_and_ps(fscal,cutoff_mask);
1774 /* Calculate temporary vectorial force */
1775 tx = _mm256_mul_ps(fscal,dx21);
1776 ty = _mm256_mul_ps(fscal,dy21);
1777 tz = _mm256_mul_ps(fscal,dz21);
1779 /* Update vectorial force */
1780 fix2 = _mm256_add_ps(fix2,tx);
1781 fiy2 = _mm256_add_ps(fiy2,ty);
1782 fiz2 = _mm256_add_ps(fiz2,tz);
1784 fjx1 = _mm256_add_ps(fjx1,tx);
1785 fjy1 = _mm256_add_ps(fjy1,ty);
1786 fjz1 = _mm256_add_ps(fjz1,tz);
1790 /**************************
1791 * CALCULATE INTERACTIONS *
1792 **************************/
1794 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1797 /* REACTION-FIELD ELECTROSTATICS */
1798 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1800 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1804 fscal = _mm256_and_ps(fscal,cutoff_mask);
1806 /* Calculate temporary vectorial force */
1807 tx = _mm256_mul_ps(fscal,dx22);
1808 ty = _mm256_mul_ps(fscal,dy22);
1809 tz = _mm256_mul_ps(fscal,dz22);
1811 /* Update vectorial force */
1812 fix2 = _mm256_add_ps(fix2,tx);
1813 fiy2 = _mm256_add_ps(fiy2,ty);
1814 fiz2 = _mm256_add_ps(fiz2,tz);
1816 fjx2 = _mm256_add_ps(fjx2,tx);
1817 fjy2 = _mm256_add_ps(fjy2,ty);
1818 fjz2 = _mm256_add_ps(fjz2,tz);
1822 /**************************
1823 * CALCULATE INTERACTIONS *
1824 **************************/
1826 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1829 /* REACTION-FIELD ELECTROSTATICS */
1830 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1832 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1836 fscal = _mm256_and_ps(fscal,cutoff_mask);
1838 /* Calculate temporary vectorial force */
1839 tx = _mm256_mul_ps(fscal,dx23);
1840 ty = _mm256_mul_ps(fscal,dy23);
1841 tz = _mm256_mul_ps(fscal,dz23);
1843 /* Update vectorial force */
1844 fix2 = _mm256_add_ps(fix2,tx);
1845 fiy2 = _mm256_add_ps(fiy2,ty);
1846 fiz2 = _mm256_add_ps(fiz2,tz);
1848 fjx3 = _mm256_add_ps(fjx3,tx);
1849 fjy3 = _mm256_add_ps(fjy3,ty);
1850 fjz3 = _mm256_add_ps(fjz3,tz);
1854 /**************************
1855 * CALCULATE INTERACTIONS *
1856 **************************/
1858 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1861 /* REACTION-FIELD ELECTROSTATICS */
1862 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1864 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1868 fscal = _mm256_and_ps(fscal,cutoff_mask);
1870 /* Calculate temporary vectorial force */
1871 tx = _mm256_mul_ps(fscal,dx31);
1872 ty = _mm256_mul_ps(fscal,dy31);
1873 tz = _mm256_mul_ps(fscal,dz31);
1875 /* Update vectorial force */
1876 fix3 = _mm256_add_ps(fix3,tx);
1877 fiy3 = _mm256_add_ps(fiy3,ty);
1878 fiz3 = _mm256_add_ps(fiz3,tz);
1880 fjx1 = _mm256_add_ps(fjx1,tx);
1881 fjy1 = _mm256_add_ps(fjy1,ty);
1882 fjz1 = _mm256_add_ps(fjz1,tz);
1886 /**************************
1887 * CALCULATE INTERACTIONS *
1888 **************************/
1890 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1893 /* REACTION-FIELD ELECTROSTATICS */
1894 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1896 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1900 fscal = _mm256_and_ps(fscal,cutoff_mask);
1902 /* Calculate temporary vectorial force */
1903 tx = _mm256_mul_ps(fscal,dx32);
1904 ty = _mm256_mul_ps(fscal,dy32);
1905 tz = _mm256_mul_ps(fscal,dz32);
1907 /* Update vectorial force */
1908 fix3 = _mm256_add_ps(fix3,tx);
1909 fiy3 = _mm256_add_ps(fiy3,ty);
1910 fiz3 = _mm256_add_ps(fiz3,tz);
1912 fjx2 = _mm256_add_ps(fjx2,tx);
1913 fjy2 = _mm256_add_ps(fjy2,ty);
1914 fjz2 = _mm256_add_ps(fjz2,tz);
1918 /**************************
1919 * CALCULATE INTERACTIONS *
1920 **************************/
1922 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1925 /* REACTION-FIELD ELECTROSTATICS */
1926 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1928 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1932 fscal = _mm256_and_ps(fscal,cutoff_mask);
1934 /* Calculate temporary vectorial force */
1935 tx = _mm256_mul_ps(fscal,dx33);
1936 ty = _mm256_mul_ps(fscal,dy33);
1937 tz = _mm256_mul_ps(fscal,dz33);
1939 /* Update vectorial force */
1940 fix3 = _mm256_add_ps(fix3,tx);
1941 fiy3 = _mm256_add_ps(fiy3,ty);
1942 fiz3 = _mm256_add_ps(fiz3,tz);
1944 fjx3 = _mm256_add_ps(fjx3,tx);
1945 fjy3 = _mm256_add_ps(fjy3,ty);
1946 fjz3 = _mm256_add_ps(fjz3,tz);
1950 fjptrA = f+j_coord_offsetA;
1951 fjptrB = f+j_coord_offsetB;
1952 fjptrC = f+j_coord_offsetC;
1953 fjptrD = f+j_coord_offsetD;
1954 fjptrE = f+j_coord_offsetE;
1955 fjptrF = f+j_coord_offsetF;
1956 fjptrG = f+j_coord_offsetG;
1957 fjptrH = f+j_coord_offsetH;
1959 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1960 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1961 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1963 /* Inner loop uses 329 flops */
1966 if(jidx<j_index_end)
1969 /* Get j neighbor index, and coordinate index */
1970 jnrlistA = jjnr[jidx];
1971 jnrlistB = jjnr[jidx+1];
1972 jnrlistC = jjnr[jidx+2];
1973 jnrlistD = jjnr[jidx+3];
1974 jnrlistE = jjnr[jidx+4];
1975 jnrlistF = jjnr[jidx+5];
1976 jnrlistG = jjnr[jidx+6];
1977 jnrlistH = jjnr[jidx+7];
1978 /* Sign of each element will be negative for non-real atoms.
1979 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1980 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1982 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1983 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1985 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1986 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1987 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1988 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1989 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
1990 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
1991 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
1992 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
1993 j_coord_offsetA = DIM*jnrA;
1994 j_coord_offsetB = DIM*jnrB;
1995 j_coord_offsetC = DIM*jnrC;
1996 j_coord_offsetD = DIM*jnrD;
1997 j_coord_offsetE = DIM*jnrE;
1998 j_coord_offsetF = DIM*jnrF;
1999 j_coord_offsetG = DIM*jnrG;
2000 j_coord_offsetH = DIM*jnrH;
2002 /* load j atom coordinates */
2003 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
2004 x+j_coord_offsetC,x+j_coord_offsetD,
2005 x+j_coord_offsetE,x+j_coord_offsetF,
2006 x+j_coord_offsetG,x+j_coord_offsetH,
2007 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
2008 &jy2,&jz2,&jx3,&jy3,&jz3);
2010 /* Calculate displacement vector */
2011 dx00 = _mm256_sub_ps(ix0,jx0);
2012 dy00 = _mm256_sub_ps(iy0,jy0);
2013 dz00 = _mm256_sub_ps(iz0,jz0);
2014 dx11 = _mm256_sub_ps(ix1,jx1);
2015 dy11 = _mm256_sub_ps(iy1,jy1);
2016 dz11 = _mm256_sub_ps(iz1,jz1);
2017 dx12 = _mm256_sub_ps(ix1,jx2);
2018 dy12 = _mm256_sub_ps(iy1,jy2);
2019 dz12 = _mm256_sub_ps(iz1,jz2);
2020 dx13 = _mm256_sub_ps(ix1,jx3);
2021 dy13 = _mm256_sub_ps(iy1,jy3);
2022 dz13 = _mm256_sub_ps(iz1,jz3);
2023 dx21 = _mm256_sub_ps(ix2,jx1);
2024 dy21 = _mm256_sub_ps(iy2,jy1);
2025 dz21 = _mm256_sub_ps(iz2,jz1);
2026 dx22 = _mm256_sub_ps(ix2,jx2);
2027 dy22 = _mm256_sub_ps(iy2,jy2);
2028 dz22 = _mm256_sub_ps(iz2,jz2);
2029 dx23 = _mm256_sub_ps(ix2,jx3);
2030 dy23 = _mm256_sub_ps(iy2,jy3);
2031 dz23 = _mm256_sub_ps(iz2,jz3);
2032 dx31 = _mm256_sub_ps(ix3,jx1);
2033 dy31 = _mm256_sub_ps(iy3,jy1);
2034 dz31 = _mm256_sub_ps(iz3,jz1);
2035 dx32 = _mm256_sub_ps(ix3,jx2);
2036 dy32 = _mm256_sub_ps(iy3,jy2);
2037 dz32 = _mm256_sub_ps(iz3,jz2);
2038 dx33 = _mm256_sub_ps(ix3,jx3);
2039 dy33 = _mm256_sub_ps(iy3,jy3);
2040 dz33 = _mm256_sub_ps(iz3,jz3);
2042 /* Calculate squared distance and things based on it */
2043 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
2044 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
2045 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
2046 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
2047 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
2048 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
2049 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
2050 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
2051 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
2052 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
2054 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
2055 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
2056 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
2057 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
2058 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
2059 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
2060 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
2061 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
2062 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
2063 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
2065 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
2066 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
2067 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
2068 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
2069 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
2070 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
2071 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
2072 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
2073 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
2074 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
2076 fjx0 = _mm256_setzero_ps();
2077 fjy0 = _mm256_setzero_ps();
2078 fjz0 = _mm256_setzero_ps();
2079 fjx1 = _mm256_setzero_ps();
2080 fjy1 = _mm256_setzero_ps();
2081 fjz1 = _mm256_setzero_ps();
2082 fjx2 = _mm256_setzero_ps();
2083 fjy2 = _mm256_setzero_ps();
2084 fjz2 = _mm256_setzero_ps();
2085 fjx3 = _mm256_setzero_ps();
2086 fjy3 = _mm256_setzero_ps();
2087 fjz3 = _mm256_setzero_ps();
2089 /**************************
2090 * CALCULATE INTERACTIONS *
2091 **************************/
2093 if (gmx_mm256_any_lt(rsq00,rcutoff2))
2096 r00 = _mm256_mul_ps(rsq00,rinv00);
2097 r00 = _mm256_andnot_ps(dummy_mask,r00);
2099 /* LENNARD-JONES DISPERSION/REPULSION */
2101 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
2102 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
2103 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
2104 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
2105 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
2107 d = _mm256_sub_ps(r00,rswitch);
2108 d = _mm256_max_ps(d,_mm256_setzero_ps());
2109 d2 = _mm256_mul_ps(d,d);
2110 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
2112 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
2114 /* Evaluate switch function */
2115 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
2116 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
2117 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2121 fscal = _mm256_and_ps(fscal,cutoff_mask);
2123 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2125 /* Calculate temporary vectorial force */
2126 tx = _mm256_mul_ps(fscal,dx00);
2127 ty = _mm256_mul_ps(fscal,dy00);
2128 tz = _mm256_mul_ps(fscal,dz00);
2130 /* Update vectorial force */
2131 fix0 = _mm256_add_ps(fix0,tx);
2132 fiy0 = _mm256_add_ps(fiy0,ty);
2133 fiz0 = _mm256_add_ps(fiz0,tz);
2135 fjx0 = _mm256_add_ps(fjx0,tx);
2136 fjy0 = _mm256_add_ps(fjy0,ty);
2137 fjz0 = _mm256_add_ps(fjz0,tz);
2141 /**************************
2142 * CALCULATE INTERACTIONS *
2143 **************************/
2145 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2148 /* REACTION-FIELD ELECTROSTATICS */
2149 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2151 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2155 fscal = _mm256_and_ps(fscal,cutoff_mask);
2157 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2159 /* Calculate temporary vectorial force */
2160 tx = _mm256_mul_ps(fscal,dx11);
2161 ty = _mm256_mul_ps(fscal,dy11);
2162 tz = _mm256_mul_ps(fscal,dz11);
2164 /* Update vectorial force */
2165 fix1 = _mm256_add_ps(fix1,tx);
2166 fiy1 = _mm256_add_ps(fiy1,ty);
2167 fiz1 = _mm256_add_ps(fiz1,tz);
2169 fjx1 = _mm256_add_ps(fjx1,tx);
2170 fjy1 = _mm256_add_ps(fjy1,ty);
2171 fjz1 = _mm256_add_ps(fjz1,tz);
2175 /**************************
2176 * CALCULATE INTERACTIONS *
2177 **************************/
2179 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2182 /* REACTION-FIELD ELECTROSTATICS */
2183 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2185 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2189 fscal = _mm256_and_ps(fscal,cutoff_mask);
2191 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2193 /* Calculate temporary vectorial force */
2194 tx = _mm256_mul_ps(fscal,dx12);
2195 ty = _mm256_mul_ps(fscal,dy12);
2196 tz = _mm256_mul_ps(fscal,dz12);
2198 /* Update vectorial force */
2199 fix1 = _mm256_add_ps(fix1,tx);
2200 fiy1 = _mm256_add_ps(fiy1,ty);
2201 fiz1 = _mm256_add_ps(fiz1,tz);
2203 fjx2 = _mm256_add_ps(fjx2,tx);
2204 fjy2 = _mm256_add_ps(fjy2,ty);
2205 fjz2 = _mm256_add_ps(fjz2,tz);
2209 /**************************
2210 * CALCULATE INTERACTIONS *
2211 **************************/
2213 if (gmx_mm256_any_lt(rsq13,rcutoff2))
2216 /* REACTION-FIELD ELECTROSTATICS */
2217 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
2219 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
2223 fscal = _mm256_and_ps(fscal,cutoff_mask);
2225 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2227 /* Calculate temporary vectorial force */
2228 tx = _mm256_mul_ps(fscal,dx13);
2229 ty = _mm256_mul_ps(fscal,dy13);
2230 tz = _mm256_mul_ps(fscal,dz13);
2232 /* Update vectorial force */
2233 fix1 = _mm256_add_ps(fix1,tx);
2234 fiy1 = _mm256_add_ps(fiy1,ty);
2235 fiz1 = _mm256_add_ps(fiz1,tz);
2237 fjx3 = _mm256_add_ps(fjx3,tx);
2238 fjy3 = _mm256_add_ps(fjy3,ty);
2239 fjz3 = _mm256_add_ps(fjz3,tz);
2243 /**************************
2244 * CALCULATE INTERACTIONS *
2245 **************************/
2247 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2250 /* REACTION-FIELD ELECTROSTATICS */
2251 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2253 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2257 fscal = _mm256_and_ps(fscal,cutoff_mask);
2259 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2261 /* Calculate temporary vectorial force */
2262 tx = _mm256_mul_ps(fscal,dx21);
2263 ty = _mm256_mul_ps(fscal,dy21);
2264 tz = _mm256_mul_ps(fscal,dz21);
2266 /* Update vectorial force */
2267 fix2 = _mm256_add_ps(fix2,tx);
2268 fiy2 = _mm256_add_ps(fiy2,ty);
2269 fiz2 = _mm256_add_ps(fiz2,tz);
2271 fjx1 = _mm256_add_ps(fjx1,tx);
2272 fjy1 = _mm256_add_ps(fjy1,ty);
2273 fjz1 = _mm256_add_ps(fjz1,tz);
2277 /**************************
2278 * CALCULATE INTERACTIONS *
2279 **************************/
2281 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2284 /* REACTION-FIELD ELECTROSTATICS */
2285 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2287 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2291 fscal = _mm256_and_ps(fscal,cutoff_mask);
2293 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2295 /* Calculate temporary vectorial force */
2296 tx = _mm256_mul_ps(fscal,dx22);
2297 ty = _mm256_mul_ps(fscal,dy22);
2298 tz = _mm256_mul_ps(fscal,dz22);
2300 /* Update vectorial force */
2301 fix2 = _mm256_add_ps(fix2,tx);
2302 fiy2 = _mm256_add_ps(fiy2,ty);
2303 fiz2 = _mm256_add_ps(fiz2,tz);
2305 fjx2 = _mm256_add_ps(fjx2,tx);
2306 fjy2 = _mm256_add_ps(fjy2,ty);
2307 fjz2 = _mm256_add_ps(fjz2,tz);
2311 /**************************
2312 * CALCULATE INTERACTIONS *
2313 **************************/
2315 if (gmx_mm256_any_lt(rsq23,rcutoff2))
2318 /* REACTION-FIELD ELECTROSTATICS */
2319 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
2321 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
2325 fscal = _mm256_and_ps(fscal,cutoff_mask);
2327 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2329 /* Calculate temporary vectorial force */
2330 tx = _mm256_mul_ps(fscal,dx23);
2331 ty = _mm256_mul_ps(fscal,dy23);
2332 tz = _mm256_mul_ps(fscal,dz23);
2334 /* Update vectorial force */
2335 fix2 = _mm256_add_ps(fix2,tx);
2336 fiy2 = _mm256_add_ps(fiy2,ty);
2337 fiz2 = _mm256_add_ps(fiz2,tz);
2339 fjx3 = _mm256_add_ps(fjx3,tx);
2340 fjy3 = _mm256_add_ps(fjy3,ty);
2341 fjz3 = _mm256_add_ps(fjz3,tz);
2345 /**************************
2346 * CALCULATE INTERACTIONS *
2347 **************************/
2349 if (gmx_mm256_any_lt(rsq31,rcutoff2))
2352 /* REACTION-FIELD ELECTROSTATICS */
2353 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
2355 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
2359 fscal = _mm256_and_ps(fscal,cutoff_mask);
2361 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2363 /* Calculate temporary vectorial force */
2364 tx = _mm256_mul_ps(fscal,dx31);
2365 ty = _mm256_mul_ps(fscal,dy31);
2366 tz = _mm256_mul_ps(fscal,dz31);
2368 /* Update vectorial force */
2369 fix3 = _mm256_add_ps(fix3,tx);
2370 fiy3 = _mm256_add_ps(fiy3,ty);
2371 fiz3 = _mm256_add_ps(fiz3,tz);
2373 fjx1 = _mm256_add_ps(fjx1,tx);
2374 fjy1 = _mm256_add_ps(fjy1,ty);
2375 fjz1 = _mm256_add_ps(fjz1,tz);
2379 /**************************
2380 * CALCULATE INTERACTIONS *
2381 **************************/
2383 if (gmx_mm256_any_lt(rsq32,rcutoff2))
2386 /* REACTION-FIELD ELECTROSTATICS */
2387 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
2389 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
2393 fscal = _mm256_and_ps(fscal,cutoff_mask);
2395 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2397 /* Calculate temporary vectorial force */
2398 tx = _mm256_mul_ps(fscal,dx32);
2399 ty = _mm256_mul_ps(fscal,dy32);
2400 tz = _mm256_mul_ps(fscal,dz32);
2402 /* Update vectorial force */
2403 fix3 = _mm256_add_ps(fix3,tx);
2404 fiy3 = _mm256_add_ps(fiy3,ty);
2405 fiz3 = _mm256_add_ps(fiz3,tz);
2407 fjx2 = _mm256_add_ps(fjx2,tx);
2408 fjy2 = _mm256_add_ps(fjy2,ty);
2409 fjz2 = _mm256_add_ps(fjz2,tz);
2413 /**************************
2414 * CALCULATE INTERACTIONS *
2415 **************************/
2417 if (gmx_mm256_any_lt(rsq33,rcutoff2))
2420 /* REACTION-FIELD ELECTROSTATICS */
2421 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
2423 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
2427 fscal = _mm256_and_ps(fscal,cutoff_mask);
2429 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2431 /* Calculate temporary vectorial force */
2432 tx = _mm256_mul_ps(fscal,dx33);
2433 ty = _mm256_mul_ps(fscal,dy33);
2434 tz = _mm256_mul_ps(fscal,dz33);
2436 /* Update vectorial force */
2437 fix3 = _mm256_add_ps(fix3,tx);
2438 fiy3 = _mm256_add_ps(fiy3,ty);
2439 fiz3 = _mm256_add_ps(fiz3,tz);
2441 fjx3 = _mm256_add_ps(fjx3,tx);
2442 fjy3 = _mm256_add_ps(fjy3,ty);
2443 fjz3 = _mm256_add_ps(fjz3,tz);
2447 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2448 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2449 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2450 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2451 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2452 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2453 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2454 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2456 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2457 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2458 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2460 /* Inner loop uses 330 flops */
2463 /* End of innermost loop */
2465 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2466 f+i_coord_offset,fshift+i_shift_offset);
2468 /* Increment number of inner iterations */
2469 inneriter += j_index_end - j_index_start;
2471 /* Outer loop uses 24 flops */
2474 /* Increment number of outer iterations */
2477 /* Update outer/inner flops */
2479 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*330);