2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_256_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_256_single.h"
48 #include "kernelutil_x86_avx_256_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_256_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water3-Water3
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_256_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrE,jnrF,jnrG,jnrH;
76 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
77 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
80 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
82 real *shiftvec,*fshift,*x,*f;
83 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
85 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 real * vdwioffsetptr0;
87 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 real * vdwioffsetptr1;
89 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 real * vdwioffsetptr2;
91 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
93 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
94 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
95 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
96 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
97 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
98 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
99 __m256 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
100 __m256 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
101 __m256 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
102 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
103 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
104 __m256 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
105 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
106 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
107 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
110 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
113 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
114 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
116 __m128i vfitab_lo,vfitab_hi;
117 __m128i ifour = _mm_set1_epi32(4);
118 __m256 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
120 __m256 dummy_mask,cutoff_mask;
121 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
122 __m256 one = _mm256_set1_ps(1.0);
123 __m256 two = _mm256_set1_ps(2.0);
129 jindex = nlist->jindex;
131 shiftidx = nlist->shift;
133 shiftvec = fr->shift_vec[0];
134 fshift = fr->fshift[0];
135 facel = _mm256_set1_ps(fr->epsfac);
136 charge = mdatoms->chargeA;
137 krf = _mm256_set1_ps(fr->ic->k_rf);
138 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
139 crf = _mm256_set1_ps(fr->ic->c_rf);
140 nvdwtype = fr->ntype;
142 vdwtype = mdatoms->typeA;
144 vftab = kernel_data->table_vdw->data;
145 vftabscale = _mm256_set1_ps(kernel_data->table_vdw->scale);
147 /* Setup water-specific parameters */
148 inr = nlist->iinr[0];
149 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+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 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
154 jq0 = _mm256_set1_ps(charge[inr+0]);
155 jq1 = _mm256_set1_ps(charge[inr+1]);
156 jq2 = _mm256_set1_ps(charge[inr+2]);
157 vdwjidx0A = 2*vdwtype[inr+0];
158 qq00 = _mm256_mul_ps(iq0,jq0);
159 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
160 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
161 qq01 = _mm256_mul_ps(iq0,jq1);
162 qq02 = _mm256_mul_ps(iq0,jq2);
163 qq10 = _mm256_mul_ps(iq1,jq0);
164 qq11 = _mm256_mul_ps(iq1,jq1);
165 qq12 = _mm256_mul_ps(iq1,jq2);
166 qq20 = _mm256_mul_ps(iq2,jq0);
167 qq21 = _mm256_mul_ps(iq2,jq1);
168 qq22 = _mm256_mul_ps(iq2,jq2);
170 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
171 rcutoff_scalar = fr->rcoulomb;
172 rcutoff = _mm256_set1_ps(rcutoff_scalar);
173 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
175 /* Avoid stupid compiler warnings */
176 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
189 for(iidx=0;iidx<4*DIM;iidx++)
194 /* Start outer loop over neighborlists */
195 for(iidx=0; iidx<nri; iidx++)
197 /* Load shift vector for this list */
198 i_shift_offset = DIM*shiftidx[iidx];
200 /* Load limits for loop over neighbors */
201 j_index_start = jindex[iidx];
202 j_index_end = jindex[iidx+1];
204 /* Get outer coordinate index */
206 i_coord_offset = DIM*inr;
208 /* Load i particle coords and add shift vector */
209 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
210 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
212 fix0 = _mm256_setzero_ps();
213 fiy0 = _mm256_setzero_ps();
214 fiz0 = _mm256_setzero_ps();
215 fix1 = _mm256_setzero_ps();
216 fiy1 = _mm256_setzero_ps();
217 fiz1 = _mm256_setzero_ps();
218 fix2 = _mm256_setzero_ps();
219 fiy2 = _mm256_setzero_ps();
220 fiz2 = _mm256_setzero_ps();
222 /* Reset potential sums */
223 velecsum = _mm256_setzero_ps();
224 vvdwsum = _mm256_setzero_ps();
226 /* Start inner kernel loop */
227 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
230 /* Get j neighbor index, and coordinate index */
239 j_coord_offsetA = DIM*jnrA;
240 j_coord_offsetB = DIM*jnrB;
241 j_coord_offsetC = DIM*jnrC;
242 j_coord_offsetD = DIM*jnrD;
243 j_coord_offsetE = DIM*jnrE;
244 j_coord_offsetF = DIM*jnrF;
245 j_coord_offsetG = DIM*jnrG;
246 j_coord_offsetH = DIM*jnrH;
248 /* load j atom coordinates */
249 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
250 x+j_coord_offsetC,x+j_coord_offsetD,
251 x+j_coord_offsetE,x+j_coord_offsetF,
252 x+j_coord_offsetG,x+j_coord_offsetH,
253 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
255 /* Calculate displacement vector */
256 dx00 = _mm256_sub_ps(ix0,jx0);
257 dy00 = _mm256_sub_ps(iy0,jy0);
258 dz00 = _mm256_sub_ps(iz0,jz0);
259 dx01 = _mm256_sub_ps(ix0,jx1);
260 dy01 = _mm256_sub_ps(iy0,jy1);
261 dz01 = _mm256_sub_ps(iz0,jz1);
262 dx02 = _mm256_sub_ps(ix0,jx2);
263 dy02 = _mm256_sub_ps(iy0,jy2);
264 dz02 = _mm256_sub_ps(iz0,jz2);
265 dx10 = _mm256_sub_ps(ix1,jx0);
266 dy10 = _mm256_sub_ps(iy1,jy0);
267 dz10 = _mm256_sub_ps(iz1,jz0);
268 dx11 = _mm256_sub_ps(ix1,jx1);
269 dy11 = _mm256_sub_ps(iy1,jy1);
270 dz11 = _mm256_sub_ps(iz1,jz1);
271 dx12 = _mm256_sub_ps(ix1,jx2);
272 dy12 = _mm256_sub_ps(iy1,jy2);
273 dz12 = _mm256_sub_ps(iz1,jz2);
274 dx20 = _mm256_sub_ps(ix2,jx0);
275 dy20 = _mm256_sub_ps(iy2,jy0);
276 dz20 = _mm256_sub_ps(iz2,jz0);
277 dx21 = _mm256_sub_ps(ix2,jx1);
278 dy21 = _mm256_sub_ps(iy2,jy1);
279 dz21 = _mm256_sub_ps(iz2,jz1);
280 dx22 = _mm256_sub_ps(ix2,jx2);
281 dy22 = _mm256_sub_ps(iy2,jy2);
282 dz22 = _mm256_sub_ps(iz2,jz2);
284 /* Calculate squared distance and things based on it */
285 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
286 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
287 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
288 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
289 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
290 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
291 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
292 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
293 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
295 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
296 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
297 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
298 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
299 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
300 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
301 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
302 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
303 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
305 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
306 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
307 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
308 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
309 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
310 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
311 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
312 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
313 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
315 fjx0 = _mm256_setzero_ps();
316 fjy0 = _mm256_setzero_ps();
317 fjz0 = _mm256_setzero_ps();
318 fjx1 = _mm256_setzero_ps();
319 fjy1 = _mm256_setzero_ps();
320 fjz1 = _mm256_setzero_ps();
321 fjx2 = _mm256_setzero_ps();
322 fjy2 = _mm256_setzero_ps();
323 fjz2 = _mm256_setzero_ps();
325 /**************************
326 * CALCULATE INTERACTIONS *
327 **************************/
329 if (gmx_mm256_any_lt(rsq00,rcutoff2))
332 r00 = _mm256_mul_ps(rsq00,rinv00);
334 /* Calculate table index by multiplying r with table scale and truncate to integer */
335 rt = _mm256_mul_ps(r00,vftabscale);
336 vfitab = _mm256_cvttps_epi32(rt);
337 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
338 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
339 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
340 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
341 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
342 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
344 /* REACTION-FIELD ELECTROSTATICS */
345 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
346 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
348 /* CUBIC SPLINE TABLE DISPERSION */
349 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
350 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
351 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
352 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
353 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
354 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
355 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
356 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
357 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
358 Heps = _mm256_mul_ps(vfeps,H);
359 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
360 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
361 vvdw6 = _mm256_mul_ps(c6_00,VV);
362 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
363 fvdw6 = _mm256_mul_ps(c6_00,FF);
365 /* CUBIC SPLINE TABLE REPULSION */
366 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
367 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
368 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
369 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
370 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
371 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
372 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
373 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
374 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
375 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
376 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
377 Heps = _mm256_mul_ps(vfeps,H);
378 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
379 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
380 vvdw12 = _mm256_mul_ps(c12_00,VV);
381 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
382 fvdw12 = _mm256_mul_ps(c12_00,FF);
383 vvdw = _mm256_add_ps(vvdw12,vvdw6);
384 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
386 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
388 /* Update potential sum for this i atom from the interaction with this j atom. */
389 velec = _mm256_and_ps(velec,cutoff_mask);
390 velecsum = _mm256_add_ps(velecsum,velec);
391 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
392 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
394 fscal = _mm256_add_ps(felec,fvdw);
396 fscal = _mm256_and_ps(fscal,cutoff_mask);
398 /* Calculate temporary vectorial force */
399 tx = _mm256_mul_ps(fscal,dx00);
400 ty = _mm256_mul_ps(fscal,dy00);
401 tz = _mm256_mul_ps(fscal,dz00);
403 /* Update vectorial force */
404 fix0 = _mm256_add_ps(fix0,tx);
405 fiy0 = _mm256_add_ps(fiy0,ty);
406 fiz0 = _mm256_add_ps(fiz0,tz);
408 fjx0 = _mm256_add_ps(fjx0,tx);
409 fjy0 = _mm256_add_ps(fjy0,ty);
410 fjz0 = _mm256_add_ps(fjz0,tz);
414 /**************************
415 * CALCULATE INTERACTIONS *
416 **************************/
418 if (gmx_mm256_any_lt(rsq01,rcutoff2))
421 /* REACTION-FIELD ELECTROSTATICS */
422 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
423 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
425 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
427 /* Update potential sum for this i atom from the interaction with this j atom. */
428 velec = _mm256_and_ps(velec,cutoff_mask);
429 velecsum = _mm256_add_ps(velecsum,velec);
433 fscal = _mm256_and_ps(fscal,cutoff_mask);
435 /* Calculate temporary vectorial force */
436 tx = _mm256_mul_ps(fscal,dx01);
437 ty = _mm256_mul_ps(fscal,dy01);
438 tz = _mm256_mul_ps(fscal,dz01);
440 /* Update vectorial force */
441 fix0 = _mm256_add_ps(fix0,tx);
442 fiy0 = _mm256_add_ps(fiy0,ty);
443 fiz0 = _mm256_add_ps(fiz0,tz);
445 fjx1 = _mm256_add_ps(fjx1,tx);
446 fjy1 = _mm256_add_ps(fjy1,ty);
447 fjz1 = _mm256_add_ps(fjz1,tz);
451 /**************************
452 * CALCULATE INTERACTIONS *
453 **************************/
455 if (gmx_mm256_any_lt(rsq02,rcutoff2))
458 /* REACTION-FIELD ELECTROSTATICS */
459 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
460 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
462 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
464 /* Update potential sum for this i atom from the interaction with this j atom. */
465 velec = _mm256_and_ps(velec,cutoff_mask);
466 velecsum = _mm256_add_ps(velecsum,velec);
470 fscal = _mm256_and_ps(fscal,cutoff_mask);
472 /* Calculate temporary vectorial force */
473 tx = _mm256_mul_ps(fscal,dx02);
474 ty = _mm256_mul_ps(fscal,dy02);
475 tz = _mm256_mul_ps(fscal,dz02);
477 /* Update vectorial force */
478 fix0 = _mm256_add_ps(fix0,tx);
479 fiy0 = _mm256_add_ps(fiy0,ty);
480 fiz0 = _mm256_add_ps(fiz0,tz);
482 fjx2 = _mm256_add_ps(fjx2,tx);
483 fjy2 = _mm256_add_ps(fjy2,ty);
484 fjz2 = _mm256_add_ps(fjz2,tz);
488 /**************************
489 * CALCULATE INTERACTIONS *
490 **************************/
492 if (gmx_mm256_any_lt(rsq10,rcutoff2))
495 /* REACTION-FIELD ELECTROSTATICS */
496 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
497 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
499 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
501 /* Update potential sum for this i atom from the interaction with this j atom. */
502 velec = _mm256_and_ps(velec,cutoff_mask);
503 velecsum = _mm256_add_ps(velecsum,velec);
507 fscal = _mm256_and_ps(fscal,cutoff_mask);
509 /* Calculate temporary vectorial force */
510 tx = _mm256_mul_ps(fscal,dx10);
511 ty = _mm256_mul_ps(fscal,dy10);
512 tz = _mm256_mul_ps(fscal,dz10);
514 /* Update vectorial force */
515 fix1 = _mm256_add_ps(fix1,tx);
516 fiy1 = _mm256_add_ps(fiy1,ty);
517 fiz1 = _mm256_add_ps(fiz1,tz);
519 fjx0 = _mm256_add_ps(fjx0,tx);
520 fjy0 = _mm256_add_ps(fjy0,ty);
521 fjz0 = _mm256_add_ps(fjz0,tz);
525 /**************************
526 * CALCULATE INTERACTIONS *
527 **************************/
529 if (gmx_mm256_any_lt(rsq11,rcutoff2))
532 /* REACTION-FIELD ELECTROSTATICS */
533 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
534 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
536 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
538 /* Update potential sum for this i atom from the interaction with this j atom. */
539 velec = _mm256_and_ps(velec,cutoff_mask);
540 velecsum = _mm256_add_ps(velecsum,velec);
544 fscal = _mm256_and_ps(fscal,cutoff_mask);
546 /* Calculate temporary vectorial force */
547 tx = _mm256_mul_ps(fscal,dx11);
548 ty = _mm256_mul_ps(fscal,dy11);
549 tz = _mm256_mul_ps(fscal,dz11);
551 /* Update vectorial force */
552 fix1 = _mm256_add_ps(fix1,tx);
553 fiy1 = _mm256_add_ps(fiy1,ty);
554 fiz1 = _mm256_add_ps(fiz1,tz);
556 fjx1 = _mm256_add_ps(fjx1,tx);
557 fjy1 = _mm256_add_ps(fjy1,ty);
558 fjz1 = _mm256_add_ps(fjz1,tz);
562 /**************************
563 * CALCULATE INTERACTIONS *
564 **************************/
566 if (gmx_mm256_any_lt(rsq12,rcutoff2))
569 /* REACTION-FIELD ELECTROSTATICS */
570 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
571 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
573 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
575 /* Update potential sum for this i atom from the interaction with this j atom. */
576 velec = _mm256_and_ps(velec,cutoff_mask);
577 velecsum = _mm256_add_ps(velecsum,velec);
581 fscal = _mm256_and_ps(fscal,cutoff_mask);
583 /* Calculate temporary vectorial force */
584 tx = _mm256_mul_ps(fscal,dx12);
585 ty = _mm256_mul_ps(fscal,dy12);
586 tz = _mm256_mul_ps(fscal,dz12);
588 /* Update vectorial force */
589 fix1 = _mm256_add_ps(fix1,tx);
590 fiy1 = _mm256_add_ps(fiy1,ty);
591 fiz1 = _mm256_add_ps(fiz1,tz);
593 fjx2 = _mm256_add_ps(fjx2,tx);
594 fjy2 = _mm256_add_ps(fjy2,ty);
595 fjz2 = _mm256_add_ps(fjz2,tz);
599 /**************************
600 * CALCULATE INTERACTIONS *
601 **************************/
603 if (gmx_mm256_any_lt(rsq20,rcutoff2))
606 /* REACTION-FIELD ELECTROSTATICS */
607 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
608 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
610 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
612 /* Update potential sum for this i atom from the interaction with this j atom. */
613 velec = _mm256_and_ps(velec,cutoff_mask);
614 velecsum = _mm256_add_ps(velecsum,velec);
618 fscal = _mm256_and_ps(fscal,cutoff_mask);
620 /* Calculate temporary vectorial force */
621 tx = _mm256_mul_ps(fscal,dx20);
622 ty = _mm256_mul_ps(fscal,dy20);
623 tz = _mm256_mul_ps(fscal,dz20);
625 /* Update vectorial force */
626 fix2 = _mm256_add_ps(fix2,tx);
627 fiy2 = _mm256_add_ps(fiy2,ty);
628 fiz2 = _mm256_add_ps(fiz2,tz);
630 fjx0 = _mm256_add_ps(fjx0,tx);
631 fjy0 = _mm256_add_ps(fjy0,ty);
632 fjz0 = _mm256_add_ps(fjz0,tz);
636 /**************************
637 * CALCULATE INTERACTIONS *
638 **************************/
640 if (gmx_mm256_any_lt(rsq21,rcutoff2))
643 /* REACTION-FIELD ELECTROSTATICS */
644 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
645 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
647 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
649 /* Update potential sum for this i atom from the interaction with this j atom. */
650 velec = _mm256_and_ps(velec,cutoff_mask);
651 velecsum = _mm256_add_ps(velecsum,velec);
655 fscal = _mm256_and_ps(fscal,cutoff_mask);
657 /* Calculate temporary vectorial force */
658 tx = _mm256_mul_ps(fscal,dx21);
659 ty = _mm256_mul_ps(fscal,dy21);
660 tz = _mm256_mul_ps(fscal,dz21);
662 /* Update vectorial force */
663 fix2 = _mm256_add_ps(fix2,tx);
664 fiy2 = _mm256_add_ps(fiy2,ty);
665 fiz2 = _mm256_add_ps(fiz2,tz);
667 fjx1 = _mm256_add_ps(fjx1,tx);
668 fjy1 = _mm256_add_ps(fjy1,ty);
669 fjz1 = _mm256_add_ps(fjz1,tz);
673 /**************************
674 * CALCULATE INTERACTIONS *
675 **************************/
677 if (gmx_mm256_any_lt(rsq22,rcutoff2))
680 /* REACTION-FIELD ELECTROSTATICS */
681 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
682 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
684 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
686 /* Update potential sum for this i atom from the interaction with this j atom. */
687 velec = _mm256_and_ps(velec,cutoff_mask);
688 velecsum = _mm256_add_ps(velecsum,velec);
692 fscal = _mm256_and_ps(fscal,cutoff_mask);
694 /* Calculate temporary vectorial force */
695 tx = _mm256_mul_ps(fscal,dx22);
696 ty = _mm256_mul_ps(fscal,dy22);
697 tz = _mm256_mul_ps(fscal,dz22);
699 /* Update vectorial force */
700 fix2 = _mm256_add_ps(fix2,tx);
701 fiy2 = _mm256_add_ps(fiy2,ty);
702 fiz2 = _mm256_add_ps(fiz2,tz);
704 fjx2 = _mm256_add_ps(fjx2,tx);
705 fjy2 = _mm256_add_ps(fjy2,ty);
706 fjz2 = _mm256_add_ps(fjz2,tz);
710 fjptrA = f+j_coord_offsetA;
711 fjptrB = f+j_coord_offsetB;
712 fjptrC = f+j_coord_offsetC;
713 fjptrD = f+j_coord_offsetD;
714 fjptrE = f+j_coord_offsetE;
715 fjptrF = f+j_coord_offsetF;
716 fjptrG = f+j_coord_offsetG;
717 fjptrH = f+j_coord_offsetH;
719 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
720 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
722 /* Inner loop uses 360 flops */
728 /* Get j neighbor index, and coordinate index */
729 jnrlistA = jjnr[jidx];
730 jnrlistB = jjnr[jidx+1];
731 jnrlistC = jjnr[jidx+2];
732 jnrlistD = jjnr[jidx+3];
733 jnrlistE = jjnr[jidx+4];
734 jnrlistF = jjnr[jidx+5];
735 jnrlistG = jjnr[jidx+6];
736 jnrlistH = jjnr[jidx+7];
737 /* Sign of each element will be negative for non-real atoms.
738 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
739 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
741 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
742 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
744 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
745 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
746 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
747 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
748 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
749 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
750 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
751 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
752 j_coord_offsetA = DIM*jnrA;
753 j_coord_offsetB = DIM*jnrB;
754 j_coord_offsetC = DIM*jnrC;
755 j_coord_offsetD = DIM*jnrD;
756 j_coord_offsetE = DIM*jnrE;
757 j_coord_offsetF = DIM*jnrF;
758 j_coord_offsetG = DIM*jnrG;
759 j_coord_offsetH = DIM*jnrH;
761 /* load j atom coordinates */
762 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
763 x+j_coord_offsetC,x+j_coord_offsetD,
764 x+j_coord_offsetE,x+j_coord_offsetF,
765 x+j_coord_offsetG,x+j_coord_offsetH,
766 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
768 /* Calculate displacement vector */
769 dx00 = _mm256_sub_ps(ix0,jx0);
770 dy00 = _mm256_sub_ps(iy0,jy0);
771 dz00 = _mm256_sub_ps(iz0,jz0);
772 dx01 = _mm256_sub_ps(ix0,jx1);
773 dy01 = _mm256_sub_ps(iy0,jy1);
774 dz01 = _mm256_sub_ps(iz0,jz1);
775 dx02 = _mm256_sub_ps(ix0,jx2);
776 dy02 = _mm256_sub_ps(iy0,jy2);
777 dz02 = _mm256_sub_ps(iz0,jz2);
778 dx10 = _mm256_sub_ps(ix1,jx0);
779 dy10 = _mm256_sub_ps(iy1,jy0);
780 dz10 = _mm256_sub_ps(iz1,jz0);
781 dx11 = _mm256_sub_ps(ix1,jx1);
782 dy11 = _mm256_sub_ps(iy1,jy1);
783 dz11 = _mm256_sub_ps(iz1,jz1);
784 dx12 = _mm256_sub_ps(ix1,jx2);
785 dy12 = _mm256_sub_ps(iy1,jy2);
786 dz12 = _mm256_sub_ps(iz1,jz2);
787 dx20 = _mm256_sub_ps(ix2,jx0);
788 dy20 = _mm256_sub_ps(iy2,jy0);
789 dz20 = _mm256_sub_ps(iz2,jz0);
790 dx21 = _mm256_sub_ps(ix2,jx1);
791 dy21 = _mm256_sub_ps(iy2,jy1);
792 dz21 = _mm256_sub_ps(iz2,jz1);
793 dx22 = _mm256_sub_ps(ix2,jx2);
794 dy22 = _mm256_sub_ps(iy2,jy2);
795 dz22 = _mm256_sub_ps(iz2,jz2);
797 /* Calculate squared distance and things based on it */
798 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
799 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
800 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
801 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
802 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
803 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
804 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
805 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
806 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
808 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
809 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
810 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
811 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
812 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
813 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
814 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
815 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
816 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
818 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
819 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
820 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
821 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
822 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
823 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
824 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
825 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
826 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
828 fjx0 = _mm256_setzero_ps();
829 fjy0 = _mm256_setzero_ps();
830 fjz0 = _mm256_setzero_ps();
831 fjx1 = _mm256_setzero_ps();
832 fjy1 = _mm256_setzero_ps();
833 fjz1 = _mm256_setzero_ps();
834 fjx2 = _mm256_setzero_ps();
835 fjy2 = _mm256_setzero_ps();
836 fjz2 = _mm256_setzero_ps();
838 /**************************
839 * CALCULATE INTERACTIONS *
840 **************************/
842 if (gmx_mm256_any_lt(rsq00,rcutoff2))
845 r00 = _mm256_mul_ps(rsq00,rinv00);
846 r00 = _mm256_andnot_ps(dummy_mask,r00);
848 /* Calculate table index by multiplying r with table scale and truncate to integer */
849 rt = _mm256_mul_ps(r00,vftabscale);
850 vfitab = _mm256_cvttps_epi32(rt);
851 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
852 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
853 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
854 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
855 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
856 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
858 /* REACTION-FIELD ELECTROSTATICS */
859 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
860 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
862 /* CUBIC SPLINE TABLE DISPERSION */
863 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
864 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
865 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
866 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
867 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
868 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
869 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
870 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
871 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
872 Heps = _mm256_mul_ps(vfeps,H);
873 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
874 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
875 vvdw6 = _mm256_mul_ps(c6_00,VV);
876 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
877 fvdw6 = _mm256_mul_ps(c6_00,FF);
879 /* CUBIC SPLINE TABLE REPULSION */
880 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
881 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
882 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
883 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
884 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
885 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
886 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
887 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
888 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
889 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
890 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
891 Heps = _mm256_mul_ps(vfeps,H);
892 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
893 VV = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
894 vvdw12 = _mm256_mul_ps(c12_00,VV);
895 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
896 fvdw12 = _mm256_mul_ps(c12_00,FF);
897 vvdw = _mm256_add_ps(vvdw12,vvdw6);
898 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
900 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
902 /* Update potential sum for this i atom from the interaction with this j atom. */
903 velec = _mm256_and_ps(velec,cutoff_mask);
904 velec = _mm256_andnot_ps(dummy_mask,velec);
905 velecsum = _mm256_add_ps(velecsum,velec);
906 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
907 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
908 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
910 fscal = _mm256_add_ps(felec,fvdw);
912 fscal = _mm256_and_ps(fscal,cutoff_mask);
914 fscal = _mm256_andnot_ps(dummy_mask,fscal);
916 /* Calculate temporary vectorial force */
917 tx = _mm256_mul_ps(fscal,dx00);
918 ty = _mm256_mul_ps(fscal,dy00);
919 tz = _mm256_mul_ps(fscal,dz00);
921 /* Update vectorial force */
922 fix0 = _mm256_add_ps(fix0,tx);
923 fiy0 = _mm256_add_ps(fiy0,ty);
924 fiz0 = _mm256_add_ps(fiz0,tz);
926 fjx0 = _mm256_add_ps(fjx0,tx);
927 fjy0 = _mm256_add_ps(fjy0,ty);
928 fjz0 = _mm256_add_ps(fjz0,tz);
932 /**************************
933 * CALCULATE INTERACTIONS *
934 **************************/
936 if (gmx_mm256_any_lt(rsq01,rcutoff2))
939 /* REACTION-FIELD ELECTROSTATICS */
940 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
941 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
943 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
945 /* Update potential sum for this i atom from the interaction with this j atom. */
946 velec = _mm256_and_ps(velec,cutoff_mask);
947 velec = _mm256_andnot_ps(dummy_mask,velec);
948 velecsum = _mm256_add_ps(velecsum,velec);
952 fscal = _mm256_and_ps(fscal,cutoff_mask);
954 fscal = _mm256_andnot_ps(dummy_mask,fscal);
956 /* Calculate temporary vectorial force */
957 tx = _mm256_mul_ps(fscal,dx01);
958 ty = _mm256_mul_ps(fscal,dy01);
959 tz = _mm256_mul_ps(fscal,dz01);
961 /* Update vectorial force */
962 fix0 = _mm256_add_ps(fix0,tx);
963 fiy0 = _mm256_add_ps(fiy0,ty);
964 fiz0 = _mm256_add_ps(fiz0,tz);
966 fjx1 = _mm256_add_ps(fjx1,tx);
967 fjy1 = _mm256_add_ps(fjy1,ty);
968 fjz1 = _mm256_add_ps(fjz1,tz);
972 /**************************
973 * CALCULATE INTERACTIONS *
974 **************************/
976 if (gmx_mm256_any_lt(rsq02,rcutoff2))
979 /* REACTION-FIELD ELECTROSTATICS */
980 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
981 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
983 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
985 /* Update potential sum for this i atom from the interaction with this j atom. */
986 velec = _mm256_and_ps(velec,cutoff_mask);
987 velec = _mm256_andnot_ps(dummy_mask,velec);
988 velecsum = _mm256_add_ps(velecsum,velec);
992 fscal = _mm256_and_ps(fscal,cutoff_mask);
994 fscal = _mm256_andnot_ps(dummy_mask,fscal);
996 /* Calculate temporary vectorial force */
997 tx = _mm256_mul_ps(fscal,dx02);
998 ty = _mm256_mul_ps(fscal,dy02);
999 tz = _mm256_mul_ps(fscal,dz02);
1001 /* Update vectorial force */
1002 fix0 = _mm256_add_ps(fix0,tx);
1003 fiy0 = _mm256_add_ps(fiy0,ty);
1004 fiz0 = _mm256_add_ps(fiz0,tz);
1006 fjx2 = _mm256_add_ps(fjx2,tx);
1007 fjy2 = _mm256_add_ps(fjy2,ty);
1008 fjz2 = _mm256_add_ps(fjz2,tz);
1012 /**************************
1013 * CALCULATE INTERACTIONS *
1014 **************************/
1016 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1019 /* REACTION-FIELD ELECTROSTATICS */
1020 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
1021 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1023 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1025 /* Update potential sum for this i atom from the interaction with this j atom. */
1026 velec = _mm256_and_ps(velec,cutoff_mask);
1027 velec = _mm256_andnot_ps(dummy_mask,velec);
1028 velecsum = _mm256_add_ps(velecsum,velec);
1032 fscal = _mm256_and_ps(fscal,cutoff_mask);
1034 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1036 /* Calculate temporary vectorial force */
1037 tx = _mm256_mul_ps(fscal,dx10);
1038 ty = _mm256_mul_ps(fscal,dy10);
1039 tz = _mm256_mul_ps(fscal,dz10);
1041 /* Update vectorial force */
1042 fix1 = _mm256_add_ps(fix1,tx);
1043 fiy1 = _mm256_add_ps(fiy1,ty);
1044 fiz1 = _mm256_add_ps(fiz1,tz);
1046 fjx0 = _mm256_add_ps(fjx0,tx);
1047 fjy0 = _mm256_add_ps(fjy0,ty);
1048 fjz0 = _mm256_add_ps(fjz0,tz);
1052 /**************************
1053 * CALCULATE INTERACTIONS *
1054 **************************/
1056 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1059 /* REACTION-FIELD ELECTROSTATICS */
1060 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
1061 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1063 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1065 /* Update potential sum for this i atom from the interaction with this j atom. */
1066 velec = _mm256_and_ps(velec,cutoff_mask);
1067 velec = _mm256_andnot_ps(dummy_mask,velec);
1068 velecsum = _mm256_add_ps(velecsum,velec);
1072 fscal = _mm256_and_ps(fscal,cutoff_mask);
1074 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1076 /* Calculate temporary vectorial force */
1077 tx = _mm256_mul_ps(fscal,dx11);
1078 ty = _mm256_mul_ps(fscal,dy11);
1079 tz = _mm256_mul_ps(fscal,dz11);
1081 /* Update vectorial force */
1082 fix1 = _mm256_add_ps(fix1,tx);
1083 fiy1 = _mm256_add_ps(fiy1,ty);
1084 fiz1 = _mm256_add_ps(fiz1,tz);
1086 fjx1 = _mm256_add_ps(fjx1,tx);
1087 fjy1 = _mm256_add_ps(fjy1,ty);
1088 fjz1 = _mm256_add_ps(fjz1,tz);
1092 /**************************
1093 * CALCULATE INTERACTIONS *
1094 **************************/
1096 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1099 /* REACTION-FIELD ELECTROSTATICS */
1100 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
1101 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1103 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1105 /* Update potential sum for this i atom from the interaction with this j atom. */
1106 velec = _mm256_and_ps(velec,cutoff_mask);
1107 velec = _mm256_andnot_ps(dummy_mask,velec);
1108 velecsum = _mm256_add_ps(velecsum,velec);
1112 fscal = _mm256_and_ps(fscal,cutoff_mask);
1114 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1116 /* Calculate temporary vectorial force */
1117 tx = _mm256_mul_ps(fscal,dx12);
1118 ty = _mm256_mul_ps(fscal,dy12);
1119 tz = _mm256_mul_ps(fscal,dz12);
1121 /* Update vectorial force */
1122 fix1 = _mm256_add_ps(fix1,tx);
1123 fiy1 = _mm256_add_ps(fiy1,ty);
1124 fiz1 = _mm256_add_ps(fiz1,tz);
1126 fjx2 = _mm256_add_ps(fjx2,tx);
1127 fjy2 = _mm256_add_ps(fjy2,ty);
1128 fjz2 = _mm256_add_ps(fjz2,tz);
1132 /**************************
1133 * CALCULATE INTERACTIONS *
1134 **************************/
1136 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1139 /* REACTION-FIELD ELECTROSTATICS */
1140 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
1141 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1143 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1145 /* Update potential sum for this i atom from the interaction with this j atom. */
1146 velec = _mm256_and_ps(velec,cutoff_mask);
1147 velec = _mm256_andnot_ps(dummy_mask,velec);
1148 velecsum = _mm256_add_ps(velecsum,velec);
1152 fscal = _mm256_and_ps(fscal,cutoff_mask);
1154 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1156 /* Calculate temporary vectorial force */
1157 tx = _mm256_mul_ps(fscal,dx20);
1158 ty = _mm256_mul_ps(fscal,dy20);
1159 tz = _mm256_mul_ps(fscal,dz20);
1161 /* Update vectorial force */
1162 fix2 = _mm256_add_ps(fix2,tx);
1163 fiy2 = _mm256_add_ps(fiy2,ty);
1164 fiz2 = _mm256_add_ps(fiz2,tz);
1166 fjx0 = _mm256_add_ps(fjx0,tx);
1167 fjy0 = _mm256_add_ps(fjy0,ty);
1168 fjz0 = _mm256_add_ps(fjz0,tz);
1172 /**************************
1173 * CALCULATE INTERACTIONS *
1174 **************************/
1176 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1179 /* REACTION-FIELD ELECTROSTATICS */
1180 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1181 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1183 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1185 /* Update potential sum for this i atom from the interaction with this j atom. */
1186 velec = _mm256_and_ps(velec,cutoff_mask);
1187 velec = _mm256_andnot_ps(dummy_mask,velec);
1188 velecsum = _mm256_add_ps(velecsum,velec);
1192 fscal = _mm256_and_ps(fscal,cutoff_mask);
1194 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1196 /* Calculate temporary vectorial force */
1197 tx = _mm256_mul_ps(fscal,dx21);
1198 ty = _mm256_mul_ps(fscal,dy21);
1199 tz = _mm256_mul_ps(fscal,dz21);
1201 /* Update vectorial force */
1202 fix2 = _mm256_add_ps(fix2,tx);
1203 fiy2 = _mm256_add_ps(fiy2,ty);
1204 fiz2 = _mm256_add_ps(fiz2,tz);
1206 fjx1 = _mm256_add_ps(fjx1,tx);
1207 fjy1 = _mm256_add_ps(fjy1,ty);
1208 fjz1 = _mm256_add_ps(fjz1,tz);
1212 /**************************
1213 * CALCULATE INTERACTIONS *
1214 **************************/
1216 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1219 /* REACTION-FIELD ELECTROSTATICS */
1220 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1221 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1223 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1225 /* Update potential sum for this i atom from the interaction with this j atom. */
1226 velec = _mm256_and_ps(velec,cutoff_mask);
1227 velec = _mm256_andnot_ps(dummy_mask,velec);
1228 velecsum = _mm256_add_ps(velecsum,velec);
1232 fscal = _mm256_and_ps(fscal,cutoff_mask);
1234 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1236 /* Calculate temporary vectorial force */
1237 tx = _mm256_mul_ps(fscal,dx22);
1238 ty = _mm256_mul_ps(fscal,dy22);
1239 tz = _mm256_mul_ps(fscal,dz22);
1241 /* Update vectorial force */
1242 fix2 = _mm256_add_ps(fix2,tx);
1243 fiy2 = _mm256_add_ps(fiy2,ty);
1244 fiz2 = _mm256_add_ps(fiz2,tz);
1246 fjx2 = _mm256_add_ps(fjx2,tx);
1247 fjy2 = _mm256_add_ps(fjy2,ty);
1248 fjz2 = _mm256_add_ps(fjz2,tz);
1252 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1253 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1254 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1255 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1256 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1257 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1258 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1259 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1261 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1262 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1264 /* Inner loop uses 361 flops */
1267 /* End of innermost loop */
1269 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1270 f+i_coord_offset,fshift+i_shift_offset);
1273 /* Update potential energies */
1274 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1275 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1277 /* Increment number of inner iterations */
1278 inneriter += j_index_end - j_index_start;
1280 /* Outer loop uses 20 flops */
1283 /* Increment number of outer iterations */
1286 /* Update outer/inner flops */
1288 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*361);
1291 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1292 * Electrostatics interaction: ReactionField
1293 * VdW interaction: CubicSplineTable
1294 * Geometry: Water3-Water3
1295 * Calculate force/pot: Force
1298 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1299 (t_nblist * gmx_restrict nlist,
1300 rvec * gmx_restrict xx,
1301 rvec * gmx_restrict ff,
1302 t_forcerec * gmx_restrict fr,
1303 t_mdatoms * gmx_restrict mdatoms,
1304 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1305 t_nrnb * gmx_restrict nrnb)
1307 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1308 * just 0 for non-waters.
1309 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1310 * jnr indices corresponding to data put in the four positions in the SIMD register.
1312 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1313 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1314 int jnrA,jnrB,jnrC,jnrD;
1315 int jnrE,jnrF,jnrG,jnrH;
1316 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1317 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1318 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1319 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1320 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1321 real rcutoff_scalar;
1322 real *shiftvec,*fshift,*x,*f;
1323 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1324 real scratch[4*DIM];
1325 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1326 real * vdwioffsetptr0;
1327 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1328 real * vdwioffsetptr1;
1329 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1330 real * vdwioffsetptr2;
1331 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1332 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1333 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1334 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1335 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1336 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1337 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1338 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1339 __m256 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1340 __m256 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1341 __m256 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1342 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1343 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1344 __m256 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1345 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1346 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1347 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1350 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1353 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1354 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1356 __m128i vfitab_lo,vfitab_hi;
1357 __m128i ifour = _mm_set1_epi32(4);
1358 __m256 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
1360 __m256 dummy_mask,cutoff_mask;
1361 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1362 __m256 one = _mm256_set1_ps(1.0);
1363 __m256 two = _mm256_set1_ps(2.0);
1369 jindex = nlist->jindex;
1371 shiftidx = nlist->shift;
1373 shiftvec = fr->shift_vec[0];
1374 fshift = fr->fshift[0];
1375 facel = _mm256_set1_ps(fr->epsfac);
1376 charge = mdatoms->chargeA;
1377 krf = _mm256_set1_ps(fr->ic->k_rf);
1378 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1379 crf = _mm256_set1_ps(fr->ic->c_rf);
1380 nvdwtype = fr->ntype;
1381 vdwparam = fr->nbfp;
1382 vdwtype = mdatoms->typeA;
1384 vftab = kernel_data->table_vdw->data;
1385 vftabscale = _mm256_set1_ps(kernel_data->table_vdw->scale);
1387 /* Setup water-specific parameters */
1388 inr = nlist->iinr[0];
1389 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
1390 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1391 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1392 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1394 jq0 = _mm256_set1_ps(charge[inr+0]);
1395 jq1 = _mm256_set1_ps(charge[inr+1]);
1396 jq2 = _mm256_set1_ps(charge[inr+2]);
1397 vdwjidx0A = 2*vdwtype[inr+0];
1398 qq00 = _mm256_mul_ps(iq0,jq0);
1399 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1400 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1401 qq01 = _mm256_mul_ps(iq0,jq1);
1402 qq02 = _mm256_mul_ps(iq0,jq2);
1403 qq10 = _mm256_mul_ps(iq1,jq0);
1404 qq11 = _mm256_mul_ps(iq1,jq1);
1405 qq12 = _mm256_mul_ps(iq1,jq2);
1406 qq20 = _mm256_mul_ps(iq2,jq0);
1407 qq21 = _mm256_mul_ps(iq2,jq1);
1408 qq22 = _mm256_mul_ps(iq2,jq2);
1410 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1411 rcutoff_scalar = fr->rcoulomb;
1412 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1413 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1415 /* Avoid stupid compiler warnings */
1416 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1417 j_coord_offsetA = 0;
1418 j_coord_offsetB = 0;
1419 j_coord_offsetC = 0;
1420 j_coord_offsetD = 0;
1421 j_coord_offsetE = 0;
1422 j_coord_offsetF = 0;
1423 j_coord_offsetG = 0;
1424 j_coord_offsetH = 0;
1429 for(iidx=0;iidx<4*DIM;iidx++)
1431 scratch[iidx] = 0.0;
1434 /* Start outer loop over neighborlists */
1435 for(iidx=0; iidx<nri; iidx++)
1437 /* Load shift vector for this list */
1438 i_shift_offset = DIM*shiftidx[iidx];
1440 /* Load limits for loop over neighbors */
1441 j_index_start = jindex[iidx];
1442 j_index_end = jindex[iidx+1];
1444 /* Get outer coordinate index */
1446 i_coord_offset = DIM*inr;
1448 /* Load i particle coords and add shift vector */
1449 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1450 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1452 fix0 = _mm256_setzero_ps();
1453 fiy0 = _mm256_setzero_ps();
1454 fiz0 = _mm256_setzero_ps();
1455 fix1 = _mm256_setzero_ps();
1456 fiy1 = _mm256_setzero_ps();
1457 fiz1 = _mm256_setzero_ps();
1458 fix2 = _mm256_setzero_ps();
1459 fiy2 = _mm256_setzero_ps();
1460 fiz2 = _mm256_setzero_ps();
1462 /* Start inner kernel loop */
1463 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1466 /* Get j neighbor index, and coordinate index */
1468 jnrB = jjnr[jidx+1];
1469 jnrC = jjnr[jidx+2];
1470 jnrD = jjnr[jidx+3];
1471 jnrE = jjnr[jidx+4];
1472 jnrF = jjnr[jidx+5];
1473 jnrG = jjnr[jidx+6];
1474 jnrH = jjnr[jidx+7];
1475 j_coord_offsetA = DIM*jnrA;
1476 j_coord_offsetB = DIM*jnrB;
1477 j_coord_offsetC = DIM*jnrC;
1478 j_coord_offsetD = DIM*jnrD;
1479 j_coord_offsetE = DIM*jnrE;
1480 j_coord_offsetF = DIM*jnrF;
1481 j_coord_offsetG = DIM*jnrG;
1482 j_coord_offsetH = DIM*jnrH;
1484 /* load j atom coordinates */
1485 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1486 x+j_coord_offsetC,x+j_coord_offsetD,
1487 x+j_coord_offsetE,x+j_coord_offsetF,
1488 x+j_coord_offsetG,x+j_coord_offsetH,
1489 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1491 /* Calculate displacement vector */
1492 dx00 = _mm256_sub_ps(ix0,jx0);
1493 dy00 = _mm256_sub_ps(iy0,jy0);
1494 dz00 = _mm256_sub_ps(iz0,jz0);
1495 dx01 = _mm256_sub_ps(ix0,jx1);
1496 dy01 = _mm256_sub_ps(iy0,jy1);
1497 dz01 = _mm256_sub_ps(iz0,jz1);
1498 dx02 = _mm256_sub_ps(ix0,jx2);
1499 dy02 = _mm256_sub_ps(iy0,jy2);
1500 dz02 = _mm256_sub_ps(iz0,jz2);
1501 dx10 = _mm256_sub_ps(ix1,jx0);
1502 dy10 = _mm256_sub_ps(iy1,jy0);
1503 dz10 = _mm256_sub_ps(iz1,jz0);
1504 dx11 = _mm256_sub_ps(ix1,jx1);
1505 dy11 = _mm256_sub_ps(iy1,jy1);
1506 dz11 = _mm256_sub_ps(iz1,jz1);
1507 dx12 = _mm256_sub_ps(ix1,jx2);
1508 dy12 = _mm256_sub_ps(iy1,jy2);
1509 dz12 = _mm256_sub_ps(iz1,jz2);
1510 dx20 = _mm256_sub_ps(ix2,jx0);
1511 dy20 = _mm256_sub_ps(iy2,jy0);
1512 dz20 = _mm256_sub_ps(iz2,jz0);
1513 dx21 = _mm256_sub_ps(ix2,jx1);
1514 dy21 = _mm256_sub_ps(iy2,jy1);
1515 dz21 = _mm256_sub_ps(iz2,jz1);
1516 dx22 = _mm256_sub_ps(ix2,jx2);
1517 dy22 = _mm256_sub_ps(iy2,jy2);
1518 dz22 = _mm256_sub_ps(iz2,jz2);
1520 /* Calculate squared distance and things based on it */
1521 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1522 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1523 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1524 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1525 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1526 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1527 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1528 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1529 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1531 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1532 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1533 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1534 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1535 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1536 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1537 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
1538 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1539 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1541 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1542 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
1543 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
1544 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
1545 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1546 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1547 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
1548 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1549 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1551 fjx0 = _mm256_setzero_ps();
1552 fjy0 = _mm256_setzero_ps();
1553 fjz0 = _mm256_setzero_ps();
1554 fjx1 = _mm256_setzero_ps();
1555 fjy1 = _mm256_setzero_ps();
1556 fjz1 = _mm256_setzero_ps();
1557 fjx2 = _mm256_setzero_ps();
1558 fjy2 = _mm256_setzero_ps();
1559 fjz2 = _mm256_setzero_ps();
1561 /**************************
1562 * CALCULATE INTERACTIONS *
1563 **************************/
1565 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1568 r00 = _mm256_mul_ps(rsq00,rinv00);
1570 /* Calculate table index by multiplying r with table scale and truncate to integer */
1571 rt = _mm256_mul_ps(r00,vftabscale);
1572 vfitab = _mm256_cvttps_epi32(rt);
1573 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
1574 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
1575 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
1576 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
1577 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
1578 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
1580 /* REACTION-FIELD ELECTROSTATICS */
1581 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1583 /* CUBIC SPLINE TABLE DISPERSION */
1584 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1585 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1586 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1587 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1588 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1589 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1590 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1591 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1592 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1593 Heps = _mm256_mul_ps(vfeps,H);
1594 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1595 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1596 fvdw6 = _mm256_mul_ps(c6_00,FF);
1598 /* CUBIC SPLINE TABLE REPULSION */
1599 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
1600 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
1601 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1602 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1603 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1604 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1605 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1606 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1607 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1608 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1609 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1610 Heps = _mm256_mul_ps(vfeps,H);
1611 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1612 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1613 fvdw12 = _mm256_mul_ps(c12_00,FF);
1614 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
1616 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1618 fscal = _mm256_add_ps(felec,fvdw);
1620 fscal = _mm256_and_ps(fscal,cutoff_mask);
1622 /* Calculate temporary vectorial force */
1623 tx = _mm256_mul_ps(fscal,dx00);
1624 ty = _mm256_mul_ps(fscal,dy00);
1625 tz = _mm256_mul_ps(fscal,dz00);
1627 /* Update vectorial force */
1628 fix0 = _mm256_add_ps(fix0,tx);
1629 fiy0 = _mm256_add_ps(fiy0,ty);
1630 fiz0 = _mm256_add_ps(fiz0,tz);
1632 fjx0 = _mm256_add_ps(fjx0,tx);
1633 fjy0 = _mm256_add_ps(fjy0,ty);
1634 fjz0 = _mm256_add_ps(fjz0,tz);
1638 /**************************
1639 * CALCULATE INTERACTIONS *
1640 **************************/
1642 if (gmx_mm256_any_lt(rsq01,rcutoff2))
1645 /* REACTION-FIELD ELECTROSTATICS */
1646 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1648 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1652 fscal = _mm256_and_ps(fscal,cutoff_mask);
1654 /* Calculate temporary vectorial force */
1655 tx = _mm256_mul_ps(fscal,dx01);
1656 ty = _mm256_mul_ps(fscal,dy01);
1657 tz = _mm256_mul_ps(fscal,dz01);
1659 /* Update vectorial force */
1660 fix0 = _mm256_add_ps(fix0,tx);
1661 fiy0 = _mm256_add_ps(fiy0,ty);
1662 fiz0 = _mm256_add_ps(fiz0,tz);
1664 fjx1 = _mm256_add_ps(fjx1,tx);
1665 fjy1 = _mm256_add_ps(fjy1,ty);
1666 fjz1 = _mm256_add_ps(fjz1,tz);
1670 /**************************
1671 * CALCULATE INTERACTIONS *
1672 **************************/
1674 if (gmx_mm256_any_lt(rsq02,rcutoff2))
1677 /* REACTION-FIELD ELECTROSTATICS */
1678 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1680 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1684 fscal = _mm256_and_ps(fscal,cutoff_mask);
1686 /* Calculate temporary vectorial force */
1687 tx = _mm256_mul_ps(fscal,dx02);
1688 ty = _mm256_mul_ps(fscal,dy02);
1689 tz = _mm256_mul_ps(fscal,dz02);
1691 /* Update vectorial force */
1692 fix0 = _mm256_add_ps(fix0,tx);
1693 fiy0 = _mm256_add_ps(fiy0,ty);
1694 fiz0 = _mm256_add_ps(fiz0,tz);
1696 fjx2 = _mm256_add_ps(fjx2,tx);
1697 fjy2 = _mm256_add_ps(fjy2,ty);
1698 fjz2 = _mm256_add_ps(fjz2,tz);
1702 /**************************
1703 * CALCULATE INTERACTIONS *
1704 **************************/
1706 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1709 /* REACTION-FIELD ELECTROSTATICS */
1710 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1712 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1716 fscal = _mm256_and_ps(fscal,cutoff_mask);
1718 /* Calculate temporary vectorial force */
1719 tx = _mm256_mul_ps(fscal,dx10);
1720 ty = _mm256_mul_ps(fscal,dy10);
1721 tz = _mm256_mul_ps(fscal,dz10);
1723 /* Update vectorial force */
1724 fix1 = _mm256_add_ps(fix1,tx);
1725 fiy1 = _mm256_add_ps(fiy1,ty);
1726 fiz1 = _mm256_add_ps(fiz1,tz);
1728 fjx0 = _mm256_add_ps(fjx0,tx);
1729 fjy0 = _mm256_add_ps(fjy0,ty);
1730 fjz0 = _mm256_add_ps(fjz0,tz);
1734 /**************************
1735 * CALCULATE INTERACTIONS *
1736 **************************/
1738 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1741 /* REACTION-FIELD ELECTROSTATICS */
1742 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1744 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1748 fscal = _mm256_and_ps(fscal,cutoff_mask);
1750 /* Calculate temporary vectorial force */
1751 tx = _mm256_mul_ps(fscal,dx11);
1752 ty = _mm256_mul_ps(fscal,dy11);
1753 tz = _mm256_mul_ps(fscal,dz11);
1755 /* Update vectorial force */
1756 fix1 = _mm256_add_ps(fix1,tx);
1757 fiy1 = _mm256_add_ps(fiy1,ty);
1758 fiz1 = _mm256_add_ps(fiz1,tz);
1760 fjx1 = _mm256_add_ps(fjx1,tx);
1761 fjy1 = _mm256_add_ps(fjy1,ty);
1762 fjz1 = _mm256_add_ps(fjz1,tz);
1766 /**************************
1767 * CALCULATE INTERACTIONS *
1768 **************************/
1770 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1773 /* REACTION-FIELD ELECTROSTATICS */
1774 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1776 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1780 fscal = _mm256_and_ps(fscal,cutoff_mask);
1782 /* Calculate temporary vectorial force */
1783 tx = _mm256_mul_ps(fscal,dx12);
1784 ty = _mm256_mul_ps(fscal,dy12);
1785 tz = _mm256_mul_ps(fscal,dz12);
1787 /* Update vectorial force */
1788 fix1 = _mm256_add_ps(fix1,tx);
1789 fiy1 = _mm256_add_ps(fiy1,ty);
1790 fiz1 = _mm256_add_ps(fiz1,tz);
1792 fjx2 = _mm256_add_ps(fjx2,tx);
1793 fjy2 = _mm256_add_ps(fjy2,ty);
1794 fjz2 = _mm256_add_ps(fjz2,tz);
1798 /**************************
1799 * CALCULATE INTERACTIONS *
1800 **************************/
1802 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1805 /* REACTION-FIELD ELECTROSTATICS */
1806 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1808 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1812 fscal = _mm256_and_ps(fscal,cutoff_mask);
1814 /* Calculate temporary vectorial force */
1815 tx = _mm256_mul_ps(fscal,dx20);
1816 ty = _mm256_mul_ps(fscal,dy20);
1817 tz = _mm256_mul_ps(fscal,dz20);
1819 /* Update vectorial force */
1820 fix2 = _mm256_add_ps(fix2,tx);
1821 fiy2 = _mm256_add_ps(fiy2,ty);
1822 fiz2 = _mm256_add_ps(fiz2,tz);
1824 fjx0 = _mm256_add_ps(fjx0,tx);
1825 fjy0 = _mm256_add_ps(fjy0,ty);
1826 fjz0 = _mm256_add_ps(fjz0,tz);
1830 /**************************
1831 * CALCULATE INTERACTIONS *
1832 **************************/
1834 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1837 /* REACTION-FIELD ELECTROSTATICS */
1838 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1840 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1844 fscal = _mm256_and_ps(fscal,cutoff_mask);
1846 /* Calculate temporary vectorial force */
1847 tx = _mm256_mul_ps(fscal,dx21);
1848 ty = _mm256_mul_ps(fscal,dy21);
1849 tz = _mm256_mul_ps(fscal,dz21);
1851 /* Update vectorial force */
1852 fix2 = _mm256_add_ps(fix2,tx);
1853 fiy2 = _mm256_add_ps(fiy2,ty);
1854 fiz2 = _mm256_add_ps(fiz2,tz);
1856 fjx1 = _mm256_add_ps(fjx1,tx);
1857 fjy1 = _mm256_add_ps(fjy1,ty);
1858 fjz1 = _mm256_add_ps(fjz1,tz);
1862 /**************************
1863 * CALCULATE INTERACTIONS *
1864 **************************/
1866 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1869 /* REACTION-FIELD ELECTROSTATICS */
1870 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1872 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1876 fscal = _mm256_and_ps(fscal,cutoff_mask);
1878 /* Calculate temporary vectorial force */
1879 tx = _mm256_mul_ps(fscal,dx22);
1880 ty = _mm256_mul_ps(fscal,dy22);
1881 tz = _mm256_mul_ps(fscal,dz22);
1883 /* Update vectorial force */
1884 fix2 = _mm256_add_ps(fix2,tx);
1885 fiy2 = _mm256_add_ps(fiy2,ty);
1886 fiz2 = _mm256_add_ps(fiz2,tz);
1888 fjx2 = _mm256_add_ps(fjx2,tx);
1889 fjy2 = _mm256_add_ps(fjy2,ty);
1890 fjz2 = _mm256_add_ps(fjz2,tz);
1894 fjptrA = f+j_coord_offsetA;
1895 fjptrB = f+j_coord_offsetB;
1896 fjptrC = f+j_coord_offsetC;
1897 fjptrD = f+j_coord_offsetD;
1898 fjptrE = f+j_coord_offsetE;
1899 fjptrF = f+j_coord_offsetF;
1900 fjptrG = f+j_coord_offsetG;
1901 fjptrH = f+j_coord_offsetH;
1903 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1904 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1906 /* Inner loop uses 297 flops */
1909 if(jidx<j_index_end)
1912 /* Get j neighbor index, and coordinate index */
1913 jnrlistA = jjnr[jidx];
1914 jnrlistB = jjnr[jidx+1];
1915 jnrlistC = jjnr[jidx+2];
1916 jnrlistD = jjnr[jidx+3];
1917 jnrlistE = jjnr[jidx+4];
1918 jnrlistF = jjnr[jidx+5];
1919 jnrlistG = jjnr[jidx+6];
1920 jnrlistH = jjnr[jidx+7];
1921 /* Sign of each element will be negative for non-real atoms.
1922 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1923 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1925 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1926 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1928 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1929 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1930 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1931 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1932 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
1933 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
1934 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
1935 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
1936 j_coord_offsetA = DIM*jnrA;
1937 j_coord_offsetB = DIM*jnrB;
1938 j_coord_offsetC = DIM*jnrC;
1939 j_coord_offsetD = DIM*jnrD;
1940 j_coord_offsetE = DIM*jnrE;
1941 j_coord_offsetF = DIM*jnrF;
1942 j_coord_offsetG = DIM*jnrG;
1943 j_coord_offsetH = DIM*jnrH;
1945 /* load j atom coordinates */
1946 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1947 x+j_coord_offsetC,x+j_coord_offsetD,
1948 x+j_coord_offsetE,x+j_coord_offsetF,
1949 x+j_coord_offsetG,x+j_coord_offsetH,
1950 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1952 /* Calculate displacement vector */
1953 dx00 = _mm256_sub_ps(ix0,jx0);
1954 dy00 = _mm256_sub_ps(iy0,jy0);
1955 dz00 = _mm256_sub_ps(iz0,jz0);
1956 dx01 = _mm256_sub_ps(ix0,jx1);
1957 dy01 = _mm256_sub_ps(iy0,jy1);
1958 dz01 = _mm256_sub_ps(iz0,jz1);
1959 dx02 = _mm256_sub_ps(ix0,jx2);
1960 dy02 = _mm256_sub_ps(iy0,jy2);
1961 dz02 = _mm256_sub_ps(iz0,jz2);
1962 dx10 = _mm256_sub_ps(ix1,jx0);
1963 dy10 = _mm256_sub_ps(iy1,jy0);
1964 dz10 = _mm256_sub_ps(iz1,jz0);
1965 dx11 = _mm256_sub_ps(ix1,jx1);
1966 dy11 = _mm256_sub_ps(iy1,jy1);
1967 dz11 = _mm256_sub_ps(iz1,jz1);
1968 dx12 = _mm256_sub_ps(ix1,jx2);
1969 dy12 = _mm256_sub_ps(iy1,jy2);
1970 dz12 = _mm256_sub_ps(iz1,jz2);
1971 dx20 = _mm256_sub_ps(ix2,jx0);
1972 dy20 = _mm256_sub_ps(iy2,jy0);
1973 dz20 = _mm256_sub_ps(iz2,jz0);
1974 dx21 = _mm256_sub_ps(ix2,jx1);
1975 dy21 = _mm256_sub_ps(iy2,jy1);
1976 dz21 = _mm256_sub_ps(iz2,jz1);
1977 dx22 = _mm256_sub_ps(ix2,jx2);
1978 dy22 = _mm256_sub_ps(iy2,jy2);
1979 dz22 = _mm256_sub_ps(iz2,jz2);
1981 /* Calculate squared distance and things based on it */
1982 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1983 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1984 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1985 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1986 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1987 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1988 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1989 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1990 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1992 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1993 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1994 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1995 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1996 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1997 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1998 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
1999 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
2000 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
2002 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
2003 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
2004 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
2005 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
2006 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
2007 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
2008 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
2009 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
2010 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
2012 fjx0 = _mm256_setzero_ps();
2013 fjy0 = _mm256_setzero_ps();
2014 fjz0 = _mm256_setzero_ps();
2015 fjx1 = _mm256_setzero_ps();
2016 fjy1 = _mm256_setzero_ps();
2017 fjz1 = _mm256_setzero_ps();
2018 fjx2 = _mm256_setzero_ps();
2019 fjy2 = _mm256_setzero_ps();
2020 fjz2 = _mm256_setzero_ps();
2022 /**************************
2023 * CALCULATE INTERACTIONS *
2024 **************************/
2026 if (gmx_mm256_any_lt(rsq00,rcutoff2))
2029 r00 = _mm256_mul_ps(rsq00,rinv00);
2030 r00 = _mm256_andnot_ps(dummy_mask,r00);
2032 /* Calculate table index by multiplying r with table scale and truncate to integer */
2033 rt = _mm256_mul_ps(r00,vftabscale);
2034 vfitab = _mm256_cvttps_epi32(rt);
2035 vfeps = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
2036 /* AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
2037 vfitab_lo = _mm256_extractf128_si256(vfitab,0x0);
2038 vfitab_hi = _mm256_extractf128_si256(vfitab,0x1);
2039 vfitab_lo = _mm_slli_epi32(vfitab_lo,3);
2040 vfitab_hi = _mm_slli_epi32(vfitab_hi,3);
2042 /* REACTION-FIELD ELECTROSTATICS */
2043 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
2045 /* CUBIC SPLINE TABLE DISPERSION */
2046 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2047 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2048 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2049 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2050 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2051 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2052 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2053 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2054 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2055 Heps = _mm256_mul_ps(vfeps,H);
2056 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2057 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2058 fvdw6 = _mm256_mul_ps(c6_00,FF);
2060 /* CUBIC SPLINE TABLE REPULSION */
2061 vfitab_lo = _mm_add_epi32(vfitab_lo,ifour);
2062 vfitab_hi = _mm_add_epi32(vfitab_hi,ifour);
2063 Y = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2064 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2065 F = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2066 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2067 G = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2068 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2069 H = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2070 _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2071 GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2072 Heps = _mm256_mul_ps(vfeps,H);
2073 Fp = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2074 FF = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2075 fvdw12 = _mm256_mul_ps(c12_00,FF);
2076 fvdw = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
2078 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2080 fscal = _mm256_add_ps(felec,fvdw);
2082 fscal = _mm256_and_ps(fscal,cutoff_mask);
2084 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2086 /* Calculate temporary vectorial force */
2087 tx = _mm256_mul_ps(fscal,dx00);
2088 ty = _mm256_mul_ps(fscal,dy00);
2089 tz = _mm256_mul_ps(fscal,dz00);
2091 /* Update vectorial force */
2092 fix0 = _mm256_add_ps(fix0,tx);
2093 fiy0 = _mm256_add_ps(fiy0,ty);
2094 fiz0 = _mm256_add_ps(fiz0,tz);
2096 fjx0 = _mm256_add_ps(fjx0,tx);
2097 fjy0 = _mm256_add_ps(fjy0,ty);
2098 fjz0 = _mm256_add_ps(fjz0,tz);
2102 /**************************
2103 * CALCULATE INTERACTIONS *
2104 **************************/
2106 if (gmx_mm256_any_lt(rsq01,rcutoff2))
2109 /* REACTION-FIELD ELECTROSTATICS */
2110 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
2112 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
2116 fscal = _mm256_and_ps(fscal,cutoff_mask);
2118 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2120 /* Calculate temporary vectorial force */
2121 tx = _mm256_mul_ps(fscal,dx01);
2122 ty = _mm256_mul_ps(fscal,dy01);
2123 tz = _mm256_mul_ps(fscal,dz01);
2125 /* Update vectorial force */
2126 fix0 = _mm256_add_ps(fix0,tx);
2127 fiy0 = _mm256_add_ps(fiy0,ty);
2128 fiz0 = _mm256_add_ps(fiz0,tz);
2130 fjx1 = _mm256_add_ps(fjx1,tx);
2131 fjy1 = _mm256_add_ps(fjy1,ty);
2132 fjz1 = _mm256_add_ps(fjz1,tz);
2136 /**************************
2137 * CALCULATE INTERACTIONS *
2138 **************************/
2140 if (gmx_mm256_any_lt(rsq02,rcutoff2))
2143 /* REACTION-FIELD ELECTROSTATICS */
2144 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
2146 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
2150 fscal = _mm256_and_ps(fscal,cutoff_mask);
2152 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2154 /* Calculate temporary vectorial force */
2155 tx = _mm256_mul_ps(fscal,dx02);
2156 ty = _mm256_mul_ps(fscal,dy02);
2157 tz = _mm256_mul_ps(fscal,dz02);
2159 /* Update vectorial force */
2160 fix0 = _mm256_add_ps(fix0,tx);
2161 fiy0 = _mm256_add_ps(fiy0,ty);
2162 fiz0 = _mm256_add_ps(fiz0,tz);
2164 fjx2 = _mm256_add_ps(fjx2,tx);
2165 fjy2 = _mm256_add_ps(fjy2,ty);
2166 fjz2 = _mm256_add_ps(fjz2,tz);
2170 /**************************
2171 * CALCULATE INTERACTIONS *
2172 **************************/
2174 if (gmx_mm256_any_lt(rsq10,rcutoff2))
2177 /* REACTION-FIELD ELECTROSTATICS */
2178 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
2180 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
2184 fscal = _mm256_and_ps(fscal,cutoff_mask);
2186 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2188 /* Calculate temporary vectorial force */
2189 tx = _mm256_mul_ps(fscal,dx10);
2190 ty = _mm256_mul_ps(fscal,dy10);
2191 tz = _mm256_mul_ps(fscal,dz10);
2193 /* Update vectorial force */
2194 fix1 = _mm256_add_ps(fix1,tx);
2195 fiy1 = _mm256_add_ps(fiy1,ty);
2196 fiz1 = _mm256_add_ps(fiz1,tz);
2198 fjx0 = _mm256_add_ps(fjx0,tx);
2199 fjy0 = _mm256_add_ps(fjy0,ty);
2200 fjz0 = _mm256_add_ps(fjz0,tz);
2204 /**************************
2205 * CALCULATE INTERACTIONS *
2206 **************************/
2208 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2211 /* REACTION-FIELD ELECTROSTATICS */
2212 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2214 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2218 fscal = _mm256_and_ps(fscal,cutoff_mask);
2220 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2222 /* Calculate temporary vectorial force */
2223 tx = _mm256_mul_ps(fscal,dx11);
2224 ty = _mm256_mul_ps(fscal,dy11);
2225 tz = _mm256_mul_ps(fscal,dz11);
2227 /* Update vectorial force */
2228 fix1 = _mm256_add_ps(fix1,tx);
2229 fiy1 = _mm256_add_ps(fiy1,ty);
2230 fiz1 = _mm256_add_ps(fiz1,tz);
2232 fjx1 = _mm256_add_ps(fjx1,tx);
2233 fjy1 = _mm256_add_ps(fjy1,ty);
2234 fjz1 = _mm256_add_ps(fjz1,tz);
2238 /**************************
2239 * CALCULATE INTERACTIONS *
2240 **************************/
2242 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2245 /* REACTION-FIELD ELECTROSTATICS */
2246 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2248 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2252 fscal = _mm256_and_ps(fscal,cutoff_mask);
2254 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2256 /* Calculate temporary vectorial force */
2257 tx = _mm256_mul_ps(fscal,dx12);
2258 ty = _mm256_mul_ps(fscal,dy12);
2259 tz = _mm256_mul_ps(fscal,dz12);
2261 /* Update vectorial force */
2262 fix1 = _mm256_add_ps(fix1,tx);
2263 fiy1 = _mm256_add_ps(fiy1,ty);
2264 fiz1 = _mm256_add_ps(fiz1,tz);
2266 fjx2 = _mm256_add_ps(fjx2,tx);
2267 fjy2 = _mm256_add_ps(fjy2,ty);
2268 fjz2 = _mm256_add_ps(fjz2,tz);
2272 /**************************
2273 * CALCULATE INTERACTIONS *
2274 **************************/
2276 if (gmx_mm256_any_lt(rsq20,rcutoff2))
2279 /* REACTION-FIELD ELECTROSTATICS */
2280 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
2282 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
2286 fscal = _mm256_and_ps(fscal,cutoff_mask);
2288 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2290 /* Calculate temporary vectorial force */
2291 tx = _mm256_mul_ps(fscal,dx20);
2292 ty = _mm256_mul_ps(fscal,dy20);
2293 tz = _mm256_mul_ps(fscal,dz20);
2295 /* Update vectorial force */
2296 fix2 = _mm256_add_ps(fix2,tx);
2297 fiy2 = _mm256_add_ps(fiy2,ty);
2298 fiz2 = _mm256_add_ps(fiz2,tz);
2300 fjx0 = _mm256_add_ps(fjx0,tx);
2301 fjy0 = _mm256_add_ps(fjy0,ty);
2302 fjz0 = _mm256_add_ps(fjz0,tz);
2306 /**************************
2307 * CALCULATE INTERACTIONS *
2308 **************************/
2310 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2313 /* REACTION-FIELD ELECTROSTATICS */
2314 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2316 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2320 fscal = _mm256_and_ps(fscal,cutoff_mask);
2322 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2324 /* Calculate temporary vectorial force */
2325 tx = _mm256_mul_ps(fscal,dx21);
2326 ty = _mm256_mul_ps(fscal,dy21);
2327 tz = _mm256_mul_ps(fscal,dz21);
2329 /* Update vectorial force */
2330 fix2 = _mm256_add_ps(fix2,tx);
2331 fiy2 = _mm256_add_ps(fiy2,ty);
2332 fiz2 = _mm256_add_ps(fiz2,tz);
2334 fjx1 = _mm256_add_ps(fjx1,tx);
2335 fjy1 = _mm256_add_ps(fjy1,ty);
2336 fjz1 = _mm256_add_ps(fjz1,tz);
2340 /**************************
2341 * CALCULATE INTERACTIONS *
2342 **************************/
2344 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2347 /* REACTION-FIELD ELECTROSTATICS */
2348 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2350 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2354 fscal = _mm256_and_ps(fscal,cutoff_mask);
2356 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2358 /* Calculate temporary vectorial force */
2359 tx = _mm256_mul_ps(fscal,dx22);
2360 ty = _mm256_mul_ps(fscal,dy22);
2361 tz = _mm256_mul_ps(fscal,dz22);
2363 /* Update vectorial force */
2364 fix2 = _mm256_add_ps(fix2,tx);
2365 fiy2 = _mm256_add_ps(fiy2,ty);
2366 fiz2 = _mm256_add_ps(fiz2,tz);
2368 fjx2 = _mm256_add_ps(fjx2,tx);
2369 fjy2 = _mm256_add_ps(fjy2,ty);
2370 fjz2 = _mm256_add_ps(fjz2,tz);
2374 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2375 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2376 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2377 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2378 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2379 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2380 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2381 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2383 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2384 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2386 /* Inner loop uses 298 flops */
2389 /* End of innermost loop */
2391 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2392 f+i_coord_offset,fshift+i_shift_offset);
2394 /* Increment number of inner iterations */
2395 inneriter += j_index_end - j_index_start;
2397 /* Outer loop uses 18 flops */
2400 /* Increment number of outer iterations */
2403 /* Update outer/inner flops */
2405 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);