2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_256_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_VF_avx_256_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwLJSw_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);
117 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
118 real rswitch_scalar,d_scalar;
119 __m256 dummy_mask,cutoff_mask;
120 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
121 __m256 one = _mm256_set1_ps(1.0);
122 __m256 two = _mm256_set1_ps(2.0);
128 jindex = nlist->jindex;
130 shiftidx = nlist->shift;
132 shiftvec = fr->shift_vec[0];
133 fshift = fr->fshift[0];
134 facel = _mm256_set1_ps(fr->epsfac);
135 charge = mdatoms->chargeA;
136 krf = _mm256_set1_ps(fr->ic->k_rf);
137 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
138 crf = _mm256_set1_ps(fr->ic->c_rf);
139 nvdwtype = fr->ntype;
141 vdwtype = mdatoms->typeA;
143 /* Setup water-specific parameters */
144 inr = nlist->iinr[0];
145 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
146 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
147 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
148 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
150 jq0 = _mm256_set1_ps(charge[inr+0]);
151 jq1 = _mm256_set1_ps(charge[inr+1]);
152 jq2 = _mm256_set1_ps(charge[inr+2]);
153 vdwjidx0A = 2*vdwtype[inr+0];
154 qq00 = _mm256_mul_ps(iq0,jq0);
155 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
156 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
157 qq01 = _mm256_mul_ps(iq0,jq1);
158 qq02 = _mm256_mul_ps(iq0,jq2);
159 qq10 = _mm256_mul_ps(iq1,jq0);
160 qq11 = _mm256_mul_ps(iq1,jq1);
161 qq12 = _mm256_mul_ps(iq1,jq2);
162 qq20 = _mm256_mul_ps(iq2,jq0);
163 qq21 = _mm256_mul_ps(iq2,jq1);
164 qq22 = _mm256_mul_ps(iq2,jq2);
166 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
167 rcutoff_scalar = fr->rcoulomb;
168 rcutoff = _mm256_set1_ps(rcutoff_scalar);
169 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
171 rswitch_scalar = fr->rvdw_switch;
172 rswitch = _mm256_set1_ps(rswitch_scalar);
173 /* Setup switch parameters */
174 d_scalar = rcutoff_scalar-rswitch_scalar;
175 d = _mm256_set1_ps(d_scalar);
176 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
177 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
178 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
179 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
180 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
181 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
183 /* Avoid stupid compiler warnings */
184 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
197 for(iidx=0;iidx<4*DIM;iidx++)
202 /* Start outer loop over neighborlists */
203 for(iidx=0; iidx<nri; iidx++)
205 /* Load shift vector for this list */
206 i_shift_offset = DIM*shiftidx[iidx];
208 /* Load limits for loop over neighbors */
209 j_index_start = jindex[iidx];
210 j_index_end = jindex[iidx+1];
212 /* Get outer coordinate index */
214 i_coord_offset = DIM*inr;
216 /* Load i particle coords and add shift vector */
217 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
218 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
220 fix0 = _mm256_setzero_ps();
221 fiy0 = _mm256_setzero_ps();
222 fiz0 = _mm256_setzero_ps();
223 fix1 = _mm256_setzero_ps();
224 fiy1 = _mm256_setzero_ps();
225 fiz1 = _mm256_setzero_ps();
226 fix2 = _mm256_setzero_ps();
227 fiy2 = _mm256_setzero_ps();
228 fiz2 = _mm256_setzero_ps();
230 /* Reset potential sums */
231 velecsum = _mm256_setzero_ps();
232 vvdwsum = _mm256_setzero_ps();
234 /* Start inner kernel loop */
235 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
238 /* Get j neighbor index, and coordinate index */
247 j_coord_offsetA = DIM*jnrA;
248 j_coord_offsetB = DIM*jnrB;
249 j_coord_offsetC = DIM*jnrC;
250 j_coord_offsetD = DIM*jnrD;
251 j_coord_offsetE = DIM*jnrE;
252 j_coord_offsetF = DIM*jnrF;
253 j_coord_offsetG = DIM*jnrG;
254 j_coord_offsetH = DIM*jnrH;
256 /* load j atom coordinates */
257 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
258 x+j_coord_offsetC,x+j_coord_offsetD,
259 x+j_coord_offsetE,x+j_coord_offsetF,
260 x+j_coord_offsetG,x+j_coord_offsetH,
261 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
263 /* Calculate displacement vector */
264 dx00 = _mm256_sub_ps(ix0,jx0);
265 dy00 = _mm256_sub_ps(iy0,jy0);
266 dz00 = _mm256_sub_ps(iz0,jz0);
267 dx01 = _mm256_sub_ps(ix0,jx1);
268 dy01 = _mm256_sub_ps(iy0,jy1);
269 dz01 = _mm256_sub_ps(iz0,jz1);
270 dx02 = _mm256_sub_ps(ix0,jx2);
271 dy02 = _mm256_sub_ps(iy0,jy2);
272 dz02 = _mm256_sub_ps(iz0,jz2);
273 dx10 = _mm256_sub_ps(ix1,jx0);
274 dy10 = _mm256_sub_ps(iy1,jy0);
275 dz10 = _mm256_sub_ps(iz1,jz0);
276 dx11 = _mm256_sub_ps(ix1,jx1);
277 dy11 = _mm256_sub_ps(iy1,jy1);
278 dz11 = _mm256_sub_ps(iz1,jz1);
279 dx12 = _mm256_sub_ps(ix1,jx2);
280 dy12 = _mm256_sub_ps(iy1,jy2);
281 dz12 = _mm256_sub_ps(iz1,jz2);
282 dx20 = _mm256_sub_ps(ix2,jx0);
283 dy20 = _mm256_sub_ps(iy2,jy0);
284 dz20 = _mm256_sub_ps(iz2,jz0);
285 dx21 = _mm256_sub_ps(ix2,jx1);
286 dy21 = _mm256_sub_ps(iy2,jy1);
287 dz21 = _mm256_sub_ps(iz2,jz1);
288 dx22 = _mm256_sub_ps(ix2,jx2);
289 dy22 = _mm256_sub_ps(iy2,jy2);
290 dz22 = _mm256_sub_ps(iz2,jz2);
292 /* Calculate squared distance and things based on it */
293 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
294 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
295 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
296 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
297 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
298 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
299 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
300 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
301 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
303 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
304 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
305 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
306 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
307 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
308 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
309 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
310 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
311 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
313 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
314 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
315 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
316 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
317 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
318 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
319 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
320 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
321 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
323 fjx0 = _mm256_setzero_ps();
324 fjy0 = _mm256_setzero_ps();
325 fjz0 = _mm256_setzero_ps();
326 fjx1 = _mm256_setzero_ps();
327 fjy1 = _mm256_setzero_ps();
328 fjz1 = _mm256_setzero_ps();
329 fjx2 = _mm256_setzero_ps();
330 fjy2 = _mm256_setzero_ps();
331 fjz2 = _mm256_setzero_ps();
333 /**************************
334 * CALCULATE INTERACTIONS *
335 **************************/
337 if (gmx_mm256_any_lt(rsq00,rcutoff2))
340 r00 = _mm256_mul_ps(rsq00,rinv00);
342 /* REACTION-FIELD ELECTROSTATICS */
343 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
344 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
346 /* LENNARD-JONES DISPERSION/REPULSION */
348 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
349 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
350 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
351 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
352 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
354 d = _mm256_sub_ps(r00,rswitch);
355 d = _mm256_max_ps(d,_mm256_setzero_ps());
356 d2 = _mm256_mul_ps(d,d);
357 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
359 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
361 /* Evaluate switch function */
362 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
363 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
364 vvdw = _mm256_mul_ps(vvdw,sw);
365 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
367 /* Update potential sum for this i atom from the interaction with this j atom. */
368 velec = _mm256_and_ps(velec,cutoff_mask);
369 velecsum = _mm256_add_ps(velecsum,velec);
370 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
371 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
373 fscal = _mm256_add_ps(felec,fvdw);
375 fscal = _mm256_and_ps(fscal,cutoff_mask);
377 /* Calculate temporary vectorial force */
378 tx = _mm256_mul_ps(fscal,dx00);
379 ty = _mm256_mul_ps(fscal,dy00);
380 tz = _mm256_mul_ps(fscal,dz00);
382 /* Update vectorial force */
383 fix0 = _mm256_add_ps(fix0,tx);
384 fiy0 = _mm256_add_ps(fiy0,ty);
385 fiz0 = _mm256_add_ps(fiz0,tz);
387 fjx0 = _mm256_add_ps(fjx0,tx);
388 fjy0 = _mm256_add_ps(fjy0,ty);
389 fjz0 = _mm256_add_ps(fjz0,tz);
393 /**************************
394 * CALCULATE INTERACTIONS *
395 **************************/
397 if (gmx_mm256_any_lt(rsq01,rcutoff2))
400 /* REACTION-FIELD ELECTROSTATICS */
401 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
402 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
404 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
406 /* Update potential sum for this i atom from the interaction with this j atom. */
407 velec = _mm256_and_ps(velec,cutoff_mask);
408 velecsum = _mm256_add_ps(velecsum,velec);
412 fscal = _mm256_and_ps(fscal,cutoff_mask);
414 /* Calculate temporary vectorial force */
415 tx = _mm256_mul_ps(fscal,dx01);
416 ty = _mm256_mul_ps(fscal,dy01);
417 tz = _mm256_mul_ps(fscal,dz01);
419 /* Update vectorial force */
420 fix0 = _mm256_add_ps(fix0,tx);
421 fiy0 = _mm256_add_ps(fiy0,ty);
422 fiz0 = _mm256_add_ps(fiz0,tz);
424 fjx1 = _mm256_add_ps(fjx1,tx);
425 fjy1 = _mm256_add_ps(fjy1,ty);
426 fjz1 = _mm256_add_ps(fjz1,tz);
430 /**************************
431 * CALCULATE INTERACTIONS *
432 **************************/
434 if (gmx_mm256_any_lt(rsq02,rcutoff2))
437 /* REACTION-FIELD ELECTROSTATICS */
438 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
439 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
441 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
443 /* Update potential sum for this i atom from the interaction with this j atom. */
444 velec = _mm256_and_ps(velec,cutoff_mask);
445 velecsum = _mm256_add_ps(velecsum,velec);
449 fscal = _mm256_and_ps(fscal,cutoff_mask);
451 /* Calculate temporary vectorial force */
452 tx = _mm256_mul_ps(fscal,dx02);
453 ty = _mm256_mul_ps(fscal,dy02);
454 tz = _mm256_mul_ps(fscal,dz02);
456 /* Update vectorial force */
457 fix0 = _mm256_add_ps(fix0,tx);
458 fiy0 = _mm256_add_ps(fiy0,ty);
459 fiz0 = _mm256_add_ps(fiz0,tz);
461 fjx2 = _mm256_add_ps(fjx2,tx);
462 fjy2 = _mm256_add_ps(fjy2,ty);
463 fjz2 = _mm256_add_ps(fjz2,tz);
467 /**************************
468 * CALCULATE INTERACTIONS *
469 **************************/
471 if (gmx_mm256_any_lt(rsq10,rcutoff2))
474 /* REACTION-FIELD ELECTROSTATICS */
475 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
476 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
478 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
480 /* Update potential sum for this i atom from the interaction with this j atom. */
481 velec = _mm256_and_ps(velec,cutoff_mask);
482 velecsum = _mm256_add_ps(velecsum,velec);
486 fscal = _mm256_and_ps(fscal,cutoff_mask);
488 /* Calculate temporary vectorial force */
489 tx = _mm256_mul_ps(fscal,dx10);
490 ty = _mm256_mul_ps(fscal,dy10);
491 tz = _mm256_mul_ps(fscal,dz10);
493 /* Update vectorial force */
494 fix1 = _mm256_add_ps(fix1,tx);
495 fiy1 = _mm256_add_ps(fiy1,ty);
496 fiz1 = _mm256_add_ps(fiz1,tz);
498 fjx0 = _mm256_add_ps(fjx0,tx);
499 fjy0 = _mm256_add_ps(fjy0,ty);
500 fjz0 = _mm256_add_ps(fjz0,tz);
504 /**************************
505 * CALCULATE INTERACTIONS *
506 **************************/
508 if (gmx_mm256_any_lt(rsq11,rcutoff2))
511 /* REACTION-FIELD ELECTROSTATICS */
512 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
513 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
515 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
517 /* Update potential sum for this i atom from the interaction with this j atom. */
518 velec = _mm256_and_ps(velec,cutoff_mask);
519 velecsum = _mm256_add_ps(velecsum,velec);
523 fscal = _mm256_and_ps(fscal,cutoff_mask);
525 /* Calculate temporary vectorial force */
526 tx = _mm256_mul_ps(fscal,dx11);
527 ty = _mm256_mul_ps(fscal,dy11);
528 tz = _mm256_mul_ps(fscal,dz11);
530 /* Update vectorial force */
531 fix1 = _mm256_add_ps(fix1,tx);
532 fiy1 = _mm256_add_ps(fiy1,ty);
533 fiz1 = _mm256_add_ps(fiz1,tz);
535 fjx1 = _mm256_add_ps(fjx1,tx);
536 fjy1 = _mm256_add_ps(fjy1,ty);
537 fjz1 = _mm256_add_ps(fjz1,tz);
541 /**************************
542 * CALCULATE INTERACTIONS *
543 **************************/
545 if (gmx_mm256_any_lt(rsq12,rcutoff2))
548 /* REACTION-FIELD ELECTROSTATICS */
549 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
550 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
552 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
554 /* Update potential sum for this i atom from the interaction with this j atom. */
555 velec = _mm256_and_ps(velec,cutoff_mask);
556 velecsum = _mm256_add_ps(velecsum,velec);
560 fscal = _mm256_and_ps(fscal,cutoff_mask);
562 /* Calculate temporary vectorial force */
563 tx = _mm256_mul_ps(fscal,dx12);
564 ty = _mm256_mul_ps(fscal,dy12);
565 tz = _mm256_mul_ps(fscal,dz12);
567 /* Update vectorial force */
568 fix1 = _mm256_add_ps(fix1,tx);
569 fiy1 = _mm256_add_ps(fiy1,ty);
570 fiz1 = _mm256_add_ps(fiz1,tz);
572 fjx2 = _mm256_add_ps(fjx2,tx);
573 fjy2 = _mm256_add_ps(fjy2,ty);
574 fjz2 = _mm256_add_ps(fjz2,tz);
578 /**************************
579 * CALCULATE INTERACTIONS *
580 **************************/
582 if (gmx_mm256_any_lt(rsq20,rcutoff2))
585 /* REACTION-FIELD ELECTROSTATICS */
586 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
587 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
589 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
591 /* Update potential sum for this i atom from the interaction with this j atom. */
592 velec = _mm256_and_ps(velec,cutoff_mask);
593 velecsum = _mm256_add_ps(velecsum,velec);
597 fscal = _mm256_and_ps(fscal,cutoff_mask);
599 /* Calculate temporary vectorial force */
600 tx = _mm256_mul_ps(fscal,dx20);
601 ty = _mm256_mul_ps(fscal,dy20);
602 tz = _mm256_mul_ps(fscal,dz20);
604 /* Update vectorial force */
605 fix2 = _mm256_add_ps(fix2,tx);
606 fiy2 = _mm256_add_ps(fiy2,ty);
607 fiz2 = _mm256_add_ps(fiz2,tz);
609 fjx0 = _mm256_add_ps(fjx0,tx);
610 fjy0 = _mm256_add_ps(fjy0,ty);
611 fjz0 = _mm256_add_ps(fjz0,tz);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm256_any_lt(rsq21,rcutoff2))
622 /* REACTION-FIELD ELECTROSTATICS */
623 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
624 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
626 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
628 /* Update potential sum for this i atom from the interaction with this j atom. */
629 velec = _mm256_and_ps(velec,cutoff_mask);
630 velecsum = _mm256_add_ps(velecsum,velec);
634 fscal = _mm256_and_ps(fscal,cutoff_mask);
636 /* Calculate temporary vectorial force */
637 tx = _mm256_mul_ps(fscal,dx21);
638 ty = _mm256_mul_ps(fscal,dy21);
639 tz = _mm256_mul_ps(fscal,dz21);
641 /* Update vectorial force */
642 fix2 = _mm256_add_ps(fix2,tx);
643 fiy2 = _mm256_add_ps(fiy2,ty);
644 fiz2 = _mm256_add_ps(fiz2,tz);
646 fjx1 = _mm256_add_ps(fjx1,tx);
647 fjy1 = _mm256_add_ps(fjy1,ty);
648 fjz1 = _mm256_add_ps(fjz1,tz);
652 /**************************
653 * CALCULATE INTERACTIONS *
654 **************************/
656 if (gmx_mm256_any_lt(rsq22,rcutoff2))
659 /* REACTION-FIELD ELECTROSTATICS */
660 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
661 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
663 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
665 /* Update potential sum for this i atom from the interaction with this j atom. */
666 velec = _mm256_and_ps(velec,cutoff_mask);
667 velecsum = _mm256_add_ps(velecsum,velec);
671 fscal = _mm256_and_ps(fscal,cutoff_mask);
673 /* Calculate temporary vectorial force */
674 tx = _mm256_mul_ps(fscal,dx22);
675 ty = _mm256_mul_ps(fscal,dy22);
676 tz = _mm256_mul_ps(fscal,dz22);
678 /* Update vectorial force */
679 fix2 = _mm256_add_ps(fix2,tx);
680 fiy2 = _mm256_add_ps(fiy2,ty);
681 fiz2 = _mm256_add_ps(fiz2,tz);
683 fjx2 = _mm256_add_ps(fjx2,tx);
684 fjy2 = _mm256_add_ps(fjy2,ty);
685 fjz2 = _mm256_add_ps(fjz2,tz);
689 fjptrA = f+j_coord_offsetA;
690 fjptrB = f+j_coord_offsetB;
691 fjptrC = f+j_coord_offsetC;
692 fjptrD = f+j_coord_offsetD;
693 fjptrE = f+j_coord_offsetE;
694 fjptrF = f+j_coord_offsetF;
695 fjptrG = f+j_coord_offsetG;
696 fjptrH = f+j_coord_offsetH;
698 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
699 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
701 /* Inner loop uses 358 flops */
707 /* Get j neighbor index, and coordinate index */
708 jnrlistA = jjnr[jidx];
709 jnrlistB = jjnr[jidx+1];
710 jnrlistC = jjnr[jidx+2];
711 jnrlistD = jjnr[jidx+3];
712 jnrlistE = jjnr[jidx+4];
713 jnrlistF = jjnr[jidx+5];
714 jnrlistG = jjnr[jidx+6];
715 jnrlistH = jjnr[jidx+7];
716 /* Sign of each element will be negative for non-real atoms.
717 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
718 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
720 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
721 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
723 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
724 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
725 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
726 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
727 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
728 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
729 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
730 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
731 j_coord_offsetA = DIM*jnrA;
732 j_coord_offsetB = DIM*jnrB;
733 j_coord_offsetC = DIM*jnrC;
734 j_coord_offsetD = DIM*jnrD;
735 j_coord_offsetE = DIM*jnrE;
736 j_coord_offsetF = DIM*jnrF;
737 j_coord_offsetG = DIM*jnrG;
738 j_coord_offsetH = DIM*jnrH;
740 /* load j atom coordinates */
741 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
742 x+j_coord_offsetC,x+j_coord_offsetD,
743 x+j_coord_offsetE,x+j_coord_offsetF,
744 x+j_coord_offsetG,x+j_coord_offsetH,
745 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
747 /* Calculate displacement vector */
748 dx00 = _mm256_sub_ps(ix0,jx0);
749 dy00 = _mm256_sub_ps(iy0,jy0);
750 dz00 = _mm256_sub_ps(iz0,jz0);
751 dx01 = _mm256_sub_ps(ix0,jx1);
752 dy01 = _mm256_sub_ps(iy0,jy1);
753 dz01 = _mm256_sub_ps(iz0,jz1);
754 dx02 = _mm256_sub_ps(ix0,jx2);
755 dy02 = _mm256_sub_ps(iy0,jy2);
756 dz02 = _mm256_sub_ps(iz0,jz2);
757 dx10 = _mm256_sub_ps(ix1,jx0);
758 dy10 = _mm256_sub_ps(iy1,jy0);
759 dz10 = _mm256_sub_ps(iz1,jz0);
760 dx11 = _mm256_sub_ps(ix1,jx1);
761 dy11 = _mm256_sub_ps(iy1,jy1);
762 dz11 = _mm256_sub_ps(iz1,jz1);
763 dx12 = _mm256_sub_ps(ix1,jx2);
764 dy12 = _mm256_sub_ps(iy1,jy2);
765 dz12 = _mm256_sub_ps(iz1,jz2);
766 dx20 = _mm256_sub_ps(ix2,jx0);
767 dy20 = _mm256_sub_ps(iy2,jy0);
768 dz20 = _mm256_sub_ps(iz2,jz0);
769 dx21 = _mm256_sub_ps(ix2,jx1);
770 dy21 = _mm256_sub_ps(iy2,jy1);
771 dz21 = _mm256_sub_ps(iz2,jz1);
772 dx22 = _mm256_sub_ps(ix2,jx2);
773 dy22 = _mm256_sub_ps(iy2,jy2);
774 dz22 = _mm256_sub_ps(iz2,jz2);
776 /* Calculate squared distance and things based on it */
777 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
778 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
779 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
780 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
781 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
782 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
783 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
784 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
785 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
787 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
788 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
789 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
790 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
791 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
792 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
793 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
794 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
795 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
797 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
798 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
799 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
800 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
801 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
802 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
803 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
804 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
805 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
807 fjx0 = _mm256_setzero_ps();
808 fjy0 = _mm256_setzero_ps();
809 fjz0 = _mm256_setzero_ps();
810 fjx1 = _mm256_setzero_ps();
811 fjy1 = _mm256_setzero_ps();
812 fjz1 = _mm256_setzero_ps();
813 fjx2 = _mm256_setzero_ps();
814 fjy2 = _mm256_setzero_ps();
815 fjz2 = _mm256_setzero_ps();
817 /**************************
818 * CALCULATE INTERACTIONS *
819 **************************/
821 if (gmx_mm256_any_lt(rsq00,rcutoff2))
824 r00 = _mm256_mul_ps(rsq00,rinv00);
825 r00 = _mm256_andnot_ps(dummy_mask,r00);
827 /* REACTION-FIELD ELECTROSTATICS */
828 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
829 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
831 /* LENNARD-JONES DISPERSION/REPULSION */
833 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
834 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
835 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
836 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
837 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
839 d = _mm256_sub_ps(r00,rswitch);
840 d = _mm256_max_ps(d,_mm256_setzero_ps());
841 d2 = _mm256_mul_ps(d,d);
842 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
844 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
846 /* Evaluate switch function */
847 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
848 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
849 vvdw = _mm256_mul_ps(vvdw,sw);
850 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
852 /* Update potential sum for this i atom from the interaction with this j atom. */
853 velec = _mm256_and_ps(velec,cutoff_mask);
854 velec = _mm256_andnot_ps(dummy_mask,velec);
855 velecsum = _mm256_add_ps(velecsum,velec);
856 vvdw = _mm256_and_ps(vvdw,cutoff_mask);
857 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
858 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
860 fscal = _mm256_add_ps(felec,fvdw);
862 fscal = _mm256_and_ps(fscal,cutoff_mask);
864 fscal = _mm256_andnot_ps(dummy_mask,fscal);
866 /* Calculate temporary vectorial force */
867 tx = _mm256_mul_ps(fscal,dx00);
868 ty = _mm256_mul_ps(fscal,dy00);
869 tz = _mm256_mul_ps(fscal,dz00);
871 /* Update vectorial force */
872 fix0 = _mm256_add_ps(fix0,tx);
873 fiy0 = _mm256_add_ps(fiy0,ty);
874 fiz0 = _mm256_add_ps(fiz0,tz);
876 fjx0 = _mm256_add_ps(fjx0,tx);
877 fjy0 = _mm256_add_ps(fjy0,ty);
878 fjz0 = _mm256_add_ps(fjz0,tz);
882 /**************************
883 * CALCULATE INTERACTIONS *
884 **************************/
886 if (gmx_mm256_any_lt(rsq01,rcutoff2))
889 /* REACTION-FIELD ELECTROSTATICS */
890 velec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
891 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
893 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
895 /* Update potential sum for this i atom from the interaction with this j atom. */
896 velec = _mm256_and_ps(velec,cutoff_mask);
897 velec = _mm256_andnot_ps(dummy_mask,velec);
898 velecsum = _mm256_add_ps(velecsum,velec);
902 fscal = _mm256_and_ps(fscal,cutoff_mask);
904 fscal = _mm256_andnot_ps(dummy_mask,fscal);
906 /* Calculate temporary vectorial force */
907 tx = _mm256_mul_ps(fscal,dx01);
908 ty = _mm256_mul_ps(fscal,dy01);
909 tz = _mm256_mul_ps(fscal,dz01);
911 /* Update vectorial force */
912 fix0 = _mm256_add_ps(fix0,tx);
913 fiy0 = _mm256_add_ps(fiy0,ty);
914 fiz0 = _mm256_add_ps(fiz0,tz);
916 fjx1 = _mm256_add_ps(fjx1,tx);
917 fjy1 = _mm256_add_ps(fjy1,ty);
918 fjz1 = _mm256_add_ps(fjz1,tz);
922 /**************************
923 * CALCULATE INTERACTIONS *
924 **************************/
926 if (gmx_mm256_any_lt(rsq02,rcutoff2))
929 /* REACTION-FIELD ELECTROSTATICS */
930 velec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
931 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
933 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
935 /* Update potential sum for this i atom from the interaction with this j atom. */
936 velec = _mm256_and_ps(velec,cutoff_mask);
937 velec = _mm256_andnot_ps(dummy_mask,velec);
938 velecsum = _mm256_add_ps(velecsum,velec);
942 fscal = _mm256_and_ps(fscal,cutoff_mask);
944 fscal = _mm256_andnot_ps(dummy_mask,fscal);
946 /* Calculate temporary vectorial force */
947 tx = _mm256_mul_ps(fscal,dx02);
948 ty = _mm256_mul_ps(fscal,dy02);
949 tz = _mm256_mul_ps(fscal,dz02);
951 /* Update vectorial force */
952 fix0 = _mm256_add_ps(fix0,tx);
953 fiy0 = _mm256_add_ps(fiy0,ty);
954 fiz0 = _mm256_add_ps(fiz0,tz);
956 fjx2 = _mm256_add_ps(fjx2,tx);
957 fjy2 = _mm256_add_ps(fjy2,ty);
958 fjz2 = _mm256_add_ps(fjz2,tz);
962 /**************************
963 * CALCULATE INTERACTIONS *
964 **************************/
966 if (gmx_mm256_any_lt(rsq10,rcutoff2))
969 /* REACTION-FIELD ELECTROSTATICS */
970 velec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
971 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
973 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
975 /* Update potential sum for this i atom from the interaction with this j atom. */
976 velec = _mm256_and_ps(velec,cutoff_mask);
977 velec = _mm256_andnot_ps(dummy_mask,velec);
978 velecsum = _mm256_add_ps(velecsum,velec);
982 fscal = _mm256_and_ps(fscal,cutoff_mask);
984 fscal = _mm256_andnot_ps(dummy_mask,fscal);
986 /* Calculate temporary vectorial force */
987 tx = _mm256_mul_ps(fscal,dx10);
988 ty = _mm256_mul_ps(fscal,dy10);
989 tz = _mm256_mul_ps(fscal,dz10);
991 /* Update vectorial force */
992 fix1 = _mm256_add_ps(fix1,tx);
993 fiy1 = _mm256_add_ps(fiy1,ty);
994 fiz1 = _mm256_add_ps(fiz1,tz);
996 fjx0 = _mm256_add_ps(fjx0,tx);
997 fjy0 = _mm256_add_ps(fjy0,ty);
998 fjz0 = _mm256_add_ps(fjz0,tz);
1002 /**************************
1003 * CALCULATE INTERACTIONS *
1004 **************************/
1006 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1009 /* REACTION-FIELD ELECTROSTATICS */
1010 velec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
1011 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1013 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1015 /* Update potential sum for this i atom from the interaction with this j atom. */
1016 velec = _mm256_and_ps(velec,cutoff_mask);
1017 velec = _mm256_andnot_ps(dummy_mask,velec);
1018 velecsum = _mm256_add_ps(velecsum,velec);
1022 fscal = _mm256_and_ps(fscal,cutoff_mask);
1024 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1026 /* Calculate temporary vectorial force */
1027 tx = _mm256_mul_ps(fscal,dx11);
1028 ty = _mm256_mul_ps(fscal,dy11);
1029 tz = _mm256_mul_ps(fscal,dz11);
1031 /* Update vectorial force */
1032 fix1 = _mm256_add_ps(fix1,tx);
1033 fiy1 = _mm256_add_ps(fiy1,ty);
1034 fiz1 = _mm256_add_ps(fiz1,tz);
1036 fjx1 = _mm256_add_ps(fjx1,tx);
1037 fjy1 = _mm256_add_ps(fjy1,ty);
1038 fjz1 = _mm256_add_ps(fjz1,tz);
1042 /**************************
1043 * CALCULATE INTERACTIONS *
1044 **************************/
1046 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1049 /* REACTION-FIELD ELECTROSTATICS */
1050 velec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
1051 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1053 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1055 /* Update potential sum for this i atom from the interaction with this j atom. */
1056 velec = _mm256_and_ps(velec,cutoff_mask);
1057 velec = _mm256_andnot_ps(dummy_mask,velec);
1058 velecsum = _mm256_add_ps(velecsum,velec);
1062 fscal = _mm256_and_ps(fscal,cutoff_mask);
1064 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1066 /* Calculate temporary vectorial force */
1067 tx = _mm256_mul_ps(fscal,dx12);
1068 ty = _mm256_mul_ps(fscal,dy12);
1069 tz = _mm256_mul_ps(fscal,dz12);
1071 /* Update vectorial force */
1072 fix1 = _mm256_add_ps(fix1,tx);
1073 fiy1 = _mm256_add_ps(fiy1,ty);
1074 fiz1 = _mm256_add_ps(fiz1,tz);
1076 fjx2 = _mm256_add_ps(fjx2,tx);
1077 fjy2 = _mm256_add_ps(fjy2,ty);
1078 fjz2 = _mm256_add_ps(fjz2,tz);
1082 /**************************
1083 * CALCULATE INTERACTIONS *
1084 **************************/
1086 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1089 /* REACTION-FIELD ELECTROSTATICS */
1090 velec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
1091 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1093 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1095 /* Update potential sum for this i atom from the interaction with this j atom. */
1096 velec = _mm256_and_ps(velec,cutoff_mask);
1097 velec = _mm256_andnot_ps(dummy_mask,velec);
1098 velecsum = _mm256_add_ps(velecsum,velec);
1102 fscal = _mm256_and_ps(fscal,cutoff_mask);
1104 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1106 /* Calculate temporary vectorial force */
1107 tx = _mm256_mul_ps(fscal,dx20);
1108 ty = _mm256_mul_ps(fscal,dy20);
1109 tz = _mm256_mul_ps(fscal,dz20);
1111 /* Update vectorial force */
1112 fix2 = _mm256_add_ps(fix2,tx);
1113 fiy2 = _mm256_add_ps(fiy2,ty);
1114 fiz2 = _mm256_add_ps(fiz2,tz);
1116 fjx0 = _mm256_add_ps(fjx0,tx);
1117 fjy0 = _mm256_add_ps(fjy0,ty);
1118 fjz0 = _mm256_add_ps(fjz0,tz);
1122 /**************************
1123 * CALCULATE INTERACTIONS *
1124 **************************/
1126 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1129 /* REACTION-FIELD ELECTROSTATICS */
1130 velec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1131 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1133 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1135 /* Update potential sum for this i atom from the interaction with this j atom. */
1136 velec = _mm256_and_ps(velec,cutoff_mask);
1137 velec = _mm256_andnot_ps(dummy_mask,velec);
1138 velecsum = _mm256_add_ps(velecsum,velec);
1142 fscal = _mm256_and_ps(fscal,cutoff_mask);
1144 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1146 /* Calculate temporary vectorial force */
1147 tx = _mm256_mul_ps(fscal,dx21);
1148 ty = _mm256_mul_ps(fscal,dy21);
1149 tz = _mm256_mul_ps(fscal,dz21);
1151 /* Update vectorial force */
1152 fix2 = _mm256_add_ps(fix2,tx);
1153 fiy2 = _mm256_add_ps(fiy2,ty);
1154 fiz2 = _mm256_add_ps(fiz2,tz);
1156 fjx1 = _mm256_add_ps(fjx1,tx);
1157 fjy1 = _mm256_add_ps(fjy1,ty);
1158 fjz1 = _mm256_add_ps(fjz1,tz);
1162 /**************************
1163 * CALCULATE INTERACTIONS *
1164 **************************/
1166 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1169 /* REACTION-FIELD ELECTROSTATICS */
1170 velec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1171 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1173 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1175 /* Update potential sum for this i atom from the interaction with this j atom. */
1176 velec = _mm256_and_ps(velec,cutoff_mask);
1177 velec = _mm256_andnot_ps(dummy_mask,velec);
1178 velecsum = _mm256_add_ps(velecsum,velec);
1182 fscal = _mm256_and_ps(fscal,cutoff_mask);
1184 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1186 /* Calculate temporary vectorial force */
1187 tx = _mm256_mul_ps(fscal,dx22);
1188 ty = _mm256_mul_ps(fscal,dy22);
1189 tz = _mm256_mul_ps(fscal,dz22);
1191 /* Update vectorial force */
1192 fix2 = _mm256_add_ps(fix2,tx);
1193 fiy2 = _mm256_add_ps(fiy2,ty);
1194 fiz2 = _mm256_add_ps(fiz2,tz);
1196 fjx2 = _mm256_add_ps(fjx2,tx);
1197 fjy2 = _mm256_add_ps(fjy2,ty);
1198 fjz2 = _mm256_add_ps(fjz2,tz);
1202 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1203 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1204 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1205 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1206 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1207 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1208 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1209 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1211 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1212 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1214 /* Inner loop uses 359 flops */
1217 /* End of innermost loop */
1219 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1220 f+i_coord_offset,fshift+i_shift_offset);
1223 /* Update potential energies */
1224 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1225 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1227 /* Increment number of inner iterations */
1228 inneriter += j_index_end - j_index_start;
1230 /* Outer loop uses 20 flops */
1233 /* Increment number of outer iterations */
1236 /* Update outer/inner flops */
1238 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*359);
1241 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_F_avx_256_single
1242 * Electrostatics interaction: ReactionField
1243 * VdW interaction: LennardJones
1244 * Geometry: Water3-Water3
1245 * Calculate force/pot: Force
1248 nb_kernel_ElecRFCut_VdwLJSw_GeomW3W3_F_avx_256_single
1249 (t_nblist * gmx_restrict nlist,
1250 rvec * gmx_restrict xx,
1251 rvec * gmx_restrict ff,
1252 t_forcerec * gmx_restrict fr,
1253 t_mdatoms * gmx_restrict mdatoms,
1254 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1255 t_nrnb * gmx_restrict nrnb)
1257 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1258 * just 0 for non-waters.
1259 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1260 * jnr indices corresponding to data put in the four positions in the SIMD register.
1262 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1263 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1264 int jnrA,jnrB,jnrC,jnrD;
1265 int jnrE,jnrF,jnrG,jnrH;
1266 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1267 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1268 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1269 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1270 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1271 real rcutoff_scalar;
1272 real *shiftvec,*fshift,*x,*f;
1273 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1274 real scratch[4*DIM];
1275 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1276 real * vdwioffsetptr0;
1277 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1278 real * vdwioffsetptr1;
1279 __m256 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1280 real * vdwioffsetptr2;
1281 __m256 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1282 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1283 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1284 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1285 __m256 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1286 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1287 __m256 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1288 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1289 __m256 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1290 __m256 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1291 __m256 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1292 __m256 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1293 __m256 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1294 __m256 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1295 __m256 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1296 __m256 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1297 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
1300 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1303 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
1304 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
1305 __m256 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
1306 real rswitch_scalar,d_scalar;
1307 __m256 dummy_mask,cutoff_mask;
1308 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1309 __m256 one = _mm256_set1_ps(1.0);
1310 __m256 two = _mm256_set1_ps(2.0);
1316 jindex = nlist->jindex;
1318 shiftidx = nlist->shift;
1320 shiftvec = fr->shift_vec[0];
1321 fshift = fr->fshift[0];
1322 facel = _mm256_set1_ps(fr->epsfac);
1323 charge = mdatoms->chargeA;
1324 krf = _mm256_set1_ps(fr->ic->k_rf);
1325 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
1326 crf = _mm256_set1_ps(fr->ic->c_rf);
1327 nvdwtype = fr->ntype;
1328 vdwparam = fr->nbfp;
1329 vdwtype = mdatoms->typeA;
1331 /* Setup water-specific parameters */
1332 inr = nlist->iinr[0];
1333 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
1334 iq1 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1335 iq2 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1336 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
1338 jq0 = _mm256_set1_ps(charge[inr+0]);
1339 jq1 = _mm256_set1_ps(charge[inr+1]);
1340 jq2 = _mm256_set1_ps(charge[inr+2]);
1341 vdwjidx0A = 2*vdwtype[inr+0];
1342 qq00 = _mm256_mul_ps(iq0,jq0);
1343 c6_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1344 c12_00 = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1345 qq01 = _mm256_mul_ps(iq0,jq1);
1346 qq02 = _mm256_mul_ps(iq0,jq2);
1347 qq10 = _mm256_mul_ps(iq1,jq0);
1348 qq11 = _mm256_mul_ps(iq1,jq1);
1349 qq12 = _mm256_mul_ps(iq1,jq2);
1350 qq20 = _mm256_mul_ps(iq2,jq0);
1351 qq21 = _mm256_mul_ps(iq2,jq1);
1352 qq22 = _mm256_mul_ps(iq2,jq2);
1354 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1355 rcutoff_scalar = fr->rcoulomb;
1356 rcutoff = _mm256_set1_ps(rcutoff_scalar);
1357 rcutoff2 = _mm256_mul_ps(rcutoff,rcutoff);
1359 rswitch_scalar = fr->rvdw_switch;
1360 rswitch = _mm256_set1_ps(rswitch_scalar);
1361 /* Setup switch parameters */
1362 d_scalar = rcutoff_scalar-rswitch_scalar;
1363 d = _mm256_set1_ps(d_scalar);
1364 swV3 = _mm256_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
1365 swV4 = _mm256_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1366 swV5 = _mm256_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1367 swF2 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
1368 swF3 = _mm256_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
1369 swF4 = _mm256_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
1371 /* Avoid stupid compiler warnings */
1372 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1373 j_coord_offsetA = 0;
1374 j_coord_offsetB = 0;
1375 j_coord_offsetC = 0;
1376 j_coord_offsetD = 0;
1377 j_coord_offsetE = 0;
1378 j_coord_offsetF = 0;
1379 j_coord_offsetG = 0;
1380 j_coord_offsetH = 0;
1385 for(iidx=0;iidx<4*DIM;iidx++)
1387 scratch[iidx] = 0.0;
1390 /* Start outer loop over neighborlists */
1391 for(iidx=0; iidx<nri; iidx++)
1393 /* Load shift vector for this list */
1394 i_shift_offset = DIM*shiftidx[iidx];
1396 /* Load limits for loop over neighbors */
1397 j_index_start = jindex[iidx];
1398 j_index_end = jindex[iidx+1];
1400 /* Get outer coordinate index */
1402 i_coord_offset = DIM*inr;
1404 /* Load i particle coords and add shift vector */
1405 gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1406 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1408 fix0 = _mm256_setzero_ps();
1409 fiy0 = _mm256_setzero_ps();
1410 fiz0 = _mm256_setzero_ps();
1411 fix1 = _mm256_setzero_ps();
1412 fiy1 = _mm256_setzero_ps();
1413 fiz1 = _mm256_setzero_ps();
1414 fix2 = _mm256_setzero_ps();
1415 fiy2 = _mm256_setzero_ps();
1416 fiz2 = _mm256_setzero_ps();
1418 /* Start inner kernel loop */
1419 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1422 /* Get j neighbor index, and coordinate index */
1424 jnrB = jjnr[jidx+1];
1425 jnrC = jjnr[jidx+2];
1426 jnrD = jjnr[jidx+3];
1427 jnrE = jjnr[jidx+4];
1428 jnrF = jjnr[jidx+5];
1429 jnrG = jjnr[jidx+6];
1430 jnrH = jjnr[jidx+7];
1431 j_coord_offsetA = DIM*jnrA;
1432 j_coord_offsetB = DIM*jnrB;
1433 j_coord_offsetC = DIM*jnrC;
1434 j_coord_offsetD = DIM*jnrD;
1435 j_coord_offsetE = DIM*jnrE;
1436 j_coord_offsetF = DIM*jnrF;
1437 j_coord_offsetG = DIM*jnrG;
1438 j_coord_offsetH = DIM*jnrH;
1440 /* load j atom coordinates */
1441 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1442 x+j_coord_offsetC,x+j_coord_offsetD,
1443 x+j_coord_offsetE,x+j_coord_offsetF,
1444 x+j_coord_offsetG,x+j_coord_offsetH,
1445 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1447 /* Calculate displacement vector */
1448 dx00 = _mm256_sub_ps(ix0,jx0);
1449 dy00 = _mm256_sub_ps(iy0,jy0);
1450 dz00 = _mm256_sub_ps(iz0,jz0);
1451 dx01 = _mm256_sub_ps(ix0,jx1);
1452 dy01 = _mm256_sub_ps(iy0,jy1);
1453 dz01 = _mm256_sub_ps(iz0,jz1);
1454 dx02 = _mm256_sub_ps(ix0,jx2);
1455 dy02 = _mm256_sub_ps(iy0,jy2);
1456 dz02 = _mm256_sub_ps(iz0,jz2);
1457 dx10 = _mm256_sub_ps(ix1,jx0);
1458 dy10 = _mm256_sub_ps(iy1,jy0);
1459 dz10 = _mm256_sub_ps(iz1,jz0);
1460 dx11 = _mm256_sub_ps(ix1,jx1);
1461 dy11 = _mm256_sub_ps(iy1,jy1);
1462 dz11 = _mm256_sub_ps(iz1,jz1);
1463 dx12 = _mm256_sub_ps(ix1,jx2);
1464 dy12 = _mm256_sub_ps(iy1,jy2);
1465 dz12 = _mm256_sub_ps(iz1,jz2);
1466 dx20 = _mm256_sub_ps(ix2,jx0);
1467 dy20 = _mm256_sub_ps(iy2,jy0);
1468 dz20 = _mm256_sub_ps(iz2,jz0);
1469 dx21 = _mm256_sub_ps(ix2,jx1);
1470 dy21 = _mm256_sub_ps(iy2,jy1);
1471 dz21 = _mm256_sub_ps(iz2,jz1);
1472 dx22 = _mm256_sub_ps(ix2,jx2);
1473 dy22 = _mm256_sub_ps(iy2,jy2);
1474 dz22 = _mm256_sub_ps(iz2,jz2);
1476 /* Calculate squared distance and things based on it */
1477 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1478 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1479 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1480 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1481 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1482 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1483 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1484 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1485 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1487 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1488 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1489 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1490 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1491 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1492 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1493 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
1494 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1495 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1497 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1498 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
1499 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
1500 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
1501 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1502 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1503 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
1504 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1505 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1507 fjx0 = _mm256_setzero_ps();
1508 fjy0 = _mm256_setzero_ps();
1509 fjz0 = _mm256_setzero_ps();
1510 fjx1 = _mm256_setzero_ps();
1511 fjy1 = _mm256_setzero_ps();
1512 fjz1 = _mm256_setzero_ps();
1513 fjx2 = _mm256_setzero_ps();
1514 fjy2 = _mm256_setzero_ps();
1515 fjz2 = _mm256_setzero_ps();
1517 /**************************
1518 * CALCULATE INTERACTIONS *
1519 **************************/
1521 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1524 r00 = _mm256_mul_ps(rsq00,rinv00);
1526 /* REACTION-FIELD ELECTROSTATICS */
1527 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1529 /* LENNARD-JONES DISPERSION/REPULSION */
1531 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1532 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
1533 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
1534 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
1535 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
1537 d = _mm256_sub_ps(r00,rswitch);
1538 d = _mm256_max_ps(d,_mm256_setzero_ps());
1539 d2 = _mm256_mul_ps(d,d);
1540 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
1542 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
1544 /* Evaluate switch function */
1545 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1546 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
1547 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1549 fscal = _mm256_add_ps(felec,fvdw);
1551 fscal = _mm256_and_ps(fscal,cutoff_mask);
1553 /* Calculate temporary vectorial force */
1554 tx = _mm256_mul_ps(fscal,dx00);
1555 ty = _mm256_mul_ps(fscal,dy00);
1556 tz = _mm256_mul_ps(fscal,dz00);
1558 /* Update vectorial force */
1559 fix0 = _mm256_add_ps(fix0,tx);
1560 fiy0 = _mm256_add_ps(fiy0,ty);
1561 fiz0 = _mm256_add_ps(fiz0,tz);
1563 fjx0 = _mm256_add_ps(fjx0,tx);
1564 fjy0 = _mm256_add_ps(fjy0,ty);
1565 fjz0 = _mm256_add_ps(fjz0,tz);
1569 /**************************
1570 * CALCULATE INTERACTIONS *
1571 **************************/
1573 if (gmx_mm256_any_lt(rsq01,rcutoff2))
1576 /* REACTION-FIELD ELECTROSTATICS */
1577 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1579 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1583 fscal = _mm256_and_ps(fscal,cutoff_mask);
1585 /* Calculate temporary vectorial force */
1586 tx = _mm256_mul_ps(fscal,dx01);
1587 ty = _mm256_mul_ps(fscal,dy01);
1588 tz = _mm256_mul_ps(fscal,dz01);
1590 /* Update vectorial force */
1591 fix0 = _mm256_add_ps(fix0,tx);
1592 fiy0 = _mm256_add_ps(fiy0,ty);
1593 fiz0 = _mm256_add_ps(fiz0,tz);
1595 fjx1 = _mm256_add_ps(fjx1,tx);
1596 fjy1 = _mm256_add_ps(fjy1,ty);
1597 fjz1 = _mm256_add_ps(fjz1,tz);
1601 /**************************
1602 * CALCULATE INTERACTIONS *
1603 **************************/
1605 if (gmx_mm256_any_lt(rsq02,rcutoff2))
1608 /* REACTION-FIELD ELECTROSTATICS */
1609 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1611 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1615 fscal = _mm256_and_ps(fscal,cutoff_mask);
1617 /* Calculate temporary vectorial force */
1618 tx = _mm256_mul_ps(fscal,dx02);
1619 ty = _mm256_mul_ps(fscal,dy02);
1620 tz = _mm256_mul_ps(fscal,dz02);
1622 /* Update vectorial force */
1623 fix0 = _mm256_add_ps(fix0,tx);
1624 fiy0 = _mm256_add_ps(fiy0,ty);
1625 fiz0 = _mm256_add_ps(fiz0,tz);
1627 fjx2 = _mm256_add_ps(fjx2,tx);
1628 fjy2 = _mm256_add_ps(fjy2,ty);
1629 fjz2 = _mm256_add_ps(fjz2,tz);
1633 /**************************
1634 * CALCULATE INTERACTIONS *
1635 **************************/
1637 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1640 /* REACTION-FIELD ELECTROSTATICS */
1641 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1643 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1647 fscal = _mm256_and_ps(fscal,cutoff_mask);
1649 /* Calculate temporary vectorial force */
1650 tx = _mm256_mul_ps(fscal,dx10);
1651 ty = _mm256_mul_ps(fscal,dy10);
1652 tz = _mm256_mul_ps(fscal,dz10);
1654 /* Update vectorial force */
1655 fix1 = _mm256_add_ps(fix1,tx);
1656 fiy1 = _mm256_add_ps(fiy1,ty);
1657 fiz1 = _mm256_add_ps(fiz1,tz);
1659 fjx0 = _mm256_add_ps(fjx0,tx);
1660 fjy0 = _mm256_add_ps(fjy0,ty);
1661 fjz0 = _mm256_add_ps(fjz0,tz);
1665 /**************************
1666 * CALCULATE INTERACTIONS *
1667 **************************/
1669 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1672 /* REACTION-FIELD ELECTROSTATICS */
1673 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1675 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1679 fscal = _mm256_and_ps(fscal,cutoff_mask);
1681 /* Calculate temporary vectorial force */
1682 tx = _mm256_mul_ps(fscal,dx11);
1683 ty = _mm256_mul_ps(fscal,dy11);
1684 tz = _mm256_mul_ps(fscal,dz11);
1686 /* Update vectorial force */
1687 fix1 = _mm256_add_ps(fix1,tx);
1688 fiy1 = _mm256_add_ps(fiy1,ty);
1689 fiz1 = _mm256_add_ps(fiz1,tz);
1691 fjx1 = _mm256_add_ps(fjx1,tx);
1692 fjy1 = _mm256_add_ps(fjy1,ty);
1693 fjz1 = _mm256_add_ps(fjz1,tz);
1697 /**************************
1698 * CALCULATE INTERACTIONS *
1699 **************************/
1701 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1704 /* REACTION-FIELD ELECTROSTATICS */
1705 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1707 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1711 fscal = _mm256_and_ps(fscal,cutoff_mask);
1713 /* Calculate temporary vectorial force */
1714 tx = _mm256_mul_ps(fscal,dx12);
1715 ty = _mm256_mul_ps(fscal,dy12);
1716 tz = _mm256_mul_ps(fscal,dz12);
1718 /* Update vectorial force */
1719 fix1 = _mm256_add_ps(fix1,tx);
1720 fiy1 = _mm256_add_ps(fiy1,ty);
1721 fiz1 = _mm256_add_ps(fiz1,tz);
1723 fjx2 = _mm256_add_ps(fjx2,tx);
1724 fjy2 = _mm256_add_ps(fjy2,ty);
1725 fjz2 = _mm256_add_ps(fjz2,tz);
1729 /**************************
1730 * CALCULATE INTERACTIONS *
1731 **************************/
1733 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1736 /* REACTION-FIELD ELECTROSTATICS */
1737 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1739 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1743 fscal = _mm256_and_ps(fscal,cutoff_mask);
1745 /* Calculate temporary vectorial force */
1746 tx = _mm256_mul_ps(fscal,dx20);
1747 ty = _mm256_mul_ps(fscal,dy20);
1748 tz = _mm256_mul_ps(fscal,dz20);
1750 /* Update vectorial force */
1751 fix2 = _mm256_add_ps(fix2,tx);
1752 fiy2 = _mm256_add_ps(fiy2,ty);
1753 fiz2 = _mm256_add_ps(fiz2,tz);
1755 fjx0 = _mm256_add_ps(fjx0,tx);
1756 fjy0 = _mm256_add_ps(fjy0,ty);
1757 fjz0 = _mm256_add_ps(fjz0,tz);
1761 /**************************
1762 * CALCULATE INTERACTIONS *
1763 **************************/
1765 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1768 /* REACTION-FIELD ELECTROSTATICS */
1769 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1771 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1775 fscal = _mm256_and_ps(fscal,cutoff_mask);
1777 /* Calculate temporary vectorial force */
1778 tx = _mm256_mul_ps(fscal,dx21);
1779 ty = _mm256_mul_ps(fscal,dy21);
1780 tz = _mm256_mul_ps(fscal,dz21);
1782 /* Update vectorial force */
1783 fix2 = _mm256_add_ps(fix2,tx);
1784 fiy2 = _mm256_add_ps(fiy2,ty);
1785 fiz2 = _mm256_add_ps(fiz2,tz);
1787 fjx1 = _mm256_add_ps(fjx1,tx);
1788 fjy1 = _mm256_add_ps(fjy1,ty);
1789 fjz1 = _mm256_add_ps(fjz1,tz);
1793 /**************************
1794 * CALCULATE INTERACTIONS *
1795 **************************/
1797 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1800 /* REACTION-FIELD ELECTROSTATICS */
1801 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1803 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1807 fscal = _mm256_and_ps(fscal,cutoff_mask);
1809 /* Calculate temporary vectorial force */
1810 tx = _mm256_mul_ps(fscal,dx22);
1811 ty = _mm256_mul_ps(fscal,dy22);
1812 tz = _mm256_mul_ps(fscal,dz22);
1814 /* Update vectorial force */
1815 fix2 = _mm256_add_ps(fix2,tx);
1816 fiy2 = _mm256_add_ps(fiy2,ty);
1817 fiz2 = _mm256_add_ps(fiz2,tz);
1819 fjx2 = _mm256_add_ps(fjx2,tx);
1820 fjy2 = _mm256_add_ps(fjy2,ty);
1821 fjz2 = _mm256_add_ps(fjz2,tz);
1825 fjptrA = f+j_coord_offsetA;
1826 fjptrB = f+j_coord_offsetB;
1827 fjptrC = f+j_coord_offsetC;
1828 fjptrD = f+j_coord_offsetD;
1829 fjptrE = f+j_coord_offsetE;
1830 fjptrF = f+j_coord_offsetF;
1831 fjptrG = f+j_coord_offsetG;
1832 fjptrH = f+j_coord_offsetH;
1834 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1835 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1837 /* Inner loop uses 301 flops */
1840 if(jidx<j_index_end)
1843 /* Get j neighbor index, and coordinate index */
1844 jnrlistA = jjnr[jidx];
1845 jnrlistB = jjnr[jidx+1];
1846 jnrlistC = jjnr[jidx+2];
1847 jnrlistD = jjnr[jidx+3];
1848 jnrlistE = jjnr[jidx+4];
1849 jnrlistF = jjnr[jidx+5];
1850 jnrlistG = jjnr[jidx+6];
1851 jnrlistH = jjnr[jidx+7];
1852 /* Sign of each element will be negative for non-real atoms.
1853 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1854 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1856 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1857 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1859 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1860 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1861 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1862 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1863 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
1864 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
1865 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
1866 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
1867 j_coord_offsetA = DIM*jnrA;
1868 j_coord_offsetB = DIM*jnrB;
1869 j_coord_offsetC = DIM*jnrC;
1870 j_coord_offsetD = DIM*jnrD;
1871 j_coord_offsetE = DIM*jnrE;
1872 j_coord_offsetF = DIM*jnrF;
1873 j_coord_offsetG = DIM*jnrG;
1874 j_coord_offsetH = DIM*jnrH;
1876 /* load j atom coordinates */
1877 gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1878 x+j_coord_offsetC,x+j_coord_offsetD,
1879 x+j_coord_offsetE,x+j_coord_offsetF,
1880 x+j_coord_offsetG,x+j_coord_offsetH,
1881 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1883 /* Calculate displacement vector */
1884 dx00 = _mm256_sub_ps(ix0,jx0);
1885 dy00 = _mm256_sub_ps(iy0,jy0);
1886 dz00 = _mm256_sub_ps(iz0,jz0);
1887 dx01 = _mm256_sub_ps(ix0,jx1);
1888 dy01 = _mm256_sub_ps(iy0,jy1);
1889 dz01 = _mm256_sub_ps(iz0,jz1);
1890 dx02 = _mm256_sub_ps(ix0,jx2);
1891 dy02 = _mm256_sub_ps(iy0,jy2);
1892 dz02 = _mm256_sub_ps(iz0,jz2);
1893 dx10 = _mm256_sub_ps(ix1,jx0);
1894 dy10 = _mm256_sub_ps(iy1,jy0);
1895 dz10 = _mm256_sub_ps(iz1,jz0);
1896 dx11 = _mm256_sub_ps(ix1,jx1);
1897 dy11 = _mm256_sub_ps(iy1,jy1);
1898 dz11 = _mm256_sub_ps(iz1,jz1);
1899 dx12 = _mm256_sub_ps(ix1,jx2);
1900 dy12 = _mm256_sub_ps(iy1,jy2);
1901 dz12 = _mm256_sub_ps(iz1,jz2);
1902 dx20 = _mm256_sub_ps(ix2,jx0);
1903 dy20 = _mm256_sub_ps(iy2,jy0);
1904 dz20 = _mm256_sub_ps(iz2,jz0);
1905 dx21 = _mm256_sub_ps(ix2,jx1);
1906 dy21 = _mm256_sub_ps(iy2,jy1);
1907 dz21 = _mm256_sub_ps(iz2,jz1);
1908 dx22 = _mm256_sub_ps(ix2,jx2);
1909 dy22 = _mm256_sub_ps(iy2,jy2);
1910 dz22 = _mm256_sub_ps(iz2,jz2);
1912 /* Calculate squared distance and things based on it */
1913 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1914 rsq01 = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1915 rsq02 = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1916 rsq10 = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1917 rsq11 = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1918 rsq12 = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1919 rsq20 = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1920 rsq21 = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1921 rsq22 = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1923 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
1924 rinv01 = gmx_mm256_invsqrt_ps(rsq01);
1925 rinv02 = gmx_mm256_invsqrt_ps(rsq02);
1926 rinv10 = gmx_mm256_invsqrt_ps(rsq10);
1927 rinv11 = gmx_mm256_invsqrt_ps(rsq11);
1928 rinv12 = gmx_mm256_invsqrt_ps(rsq12);
1929 rinv20 = gmx_mm256_invsqrt_ps(rsq20);
1930 rinv21 = gmx_mm256_invsqrt_ps(rsq21);
1931 rinv22 = gmx_mm256_invsqrt_ps(rsq22);
1933 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
1934 rinvsq01 = _mm256_mul_ps(rinv01,rinv01);
1935 rinvsq02 = _mm256_mul_ps(rinv02,rinv02);
1936 rinvsq10 = _mm256_mul_ps(rinv10,rinv10);
1937 rinvsq11 = _mm256_mul_ps(rinv11,rinv11);
1938 rinvsq12 = _mm256_mul_ps(rinv12,rinv12);
1939 rinvsq20 = _mm256_mul_ps(rinv20,rinv20);
1940 rinvsq21 = _mm256_mul_ps(rinv21,rinv21);
1941 rinvsq22 = _mm256_mul_ps(rinv22,rinv22);
1943 fjx0 = _mm256_setzero_ps();
1944 fjy0 = _mm256_setzero_ps();
1945 fjz0 = _mm256_setzero_ps();
1946 fjx1 = _mm256_setzero_ps();
1947 fjy1 = _mm256_setzero_ps();
1948 fjz1 = _mm256_setzero_ps();
1949 fjx2 = _mm256_setzero_ps();
1950 fjy2 = _mm256_setzero_ps();
1951 fjz2 = _mm256_setzero_ps();
1953 /**************************
1954 * CALCULATE INTERACTIONS *
1955 **************************/
1957 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1960 r00 = _mm256_mul_ps(rsq00,rinv00);
1961 r00 = _mm256_andnot_ps(dummy_mask,r00);
1963 /* REACTION-FIELD ELECTROSTATICS */
1964 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1966 /* LENNARD-JONES DISPERSION/REPULSION */
1968 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1969 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
1970 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
1971 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
1972 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
1974 d = _mm256_sub_ps(r00,rswitch);
1975 d = _mm256_max_ps(d,_mm256_setzero_ps());
1976 d2 = _mm256_mul_ps(d,d);
1977 sw = _mm256_add_ps(one,_mm256_mul_ps(d2,_mm256_mul_ps(d,_mm256_add_ps(swV3,_mm256_mul_ps(d,_mm256_add_ps(swV4,_mm256_mul_ps(d,swV5)))))));
1979 dsw = _mm256_mul_ps(d2,_mm256_add_ps(swF2,_mm256_mul_ps(d,_mm256_add_ps(swF3,_mm256_mul_ps(d,swF4)))));
1981 /* Evaluate switch function */
1982 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1983 fvdw = _mm256_sub_ps( _mm256_mul_ps(fvdw,sw) , _mm256_mul_ps(rinv00,_mm256_mul_ps(vvdw,dsw)) );
1984 cutoff_mask = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1986 fscal = _mm256_add_ps(felec,fvdw);
1988 fscal = _mm256_and_ps(fscal,cutoff_mask);
1990 fscal = _mm256_andnot_ps(dummy_mask,fscal);
1992 /* Calculate temporary vectorial force */
1993 tx = _mm256_mul_ps(fscal,dx00);
1994 ty = _mm256_mul_ps(fscal,dy00);
1995 tz = _mm256_mul_ps(fscal,dz00);
1997 /* Update vectorial force */
1998 fix0 = _mm256_add_ps(fix0,tx);
1999 fiy0 = _mm256_add_ps(fiy0,ty);
2000 fiz0 = _mm256_add_ps(fiz0,tz);
2002 fjx0 = _mm256_add_ps(fjx0,tx);
2003 fjy0 = _mm256_add_ps(fjy0,ty);
2004 fjz0 = _mm256_add_ps(fjz0,tz);
2008 /**************************
2009 * CALCULATE INTERACTIONS *
2010 **************************/
2012 if (gmx_mm256_any_lt(rsq01,rcutoff2))
2015 /* REACTION-FIELD ELECTROSTATICS */
2016 felec = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
2018 cutoff_mask = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
2022 fscal = _mm256_and_ps(fscal,cutoff_mask);
2024 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2026 /* Calculate temporary vectorial force */
2027 tx = _mm256_mul_ps(fscal,dx01);
2028 ty = _mm256_mul_ps(fscal,dy01);
2029 tz = _mm256_mul_ps(fscal,dz01);
2031 /* Update vectorial force */
2032 fix0 = _mm256_add_ps(fix0,tx);
2033 fiy0 = _mm256_add_ps(fiy0,ty);
2034 fiz0 = _mm256_add_ps(fiz0,tz);
2036 fjx1 = _mm256_add_ps(fjx1,tx);
2037 fjy1 = _mm256_add_ps(fjy1,ty);
2038 fjz1 = _mm256_add_ps(fjz1,tz);
2042 /**************************
2043 * CALCULATE INTERACTIONS *
2044 **************************/
2046 if (gmx_mm256_any_lt(rsq02,rcutoff2))
2049 /* REACTION-FIELD ELECTROSTATICS */
2050 felec = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
2052 cutoff_mask = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
2056 fscal = _mm256_and_ps(fscal,cutoff_mask);
2058 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2060 /* Calculate temporary vectorial force */
2061 tx = _mm256_mul_ps(fscal,dx02);
2062 ty = _mm256_mul_ps(fscal,dy02);
2063 tz = _mm256_mul_ps(fscal,dz02);
2065 /* Update vectorial force */
2066 fix0 = _mm256_add_ps(fix0,tx);
2067 fiy0 = _mm256_add_ps(fiy0,ty);
2068 fiz0 = _mm256_add_ps(fiz0,tz);
2070 fjx2 = _mm256_add_ps(fjx2,tx);
2071 fjy2 = _mm256_add_ps(fjy2,ty);
2072 fjz2 = _mm256_add_ps(fjz2,tz);
2076 /**************************
2077 * CALCULATE INTERACTIONS *
2078 **************************/
2080 if (gmx_mm256_any_lt(rsq10,rcutoff2))
2083 /* REACTION-FIELD ELECTROSTATICS */
2084 felec = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
2086 cutoff_mask = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
2090 fscal = _mm256_and_ps(fscal,cutoff_mask);
2092 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2094 /* Calculate temporary vectorial force */
2095 tx = _mm256_mul_ps(fscal,dx10);
2096 ty = _mm256_mul_ps(fscal,dy10);
2097 tz = _mm256_mul_ps(fscal,dz10);
2099 /* Update vectorial force */
2100 fix1 = _mm256_add_ps(fix1,tx);
2101 fiy1 = _mm256_add_ps(fiy1,ty);
2102 fiz1 = _mm256_add_ps(fiz1,tz);
2104 fjx0 = _mm256_add_ps(fjx0,tx);
2105 fjy0 = _mm256_add_ps(fjy0,ty);
2106 fjz0 = _mm256_add_ps(fjz0,tz);
2110 /**************************
2111 * CALCULATE INTERACTIONS *
2112 **************************/
2114 if (gmx_mm256_any_lt(rsq11,rcutoff2))
2117 /* REACTION-FIELD ELECTROSTATICS */
2118 felec = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2120 cutoff_mask = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2124 fscal = _mm256_and_ps(fscal,cutoff_mask);
2126 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2128 /* Calculate temporary vectorial force */
2129 tx = _mm256_mul_ps(fscal,dx11);
2130 ty = _mm256_mul_ps(fscal,dy11);
2131 tz = _mm256_mul_ps(fscal,dz11);
2133 /* Update vectorial force */
2134 fix1 = _mm256_add_ps(fix1,tx);
2135 fiy1 = _mm256_add_ps(fiy1,ty);
2136 fiz1 = _mm256_add_ps(fiz1,tz);
2138 fjx1 = _mm256_add_ps(fjx1,tx);
2139 fjy1 = _mm256_add_ps(fjy1,ty);
2140 fjz1 = _mm256_add_ps(fjz1,tz);
2144 /**************************
2145 * CALCULATE INTERACTIONS *
2146 **************************/
2148 if (gmx_mm256_any_lt(rsq12,rcutoff2))
2151 /* REACTION-FIELD ELECTROSTATICS */
2152 felec = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2154 cutoff_mask = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2158 fscal = _mm256_and_ps(fscal,cutoff_mask);
2160 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2162 /* Calculate temporary vectorial force */
2163 tx = _mm256_mul_ps(fscal,dx12);
2164 ty = _mm256_mul_ps(fscal,dy12);
2165 tz = _mm256_mul_ps(fscal,dz12);
2167 /* Update vectorial force */
2168 fix1 = _mm256_add_ps(fix1,tx);
2169 fiy1 = _mm256_add_ps(fiy1,ty);
2170 fiz1 = _mm256_add_ps(fiz1,tz);
2172 fjx2 = _mm256_add_ps(fjx2,tx);
2173 fjy2 = _mm256_add_ps(fjy2,ty);
2174 fjz2 = _mm256_add_ps(fjz2,tz);
2178 /**************************
2179 * CALCULATE INTERACTIONS *
2180 **************************/
2182 if (gmx_mm256_any_lt(rsq20,rcutoff2))
2185 /* REACTION-FIELD ELECTROSTATICS */
2186 felec = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
2188 cutoff_mask = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
2192 fscal = _mm256_and_ps(fscal,cutoff_mask);
2194 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2196 /* Calculate temporary vectorial force */
2197 tx = _mm256_mul_ps(fscal,dx20);
2198 ty = _mm256_mul_ps(fscal,dy20);
2199 tz = _mm256_mul_ps(fscal,dz20);
2201 /* Update vectorial force */
2202 fix2 = _mm256_add_ps(fix2,tx);
2203 fiy2 = _mm256_add_ps(fiy2,ty);
2204 fiz2 = _mm256_add_ps(fiz2,tz);
2206 fjx0 = _mm256_add_ps(fjx0,tx);
2207 fjy0 = _mm256_add_ps(fjy0,ty);
2208 fjz0 = _mm256_add_ps(fjz0,tz);
2212 /**************************
2213 * CALCULATE INTERACTIONS *
2214 **************************/
2216 if (gmx_mm256_any_lt(rsq21,rcutoff2))
2219 /* REACTION-FIELD ELECTROSTATICS */
2220 felec = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2222 cutoff_mask = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2226 fscal = _mm256_and_ps(fscal,cutoff_mask);
2228 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2230 /* Calculate temporary vectorial force */
2231 tx = _mm256_mul_ps(fscal,dx21);
2232 ty = _mm256_mul_ps(fscal,dy21);
2233 tz = _mm256_mul_ps(fscal,dz21);
2235 /* Update vectorial force */
2236 fix2 = _mm256_add_ps(fix2,tx);
2237 fiy2 = _mm256_add_ps(fiy2,ty);
2238 fiz2 = _mm256_add_ps(fiz2,tz);
2240 fjx1 = _mm256_add_ps(fjx1,tx);
2241 fjy1 = _mm256_add_ps(fjy1,ty);
2242 fjz1 = _mm256_add_ps(fjz1,tz);
2246 /**************************
2247 * CALCULATE INTERACTIONS *
2248 **************************/
2250 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2253 /* REACTION-FIELD ELECTROSTATICS */
2254 felec = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2256 cutoff_mask = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2260 fscal = _mm256_and_ps(fscal,cutoff_mask);
2262 fscal = _mm256_andnot_ps(dummy_mask,fscal);
2264 /* Calculate temporary vectorial force */
2265 tx = _mm256_mul_ps(fscal,dx22);
2266 ty = _mm256_mul_ps(fscal,dy22);
2267 tz = _mm256_mul_ps(fscal,dz22);
2269 /* Update vectorial force */
2270 fix2 = _mm256_add_ps(fix2,tx);
2271 fiy2 = _mm256_add_ps(fiy2,ty);
2272 fiz2 = _mm256_add_ps(fiz2,tz);
2274 fjx2 = _mm256_add_ps(fjx2,tx);
2275 fjy2 = _mm256_add_ps(fjy2,ty);
2276 fjz2 = _mm256_add_ps(fjz2,tz);
2280 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2281 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2282 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2283 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2284 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2285 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2286 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2287 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2289 gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2290 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2292 /* Inner loop uses 302 flops */
2295 /* End of innermost loop */
2297 gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2298 f+i_coord_offset,fshift+i_shift_offset);
2300 /* Increment number of inner iterations */
2301 inneriter += j_index_end - j_index_start;
2303 /* Outer loop uses 18 flops */
2306 /* Increment number of outer iterations */
2309 /* Update outer/inner flops */
2311 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*302);