2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 "types/simple.h"
49 #include "gmx_math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_256_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_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 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 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
101 __m256 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
102 __m256 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
103 __m256 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
104 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
105 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
106 __m256 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
107 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
108 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
109 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
112 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
115 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
116 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
118 __m128i vfitab_lo,vfitab_hi;
119 __m128i ifour = _mm_set1_epi32(4);
120 __m256 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
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 vftab = kernel_data->table_vdw->data;
147 vftabscale = _mm256_set1_ps(kernel_data->table_vdw->scale);
149 /* Setup water-specific parameters */
150 inr = nlist->iinr[0];
151 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
152 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
153 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
154 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
156 jq0 = _mm256_set1_ps(charge[inr+0]);
157 jq1 = _mm256_set1_ps(charge[inr+1]);
158 jq2 = _mm256_set1_ps(charge[inr+2]);
159 vdwjidx0A = 2*vdwtype[inr+0];
160 qq00 = _mm256_mul_ps(iq0,jq0);
161 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
162 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
163 qq01 = _mm256_mul_ps(iq0,jq1);
164 qq02 = _mm256_mul_ps(iq0,jq2);
165 qq10 = _mm256_mul_ps(iq1,jq0);
166 qq11 = _mm256_mul_ps(iq1,jq1);
167 qq12 = _mm256_mul_ps(iq1,jq2);
168 qq20 = _mm256_mul_ps(iq2,jq0);
169 qq21 = _mm256_mul_ps(iq2,jq1);
170 qq22 = _mm256_mul_ps(iq2,jq2);
172 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
173 rcutoff_scalar = fr->rcoulomb;
174 rcutoff = _mm256_set1_ps(rcutoff_scalar);
175 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
177 /* Avoid stupid compiler warnings */
178 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
191 for(iidx=0;iidx<4*DIM;iidx++)
196 /* Start outer loop over neighborlists */
197 for(iidx=0; iidx<nri; iidx++)
199 /* Load shift vector for this list */
200 i_shift_offset = DIM*shiftidx[iidx];
202 /* Load limits for loop over neighbors */
203 j_index_start = jindex[iidx];
204 j_index_end = jindex[iidx+1];
206 /* Get outer coordinate index */
208 i_coord_offset = DIM*inr;
210 /* Load i particle coords and add shift vector */
211 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
212 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
214 fix0 = _mm256_setzero_ps();
215 fiy0 = _mm256_setzero_ps();
216 fiz0 = _mm256_setzero_ps();
217 fix1 = _mm256_setzero_ps();
218 fiy1 = _mm256_setzero_ps();
219 fiz1 = _mm256_setzero_ps();
220 fix2 = _mm256_setzero_ps();
221 fiy2 = _mm256_setzero_ps();
222 fiz2 = _mm256_setzero_ps();
224 /* Reset potential sums */
225 velecsum = _mm256_setzero_ps();
226 vvdwsum = _mm256_setzero_ps();
228 /* Start inner kernel loop */
229 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
232 /* Get j neighbor index, and coordinate index */
241 j_coord_offsetA = DIM*jnrA;
242 j_coord_offsetB = DIM*jnrB;
243 j_coord_offsetC = DIM*jnrC;
244 j_coord_offsetD = DIM*jnrD;
245 j_coord_offsetE = DIM*jnrE;
246 j_coord_offsetF = DIM*jnrF;
247 j_coord_offsetG = DIM*jnrG;
248 j_coord_offsetH = DIM*jnrH;
250 /* load j atom coordinates */
251 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
252 x+j_coord_offsetC,x+j_coord_offsetD,
253 x+j_coord_offsetE,x+j_coord_offsetF,
254 x+j_coord_offsetG,x+j_coord_offsetH,
255 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
257 /* Calculate displacement vector */
258 dx00 = _mm256_sub_ps(ix0,jx0);
259 dy00 = _mm256_sub_ps(iy0,jy0);
260 dz00 = _mm256_sub_ps(iz0,jz0);
261 dx01 = _mm256_sub_ps(ix0,jx1);
262 dy01 = _mm256_sub_ps(iy0,jy1);
263 dz01 = _mm256_sub_ps(iz0,jz1);
264 dx02 = _mm256_sub_ps(ix0,jx2);
265 dy02 = _mm256_sub_ps(iy0,jy2);
266 dz02 = _mm256_sub_ps(iz0,jz2);
267 dx10 = _mm256_sub_ps(ix1,jx0);
268 dy10 = _mm256_sub_ps(iy1,jy0);
269 dz10 = _mm256_sub_ps(iz1,jz0);
270 dx11 = _mm256_sub_ps(ix1,jx1);
271 dy11 = _mm256_sub_ps(iy1,jy1);
272 dz11 = _mm256_sub_ps(iz1,jz1);
273 dx12 = _mm256_sub_ps(ix1,jx2);
274 dy12 = _mm256_sub_ps(iy1,jy2);
275 dz12 = _mm256_sub_ps(iz1,jz2);
276 dx20 = _mm256_sub_ps(ix2,jx0);
277 dy20 = _mm256_sub_ps(iy2,jy0);
278 dz20 = _mm256_sub_ps(iz2,jz0);
279 dx21 = _mm256_sub_ps(ix2,jx1);
280 dy21 = _mm256_sub_ps(iy2,jy1);
281 dz21 = _mm256_sub_ps(iz2,jz1);
282 dx22 = _mm256_sub_ps(ix2,jx2);
283 dy22 = _mm256_sub_ps(iy2,jy2);
284 dz22 = _mm256_sub_ps(iz2,jz2);
286 /* Calculate squared distance and things based on it */
287 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
288 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
289 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
290 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
291 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
292 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
293 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
294 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
295 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
297 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
298 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
299 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
300 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
301 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
302 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
303 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
304 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
305 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
307 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
308 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
309 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
310 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
311 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
312 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
313 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
314 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
315 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
317 fjx0 = _mm256_setzero_ps();
318 fjy0 = _mm256_setzero_ps();
319 fjz0 = _mm256_setzero_ps();
320 fjx1 = _mm256_setzero_ps();
321 fjy1 = _mm256_setzero_ps();
322 fjz1 = _mm256_setzero_ps();
323 fjx2 = _mm256_setzero_ps();
324 fjy2 = _mm256_setzero_ps();
325 fjz2 = _mm256_setzero_ps();
327 /**************************
328 * CALCULATE INTERACTIONS *
329 **************************/
331 if (gmx_mm256_any_lt(rsq00,rcutoff2))
334 r00 = _mm256_mul_ps(rsq00,rinv00);
336 /* Calculate table index by multiplying r with table scale and truncate to integer */
337 rt = _mm256_mul_ps(r00,vftabscale);
338 vfitab = _mm256_cvttps_epi32(rt);
339 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
340 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
341 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
342 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
343 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
344 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
346 /* REACTION-FIELD ELECTROSTATICS */
347 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
348 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
350 /* CUBIC SPLINE TABLE DISPERSION */
351 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
352 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
353 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
354 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
355 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
356 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
357 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
358 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
359 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
360 Heps = _mm256_mul_ps(vfeps,H);
361 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
362 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
363 vvdw6 = _mm256_mul_ps(c6_00,VV);
364 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
365 fvdw6 = _mm256_mul_ps(c6_00,FF);
367 /* CUBIC SPLINE TABLE REPULSION */
368 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
369 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
370 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
371 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
372 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
373 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
374 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
375 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
376 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
377 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
378 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
379 Heps = _mm256_mul_ps(vfeps,H);
380 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
381 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
382 vvdw12 = _mm256_mul_ps(c12_00,VV);
383 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
384 fvdw12 = _mm256_mul_ps(c12_00,FF);
385 vvdw = _mm256_add_ps(vvdw12,vvdw6);
386 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
388 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
390 /* Update potential sum for this i atom from the interaction with this j atom. */
391 velec = _mm256_and_ps(velec,cutoff_mask);
392 velecsum = _mm256_add_ps(velecsum,velec);
393 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
394 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
396 fscal = _mm256_add_ps(felec,fvdw);
398 fscal = _mm256_and_ps(fscal,cutoff_mask);
400 /* Calculate temporary vectorial force */
401 tx = _mm256_mul_ps(fscal,dx00);
402 ty = _mm256_mul_ps(fscal,dy00);
403 tz = _mm256_mul_ps(fscal,dz00);
405 /* Update vectorial force */
406 fix0 = _mm256_add_ps(fix0,tx);
407 fiy0 = _mm256_add_ps(fiy0,ty);
408 fiz0 = _mm256_add_ps(fiz0,tz);
410 fjx0 = _mm256_add_ps(fjx0,tx);
411 fjy0 = _mm256_add_ps(fjy0,ty);
412 fjz0 = _mm256_add_ps(fjz0,tz);
416 /**************************
417 * CALCULATE INTERACTIONS *
418 **************************/
420 if (gmx_mm256_any_lt(rsq01,rcutoff2))
423 /* REACTION-FIELD ELECTROSTATICS */
424 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
425 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
427 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
429 /* Update potential sum for this i atom from the interaction with this j atom. */
430 velec = _mm256_and_ps(velec,cutoff_mask);
431 velecsum = _mm256_add_ps(velecsum,velec);
435 fscal = _mm256_and_ps(fscal,cutoff_mask);
437 /* Calculate temporary vectorial force */
438 tx = _mm256_mul_ps(fscal,dx01);
439 ty = _mm256_mul_ps(fscal,dy01);
440 tz = _mm256_mul_ps(fscal,dz01);
442 /* Update vectorial force */
443 fix0 = _mm256_add_ps(fix0,tx);
444 fiy0 = _mm256_add_ps(fiy0,ty);
445 fiz0 = _mm256_add_ps(fiz0,tz);
447 fjx1 = _mm256_add_ps(fjx1,tx);
448 fjy1 = _mm256_add_ps(fjy1,ty);
449 fjz1 = _mm256_add_ps(fjz1,tz);
453 /**************************
454 * CALCULATE INTERACTIONS *
455 **************************/
457 if (gmx_mm256_any_lt(rsq02,rcutoff2))
460 /* REACTION-FIELD ELECTROSTATICS */
461 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
462 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
464 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
466 /* Update potential sum for this i atom from the interaction with this j atom. */
467 velec = _mm256_and_ps(velec,cutoff_mask);
468 velecsum = _mm256_add_ps(velecsum,velec);
472 fscal = _mm256_and_ps(fscal,cutoff_mask);
474 /* Calculate temporary vectorial force */
475 tx = _mm256_mul_ps(fscal,dx02);
476 ty = _mm256_mul_ps(fscal,dy02);
477 tz = _mm256_mul_ps(fscal,dz02);
479 /* Update vectorial force */
480 fix0 = _mm256_add_ps(fix0,tx);
481 fiy0 = _mm256_add_ps(fiy0,ty);
482 fiz0 = _mm256_add_ps(fiz0,tz);
484 fjx2 = _mm256_add_ps(fjx2,tx);
485 fjy2 = _mm256_add_ps(fjy2,ty);
486 fjz2 = _mm256_add_ps(fjz2,tz);
490 /**************************
491 * CALCULATE INTERACTIONS *
492 **************************/
494 if (gmx_mm256_any_lt(rsq10,rcutoff2))
497 /* REACTION-FIELD ELECTROSTATICS */
498 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
499 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
501 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
503 /* Update potential sum for this i atom from the interaction with this j atom. */
504 velec = _mm256_and_ps(velec,cutoff_mask);
505 velecsum = _mm256_add_ps(velecsum,velec);
509 fscal = _mm256_and_ps(fscal,cutoff_mask);
511 /* Calculate temporary vectorial force */
512 tx = _mm256_mul_ps(fscal,dx10);
513 ty = _mm256_mul_ps(fscal,dy10);
514 tz = _mm256_mul_ps(fscal,dz10);
516 /* Update vectorial force */
517 fix1 = _mm256_add_ps(fix1,tx);
518 fiy1 = _mm256_add_ps(fiy1,ty);
519 fiz1 = _mm256_add_ps(fiz1,tz);
521 fjx0 = _mm256_add_ps(fjx0,tx);
522 fjy0 = _mm256_add_ps(fjy0,ty);
523 fjz0 = _mm256_add_ps(fjz0,tz);
527 /**************************
528 * CALCULATE INTERACTIONS *
529 **************************/
531 if (gmx_mm256_any_lt(rsq11,rcutoff2))
534 /* REACTION-FIELD ELECTROSTATICS */
535 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
536 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
538 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
540 /* Update potential sum for this i atom from the interaction with this j atom. */
541 velec = _mm256_and_ps(velec,cutoff_mask);
542 velecsum = _mm256_add_ps(velecsum,velec);
546 fscal = _mm256_and_ps(fscal,cutoff_mask);
548 /* Calculate temporary vectorial force */
549 tx = _mm256_mul_ps(fscal,dx11);
550 ty = _mm256_mul_ps(fscal,dy11);
551 tz = _mm256_mul_ps(fscal,dz11);
553 /* Update vectorial force */
554 fix1 = _mm256_add_ps(fix1,tx);
555 fiy1 = _mm256_add_ps(fiy1,ty);
556 fiz1 = _mm256_add_ps(fiz1,tz);
558 fjx1 = _mm256_add_ps(fjx1,tx);
559 fjy1 = _mm256_add_ps(fjy1,ty);
560 fjz1 = _mm256_add_ps(fjz1,tz);
564 /**************************
565 * CALCULATE INTERACTIONS *
566 **************************/
568 if (gmx_mm256_any_lt(rsq12,rcutoff2))
571 /* REACTION-FIELD ELECTROSTATICS */
572 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
573 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
575 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
577 /* Update potential sum for this i atom from the interaction with this j atom. */
578 velec = _mm256_and_ps(velec,cutoff_mask);
579 velecsum = _mm256_add_ps(velecsum,velec);
583 fscal = _mm256_and_ps(fscal,cutoff_mask);
585 /* Calculate temporary vectorial force */
586 tx = _mm256_mul_ps(fscal,dx12);
587 ty = _mm256_mul_ps(fscal,dy12);
588 tz = _mm256_mul_ps(fscal,dz12);
590 /* Update vectorial force */
591 fix1 = _mm256_add_ps(fix1,tx);
592 fiy1 = _mm256_add_ps(fiy1,ty);
593 fiz1 = _mm256_add_ps(fiz1,tz);
595 fjx2 = _mm256_add_ps(fjx2,tx);
596 fjy2 = _mm256_add_ps(fjy2,ty);
597 fjz2 = _mm256_add_ps(fjz2,tz);
601 /**************************
602 * CALCULATE INTERACTIONS *
603 **************************/
605 if (gmx_mm256_any_lt(rsq20,rcutoff2))
608 /* REACTION-FIELD ELECTROSTATICS */
609 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
610 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
612 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
614 /* Update potential sum for this i atom from the interaction with this j atom. */
615 velec = _mm256_and_ps(velec,cutoff_mask);
616 velecsum = _mm256_add_ps(velecsum,velec);
620 fscal = _mm256_and_ps(fscal,cutoff_mask);
622 /* Calculate temporary vectorial force */
623 tx = _mm256_mul_ps(fscal,dx20);
624 ty = _mm256_mul_ps(fscal,dy20);
625 tz = _mm256_mul_ps(fscal,dz20);
627 /* Update vectorial force */
628 fix2 = _mm256_add_ps(fix2,tx);
629 fiy2 = _mm256_add_ps(fiy2,ty);
630 fiz2 = _mm256_add_ps(fiz2,tz);
632 fjx0 = _mm256_add_ps(fjx0,tx);
633 fjy0 = _mm256_add_ps(fjy0,ty);
634 fjz0 = _mm256_add_ps(fjz0,tz);
638 /**************************
639 * CALCULATE INTERACTIONS *
640 **************************/
642 if (gmx_mm256_any_lt(rsq21,rcutoff2))
645 /* REACTION-FIELD ELECTROSTATICS */
646 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
647 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
649 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
651 /* Update potential sum for this i atom from the interaction with this j atom. */
652 velec = _mm256_and_ps(velec,cutoff_mask);
653 velecsum = _mm256_add_ps(velecsum,velec);
657 fscal = _mm256_and_ps(fscal,cutoff_mask);
659 /* Calculate temporary vectorial force */
660 tx = _mm256_mul_ps(fscal,dx21);
661 ty = _mm256_mul_ps(fscal,dy21);
662 tz = _mm256_mul_ps(fscal,dz21);
664 /* Update vectorial force */
665 fix2 = _mm256_add_ps(fix2,tx);
666 fiy2 = _mm256_add_ps(fiy2,ty);
667 fiz2 = _mm256_add_ps(fiz2,tz);
669 fjx1 = _mm256_add_ps(fjx1,tx);
670 fjy1 = _mm256_add_ps(fjy1,ty);
671 fjz1 = _mm256_add_ps(fjz1,tz);
675 /**************************
676 * CALCULATE INTERACTIONS *
677 **************************/
679 if (gmx_mm256_any_lt(rsq22,rcutoff2))
682 /* REACTION-FIELD ELECTROSTATICS */
683 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
684 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
686 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
688 /* Update potential sum for this i atom from the interaction with this j atom. */
689 velec = _mm256_and_ps(velec,cutoff_mask);
690 velecsum = _mm256_add_ps(velecsum,velec);
694 fscal = _mm256_and_ps(fscal,cutoff_mask);
696 /* Calculate temporary vectorial force */
697 tx = _mm256_mul_ps(fscal,dx22);
698 ty = _mm256_mul_ps(fscal,dy22);
699 tz = _mm256_mul_ps(fscal,dz22);
701 /* Update vectorial force */
702 fix2 = _mm256_add_ps(fix2,tx);
703 fiy2 = _mm256_add_ps(fiy2,ty);
704 fiz2 = _mm256_add_ps(fiz2,tz);
706 fjx2 = _mm256_add_ps(fjx2,tx);
707 fjy2 = _mm256_add_ps(fjy2,ty);
708 fjz2 = _mm256_add_ps(fjz2,tz);
712 fjptrA = f+j_coord_offsetA;
713 fjptrB = f+j_coord_offsetB;
714 fjptrC = f+j_coord_offsetC;
715 fjptrD = f+j_coord_offsetD;
716 fjptrE = f+j_coord_offsetE;
717 fjptrF = f+j_coord_offsetF;
718 fjptrG = f+j_coord_offsetG;
719 fjptrH = f+j_coord_offsetH;
721 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
722 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
724 /* Inner loop uses 360 flops */
730 /* Get j neighbor index, and coordinate index */
731 jnrlistA = jjnr[jidx];
732 jnrlistB = jjnr[jidx+1];
733 jnrlistC = jjnr[jidx+2];
734 jnrlistD = jjnr[jidx+3];
735 jnrlistE = jjnr[jidx+4];
736 jnrlistF = jjnr[jidx+5];
737 jnrlistG = jjnr[jidx+6];
738 jnrlistH = jjnr[jidx+7];
739 /* Sign of each element will be negative for non-real atoms.
740 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
741 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
743 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
744 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
746 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
747 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
748 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
749 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
750 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
751 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
752 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
753 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
754 j_coord_offsetA = DIM*jnrA;
755 j_coord_offsetB = DIM*jnrB;
756 j_coord_offsetC = DIM*jnrC;
757 j_coord_offsetD = DIM*jnrD;
758 j_coord_offsetE = DIM*jnrE;
759 j_coord_offsetF = DIM*jnrF;
760 j_coord_offsetG = DIM*jnrG;
761 j_coord_offsetH = DIM*jnrH;
763 /* load j atom coordinates */
764 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
765 x+j_coord_offsetC,x+j_coord_offsetD,
766 x+j_coord_offsetE,x+j_coord_offsetF,
767 x+j_coord_offsetG,x+j_coord_offsetH,
768 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
770 /* Calculate displacement vector */
771 dx00 = _mm256_sub_ps(ix0,jx0);
772 dy00 = _mm256_sub_ps(iy0,jy0);
773 dz00 = _mm256_sub_ps(iz0,jz0);
774 dx01 = _mm256_sub_ps(ix0,jx1);
775 dy01 = _mm256_sub_ps(iy0,jy1);
776 dz01 = _mm256_sub_ps(iz0,jz1);
777 dx02 = _mm256_sub_ps(ix0,jx2);
778 dy02 = _mm256_sub_ps(iy0,jy2);
779 dz02 = _mm256_sub_ps(iz0,jz2);
780 dx10 = _mm256_sub_ps(ix1,jx0);
781 dy10 = _mm256_sub_ps(iy1,jy0);
782 dz10 = _mm256_sub_ps(iz1,jz0);
783 dx11 = _mm256_sub_ps(ix1,jx1);
784 dy11 = _mm256_sub_ps(iy1,jy1);
785 dz11 = _mm256_sub_ps(iz1,jz1);
786 dx12 = _mm256_sub_ps(ix1,jx2);
787 dy12 = _mm256_sub_ps(iy1,jy2);
788 dz12 = _mm256_sub_ps(iz1,jz2);
789 dx20 = _mm256_sub_ps(ix2,jx0);
790 dy20 = _mm256_sub_ps(iy2,jy0);
791 dz20 = _mm256_sub_ps(iz2,jz0);
792 dx21 = _mm256_sub_ps(ix2,jx1);
793 dy21 = _mm256_sub_ps(iy2,jy1);
794 dz21 = _mm256_sub_ps(iz2,jz1);
795 dx22 = _mm256_sub_ps(ix2,jx2);
796 dy22 = _mm256_sub_ps(iy2,jy2);
797 dz22 = _mm256_sub_ps(iz2,jz2);
799 /* Calculate squared distance and things based on it */
800 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
801 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
802 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
803 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
804 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
805 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
806 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
807 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
808 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
810 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
811 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
812 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
813 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
814 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
815 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
816 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
817 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
818 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
820 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
821 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
822 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
823 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
824 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
825 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
826 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
827 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
828 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
830 fjx0 = _mm256_setzero_ps();
831 fjy0 = _mm256_setzero_ps();
832 fjz0 = _mm256_setzero_ps();
833 fjx1 = _mm256_setzero_ps();
834 fjy1 = _mm256_setzero_ps();
835 fjz1 = _mm256_setzero_ps();
836 fjx2 = _mm256_setzero_ps();
837 fjy2 = _mm256_setzero_ps();
838 fjz2 = _mm256_setzero_ps();
840 /**************************
841 * CALCULATE INTERACTIONS *
842 **************************/
844 if (gmx_mm256_any_lt(rsq00,rcutoff2))
847 r00 = _mm256_mul_ps(rsq00,rinv00);
848 r00 = _mm256_andnot_ps(dummy_mask,r00);
850 /* Calculate table index by multiplying r with table scale and truncate to integer */
851 rt = _mm256_mul_ps(r00,vftabscale);
852 vfitab = _mm256_cvttps_epi32(rt);
853 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
854 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
855 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
856 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
857 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
858 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
860 /* REACTION-FIELD ELECTROSTATICS */
861 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
862 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
864 /* CUBIC SPLINE TABLE DISPERSION */
865 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
866 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
867 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
868 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
869 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
870 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
871 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
872 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
873 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
874 Heps = _mm256_mul_ps(vfeps,H);
875 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
876 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
877 vvdw6 = _mm256_mul_ps(c6_00,VV);
878 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
879 fvdw6 = _mm256_mul_ps(c6_00,FF);
881 /* CUBIC SPLINE TABLE REPULSION */
882 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
883 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
884 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
885 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
886 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
887 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
888 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
889 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
890 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
891 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
892 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
893 Heps = _mm256_mul_ps(vfeps,H);
894 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
895 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
896 vvdw12 = _mm256_mul_ps(c12_00,VV);
897 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
898 fvdw12 = _mm256_mul_ps(c12_00,FF);
899 vvdw = _mm256_add_ps(vvdw12,vvdw6);
900 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
902 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
904 /* Update potential sum for this i atom from the interaction with this j atom. */
905 velec = _mm256_and_ps(velec,cutoff_mask);
906 velec = _mm256_andnot_ps(dummy_mask,velec);
907 velecsum = _mm256_add_ps(velecsum,velec);
908 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
909 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
910 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
912 fscal = _mm256_add_ps(felec,fvdw);
914 fscal = _mm256_and_ps(fscal,cutoff_mask);
916 fscal = _mm256_andnot_ps(dummy_mask,fscal);
918 /* Calculate temporary vectorial force */
919 tx = _mm256_mul_ps(fscal,dx00);
920 ty = _mm256_mul_ps(fscal,dy00);
921 tz = _mm256_mul_ps(fscal,dz00);
923 /* Update vectorial force */
924 fix0 = _mm256_add_ps(fix0,tx);
925 fiy0 = _mm256_add_ps(fiy0,ty);
926 fiz0 = _mm256_add_ps(fiz0,tz);
928 fjx0 = _mm256_add_ps(fjx0,tx);
929 fjy0 = _mm256_add_ps(fjy0,ty);
930 fjz0 = _mm256_add_ps(fjz0,tz);
934 /**************************
935 * CALCULATE INTERACTIONS *
936 **************************/
938 if (gmx_mm256_any_lt(rsq01,rcutoff2))
941 /* REACTION-FIELD ELECTROSTATICS */
942 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
943 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
945 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
947 /* Update potential sum for this i atom from the interaction with this j atom. */
948 velec = _mm256_and_ps(velec,cutoff_mask);
949 velec = _mm256_andnot_ps(dummy_mask,velec);
950 velecsum = _mm256_add_ps(velecsum,velec);
954 fscal = _mm256_and_ps(fscal,cutoff_mask);
956 fscal = _mm256_andnot_ps(dummy_mask,fscal);
958 /* Calculate temporary vectorial force */
959 tx = _mm256_mul_ps(fscal,dx01);
960 ty = _mm256_mul_ps(fscal,dy01);
961 tz = _mm256_mul_ps(fscal,dz01);
963 /* Update vectorial force */
964 fix0 = _mm256_add_ps(fix0,tx);
965 fiy0 = _mm256_add_ps(fiy0,ty);
966 fiz0 = _mm256_add_ps(fiz0,tz);
968 fjx1 = _mm256_add_ps(fjx1,tx);
969 fjy1 = _mm256_add_ps(fjy1,ty);
970 fjz1 = _mm256_add_ps(fjz1,tz);
974 /**************************
975 * CALCULATE INTERACTIONS *
976 **************************/
978 if (gmx_mm256_any_lt(rsq02,rcutoff2))
981 /* REACTION-FIELD ELECTROSTATICS */
982 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
983 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
985 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
987 /* Update potential sum for this i atom from the interaction with this j atom. */
988 velec = _mm256_and_ps(velec,cutoff_mask);
989 velec = _mm256_andnot_ps(dummy_mask,velec);
990 velecsum = _mm256_add_ps(velecsum,velec);
994 fscal = _mm256_and_ps(fscal,cutoff_mask);
996 fscal = _mm256_andnot_ps(dummy_mask,fscal);
998 /* Calculate temporary vectorial force */
999 tx = _mm256_mul_ps(fscal,dx02);
1000 ty = _mm256_mul_ps(fscal,dy02);
1001 tz = _mm256_mul_ps(fscal,dz02);
1003 /* Update vectorial force */
1004 fix0 = _mm256_add_ps(fix0,tx);
1005 fiy0 = _mm256_add_ps(fiy0,ty);
1006 fiz0 = _mm256_add_ps(fiz0,tz);
1008 fjx2 = _mm256_add_ps(fjx2,tx);
1009 fjy2 = _mm256_add_ps(fjy2,ty);
1010 fjz2 = _mm256_add_ps(fjz2,tz);
1014 /**************************
1015 * CALCULATE INTERACTIONS *
1016 **************************/
1018 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1021 /* REACTION-FIELD ELECTROSTATICS */
1022 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
1023 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1025 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1027 /* Update potential sum for this i atom from the interaction with this j atom. */
1028 velec = _mm256_and_ps(velec,cutoff_mask);
1029 velec = _mm256_andnot_ps(dummy_mask,velec);
1030 velecsum = _mm256_add_ps(velecsum,velec);
1034 fscal = _mm256_and_ps(fscal,cutoff_mask);
1036 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1038 /* Calculate temporary vectorial force */
1039 tx = _mm256_mul_ps(fscal,dx10);
1040 ty = _mm256_mul_ps(fscal,dy10);
1041 tz = _mm256_mul_ps(fscal,dz10);
1043 /* Update vectorial force */
1044 fix1 = _mm256_add_ps(fix1,tx);
1045 fiy1 = _mm256_add_ps(fiy1,ty);
1046 fiz1 = _mm256_add_ps(fiz1,tz);
1048 fjx0 = _mm256_add_ps(fjx0,tx);
1049 fjy0 = _mm256_add_ps(fjy0,ty);
1050 fjz0 = _mm256_add_ps(fjz0,tz);
1054 /**************************
1055 * CALCULATE INTERACTIONS *
1056 **************************/
1058 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1061 /* REACTION-FIELD ELECTROSTATICS */
1062 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
1063 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1065 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1067 /* Update potential sum for this i atom from the interaction with this j atom. */
1068 velec = _mm256_and_ps(velec,cutoff_mask);
1069 velec = _mm256_andnot_ps(dummy_mask,velec);
1070 velecsum = _mm256_add_ps(velecsum,velec);
1074 fscal = _mm256_and_ps(fscal,cutoff_mask);
1076 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1078 /* Calculate temporary vectorial force */
1079 tx = _mm256_mul_ps(fscal,dx11);
1080 ty = _mm256_mul_ps(fscal,dy11);
1081 tz = _mm256_mul_ps(fscal,dz11);
1083 /* Update vectorial force */
1084 fix1 = _mm256_add_ps(fix1,tx);
1085 fiy1 = _mm256_add_ps(fiy1,ty);
1086 fiz1 = _mm256_add_ps(fiz1,tz);
1088 fjx1 = _mm256_add_ps(fjx1,tx);
1089 fjy1 = _mm256_add_ps(fjy1,ty);
1090 fjz1 = _mm256_add_ps(fjz1,tz);
1094 /**************************
1095 * CALCULATE INTERACTIONS *
1096 **************************/
1098 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1101 /* REACTION-FIELD ELECTROSTATICS */
1102 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
1103 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1105 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1107 /* Update potential sum for this i atom from the interaction with this j atom. */
1108 velec = _mm256_and_ps(velec,cutoff_mask);
1109 velec = _mm256_andnot_ps(dummy_mask,velec);
1110 velecsum = _mm256_add_ps(velecsum,velec);
1114 fscal = _mm256_and_ps(fscal,cutoff_mask);
1116 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1118 /* Calculate temporary vectorial force */
1119 tx = _mm256_mul_ps(fscal,dx12);
1120 ty = _mm256_mul_ps(fscal,dy12);
1121 tz = _mm256_mul_ps(fscal,dz12);
1123 /* Update vectorial force */
1124 fix1 = _mm256_add_ps(fix1,tx);
1125 fiy1 = _mm256_add_ps(fiy1,ty);
1126 fiz1 = _mm256_add_ps(fiz1,tz);
1128 fjx2 = _mm256_add_ps(fjx2,tx);
1129 fjy2 = _mm256_add_ps(fjy2,ty);
1130 fjz2 = _mm256_add_ps(fjz2,tz);
1134 /**************************
1135 * CALCULATE INTERACTIONS *
1136 **************************/
1138 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1141 /* REACTION-FIELD ELECTROSTATICS */
1142 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
1143 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1145 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1147 /* Update potential sum for this i atom from the interaction with this j atom. */
1148 velec = _mm256_and_ps(velec,cutoff_mask);
1149 velec = _mm256_andnot_ps(dummy_mask,velec);
1150 velecsum = _mm256_add_ps(velecsum,velec);
1154 fscal = _mm256_and_ps(fscal,cutoff_mask);
1156 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1158 /* Calculate temporary vectorial force */
1159 tx = _mm256_mul_ps(fscal,dx20);
1160 ty = _mm256_mul_ps(fscal,dy20);
1161 tz = _mm256_mul_ps(fscal,dz20);
1163 /* Update vectorial force */
1164 fix2 = _mm256_add_ps(fix2,tx);
1165 fiy2 = _mm256_add_ps(fiy2,ty);
1166 fiz2 = _mm256_add_ps(fiz2,tz);
1168 fjx0 = _mm256_add_ps(fjx0,tx);
1169 fjy0 = _mm256_add_ps(fjy0,ty);
1170 fjz0 = _mm256_add_ps(fjz0,tz);
1174 /**************************
1175 * CALCULATE INTERACTIONS *
1176 **************************/
1178 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1181 /* REACTION-FIELD ELECTROSTATICS */
1182 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1183 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1185 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1187 /* Update potential sum for this i atom from the interaction with this j atom. */
1188 velec = _mm256_and_ps(velec,cutoff_mask);
1189 velec = _mm256_andnot_ps(dummy_mask,velec);
1190 velecsum = _mm256_add_ps(velecsum,velec);
1194 fscal = _mm256_and_ps(fscal,cutoff_mask);
1196 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1198 /* Calculate temporary vectorial force */
1199 tx = _mm256_mul_ps(fscal,dx21);
1200 ty = _mm256_mul_ps(fscal,dy21);
1201 tz = _mm256_mul_ps(fscal,dz21);
1203 /* Update vectorial force */
1204 fix2 = _mm256_add_ps(fix2,tx);
1205 fiy2 = _mm256_add_ps(fiy2,ty);
1206 fiz2 = _mm256_add_ps(fiz2,tz);
1208 fjx1 = _mm256_add_ps(fjx1,tx);
1209 fjy1 = _mm256_add_ps(fjy1,ty);
1210 fjz1 = _mm256_add_ps(fjz1,tz);
1214 /**************************
1215 * CALCULATE INTERACTIONS *
1216 **************************/
1218 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1221 /* REACTION-FIELD ELECTROSTATICS */
1222 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1223 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1225 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1227 /* Update potential sum for this i atom from the interaction with this j atom. */
1228 velec = _mm256_and_ps(velec,cutoff_mask);
1229 velec = _mm256_andnot_ps(dummy_mask,velec);
1230 velecsum = _mm256_add_ps(velecsum,velec);
1234 fscal = _mm256_and_ps(fscal,cutoff_mask);
1236 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1238 /* Calculate temporary vectorial force */
1239 tx = _mm256_mul_ps(fscal,dx22);
1240 ty = _mm256_mul_ps(fscal,dy22);
1241 tz = _mm256_mul_ps(fscal,dz22);
1243 /* Update vectorial force */
1244 fix2 = _mm256_add_ps(fix2,tx);
1245 fiy2 = _mm256_add_ps(fiy2,ty);
1246 fiz2 = _mm256_add_ps(fiz2,tz);
1248 fjx2 = _mm256_add_ps(fjx2,tx);
1249 fjy2 = _mm256_add_ps(fjy2,ty);
1250 fjz2 = _mm256_add_ps(fjz2,tz);
1254 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1255 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1256 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1257 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1258 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1259 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1260 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1261 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1263 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1264 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1266 /* Inner loop uses 361 flops */
1269 /* End of innermost loop */
1271 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1272 f+i_coord_offset,fshift+i_shift_offset);
1275 /* Update potential energies */
1276 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1277 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1279 /* Increment number of inner iterations */
1280 inneriter += j_index_end - j_index_start;
1282 /* Outer loop uses 20 flops */
1285 /* Increment number of outer iterations */
1288 /* Update outer/inner flops */
1290 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*361);
1293 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1294 * Electrostatics interaction: ReactionField
1295 * VdW interaction: CubicSplineTable
1296 * Geometry: Water3-Water3
1297 * Calculate force/pot: Force
1300 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1301 (t_nblist * gmx_restrict nlist,
1302 rvec * gmx_restrict xx,
1303 rvec * gmx_restrict ff,
1304 t_forcerec * gmx_restrict fr,
1305 t_mdatoms * gmx_restrict mdatoms,
1306 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1307 t_nrnb * gmx_restrict nrnb)
1309 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1310 * just 0 for non-waters.
1311 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1312 * jnr indices corresponding to data put in the four positions in the SIMD register.
1314 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1315 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1316 int jnrA,jnrB,jnrC,jnrD;
1317 int jnrE,jnrF,jnrG,jnrH;
1318 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1319 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1320 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1321 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1322 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1323 real rcutoff_scalar;
1324 real *shiftvec,*fshift,*x,*f;
1325 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1326 real scratch[4*DIM];
1327 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1328 real * vdwioffsetptr0;
1329 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1330 real * vdwioffsetptr1;
1331 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1332 real * vdwioffsetptr2;
1333 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1334 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1335 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1336 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1337 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1338 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1339 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1340 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1341 __m256 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1342 __m256 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1343 __m256 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1344 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1345 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1346 __m256 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1347 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1348 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1349 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1352 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1355 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1356 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1358 __m128i vfitab_lo,vfitab_hi;
1359 __m128i ifour = _mm_set1_epi32(4);
1360 __m256 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
1362 __m256 dummy_mask,cutoff_mask;
1363 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1364 __m256 one = _mm256_set1_ps(1.0);
1365 __m256 two = _mm256_set1_ps(2.0);
1371 jindex = nlist->jindex;
1373 shiftidx = nlist->shift;
1375 shiftvec = fr->shift_vec[0];
1376 fshift = fr->fshift[0];
1377 facel = _mm256_set1_ps(fr->epsfac);
1378 charge = mdatoms->chargeA;
1379 krf = _mm256_set1_ps(fr->ic->k_rf);
1380 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1381 crf = _mm256_set1_ps(fr->ic->c_rf);
1382 nvdwtype = fr->ntype;
1383 vdwparam = fr->nbfp;
1384 vdwtype = mdatoms->typeA;
1386 vftab = kernel_data->table_vdw->data;
1387 vftabscale = _mm256_set1_ps(kernel_data->table_vdw->scale);
1389 /* Setup water-specific parameters */
1390 inr = nlist->iinr[0];
1391 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
1392 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1393 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1394 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1396 jq0 = _mm256_set1_ps(charge[inr+0]);
1397 jq1 = _mm256_set1_ps(charge[inr+1]);
1398 jq2 = _mm256_set1_ps(charge[inr+2]);
1399 vdwjidx0A = 2*vdwtype[inr+0];
1400 qq00 = _mm256_mul_ps(iq0,jq0);
1401 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1402 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1403 qq01 = _mm256_mul_ps(iq0,jq1);
1404 qq02 = _mm256_mul_ps(iq0,jq2);
1405 qq10 = _mm256_mul_ps(iq1,jq0);
1406 qq11 = _mm256_mul_ps(iq1,jq1);
1407 qq12 = _mm256_mul_ps(iq1,jq2);
1408 qq20 = _mm256_mul_ps(iq2,jq0);
1409 qq21 = _mm256_mul_ps(iq2,jq1);
1410 qq22 = _mm256_mul_ps(iq2,jq2);
1412 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1413 rcutoff_scalar = fr->rcoulomb;
1414 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1415 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1417 /* Avoid stupid compiler warnings */
1418 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1419 j_coord_offsetA = 0;
1420 j_coord_offsetB = 0;
1421 j_coord_offsetC = 0;
1422 j_coord_offsetD = 0;
1423 j_coord_offsetE = 0;
1424 j_coord_offsetF = 0;
1425 j_coord_offsetG = 0;
1426 j_coord_offsetH = 0;
1431 for(iidx=0;iidx<4*DIM;iidx++)
1433 scratch[iidx] = 0.0;
1436 /* Start outer loop over neighborlists */
1437 for(iidx=0; iidx<nri; iidx++)
1439 /* Load shift vector for this list */
1440 i_shift_offset = DIM*shiftidx[iidx];
1442 /* Load limits for loop over neighbors */
1443 j_index_start = jindex[iidx];
1444 j_index_end = jindex[iidx+1];
1446 /* Get outer coordinate index */
1448 i_coord_offset = DIM*inr;
1450 /* Load i particle coords and add shift vector */
1451 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1452 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1454 fix0 = _mm256_setzero_ps();
1455 fiy0 = _mm256_setzero_ps();
1456 fiz0 = _mm256_setzero_ps();
1457 fix1 = _mm256_setzero_ps();
1458 fiy1 = _mm256_setzero_ps();
1459 fiz1 = _mm256_setzero_ps();
1460 fix2 = _mm256_setzero_ps();
1461 fiy2 = _mm256_setzero_ps();
1462 fiz2 = _mm256_setzero_ps();
1464 /* Start inner kernel loop */
1465 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1468 /* Get j neighbor index, and coordinate index */
1470 jnrB = jjnr[jidx+1];
1471 jnrC = jjnr[jidx+2];
1472 jnrD = jjnr[jidx+3];
1473 jnrE = jjnr[jidx+4];
1474 jnrF = jjnr[jidx+5];
1475 jnrG = jjnr[jidx+6];
1476 jnrH = jjnr[jidx+7];
1477 j_coord_offsetA = DIM*jnrA;
1478 j_coord_offsetB = DIM*jnrB;
1479 j_coord_offsetC = DIM*jnrC;
1480 j_coord_offsetD = DIM*jnrD;
1481 j_coord_offsetE = DIM*jnrE;
1482 j_coord_offsetF = DIM*jnrF;
1483 j_coord_offsetG = DIM*jnrG;
1484 j_coord_offsetH = DIM*jnrH;
1486 /* load j atom coordinates */
1487 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1488 x+j_coord_offsetC,x+j_coord_offsetD,
1489 x+j_coord_offsetE,x+j_coord_offsetF,
1490 x+j_coord_offsetG,x+j_coord_offsetH,
1491 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1493 /* Calculate displacement vector */
1494 dx00 = _mm256_sub_ps(ix0,jx0);
1495 dy00 = _mm256_sub_ps(iy0,jy0);
1496 dz00 = _mm256_sub_ps(iz0,jz0);
1497 dx01 = _mm256_sub_ps(ix0,jx1);
1498 dy01 = _mm256_sub_ps(iy0,jy1);
1499 dz01 = _mm256_sub_ps(iz0,jz1);
1500 dx02 = _mm256_sub_ps(ix0,jx2);
1501 dy02 = _mm256_sub_ps(iy0,jy2);
1502 dz02 = _mm256_sub_ps(iz0,jz2);
1503 dx10 = _mm256_sub_ps(ix1,jx0);
1504 dy10 = _mm256_sub_ps(iy1,jy0);
1505 dz10 = _mm256_sub_ps(iz1,jz0);
1506 dx11 = _mm256_sub_ps(ix1,jx1);
1507 dy11 = _mm256_sub_ps(iy1,jy1);
1508 dz11 = _mm256_sub_ps(iz1,jz1);
1509 dx12 = _mm256_sub_ps(ix1,jx2);
1510 dy12 = _mm256_sub_ps(iy1,jy2);
1511 dz12 = _mm256_sub_ps(iz1,jz2);
1512 dx20 = _mm256_sub_ps(ix2,jx0);
1513 dy20 = _mm256_sub_ps(iy2,jy0);
1514 dz20 = _mm256_sub_ps(iz2,jz0);
1515 dx21 = _mm256_sub_ps(ix2,jx1);
1516 dy21 = _mm256_sub_ps(iy2,jy1);
1517 dz21 = _mm256_sub_ps(iz2,jz1);
1518 dx22 = _mm256_sub_ps(ix2,jx2);
1519 dy22 = _mm256_sub_ps(iy2,jy2);
1520 dz22 = _mm256_sub_ps(iz2,jz2);
1522 /* Calculate squared distance and things based on it */
1523 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1524 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1525 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1526 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1527 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1528 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1529 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1530 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1531 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1533 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1534 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1535 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1536 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1537 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1538 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1539 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
1540 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1541 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1543 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1544 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
1545 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
1546 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
1547 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1548 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1549 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
1550 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1551 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1553 fjx0 = _mm256_setzero_ps();
1554 fjy0 = _mm256_setzero_ps();
1555 fjz0 = _mm256_setzero_ps();
1556 fjx1 = _mm256_setzero_ps();
1557 fjy1 = _mm256_setzero_ps();
1558 fjz1 = _mm256_setzero_ps();
1559 fjx2 = _mm256_setzero_ps();
1560 fjy2 = _mm256_setzero_ps();
1561 fjz2 = _mm256_setzero_ps();
1563 /**************************
1564 * CALCULATE INTERACTIONS *
1565 **************************/
1567 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1570 r00 = _mm256_mul_ps(rsq00,rinv00);
1572 /* Calculate table index by multiplying r with table scale and truncate to integer */
1573 rt = _mm256_mul_ps(r00,vftabscale);
1574 vfitab = _mm256_cvttps_epi32(rt);
1575 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
1576 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
1577 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
1578 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
1579 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
1580 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
1582 /* REACTION-FIELD ELECTROSTATICS */
1583 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1585 /* CUBIC SPLINE TABLE DISPERSION */
1586 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1587 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1588 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1589 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1590 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1591 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1592 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1593 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1594 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1595 Heps = _mm256_mul_ps(vfeps,H);
1596 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1597 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1598 fvdw6 = _mm256_mul_ps(c6_00,FF);
1600 /* CUBIC SPLINE TABLE REPULSION */
1601 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
1602 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
1603 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1604 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1605 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1606 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1607 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1608 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1609 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1610 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1611 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1612 Heps = _mm256_mul_ps(vfeps,H);
1613 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1614 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1615 fvdw12 = _mm256_mul_ps(c12_00,FF);
1616 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
1618 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1620 fscal = _mm256_add_ps(felec,fvdw);
1622 fscal = _mm256_and_ps(fscal,cutoff_mask);
1624 /* Calculate temporary vectorial force */
1625 tx = _mm256_mul_ps(fscal,dx00);
1626 ty = _mm256_mul_ps(fscal,dy00);
1627 tz = _mm256_mul_ps(fscal,dz00);
1629 /* Update vectorial force */
1630 fix0 = _mm256_add_ps(fix0,tx);
1631 fiy0 = _mm256_add_ps(fiy0,ty);
1632 fiz0 = _mm256_add_ps(fiz0,tz);
1634 fjx0 = _mm256_add_ps(fjx0,tx);
1635 fjy0 = _mm256_add_ps(fjy0,ty);
1636 fjz0 = _mm256_add_ps(fjz0,tz);
1640 /**************************
1641 * CALCULATE INTERACTIONS *
1642 **************************/
1644 if (gmx_mm256_any_lt(rsq01,rcutoff2))
1647 /* REACTION-FIELD ELECTROSTATICS */
1648 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1650 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1654 fscal = _mm256_and_ps(fscal,cutoff_mask);
1656 /* Calculate temporary vectorial force */
1657 tx = _mm256_mul_ps(fscal,dx01);
1658 ty = _mm256_mul_ps(fscal,dy01);
1659 tz = _mm256_mul_ps(fscal,dz01);
1661 /* Update vectorial force */
1662 fix0 = _mm256_add_ps(fix0,tx);
1663 fiy0 = _mm256_add_ps(fiy0,ty);
1664 fiz0 = _mm256_add_ps(fiz0,tz);
1666 fjx1 = _mm256_add_ps(fjx1,tx);
1667 fjy1 = _mm256_add_ps(fjy1,ty);
1668 fjz1 = _mm256_add_ps(fjz1,tz);
1672 /**************************
1673 * CALCULATE INTERACTIONS *
1674 **************************/
1676 if (gmx_mm256_any_lt(rsq02,rcutoff2))
1679 /* REACTION-FIELD ELECTROSTATICS */
1680 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1682 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1686 fscal = _mm256_and_ps(fscal,cutoff_mask);
1688 /* Calculate temporary vectorial force */
1689 tx = _mm256_mul_ps(fscal,dx02);
1690 ty = _mm256_mul_ps(fscal,dy02);
1691 tz = _mm256_mul_ps(fscal,dz02);
1693 /* Update vectorial force */
1694 fix0 = _mm256_add_ps(fix0,tx);
1695 fiy0 = _mm256_add_ps(fiy0,ty);
1696 fiz0 = _mm256_add_ps(fiz0,tz);
1698 fjx2 = _mm256_add_ps(fjx2,tx);
1699 fjy2 = _mm256_add_ps(fjy2,ty);
1700 fjz2 = _mm256_add_ps(fjz2,tz);
1704 /**************************
1705 * CALCULATE INTERACTIONS *
1706 **************************/
1708 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1711 /* REACTION-FIELD ELECTROSTATICS */
1712 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1714 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1718 fscal = _mm256_and_ps(fscal,cutoff_mask);
1720 /* Calculate temporary vectorial force */
1721 tx = _mm256_mul_ps(fscal,dx10);
1722 ty = _mm256_mul_ps(fscal,dy10);
1723 tz = _mm256_mul_ps(fscal,dz10);
1725 /* Update vectorial force */
1726 fix1 = _mm256_add_ps(fix1,tx);
1727 fiy1 = _mm256_add_ps(fiy1,ty);
1728 fiz1 = _mm256_add_ps(fiz1,tz);
1730 fjx0 = _mm256_add_ps(fjx0,tx);
1731 fjy0 = _mm256_add_ps(fjy0,ty);
1732 fjz0 = _mm256_add_ps(fjz0,tz);
1736 /**************************
1737 * CALCULATE INTERACTIONS *
1738 **************************/
1740 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1743 /* REACTION-FIELD ELECTROSTATICS */
1744 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1746 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1750 fscal = _mm256_and_ps(fscal,cutoff_mask);
1752 /* Calculate temporary vectorial force */
1753 tx = _mm256_mul_ps(fscal,dx11);
1754 ty = _mm256_mul_ps(fscal,dy11);
1755 tz = _mm256_mul_ps(fscal,dz11);
1757 /* Update vectorial force */
1758 fix1 = _mm256_add_ps(fix1,tx);
1759 fiy1 = _mm256_add_ps(fiy1,ty);
1760 fiz1 = _mm256_add_ps(fiz1,tz);
1762 fjx1 = _mm256_add_ps(fjx1,tx);
1763 fjy1 = _mm256_add_ps(fjy1,ty);
1764 fjz1 = _mm256_add_ps(fjz1,tz);
1768 /**************************
1769 * CALCULATE INTERACTIONS *
1770 **************************/
1772 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1775 /* REACTION-FIELD ELECTROSTATICS */
1776 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1778 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1782 fscal = _mm256_and_ps(fscal,cutoff_mask);
1784 /* Calculate temporary vectorial force */
1785 tx = _mm256_mul_ps(fscal,dx12);
1786 ty = _mm256_mul_ps(fscal,dy12);
1787 tz = _mm256_mul_ps(fscal,dz12);
1789 /* Update vectorial force */
1790 fix1 = _mm256_add_ps(fix1,tx);
1791 fiy1 = _mm256_add_ps(fiy1,ty);
1792 fiz1 = _mm256_add_ps(fiz1,tz);
1794 fjx2 = _mm256_add_ps(fjx2,tx);
1795 fjy2 = _mm256_add_ps(fjy2,ty);
1796 fjz2 = _mm256_add_ps(fjz2,tz);
1800 /**************************
1801 * CALCULATE INTERACTIONS *
1802 **************************/
1804 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1807 /* REACTION-FIELD ELECTROSTATICS */
1808 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1810 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1814 fscal = _mm256_and_ps(fscal,cutoff_mask);
1816 /* Calculate temporary vectorial force */
1817 tx = _mm256_mul_ps(fscal,dx20);
1818 ty = _mm256_mul_ps(fscal,dy20);
1819 tz = _mm256_mul_ps(fscal,dz20);
1821 /* Update vectorial force */
1822 fix2 = _mm256_add_ps(fix2,tx);
1823 fiy2 = _mm256_add_ps(fiy2,ty);
1824 fiz2 = _mm256_add_ps(fiz2,tz);
1826 fjx0 = _mm256_add_ps(fjx0,tx);
1827 fjy0 = _mm256_add_ps(fjy0,ty);
1828 fjz0 = _mm256_add_ps(fjz0,tz);
1832 /**************************
1833 * CALCULATE INTERACTIONS *
1834 **************************/
1836 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1839 /* REACTION-FIELD ELECTROSTATICS */
1840 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1842 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1846 fscal = _mm256_and_ps(fscal,cutoff_mask);
1848 /* Calculate temporary vectorial force */
1849 tx = _mm256_mul_ps(fscal,dx21);
1850 ty = _mm256_mul_ps(fscal,dy21);
1851 tz = _mm256_mul_ps(fscal,dz21);
1853 /* Update vectorial force */
1854 fix2 = _mm256_add_ps(fix2,tx);
1855 fiy2 = _mm256_add_ps(fiy2,ty);
1856 fiz2 = _mm256_add_ps(fiz2,tz);
1858 fjx1 = _mm256_add_ps(fjx1,tx);
1859 fjy1 = _mm256_add_ps(fjy1,ty);
1860 fjz1 = _mm256_add_ps(fjz1,tz);
1864 /**************************
1865 * CALCULATE INTERACTIONS *
1866 **************************/
1868 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1871 /* REACTION-FIELD ELECTROSTATICS */
1872 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1874 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1878 fscal = _mm256_and_ps(fscal,cutoff_mask);
1880 /* Calculate temporary vectorial force */
1881 tx = _mm256_mul_ps(fscal,dx22);
1882 ty = _mm256_mul_ps(fscal,dy22);
1883 tz = _mm256_mul_ps(fscal,dz22);
1885 /* Update vectorial force */
1886 fix2 = _mm256_add_ps(fix2,tx);
1887 fiy2 = _mm256_add_ps(fiy2,ty);
1888 fiz2 = _mm256_add_ps(fiz2,tz);
1890 fjx2 = _mm256_add_ps(fjx2,tx);
1891 fjy2 = _mm256_add_ps(fjy2,ty);
1892 fjz2 = _mm256_add_ps(fjz2,tz);
1896 fjptrA = f+j_coord_offsetA;
1897 fjptrB = f+j_coord_offsetB;
1898 fjptrC = f+j_coord_offsetC;
1899 fjptrD = f+j_coord_offsetD;
1900 fjptrE = f+j_coord_offsetE;
1901 fjptrF = f+j_coord_offsetF;
1902 fjptrG = f+j_coord_offsetG;
1903 fjptrH = f+j_coord_offsetH;
1905 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1906 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1908 /* Inner loop uses 297 flops */
1911 if(jidx<j_index_end)
1914 /* Get j neighbor index, and coordinate index */
1915 jnrlistA = jjnr[jidx];
1916 jnrlistB = jjnr[jidx+1];
1917 jnrlistC = jjnr[jidx+2];
1918 jnrlistD = jjnr[jidx+3];
1919 jnrlistE = jjnr[jidx+4];
1920 jnrlistF = jjnr[jidx+5];
1921 jnrlistG = jjnr[jidx+6];
1922 jnrlistH = jjnr[jidx+7];
1923 /* Sign of each element will be negative for non-real atoms.
1924 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1925 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1927 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1928 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1930 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1931 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1932 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1933 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1934 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
1935 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
1936 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
1937 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
1938 j_coord_offsetA = DIM*jnrA;
1939 j_coord_offsetB = DIM*jnrB;
1940 j_coord_offsetC = DIM*jnrC;
1941 j_coord_offsetD = DIM*jnrD;
1942 j_coord_offsetE = DIM*jnrE;
1943 j_coord_offsetF = DIM*jnrF;
1944 j_coord_offsetG = DIM*jnrG;
1945 j_coord_offsetH = DIM*jnrH;
1947 /* load j atom coordinates */
1948 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1949 x+j_coord_offsetC,x+j_coord_offsetD,
1950 x+j_coord_offsetE,x+j_coord_offsetF,
1951 x+j_coord_offsetG,x+j_coord_offsetH,
1952 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1954 /* Calculate displacement vector */
1955 dx00 = _mm256_sub_ps(ix0,jx0);
1956 dy00 = _mm256_sub_ps(iy0,jy0);
1957 dz00 = _mm256_sub_ps(iz0,jz0);
1958 dx01 = _mm256_sub_ps(ix0,jx1);
1959 dy01 = _mm256_sub_ps(iy0,jy1);
1960 dz01 = _mm256_sub_ps(iz0,jz1);
1961 dx02 = _mm256_sub_ps(ix0,jx2);
1962 dy02 = _mm256_sub_ps(iy0,jy2);
1963 dz02 = _mm256_sub_ps(iz0,jz2);
1964 dx10 = _mm256_sub_ps(ix1,jx0);
1965 dy10 = _mm256_sub_ps(iy1,jy0);
1966 dz10 = _mm256_sub_ps(iz1,jz0);
1967 dx11 = _mm256_sub_ps(ix1,jx1);
1968 dy11 = _mm256_sub_ps(iy1,jy1);
1969 dz11 = _mm256_sub_ps(iz1,jz1);
1970 dx12 = _mm256_sub_ps(ix1,jx2);
1971 dy12 = _mm256_sub_ps(iy1,jy2);
1972 dz12 = _mm256_sub_ps(iz1,jz2);
1973 dx20 = _mm256_sub_ps(ix2,jx0);
1974 dy20 = _mm256_sub_ps(iy2,jy0);
1975 dz20 = _mm256_sub_ps(iz2,jz0);
1976 dx21 = _mm256_sub_ps(ix2,jx1);
1977 dy21 = _mm256_sub_ps(iy2,jy1);
1978 dz21 = _mm256_sub_ps(iz2,jz1);
1979 dx22 = _mm256_sub_ps(ix2,jx2);
1980 dy22 = _mm256_sub_ps(iy2,jy2);
1981 dz22 = _mm256_sub_ps(iz2,jz2);
1983 /* Calculate squared distance and things based on it */
1984 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1985 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1986 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1987 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1988 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1989 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1990 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1991 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1992 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1994 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1995 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1996 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1997 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1998 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1999 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
2000 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
2001 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
2002 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
2004 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
2005 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
2006 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
2007 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
2008 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
2009 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
2010 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
2011 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
2012 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
2014 fjx0 = _mm256_setzero_ps();
2015 fjy0 = _mm256_setzero_ps();
2016 fjz0 = _mm256_setzero_ps();
2017 fjx1 = _mm256_setzero_ps();
2018 fjy1 = _mm256_setzero_ps();
2019 fjz1 = _mm256_setzero_ps();
2020 fjx2 = _mm256_setzero_ps();
2021 fjy2 = _mm256_setzero_ps();
2022 fjz2 = _mm256_setzero_ps();
2024 /**************************
2025 * CALCULATE INTERACTIONS *
2026 **************************/
2028 if (gmx_mm256_any_lt(rsq00,rcutoff2))
2031 r00 = _mm256_mul_ps(rsq00,rinv00);
2032 r00 = _mm256_andnot_ps(dummy_mask,r00);
2034 /* Calculate table index by multiplying r with table scale and truncate to integer */
2035 rt = _mm256_mul_ps(r00,vftabscale);
2036 vfitab = _mm256_cvttps_epi32(rt);
2037 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
2038 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
2039 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
2040 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
2041 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
2042 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
2044 /* REACTION-FIELD ELECTROSTATICS */
2045 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
2047 /* CUBIC SPLINE TABLE DISPERSION */
2048 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2049 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2050 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2051 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2052 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2053 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2054 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2055 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2056 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2057 Heps = _mm256_mul_ps(vfeps,H);
2058 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2059 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2060 fvdw6 = _mm256_mul_ps(c6_00,FF);
2062 /* CUBIC SPLINE TABLE REPULSION */
2063 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
2064 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
2065 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2066 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2067 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2068 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2069 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2070 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2071 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2072 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2073 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2074 Heps = _mm256_mul_ps(vfeps,H);
2075 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2076 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2077 fvdw12 = _mm256_mul_ps(c12_00,FF);
2078 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
2080 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2082 fscal = _mm256_add_ps(felec,fvdw);
2084 fscal = _mm256_and_ps(fscal,cutoff_mask);
2086 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2088 /* Calculate temporary vectorial force */
2089 tx = _mm256_mul_ps(fscal,dx00);
2090 ty = _mm256_mul_ps(fscal,dy00);
2091 tz = _mm256_mul_ps(fscal,dz00);
2093 /* Update vectorial force */
2094 fix0 = _mm256_add_ps(fix0,tx);
2095 fiy0 = _mm256_add_ps(fiy0,ty);
2096 fiz0 = _mm256_add_ps(fiz0,tz);
2098 fjx0 = _mm256_add_ps(fjx0,tx);
2099 fjy0 = _mm256_add_ps(fjy0,ty);
2100 fjz0 = _mm256_add_ps(fjz0,tz);
2104 /**************************
2105 * CALCULATE INTERACTIONS *
2106 **************************/
2108 if (gmx_mm256_any_lt(rsq01,rcutoff2))
2111 /* REACTION-FIELD ELECTROSTATICS */
2112 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
2114 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
2118 fscal = _mm256_and_ps(fscal,cutoff_mask);
2120 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2122 /* Calculate temporary vectorial force */
2123 tx = _mm256_mul_ps(fscal,dx01);
2124 ty = _mm256_mul_ps(fscal,dy01);
2125 tz = _mm256_mul_ps(fscal,dz01);
2127 /* Update vectorial force */
2128 fix0 = _mm256_add_ps(fix0,tx);
2129 fiy0 = _mm256_add_ps(fiy0,ty);
2130 fiz0 = _mm256_add_ps(fiz0,tz);
2132 fjx1 = _mm256_add_ps(fjx1,tx);
2133 fjy1 = _mm256_add_ps(fjy1,ty);
2134 fjz1 = _mm256_add_ps(fjz1,tz);
2138 /**************************
2139 * CALCULATE INTERACTIONS *
2140 **************************/
2142 if (gmx_mm256_any_lt(rsq02,rcutoff2))
2145 /* REACTION-FIELD ELECTROSTATICS */
2146 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
2148 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
2152 fscal = _mm256_and_ps(fscal,cutoff_mask);
2154 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2156 /* Calculate temporary vectorial force */
2157 tx = _mm256_mul_ps(fscal,dx02);
2158 ty = _mm256_mul_ps(fscal,dy02);
2159 tz = _mm256_mul_ps(fscal,dz02);
2161 /* Update vectorial force */
2162 fix0 = _mm256_add_ps(fix0,tx);
2163 fiy0 = _mm256_add_ps(fiy0,ty);
2164 fiz0 = _mm256_add_ps(fiz0,tz);
2166 fjx2 = _mm256_add_ps(fjx2,tx);
2167 fjy2 = _mm256_add_ps(fjy2,ty);
2168 fjz2 = _mm256_add_ps(fjz2,tz);
2172 /**************************
2173 * CALCULATE INTERACTIONS *
2174 **************************/
2176 if (gmx_mm256_any_lt(rsq10,rcutoff2))
2179 /* REACTION-FIELD ELECTROSTATICS */
2180 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
2182 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
2186 fscal = _mm256_and_ps(fscal,cutoff_mask);
2188 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2190 /* Calculate temporary vectorial force */
2191 tx = _mm256_mul_ps(fscal,dx10);
2192 ty = _mm256_mul_ps(fscal,dy10);
2193 tz = _mm256_mul_ps(fscal,dz10);
2195 /* Update vectorial force */
2196 fix1 = _mm256_add_ps(fix1,tx);
2197 fiy1 = _mm256_add_ps(fiy1,ty);
2198 fiz1 = _mm256_add_ps(fiz1,tz);
2200 fjx0 = _mm256_add_ps(fjx0,tx);
2201 fjy0 = _mm256_add_ps(fjy0,ty);
2202 fjz0 = _mm256_add_ps(fjz0,tz);
2206 /**************************
2207 * CALCULATE INTERACTIONS *
2208 **************************/
2210 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2213 /* REACTION-FIELD ELECTROSTATICS */
2214 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2216 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2220 fscal = _mm256_and_ps(fscal,cutoff_mask);
2222 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2224 /* Calculate temporary vectorial force */
2225 tx = _mm256_mul_ps(fscal,dx11);
2226 ty = _mm256_mul_ps(fscal,dy11);
2227 tz = _mm256_mul_ps(fscal,dz11);
2229 /* Update vectorial force */
2230 fix1 = _mm256_add_ps(fix1,tx);
2231 fiy1 = _mm256_add_ps(fiy1,ty);
2232 fiz1 = _mm256_add_ps(fiz1,tz);
2234 fjx1 = _mm256_add_ps(fjx1,tx);
2235 fjy1 = _mm256_add_ps(fjy1,ty);
2236 fjz1 = _mm256_add_ps(fjz1,tz);
2240 /**************************
2241 * CALCULATE INTERACTIONS *
2242 **************************/
2244 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2247 /* REACTION-FIELD ELECTROSTATICS */
2248 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2250 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2254 fscal = _mm256_and_ps(fscal,cutoff_mask);
2256 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2258 /* Calculate temporary vectorial force */
2259 tx = _mm256_mul_ps(fscal,dx12);
2260 ty = _mm256_mul_ps(fscal,dy12);
2261 tz = _mm256_mul_ps(fscal,dz12);
2263 /* Update vectorial force */
2264 fix1 = _mm256_add_ps(fix1,tx);
2265 fiy1 = _mm256_add_ps(fiy1,ty);
2266 fiz1 = _mm256_add_ps(fiz1,tz);
2268 fjx2 = _mm256_add_ps(fjx2,tx);
2269 fjy2 = _mm256_add_ps(fjy2,ty);
2270 fjz2 = _mm256_add_ps(fjz2,tz);
2274 /**************************
2275 * CALCULATE INTERACTIONS *
2276 **************************/
2278 if (gmx_mm256_any_lt(rsq20,rcutoff2))
2281 /* REACTION-FIELD ELECTROSTATICS */
2282 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
2284 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
2288 fscal = _mm256_and_ps(fscal,cutoff_mask);
2290 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2292 /* Calculate temporary vectorial force */
2293 tx = _mm256_mul_ps(fscal,dx20);
2294 ty = _mm256_mul_ps(fscal,dy20);
2295 tz = _mm256_mul_ps(fscal,dz20);
2297 /* Update vectorial force */
2298 fix2 = _mm256_add_ps(fix2,tx);
2299 fiy2 = _mm256_add_ps(fiy2,ty);
2300 fiz2 = _mm256_add_ps(fiz2,tz);
2302 fjx0 = _mm256_add_ps(fjx0,tx);
2303 fjy0 = _mm256_add_ps(fjy0,ty);
2304 fjz0 = _mm256_add_ps(fjz0,tz);
2308 /**************************
2309 * CALCULATE INTERACTIONS *
2310 **************************/
2312 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2315 /* REACTION-FIELD ELECTROSTATICS */
2316 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2318 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2322 fscal = _mm256_and_ps(fscal,cutoff_mask);
2324 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2326 /* Calculate temporary vectorial force */
2327 tx = _mm256_mul_ps(fscal,dx21);
2328 ty = _mm256_mul_ps(fscal,dy21);
2329 tz = _mm256_mul_ps(fscal,dz21);
2331 /* Update vectorial force */
2332 fix2 = _mm256_add_ps(fix2,tx);
2333 fiy2 = _mm256_add_ps(fiy2,ty);
2334 fiz2 = _mm256_add_ps(fiz2,tz);
2336 fjx1 = _mm256_add_ps(fjx1,tx);
2337 fjy1 = _mm256_add_ps(fjy1,ty);
2338 fjz1 = _mm256_add_ps(fjz1,tz);
2342 /**************************
2343 * CALCULATE INTERACTIONS *
2344 **************************/
2346 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2349 /* REACTION-FIELD ELECTROSTATICS */
2350 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2352 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2356 fscal = _mm256_and_ps(fscal,cutoff_mask);
2358 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2360 /* Calculate temporary vectorial force */
2361 tx = _mm256_mul_ps(fscal,dx22);
2362 ty = _mm256_mul_ps(fscal,dy22);
2363 tz = _mm256_mul_ps(fscal,dz22);
2365 /* Update vectorial force */
2366 fix2 = _mm256_add_ps(fix2,tx);
2367 fiy2 = _mm256_add_ps(fiy2,ty);
2368 fiz2 = _mm256_add_ps(fiz2,tz);
2370 fjx2 = _mm256_add_ps(fjx2,tx);
2371 fjy2 = _mm256_add_ps(fjy2,ty);
2372 fjz2 = _mm256_add_ps(fjz2,tz);
2376 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2377 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2378 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2379 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2380 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2381 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2382 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2383 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2385 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2386 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2388 /* Inner loop uses 298 flops */
2391 /* End of innermost loop */
2393 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2394 f+i_coord_offset,fshift+i_shift_offset);
2396 /* Increment number of inner iterations */
2397 inneriter += j_index_end - j_index_start;
2399 /* Outer loop uses 18 flops */
2402 /* Increment number of outer iterations */
2405 /* Update outer/inner flops */
2407 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);