2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_256_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_256_single.h"
48 #include "kernelutil_x86_avx_256_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Water4
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrE,jnrF,jnrG,jnrH;
76 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
77 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
80 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
82 real *shiftvec,*fshift,*x,*f;
83 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
85 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 real * vdwioffsetptr0;
87 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 real * vdwioffsetptr1;
89 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 real * vdwioffsetptr2;
91 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 real * vdwioffsetptr3;
93 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
94 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
95 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
96 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
97 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
98 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
99 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
100 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
101 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
102 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
103 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
104 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
105 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
106 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
107 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
108 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
109 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
110 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
111 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
112 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
115 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
118 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
119 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
120 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
121 real rswitch_scalar,d_scalar;
122 __m256 dummy_mask,cutoff_mask;
123 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
124 __m256 one = _mm256_set1_ps(1.0);
125 __m256 two = _mm256_set1_ps(2.0);
131 jindex = nlist->jindex;
133 shiftidx = nlist->shift;
135 shiftvec = fr->shift_vec[0];
136 fshift = fr->fshift[0];
137 facel = _mm256_set1_ps(fr->epsfac);
138 charge = mdatoms->chargeA;
139 krf = _mm256_set1_ps(fr->ic->k_rf);
140 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
141 crf = _mm256_set1_ps(fr->ic->c_rf);
142 nvdwtype = fr->ntype;
144 vdwtype = mdatoms->typeA;
146 /* Setup water-specific parameters */
147 inr = nlist->iinr[0];
148 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
149 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
150 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
151 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
153 jq1 = _mm256_set1_ps(charge[inr+1]);
154 jq2 = _mm256_set1_ps(charge[inr+2]);
155 jq3 = _mm256_set1_ps(charge[inr+3]);
156 vdwjidx0A = 2*vdwtype[inr+0];
157 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
158 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
159 qq11 = _mm256_mul_ps(iq1,jq1);
160 qq12 = _mm256_mul_ps(iq1,jq2);
161 qq13 = _mm256_mul_ps(iq1,jq3);
162 qq21 = _mm256_mul_ps(iq2,jq1);
163 qq22 = _mm256_mul_ps(iq2,jq2);
164 qq23 = _mm256_mul_ps(iq2,jq3);
165 qq31 = _mm256_mul_ps(iq3,jq1);
166 qq32 = _mm256_mul_ps(iq3,jq2);
167 qq33 = _mm256_mul_ps(iq3,jq3);
169 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
170 rcutoff_scalar = fr->rcoulomb;
171 rcutoff = _mm256_set1_ps(rcutoff_scalar);
172 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
174 rswitch_scalar = fr->rvdw_switch;
175 rswitch = _mm256_set1_ps(rswitch_scalar);
176 /* Setup switch parameters */
177 d_scalar = rcutoff_scalar-rswitch_scalar;
178 d = _mm256_set1_ps(d_scalar);
179 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
180 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
181 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
182 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
183 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
184 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
186 /* Avoid stupid compiler warnings */
187 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
200 for(iidx=0;iidx<4*DIM;iidx++)
205 /* Start outer loop over neighborlists */
206 for(iidx=0; iidx<nri; iidx++)
208 /* Load shift vector for this list */
209 i_shift_offset = DIM*shiftidx[iidx];
211 /* Load limits for loop over neighbors */
212 j_index_start = jindex[iidx];
213 j_index_end = jindex[iidx+1];
215 /* Get outer coordinate index */
217 i_coord_offset = DIM*inr;
219 /* Load i particle coords and add shift vector */
220 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
221 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
223 fix0 = _mm256_setzero_ps();
224 fiy0 = _mm256_setzero_ps();
225 fiz0 = _mm256_setzero_ps();
226 fix1 = _mm256_setzero_ps();
227 fiy1 = _mm256_setzero_ps();
228 fiz1 = _mm256_setzero_ps();
229 fix2 = _mm256_setzero_ps();
230 fiy2 = _mm256_setzero_ps();
231 fiz2 = _mm256_setzero_ps();
232 fix3 = _mm256_setzero_ps();
233 fiy3 = _mm256_setzero_ps();
234 fiz3 = _mm256_setzero_ps();
236 /* Reset potential sums */
237 velecsum = _mm256_setzero_ps();
238 vvdwsum = _mm256_setzero_ps();
240 /* Start inner kernel loop */
241 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
244 /* Get j neighbor index, and coordinate index */
253 j_coord_offsetA = DIM*jnrA;
254 j_coord_offsetB = DIM*jnrB;
255 j_coord_offsetC = DIM*jnrC;
256 j_coord_offsetD = DIM*jnrD;
257 j_coord_offsetE = DIM*jnrE;
258 j_coord_offsetF = DIM*jnrF;
259 j_coord_offsetG = DIM*jnrG;
260 j_coord_offsetH = DIM*jnrH;
262 /* load j atom coordinates */
263 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
264 x+j_coord_offsetC,x+j_coord_offsetD,
265 x+j_coord_offsetE,x+j_coord_offsetF,
266 x+j_coord_offsetG,x+j_coord_offsetH,
267 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
268 &jy2,&jz2,&jx3,&jy3,&jz3);
270 /* Calculate displacement vector */
271 dx00 = _mm256_sub_ps(ix0,jx0);
272 dy00 = _mm256_sub_ps(iy0,jy0);
273 dz00 = _mm256_sub_ps(iz0,jz0);
274 dx11 = _mm256_sub_ps(ix1,jx1);
275 dy11 = _mm256_sub_ps(iy1,jy1);
276 dz11 = _mm256_sub_ps(iz1,jz1);
277 dx12 = _mm256_sub_ps(ix1,jx2);
278 dy12 = _mm256_sub_ps(iy1,jy2);
279 dz12 = _mm256_sub_ps(iz1,jz2);
280 dx13 = _mm256_sub_ps(ix1,jx3);
281 dy13 = _mm256_sub_ps(iy1,jy3);
282 dz13 = _mm256_sub_ps(iz1,jz3);
283 dx21 = _mm256_sub_ps(ix2,jx1);
284 dy21 = _mm256_sub_ps(iy2,jy1);
285 dz21 = _mm256_sub_ps(iz2,jz1);
286 dx22 = _mm256_sub_ps(ix2,jx2);
287 dy22 = _mm256_sub_ps(iy2,jy2);
288 dz22 = _mm256_sub_ps(iz2,jz2);
289 dx23 = _mm256_sub_ps(ix2,jx3);
290 dy23 = _mm256_sub_ps(iy2,jy3);
291 dz23 = _mm256_sub_ps(iz2,jz3);
292 dx31 = _mm256_sub_ps(ix3,jx1);
293 dy31 = _mm256_sub_ps(iy3,jy1);
294 dz31 = _mm256_sub_ps(iz3,jz1);
295 dx32 = _mm256_sub_ps(ix3,jx2);
296 dy32 = _mm256_sub_ps(iy3,jy2);
297 dz32 = _mm256_sub_ps(iz3,jz2);
298 dx33 = _mm256_sub_ps(ix3,jx3);
299 dy33 = _mm256_sub_ps(iy3,jy3);
300 dz33 = _mm256_sub_ps(iz3,jz3);
302 /* Calculate squared distance and things based on it */
303 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
304 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
305 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
306 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
307 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
308 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
309 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
310 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
311 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
312 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
314 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
315 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
316 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
317 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
318 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
319 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
320 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
321 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
322 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
323 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
325 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
326 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
327 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
328 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
329 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
330 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
331 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
332 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
333 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
334 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
336 fjx0 = _mm256_setzero_ps();
337 fjy0 = _mm256_setzero_ps();
338 fjz0 = _mm256_setzero_ps();
339 fjx1 = _mm256_setzero_ps();
340 fjy1 = _mm256_setzero_ps();
341 fjz1 = _mm256_setzero_ps();
342 fjx2 = _mm256_setzero_ps();
343 fjy2 = _mm256_setzero_ps();
344 fjz2 = _mm256_setzero_ps();
345 fjx3 = _mm256_setzero_ps();
346 fjy3 = _mm256_setzero_ps();
347 fjz3 = _mm256_setzero_ps();
349 /**************************
350 * CALCULATE INTERACTIONS *
351 **************************/
353 if (gmx_mm256_any_lt(rsq00,rcutoff2))
356 r00 = _mm256_mul_ps(rsq00,rinv00);
358 /* LENNARD-JONES DISPERSION/REPULSION */
360 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
361 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
362 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
363 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
364 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
366 d = _mm256_sub_ps(r00,rswitch);
367 d = _mm256_max_ps(d,_mm256_setzero_ps());
368 d2 = _mm256_mul_ps(d,d);
369 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)))))));
371 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
373 /* Evaluate switch function */
374 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
375 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
376 vvdw = _mm256_mul_ps(vvdw,sw);
377 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
379 /* Update potential sum for this i atom from the interaction with this j atom. */
380 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
381 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
385 fscal = _mm256_and_ps(fscal,cutoff_mask);
387 /* Calculate temporary vectorial force */
388 tx = _mm256_mul_ps(fscal,dx00);
389 ty = _mm256_mul_ps(fscal,dy00);
390 tz = _mm256_mul_ps(fscal,dz00);
392 /* Update vectorial force */
393 fix0 = _mm256_add_ps(fix0,tx);
394 fiy0 = _mm256_add_ps(fiy0,ty);
395 fiz0 = _mm256_add_ps(fiz0,tz);
397 fjx0 = _mm256_add_ps(fjx0,tx);
398 fjy0 = _mm256_add_ps(fjy0,ty);
399 fjz0 = _mm256_add_ps(fjz0,tz);
403 /**************************
404 * CALCULATE INTERACTIONS *
405 **************************/
407 if (gmx_mm256_any_lt(rsq11,rcutoff2))
410 /* REACTION-FIELD ELECTROSTATICS */
411 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
412 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
414 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
416 /* Update potential sum for this i atom from the interaction with this j atom. */
417 velec = _mm256_and_ps(velec,cutoff_mask);
418 velecsum = _mm256_add_ps(velecsum,velec);
422 fscal = _mm256_and_ps(fscal,cutoff_mask);
424 /* Calculate temporary vectorial force */
425 tx = _mm256_mul_ps(fscal,dx11);
426 ty = _mm256_mul_ps(fscal,dy11);
427 tz = _mm256_mul_ps(fscal,dz11);
429 /* Update vectorial force */
430 fix1 = _mm256_add_ps(fix1,tx);
431 fiy1 = _mm256_add_ps(fiy1,ty);
432 fiz1 = _mm256_add_ps(fiz1,tz);
434 fjx1 = _mm256_add_ps(fjx1,tx);
435 fjy1 = _mm256_add_ps(fjy1,ty);
436 fjz1 = _mm256_add_ps(fjz1,tz);
440 /**************************
441 * CALCULATE INTERACTIONS *
442 **************************/
444 if (gmx_mm256_any_lt(rsq12,rcutoff2))
447 /* REACTION-FIELD ELECTROSTATICS */
448 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
449 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
451 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm256_and_ps(velec,cutoff_mask);
455 velecsum = _mm256_add_ps(velecsum,velec);
459 fscal = _mm256_and_ps(fscal,cutoff_mask);
461 /* Calculate temporary vectorial force */
462 tx = _mm256_mul_ps(fscal,dx12);
463 ty = _mm256_mul_ps(fscal,dy12);
464 tz = _mm256_mul_ps(fscal,dz12);
466 /* Update vectorial force */
467 fix1 = _mm256_add_ps(fix1,tx);
468 fiy1 = _mm256_add_ps(fiy1,ty);
469 fiz1 = _mm256_add_ps(fiz1,tz);
471 fjx2 = _mm256_add_ps(fjx2,tx);
472 fjy2 = _mm256_add_ps(fjy2,ty);
473 fjz2 = _mm256_add_ps(fjz2,tz);
477 /**************************
478 * CALCULATE INTERACTIONS *
479 **************************/
481 if (gmx_mm256_any_lt(rsq13,rcutoff2))
484 /* REACTION-FIELD ELECTROSTATICS */
485 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
486 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
488 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
490 /* Update potential sum for this i atom from the interaction with this j atom. */
491 velec = _mm256_and_ps(velec,cutoff_mask);
492 velecsum = _mm256_add_ps(velecsum,velec);
496 fscal = _mm256_and_ps(fscal,cutoff_mask);
498 /* Calculate temporary vectorial force */
499 tx = _mm256_mul_ps(fscal,dx13);
500 ty = _mm256_mul_ps(fscal,dy13);
501 tz = _mm256_mul_ps(fscal,dz13);
503 /* Update vectorial force */
504 fix1 = _mm256_add_ps(fix1,tx);
505 fiy1 = _mm256_add_ps(fiy1,ty);
506 fiz1 = _mm256_add_ps(fiz1,tz);
508 fjx3 = _mm256_add_ps(fjx3,tx);
509 fjy3 = _mm256_add_ps(fjy3,ty);
510 fjz3 = _mm256_add_ps(fjz3,tz);
514 /**************************
515 * CALCULATE INTERACTIONS *
516 **************************/
518 if (gmx_mm256_any_lt(rsq21,rcutoff2))
521 /* REACTION-FIELD ELECTROSTATICS */
522 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
523 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
525 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
527 /* Update potential sum for this i atom from the interaction with this j atom. */
528 velec = _mm256_and_ps(velec,cutoff_mask);
529 velecsum = _mm256_add_ps(velecsum,velec);
533 fscal = _mm256_and_ps(fscal,cutoff_mask);
535 /* Calculate temporary vectorial force */
536 tx = _mm256_mul_ps(fscal,dx21);
537 ty = _mm256_mul_ps(fscal,dy21);
538 tz = _mm256_mul_ps(fscal,dz21);
540 /* Update vectorial force */
541 fix2 = _mm256_add_ps(fix2,tx);
542 fiy2 = _mm256_add_ps(fiy2,ty);
543 fiz2 = _mm256_add_ps(fiz2,tz);
545 fjx1 = _mm256_add_ps(fjx1,tx);
546 fjy1 = _mm256_add_ps(fjy1,ty);
547 fjz1 = _mm256_add_ps(fjz1,tz);
551 /**************************
552 * CALCULATE INTERACTIONS *
553 **************************/
555 if (gmx_mm256_any_lt(rsq22,rcutoff2))
558 /* REACTION-FIELD ELECTROSTATICS */
559 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
560 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
562 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
564 /* Update potential sum for this i atom from the interaction with this j atom. */
565 velec = _mm256_and_ps(velec,cutoff_mask);
566 velecsum = _mm256_add_ps(velecsum,velec);
570 fscal = _mm256_and_ps(fscal,cutoff_mask);
572 /* Calculate temporary vectorial force */
573 tx = _mm256_mul_ps(fscal,dx22);
574 ty = _mm256_mul_ps(fscal,dy22);
575 tz = _mm256_mul_ps(fscal,dz22);
577 /* Update vectorial force */
578 fix2 = _mm256_add_ps(fix2,tx);
579 fiy2 = _mm256_add_ps(fiy2,ty);
580 fiz2 = _mm256_add_ps(fiz2,tz);
582 fjx2 = _mm256_add_ps(fjx2,tx);
583 fjy2 = _mm256_add_ps(fjy2,ty);
584 fjz2 = _mm256_add_ps(fjz2,tz);
588 /**************************
589 * CALCULATE INTERACTIONS *
590 **************************/
592 if (gmx_mm256_any_lt(rsq23,rcutoff2))
595 /* REACTION-FIELD ELECTROSTATICS */
596 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
597 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
599 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
601 /* Update potential sum for this i atom from the interaction with this j atom. */
602 velec = _mm256_and_ps(velec,cutoff_mask);
603 velecsum = _mm256_add_ps(velecsum,velec);
607 fscal = _mm256_and_ps(fscal,cutoff_mask);
609 /* Calculate temporary vectorial force */
610 tx = _mm256_mul_ps(fscal,dx23);
611 ty = _mm256_mul_ps(fscal,dy23);
612 tz = _mm256_mul_ps(fscal,dz23);
614 /* Update vectorial force */
615 fix2 = _mm256_add_ps(fix2,tx);
616 fiy2 = _mm256_add_ps(fiy2,ty);
617 fiz2 = _mm256_add_ps(fiz2,tz);
619 fjx3 = _mm256_add_ps(fjx3,tx);
620 fjy3 = _mm256_add_ps(fjy3,ty);
621 fjz3 = _mm256_add_ps(fjz3,tz);
625 /**************************
626 * CALCULATE INTERACTIONS *
627 **************************/
629 if (gmx_mm256_any_lt(rsq31,rcutoff2))
632 /* REACTION-FIELD ELECTROSTATICS */
633 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
634 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
636 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
638 /* Update potential sum for this i atom from the interaction with this j atom. */
639 velec = _mm256_and_ps(velec,cutoff_mask);
640 velecsum = _mm256_add_ps(velecsum,velec);
644 fscal = _mm256_and_ps(fscal,cutoff_mask);
646 /* Calculate temporary vectorial force */
647 tx = _mm256_mul_ps(fscal,dx31);
648 ty = _mm256_mul_ps(fscal,dy31);
649 tz = _mm256_mul_ps(fscal,dz31);
651 /* Update vectorial force */
652 fix3 = _mm256_add_ps(fix3,tx);
653 fiy3 = _mm256_add_ps(fiy3,ty);
654 fiz3 = _mm256_add_ps(fiz3,tz);
656 fjx1 = _mm256_add_ps(fjx1,tx);
657 fjy1 = _mm256_add_ps(fjy1,ty);
658 fjz1 = _mm256_add_ps(fjz1,tz);
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
666 if (gmx_mm256_any_lt(rsq32,rcutoff2))
669 /* REACTION-FIELD ELECTROSTATICS */
670 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
671 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
673 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
675 /* Update potential sum for this i atom from the interaction with this j atom. */
676 velec = _mm256_and_ps(velec,cutoff_mask);
677 velecsum = _mm256_add_ps(velecsum,velec);
681 fscal = _mm256_and_ps(fscal,cutoff_mask);
683 /* Calculate temporary vectorial force */
684 tx = _mm256_mul_ps(fscal,dx32);
685 ty = _mm256_mul_ps(fscal,dy32);
686 tz = _mm256_mul_ps(fscal,dz32);
688 /* Update vectorial force */
689 fix3 = _mm256_add_ps(fix3,tx);
690 fiy3 = _mm256_add_ps(fiy3,ty);
691 fiz3 = _mm256_add_ps(fiz3,tz);
693 fjx2 = _mm256_add_ps(fjx2,tx);
694 fjy2 = _mm256_add_ps(fjy2,ty);
695 fjz2 = _mm256_add_ps(fjz2,tz);
699 /**************************
700 * CALCULATE INTERACTIONS *
701 **************************/
703 if (gmx_mm256_any_lt(rsq33,rcutoff2))
706 /* REACTION-FIELD ELECTROSTATICS */
707 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
708 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
710 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
712 /* Update potential sum for this i atom from the interaction with this j atom. */
713 velec = _mm256_and_ps(velec,cutoff_mask);
714 velecsum = _mm256_add_ps(velecsum,velec);
718 fscal = _mm256_and_ps(fscal,cutoff_mask);
720 /* Calculate temporary vectorial force */
721 tx = _mm256_mul_ps(fscal,dx33);
722 ty = _mm256_mul_ps(fscal,dy33);
723 tz = _mm256_mul_ps(fscal,dz33);
725 /* Update vectorial force */
726 fix3 = _mm256_add_ps(fix3,tx);
727 fiy3 = _mm256_add_ps(fiy3,ty);
728 fiz3 = _mm256_add_ps(fiz3,tz);
730 fjx3 = _mm256_add_ps(fjx3,tx);
731 fjy3 = _mm256_add_ps(fjy3,ty);
732 fjz3 = _mm256_add_ps(fjz3,tz);
736 fjptrA = f+j_coord_offsetA;
737 fjptrB = f+j_coord_offsetB;
738 fjptrC = f+j_coord_offsetC;
739 fjptrD = f+j_coord_offsetD;
740 fjptrE = f+j_coord_offsetE;
741 fjptrF = f+j_coord_offsetF;
742 fjptrG = f+j_coord_offsetG;
743 fjptrH = f+j_coord_offsetH;
745 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
746 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
747 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
749 /* Inner loop uses 386 flops */
755 /* Get j neighbor index, and coordinate index */
756 jnrlistA = jjnr[jidx];
757 jnrlistB = jjnr[jidx+1];
758 jnrlistC = jjnr[jidx+2];
759 jnrlistD = jjnr[jidx+3];
760 jnrlistE = jjnr[jidx+4];
761 jnrlistF = jjnr[jidx+5];
762 jnrlistG = jjnr[jidx+6];
763 jnrlistH = jjnr[jidx+7];
764 /* Sign of each element will be negative for non-real atoms.
765 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
766 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
768 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
769 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
771 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
772 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
773 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
774 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
775 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
776 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
777 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
778 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
779 j_coord_offsetA = DIM*jnrA;
780 j_coord_offsetB = DIM*jnrB;
781 j_coord_offsetC = DIM*jnrC;
782 j_coord_offsetD = DIM*jnrD;
783 j_coord_offsetE = DIM*jnrE;
784 j_coord_offsetF = DIM*jnrF;
785 j_coord_offsetG = DIM*jnrG;
786 j_coord_offsetH = DIM*jnrH;
788 /* load j atom coordinates */
789 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
790 x+j_coord_offsetC,x+j_coord_offsetD,
791 x+j_coord_offsetE,x+j_coord_offsetF,
792 x+j_coord_offsetG,x+j_coord_offsetH,
793 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
794 &jy2,&jz2,&jx3,&jy3,&jz3);
796 /* Calculate displacement vector */
797 dx00 = _mm256_sub_ps(ix0,jx0);
798 dy00 = _mm256_sub_ps(iy0,jy0);
799 dz00 = _mm256_sub_ps(iz0,jz0);
800 dx11 = _mm256_sub_ps(ix1,jx1);
801 dy11 = _mm256_sub_ps(iy1,jy1);
802 dz11 = _mm256_sub_ps(iz1,jz1);
803 dx12 = _mm256_sub_ps(ix1,jx2);
804 dy12 = _mm256_sub_ps(iy1,jy2);
805 dz12 = _mm256_sub_ps(iz1,jz2);
806 dx13 = _mm256_sub_ps(ix1,jx3);
807 dy13 = _mm256_sub_ps(iy1,jy3);
808 dz13 = _mm256_sub_ps(iz1,jz3);
809 dx21 = _mm256_sub_ps(ix2,jx1);
810 dy21 = _mm256_sub_ps(iy2,jy1);
811 dz21 = _mm256_sub_ps(iz2,jz1);
812 dx22 = _mm256_sub_ps(ix2,jx2);
813 dy22 = _mm256_sub_ps(iy2,jy2);
814 dz22 = _mm256_sub_ps(iz2,jz2);
815 dx23 = _mm256_sub_ps(ix2,jx3);
816 dy23 = _mm256_sub_ps(iy2,jy3);
817 dz23 = _mm256_sub_ps(iz2,jz3);
818 dx31 = _mm256_sub_ps(ix3,jx1);
819 dy31 = _mm256_sub_ps(iy3,jy1);
820 dz31 = _mm256_sub_ps(iz3,jz1);
821 dx32 = _mm256_sub_ps(ix3,jx2);
822 dy32 = _mm256_sub_ps(iy3,jy2);
823 dz32 = _mm256_sub_ps(iz3,jz2);
824 dx33 = _mm256_sub_ps(ix3,jx3);
825 dy33 = _mm256_sub_ps(iy3,jy3);
826 dz33 = _mm256_sub_ps(iz3,jz3);
828 /* Calculate squared distance and things based on it */
829 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
830 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
831 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
832 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
833 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
834 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
835 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
836 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
837 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
838 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
840 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
841 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
842 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
843 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
844 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
845 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
846 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
847 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
848 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
849 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
851 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
852 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
853 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
854 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
855 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
856 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
857 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
858 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
859 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
860 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
862 fjx0 = _mm256_setzero_ps();
863 fjy0 = _mm256_setzero_ps();
864 fjz0 = _mm256_setzero_ps();
865 fjx1 = _mm256_setzero_ps();
866 fjy1 = _mm256_setzero_ps();
867 fjz1 = _mm256_setzero_ps();
868 fjx2 = _mm256_setzero_ps();
869 fjy2 = _mm256_setzero_ps();
870 fjz2 = _mm256_setzero_ps();
871 fjx3 = _mm256_setzero_ps();
872 fjy3 = _mm256_setzero_ps();
873 fjz3 = _mm256_setzero_ps();
875 /**************************
876 * CALCULATE INTERACTIONS *
877 **************************/
879 if (gmx_mm256_any_lt(rsq00,rcutoff2))
882 r00 = _mm256_mul_ps(rsq00,rinv00);
883 r00 = _mm256_andnot_ps(dummy_mask,r00);
885 /* LENNARD-JONES DISPERSION/REPULSION */
887 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
888 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
889 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
890 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
891 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
893 d = _mm256_sub_ps(r00,rswitch);
894 d = _mm256_max_ps(d,_mm256_setzero_ps());
895 d2 = _mm256_mul_ps(d,d);
896 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)))))));
898 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
900 /* Evaluate switch function */
901 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
902 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
903 vvdw = _mm256_mul_ps(vvdw,sw);
904 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
906 /* Update potential sum for this i atom from the interaction with this j atom. */
907 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
908 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
909 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
913 fscal = _mm256_and_ps(fscal,cutoff_mask);
915 fscal = _mm256_andnot_ps(dummy_mask,fscal);
917 /* Calculate temporary vectorial force */
918 tx = _mm256_mul_ps(fscal,dx00);
919 ty = _mm256_mul_ps(fscal,dy00);
920 tz = _mm256_mul_ps(fscal,dz00);
922 /* Update vectorial force */
923 fix0 = _mm256_add_ps(fix0,tx);
924 fiy0 = _mm256_add_ps(fiy0,ty);
925 fiz0 = _mm256_add_ps(fiz0,tz);
927 fjx0 = _mm256_add_ps(fjx0,tx);
928 fjy0 = _mm256_add_ps(fjy0,ty);
929 fjz0 = _mm256_add_ps(fjz0,tz);
933 /**************************
934 * CALCULATE INTERACTIONS *
935 **************************/
937 if (gmx_mm256_any_lt(rsq11,rcutoff2))
940 /* REACTION-FIELD ELECTROSTATICS */
941 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
942 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
944 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
946 /* Update potential sum for this i atom from the interaction with this j atom. */
947 velec = _mm256_and_ps(velec,cutoff_mask);
948 velec = _mm256_andnot_ps(dummy_mask,velec);
949 velecsum = _mm256_add_ps(velecsum,velec);
953 fscal = _mm256_and_ps(fscal,cutoff_mask);
955 fscal = _mm256_andnot_ps(dummy_mask,fscal);
957 /* Calculate temporary vectorial force */
958 tx = _mm256_mul_ps(fscal,dx11);
959 ty = _mm256_mul_ps(fscal,dy11);
960 tz = _mm256_mul_ps(fscal,dz11);
962 /* Update vectorial force */
963 fix1 = _mm256_add_ps(fix1,tx);
964 fiy1 = _mm256_add_ps(fiy1,ty);
965 fiz1 = _mm256_add_ps(fiz1,tz);
967 fjx1 = _mm256_add_ps(fjx1,tx);
968 fjy1 = _mm256_add_ps(fjy1,ty);
969 fjz1 = _mm256_add_ps(fjz1,tz);
973 /**************************
974 * CALCULATE INTERACTIONS *
975 **************************/
977 if (gmx_mm256_any_lt(rsq12,rcutoff2))
980 /* REACTION-FIELD ELECTROSTATICS */
981 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
982 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
984 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
986 /* Update potential sum for this i atom from the interaction with this j atom. */
987 velec = _mm256_and_ps(velec,cutoff_mask);
988 velec = _mm256_andnot_ps(dummy_mask,velec);
989 velecsum = _mm256_add_ps(velecsum,velec);
993 fscal = _mm256_and_ps(fscal,cutoff_mask);
995 fscal = _mm256_andnot_ps(dummy_mask,fscal);
997 /* Calculate temporary vectorial force */
998 tx = _mm256_mul_ps(fscal,dx12);
999 ty = _mm256_mul_ps(fscal,dy12);
1000 tz = _mm256_mul_ps(fscal,dz12);
1002 /* Update vectorial force */
1003 fix1 = _mm256_add_ps(fix1,tx);
1004 fiy1 = _mm256_add_ps(fiy1,ty);
1005 fiz1 = _mm256_add_ps(fiz1,tz);
1007 fjx2 = _mm256_add_ps(fjx2,tx);
1008 fjy2 = _mm256_add_ps(fjy2,ty);
1009 fjz2 = _mm256_add_ps(fjz2,tz);
1013 /**************************
1014 * CALCULATE INTERACTIONS *
1015 **************************/
1017 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1020 /* REACTION-FIELD ELECTROSTATICS */
1021 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
1022 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1024 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1026 /* Update potential sum for this i atom from the interaction with this j atom. */
1027 velec = _mm256_and_ps(velec,cutoff_mask);
1028 velec = _mm256_andnot_ps(dummy_mask,velec);
1029 velecsum = _mm256_add_ps(velecsum,velec);
1033 fscal = _mm256_and_ps(fscal,cutoff_mask);
1035 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1037 /* Calculate temporary vectorial force */
1038 tx = _mm256_mul_ps(fscal,dx13);
1039 ty = _mm256_mul_ps(fscal,dy13);
1040 tz = _mm256_mul_ps(fscal,dz13);
1042 /* Update vectorial force */
1043 fix1 = _mm256_add_ps(fix1,tx);
1044 fiy1 = _mm256_add_ps(fiy1,ty);
1045 fiz1 = _mm256_add_ps(fiz1,tz);
1047 fjx3 = _mm256_add_ps(fjx3,tx);
1048 fjy3 = _mm256_add_ps(fjy3,ty);
1049 fjz3 = _mm256_add_ps(fjz3,tz);
1053 /**************************
1054 * CALCULATE INTERACTIONS *
1055 **************************/
1057 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1060 /* REACTION-FIELD ELECTROSTATICS */
1061 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1062 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1064 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1066 /* Update potential sum for this i atom from the interaction with this j atom. */
1067 velec = _mm256_and_ps(velec,cutoff_mask);
1068 velec = _mm256_andnot_ps(dummy_mask,velec);
1069 velecsum = _mm256_add_ps(velecsum,velec);
1073 fscal = _mm256_and_ps(fscal,cutoff_mask);
1075 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1077 /* Calculate temporary vectorial force */
1078 tx = _mm256_mul_ps(fscal,dx21);
1079 ty = _mm256_mul_ps(fscal,dy21);
1080 tz = _mm256_mul_ps(fscal,dz21);
1082 /* Update vectorial force */
1083 fix2 = _mm256_add_ps(fix2,tx);
1084 fiy2 = _mm256_add_ps(fiy2,ty);
1085 fiz2 = _mm256_add_ps(fiz2,tz);
1087 fjx1 = _mm256_add_ps(fjx1,tx);
1088 fjy1 = _mm256_add_ps(fjy1,ty);
1089 fjz1 = _mm256_add_ps(fjz1,tz);
1093 /**************************
1094 * CALCULATE INTERACTIONS *
1095 **************************/
1097 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1100 /* REACTION-FIELD ELECTROSTATICS */
1101 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1102 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1104 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1106 /* Update potential sum for this i atom from the interaction with this j atom. */
1107 velec = _mm256_and_ps(velec,cutoff_mask);
1108 velec = _mm256_andnot_ps(dummy_mask,velec);
1109 velecsum = _mm256_add_ps(velecsum,velec);
1113 fscal = _mm256_and_ps(fscal,cutoff_mask);
1115 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1117 /* Calculate temporary vectorial force */
1118 tx = _mm256_mul_ps(fscal,dx22);
1119 ty = _mm256_mul_ps(fscal,dy22);
1120 tz = _mm256_mul_ps(fscal,dz22);
1122 /* Update vectorial force */
1123 fix2 = _mm256_add_ps(fix2,tx);
1124 fiy2 = _mm256_add_ps(fiy2,ty);
1125 fiz2 = _mm256_add_ps(fiz2,tz);
1127 fjx2 = _mm256_add_ps(fjx2,tx);
1128 fjy2 = _mm256_add_ps(fjy2,ty);
1129 fjz2 = _mm256_add_ps(fjz2,tz);
1133 /**************************
1134 * CALCULATE INTERACTIONS *
1135 **************************/
1137 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1140 /* REACTION-FIELD ELECTROSTATICS */
1141 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
1142 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1144 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1146 /* Update potential sum for this i atom from the interaction with this j atom. */
1147 velec = _mm256_and_ps(velec,cutoff_mask);
1148 velec = _mm256_andnot_ps(dummy_mask,velec);
1149 velecsum = _mm256_add_ps(velecsum,velec);
1153 fscal = _mm256_and_ps(fscal,cutoff_mask);
1155 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1157 /* Calculate temporary vectorial force */
1158 tx = _mm256_mul_ps(fscal,dx23);
1159 ty = _mm256_mul_ps(fscal,dy23);
1160 tz = _mm256_mul_ps(fscal,dz23);
1162 /* Update vectorial force */
1163 fix2 = _mm256_add_ps(fix2,tx);
1164 fiy2 = _mm256_add_ps(fiy2,ty);
1165 fiz2 = _mm256_add_ps(fiz2,tz);
1167 fjx3 = _mm256_add_ps(fjx3,tx);
1168 fjy3 = _mm256_add_ps(fjy3,ty);
1169 fjz3 = _mm256_add_ps(fjz3,tz);
1173 /**************************
1174 * CALCULATE INTERACTIONS *
1175 **************************/
1177 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1180 /* REACTION-FIELD ELECTROSTATICS */
1181 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
1182 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1184 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1186 /* Update potential sum for this i atom from the interaction with this j atom. */
1187 velec = _mm256_and_ps(velec,cutoff_mask);
1188 velec = _mm256_andnot_ps(dummy_mask,velec);
1189 velecsum = _mm256_add_ps(velecsum,velec);
1193 fscal = _mm256_and_ps(fscal,cutoff_mask);
1195 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1197 /* Calculate temporary vectorial force */
1198 tx = _mm256_mul_ps(fscal,dx31);
1199 ty = _mm256_mul_ps(fscal,dy31);
1200 tz = _mm256_mul_ps(fscal,dz31);
1202 /* Update vectorial force */
1203 fix3 = _mm256_add_ps(fix3,tx);
1204 fiy3 = _mm256_add_ps(fiy3,ty);
1205 fiz3 = _mm256_add_ps(fiz3,tz);
1207 fjx1 = _mm256_add_ps(fjx1,tx);
1208 fjy1 = _mm256_add_ps(fjy1,ty);
1209 fjz1 = _mm256_add_ps(fjz1,tz);
1213 /**************************
1214 * CALCULATE INTERACTIONS *
1215 **************************/
1217 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1220 /* REACTION-FIELD ELECTROSTATICS */
1221 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
1222 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1224 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1226 /* Update potential sum for this i atom from the interaction with this j atom. */
1227 velec = _mm256_and_ps(velec,cutoff_mask);
1228 velec = _mm256_andnot_ps(dummy_mask,velec);
1229 velecsum = _mm256_add_ps(velecsum,velec);
1233 fscal = _mm256_and_ps(fscal,cutoff_mask);
1235 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1237 /* Calculate temporary vectorial force */
1238 tx = _mm256_mul_ps(fscal,dx32);
1239 ty = _mm256_mul_ps(fscal,dy32);
1240 tz = _mm256_mul_ps(fscal,dz32);
1242 /* Update vectorial force */
1243 fix3 = _mm256_add_ps(fix3,tx);
1244 fiy3 = _mm256_add_ps(fiy3,ty);
1245 fiz3 = _mm256_add_ps(fiz3,tz);
1247 fjx2 = _mm256_add_ps(fjx2,tx);
1248 fjy2 = _mm256_add_ps(fjy2,ty);
1249 fjz2 = _mm256_add_ps(fjz2,tz);
1253 /**************************
1254 * CALCULATE INTERACTIONS *
1255 **************************/
1257 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1260 /* REACTION-FIELD ELECTROSTATICS */
1261 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
1262 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1264 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1266 /* Update potential sum for this i atom from the interaction with this j atom. */
1267 velec = _mm256_and_ps(velec,cutoff_mask);
1268 velec = _mm256_andnot_ps(dummy_mask,velec);
1269 velecsum = _mm256_add_ps(velecsum,velec);
1273 fscal = _mm256_and_ps(fscal,cutoff_mask);
1275 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1277 /* Calculate temporary vectorial force */
1278 tx = _mm256_mul_ps(fscal,dx33);
1279 ty = _mm256_mul_ps(fscal,dy33);
1280 tz = _mm256_mul_ps(fscal,dz33);
1282 /* Update vectorial force */
1283 fix3 = _mm256_add_ps(fix3,tx);
1284 fiy3 = _mm256_add_ps(fiy3,ty);
1285 fiz3 = _mm256_add_ps(fiz3,tz);
1287 fjx3 = _mm256_add_ps(fjx3,tx);
1288 fjy3 = _mm256_add_ps(fjy3,ty);
1289 fjz3 = _mm256_add_ps(fjz3,tz);
1293 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1294 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1295 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1296 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1297 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1298 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1299 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1300 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1302 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1303 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1304 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1306 /* Inner loop uses 387 flops */
1309 /* End of innermost loop */
1311 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1312 f+i_coord_offset,fshift+i_shift_offset);
1315 /* Update potential energies */
1316 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1317 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1319 /* Increment number of inner iterations */
1320 inneriter += j_index_end - j_index_start;
1322 /* Outer loop uses 26 flops */
1325 /* Increment number of outer iterations */
1328 /* Update outer/inner flops */
1330 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*387);
1333 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1334 * Electrostatics interaction: ReactionField
1335 * VdW interaction: LennardJones
1336 * Geometry: Water4-Water4
1337 * Calculate force/pot: Force
1340 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1341 (t_nblist * gmx_restrict nlist,
1342 rvec * gmx_restrict xx,
1343 rvec * gmx_restrict ff,
1344 t_forcerec * gmx_restrict fr,
1345 t_mdatoms * gmx_restrict mdatoms,
1346 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1347 t_nrnb * gmx_restrict nrnb)
1349 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1350 * just 0 for non-waters.
1351 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1352 * jnr indices corresponding to data put in the four positions in the SIMD register.
1354 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1355 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1356 int jnrA,jnrB,jnrC,jnrD;
1357 int jnrE,jnrF,jnrG,jnrH;
1358 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1359 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1360 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1361 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1362 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1363 real rcutoff_scalar;
1364 real *shiftvec,*fshift,*x,*f;
1365 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1366 real scratch[4*DIM];
1367 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1368 real * vdwioffsetptr0;
1369 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1370 real * vdwioffsetptr1;
1371 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1372 real * vdwioffsetptr2;
1373 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1374 real * vdwioffsetptr3;
1375 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1376 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1377 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1378 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1379 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1380 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1381 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1382 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
1383 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1384 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1385 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1386 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1387 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1388 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1389 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1390 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1391 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1392 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1393 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1394 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1397 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1400 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1401 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1402 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
1403 real rswitch_scalar,d_scalar;
1404 __m256 dummy_mask,cutoff_mask;
1405 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1406 __m256 one = _mm256_set1_ps(1.0);
1407 __m256 two = _mm256_set1_ps(2.0);
1413 jindex = nlist->jindex;
1415 shiftidx = nlist->shift;
1417 shiftvec = fr->shift_vec[0];
1418 fshift = fr->fshift[0];
1419 facel = _mm256_set1_ps(fr->epsfac);
1420 charge = mdatoms->chargeA;
1421 krf = _mm256_set1_ps(fr->ic->k_rf);
1422 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1423 crf = _mm256_set1_ps(fr->ic->c_rf);
1424 nvdwtype = fr->ntype;
1425 vdwparam = fr->nbfp;
1426 vdwtype = mdatoms->typeA;
1428 /* Setup water-specific parameters */
1429 inr = nlist->iinr[0];
1430 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1431 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1432 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
1433 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1435 jq1 = _mm256_set1_ps(charge[inr+1]);
1436 jq2 = _mm256_set1_ps(charge[inr+2]);
1437 jq3 = _mm256_set1_ps(charge[inr+3]);
1438 vdwjidx0A = 2*vdwtype[inr+0];
1439 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1440 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1441 qq11 = _mm256_mul_ps(iq1,jq1);
1442 qq12 = _mm256_mul_ps(iq1,jq2);
1443 qq13 = _mm256_mul_ps(iq1,jq3);
1444 qq21 = _mm256_mul_ps(iq2,jq1);
1445 qq22 = _mm256_mul_ps(iq2,jq2);
1446 qq23 = _mm256_mul_ps(iq2,jq3);
1447 qq31 = _mm256_mul_ps(iq3,jq1);
1448 qq32 = _mm256_mul_ps(iq3,jq2);
1449 qq33 = _mm256_mul_ps(iq3,jq3);
1451 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1452 rcutoff_scalar = fr->rcoulomb;
1453 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1454 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1456 rswitch_scalar = fr->rvdw_switch;
1457 rswitch = _mm256_set1_ps(rswitch_scalar);
1458 /* Setup switch parameters */
1459 d_scalar = rcutoff_scalar-rswitch_scalar;
1460 d = _mm256_set1_ps(d_scalar);
1461 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
1462 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1463 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1464 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
1465 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1466 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1468 /* Avoid stupid compiler warnings */
1469 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1470 j_coord_offsetA = 0;
1471 j_coord_offsetB = 0;
1472 j_coord_offsetC = 0;
1473 j_coord_offsetD = 0;
1474 j_coord_offsetE = 0;
1475 j_coord_offsetF = 0;
1476 j_coord_offsetG = 0;
1477 j_coord_offsetH = 0;
1482 for(iidx=0;iidx<4*DIM;iidx++)
1484 scratch[iidx] = 0.0;
1487 /* Start outer loop over neighborlists */
1488 for(iidx=0; iidx<nri; iidx++)
1490 /* Load shift vector for this list */
1491 i_shift_offset = DIM*shiftidx[iidx];
1493 /* Load limits for loop over neighbors */
1494 j_index_start = jindex[iidx];
1495 j_index_end = jindex[iidx+1];
1497 /* Get outer coordinate index */
1499 i_coord_offset = DIM*inr;
1501 /* Load i particle coords and add shift vector */
1502 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1503 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1505 fix0 = _mm256_setzero_ps();
1506 fiy0 = _mm256_setzero_ps();
1507 fiz0 = _mm256_setzero_ps();
1508 fix1 = _mm256_setzero_ps();
1509 fiy1 = _mm256_setzero_ps();
1510 fiz1 = _mm256_setzero_ps();
1511 fix2 = _mm256_setzero_ps();
1512 fiy2 = _mm256_setzero_ps();
1513 fiz2 = _mm256_setzero_ps();
1514 fix3 = _mm256_setzero_ps();
1515 fiy3 = _mm256_setzero_ps();
1516 fiz3 = _mm256_setzero_ps();
1518 /* Start inner kernel loop */
1519 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1522 /* Get j neighbor index, and coordinate index */
1524 jnrB = jjnr[jidx+1];
1525 jnrC = jjnr[jidx+2];
1526 jnrD = jjnr[jidx+3];
1527 jnrE = jjnr[jidx+4];
1528 jnrF = jjnr[jidx+5];
1529 jnrG = jjnr[jidx+6];
1530 jnrH = jjnr[jidx+7];
1531 j_coord_offsetA = DIM*jnrA;
1532 j_coord_offsetB = DIM*jnrB;
1533 j_coord_offsetC = DIM*jnrC;
1534 j_coord_offsetD = DIM*jnrD;
1535 j_coord_offsetE = DIM*jnrE;
1536 j_coord_offsetF = DIM*jnrF;
1537 j_coord_offsetG = DIM*jnrG;
1538 j_coord_offsetH = DIM*jnrH;
1540 /* load j atom coordinates */
1541 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1542 x+j_coord_offsetC,x+j_coord_offsetD,
1543 x+j_coord_offsetE,x+j_coord_offsetF,
1544 x+j_coord_offsetG,x+j_coord_offsetH,
1545 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1546 &jy2,&jz2,&jx3,&jy3,&jz3);
1548 /* Calculate displacement vector */
1549 dx00 = _mm256_sub_ps(ix0,jx0);
1550 dy00 = _mm256_sub_ps(iy0,jy0);
1551 dz00 = _mm256_sub_ps(iz0,jz0);
1552 dx11 = _mm256_sub_ps(ix1,jx1);
1553 dy11 = _mm256_sub_ps(iy1,jy1);
1554 dz11 = _mm256_sub_ps(iz1,jz1);
1555 dx12 = _mm256_sub_ps(ix1,jx2);
1556 dy12 = _mm256_sub_ps(iy1,jy2);
1557 dz12 = _mm256_sub_ps(iz1,jz2);
1558 dx13 = _mm256_sub_ps(ix1,jx3);
1559 dy13 = _mm256_sub_ps(iy1,jy3);
1560 dz13 = _mm256_sub_ps(iz1,jz3);
1561 dx21 = _mm256_sub_ps(ix2,jx1);
1562 dy21 = _mm256_sub_ps(iy2,jy1);
1563 dz21 = _mm256_sub_ps(iz2,jz1);
1564 dx22 = _mm256_sub_ps(ix2,jx2);
1565 dy22 = _mm256_sub_ps(iy2,jy2);
1566 dz22 = _mm256_sub_ps(iz2,jz2);
1567 dx23 = _mm256_sub_ps(ix2,jx3);
1568 dy23 = _mm256_sub_ps(iy2,jy3);
1569 dz23 = _mm256_sub_ps(iz2,jz3);
1570 dx31 = _mm256_sub_ps(ix3,jx1);
1571 dy31 = _mm256_sub_ps(iy3,jy1);
1572 dz31 = _mm256_sub_ps(iz3,jz1);
1573 dx32 = _mm256_sub_ps(ix3,jx2);
1574 dy32 = _mm256_sub_ps(iy3,jy2);
1575 dz32 = _mm256_sub_ps(iz3,jz2);
1576 dx33 = _mm256_sub_ps(ix3,jx3);
1577 dy33 = _mm256_sub_ps(iy3,jy3);
1578 dz33 = _mm256_sub_ps(iz3,jz3);
1580 /* Calculate squared distance and things based on it */
1581 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1582 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1583 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1584 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
1585 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1586 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1587 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
1588 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
1589 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
1590 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
1592 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1593 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1594 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1595 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
1596 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1597 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1598 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
1599 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
1600 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
1601 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
1603 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1604 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1605 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1606 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
1607 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1608 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1609 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
1610 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
1611 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
1612 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
1614 fjx0 = _mm256_setzero_ps();
1615 fjy0 = _mm256_setzero_ps();
1616 fjz0 = _mm256_setzero_ps();
1617 fjx1 = _mm256_setzero_ps();
1618 fjy1 = _mm256_setzero_ps();
1619 fjz1 = _mm256_setzero_ps();
1620 fjx2 = _mm256_setzero_ps();
1621 fjy2 = _mm256_setzero_ps();
1622 fjz2 = _mm256_setzero_ps();
1623 fjx3 = _mm256_setzero_ps();
1624 fjy3 = _mm256_setzero_ps();
1625 fjz3 = _mm256_setzero_ps();
1627 /**************************
1628 * CALCULATE INTERACTIONS *
1629 **************************/
1631 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1634 r00 = _mm256_mul_ps(rsq00,rinv00);
1636 /* LENNARD-JONES DISPERSION/REPULSION */
1638 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1639 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
1640 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
1641 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
1642 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
1644 d = _mm256_sub_ps(r00,rswitch);
1645 d = _mm256_max_ps(d,_mm256_setzero_ps());
1646 d2 = _mm256_mul_ps(d,d);
1647 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)))))));
1649 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
1651 /* Evaluate switch function */
1652 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1653 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
1654 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1658 fscal = _mm256_and_ps(fscal,cutoff_mask);
1660 /* Calculate temporary vectorial force */
1661 tx = _mm256_mul_ps(fscal,dx00);
1662 ty = _mm256_mul_ps(fscal,dy00);
1663 tz = _mm256_mul_ps(fscal,dz00);
1665 /* Update vectorial force */
1666 fix0 = _mm256_add_ps(fix0,tx);
1667 fiy0 = _mm256_add_ps(fiy0,ty);
1668 fiz0 = _mm256_add_ps(fiz0,tz);
1670 fjx0 = _mm256_add_ps(fjx0,tx);
1671 fjy0 = _mm256_add_ps(fjy0,ty);
1672 fjz0 = _mm256_add_ps(fjz0,tz);
1676 /**************************
1677 * CALCULATE INTERACTIONS *
1678 **************************/
1680 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1683 /* REACTION-FIELD ELECTROSTATICS */
1684 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1686 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1690 fscal = _mm256_and_ps(fscal,cutoff_mask);
1692 /* Calculate temporary vectorial force */
1693 tx = _mm256_mul_ps(fscal,dx11);
1694 ty = _mm256_mul_ps(fscal,dy11);
1695 tz = _mm256_mul_ps(fscal,dz11);
1697 /* Update vectorial force */
1698 fix1 = _mm256_add_ps(fix1,tx);
1699 fiy1 = _mm256_add_ps(fiy1,ty);
1700 fiz1 = _mm256_add_ps(fiz1,tz);
1702 fjx1 = _mm256_add_ps(fjx1,tx);
1703 fjy1 = _mm256_add_ps(fjy1,ty);
1704 fjz1 = _mm256_add_ps(fjz1,tz);
1708 /**************************
1709 * CALCULATE INTERACTIONS *
1710 **************************/
1712 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1715 /* REACTION-FIELD ELECTROSTATICS */
1716 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1718 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1722 fscal = _mm256_and_ps(fscal,cutoff_mask);
1724 /* Calculate temporary vectorial force */
1725 tx = _mm256_mul_ps(fscal,dx12);
1726 ty = _mm256_mul_ps(fscal,dy12);
1727 tz = _mm256_mul_ps(fscal,dz12);
1729 /* Update vectorial force */
1730 fix1 = _mm256_add_ps(fix1,tx);
1731 fiy1 = _mm256_add_ps(fiy1,ty);
1732 fiz1 = _mm256_add_ps(fiz1,tz);
1734 fjx2 = _mm256_add_ps(fjx2,tx);
1735 fjy2 = _mm256_add_ps(fjy2,ty);
1736 fjz2 = _mm256_add_ps(fjz2,tz);
1740 /**************************
1741 * CALCULATE INTERACTIONS *
1742 **************************/
1744 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1747 /* REACTION-FIELD ELECTROSTATICS */
1748 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1750 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1754 fscal = _mm256_and_ps(fscal,cutoff_mask);
1756 /* Calculate temporary vectorial force */
1757 tx = _mm256_mul_ps(fscal,dx13);
1758 ty = _mm256_mul_ps(fscal,dy13);
1759 tz = _mm256_mul_ps(fscal,dz13);
1761 /* Update vectorial force */
1762 fix1 = _mm256_add_ps(fix1,tx);
1763 fiy1 = _mm256_add_ps(fiy1,ty);
1764 fiz1 = _mm256_add_ps(fiz1,tz);
1766 fjx3 = _mm256_add_ps(fjx3,tx);
1767 fjy3 = _mm256_add_ps(fjy3,ty);
1768 fjz3 = _mm256_add_ps(fjz3,tz);
1772 /**************************
1773 * CALCULATE INTERACTIONS *
1774 **************************/
1776 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1779 /* REACTION-FIELD ELECTROSTATICS */
1780 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1782 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1786 fscal = _mm256_and_ps(fscal,cutoff_mask);
1788 /* Calculate temporary vectorial force */
1789 tx = _mm256_mul_ps(fscal,dx21);
1790 ty = _mm256_mul_ps(fscal,dy21);
1791 tz = _mm256_mul_ps(fscal,dz21);
1793 /* Update vectorial force */
1794 fix2 = _mm256_add_ps(fix2,tx);
1795 fiy2 = _mm256_add_ps(fiy2,ty);
1796 fiz2 = _mm256_add_ps(fiz2,tz);
1798 fjx1 = _mm256_add_ps(fjx1,tx);
1799 fjy1 = _mm256_add_ps(fjy1,ty);
1800 fjz1 = _mm256_add_ps(fjz1,tz);
1804 /**************************
1805 * CALCULATE INTERACTIONS *
1806 **************************/
1808 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1811 /* REACTION-FIELD ELECTROSTATICS */
1812 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1814 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1818 fscal = _mm256_and_ps(fscal,cutoff_mask);
1820 /* Calculate temporary vectorial force */
1821 tx = _mm256_mul_ps(fscal,dx22);
1822 ty = _mm256_mul_ps(fscal,dy22);
1823 tz = _mm256_mul_ps(fscal,dz22);
1825 /* Update vectorial force */
1826 fix2 = _mm256_add_ps(fix2,tx);
1827 fiy2 = _mm256_add_ps(fiy2,ty);
1828 fiz2 = _mm256_add_ps(fiz2,tz);
1830 fjx2 = _mm256_add_ps(fjx2,tx);
1831 fjy2 = _mm256_add_ps(fjy2,ty);
1832 fjz2 = _mm256_add_ps(fjz2,tz);
1836 /**************************
1837 * CALCULATE INTERACTIONS *
1838 **************************/
1840 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1843 /* REACTION-FIELD ELECTROSTATICS */
1844 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1846 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1850 fscal = _mm256_and_ps(fscal,cutoff_mask);
1852 /* Calculate temporary vectorial force */
1853 tx = _mm256_mul_ps(fscal,dx23);
1854 ty = _mm256_mul_ps(fscal,dy23);
1855 tz = _mm256_mul_ps(fscal,dz23);
1857 /* Update vectorial force */
1858 fix2 = _mm256_add_ps(fix2,tx);
1859 fiy2 = _mm256_add_ps(fiy2,ty);
1860 fiz2 = _mm256_add_ps(fiz2,tz);
1862 fjx3 = _mm256_add_ps(fjx3,tx);
1863 fjy3 = _mm256_add_ps(fjy3,ty);
1864 fjz3 = _mm256_add_ps(fjz3,tz);
1868 /**************************
1869 * CALCULATE INTERACTIONS *
1870 **************************/
1872 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1875 /* REACTION-FIELD ELECTROSTATICS */
1876 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1878 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1882 fscal = _mm256_and_ps(fscal,cutoff_mask);
1884 /* Calculate temporary vectorial force */
1885 tx = _mm256_mul_ps(fscal,dx31);
1886 ty = _mm256_mul_ps(fscal,dy31);
1887 tz = _mm256_mul_ps(fscal,dz31);
1889 /* Update vectorial force */
1890 fix3 = _mm256_add_ps(fix3,tx);
1891 fiy3 = _mm256_add_ps(fiy3,ty);
1892 fiz3 = _mm256_add_ps(fiz3,tz);
1894 fjx1 = _mm256_add_ps(fjx1,tx);
1895 fjy1 = _mm256_add_ps(fjy1,ty);
1896 fjz1 = _mm256_add_ps(fjz1,tz);
1900 /**************************
1901 * CALCULATE INTERACTIONS *
1902 **************************/
1904 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1907 /* REACTION-FIELD ELECTROSTATICS */
1908 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1910 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1914 fscal = _mm256_and_ps(fscal,cutoff_mask);
1916 /* Calculate temporary vectorial force */
1917 tx = _mm256_mul_ps(fscal,dx32);
1918 ty = _mm256_mul_ps(fscal,dy32);
1919 tz = _mm256_mul_ps(fscal,dz32);
1921 /* Update vectorial force */
1922 fix3 = _mm256_add_ps(fix3,tx);
1923 fiy3 = _mm256_add_ps(fiy3,ty);
1924 fiz3 = _mm256_add_ps(fiz3,tz);
1926 fjx2 = _mm256_add_ps(fjx2,tx);
1927 fjy2 = _mm256_add_ps(fjy2,ty);
1928 fjz2 = _mm256_add_ps(fjz2,tz);
1932 /**************************
1933 * CALCULATE INTERACTIONS *
1934 **************************/
1936 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1939 /* REACTION-FIELD ELECTROSTATICS */
1940 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1942 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1946 fscal = _mm256_and_ps(fscal,cutoff_mask);
1948 /* Calculate temporary vectorial force */
1949 tx = _mm256_mul_ps(fscal,dx33);
1950 ty = _mm256_mul_ps(fscal,dy33);
1951 tz = _mm256_mul_ps(fscal,dz33);
1953 /* Update vectorial force */
1954 fix3 = _mm256_add_ps(fix3,tx);
1955 fiy3 = _mm256_add_ps(fiy3,ty);
1956 fiz3 = _mm256_add_ps(fiz3,tz);
1958 fjx3 = _mm256_add_ps(fjx3,tx);
1959 fjy3 = _mm256_add_ps(fjy3,ty);
1960 fjz3 = _mm256_add_ps(fjz3,tz);
1964 fjptrA = f+j_coord_offsetA;
1965 fjptrB = f+j_coord_offsetB;
1966 fjptrC = f+j_coord_offsetC;
1967 fjptrD = f+j_coord_offsetD;
1968 fjptrE = f+j_coord_offsetE;
1969 fjptrF = f+j_coord_offsetF;
1970 fjptrG = f+j_coord_offsetG;
1971 fjptrH = f+j_coord_offsetH;
1973 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1974 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1975 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1977 /* Inner loop uses 329 flops */
1980 if(jidx<j_index_end)
1983 /* Get j neighbor index, and coordinate index */
1984 jnrlistA = jjnr[jidx];
1985 jnrlistB = jjnr[jidx+1];
1986 jnrlistC = jjnr[jidx+2];
1987 jnrlistD = jjnr[jidx+3];
1988 jnrlistE = jjnr[jidx+4];
1989 jnrlistF = jjnr[jidx+5];
1990 jnrlistG = jjnr[jidx+6];
1991 jnrlistH = jjnr[jidx+7];
1992 /* Sign of each element will be negative for non-real atoms.
1993 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1994 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1996 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1997 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1999 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
2000 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
2001 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
2002 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
2003 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
2004 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
2005 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
2006 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
2007 j_coord_offsetA = DIM*jnrA;
2008 j_coord_offsetB = DIM*jnrB;
2009 j_coord_offsetC = DIM*jnrC;
2010 j_coord_offsetD = DIM*jnrD;
2011 j_coord_offsetE = DIM*jnrE;
2012 j_coord_offsetF = DIM*jnrF;
2013 j_coord_offsetG = DIM*jnrG;
2014 j_coord_offsetH = DIM*jnrH;
2016 /* load j atom coordinates */
2017 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
2018 x+j_coord_offsetC,x+j_coord_offsetD,
2019 x+j_coord_offsetE,x+j_coord_offsetF,
2020 x+j_coord_offsetG,x+j_coord_offsetH,
2021 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
2022 &jy2,&jz2,&jx3,&jy3,&jz3);
2024 /* Calculate displacement vector */
2025 dx00 = _mm256_sub_ps(ix0,jx0);
2026 dy00 = _mm256_sub_ps(iy0,jy0);
2027 dz00 = _mm256_sub_ps(iz0,jz0);
2028 dx11 = _mm256_sub_ps(ix1,jx1);
2029 dy11 = _mm256_sub_ps(iy1,jy1);
2030 dz11 = _mm256_sub_ps(iz1,jz1);
2031 dx12 = _mm256_sub_ps(ix1,jx2);
2032 dy12 = _mm256_sub_ps(iy1,jy2);
2033 dz12 = _mm256_sub_ps(iz1,jz2);
2034 dx13 = _mm256_sub_ps(ix1,jx3);
2035 dy13 = _mm256_sub_ps(iy1,jy3);
2036 dz13 = _mm256_sub_ps(iz1,jz3);
2037 dx21 = _mm256_sub_ps(ix2,jx1);
2038 dy21 = _mm256_sub_ps(iy2,jy1);
2039 dz21 = _mm256_sub_ps(iz2,jz1);
2040 dx22 = _mm256_sub_ps(ix2,jx2);
2041 dy22 = _mm256_sub_ps(iy2,jy2);
2042 dz22 = _mm256_sub_ps(iz2,jz2);
2043 dx23 = _mm256_sub_ps(ix2,jx3);
2044 dy23 = _mm256_sub_ps(iy2,jy3);
2045 dz23 = _mm256_sub_ps(iz2,jz3);
2046 dx31 = _mm256_sub_ps(ix3,jx1);
2047 dy31 = _mm256_sub_ps(iy3,jy1);
2048 dz31 = _mm256_sub_ps(iz3,jz1);
2049 dx32 = _mm256_sub_ps(ix3,jx2);
2050 dy32 = _mm256_sub_ps(iy3,jy2);
2051 dz32 = _mm256_sub_ps(iz3,jz2);
2052 dx33 = _mm256_sub_ps(ix3,jx3);
2053 dy33 = _mm256_sub_ps(iy3,jy3);
2054 dz33 = _mm256_sub_ps(iz3,jz3);
2056 /* Calculate squared distance and things based on it */
2057 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
2058 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
2059 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
2060 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
2061 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
2062 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
2063 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
2064 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
2065 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
2066 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
2068 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
2069 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
2070 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
2071 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
2072 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
2073 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
2074 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
2075 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
2076 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
2077 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
2079 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
2080 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
2081 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
2082 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
2083 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
2084 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
2085 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
2086 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
2087 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
2088 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
2090 fjx0 = _mm256_setzero_ps();
2091 fjy0 = _mm256_setzero_ps();
2092 fjz0 = _mm256_setzero_ps();
2093 fjx1 = _mm256_setzero_ps();
2094 fjy1 = _mm256_setzero_ps();
2095 fjz1 = _mm256_setzero_ps();
2096 fjx2 = _mm256_setzero_ps();
2097 fjy2 = _mm256_setzero_ps();
2098 fjz2 = _mm256_setzero_ps();
2099 fjx3 = _mm256_setzero_ps();
2100 fjy3 = _mm256_setzero_ps();
2101 fjz3 = _mm256_setzero_ps();
2103 /**************************
2104 * CALCULATE INTERACTIONS *
2105 **************************/
2107 if (gmx_mm256_any_lt(rsq00,rcutoff2))
2110 r00 = _mm256_mul_ps(rsq00,rinv00);
2111 r00 = _mm256_andnot_ps(dummy_mask,r00);
2113 /* LENNARD-JONES DISPERSION/REPULSION */
2115 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
2116 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
2117 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
2118 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
2119 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
2121 d = _mm256_sub_ps(r00,rswitch);
2122 d = _mm256_max_ps(d,_mm256_setzero_ps());
2123 d2 = _mm256_mul_ps(d,d);
2124 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)))))));
2126 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
2128 /* Evaluate switch function */
2129 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
2130 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
2131 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2135 fscal = _mm256_and_ps(fscal,cutoff_mask);
2137 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2139 /* Calculate temporary vectorial force */
2140 tx = _mm256_mul_ps(fscal,dx00);
2141 ty = _mm256_mul_ps(fscal,dy00);
2142 tz = _mm256_mul_ps(fscal,dz00);
2144 /* Update vectorial force */
2145 fix0 = _mm256_add_ps(fix0,tx);
2146 fiy0 = _mm256_add_ps(fiy0,ty);
2147 fiz0 = _mm256_add_ps(fiz0,tz);
2149 fjx0 = _mm256_add_ps(fjx0,tx);
2150 fjy0 = _mm256_add_ps(fjy0,ty);
2151 fjz0 = _mm256_add_ps(fjz0,tz);
2155 /**************************
2156 * CALCULATE INTERACTIONS *
2157 **************************/
2159 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2162 /* REACTION-FIELD ELECTROSTATICS */
2163 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2165 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2169 fscal = _mm256_and_ps(fscal,cutoff_mask);
2171 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2173 /* Calculate temporary vectorial force */
2174 tx = _mm256_mul_ps(fscal,dx11);
2175 ty = _mm256_mul_ps(fscal,dy11);
2176 tz = _mm256_mul_ps(fscal,dz11);
2178 /* Update vectorial force */
2179 fix1 = _mm256_add_ps(fix1,tx);
2180 fiy1 = _mm256_add_ps(fiy1,ty);
2181 fiz1 = _mm256_add_ps(fiz1,tz);
2183 fjx1 = _mm256_add_ps(fjx1,tx);
2184 fjy1 = _mm256_add_ps(fjy1,ty);
2185 fjz1 = _mm256_add_ps(fjz1,tz);
2189 /**************************
2190 * CALCULATE INTERACTIONS *
2191 **************************/
2193 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2196 /* REACTION-FIELD ELECTROSTATICS */
2197 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2199 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2203 fscal = _mm256_and_ps(fscal,cutoff_mask);
2205 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2207 /* Calculate temporary vectorial force */
2208 tx = _mm256_mul_ps(fscal,dx12);
2209 ty = _mm256_mul_ps(fscal,dy12);
2210 tz = _mm256_mul_ps(fscal,dz12);
2212 /* Update vectorial force */
2213 fix1 = _mm256_add_ps(fix1,tx);
2214 fiy1 = _mm256_add_ps(fiy1,ty);
2215 fiz1 = _mm256_add_ps(fiz1,tz);
2217 fjx2 = _mm256_add_ps(fjx2,tx);
2218 fjy2 = _mm256_add_ps(fjy2,ty);
2219 fjz2 = _mm256_add_ps(fjz2,tz);
2223 /**************************
2224 * CALCULATE INTERACTIONS *
2225 **************************/
2227 if (gmx_mm256_any_lt(rsq13,rcutoff2))
2230 /* REACTION-FIELD ELECTROSTATICS */
2231 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
2233 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
2237 fscal = _mm256_and_ps(fscal,cutoff_mask);
2239 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2241 /* Calculate temporary vectorial force */
2242 tx = _mm256_mul_ps(fscal,dx13);
2243 ty = _mm256_mul_ps(fscal,dy13);
2244 tz = _mm256_mul_ps(fscal,dz13);
2246 /* Update vectorial force */
2247 fix1 = _mm256_add_ps(fix1,tx);
2248 fiy1 = _mm256_add_ps(fiy1,ty);
2249 fiz1 = _mm256_add_ps(fiz1,tz);
2251 fjx3 = _mm256_add_ps(fjx3,tx);
2252 fjy3 = _mm256_add_ps(fjy3,ty);
2253 fjz3 = _mm256_add_ps(fjz3,tz);
2257 /**************************
2258 * CALCULATE INTERACTIONS *
2259 **************************/
2261 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2264 /* REACTION-FIELD ELECTROSTATICS */
2265 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2267 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2271 fscal = _mm256_and_ps(fscal,cutoff_mask);
2273 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2275 /* Calculate temporary vectorial force */
2276 tx = _mm256_mul_ps(fscal,dx21);
2277 ty = _mm256_mul_ps(fscal,dy21);
2278 tz = _mm256_mul_ps(fscal,dz21);
2280 /* Update vectorial force */
2281 fix2 = _mm256_add_ps(fix2,tx);
2282 fiy2 = _mm256_add_ps(fiy2,ty);
2283 fiz2 = _mm256_add_ps(fiz2,tz);
2285 fjx1 = _mm256_add_ps(fjx1,tx);
2286 fjy1 = _mm256_add_ps(fjy1,ty);
2287 fjz1 = _mm256_add_ps(fjz1,tz);
2291 /**************************
2292 * CALCULATE INTERACTIONS *
2293 **************************/
2295 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2298 /* REACTION-FIELD ELECTROSTATICS */
2299 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2301 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2305 fscal = _mm256_and_ps(fscal,cutoff_mask);
2307 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2309 /* Calculate temporary vectorial force */
2310 tx = _mm256_mul_ps(fscal,dx22);
2311 ty = _mm256_mul_ps(fscal,dy22);
2312 tz = _mm256_mul_ps(fscal,dz22);
2314 /* Update vectorial force */
2315 fix2 = _mm256_add_ps(fix2,tx);
2316 fiy2 = _mm256_add_ps(fiy2,ty);
2317 fiz2 = _mm256_add_ps(fiz2,tz);
2319 fjx2 = _mm256_add_ps(fjx2,tx);
2320 fjy2 = _mm256_add_ps(fjy2,ty);
2321 fjz2 = _mm256_add_ps(fjz2,tz);
2325 /**************************
2326 * CALCULATE INTERACTIONS *
2327 **************************/
2329 if (gmx_mm256_any_lt(rsq23,rcutoff2))
2332 /* REACTION-FIELD ELECTROSTATICS */
2333 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
2335 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
2339 fscal = _mm256_and_ps(fscal,cutoff_mask);
2341 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2343 /* Calculate temporary vectorial force */
2344 tx = _mm256_mul_ps(fscal,dx23);
2345 ty = _mm256_mul_ps(fscal,dy23);
2346 tz = _mm256_mul_ps(fscal,dz23);
2348 /* Update vectorial force */
2349 fix2 = _mm256_add_ps(fix2,tx);
2350 fiy2 = _mm256_add_ps(fiy2,ty);
2351 fiz2 = _mm256_add_ps(fiz2,tz);
2353 fjx3 = _mm256_add_ps(fjx3,tx);
2354 fjy3 = _mm256_add_ps(fjy3,ty);
2355 fjz3 = _mm256_add_ps(fjz3,tz);
2359 /**************************
2360 * CALCULATE INTERACTIONS *
2361 **************************/
2363 if (gmx_mm256_any_lt(rsq31,rcutoff2))
2366 /* REACTION-FIELD ELECTROSTATICS */
2367 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
2369 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
2373 fscal = _mm256_and_ps(fscal,cutoff_mask);
2375 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2377 /* Calculate temporary vectorial force */
2378 tx = _mm256_mul_ps(fscal,dx31);
2379 ty = _mm256_mul_ps(fscal,dy31);
2380 tz = _mm256_mul_ps(fscal,dz31);
2382 /* Update vectorial force */
2383 fix3 = _mm256_add_ps(fix3,tx);
2384 fiy3 = _mm256_add_ps(fiy3,ty);
2385 fiz3 = _mm256_add_ps(fiz3,tz);
2387 fjx1 = _mm256_add_ps(fjx1,tx);
2388 fjy1 = _mm256_add_ps(fjy1,ty);
2389 fjz1 = _mm256_add_ps(fjz1,tz);
2393 /**************************
2394 * CALCULATE INTERACTIONS *
2395 **************************/
2397 if (gmx_mm256_any_lt(rsq32,rcutoff2))
2400 /* REACTION-FIELD ELECTROSTATICS */
2401 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
2403 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
2407 fscal = _mm256_and_ps(fscal,cutoff_mask);
2409 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2411 /* Calculate temporary vectorial force */
2412 tx = _mm256_mul_ps(fscal,dx32);
2413 ty = _mm256_mul_ps(fscal,dy32);
2414 tz = _mm256_mul_ps(fscal,dz32);
2416 /* Update vectorial force */
2417 fix3 = _mm256_add_ps(fix3,tx);
2418 fiy3 = _mm256_add_ps(fiy3,ty);
2419 fiz3 = _mm256_add_ps(fiz3,tz);
2421 fjx2 = _mm256_add_ps(fjx2,tx);
2422 fjy2 = _mm256_add_ps(fjy2,ty);
2423 fjz2 = _mm256_add_ps(fjz2,tz);
2427 /**************************
2428 * CALCULATE INTERACTIONS *
2429 **************************/
2431 if (gmx_mm256_any_lt(rsq33,rcutoff2))
2434 /* REACTION-FIELD ELECTROSTATICS */
2435 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
2437 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
2441 fscal = _mm256_and_ps(fscal,cutoff_mask);
2443 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2445 /* Calculate temporary vectorial force */
2446 tx = _mm256_mul_ps(fscal,dx33);
2447 ty = _mm256_mul_ps(fscal,dy33);
2448 tz = _mm256_mul_ps(fscal,dz33);
2450 /* Update vectorial force */
2451 fix3 = _mm256_add_ps(fix3,tx);
2452 fiy3 = _mm256_add_ps(fiy3,ty);
2453 fiz3 = _mm256_add_ps(fiz3,tz);
2455 fjx3 = _mm256_add_ps(fjx3,tx);
2456 fjy3 = _mm256_add_ps(fjy3,ty);
2457 fjz3 = _mm256_add_ps(fjz3,tz);
2461 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2462 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2463 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2464 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2465 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2466 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2467 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2468 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2470 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2471 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2472 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2474 /* Inner loop uses 330 flops */
2477 /* End of innermost loop */
2479 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2480 f+i_coord_offset,fshift+i_shift_offset);
2482 /* Increment number of inner iterations */
2483 inneriter += j_index_end - j_index_start;
2485 /* Outer loop uses 24 flops */
2488 /* Increment number of outer iterations */
2491 /* Update outer/inner flops */
2493 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*330);