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.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water4-Water4
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_VF_avx_256_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrE,jnrF,jnrG,jnrH;
78 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
79 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
80 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
81 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
82 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
84 real *shiftvec,*fshift,*x,*f;
85 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
87 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
88 real * vdwioffsetptr0;
89 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
90 real * vdwioffsetptr1;
91 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
92 real * vdwioffsetptr2;
93 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
94 real * vdwioffsetptr3;
95 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
96 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
97 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
98 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
99 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
100 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
101 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
102 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
103 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
104 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
105 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
106 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
107 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
108 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
109 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
110 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
111 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
112 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
113 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
114 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
117 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
120 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
121 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
122 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
123 real rswitch_scalar,d_scalar;
124 __m256 dummy_mask,cutoff_mask;
125 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
126 __m256 one = _mm256_set1_ps(1.0);
127 __m256 two = _mm256_set1_ps(2.0);
133 jindex = nlist->jindex;
135 shiftidx = nlist->shift;
137 shiftvec = fr->shift_vec[0];
138 fshift = fr->fshift[0];
139 facel = _mm256_set1_ps(fr->epsfac);
140 charge = mdatoms->chargeA;
141 krf = _mm256_set1_ps(fr->ic->k_rf);
142 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
143 crf = _mm256_set1_ps(fr->ic->c_rf);
144 nvdwtype = fr->ntype;
146 vdwtype = mdatoms->typeA;
148 /* Setup water-specific parameters */
149 inr = nlist->iinr[0];
150 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
151 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
152 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
153 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
155 jq1 = _mm256_set1_ps(charge[inr+1]);
156 jq2 = _mm256_set1_ps(charge[inr+2]);
157 jq3 = _mm256_set1_ps(charge[inr+3]);
158 vdwjidx0A = 2*vdwtype[inr+0];
159 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
160 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
161 qq11 = _mm256_mul_ps(iq1,jq1);
162 qq12 = _mm256_mul_ps(iq1,jq2);
163 qq13 = _mm256_mul_ps(iq1,jq3);
164 qq21 = _mm256_mul_ps(iq2,jq1);
165 qq22 = _mm256_mul_ps(iq2,jq2);
166 qq23 = _mm256_mul_ps(iq2,jq3);
167 qq31 = _mm256_mul_ps(iq3,jq1);
168 qq32 = _mm256_mul_ps(iq3,jq2);
169 qq33 = _mm256_mul_ps(iq3,jq3);
171 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
172 rcutoff_scalar = fr->rcoulomb;
173 rcutoff = _mm256_set1_ps(rcutoff_scalar);
174 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
176 rswitch_scalar = fr->rvdw_switch;
177 rswitch = _mm256_set1_ps(rswitch_scalar);
178 /* Setup switch parameters */
179 d_scalar = rcutoff_scalar-rswitch_scalar;
180 d = _mm256_set1_ps(d_scalar);
181 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
182 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
183 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
184 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
185 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
186 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
188 /* Avoid stupid compiler warnings */
189 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
202 for(iidx=0;iidx<4*DIM;iidx++)
207 /* Start outer loop over neighborlists */
208 for(iidx=0; iidx<nri; iidx++)
210 /* Load shift vector for this list */
211 i_shift_offset = DIM*shiftidx[iidx];
213 /* Load limits for loop over neighbors */
214 j_index_start = jindex[iidx];
215 j_index_end = jindex[iidx+1];
217 /* Get outer coordinate index */
219 i_coord_offset = DIM*inr;
221 /* Load i particle coords and add shift vector */
222 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
223 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
225 fix0 = _mm256_setzero_ps();
226 fiy0 = _mm256_setzero_ps();
227 fiz0 = _mm256_setzero_ps();
228 fix1 = _mm256_setzero_ps();
229 fiy1 = _mm256_setzero_ps();
230 fiz1 = _mm256_setzero_ps();
231 fix2 = _mm256_setzero_ps();
232 fiy2 = _mm256_setzero_ps();
233 fiz2 = _mm256_setzero_ps();
234 fix3 = _mm256_setzero_ps();
235 fiy3 = _mm256_setzero_ps();
236 fiz3 = _mm256_setzero_ps();
238 /* Reset potential sums */
239 velecsum = _mm256_setzero_ps();
240 vvdwsum = _mm256_setzero_ps();
242 /* Start inner kernel loop */
243 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
246 /* Get j neighbor index, and coordinate index */
255 j_coord_offsetA = DIM*jnrA;
256 j_coord_offsetB = DIM*jnrB;
257 j_coord_offsetC = DIM*jnrC;
258 j_coord_offsetD = DIM*jnrD;
259 j_coord_offsetE = DIM*jnrE;
260 j_coord_offsetF = DIM*jnrF;
261 j_coord_offsetG = DIM*jnrG;
262 j_coord_offsetH = DIM*jnrH;
264 /* load j atom coordinates */
265 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
266 x+j_coord_offsetC,x+j_coord_offsetD,
267 x+j_coord_offsetE,x+j_coord_offsetF,
268 x+j_coord_offsetG,x+j_coord_offsetH,
269 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
270 &jy2,&jz2,&jx3,&jy3,&jz3);
272 /* Calculate displacement vector */
273 dx00 = _mm256_sub_ps(ix0,jx0);
274 dy00 = _mm256_sub_ps(iy0,jy0);
275 dz00 = _mm256_sub_ps(iz0,jz0);
276 dx11 = _mm256_sub_ps(ix1,jx1);
277 dy11 = _mm256_sub_ps(iy1,jy1);
278 dz11 = _mm256_sub_ps(iz1,jz1);
279 dx12 = _mm256_sub_ps(ix1,jx2);
280 dy12 = _mm256_sub_ps(iy1,jy2);
281 dz12 = _mm256_sub_ps(iz1,jz2);
282 dx13 = _mm256_sub_ps(ix1,jx3);
283 dy13 = _mm256_sub_ps(iy1,jy3);
284 dz13 = _mm256_sub_ps(iz1,jz3);
285 dx21 = _mm256_sub_ps(ix2,jx1);
286 dy21 = _mm256_sub_ps(iy2,jy1);
287 dz21 = _mm256_sub_ps(iz2,jz1);
288 dx22 = _mm256_sub_ps(ix2,jx2);
289 dy22 = _mm256_sub_ps(iy2,jy2);
290 dz22 = _mm256_sub_ps(iz2,jz2);
291 dx23 = _mm256_sub_ps(ix2,jx3);
292 dy23 = _mm256_sub_ps(iy2,jy3);
293 dz23 = _mm256_sub_ps(iz2,jz3);
294 dx31 = _mm256_sub_ps(ix3,jx1);
295 dy31 = _mm256_sub_ps(iy3,jy1);
296 dz31 = _mm256_sub_ps(iz3,jz1);
297 dx32 = _mm256_sub_ps(ix3,jx2);
298 dy32 = _mm256_sub_ps(iy3,jy2);
299 dz32 = _mm256_sub_ps(iz3,jz2);
300 dx33 = _mm256_sub_ps(ix3,jx3);
301 dy33 = _mm256_sub_ps(iy3,jy3);
302 dz33 = _mm256_sub_ps(iz3,jz3);
304 /* Calculate squared distance and things based on it */
305 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
306 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
307 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
308 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
309 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
310 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
311 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
312 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
313 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
314 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
316 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
317 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
318 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
319 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
320 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
321 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
322 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
323 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
324 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
325 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
327 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
328 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
329 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
330 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
331 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
332 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
333 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
334 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
335 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
336 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
338 fjx0 = _mm256_setzero_ps();
339 fjy0 = _mm256_setzero_ps();
340 fjz0 = _mm256_setzero_ps();
341 fjx1 = _mm256_setzero_ps();
342 fjy1 = _mm256_setzero_ps();
343 fjz1 = _mm256_setzero_ps();
344 fjx2 = _mm256_setzero_ps();
345 fjy2 = _mm256_setzero_ps();
346 fjz2 = _mm256_setzero_ps();
347 fjx3 = _mm256_setzero_ps();
348 fjy3 = _mm256_setzero_ps();
349 fjz3 = _mm256_setzero_ps();
351 /**************************
352 * CALCULATE INTERACTIONS *
353 **************************/
355 if (gmx_mm256_any_lt(rsq00,rcutoff2))
358 r00 = _mm256_mul_ps(rsq00,rinv00);
360 /* LENNARD-JONES DISPERSION/REPULSION */
362 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
363 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
364 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
365 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
366 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
368 d = _mm256_sub_ps(r00,rswitch);
369 d = _mm256_max_ps(d,_mm256_setzero_ps());
370 d2 = _mm256_mul_ps(d,d);
371 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)))))));
373 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
375 /* Evaluate switch function */
376 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
377 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
378 vvdw = _mm256_mul_ps(vvdw,sw);
379 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
381 /* Update potential sum for this i atom from the interaction with this j atom. */
382 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
383 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
387 fscal = _mm256_and_ps(fscal,cutoff_mask);
389 /* Calculate temporary vectorial force */
390 tx = _mm256_mul_ps(fscal,dx00);
391 ty = _mm256_mul_ps(fscal,dy00);
392 tz = _mm256_mul_ps(fscal,dz00);
394 /* Update vectorial force */
395 fix0 = _mm256_add_ps(fix0,tx);
396 fiy0 = _mm256_add_ps(fiy0,ty);
397 fiz0 = _mm256_add_ps(fiz0,tz);
399 fjx0 = _mm256_add_ps(fjx0,tx);
400 fjy0 = _mm256_add_ps(fjy0,ty);
401 fjz0 = _mm256_add_ps(fjz0,tz);
405 /**************************
406 * CALCULATE INTERACTIONS *
407 **************************/
409 if (gmx_mm256_any_lt(rsq11,rcutoff2))
412 /* REACTION-FIELD ELECTROSTATICS */
413 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
414 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
416 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
418 /* Update potential sum for this i atom from the interaction with this j atom. */
419 velec = _mm256_and_ps(velec,cutoff_mask);
420 velecsum = _mm256_add_ps(velecsum,velec);
424 fscal = _mm256_and_ps(fscal,cutoff_mask);
426 /* Calculate temporary vectorial force */
427 tx = _mm256_mul_ps(fscal,dx11);
428 ty = _mm256_mul_ps(fscal,dy11);
429 tz = _mm256_mul_ps(fscal,dz11);
431 /* Update vectorial force */
432 fix1 = _mm256_add_ps(fix1,tx);
433 fiy1 = _mm256_add_ps(fiy1,ty);
434 fiz1 = _mm256_add_ps(fiz1,tz);
436 fjx1 = _mm256_add_ps(fjx1,tx);
437 fjy1 = _mm256_add_ps(fjy1,ty);
438 fjz1 = _mm256_add_ps(fjz1,tz);
442 /**************************
443 * CALCULATE INTERACTIONS *
444 **************************/
446 if (gmx_mm256_any_lt(rsq12,rcutoff2))
449 /* REACTION-FIELD ELECTROSTATICS */
450 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
451 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
453 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
455 /* Update potential sum for this i atom from the interaction with this j atom. */
456 velec = _mm256_and_ps(velec,cutoff_mask);
457 velecsum = _mm256_add_ps(velecsum,velec);
461 fscal = _mm256_and_ps(fscal,cutoff_mask);
463 /* Calculate temporary vectorial force */
464 tx = _mm256_mul_ps(fscal,dx12);
465 ty = _mm256_mul_ps(fscal,dy12);
466 tz = _mm256_mul_ps(fscal,dz12);
468 /* Update vectorial force */
469 fix1 = _mm256_add_ps(fix1,tx);
470 fiy1 = _mm256_add_ps(fiy1,ty);
471 fiz1 = _mm256_add_ps(fiz1,tz);
473 fjx2 = _mm256_add_ps(fjx2,tx);
474 fjy2 = _mm256_add_ps(fjy2,ty);
475 fjz2 = _mm256_add_ps(fjz2,tz);
479 /**************************
480 * CALCULATE INTERACTIONS *
481 **************************/
483 if (gmx_mm256_any_lt(rsq13,rcutoff2))
486 /* REACTION-FIELD ELECTROSTATICS */
487 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
488 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
490 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
492 /* Update potential sum for this i atom from the interaction with this j atom. */
493 velec = _mm256_and_ps(velec,cutoff_mask);
494 velecsum = _mm256_add_ps(velecsum,velec);
498 fscal = _mm256_and_ps(fscal,cutoff_mask);
500 /* Calculate temporary vectorial force */
501 tx = _mm256_mul_ps(fscal,dx13);
502 ty = _mm256_mul_ps(fscal,dy13);
503 tz = _mm256_mul_ps(fscal,dz13);
505 /* Update vectorial force */
506 fix1 = _mm256_add_ps(fix1,tx);
507 fiy1 = _mm256_add_ps(fiy1,ty);
508 fiz1 = _mm256_add_ps(fiz1,tz);
510 fjx3 = _mm256_add_ps(fjx3,tx);
511 fjy3 = _mm256_add_ps(fjy3,ty);
512 fjz3 = _mm256_add_ps(fjz3,tz);
516 /**************************
517 * CALCULATE INTERACTIONS *
518 **************************/
520 if (gmx_mm256_any_lt(rsq21,rcutoff2))
523 /* REACTION-FIELD ELECTROSTATICS */
524 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
525 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
527 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
529 /* Update potential sum for this i atom from the interaction with this j atom. */
530 velec = _mm256_and_ps(velec,cutoff_mask);
531 velecsum = _mm256_add_ps(velecsum,velec);
535 fscal = _mm256_and_ps(fscal,cutoff_mask);
537 /* Calculate temporary vectorial force */
538 tx = _mm256_mul_ps(fscal,dx21);
539 ty = _mm256_mul_ps(fscal,dy21);
540 tz = _mm256_mul_ps(fscal,dz21);
542 /* Update vectorial force */
543 fix2 = _mm256_add_ps(fix2,tx);
544 fiy2 = _mm256_add_ps(fiy2,ty);
545 fiz2 = _mm256_add_ps(fiz2,tz);
547 fjx1 = _mm256_add_ps(fjx1,tx);
548 fjy1 = _mm256_add_ps(fjy1,ty);
549 fjz1 = _mm256_add_ps(fjz1,tz);
553 /**************************
554 * CALCULATE INTERACTIONS *
555 **************************/
557 if (gmx_mm256_any_lt(rsq22,rcutoff2))
560 /* REACTION-FIELD ELECTROSTATICS */
561 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
562 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
564 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
566 /* Update potential sum for this i atom from the interaction with this j atom. */
567 velec = _mm256_and_ps(velec,cutoff_mask);
568 velecsum = _mm256_add_ps(velecsum,velec);
572 fscal = _mm256_and_ps(fscal,cutoff_mask);
574 /* Calculate temporary vectorial force */
575 tx = _mm256_mul_ps(fscal,dx22);
576 ty = _mm256_mul_ps(fscal,dy22);
577 tz = _mm256_mul_ps(fscal,dz22);
579 /* Update vectorial force */
580 fix2 = _mm256_add_ps(fix2,tx);
581 fiy2 = _mm256_add_ps(fiy2,ty);
582 fiz2 = _mm256_add_ps(fiz2,tz);
584 fjx2 = _mm256_add_ps(fjx2,tx);
585 fjy2 = _mm256_add_ps(fjy2,ty);
586 fjz2 = _mm256_add_ps(fjz2,tz);
590 /**************************
591 * CALCULATE INTERACTIONS *
592 **************************/
594 if (gmx_mm256_any_lt(rsq23,rcutoff2))
597 /* REACTION-FIELD ELECTROSTATICS */
598 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
599 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
601 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
603 /* Update potential sum for this i atom from the interaction with this j atom. */
604 velec = _mm256_and_ps(velec,cutoff_mask);
605 velecsum = _mm256_add_ps(velecsum,velec);
609 fscal = _mm256_and_ps(fscal,cutoff_mask);
611 /* Calculate temporary vectorial force */
612 tx = _mm256_mul_ps(fscal,dx23);
613 ty = _mm256_mul_ps(fscal,dy23);
614 tz = _mm256_mul_ps(fscal,dz23);
616 /* Update vectorial force */
617 fix2 = _mm256_add_ps(fix2,tx);
618 fiy2 = _mm256_add_ps(fiy2,ty);
619 fiz2 = _mm256_add_ps(fiz2,tz);
621 fjx3 = _mm256_add_ps(fjx3,tx);
622 fjy3 = _mm256_add_ps(fjy3,ty);
623 fjz3 = _mm256_add_ps(fjz3,tz);
627 /**************************
628 * CALCULATE INTERACTIONS *
629 **************************/
631 if (gmx_mm256_any_lt(rsq31,rcutoff2))
634 /* REACTION-FIELD ELECTROSTATICS */
635 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
636 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
638 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
640 /* Update potential sum for this i atom from the interaction with this j atom. */
641 velec = _mm256_and_ps(velec,cutoff_mask);
642 velecsum = _mm256_add_ps(velecsum,velec);
646 fscal = _mm256_and_ps(fscal,cutoff_mask);
648 /* Calculate temporary vectorial force */
649 tx = _mm256_mul_ps(fscal,dx31);
650 ty = _mm256_mul_ps(fscal,dy31);
651 tz = _mm256_mul_ps(fscal,dz31);
653 /* Update vectorial force */
654 fix3 = _mm256_add_ps(fix3,tx);
655 fiy3 = _mm256_add_ps(fiy3,ty);
656 fiz3 = _mm256_add_ps(fiz3,tz);
658 fjx1 = _mm256_add_ps(fjx1,tx);
659 fjy1 = _mm256_add_ps(fjy1,ty);
660 fjz1 = _mm256_add_ps(fjz1,tz);
664 /**************************
665 * CALCULATE INTERACTIONS *
666 **************************/
668 if (gmx_mm256_any_lt(rsq32,rcutoff2))
671 /* REACTION-FIELD ELECTROSTATICS */
672 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
673 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
675 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
677 /* Update potential sum for this i atom from the interaction with this j atom. */
678 velec = _mm256_and_ps(velec,cutoff_mask);
679 velecsum = _mm256_add_ps(velecsum,velec);
683 fscal = _mm256_and_ps(fscal,cutoff_mask);
685 /* Calculate temporary vectorial force */
686 tx = _mm256_mul_ps(fscal,dx32);
687 ty = _mm256_mul_ps(fscal,dy32);
688 tz = _mm256_mul_ps(fscal,dz32);
690 /* Update vectorial force */
691 fix3 = _mm256_add_ps(fix3,tx);
692 fiy3 = _mm256_add_ps(fiy3,ty);
693 fiz3 = _mm256_add_ps(fiz3,tz);
695 fjx2 = _mm256_add_ps(fjx2,tx);
696 fjy2 = _mm256_add_ps(fjy2,ty);
697 fjz2 = _mm256_add_ps(fjz2,tz);
701 /**************************
702 * CALCULATE INTERACTIONS *
703 **************************/
705 if (gmx_mm256_any_lt(rsq33,rcutoff2))
708 /* REACTION-FIELD ELECTROSTATICS */
709 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
710 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
712 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
714 /* Update potential sum for this i atom from the interaction with this j atom. */
715 velec = _mm256_and_ps(velec,cutoff_mask);
716 velecsum = _mm256_add_ps(velecsum,velec);
720 fscal = _mm256_and_ps(fscal,cutoff_mask);
722 /* Calculate temporary vectorial force */
723 tx = _mm256_mul_ps(fscal,dx33);
724 ty = _mm256_mul_ps(fscal,dy33);
725 tz = _mm256_mul_ps(fscal,dz33);
727 /* Update vectorial force */
728 fix3 = _mm256_add_ps(fix3,tx);
729 fiy3 = _mm256_add_ps(fiy3,ty);
730 fiz3 = _mm256_add_ps(fiz3,tz);
732 fjx3 = _mm256_add_ps(fjx3,tx);
733 fjy3 = _mm256_add_ps(fjy3,ty);
734 fjz3 = _mm256_add_ps(fjz3,tz);
738 fjptrA = f+j_coord_offsetA;
739 fjptrB = f+j_coord_offsetB;
740 fjptrC = f+j_coord_offsetC;
741 fjptrD = f+j_coord_offsetD;
742 fjptrE = f+j_coord_offsetE;
743 fjptrF = f+j_coord_offsetF;
744 fjptrG = f+j_coord_offsetG;
745 fjptrH = f+j_coord_offsetH;
747 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
748 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
749 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
751 /* Inner loop uses 386 flops */
757 /* Get j neighbor index, and coordinate index */
758 jnrlistA = jjnr[jidx];
759 jnrlistB = jjnr[jidx+1];
760 jnrlistC = jjnr[jidx+2];
761 jnrlistD = jjnr[jidx+3];
762 jnrlistE = jjnr[jidx+4];
763 jnrlistF = jjnr[jidx+5];
764 jnrlistG = jjnr[jidx+6];
765 jnrlistH = jjnr[jidx+7];
766 /* Sign of each element will be negative for non-real atoms.
767 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
768 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
770 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
771 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
773 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
774 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
775 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
776 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
777 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
778 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
779 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
780 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
781 j_coord_offsetA = DIM*jnrA;
782 j_coord_offsetB = DIM*jnrB;
783 j_coord_offsetC = DIM*jnrC;
784 j_coord_offsetD = DIM*jnrD;
785 j_coord_offsetE = DIM*jnrE;
786 j_coord_offsetF = DIM*jnrF;
787 j_coord_offsetG = DIM*jnrG;
788 j_coord_offsetH = DIM*jnrH;
790 /* load j atom coordinates */
791 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
792 x+j_coord_offsetC,x+j_coord_offsetD,
793 x+j_coord_offsetE,x+j_coord_offsetF,
794 x+j_coord_offsetG,x+j_coord_offsetH,
795 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
796 &jy2,&jz2,&jx3,&jy3,&jz3);
798 /* Calculate displacement vector */
799 dx00 = _mm256_sub_ps(ix0,jx0);
800 dy00 = _mm256_sub_ps(iy0,jy0);
801 dz00 = _mm256_sub_ps(iz0,jz0);
802 dx11 = _mm256_sub_ps(ix1,jx1);
803 dy11 = _mm256_sub_ps(iy1,jy1);
804 dz11 = _mm256_sub_ps(iz1,jz1);
805 dx12 = _mm256_sub_ps(ix1,jx2);
806 dy12 = _mm256_sub_ps(iy1,jy2);
807 dz12 = _mm256_sub_ps(iz1,jz2);
808 dx13 = _mm256_sub_ps(ix1,jx3);
809 dy13 = _mm256_sub_ps(iy1,jy3);
810 dz13 = _mm256_sub_ps(iz1,jz3);
811 dx21 = _mm256_sub_ps(ix2,jx1);
812 dy21 = _mm256_sub_ps(iy2,jy1);
813 dz21 = _mm256_sub_ps(iz2,jz1);
814 dx22 = _mm256_sub_ps(ix2,jx2);
815 dy22 = _mm256_sub_ps(iy2,jy2);
816 dz22 = _mm256_sub_ps(iz2,jz2);
817 dx23 = _mm256_sub_ps(ix2,jx3);
818 dy23 = _mm256_sub_ps(iy2,jy3);
819 dz23 = _mm256_sub_ps(iz2,jz3);
820 dx31 = _mm256_sub_ps(ix3,jx1);
821 dy31 = _mm256_sub_ps(iy3,jy1);
822 dz31 = _mm256_sub_ps(iz3,jz1);
823 dx32 = _mm256_sub_ps(ix3,jx2);
824 dy32 = _mm256_sub_ps(iy3,jy2);
825 dz32 = _mm256_sub_ps(iz3,jz2);
826 dx33 = _mm256_sub_ps(ix3,jx3);
827 dy33 = _mm256_sub_ps(iy3,jy3);
828 dz33 = _mm256_sub_ps(iz3,jz3);
830 /* Calculate squared distance and things based on it */
831 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
832 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
833 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
834 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
835 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
836 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
837 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
838 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
839 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
840 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
842 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
843 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
844 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
845 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
846 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
847 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
848 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
849 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
850 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
851 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
853 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
854 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
855 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
856 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
857 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
858 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
859 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
860 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
861 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
862 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
864 fjx0 = _mm256_setzero_ps();
865 fjy0 = _mm256_setzero_ps();
866 fjz0 = _mm256_setzero_ps();
867 fjx1 = _mm256_setzero_ps();
868 fjy1 = _mm256_setzero_ps();
869 fjz1 = _mm256_setzero_ps();
870 fjx2 = _mm256_setzero_ps();
871 fjy2 = _mm256_setzero_ps();
872 fjz2 = _mm256_setzero_ps();
873 fjx3 = _mm256_setzero_ps();
874 fjy3 = _mm256_setzero_ps();
875 fjz3 = _mm256_setzero_ps();
877 /**************************
878 * CALCULATE INTERACTIONS *
879 **************************/
881 if (gmx_mm256_any_lt(rsq00,rcutoff2))
884 r00 = _mm256_mul_ps(rsq00,rinv00);
885 r00 = _mm256_andnot_ps(dummy_mask,r00);
887 /* LENNARD-JONES DISPERSION/REPULSION */
889 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
890 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
891 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
892 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
893 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
895 d = _mm256_sub_ps(r00,rswitch);
896 d = _mm256_max_ps(d,_mm256_setzero_ps());
897 d2 = _mm256_mul_ps(d,d);
898 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)))))));
900 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
902 /* Evaluate switch function */
903 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
904 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
905 vvdw = _mm256_mul_ps(vvdw,sw);
906 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
908 /* Update potential sum for this i atom from the interaction with this j atom. */
909 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
910 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
911 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
915 fscal = _mm256_and_ps(fscal,cutoff_mask);
917 fscal = _mm256_andnot_ps(dummy_mask,fscal);
919 /* Calculate temporary vectorial force */
920 tx = _mm256_mul_ps(fscal,dx00);
921 ty = _mm256_mul_ps(fscal,dy00);
922 tz = _mm256_mul_ps(fscal,dz00);
924 /* Update vectorial force */
925 fix0 = _mm256_add_ps(fix0,tx);
926 fiy0 = _mm256_add_ps(fiy0,ty);
927 fiz0 = _mm256_add_ps(fiz0,tz);
929 fjx0 = _mm256_add_ps(fjx0,tx);
930 fjy0 = _mm256_add_ps(fjy0,ty);
931 fjz0 = _mm256_add_ps(fjz0,tz);
935 /**************************
936 * CALCULATE INTERACTIONS *
937 **************************/
939 if (gmx_mm256_any_lt(rsq11,rcutoff2))
942 /* REACTION-FIELD ELECTROSTATICS */
943 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
944 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
946 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
948 /* Update potential sum for this i atom from the interaction with this j atom. */
949 velec = _mm256_and_ps(velec,cutoff_mask);
950 velec = _mm256_andnot_ps(dummy_mask,velec);
951 velecsum = _mm256_add_ps(velecsum,velec);
955 fscal = _mm256_and_ps(fscal,cutoff_mask);
957 fscal = _mm256_andnot_ps(dummy_mask,fscal);
959 /* Calculate temporary vectorial force */
960 tx = _mm256_mul_ps(fscal,dx11);
961 ty = _mm256_mul_ps(fscal,dy11);
962 tz = _mm256_mul_ps(fscal,dz11);
964 /* Update vectorial force */
965 fix1 = _mm256_add_ps(fix1,tx);
966 fiy1 = _mm256_add_ps(fiy1,ty);
967 fiz1 = _mm256_add_ps(fiz1,tz);
969 fjx1 = _mm256_add_ps(fjx1,tx);
970 fjy1 = _mm256_add_ps(fjy1,ty);
971 fjz1 = _mm256_add_ps(fjz1,tz);
975 /**************************
976 * CALCULATE INTERACTIONS *
977 **************************/
979 if (gmx_mm256_any_lt(rsq12,rcutoff2))
982 /* REACTION-FIELD ELECTROSTATICS */
983 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
984 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
986 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
988 /* Update potential sum for this i atom from the interaction with this j atom. */
989 velec = _mm256_and_ps(velec,cutoff_mask);
990 velec = _mm256_andnot_ps(dummy_mask,velec);
991 velecsum = _mm256_add_ps(velecsum,velec);
995 fscal = _mm256_and_ps(fscal,cutoff_mask);
997 fscal = _mm256_andnot_ps(dummy_mask,fscal);
999 /* Calculate temporary vectorial force */
1000 tx = _mm256_mul_ps(fscal,dx12);
1001 ty = _mm256_mul_ps(fscal,dy12);
1002 tz = _mm256_mul_ps(fscal,dz12);
1004 /* Update vectorial force */
1005 fix1 = _mm256_add_ps(fix1,tx);
1006 fiy1 = _mm256_add_ps(fiy1,ty);
1007 fiz1 = _mm256_add_ps(fiz1,tz);
1009 fjx2 = _mm256_add_ps(fjx2,tx);
1010 fjy2 = _mm256_add_ps(fjy2,ty);
1011 fjz2 = _mm256_add_ps(fjz2,tz);
1015 /**************************
1016 * CALCULATE INTERACTIONS *
1017 **************************/
1019 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1022 /* REACTION-FIELD ELECTROSTATICS */
1023 velec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_add_ps(rinv13,_mm256_mul_ps(krf,rsq13)),crf));
1024 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1026 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1028 /* Update potential sum for this i atom from the interaction with this j atom. */
1029 velec = _mm256_and_ps(velec,cutoff_mask);
1030 velec = _mm256_andnot_ps(dummy_mask,velec);
1031 velecsum = _mm256_add_ps(velecsum,velec);
1035 fscal = _mm256_and_ps(fscal,cutoff_mask);
1037 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1039 /* Calculate temporary vectorial force */
1040 tx = _mm256_mul_ps(fscal,dx13);
1041 ty = _mm256_mul_ps(fscal,dy13);
1042 tz = _mm256_mul_ps(fscal,dz13);
1044 /* Update vectorial force */
1045 fix1 = _mm256_add_ps(fix1,tx);
1046 fiy1 = _mm256_add_ps(fiy1,ty);
1047 fiz1 = _mm256_add_ps(fiz1,tz);
1049 fjx3 = _mm256_add_ps(fjx3,tx);
1050 fjy3 = _mm256_add_ps(fjy3,ty);
1051 fjz3 = _mm256_add_ps(fjz3,tz);
1055 /**************************
1056 * CALCULATE INTERACTIONS *
1057 **************************/
1059 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1062 /* REACTION-FIELD ELECTROSTATICS */
1063 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1064 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1066 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1068 /* Update potential sum for this i atom from the interaction with this j atom. */
1069 velec = _mm256_and_ps(velec,cutoff_mask);
1070 velec = _mm256_andnot_ps(dummy_mask,velec);
1071 velecsum = _mm256_add_ps(velecsum,velec);
1075 fscal = _mm256_and_ps(fscal,cutoff_mask);
1077 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1079 /* Calculate temporary vectorial force */
1080 tx = _mm256_mul_ps(fscal,dx21);
1081 ty = _mm256_mul_ps(fscal,dy21);
1082 tz = _mm256_mul_ps(fscal,dz21);
1084 /* Update vectorial force */
1085 fix2 = _mm256_add_ps(fix2,tx);
1086 fiy2 = _mm256_add_ps(fiy2,ty);
1087 fiz2 = _mm256_add_ps(fiz2,tz);
1089 fjx1 = _mm256_add_ps(fjx1,tx);
1090 fjy1 = _mm256_add_ps(fjy1,ty);
1091 fjz1 = _mm256_add_ps(fjz1,tz);
1095 /**************************
1096 * CALCULATE INTERACTIONS *
1097 **************************/
1099 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1102 /* REACTION-FIELD ELECTROSTATICS */
1103 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1104 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1106 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1108 /* Update potential sum for this i atom from the interaction with this j atom. */
1109 velec = _mm256_and_ps(velec,cutoff_mask);
1110 velec = _mm256_andnot_ps(dummy_mask,velec);
1111 velecsum = _mm256_add_ps(velecsum,velec);
1115 fscal = _mm256_and_ps(fscal,cutoff_mask);
1117 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1119 /* Calculate temporary vectorial force */
1120 tx = _mm256_mul_ps(fscal,dx22);
1121 ty = _mm256_mul_ps(fscal,dy22);
1122 tz = _mm256_mul_ps(fscal,dz22);
1124 /* Update vectorial force */
1125 fix2 = _mm256_add_ps(fix2,tx);
1126 fiy2 = _mm256_add_ps(fiy2,ty);
1127 fiz2 = _mm256_add_ps(fiz2,tz);
1129 fjx2 = _mm256_add_ps(fjx2,tx);
1130 fjy2 = _mm256_add_ps(fjy2,ty);
1131 fjz2 = _mm256_add_ps(fjz2,tz);
1135 /**************************
1136 * CALCULATE INTERACTIONS *
1137 **************************/
1139 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1142 /* REACTION-FIELD ELECTROSTATICS */
1143 velec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_add_ps(rinv23,_mm256_mul_ps(krf,rsq23)),crf));
1144 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1146 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1148 /* Update potential sum for this i atom from the interaction with this j atom. */
1149 velec = _mm256_and_ps(velec,cutoff_mask);
1150 velec = _mm256_andnot_ps(dummy_mask,velec);
1151 velecsum = _mm256_add_ps(velecsum,velec);
1155 fscal = _mm256_and_ps(fscal,cutoff_mask);
1157 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1159 /* Calculate temporary vectorial force */
1160 tx = _mm256_mul_ps(fscal,dx23);
1161 ty = _mm256_mul_ps(fscal,dy23);
1162 tz = _mm256_mul_ps(fscal,dz23);
1164 /* Update vectorial force */
1165 fix2 = _mm256_add_ps(fix2,tx);
1166 fiy2 = _mm256_add_ps(fiy2,ty);
1167 fiz2 = _mm256_add_ps(fiz2,tz);
1169 fjx3 = _mm256_add_ps(fjx3,tx);
1170 fjy3 = _mm256_add_ps(fjy3,ty);
1171 fjz3 = _mm256_add_ps(fjz3,tz);
1175 /**************************
1176 * CALCULATE INTERACTIONS *
1177 **************************/
1179 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1182 /* REACTION-FIELD ELECTROSTATICS */
1183 velec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_add_ps(rinv31,_mm256_mul_ps(krf,rsq31)),crf));
1184 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1186 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1188 /* Update potential sum for this i atom from the interaction with this j atom. */
1189 velec = _mm256_and_ps(velec,cutoff_mask);
1190 velec = _mm256_andnot_ps(dummy_mask,velec);
1191 velecsum = _mm256_add_ps(velecsum,velec);
1195 fscal = _mm256_and_ps(fscal,cutoff_mask);
1197 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1199 /* Calculate temporary vectorial force */
1200 tx = _mm256_mul_ps(fscal,dx31);
1201 ty = _mm256_mul_ps(fscal,dy31);
1202 tz = _mm256_mul_ps(fscal,dz31);
1204 /* Update vectorial force */
1205 fix3 = _mm256_add_ps(fix3,tx);
1206 fiy3 = _mm256_add_ps(fiy3,ty);
1207 fiz3 = _mm256_add_ps(fiz3,tz);
1209 fjx1 = _mm256_add_ps(fjx1,tx);
1210 fjy1 = _mm256_add_ps(fjy1,ty);
1211 fjz1 = _mm256_add_ps(fjz1,tz);
1215 /**************************
1216 * CALCULATE INTERACTIONS *
1217 **************************/
1219 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1222 /* REACTION-FIELD ELECTROSTATICS */
1223 velec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_add_ps(rinv32,_mm256_mul_ps(krf,rsq32)),crf));
1224 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1226 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1228 /* Update potential sum for this i atom from the interaction with this j atom. */
1229 velec = _mm256_and_ps(velec,cutoff_mask);
1230 velec = _mm256_andnot_ps(dummy_mask,velec);
1231 velecsum = _mm256_add_ps(velecsum,velec);
1235 fscal = _mm256_and_ps(fscal,cutoff_mask);
1237 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1239 /* Calculate temporary vectorial force */
1240 tx = _mm256_mul_ps(fscal,dx32);
1241 ty = _mm256_mul_ps(fscal,dy32);
1242 tz = _mm256_mul_ps(fscal,dz32);
1244 /* Update vectorial force */
1245 fix3 = _mm256_add_ps(fix3,tx);
1246 fiy3 = _mm256_add_ps(fiy3,ty);
1247 fiz3 = _mm256_add_ps(fiz3,tz);
1249 fjx2 = _mm256_add_ps(fjx2,tx);
1250 fjy2 = _mm256_add_ps(fjy2,ty);
1251 fjz2 = _mm256_add_ps(fjz2,tz);
1255 /**************************
1256 * CALCULATE INTERACTIONS *
1257 **************************/
1259 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1262 /* REACTION-FIELD ELECTROSTATICS */
1263 velec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_add_ps(rinv33,_mm256_mul_ps(krf,rsq33)),crf));
1264 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1266 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1268 /* Update potential sum for this i atom from the interaction with this j atom. */
1269 velec = _mm256_and_ps(velec,cutoff_mask);
1270 velec = _mm256_andnot_ps(dummy_mask,velec);
1271 velecsum = _mm256_add_ps(velecsum,velec);
1275 fscal = _mm256_and_ps(fscal,cutoff_mask);
1277 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1279 /* Calculate temporary vectorial force */
1280 tx = _mm256_mul_ps(fscal,dx33);
1281 ty = _mm256_mul_ps(fscal,dy33);
1282 tz = _mm256_mul_ps(fscal,dz33);
1284 /* Update vectorial force */
1285 fix3 = _mm256_add_ps(fix3,tx);
1286 fiy3 = _mm256_add_ps(fiy3,ty);
1287 fiz3 = _mm256_add_ps(fiz3,tz);
1289 fjx3 = _mm256_add_ps(fjx3,tx);
1290 fjy3 = _mm256_add_ps(fjy3,ty);
1291 fjz3 = _mm256_add_ps(fjz3,tz);
1295 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1296 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1297 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1298 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1299 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1300 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1301 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1302 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1304 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1305 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1306 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1308 /* Inner loop uses 387 flops */
1311 /* End of innermost loop */
1313 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1314 f+i_coord_offset,fshift+i_shift_offset);
1317 /* Update potential energies */
1318 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1319 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1321 /* Increment number of inner iterations */
1322 inneriter += j_index_end - j_index_start;
1324 /* Outer loop uses 26 flops */
1327 /* Increment number of outer iterations */
1330 /* Update outer/inner flops */
1332 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*387);
1335 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1336 * Electrostatics interaction: ReactionField
1337 * VdW interaction: LennardJones
1338 * Geometry: Water4-Water4
1339 * Calculate force/pot: Force
1342 nb_kernel_ElecRFCut_VdwLJSw_GeomW4W4_F_avx_256_single
1343 (t_nblist * gmx_restrict nlist,
1344 rvec * gmx_restrict xx,
1345 rvec * gmx_restrict ff,
1346 t_forcerec * gmx_restrict fr,
1347 t_mdatoms * gmx_restrict mdatoms,
1348 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1349 t_nrnb * gmx_restrict nrnb)
1351 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1352 * just 0 for non-waters.
1353 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1354 * jnr indices corresponding to data put in the four positions in the SIMD register.
1356 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1357 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1358 int jnrA,jnrB,jnrC,jnrD;
1359 int jnrE,jnrF,jnrG,jnrH;
1360 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1361 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1362 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1363 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1364 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1365 real rcutoff_scalar;
1366 real *shiftvec,*fshift,*x,*f;
1367 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1368 real scratch[4*DIM];
1369 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1370 real * vdwioffsetptr0;
1371 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1372 real * vdwioffsetptr1;
1373 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1374 real * vdwioffsetptr2;
1375 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1376 real * vdwioffsetptr3;
1377 __m256 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1378 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1379 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1380 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1381 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1382 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1383 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1384 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D,vdwjidx3E,vdwjidx3F,vdwjidx3G,vdwjidx3H;
1385 __m256 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1386 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1387 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1388 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1389 __m256 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1390 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1391 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1392 __m256 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1393 __m256 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1394 __m256 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1395 __m256 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1396 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1399 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1402 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1403 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1404 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
1405 real rswitch_scalar,d_scalar;
1406 __m256 dummy_mask,cutoff_mask;
1407 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1408 __m256 one = _mm256_set1_ps(1.0);
1409 __m256 two = _mm256_set1_ps(2.0);
1415 jindex = nlist->jindex;
1417 shiftidx = nlist->shift;
1419 shiftvec = fr->shift_vec[0];
1420 fshift = fr->fshift[0];
1421 facel = _mm256_set1_ps(fr->epsfac);
1422 charge = mdatoms->chargeA;
1423 krf = _mm256_set1_ps(fr->ic->k_rf);
1424 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1425 crf = _mm256_set1_ps(fr->ic->c_rf);
1426 nvdwtype = fr->ntype;
1427 vdwparam = fr->nbfp;
1428 vdwtype = mdatoms->typeA;
1430 /* Setup water-specific parameters */
1431 inr = nlist->iinr[0];
1432 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1433 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1434 iq3 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+3]));
1435 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1437 jq1 = _mm256_set1_ps(charge[inr+1]);
1438 jq2 = _mm256_set1_ps(charge[inr+2]);
1439 jq3 = _mm256_set1_ps(charge[inr+3]);
1440 vdwjidx0A = 2*vdwtype[inr+0];
1441 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1442 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1443 qq11 = _mm256_mul_ps(iq1,jq1);
1444 qq12 = _mm256_mul_ps(iq1,jq2);
1445 qq13 = _mm256_mul_ps(iq1,jq3);
1446 qq21 = _mm256_mul_ps(iq2,jq1);
1447 qq22 = _mm256_mul_ps(iq2,jq2);
1448 qq23 = _mm256_mul_ps(iq2,jq3);
1449 qq31 = _mm256_mul_ps(iq3,jq1);
1450 qq32 = _mm256_mul_ps(iq3,jq2);
1451 qq33 = _mm256_mul_ps(iq3,jq3);
1453 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1454 rcutoff_scalar = fr->rcoulomb;
1455 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1456 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1458 rswitch_scalar = fr->rvdw_switch;
1459 rswitch = _mm256_set1_ps(rswitch_scalar);
1460 /* Setup switch parameters */
1461 d_scalar = rcutoff_scalar-rswitch_scalar;
1462 d = _mm256_set1_ps(d_scalar);
1463 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
1464 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1465 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1466 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
1467 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1468 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1470 /* Avoid stupid compiler warnings */
1471 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1472 j_coord_offsetA = 0;
1473 j_coord_offsetB = 0;
1474 j_coord_offsetC = 0;
1475 j_coord_offsetD = 0;
1476 j_coord_offsetE = 0;
1477 j_coord_offsetF = 0;
1478 j_coord_offsetG = 0;
1479 j_coord_offsetH = 0;
1484 for(iidx=0;iidx<4*DIM;iidx++)
1486 scratch[iidx] = 0.0;
1489 /* Start outer loop over neighborlists */
1490 for(iidx=0; iidx<nri; iidx++)
1492 /* Load shift vector for this list */
1493 i_shift_offset = DIM*shiftidx[iidx];
1495 /* Load limits for loop over neighbors */
1496 j_index_start = jindex[iidx];
1497 j_index_end = jindex[iidx+1];
1499 /* Get outer coordinate index */
1501 i_coord_offset = DIM*inr;
1503 /* Load i particle coords and add shift vector */
1504 gmx_mm256_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1505 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1507 fix0 = _mm256_setzero_ps();
1508 fiy0 = _mm256_setzero_ps();
1509 fiz0 = _mm256_setzero_ps();
1510 fix1 = _mm256_setzero_ps();
1511 fiy1 = _mm256_setzero_ps();
1512 fiz1 = _mm256_setzero_ps();
1513 fix2 = _mm256_setzero_ps();
1514 fiy2 = _mm256_setzero_ps();
1515 fiz2 = _mm256_setzero_ps();
1516 fix3 = _mm256_setzero_ps();
1517 fiy3 = _mm256_setzero_ps();
1518 fiz3 = _mm256_setzero_ps();
1520 /* Start inner kernel loop */
1521 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1524 /* Get j neighbor index, and coordinate index */
1526 jnrB = jjnr[jidx+1];
1527 jnrC = jjnr[jidx+2];
1528 jnrD = jjnr[jidx+3];
1529 jnrE = jjnr[jidx+4];
1530 jnrF = jjnr[jidx+5];
1531 jnrG = jjnr[jidx+6];
1532 jnrH = jjnr[jidx+7];
1533 j_coord_offsetA = DIM*jnrA;
1534 j_coord_offsetB = DIM*jnrB;
1535 j_coord_offsetC = DIM*jnrC;
1536 j_coord_offsetD = DIM*jnrD;
1537 j_coord_offsetE = DIM*jnrE;
1538 j_coord_offsetF = DIM*jnrF;
1539 j_coord_offsetG = DIM*jnrG;
1540 j_coord_offsetH = DIM*jnrH;
1542 /* load j atom coordinates */
1543 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1544 x+j_coord_offsetC,x+j_coord_offsetD,
1545 x+j_coord_offsetE,x+j_coord_offsetF,
1546 x+j_coord_offsetG,x+j_coord_offsetH,
1547 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1548 &jy2,&jz2,&jx3,&jy3,&jz3);
1550 /* Calculate displacement vector */
1551 dx00 = _mm256_sub_ps(ix0,jx0);
1552 dy00 = _mm256_sub_ps(iy0,jy0);
1553 dz00 = _mm256_sub_ps(iz0,jz0);
1554 dx11 = _mm256_sub_ps(ix1,jx1);
1555 dy11 = _mm256_sub_ps(iy1,jy1);
1556 dz11 = _mm256_sub_ps(iz1,jz1);
1557 dx12 = _mm256_sub_ps(ix1,jx2);
1558 dy12 = _mm256_sub_ps(iy1,jy2);
1559 dz12 = _mm256_sub_ps(iz1,jz2);
1560 dx13 = _mm256_sub_ps(ix1,jx3);
1561 dy13 = _mm256_sub_ps(iy1,jy3);
1562 dz13 = _mm256_sub_ps(iz1,jz3);
1563 dx21 = _mm256_sub_ps(ix2,jx1);
1564 dy21 = _mm256_sub_ps(iy2,jy1);
1565 dz21 = _mm256_sub_ps(iz2,jz1);
1566 dx22 = _mm256_sub_ps(ix2,jx2);
1567 dy22 = _mm256_sub_ps(iy2,jy2);
1568 dz22 = _mm256_sub_ps(iz2,jz2);
1569 dx23 = _mm256_sub_ps(ix2,jx3);
1570 dy23 = _mm256_sub_ps(iy2,jy3);
1571 dz23 = _mm256_sub_ps(iz2,jz3);
1572 dx31 = _mm256_sub_ps(ix3,jx1);
1573 dy31 = _mm256_sub_ps(iy3,jy1);
1574 dz31 = _mm256_sub_ps(iz3,jz1);
1575 dx32 = _mm256_sub_ps(ix3,jx2);
1576 dy32 = _mm256_sub_ps(iy3,jy2);
1577 dz32 = _mm256_sub_ps(iz3,jz2);
1578 dx33 = _mm256_sub_ps(ix3,jx3);
1579 dy33 = _mm256_sub_ps(iy3,jy3);
1580 dz33 = _mm256_sub_ps(iz3,jz3);
1582 /* Calculate squared distance and things based on it */
1583 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1584 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1585 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1586 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
1587 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1588 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1589 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
1590 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
1591 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
1592 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
1594 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1595 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1596 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1597 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
1598 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1599 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1600 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
1601 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
1602 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
1603 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
1605 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1606 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1607 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1608 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
1609 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1610 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1611 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
1612 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
1613 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
1614 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
1616 fjx0 = _mm256_setzero_ps();
1617 fjy0 = _mm256_setzero_ps();
1618 fjz0 = _mm256_setzero_ps();
1619 fjx1 = _mm256_setzero_ps();
1620 fjy1 = _mm256_setzero_ps();
1621 fjz1 = _mm256_setzero_ps();
1622 fjx2 = _mm256_setzero_ps();
1623 fjy2 = _mm256_setzero_ps();
1624 fjz2 = _mm256_setzero_ps();
1625 fjx3 = _mm256_setzero_ps();
1626 fjy3 = _mm256_setzero_ps();
1627 fjz3 = _mm256_setzero_ps();
1629 /**************************
1630 * CALCULATE INTERACTIONS *
1631 **************************/
1633 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1636 r00 = _mm256_mul_ps(rsq00,rinv00);
1638 /* LENNARD-JONES DISPERSION/REPULSION */
1640 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1641 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
1642 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
1643 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
1644 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
1646 d = _mm256_sub_ps(r00,rswitch);
1647 d = _mm256_max_ps(d,_mm256_setzero_ps());
1648 d2 = _mm256_mul_ps(d,d);
1649 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)))))));
1651 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
1653 /* Evaluate switch function */
1654 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1655 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
1656 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1660 fscal = _mm256_and_ps(fscal,cutoff_mask);
1662 /* Calculate temporary vectorial force */
1663 tx = _mm256_mul_ps(fscal,dx00);
1664 ty = _mm256_mul_ps(fscal,dy00);
1665 tz = _mm256_mul_ps(fscal,dz00);
1667 /* Update vectorial force */
1668 fix0 = _mm256_add_ps(fix0,tx);
1669 fiy0 = _mm256_add_ps(fiy0,ty);
1670 fiz0 = _mm256_add_ps(fiz0,tz);
1672 fjx0 = _mm256_add_ps(fjx0,tx);
1673 fjy0 = _mm256_add_ps(fjy0,ty);
1674 fjz0 = _mm256_add_ps(fjz0,tz);
1678 /**************************
1679 * CALCULATE INTERACTIONS *
1680 **************************/
1682 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1685 /* REACTION-FIELD ELECTROSTATICS */
1686 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1688 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1692 fscal = _mm256_and_ps(fscal,cutoff_mask);
1694 /* Calculate temporary vectorial force */
1695 tx = _mm256_mul_ps(fscal,dx11);
1696 ty = _mm256_mul_ps(fscal,dy11);
1697 tz = _mm256_mul_ps(fscal,dz11);
1699 /* Update vectorial force */
1700 fix1 = _mm256_add_ps(fix1,tx);
1701 fiy1 = _mm256_add_ps(fiy1,ty);
1702 fiz1 = _mm256_add_ps(fiz1,tz);
1704 fjx1 = _mm256_add_ps(fjx1,tx);
1705 fjy1 = _mm256_add_ps(fjy1,ty);
1706 fjz1 = _mm256_add_ps(fjz1,tz);
1710 /**************************
1711 * CALCULATE INTERACTIONS *
1712 **************************/
1714 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1717 /* REACTION-FIELD ELECTROSTATICS */
1718 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1720 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1724 fscal = _mm256_and_ps(fscal,cutoff_mask);
1726 /* Calculate temporary vectorial force */
1727 tx = _mm256_mul_ps(fscal,dx12);
1728 ty = _mm256_mul_ps(fscal,dy12);
1729 tz = _mm256_mul_ps(fscal,dz12);
1731 /* Update vectorial force */
1732 fix1 = _mm256_add_ps(fix1,tx);
1733 fiy1 = _mm256_add_ps(fiy1,ty);
1734 fiz1 = _mm256_add_ps(fiz1,tz);
1736 fjx2 = _mm256_add_ps(fjx2,tx);
1737 fjy2 = _mm256_add_ps(fjy2,ty);
1738 fjz2 = _mm256_add_ps(fjz2,tz);
1742 /**************************
1743 * CALCULATE INTERACTIONS *
1744 **************************/
1746 if (gmx_mm256_any_lt(rsq13,rcutoff2))
1749 /* REACTION-FIELD ELECTROSTATICS */
1750 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
1752 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
1756 fscal = _mm256_and_ps(fscal,cutoff_mask);
1758 /* Calculate temporary vectorial force */
1759 tx = _mm256_mul_ps(fscal,dx13);
1760 ty = _mm256_mul_ps(fscal,dy13);
1761 tz = _mm256_mul_ps(fscal,dz13);
1763 /* Update vectorial force */
1764 fix1 = _mm256_add_ps(fix1,tx);
1765 fiy1 = _mm256_add_ps(fiy1,ty);
1766 fiz1 = _mm256_add_ps(fiz1,tz);
1768 fjx3 = _mm256_add_ps(fjx3,tx);
1769 fjy3 = _mm256_add_ps(fjy3,ty);
1770 fjz3 = _mm256_add_ps(fjz3,tz);
1774 /**************************
1775 * CALCULATE INTERACTIONS *
1776 **************************/
1778 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1781 /* REACTION-FIELD ELECTROSTATICS */
1782 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1784 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1788 fscal = _mm256_and_ps(fscal,cutoff_mask);
1790 /* Calculate temporary vectorial force */
1791 tx = _mm256_mul_ps(fscal,dx21);
1792 ty = _mm256_mul_ps(fscal,dy21);
1793 tz = _mm256_mul_ps(fscal,dz21);
1795 /* Update vectorial force */
1796 fix2 = _mm256_add_ps(fix2,tx);
1797 fiy2 = _mm256_add_ps(fiy2,ty);
1798 fiz2 = _mm256_add_ps(fiz2,tz);
1800 fjx1 = _mm256_add_ps(fjx1,tx);
1801 fjy1 = _mm256_add_ps(fjy1,ty);
1802 fjz1 = _mm256_add_ps(fjz1,tz);
1806 /**************************
1807 * CALCULATE INTERACTIONS *
1808 **************************/
1810 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1813 /* REACTION-FIELD ELECTROSTATICS */
1814 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1816 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1820 fscal = _mm256_and_ps(fscal,cutoff_mask);
1822 /* Calculate temporary vectorial force */
1823 tx = _mm256_mul_ps(fscal,dx22);
1824 ty = _mm256_mul_ps(fscal,dy22);
1825 tz = _mm256_mul_ps(fscal,dz22);
1827 /* Update vectorial force */
1828 fix2 = _mm256_add_ps(fix2,tx);
1829 fiy2 = _mm256_add_ps(fiy2,ty);
1830 fiz2 = _mm256_add_ps(fiz2,tz);
1832 fjx2 = _mm256_add_ps(fjx2,tx);
1833 fjy2 = _mm256_add_ps(fjy2,ty);
1834 fjz2 = _mm256_add_ps(fjz2,tz);
1838 /**************************
1839 * CALCULATE INTERACTIONS *
1840 **************************/
1842 if (gmx_mm256_any_lt(rsq23,rcutoff2))
1845 /* REACTION-FIELD ELECTROSTATICS */
1846 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
1848 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
1852 fscal = _mm256_and_ps(fscal,cutoff_mask);
1854 /* Calculate temporary vectorial force */
1855 tx = _mm256_mul_ps(fscal,dx23);
1856 ty = _mm256_mul_ps(fscal,dy23);
1857 tz = _mm256_mul_ps(fscal,dz23);
1859 /* Update vectorial force */
1860 fix2 = _mm256_add_ps(fix2,tx);
1861 fiy2 = _mm256_add_ps(fiy2,ty);
1862 fiz2 = _mm256_add_ps(fiz2,tz);
1864 fjx3 = _mm256_add_ps(fjx3,tx);
1865 fjy3 = _mm256_add_ps(fjy3,ty);
1866 fjz3 = _mm256_add_ps(fjz3,tz);
1870 /**************************
1871 * CALCULATE INTERACTIONS *
1872 **************************/
1874 if (gmx_mm256_any_lt(rsq31,rcutoff2))
1877 /* REACTION-FIELD ELECTROSTATICS */
1878 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
1880 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
1884 fscal = _mm256_and_ps(fscal,cutoff_mask);
1886 /* Calculate temporary vectorial force */
1887 tx = _mm256_mul_ps(fscal,dx31);
1888 ty = _mm256_mul_ps(fscal,dy31);
1889 tz = _mm256_mul_ps(fscal,dz31);
1891 /* Update vectorial force */
1892 fix3 = _mm256_add_ps(fix3,tx);
1893 fiy3 = _mm256_add_ps(fiy3,ty);
1894 fiz3 = _mm256_add_ps(fiz3,tz);
1896 fjx1 = _mm256_add_ps(fjx1,tx);
1897 fjy1 = _mm256_add_ps(fjy1,ty);
1898 fjz1 = _mm256_add_ps(fjz1,tz);
1902 /**************************
1903 * CALCULATE INTERACTIONS *
1904 **************************/
1906 if (gmx_mm256_any_lt(rsq32,rcutoff2))
1909 /* REACTION-FIELD ELECTROSTATICS */
1910 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
1912 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
1916 fscal = _mm256_and_ps(fscal,cutoff_mask);
1918 /* Calculate temporary vectorial force */
1919 tx = _mm256_mul_ps(fscal,dx32);
1920 ty = _mm256_mul_ps(fscal,dy32);
1921 tz = _mm256_mul_ps(fscal,dz32);
1923 /* Update vectorial force */
1924 fix3 = _mm256_add_ps(fix3,tx);
1925 fiy3 = _mm256_add_ps(fiy3,ty);
1926 fiz3 = _mm256_add_ps(fiz3,tz);
1928 fjx2 = _mm256_add_ps(fjx2,tx);
1929 fjy2 = _mm256_add_ps(fjy2,ty);
1930 fjz2 = _mm256_add_ps(fjz2,tz);
1934 /**************************
1935 * CALCULATE INTERACTIONS *
1936 **************************/
1938 if (gmx_mm256_any_lt(rsq33,rcutoff2))
1941 /* REACTION-FIELD ELECTROSTATICS */
1942 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
1944 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
1948 fscal = _mm256_and_ps(fscal,cutoff_mask);
1950 /* Calculate temporary vectorial force */
1951 tx = _mm256_mul_ps(fscal,dx33);
1952 ty = _mm256_mul_ps(fscal,dy33);
1953 tz = _mm256_mul_ps(fscal,dz33);
1955 /* Update vectorial force */
1956 fix3 = _mm256_add_ps(fix3,tx);
1957 fiy3 = _mm256_add_ps(fiy3,ty);
1958 fiz3 = _mm256_add_ps(fiz3,tz);
1960 fjx3 = _mm256_add_ps(fjx3,tx);
1961 fjy3 = _mm256_add_ps(fjy3,ty);
1962 fjz3 = _mm256_add_ps(fjz3,tz);
1966 fjptrA = f+j_coord_offsetA;
1967 fjptrB = f+j_coord_offsetB;
1968 fjptrC = f+j_coord_offsetC;
1969 fjptrD = f+j_coord_offsetD;
1970 fjptrE = f+j_coord_offsetE;
1971 fjptrF = f+j_coord_offsetF;
1972 fjptrG = f+j_coord_offsetG;
1973 fjptrH = f+j_coord_offsetH;
1975 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1976 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1977 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1979 /* Inner loop uses 329 flops */
1982 if(jidx<j_index_end)
1985 /* Get j neighbor index, and coordinate index */
1986 jnrlistA = jjnr[jidx];
1987 jnrlistB = jjnr[jidx+1];
1988 jnrlistC = jjnr[jidx+2];
1989 jnrlistD = jjnr[jidx+3];
1990 jnrlistE = jjnr[jidx+4];
1991 jnrlistF = jjnr[jidx+5];
1992 jnrlistG = jjnr[jidx+6];
1993 jnrlistH = jjnr[jidx+7];
1994 /* Sign of each element will be negative for non-real atoms.
1995 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1996 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1998 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1999 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
2001 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
2002 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
2003 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
2004 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
2005 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
2006 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
2007 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
2008 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
2009 j_coord_offsetA = DIM*jnrA;
2010 j_coord_offsetB = DIM*jnrB;
2011 j_coord_offsetC = DIM*jnrC;
2012 j_coord_offsetD = DIM*jnrD;
2013 j_coord_offsetE = DIM*jnrE;
2014 j_coord_offsetF = DIM*jnrF;
2015 j_coord_offsetG = DIM*jnrG;
2016 j_coord_offsetH = DIM*jnrH;
2018 /* load j atom coordinates */
2019 gmx_mm256_load_4rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
2020 x+j_coord_offsetC,x+j_coord_offsetD,
2021 x+j_coord_offsetE,x+j_coord_offsetF,
2022 x+j_coord_offsetG,x+j_coord_offsetH,
2023 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
2024 &jy2,&jz2,&jx3,&jy3,&jz3);
2026 /* Calculate displacement vector */
2027 dx00 = _mm256_sub_ps(ix0,jx0);
2028 dy00 = _mm256_sub_ps(iy0,jy0);
2029 dz00 = _mm256_sub_ps(iz0,jz0);
2030 dx11 = _mm256_sub_ps(ix1,jx1);
2031 dy11 = _mm256_sub_ps(iy1,jy1);
2032 dz11 = _mm256_sub_ps(iz1,jz1);
2033 dx12 = _mm256_sub_ps(ix1,jx2);
2034 dy12 = _mm256_sub_ps(iy1,jy2);
2035 dz12 = _mm256_sub_ps(iz1,jz2);
2036 dx13 = _mm256_sub_ps(ix1,jx3);
2037 dy13 = _mm256_sub_ps(iy1,jy3);
2038 dz13 = _mm256_sub_ps(iz1,jz3);
2039 dx21 = _mm256_sub_ps(ix2,jx1);
2040 dy21 = _mm256_sub_ps(iy2,jy1);
2041 dz21 = _mm256_sub_ps(iz2,jz1);
2042 dx22 = _mm256_sub_ps(ix2,jx2);
2043 dy22 = _mm256_sub_ps(iy2,jy2);
2044 dz22 = _mm256_sub_ps(iz2,jz2);
2045 dx23 = _mm256_sub_ps(ix2,jx3);
2046 dy23 = _mm256_sub_ps(iy2,jy3);
2047 dz23 = _mm256_sub_ps(iz2,jz3);
2048 dx31 = _mm256_sub_ps(ix3,jx1);
2049 dy31 = _mm256_sub_ps(iy3,jy1);
2050 dz31 = _mm256_sub_ps(iz3,jz1);
2051 dx32 = _mm256_sub_ps(ix3,jx2);
2052 dy32 = _mm256_sub_ps(iy3,jy2);
2053 dz32 = _mm256_sub_ps(iz3,jz2);
2054 dx33 = _mm256_sub_ps(ix3,jx3);
2055 dy33 = _mm256_sub_ps(iy3,jy3);
2056 dz33 = _mm256_sub_ps(iz3,jz3);
2058 /* Calculate squared distance and things based on it */
2059 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
2060 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
2061 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
2062 rsq13 = gmx_mm256_calc_rsq_ps(dx13,dy13,dz13);
2063 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
2064 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
2065 rsq23 = gmx_mm256_calc_rsq_ps(dx23,dy23,dz23);
2066 rsq31 = gmx_mm256_calc_rsq_ps(dx31,dy31,dz31);
2067 rsq32 = gmx_mm256_calc_rsq_ps(dx32,dy32,dz32);
2068 rsq33 = gmx_mm256_calc_rsq_ps(dx33,dy33,dz33);
2070 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
2071 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
2072 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
2073 rinv13 = gmx_mm256_invsqrt_ps(rsq13);
2074 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
2075 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
2076 rinv23 = gmx_mm256_invsqrt_ps(rsq23);
2077 rinv31 = gmx_mm256_invsqrt_ps(rsq31);
2078 rinv32 = gmx_mm256_invsqrt_ps(rsq32);
2079 rinv33 = gmx_mm256_invsqrt_ps(rsq33);
2081 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
2082 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
2083 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
2084 rinvsq13 = _mm256_mul_ps(rinv13,rinv13);
2085 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
2086 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
2087 rinvsq23 = _mm256_mul_ps(rinv23,rinv23);
2088 rinvsq31 = _mm256_mul_ps(rinv31,rinv31);
2089 rinvsq32 = _mm256_mul_ps(rinv32,rinv32);
2090 rinvsq33 = _mm256_mul_ps(rinv33,rinv33);
2092 fjx0 = _mm256_setzero_ps();
2093 fjy0 = _mm256_setzero_ps();
2094 fjz0 = _mm256_setzero_ps();
2095 fjx1 = _mm256_setzero_ps();
2096 fjy1 = _mm256_setzero_ps();
2097 fjz1 = _mm256_setzero_ps();
2098 fjx2 = _mm256_setzero_ps();
2099 fjy2 = _mm256_setzero_ps();
2100 fjz2 = _mm256_setzero_ps();
2101 fjx3 = _mm256_setzero_ps();
2102 fjy3 = _mm256_setzero_ps();
2103 fjz3 = _mm256_setzero_ps();
2105 /**************************
2106 * CALCULATE INTERACTIONS *
2107 **************************/
2109 if (gmx_mm256_any_lt(rsq00,rcutoff2))
2112 r00 = _mm256_mul_ps(rsq00,rinv00);
2113 r00 = _mm256_andnot_ps(dummy_mask,r00);
2115 /* LENNARD-JONES DISPERSION/REPULSION */
2117 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
2118 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
2119 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
2120 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
2121 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
2123 d = _mm256_sub_ps(r00,rswitch);
2124 d = _mm256_max_ps(d,_mm256_setzero_ps());
2125 d2 = _mm256_mul_ps(d,d);
2126 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)))))));
2128 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
2130 /* Evaluate switch function */
2131 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
2132 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
2133 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2137 fscal = _mm256_and_ps(fscal,cutoff_mask);
2139 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2141 /* Calculate temporary vectorial force */
2142 tx = _mm256_mul_ps(fscal,dx00);
2143 ty = _mm256_mul_ps(fscal,dy00);
2144 tz = _mm256_mul_ps(fscal,dz00);
2146 /* Update vectorial force */
2147 fix0 = _mm256_add_ps(fix0,tx);
2148 fiy0 = _mm256_add_ps(fiy0,ty);
2149 fiz0 = _mm256_add_ps(fiz0,tz);
2151 fjx0 = _mm256_add_ps(fjx0,tx);
2152 fjy0 = _mm256_add_ps(fjy0,ty);
2153 fjz0 = _mm256_add_ps(fjz0,tz);
2157 /**************************
2158 * CALCULATE INTERACTIONS *
2159 **************************/
2161 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2164 /* REACTION-FIELD ELECTROSTATICS */
2165 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2167 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2171 fscal = _mm256_and_ps(fscal,cutoff_mask);
2173 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2175 /* Calculate temporary vectorial force */
2176 tx = _mm256_mul_ps(fscal,dx11);
2177 ty = _mm256_mul_ps(fscal,dy11);
2178 tz = _mm256_mul_ps(fscal,dz11);
2180 /* Update vectorial force */
2181 fix1 = _mm256_add_ps(fix1,tx);
2182 fiy1 = _mm256_add_ps(fiy1,ty);
2183 fiz1 = _mm256_add_ps(fiz1,tz);
2185 fjx1 = _mm256_add_ps(fjx1,tx);
2186 fjy1 = _mm256_add_ps(fjy1,ty);
2187 fjz1 = _mm256_add_ps(fjz1,tz);
2191 /**************************
2192 * CALCULATE INTERACTIONS *
2193 **************************/
2195 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2198 /* REACTION-FIELD ELECTROSTATICS */
2199 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2201 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2205 fscal = _mm256_and_ps(fscal,cutoff_mask);
2207 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2209 /* Calculate temporary vectorial force */
2210 tx = _mm256_mul_ps(fscal,dx12);
2211 ty = _mm256_mul_ps(fscal,dy12);
2212 tz = _mm256_mul_ps(fscal,dz12);
2214 /* Update vectorial force */
2215 fix1 = _mm256_add_ps(fix1,tx);
2216 fiy1 = _mm256_add_ps(fiy1,ty);
2217 fiz1 = _mm256_add_ps(fiz1,tz);
2219 fjx2 = _mm256_add_ps(fjx2,tx);
2220 fjy2 = _mm256_add_ps(fjy2,ty);
2221 fjz2 = _mm256_add_ps(fjz2,tz);
2225 /**************************
2226 * CALCULATE INTERACTIONS *
2227 **************************/
2229 if (gmx_mm256_any_lt(rsq13,rcutoff2))
2232 /* REACTION-FIELD ELECTROSTATICS */
2233 felec = _mm256_mul_ps(qq13,_mm256_sub_ps(_mm256_mul_ps(rinv13,rinvsq13),krf2));
2235 cutoff_mask = _mm256_cmp_ps(rsq13,rcutoff2,_CMP_LT_OQ);
2239 fscal = _mm256_and_ps(fscal,cutoff_mask);
2241 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2243 /* Calculate temporary vectorial force */
2244 tx = _mm256_mul_ps(fscal,dx13);
2245 ty = _mm256_mul_ps(fscal,dy13);
2246 tz = _mm256_mul_ps(fscal,dz13);
2248 /* Update vectorial force */
2249 fix1 = _mm256_add_ps(fix1,tx);
2250 fiy1 = _mm256_add_ps(fiy1,ty);
2251 fiz1 = _mm256_add_ps(fiz1,tz);
2253 fjx3 = _mm256_add_ps(fjx3,tx);
2254 fjy3 = _mm256_add_ps(fjy3,ty);
2255 fjz3 = _mm256_add_ps(fjz3,tz);
2259 /**************************
2260 * CALCULATE INTERACTIONS *
2261 **************************/
2263 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2266 /* REACTION-FIELD ELECTROSTATICS */
2267 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2269 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2273 fscal = _mm256_and_ps(fscal,cutoff_mask);
2275 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2277 /* Calculate temporary vectorial force */
2278 tx = _mm256_mul_ps(fscal,dx21);
2279 ty = _mm256_mul_ps(fscal,dy21);
2280 tz = _mm256_mul_ps(fscal,dz21);
2282 /* Update vectorial force */
2283 fix2 = _mm256_add_ps(fix2,tx);
2284 fiy2 = _mm256_add_ps(fiy2,ty);
2285 fiz2 = _mm256_add_ps(fiz2,tz);
2287 fjx1 = _mm256_add_ps(fjx1,tx);
2288 fjy1 = _mm256_add_ps(fjy1,ty);
2289 fjz1 = _mm256_add_ps(fjz1,tz);
2293 /**************************
2294 * CALCULATE INTERACTIONS *
2295 **************************/
2297 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2300 /* REACTION-FIELD ELECTROSTATICS */
2301 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2303 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2307 fscal = _mm256_and_ps(fscal,cutoff_mask);
2309 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2311 /* Calculate temporary vectorial force */
2312 tx = _mm256_mul_ps(fscal,dx22);
2313 ty = _mm256_mul_ps(fscal,dy22);
2314 tz = _mm256_mul_ps(fscal,dz22);
2316 /* Update vectorial force */
2317 fix2 = _mm256_add_ps(fix2,tx);
2318 fiy2 = _mm256_add_ps(fiy2,ty);
2319 fiz2 = _mm256_add_ps(fiz2,tz);
2321 fjx2 = _mm256_add_ps(fjx2,tx);
2322 fjy2 = _mm256_add_ps(fjy2,ty);
2323 fjz2 = _mm256_add_ps(fjz2,tz);
2327 /**************************
2328 * CALCULATE INTERACTIONS *
2329 **************************/
2331 if (gmx_mm256_any_lt(rsq23,rcutoff2))
2334 /* REACTION-FIELD ELECTROSTATICS */
2335 felec = _mm256_mul_ps(qq23,_mm256_sub_ps(_mm256_mul_ps(rinv23,rinvsq23),krf2));
2337 cutoff_mask = _mm256_cmp_ps(rsq23,rcutoff2,_CMP_LT_OQ);
2341 fscal = _mm256_and_ps(fscal,cutoff_mask);
2343 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2345 /* Calculate temporary vectorial force */
2346 tx = _mm256_mul_ps(fscal,dx23);
2347 ty = _mm256_mul_ps(fscal,dy23);
2348 tz = _mm256_mul_ps(fscal,dz23);
2350 /* Update vectorial force */
2351 fix2 = _mm256_add_ps(fix2,tx);
2352 fiy2 = _mm256_add_ps(fiy2,ty);
2353 fiz2 = _mm256_add_ps(fiz2,tz);
2355 fjx3 = _mm256_add_ps(fjx3,tx);
2356 fjy3 = _mm256_add_ps(fjy3,ty);
2357 fjz3 = _mm256_add_ps(fjz3,tz);
2361 /**************************
2362 * CALCULATE INTERACTIONS *
2363 **************************/
2365 if (gmx_mm256_any_lt(rsq31,rcutoff2))
2368 /* REACTION-FIELD ELECTROSTATICS */
2369 felec = _mm256_mul_ps(qq31,_mm256_sub_ps(_mm256_mul_ps(rinv31,rinvsq31),krf2));
2371 cutoff_mask = _mm256_cmp_ps(rsq31,rcutoff2,_CMP_LT_OQ);
2375 fscal = _mm256_and_ps(fscal,cutoff_mask);
2377 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2379 /* Calculate temporary vectorial force */
2380 tx = _mm256_mul_ps(fscal,dx31);
2381 ty = _mm256_mul_ps(fscal,dy31);
2382 tz = _mm256_mul_ps(fscal,dz31);
2384 /* Update vectorial force */
2385 fix3 = _mm256_add_ps(fix3,tx);
2386 fiy3 = _mm256_add_ps(fiy3,ty);
2387 fiz3 = _mm256_add_ps(fiz3,tz);
2389 fjx1 = _mm256_add_ps(fjx1,tx);
2390 fjy1 = _mm256_add_ps(fjy1,ty);
2391 fjz1 = _mm256_add_ps(fjz1,tz);
2395 /**************************
2396 * CALCULATE INTERACTIONS *
2397 **************************/
2399 if (gmx_mm256_any_lt(rsq32,rcutoff2))
2402 /* REACTION-FIELD ELECTROSTATICS */
2403 felec = _mm256_mul_ps(qq32,_mm256_sub_ps(_mm256_mul_ps(rinv32,rinvsq32),krf2));
2405 cutoff_mask = _mm256_cmp_ps(rsq32,rcutoff2,_CMP_LT_OQ);
2409 fscal = _mm256_and_ps(fscal,cutoff_mask);
2411 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2413 /* Calculate temporary vectorial force */
2414 tx = _mm256_mul_ps(fscal,dx32);
2415 ty = _mm256_mul_ps(fscal,dy32);
2416 tz = _mm256_mul_ps(fscal,dz32);
2418 /* Update vectorial force */
2419 fix3 = _mm256_add_ps(fix3,tx);
2420 fiy3 = _mm256_add_ps(fiy3,ty);
2421 fiz3 = _mm256_add_ps(fiz3,tz);
2423 fjx2 = _mm256_add_ps(fjx2,tx);
2424 fjy2 = _mm256_add_ps(fjy2,ty);
2425 fjz2 = _mm256_add_ps(fjz2,tz);
2429 /**************************
2430 * CALCULATE INTERACTIONS *
2431 **************************/
2433 if (gmx_mm256_any_lt(rsq33,rcutoff2))
2436 /* REACTION-FIELD ELECTROSTATICS */
2437 felec = _mm256_mul_ps(qq33,_mm256_sub_ps(_mm256_mul_ps(rinv33,rinvsq33),krf2));
2439 cutoff_mask = _mm256_cmp_ps(rsq33,rcutoff2,_CMP_LT_OQ);
2443 fscal = _mm256_and_ps(fscal,cutoff_mask);
2445 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2447 /* Calculate temporary vectorial force */
2448 tx = _mm256_mul_ps(fscal,dx33);
2449 ty = _mm256_mul_ps(fscal,dy33);
2450 tz = _mm256_mul_ps(fscal,dz33);
2452 /* Update vectorial force */
2453 fix3 = _mm256_add_ps(fix3,tx);
2454 fiy3 = _mm256_add_ps(fiy3,ty);
2455 fiz3 = _mm256_add_ps(fiz3,tz);
2457 fjx3 = _mm256_add_ps(fjx3,tx);
2458 fjy3 = _mm256_add_ps(fjy3,ty);
2459 fjz3 = _mm256_add_ps(fjz3,tz);
2463 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2464 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2465 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2466 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2467 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2468 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2469 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2470 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2472 gmx_mm256_decrement_4rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2473 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2474 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2476 /* Inner loop uses 330 flops */
2479 /* End of innermost loop */
2481 gmx_mm256_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2482 f+i_coord_offset,fshift+i_shift_offset);
2484 /* Increment number of inner iterations */
2485 inneriter += j_index_end - j_index_start;
2487 /* Outer loop uses 24 flops */
2490 /* Increment number of outer iterations */
2493 /* Update outer/inner flops */
2495 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*330);