Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_single / nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_avx_256_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_256_single kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_256_single
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            CubicSplineTable
56  * Geometry:                   Water3-Water3
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_256_single
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
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.
73      */
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;
83     real             rcutoff_scalar;
84     real             *shiftvec,*fshift,*x,*f;
85     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
86     real             scratch[4*DIM];
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;
110     real             *charge;
111     int              nvdwtype;
112     __m256           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
113     int              *vdwtype;
114     real             *vdwparam;
115     __m256           one_sixth   = _mm256_set1_ps(1.0/6.0);
116     __m256           one_twelfth = _mm256_set1_ps(1.0/12.0);
117     __m256i          vfitab;
118     __m128i          vfitab_lo,vfitab_hi;
119     __m128i          ifour       = _mm_set1_epi32(4);
120     __m256           rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
121     real             *vftab;
122     __m256           dummy_mask,cutoff_mask;
123     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
124     __m256           one     = _mm256_set1_ps(1.0);
125     __m256           two     = _mm256_set1_ps(2.0);
126     x                = xx[0];
127     f                = ff[0];
128
129     nri              = nlist->nri;
130     iinr             = nlist->iinr;
131     jindex           = nlist->jindex;
132     jjnr             = nlist->jjnr;
133     shiftidx         = nlist->shift;
134     gid              = nlist->gid;
135     shiftvec         = fr->shift_vec[0];
136     fshift           = fr->fshift[0];
137     facel            = _mm256_set1_ps(fr->epsfac);
138     charge           = mdatoms->chargeA;
139     krf              = _mm256_set1_ps(fr->ic->k_rf);
140     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
141     crf              = _mm256_set1_ps(fr->ic->c_rf);
142     nvdwtype         = fr->ntype;
143     vdwparam         = fr->nbfp;
144     vdwtype          = mdatoms->typeA;
145
146     vftab            = kernel_data->table_vdw->data;
147     vftabscale       = _mm256_set1_ps(kernel_data->table_vdw->scale);
148
149     /* Setup water-specific parameters */
150     inr              = nlist->iinr[0];
151     iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
152     iq1              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
153     iq2              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
154     vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
155
156     jq0              = _mm256_set1_ps(charge[inr+0]);
157     jq1              = _mm256_set1_ps(charge[inr+1]);
158     jq2              = _mm256_set1_ps(charge[inr+2]);
159     vdwjidx0A        = 2*vdwtype[inr+0];
160     qq00             = _mm256_mul_ps(iq0,jq0);
161     c6_00            = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
162     c12_00           = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
163     qq01             = _mm256_mul_ps(iq0,jq1);
164     qq02             = _mm256_mul_ps(iq0,jq2);
165     qq10             = _mm256_mul_ps(iq1,jq0);
166     qq11             = _mm256_mul_ps(iq1,jq1);
167     qq12             = _mm256_mul_ps(iq1,jq2);
168     qq20             = _mm256_mul_ps(iq2,jq0);
169     qq21             = _mm256_mul_ps(iq2,jq1);
170     qq22             = _mm256_mul_ps(iq2,jq2);
171
172     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
173     rcutoff_scalar   = fr->rcoulomb;
174     rcutoff          = _mm256_set1_ps(rcutoff_scalar);
175     rcutoff2         = _mm256_mul_ps(rcutoff,rcutoff);
176
177     /* Avoid stupid compiler warnings */
178     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
179     j_coord_offsetA = 0;
180     j_coord_offsetB = 0;
181     j_coord_offsetC = 0;
182     j_coord_offsetD = 0;
183     j_coord_offsetE = 0;
184     j_coord_offsetF = 0;
185     j_coord_offsetG = 0;
186     j_coord_offsetH = 0;
187
188     outeriter        = 0;
189     inneriter        = 0;
190
191     for(iidx=0;iidx<4*DIM;iidx++)
192     {
193         scratch[iidx] = 0.0;
194     }
195
196     /* Start outer loop over neighborlists */
197     for(iidx=0; iidx<nri; iidx++)
198     {
199         /* Load shift vector for this list */
200         i_shift_offset   = DIM*shiftidx[iidx];
201
202         /* Load limits for loop over neighbors */
203         j_index_start    = jindex[iidx];
204         j_index_end      = jindex[iidx+1];
205
206         /* Get outer coordinate index */
207         inr              = iinr[iidx];
208         i_coord_offset   = DIM*inr;
209
210         /* Load i particle coords and add shift vector */
211         gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
212                                                     &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
213
214         fix0             = _mm256_setzero_ps();
215         fiy0             = _mm256_setzero_ps();
216         fiz0             = _mm256_setzero_ps();
217         fix1             = _mm256_setzero_ps();
218         fiy1             = _mm256_setzero_ps();
219         fiz1             = _mm256_setzero_ps();
220         fix2             = _mm256_setzero_ps();
221         fiy2             = _mm256_setzero_ps();
222         fiz2             = _mm256_setzero_ps();
223
224         /* Reset potential sums */
225         velecsum         = _mm256_setzero_ps();
226         vvdwsum          = _mm256_setzero_ps();
227
228         /* Start inner kernel loop */
229         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
230         {
231
232             /* Get j neighbor index, and coordinate index */
233             jnrA             = jjnr[jidx];
234             jnrB             = jjnr[jidx+1];
235             jnrC             = jjnr[jidx+2];
236             jnrD             = jjnr[jidx+3];
237             jnrE             = jjnr[jidx+4];
238             jnrF             = jjnr[jidx+5];
239             jnrG             = jjnr[jidx+6];
240             jnrH             = jjnr[jidx+7];
241             j_coord_offsetA  = DIM*jnrA;
242             j_coord_offsetB  = DIM*jnrB;
243             j_coord_offsetC  = DIM*jnrC;
244             j_coord_offsetD  = DIM*jnrD;
245             j_coord_offsetE  = DIM*jnrE;
246             j_coord_offsetF  = DIM*jnrF;
247             j_coord_offsetG  = DIM*jnrG;
248             j_coord_offsetH  = DIM*jnrH;
249
250             /* load j atom coordinates */
251             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
252                                                  x+j_coord_offsetC,x+j_coord_offsetD,
253                                                  x+j_coord_offsetE,x+j_coord_offsetF,
254                                                  x+j_coord_offsetG,x+j_coord_offsetH,
255                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
256
257             /* Calculate displacement vector */
258             dx00             = _mm256_sub_ps(ix0,jx0);
259             dy00             = _mm256_sub_ps(iy0,jy0);
260             dz00             = _mm256_sub_ps(iz0,jz0);
261             dx01             = _mm256_sub_ps(ix0,jx1);
262             dy01             = _mm256_sub_ps(iy0,jy1);
263             dz01             = _mm256_sub_ps(iz0,jz1);
264             dx02             = _mm256_sub_ps(ix0,jx2);
265             dy02             = _mm256_sub_ps(iy0,jy2);
266             dz02             = _mm256_sub_ps(iz0,jz2);
267             dx10             = _mm256_sub_ps(ix1,jx0);
268             dy10             = _mm256_sub_ps(iy1,jy0);
269             dz10             = _mm256_sub_ps(iz1,jz0);
270             dx11             = _mm256_sub_ps(ix1,jx1);
271             dy11             = _mm256_sub_ps(iy1,jy1);
272             dz11             = _mm256_sub_ps(iz1,jz1);
273             dx12             = _mm256_sub_ps(ix1,jx2);
274             dy12             = _mm256_sub_ps(iy1,jy2);
275             dz12             = _mm256_sub_ps(iz1,jz2);
276             dx20             = _mm256_sub_ps(ix2,jx0);
277             dy20             = _mm256_sub_ps(iy2,jy0);
278             dz20             = _mm256_sub_ps(iz2,jz0);
279             dx21             = _mm256_sub_ps(ix2,jx1);
280             dy21             = _mm256_sub_ps(iy2,jy1);
281             dz21             = _mm256_sub_ps(iz2,jz1);
282             dx22             = _mm256_sub_ps(ix2,jx2);
283             dy22             = _mm256_sub_ps(iy2,jy2);
284             dz22             = _mm256_sub_ps(iz2,jz2);
285
286             /* Calculate squared distance and things based on it */
287             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
288             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
289             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
290             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
291             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
292             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
293             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
294             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
295             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
296
297             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
298             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
299             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
300             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
301             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
302             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
303             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
304             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
305             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
306
307             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
308             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
309             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
310             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
311             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
312             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
313             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
314             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
315             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
316
317             fjx0             = _mm256_setzero_ps();
318             fjy0             = _mm256_setzero_ps();
319             fjz0             = _mm256_setzero_ps();
320             fjx1             = _mm256_setzero_ps();
321             fjy1             = _mm256_setzero_ps();
322             fjz1             = _mm256_setzero_ps();
323             fjx2             = _mm256_setzero_ps();
324             fjy2             = _mm256_setzero_ps();
325             fjz2             = _mm256_setzero_ps();
326
327             /**************************
328              * CALCULATE INTERACTIONS *
329              **************************/
330
331             if (gmx_mm256_any_lt(rsq00,rcutoff2))
332             {
333
334             r00              = _mm256_mul_ps(rsq00,rinv00);
335
336             /* Calculate table index by multiplying r with table scale and truncate to integer */
337             rt               = _mm256_mul_ps(r00,vftabscale);
338             vfitab           = _mm256_cvttps_epi32(rt);
339             vfeps            = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
340             /*         AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
341             vfitab_lo        = _mm256_extractf128_si256(vfitab,0x0);
342             vfitab_hi        = _mm256_extractf128_si256(vfitab,0x1);
343             vfitab_lo        = _mm_slli_epi32(vfitab_lo,3);
344             vfitab_hi        = _mm_slli_epi32(vfitab_hi,3);
345
346             /* REACTION-FIELD ELECTROSTATICS */
347             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
348             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
349
350             /* CUBIC SPLINE TABLE DISPERSION */
351             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
352                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
353             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
354                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
355             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
356                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
357             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
358                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
359             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
360             Heps             = _mm256_mul_ps(vfeps,H);
361             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
362             VV               = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
363             vvdw6            = _mm256_mul_ps(c6_00,VV);
364             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
365             fvdw6            = _mm256_mul_ps(c6_00,FF);
366
367             /* CUBIC SPLINE TABLE REPULSION */
368             vfitab_lo        = _mm_add_epi32(vfitab_lo,ifour);
369             vfitab_hi        = _mm_add_epi32(vfitab_hi,ifour);
370             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
371                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
372             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
373                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
374             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
375                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
376             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
377                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
378             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
379             Heps             = _mm256_mul_ps(vfeps,H);
380             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
381             VV               = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
382             vvdw12           = _mm256_mul_ps(c12_00,VV);
383             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
384             fvdw12           = _mm256_mul_ps(c12_00,FF);
385             vvdw             = _mm256_add_ps(vvdw12,vvdw6);
386             fvdw             = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
387
388             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
389
390             /* Update potential sum for this i atom from the interaction with this j atom. */
391             velec            = _mm256_and_ps(velec,cutoff_mask);
392             velecsum         = _mm256_add_ps(velecsum,velec);
393             vvdw             = _mm256_and_ps(vvdw,cutoff_mask);
394             vvdwsum          = _mm256_add_ps(vvdwsum,vvdw);
395
396             fscal            = _mm256_add_ps(felec,fvdw);
397
398             fscal            = _mm256_and_ps(fscal,cutoff_mask);
399
400             /* Calculate temporary vectorial force */
401             tx               = _mm256_mul_ps(fscal,dx00);
402             ty               = _mm256_mul_ps(fscal,dy00);
403             tz               = _mm256_mul_ps(fscal,dz00);
404
405             /* Update vectorial force */
406             fix0             = _mm256_add_ps(fix0,tx);
407             fiy0             = _mm256_add_ps(fiy0,ty);
408             fiz0             = _mm256_add_ps(fiz0,tz);
409
410             fjx0             = _mm256_add_ps(fjx0,tx);
411             fjy0             = _mm256_add_ps(fjy0,ty);
412             fjz0             = _mm256_add_ps(fjz0,tz);
413
414             }
415
416             /**************************
417              * CALCULATE INTERACTIONS *
418              **************************/
419
420             if (gmx_mm256_any_lt(rsq01,rcutoff2))
421             {
422
423             /* REACTION-FIELD ELECTROSTATICS */
424             velec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
425             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
426
427             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
428
429             /* Update potential sum for this i atom from the interaction with this j atom. */
430             velec            = _mm256_and_ps(velec,cutoff_mask);
431             velecsum         = _mm256_add_ps(velecsum,velec);
432
433             fscal            = felec;
434
435             fscal            = _mm256_and_ps(fscal,cutoff_mask);
436
437             /* Calculate temporary vectorial force */
438             tx               = _mm256_mul_ps(fscal,dx01);
439             ty               = _mm256_mul_ps(fscal,dy01);
440             tz               = _mm256_mul_ps(fscal,dz01);
441
442             /* Update vectorial force */
443             fix0             = _mm256_add_ps(fix0,tx);
444             fiy0             = _mm256_add_ps(fiy0,ty);
445             fiz0             = _mm256_add_ps(fiz0,tz);
446
447             fjx1             = _mm256_add_ps(fjx1,tx);
448             fjy1             = _mm256_add_ps(fjy1,ty);
449             fjz1             = _mm256_add_ps(fjz1,tz);
450
451             }
452
453             /**************************
454              * CALCULATE INTERACTIONS *
455              **************************/
456
457             if (gmx_mm256_any_lt(rsq02,rcutoff2))
458             {
459
460             /* REACTION-FIELD ELECTROSTATICS */
461             velec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
462             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
463
464             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
465
466             /* Update potential sum for this i atom from the interaction with this j atom. */
467             velec            = _mm256_and_ps(velec,cutoff_mask);
468             velecsum         = _mm256_add_ps(velecsum,velec);
469
470             fscal            = felec;
471
472             fscal            = _mm256_and_ps(fscal,cutoff_mask);
473
474             /* Calculate temporary vectorial force */
475             tx               = _mm256_mul_ps(fscal,dx02);
476             ty               = _mm256_mul_ps(fscal,dy02);
477             tz               = _mm256_mul_ps(fscal,dz02);
478
479             /* Update vectorial force */
480             fix0             = _mm256_add_ps(fix0,tx);
481             fiy0             = _mm256_add_ps(fiy0,ty);
482             fiz0             = _mm256_add_ps(fiz0,tz);
483
484             fjx2             = _mm256_add_ps(fjx2,tx);
485             fjy2             = _mm256_add_ps(fjy2,ty);
486             fjz2             = _mm256_add_ps(fjz2,tz);
487
488             }
489
490             /**************************
491              * CALCULATE INTERACTIONS *
492              **************************/
493
494             if (gmx_mm256_any_lt(rsq10,rcutoff2))
495             {
496
497             /* REACTION-FIELD ELECTROSTATICS */
498             velec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
499             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
500
501             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
502
503             /* Update potential sum for this i atom from the interaction with this j atom. */
504             velec            = _mm256_and_ps(velec,cutoff_mask);
505             velecsum         = _mm256_add_ps(velecsum,velec);
506
507             fscal            = felec;
508
509             fscal            = _mm256_and_ps(fscal,cutoff_mask);
510
511             /* Calculate temporary vectorial force */
512             tx               = _mm256_mul_ps(fscal,dx10);
513             ty               = _mm256_mul_ps(fscal,dy10);
514             tz               = _mm256_mul_ps(fscal,dz10);
515
516             /* Update vectorial force */
517             fix1             = _mm256_add_ps(fix1,tx);
518             fiy1             = _mm256_add_ps(fiy1,ty);
519             fiz1             = _mm256_add_ps(fiz1,tz);
520
521             fjx0             = _mm256_add_ps(fjx0,tx);
522             fjy0             = _mm256_add_ps(fjy0,ty);
523             fjz0             = _mm256_add_ps(fjz0,tz);
524
525             }
526
527             /**************************
528              * CALCULATE INTERACTIONS *
529              **************************/
530
531             if (gmx_mm256_any_lt(rsq11,rcutoff2))
532             {
533
534             /* REACTION-FIELD ELECTROSTATICS */
535             velec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
536             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
537
538             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
539
540             /* Update potential sum for this i atom from the interaction with this j atom. */
541             velec            = _mm256_and_ps(velec,cutoff_mask);
542             velecsum         = _mm256_add_ps(velecsum,velec);
543
544             fscal            = felec;
545
546             fscal            = _mm256_and_ps(fscal,cutoff_mask);
547
548             /* Calculate temporary vectorial force */
549             tx               = _mm256_mul_ps(fscal,dx11);
550             ty               = _mm256_mul_ps(fscal,dy11);
551             tz               = _mm256_mul_ps(fscal,dz11);
552
553             /* Update vectorial force */
554             fix1             = _mm256_add_ps(fix1,tx);
555             fiy1             = _mm256_add_ps(fiy1,ty);
556             fiz1             = _mm256_add_ps(fiz1,tz);
557
558             fjx1             = _mm256_add_ps(fjx1,tx);
559             fjy1             = _mm256_add_ps(fjy1,ty);
560             fjz1             = _mm256_add_ps(fjz1,tz);
561
562             }
563
564             /**************************
565              * CALCULATE INTERACTIONS *
566              **************************/
567
568             if (gmx_mm256_any_lt(rsq12,rcutoff2))
569             {
570
571             /* REACTION-FIELD ELECTROSTATICS */
572             velec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
573             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
574
575             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
576
577             /* Update potential sum for this i atom from the interaction with this j atom. */
578             velec            = _mm256_and_ps(velec,cutoff_mask);
579             velecsum         = _mm256_add_ps(velecsum,velec);
580
581             fscal            = felec;
582
583             fscal            = _mm256_and_ps(fscal,cutoff_mask);
584
585             /* Calculate temporary vectorial force */
586             tx               = _mm256_mul_ps(fscal,dx12);
587             ty               = _mm256_mul_ps(fscal,dy12);
588             tz               = _mm256_mul_ps(fscal,dz12);
589
590             /* Update vectorial force */
591             fix1             = _mm256_add_ps(fix1,tx);
592             fiy1             = _mm256_add_ps(fiy1,ty);
593             fiz1             = _mm256_add_ps(fiz1,tz);
594
595             fjx2             = _mm256_add_ps(fjx2,tx);
596             fjy2             = _mm256_add_ps(fjy2,ty);
597             fjz2             = _mm256_add_ps(fjz2,tz);
598
599             }
600
601             /**************************
602              * CALCULATE INTERACTIONS *
603              **************************/
604
605             if (gmx_mm256_any_lt(rsq20,rcutoff2))
606             {
607
608             /* REACTION-FIELD ELECTROSTATICS */
609             velec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
610             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
611
612             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
613
614             /* Update potential sum for this i atom from the interaction with this j atom. */
615             velec            = _mm256_and_ps(velec,cutoff_mask);
616             velecsum         = _mm256_add_ps(velecsum,velec);
617
618             fscal            = felec;
619
620             fscal            = _mm256_and_ps(fscal,cutoff_mask);
621
622             /* Calculate temporary vectorial force */
623             tx               = _mm256_mul_ps(fscal,dx20);
624             ty               = _mm256_mul_ps(fscal,dy20);
625             tz               = _mm256_mul_ps(fscal,dz20);
626
627             /* Update vectorial force */
628             fix2             = _mm256_add_ps(fix2,tx);
629             fiy2             = _mm256_add_ps(fiy2,ty);
630             fiz2             = _mm256_add_ps(fiz2,tz);
631
632             fjx0             = _mm256_add_ps(fjx0,tx);
633             fjy0             = _mm256_add_ps(fjy0,ty);
634             fjz0             = _mm256_add_ps(fjz0,tz);
635
636             }
637
638             /**************************
639              * CALCULATE INTERACTIONS *
640              **************************/
641
642             if (gmx_mm256_any_lt(rsq21,rcutoff2))
643             {
644
645             /* REACTION-FIELD ELECTROSTATICS */
646             velec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
647             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
648
649             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
650
651             /* Update potential sum for this i atom from the interaction with this j atom. */
652             velec            = _mm256_and_ps(velec,cutoff_mask);
653             velecsum         = _mm256_add_ps(velecsum,velec);
654
655             fscal            = felec;
656
657             fscal            = _mm256_and_ps(fscal,cutoff_mask);
658
659             /* Calculate temporary vectorial force */
660             tx               = _mm256_mul_ps(fscal,dx21);
661             ty               = _mm256_mul_ps(fscal,dy21);
662             tz               = _mm256_mul_ps(fscal,dz21);
663
664             /* Update vectorial force */
665             fix2             = _mm256_add_ps(fix2,tx);
666             fiy2             = _mm256_add_ps(fiy2,ty);
667             fiz2             = _mm256_add_ps(fiz2,tz);
668
669             fjx1             = _mm256_add_ps(fjx1,tx);
670             fjy1             = _mm256_add_ps(fjy1,ty);
671             fjz1             = _mm256_add_ps(fjz1,tz);
672
673             }
674
675             /**************************
676              * CALCULATE INTERACTIONS *
677              **************************/
678
679             if (gmx_mm256_any_lt(rsq22,rcutoff2))
680             {
681
682             /* REACTION-FIELD ELECTROSTATICS */
683             velec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
684             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
685
686             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
687
688             /* Update potential sum for this i atom from the interaction with this j atom. */
689             velec            = _mm256_and_ps(velec,cutoff_mask);
690             velecsum         = _mm256_add_ps(velecsum,velec);
691
692             fscal            = felec;
693
694             fscal            = _mm256_and_ps(fscal,cutoff_mask);
695
696             /* Calculate temporary vectorial force */
697             tx               = _mm256_mul_ps(fscal,dx22);
698             ty               = _mm256_mul_ps(fscal,dy22);
699             tz               = _mm256_mul_ps(fscal,dz22);
700
701             /* Update vectorial force */
702             fix2             = _mm256_add_ps(fix2,tx);
703             fiy2             = _mm256_add_ps(fiy2,ty);
704             fiz2             = _mm256_add_ps(fiz2,tz);
705
706             fjx2             = _mm256_add_ps(fjx2,tx);
707             fjy2             = _mm256_add_ps(fjy2,ty);
708             fjz2             = _mm256_add_ps(fjz2,tz);
709
710             }
711
712             fjptrA             = f+j_coord_offsetA;
713             fjptrB             = f+j_coord_offsetB;
714             fjptrC             = f+j_coord_offsetC;
715             fjptrD             = f+j_coord_offsetD;
716             fjptrE             = f+j_coord_offsetE;
717             fjptrF             = f+j_coord_offsetF;
718             fjptrG             = f+j_coord_offsetG;
719             fjptrH             = f+j_coord_offsetH;
720
721             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
722                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
723
724             /* Inner loop uses 360 flops */
725         }
726
727         if(jidx<j_index_end)
728         {
729
730             /* Get j neighbor index, and coordinate index */
731             jnrlistA         = jjnr[jidx];
732             jnrlistB         = jjnr[jidx+1];
733             jnrlistC         = jjnr[jidx+2];
734             jnrlistD         = jjnr[jidx+3];
735             jnrlistE         = jjnr[jidx+4];
736             jnrlistF         = jjnr[jidx+5];
737             jnrlistG         = jjnr[jidx+6];
738             jnrlistH         = jjnr[jidx+7];
739             /* Sign of each element will be negative for non-real atoms.
740              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
741              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
742              */
743             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
744                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
745                                             
746             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
747             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
748             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
749             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
750             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
751             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
752             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
753             jnrH       = (jnrlistH>=0) ? jnrlistH : 0;
754             j_coord_offsetA  = DIM*jnrA;
755             j_coord_offsetB  = DIM*jnrB;
756             j_coord_offsetC  = DIM*jnrC;
757             j_coord_offsetD  = DIM*jnrD;
758             j_coord_offsetE  = DIM*jnrE;
759             j_coord_offsetF  = DIM*jnrF;
760             j_coord_offsetG  = DIM*jnrG;
761             j_coord_offsetH  = DIM*jnrH;
762
763             /* load j atom coordinates */
764             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
765                                                  x+j_coord_offsetC,x+j_coord_offsetD,
766                                                  x+j_coord_offsetE,x+j_coord_offsetF,
767                                                  x+j_coord_offsetG,x+j_coord_offsetH,
768                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
769
770             /* Calculate displacement vector */
771             dx00             = _mm256_sub_ps(ix0,jx0);
772             dy00             = _mm256_sub_ps(iy0,jy0);
773             dz00             = _mm256_sub_ps(iz0,jz0);
774             dx01             = _mm256_sub_ps(ix0,jx1);
775             dy01             = _mm256_sub_ps(iy0,jy1);
776             dz01             = _mm256_sub_ps(iz0,jz1);
777             dx02             = _mm256_sub_ps(ix0,jx2);
778             dy02             = _mm256_sub_ps(iy0,jy2);
779             dz02             = _mm256_sub_ps(iz0,jz2);
780             dx10             = _mm256_sub_ps(ix1,jx0);
781             dy10             = _mm256_sub_ps(iy1,jy0);
782             dz10             = _mm256_sub_ps(iz1,jz0);
783             dx11             = _mm256_sub_ps(ix1,jx1);
784             dy11             = _mm256_sub_ps(iy1,jy1);
785             dz11             = _mm256_sub_ps(iz1,jz1);
786             dx12             = _mm256_sub_ps(ix1,jx2);
787             dy12             = _mm256_sub_ps(iy1,jy2);
788             dz12             = _mm256_sub_ps(iz1,jz2);
789             dx20             = _mm256_sub_ps(ix2,jx0);
790             dy20             = _mm256_sub_ps(iy2,jy0);
791             dz20             = _mm256_sub_ps(iz2,jz0);
792             dx21             = _mm256_sub_ps(ix2,jx1);
793             dy21             = _mm256_sub_ps(iy2,jy1);
794             dz21             = _mm256_sub_ps(iz2,jz1);
795             dx22             = _mm256_sub_ps(ix2,jx2);
796             dy22             = _mm256_sub_ps(iy2,jy2);
797             dz22             = _mm256_sub_ps(iz2,jz2);
798
799             /* Calculate squared distance and things based on it */
800             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
801             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
802             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
803             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
804             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
805             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
806             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
807             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
808             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
809
810             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
811             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
812             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
813             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
814             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
815             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
816             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
817             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
818             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
819
820             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
821             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
822             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
823             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
824             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
825             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
826             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
827             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
828             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
829
830             fjx0             = _mm256_setzero_ps();
831             fjy0             = _mm256_setzero_ps();
832             fjz0             = _mm256_setzero_ps();
833             fjx1             = _mm256_setzero_ps();
834             fjy1             = _mm256_setzero_ps();
835             fjz1             = _mm256_setzero_ps();
836             fjx2             = _mm256_setzero_ps();
837             fjy2             = _mm256_setzero_ps();
838             fjz2             = _mm256_setzero_ps();
839
840             /**************************
841              * CALCULATE INTERACTIONS *
842              **************************/
843
844             if (gmx_mm256_any_lt(rsq00,rcutoff2))
845             {
846
847             r00              = _mm256_mul_ps(rsq00,rinv00);
848             r00              = _mm256_andnot_ps(dummy_mask,r00);
849
850             /* Calculate table index by multiplying r with table scale and truncate to integer */
851             rt               = _mm256_mul_ps(r00,vftabscale);
852             vfitab           = _mm256_cvttps_epi32(rt);
853             vfeps            = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
854             /*         AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
855             vfitab_lo        = _mm256_extractf128_si256(vfitab,0x0);
856             vfitab_hi        = _mm256_extractf128_si256(vfitab,0x1);
857             vfitab_lo        = _mm_slli_epi32(vfitab_lo,3);
858             vfitab_hi        = _mm_slli_epi32(vfitab_hi,3);
859
860             /* REACTION-FIELD ELECTROSTATICS */
861             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
862             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
863
864             /* CUBIC SPLINE TABLE DISPERSION */
865             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
866                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
867             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
868                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
869             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
870                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
871             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
872                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
873             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
874             Heps             = _mm256_mul_ps(vfeps,H);
875             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
876             VV               = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
877             vvdw6            = _mm256_mul_ps(c6_00,VV);
878             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
879             fvdw6            = _mm256_mul_ps(c6_00,FF);
880
881             /* CUBIC SPLINE TABLE REPULSION */
882             vfitab_lo        = _mm_add_epi32(vfitab_lo,ifour);
883             vfitab_hi        = _mm_add_epi32(vfitab_hi,ifour);
884             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
885                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
886             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
887                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
888             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
889                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
890             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
891                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
892             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
893             Heps             = _mm256_mul_ps(vfeps,H);
894             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
895             VV               = _mm256_add_ps(Y,_mm256_mul_ps(vfeps,Fp));
896             vvdw12           = _mm256_mul_ps(c12_00,VV);
897             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
898             fvdw12           = _mm256_mul_ps(c12_00,FF);
899             vvdw             = _mm256_add_ps(vvdw12,vvdw6);
900             fvdw             = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
901
902             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
903
904             /* Update potential sum for this i atom from the interaction with this j atom. */
905             velec            = _mm256_and_ps(velec,cutoff_mask);
906             velec            = _mm256_andnot_ps(dummy_mask,velec);
907             velecsum         = _mm256_add_ps(velecsum,velec);
908             vvdw             = _mm256_and_ps(vvdw,cutoff_mask);
909             vvdw             = _mm256_andnot_ps(dummy_mask,vvdw);
910             vvdwsum          = _mm256_add_ps(vvdwsum,vvdw);
911
912             fscal            = _mm256_add_ps(felec,fvdw);
913
914             fscal            = _mm256_and_ps(fscal,cutoff_mask);
915
916             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
917
918             /* Calculate temporary vectorial force */
919             tx               = _mm256_mul_ps(fscal,dx00);
920             ty               = _mm256_mul_ps(fscal,dy00);
921             tz               = _mm256_mul_ps(fscal,dz00);
922
923             /* Update vectorial force */
924             fix0             = _mm256_add_ps(fix0,tx);
925             fiy0             = _mm256_add_ps(fiy0,ty);
926             fiz0             = _mm256_add_ps(fiz0,tz);
927
928             fjx0             = _mm256_add_ps(fjx0,tx);
929             fjy0             = _mm256_add_ps(fjy0,ty);
930             fjz0             = _mm256_add_ps(fjz0,tz);
931
932             }
933
934             /**************************
935              * CALCULATE INTERACTIONS *
936              **************************/
937
938             if (gmx_mm256_any_lt(rsq01,rcutoff2))
939             {
940
941             /* REACTION-FIELD ELECTROSTATICS */
942             velec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
943             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
944
945             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
946
947             /* Update potential sum for this i atom from the interaction with this j atom. */
948             velec            = _mm256_and_ps(velec,cutoff_mask);
949             velec            = _mm256_andnot_ps(dummy_mask,velec);
950             velecsum         = _mm256_add_ps(velecsum,velec);
951
952             fscal            = felec;
953
954             fscal            = _mm256_and_ps(fscal,cutoff_mask);
955
956             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
957
958             /* Calculate temporary vectorial force */
959             tx               = _mm256_mul_ps(fscal,dx01);
960             ty               = _mm256_mul_ps(fscal,dy01);
961             tz               = _mm256_mul_ps(fscal,dz01);
962
963             /* Update vectorial force */
964             fix0             = _mm256_add_ps(fix0,tx);
965             fiy0             = _mm256_add_ps(fiy0,ty);
966             fiz0             = _mm256_add_ps(fiz0,tz);
967
968             fjx1             = _mm256_add_ps(fjx1,tx);
969             fjy1             = _mm256_add_ps(fjy1,ty);
970             fjz1             = _mm256_add_ps(fjz1,tz);
971
972             }
973
974             /**************************
975              * CALCULATE INTERACTIONS *
976              **************************/
977
978             if (gmx_mm256_any_lt(rsq02,rcutoff2))
979             {
980
981             /* REACTION-FIELD ELECTROSTATICS */
982             velec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
983             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
984
985             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
986
987             /* Update potential sum for this i atom from the interaction with this j atom. */
988             velec            = _mm256_and_ps(velec,cutoff_mask);
989             velec            = _mm256_andnot_ps(dummy_mask,velec);
990             velecsum         = _mm256_add_ps(velecsum,velec);
991
992             fscal            = felec;
993
994             fscal            = _mm256_and_ps(fscal,cutoff_mask);
995
996             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
997
998             /* Calculate temporary vectorial force */
999             tx               = _mm256_mul_ps(fscal,dx02);
1000             ty               = _mm256_mul_ps(fscal,dy02);
1001             tz               = _mm256_mul_ps(fscal,dz02);
1002
1003             /* Update vectorial force */
1004             fix0             = _mm256_add_ps(fix0,tx);
1005             fiy0             = _mm256_add_ps(fiy0,ty);
1006             fiz0             = _mm256_add_ps(fiz0,tz);
1007
1008             fjx2             = _mm256_add_ps(fjx2,tx);
1009             fjy2             = _mm256_add_ps(fjy2,ty);
1010             fjz2             = _mm256_add_ps(fjz2,tz);
1011
1012             }
1013
1014             /**************************
1015              * CALCULATE INTERACTIONS *
1016              **************************/
1017
1018             if (gmx_mm256_any_lt(rsq10,rcutoff2))
1019             {
1020
1021             /* REACTION-FIELD ELECTROSTATICS */
1022             velec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
1023             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1024
1025             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1026
1027             /* Update potential sum for this i atom from the interaction with this j atom. */
1028             velec            = _mm256_and_ps(velec,cutoff_mask);
1029             velec            = _mm256_andnot_ps(dummy_mask,velec);
1030             velecsum         = _mm256_add_ps(velecsum,velec);
1031
1032             fscal            = felec;
1033
1034             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1035
1036             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1037
1038             /* Calculate temporary vectorial force */
1039             tx               = _mm256_mul_ps(fscal,dx10);
1040             ty               = _mm256_mul_ps(fscal,dy10);
1041             tz               = _mm256_mul_ps(fscal,dz10);
1042
1043             /* Update vectorial force */
1044             fix1             = _mm256_add_ps(fix1,tx);
1045             fiy1             = _mm256_add_ps(fiy1,ty);
1046             fiz1             = _mm256_add_ps(fiz1,tz);
1047
1048             fjx0             = _mm256_add_ps(fjx0,tx);
1049             fjy0             = _mm256_add_ps(fjy0,ty);
1050             fjz0             = _mm256_add_ps(fjz0,tz);
1051
1052             }
1053
1054             /**************************
1055              * CALCULATE INTERACTIONS *
1056              **************************/
1057
1058             if (gmx_mm256_any_lt(rsq11,rcutoff2))
1059             {
1060
1061             /* REACTION-FIELD ELECTROSTATICS */
1062             velec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
1063             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1064
1065             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1066
1067             /* Update potential sum for this i atom from the interaction with this j atom. */
1068             velec            = _mm256_and_ps(velec,cutoff_mask);
1069             velec            = _mm256_andnot_ps(dummy_mask,velec);
1070             velecsum         = _mm256_add_ps(velecsum,velec);
1071
1072             fscal            = felec;
1073
1074             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1075
1076             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1077
1078             /* Calculate temporary vectorial force */
1079             tx               = _mm256_mul_ps(fscal,dx11);
1080             ty               = _mm256_mul_ps(fscal,dy11);
1081             tz               = _mm256_mul_ps(fscal,dz11);
1082
1083             /* Update vectorial force */
1084             fix1             = _mm256_add_ps(fix1,tx);
1085             fiy1             = _mm256_add_ps(fiy1,ty);
1086             fiz1             = _mm256_add_ps(fiz1,tz);
1087
1088             fjx1             = _mm256_add_ps(fjx1,tx);
1089             fjy1             = _mm256_add_ps(fjy1,ty);
1090             fjz1             = _mm256_add_ps(fjz1,tz);
1091
1092             }
1093
1094             /**************************
1095              * CALCULATE INTERACTIONS *
1096              **************************/
1097
1098             if (gmx_mm256_any_lt(rsq12,rcutoff2))
1099             {
1100
1101             /* REACTION-FIELD ELECTROSTATICS */
1102             velec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
1103             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1104
1105             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1106
1107             /* Update potential sum for this i atom from the interaction with this j atom. */
1108             velec            = _mm256_and_ps(velec,cutoff_mask);
1109             velec            = _mm256_andnot_ps(dummy_mask,velec);
1110             velecsum         = _mm256_add_ps(velecsum,velec);
1111
1112             fscal            = felec;
1113
1114             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1115
1116             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1117
1118             /* Calculate temporary vectorial force */
1119             tx               = _mm256_mul_ps(fscal,dx12);
1120             ty               = _mm256_mul_ps(fscal,dy12);
1121             tz               = _mm256_mul_ps(fscal,dz12);
1122
1123             /* Update vectorial force */
1124             fix1             = _mm256_add_ps(fix1,tx);
1125             fiy1             = _mm256_add_ps(fiy1,ty);
1126             fiz1             = _mm256_add_ps(fiz1,tz);
1127
1128             fjx2             = _mm256_add_ps(fjx2,tx);
1129             fjy2             = _mm256_add_ps(fjy2,ty);
1130             fjz2             = _mm256_add_ps(fjz2,tz);
1131
1132             }
1133
1134             /**************************
1135              * CALCULATE INTERACTIONS *
1136              **************************/
1137
1138             if (gmx_mm256_any_lt(rsq20,rcutoff2))
1139             {
1140
1141             /* REACTION-FIELD ELECTROSTATICS */
1142             velec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
1143             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1144
1145             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1146
1147             /* Update potential sum for this i atom from the interaction with this j atom. */
1148             velec            = _mm256_and_ps(velec,cutoff_mask);
1149             velec            = _mm256_andnot_ps(dummy_mask,velec);
1150             velecsum         = _mm256_add_ps(velecsum,velec);
1151
1152             fscal            = felec;
1153
1154             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1155
1156             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1157
1158             /* Calculate temporary vectorial force */
1159             tx               = _mm256_mul_ps(fscal,dx20);
1160             ty               = _mm256_mul_ps(fscal,dy20);
1161             tz               = _mm256_mul_ps(fscal,dz20);
1162
1163             /* Update vectorial force */
1164             fix2             = _mm256_add_ps(fix2,tx);
1165             fiy2             = _mm256_add_ps(fiy2,ty);
1166             fiz2             = _mm256_add_ps(fiz2,tz);
1167
1168             fjx0             = _mm256_add_ps(fjx0,tx);
1169             fjy0             = _mm256_add_ps(fjy0,ty);
1170             fjz0             = _mm256_add_ps(fjz0,tz);
1171
1172             }
1173
1174             /**************************
1175              * CALCULATE INTERACTIONS *
1176              **************************/
1177
1178             if (gmx_mm256_any_lt(rsq21,rcutoff2))
1179             {
1180
1181             /* REACTION-FIELD ELECTROSTATICS */
1182             velec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1183             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1184
1185             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1186
1187             /* Update potential sum for this i atom from the interaction with this j atom. */
1188             velec            = _mm256_and_ps(velec,cutoff_mask);
1189             velec            = _mm256_andnot_ps(dummy_mask,velec);
1190             velecsum         = _mm256_add_ps(velecsum,velec);
1191
1192             fscal            = felec;
1193
1194             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1195
1196             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1197
1198             /* Calculate temporary vectorial force */
1199             tx               = _mm256_mul_ps(fscal,dx21);
1200             ty               = _mm256_mul_ps(fscal,dy21);
1201             tz               = _mm256_mul_ps(fscal,dz21);
1202
1203             /* Update vectorial force */
1204             fix2             = _mm256_add_ps(fix2,tx);
1205             fiy2             = _mm256_add_ps(fiy2,ty);
1206             fiz2             = _mm256_add_ps(fiz2,tz);
1207
1208             fjx1             = _mm256_add_ps(fjx1,tx);
1209             fjy1             = _mm256_add_ps(fjy1,ty);
1210             fjz1             = _mm256_add_ps(fjz1,tz);
1211
1212             }
1213
1214             /**************************
1215              * CALCULATE INTERACTIONS *
1216              **************************/
1217
1218             if (gmx_mm256_any_lt(rsq22,rcutoff2))
1219             {
1220
1221             /* REACTION-FIELD ELECTROSTATICS */
1222             velec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1223             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1224
1225             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1226
1227             /* Update potential sum for this i atom from the interaction with this j atom. */
1228             velec            = _mm256_and_ps(velec,cutoff_mask);
1229             velec            = _mm256_andnot_ps(dummy_mask,velec);
1230             velecsum         = _mm256_add_ps(velecsum,velec);
1231
1232             fscal            = felec;
1233
1234             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1235
1236             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1237
1238             /* Calculate temporary vectorial force */
1239             tx               = _mm256_mul_ps(fscal,dx22);
1240             ty               = _mm256_mul_ps(fscal,dy22);
1241             tz               = _mm256_mul_ps(fscal,dz22);
1242
1243             /* Update vectorial force */
1244             fix2             = _mm256_add_ps(fix2,tx);
1245             fiy2             = _mm256_add_ps(fiy2,ty);
1246             fiz2             = _mm256_add_ps(fiz2,tz);
1247
1248             fjx2             = _mm256_add_ps(fjx2,tx);
1249             fjy2             = _mm256_add_ps(fjy2,ty);
1250             fjz2             = _mm256_add_ps(fjz2,tz);
1251
1252             }
1253
1254             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1255             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1256             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1257             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1258             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1259             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1260             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1261             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1262
1263             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1264                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1265
1266             /* Inner loop uses 361 flops */
1267         }
1268
1269         /* End of innermost loop */
1270
1271         gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1272                                                  f+i_coord_offset,fshift+i_shift_offset);
1273
1274         ggid                        = gid[iidx];
1275         /* Update potential energies */
1276         gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1277         gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1278
1279         /* Increment number of inner iterations */
1280         inneriter                  += j_index_end - j_index_start;
1281
1282         /* Outer loop uses 20 flops */
1283     }
1284
1285     /* Increment number of outer iterations */
1286     outeriter        += nri;
1287
1288     /* Update outer/inner flops */
1289
1290     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*361);
1291 }
1292 /*
1293  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1294  * Electrostatics interaction: ReactionField
1295  * VdW interaction:            CubicSplineTable
1296  * Geometry:                   Water3-Water3
1297  * Calculate force/pot:        Force
1298  */
1299 void
1300 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_256_single
1301                     (t_nblist                    * gmx_restrict       nlist,
1302                      rvec                        * gmx_restrict          xx,
1303                      rvec                        * gmx_restrict          ff,
1304                      t_forcerec                  * gmx_restrict          fr,
1305                      t_mdatoms                   * gmx_restrict     mdatoms,
1306                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1307                      t_nrnb                      * gmx_restrict        nrnb)
1308 {
1309     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
1310      * just 0 for non-waters.
1311      * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1312      * jnr indices corresponding to data put in the four positions in the SIMD register.
1313      */
1314     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
1315     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1316     int              jnrA,jnrB,jnrC,jnrD;
1317     int              jnrE,jnrF,jnrG,jnrH;
1318     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1319     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1320     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1321     int              j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1322     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
1323     real             rcutoff_scalar;
1324     real             *shiftvec,*fshift,*x,*f;
1325     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1326     real             scratch[4*DIM];
1327     __m256           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1328     real *           vdwioffsetptr0;
1329     __m256           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1330     real *           vdwioffsetptr1;
1331     __m256           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1332     real *           vdwioffsetptr2;
1333     __m256           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1334     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1335     __m256           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1336     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1337     __m256           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1338     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1339     __m256           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1340     __m256           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1341     __m256           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1342     __m256           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1343     __m256           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1344     __m256           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1345     __m256           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1346     __m256           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1347     __m256           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1348     __m256           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1349     __m256           velec,felec,velecsum,facel,crf,krf,krf2;
1350     real             *charge;
1351     int              nvdwtype;
1352     __m256           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1353     int              *vdwtype;
1354     real             *vdwparam;
1355     __m256           one_sixth   = _mm256_set1_ps(1.0/6.0);
1356     __m256           one_twelfth = _mm256_set1_ps(1.0/12.0);
1357     __m256i          vfitab;
1358     __m128i          vfitab_lo,vfitab_hi;
1359     __m128i          ifour       = _mm_set1_epi32(4);
1360     __m256           rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
1361     real             *vftab;
1362     __m256           dummy_mask,cutoff_mask;
1363     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1364     __m256           one     = _mm256_set1_ps(1.0);
1365     __m256           two     = _mm256_set1_ps(2.0);
1366     x                = xx[0];
1367     f                = ff[0];
1368
1369     nri              = nlist->nri;
1370     iinr             = nlist->iinr;
1371     jindex           = nlist->jindex;
1372     jjnr             = nlist->jjnr;
1373     shiftidx         = nlist->shift;
1374     gid              = nlist->gid;
1375     shiftvec         = fr->shift_vec[0];
1376     fshift           = fr->fshift[0];
1377     facel            = _mm256_set1_ps(fr->epsfac);
1378     charge           = mdatoms->chargeA;
1379     krf              = _mm256_set1_ps(fr->ic->k_rf);
1380     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
1381     crf              = _mm256_set1_ps(fr->ic->c_rf);
1382     nvdwtype         = fr->ntype;
1383     vdwparam         = fr->nbfp;
1384     vdwtype          = mdatoms->typeA;
1385
1386     vftab            = kernel_data->table_vdw->data;
1387     vftabscale       = _mm256_set1_ps(kernel_data->table_vdw->scale);
1388
1389     /* Setup water-specific parameters */
1390     inr              = nlist->iinr[0];
1391     iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
1392     iq1              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1393     iq2              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1394     vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
1395
1396     jq0              = _mm256_set1_ps(charge[inr+0]);
1397     jq1              = _mm256_set1_ps(charge[inr+1]);
1398     jq2              = _mm256_set1_ps(charge[inr+2]);
1399     vdwjidx0A        = 2*vdwtype[inr+0];
1400     qq00             = _mm256_mul_ps(iq0,jq0);
1401     c6_00            = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1402     c12_00           = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1403     qq01             = _mm256_mul_ps(iq0,jq1);
1404     qq02             = _mm256_mul_ps(iq0,jq2);
1405     qq10             = _mm256_mul_ps(iq1,jq0);
1406     qq11             = _mm256_mul_ps(iq1,jq1);
1407     qq12             = _mm256_mul_ps(iq1,jq2);
1408     qq20             = _mm256_mul_ps(iq2,jq0);
1409     qq21             = _mm256_mul_ps(iq2,jq1);
1410     qq22             = _mm256_mul_ps(iq2,jq2);
1411
1412     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1413     rcutoff_scalar   = fr->rcoulomb;
1414     rcutoff          = _mm256_set1_ps(rcutoff_scalar);
1415     rcutoff2         = _mm256_mul_ps(rcutoff,rcutoff);
1416
1417     /* Avoid stupid compiler warnings */
1418     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1419     j_coord_offsetA = 0;
1420     j_coord_offsetB = 0;
1421     j_coord_offsetC = 0;
1422     j_coord_offsetD = 0;
1423     j_coord_offsetE = 0;
1424     j_coord_offsetF = 0;
1425     j_coord_offsetG = 0;
1426     j_coord_offsetH = 0;
1427
1428     outeriter        = 0;
1429     inneriter        = 0;
1430
1431     for(iidx=0;iidx<4*DIM;iidx++)
1432     {
1433         scratch[iidx] = 0.0;
1434     }
1435
1436     /* Start outer loop over neighborlists */
1437     for(iidx=0; iidx<nri; iidx++)
1438     {
1439         /* Load shift vector for this list */
1440         i_shift_offset   = DIM*shiftidx[iidx];
1441
1442         /* Load limits for loop over neighbors */
1443         j_index_start    = jindex[iidx];
1444         j_index_end      = jindex[iidx+1];
1445
1446         /* Get outer coordinate index */
1447         inr              = iinr[iidx];
1448         i_coord_offset   = DIM*inr;
1449
1450         /* Load i particle coords and add shift vector */
1451         gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1452                                                     &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1453
1454         fix0             = _mm256_setzero_ps();
1455         fiy0             = _mm256_setzero_ps();
1456         fiz0             = _mm256_setzero_ps();
1457         fix1             = _mm256_setzero_ps();
1458         fiy1             = _mm256_setzero_ps();
1459         fiz1             = _mm256_setzero_ps();
1460         fix2             = _mm256_setzero_ps();
1461         fiy2             = _mm256_setzero_ps();
1462         fiz2             = _mm256_setzero_ps();
1463
1464         /* Start inner kernel loop */
1465         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1466         {
1467
1468             /* Get j neighbor index, and coordinate index */
1469             jnrA             = jjnr[jidx];
1470             jnrB             = jjnr[jidx+1];
1471             jnrC             = jjnr[jidx+2];
1472             jnrD             = jjnr[jidx+3];
1473             jnrE             = jjnr[jidx+4];
1474             jnrF             = jjnr[jidx+5];
1475             jnrG             = jjnr[jidx+6];
1476             jnrH             = jjnr[jidx+7];
1477             j_coord_offsetA  = DIM*jnrA;
1478             j_coord_offsetB  = DIM*jnrB;
1479             j_coord_offsetC  = DIM*jnrC;
1480             j_coord_offsetD  = DIM*jnrD;
1481             j_coord_offsetE  = DIM*jnrE;
1482             j_coord_offsetF  = DIM*jnrF;
1483             j_coord_offsetG  = DIM*jnrG;
1484             j_coord_offsetH  = DIM*jnrH;
1485
1486             /* load j atom coordinates */
1487             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1488                                                  x+j_coord_offsetC,x+j_coord_offsetD,
1489                                                  x+j_coord_offsetE,x+j_coord_offsetF,
1490                                                  x+j_coord_offsetG,x+j_coord_offsetH,
1491                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1492
1493             /* Calculate displacement vector */
1494             dx00             = _mm256_sub_ps(ix0,jx0);
1495             dy00             = _mm256_sub_ps(iy0,jy0);
1496             dz00             = _mm256_sub_ps(iz0,jz0);
1497             dx01             = _mm256_sub_ps(ix0,jx1);
1498             dy01             = _mm256_sub_ps(iy0,jy1);
1499             dz01             = _mm256_sub_ps(iz0,jz1);
1500             dx02             = _mm256_sub_ps(ix0,jx2);
1501             dy02             = _mm256_sub_ps(iy0,jy2);
1502             dz02             = _mm256_sub_ps(iz0,jz2);
1503             dx10             = _mm256_sub_ps(ix1,jx0);
1504             dy10             = _mm256_sub_ps(iy1,jy0);
1505             dz10             = _mm256_sub_ps(iz1,jz0);
1506             dx11             = _mm256_sub_ps(ix1,jx1);
1507             dy11             = _mm256_sub_ps(iy1,jy1);
1508             dz11             = _mm256_sub_ps(iz1,jz1);
1509             dx12             = _mm256_sub_ps(ix1,jx2);
1510             dy12             = _mm256_sub_ps(iy1,jy2);
1511             dz12             = _mm256_sub_ps(iz1,jz2);
1512             dx20             = _mm256_sub_ps(ix2,jx0);
1513             dy20             = _mm256_sub_ps(iy2,jy0);
1514             dz20             = _mm256_sub_ps(iz2,jz0);
1515             dx21             = _mm256_sub_ps(ix2,jx1);
1516             dy21             = _mm256_sub_ps(iy2,jy1);
1517             dz21             = _mm256_sub_ps(iz2,jz1);
1518             dx22             = _mm256_sub_ps(ix2,jx2);
1519             dy22             = _mm256_sub_ps(iy2,jy2);
1520             dz22             = _mm256_sub_ps(iz2,jz2);
1521
1522             /* Calculate squared distance and things based on it */
1523             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1524             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1525             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1526             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1527             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1528             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1529             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1530             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1531             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1532
1533             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
1534             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
1535             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
1536             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
1537             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
1538             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
1539             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
1540             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
1541             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
1542
1543             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
1544             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
1545             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
1546             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
1547             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
1548             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
1549             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
1550             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
1551             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
1552
1553             fjx0             = _mm256_setzero_ps();
1554             fjy0             = _mm256_setzero_ps();
1555             fjz0             = _mm256_setzero_ps();
1556             fjx1             = _mm256_setzero_ps();
1557             fjy1             = _mm256_setzero_ps();
1558             fjz1             = _mm256_setzero_ps();
1559             fjx2             = _mm256_setzero_ps();
1560             fjy2             = _mm256_setzero_ps();
1561             fjz2             = _mm256_setzero_ps();
1562
1563             /**************************
1564              * CALCULATE INTERACTIONS *
1565              **************************/
1566
1567             if (gmx_mm256_any_lt(rsq00,rcutoff2))
1568             {
1569
1570             r00              = _mm256_mul_ps(rsq00,rinv00);
1571
1572             /* Calculate table index by multiplying r with table scale and truncate to integer */
1573             rt               = _mm256_mul_ps(r00,vftabscale);
1574             vfitab           = _mm256_cvttps_epi32(rt);
1575             vfeps            = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
1576             /*         AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
1577             vfitab_lo        = _mm256_extractf128_si256(vfitab,0x0);
1578             vfitab_hi        = _mm256_extractf128_si256(vfitab,0x1);
1579             vfitab_lo        = _mm_slli_epi32(vfitab_lo,3);
1580             vfitab_hi        = _mm_slli_epi32(vfitab_hi,3);
1581
1582             /* REACTION-FIELD ELECTROSTATICS */
1583             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1584
1585             /* CUBIC SPLINE TABLE DISPERSION */
1586             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1587                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1588             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1589                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1590             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1591                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1592             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1593                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1594             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1595             Heps             = _mm256_mul_ps(vfeps,H);
1596             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1597             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1598             fvdw6            = _mm256_mul_ps(c6_00,FF);
1599
1600             /* CUBIC SPLINE TABLE REPULSION */
1601             vfitab_lo        = _mm_add_epi32(vfitab_lo,ifour);
1602             vfitab_hi        = _mm_add_epi32(vfitab_hi,ifour);
1603             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
1604                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
1605             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
1606                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
1607             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
1608                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
1609             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
1610                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
1611             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
1612             Heps             = _mm256_mul_ps(vfeps,H);
1613             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
1614             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
1615             fvdw12           = _mm256_mul_ps(c12_00,FF);
1616             fvdw             = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
1617
1618             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1619
1620             fscal            = _mm256_add_ps(felec,fvdw);
1621
1622             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1623
1624             /* Calculate temporary vectorial force */
1625             tx               = _mm256_mul_ps(fscal,dx00);
1626             ty               = _mm256_mul_ps(fscal,dy00);
1627             tz               = _mm256_mul_ps(fscal,dz00);
1628
1629             /* Update vectorial force */
1630             fix0             = _mm256_add_ps(fix0,tx);
1631             fiy0             = _mm256_add_ps(fiy0,ty);
1632             fiz0             = _mm256_add_ps(fiz0,tz);
1633
1634             fjx0             = _mm256_add_ps(fjx0,tx);
1635             fjy0             = _mm256_add_ps(fjy0,ty);
1636             fjz0             = _mm256_add_ps(fjz0,tz);
1637
1638             }
1639
1640             /**************************
1641              * CALCULATE INTERACTIONS *
1642              **************************/
1643
1644             if (gmx_mm256_any_lt(rsq01,rcutoff2))
1645             {
1646
1647             /* REACTION-FIELD ELECTROSTATICS */
1648             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1649
1650             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1651
1652             fscal            = felec;
1653
1654             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1655
1656             /* Calculate temporary vectorial force */
1657             tx               = _mm256_mul_ps(fscal,dx01);
1658             ty               = _mm256_mul_ps(fscal,dy01);
1659             tz               = _mm256_mul_ps(fscal,dz01);
1660
1661             /* Update vectorial force */
1662             fix0             = _mm256_add_ps(fix0,tx);
1663             fiy0             = _mm256_add_ps(fiy0,ty);
1664             fiz0             = _mm256_add_ps(fiz0,tz);
1665
1666             fjx1             = _mm256_add_ps(fjx1,tx);
1667             fjy1             = _mm256_add_ps(fjy1,ty);
1668             fjz1             = _mm256_add_ps(fjz1,tz);
1669
1670             }
1671
1672             /**************************
1673              * CALCULATE INTERACTIONS *
1674              **************************/
1675
1676             if (gmx_mm256_any_lt(rsq02,rcutoff2))
1677             {
1678
1679             /* REACTION-FIELD ELECTROSTATICS */
1680             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1681
1682             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1683
1684             fscal            = felec;
1685
1686             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1687
1688             /* Calculate temporary vectorial force */
1689             tx               = _mm256_mul_ps(fscal,dx02);
1690             ty               = _mm256_mul_ps(fscal,dy02);
1691             tz               = _mm256_mul_ps(fscal,dz02);
1692
1693             /* Update vectorial force */
1694             fix0             = _mm256_add_ps(fix0,tx);
1695             fiy0             = _mm256_add_ps(fiy0,ty);
1696             fiz0             = _mm256_add_ps(fiz0,tz);
1697
1698             fjx2             = _mm256_add_ps(fjx2,tx);
1699             fjy2             = _mm256_add_ps(fjy2,ty);
1700             fjz2             = _mm256_add_ps(fjz2,tz);
1701
1702             }
1703
1704             /**************************
1705              * CALCULATE INTERACTIONS *
1706              **************************/
1707
1708             if (gmx_mm256_any_lt(rsq10,rcutoff2))
1709             {
1710
1711             /* REACTION-FIELD ELECTROSTATICS */
1712             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1713
1714             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1715
1716             fscal            = felec;
1717
1718             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1719
1720             /* Calculate temporary vectorial force */
1721             tx               = _mm256_mul_ps(fscal,dx10);
1722             ty               = _mm256_mul_ps(fscal,dy10);
1723             tz               = _mm256_mul_ps(fscal,dz10);
1724
1725             /* Update vectorial force */
1726             fix1             = _mm256_add_ps(fix1,tx);
1727             fiy1             = _mm256_add_ps(fiy1,ty);
1728             fiz1             = _mm256_add_ps(fiz1,tz);
1729
1730             fjx0             = _mm256_add_ps(fjx0,tx);
1731             fjy0             = _mm256_add_ps(fjy0,ty);
1732             fjz0             = _mm256_add_ps(fjz0,tz);
1733
1734             }
1735
1736             /**************************
1737              * CALCULATE INTERACTIONS *
1738              **************************/
1739
1740             if (gmx_mm256_any_lt(rsq11,rcutoff2))
1741             {
1742
1743             /* REACTION-FIELD ELECTROSTATICS */
1744             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1745
1746             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1747
1748             fscal            = felec;
1749
1750             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1751
1752             /* Calculate temporary vectorial force */
1753             tx               = _mm256_mul_ps(fscal,dx11);
1754             ty               = _mm256_mul_ps(fscal,dy11);
1755             tz               = _mm256_mul_ps(fscal,dz11);
1756
1757             /* Update vectorial force */
1758             fix1             = _mm256_add_ps(fix1,tx);
1759             fiy1             = _mm256_add_ps(fiy1,ty);
1760             fiz1             = _mm256_add_ps(fiz1,tz);
1761
1762             fjx1             = _mm256_add_ps(fjx1,tx);
1763             fjy1             = _mm256_add_ps(fjy1,ty);
1764             fjz1             = _mm256_add_ps(fjz1,tz);
1765
1766             }
1767
1768             /**************************
1769              * CALCULATE INTERACTIONS *
1770              **************************/
1771
1772             if (gmx_mm256_any_lt(rsq12,rcutoff2))
1773             {
1774
1775             /* REACTION-FIELD ELECTROSTATICS */
1776             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1777
1778             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1779
1780             fscal            = felec;
1781
1782             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1783
1784             /* Calculate temporary vectorial force */
1785             tx               = _mm256_mul_ps(fscal,dx12);
1786             ty               = _mm256_mul_ps(fscal,dy12);
1787             tz               = _mm256_mul_ps(fscal,dz12);
1788
1789             /* Update vectorial force */
1790             fix1             = _mm256_add_ps(fix1,tx);
1791             fiy1             = _mm256_add_ps(fiy1,ty);
1792             fiz1             = _mm256_add_ps(fiz1,tz);
1793
1794             fjx2             = _mm256_add_ps(fjx2,tx);
1795             fjy2             = _mm256_add_ps(fjy2,ty);
1796             fjz2             = _mm256_add_ps(fjz2,tz);
1797
1798             }
1799
1800             /**************************
1801              * CALCULATE INTERACTIONS *
1802              **************************/
1803
1804             if (gmx_mm256_any_lt(rsq20,rcutoff2))
1805             {
1806
1807             /* REACTION-FIELD ELECTROSTATICS */
1808             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1809
1810             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1811
1812             fscal            = felec;
1813
1814             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1815
1816             /* Calculate temporary vectorial force */
1817             tx               = _mm256_mul_ps(fscal,dx20);
1818             ty               = _mm256_mul_ps(fscal,dy20);
1819             tz               = _mm256_mul_ps(fscal,dz20);
1820
1821             /* Update vectorial force */
1822             fix2             = _mm256_add_ps(fix2,tx);
1823             fiy2             = _mm256_add_ps(fiy2,ty);
1824             fiz2             = _mm256_add_ps(fiz2,tz);
1825
1826             fjx0             = _mm256_add_ps(fjx0,tx);
1827             fjy0             = _mm256_add_ps(fjy0,ty);
1828             fjz0             = _mm256_add_ps(fjz0,tz);
1829
1830             }
1831
1832             /**************************
1833              * CALCULATE INTERACTIONS *
1834              **************************/
1835
1836             if (gmx_mm256_any_lt(rsq21,rcutoff2))
1837             {
1838
1839             /* REACTION-FIELD ELECTROSTATICS */
1840             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1841
1842             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1843
1844             fscal            = felec;
1845
1846             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1847
1848             /* Calculate temporary vectorial force */
1849             tx               = _mm256_mul_ps(fscal,dx21);
1850             ty               = _mm256_mul_ps(fscal,dy21);
1851             tz               = _mm256_mul_ps(fscal,dz21);
1852
1853             /* Update vectorial force */
1854             fix2             = _mm256_add_ps(fix2,tx);
1855             fiy2             = _mm256_add_ps(fiy2,ty);
1856             fiz2             = _mm256_add_ps(fiz2,tz);
1857
1858             fjx1             = _mm256_add_ps(fjx1,tx);
1859             fjy1             = _mm256_add_ps(fjy1,ty);
1860             fjz1             = _mm256_add_ps(fjz1,tz);
1861
1862             }
1863
1864             /**************************
1865              * CALCULATE INTERACTIONS *
1866              **************************/
1867
1868             if (gmx_mm256_any_lt(rsq22,rcutoff2))
1869             {
1870
1871             /* REACTION-FIELD ELECTROSTATICS */
1872             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1873
1874             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1875
1876             fscal            = felec;
1877
1878             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1879
1880             /* Calculate temporary vectorial force */
1881             tx               = _mm256_mul_ps(fscal,dx22);
1882             ty               = _mm256_mul_ps(fscal,dy22);
1883             tz               = _mm256_mul_ps(fscal,dz22);
1884
1885             /* Update vectorial force */
1886             fix2             = _mm256_add_ps(fix2,tx);
1887             fiy2             = _mm256_add_ps(fiy2,ty);
1888             fiz2             = _mm256_add_ps(fiz2,tz);
1889
1890             fjx2             = _mm256_add_ps(fjx2,tx);
1891             fjy2             = _mm256_add_ps(fjy2,ty);
1892             fjz2             = _mm256_add_ps(fjz2,tz);
1893
1894             }
1895
1896             fjptrA             = f+j_coord_offsetA;
1897             fjptrB             = f+j_coord_offsetB;
1898             fjptrC             = f+j_coord_offsetC;
1899             fjptrD             = f+j_coord_offsetD;
1900             fjptrE             = f+j_coord_offsetE;
1901             fjptrF             = f+j_coord_offsetF;
1902             fjptrG             = f+j_coord_offsetG;
1903             fjptrH             = f+j_coord_offsetH;
1904
1905             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1906                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1907
1908             /* Inner loop uses 297 flops */
1909         }
1910
1911         if(jidx<j_index_end)
1912         {
1913
1914             /* Get j neighbor index, and coordinate index */
1915             jnrlistA         = jjnr[jidx];
1916             jnrlistB         = jjnr[jidx+1];
1917             jnrlistC         = jjnr[jidx+2];
1918             jnrlistD         = jjnr[jidx+3];
1919             jnrlistE         = jjnr[jidx+4];
1920             jnrlistF         = jjnr[jidx+5];
1921             jnrlistG         = jjnr[jidx+6];
1922             jnrlistH         = jjnr[jidx+7];
1923             /* Sign of each element will be negative for non-real atoms.
1924              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1925              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1926              */
1927             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1928                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1929                                             
1930             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1931             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1932             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1933             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1934             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
1935             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
1936             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
1937             jnrH       = (jnrlistH>=0) ? jnrlistH : 0;
1938             j_coord_offsetA  = DIM*jnrA;
1939             j_coord_offsetB  = DIM*jnrB;
1940             j_coord_offsetC  = DIM*jnrC;
1941             j_coord_offsetD  = DIM*jnrD;
1942             j_coord_offsetE  = DIM*jnrE;
1943             j_coord_offsetF  = DIM*jnrF;
1944             j_coord_offsetG  = DIM*jnrG;
1945             j_coord_offsetH  = DIM*jnrH;
1946
1947             /* load j atom coordinates */
1948             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1949                                                  x+j_coord_offsetC,x+j_coord_offsetD,
1950                                                  x+j_coord_offsetE,x+j_coord_offsetF,
1951                                                  x+j_coord_offsetG,x+j_coord_offsetH,
1952                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1953
1954             /* Calculate displacement vector */
1955             dx00             = _mm256_sub_ps(ix0,jx0);
1956             dy00             = _mm256_sub_ps(iy0,jy0);
1957             dz00             = _mm256_sub_ps(iz0,jz0);
1958             dx01             = _mm256_sub_ps(ix0,jx1);
1959             dy01             = _mm256_sub_ps(iy0,jy1);
1960             dz01             = _mm256_sub_ps(iz0,jz1);
1961             dx02             = _mm256_sub_ps(ix0,jx2);
1962             dy02             = _mm256_sub_ps(iy0,jy2);
1963             dz02             = _mm256_sub_ps(iz0,jz2);
1964             dx10             = _mm256_sub_ps(ix1,jx0);
1965             dy10             = _mm256_sub_ps(iy1,jy0);
1966             dz10             = _mm256_sub_ps(iz1,jz0);
1967             dx11             = _mm256_sub_ps(ix1,jx1);
1968             dy11             = _mm256_sub_ps(iy1,jy1);
1969             dz11             = _mm256_sub_ps(iz1,jz1);
1970             dx12             = _mm256_sub_ps(ix1,jx2);
1971             dy12             = _mm256_sub_ps(iy1,jy2);
1972             dz12             = _mm256_sub_ps(iz1,jz2);
1973             dx20             = _mm256_sub_ps(ix2,jx0);
1974             dy20             = _mm256_sub_ps(iy2,jy0);
1975             dz20             = _mm256_sub_ps(iz2,jz0);
1976             dx21             = _mm256_sub_ps(ix2,jx1);
1977             dy21             = _mm256_sub_ps(iy2,jy1);
1978             dz21             = _mm256_sub_ps(iz2,jz1);
1979             dx22             = _mm256_sub_ps(ix2,jx2);
1980             dy22             = _mm256_sub_ps(iy2,jy2);
1981             dz22             = _mm256_sub_ps(iz2,jz2);
1982
1983             /* Calculate squared distance and things based on it */
1984             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1985             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1986             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1987             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1988             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1989             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1990             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1991             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1992             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1993
1994             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
1995             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
1996             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
1997             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
1998             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
1999             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
2000             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
2001             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
2002             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
2003
2004             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
2005             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
2006             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
2007             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
2008             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
2009             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
2010             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
2011             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
2012             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
2013
2014             fjx0             = _mm256_setzero_ps();
2015             fjy0             = _mm256_setzero_ps();
2016             fjz0             = _mm256_setzero_ps();
2017             fjx1             = _mm256_setzero_ps();
2018             fjy1             = _mm256_setzero_ps();
2019             fjz1             = _mm256_setzero_ps();
2020             fjx2             = _mm256_setzero_ps();
2021             fjy2             = _mm256_setzero_ps();
2022             fjz2             = _mm256_setzero_ps();
2023
2024             /**************************
2025              * CALCULATE INTERACTIONS *
2026              **************************/
2027
2028             if (gmx_mm256_any_lt(rsq00,rcutoff2))
2029             {
2030
2031             r00              = _mm256_mul_ps(rsq00,rinv00);
2032             r00              = _mm256_andnot_ps(dummy_mask,r00);
2033
2034             /* Calculate table index by multiplying r with table scale and truncate to integer */
2035             rt               = _mm256_mul_ps(r00,vftabscale);
2036             vfitab           = _mm256_cvttps_epi32(rt);
2037             vfeps            = _mm256_sub_ps(rt,_mm256_round_ps(rt, _MM_FROUND_FLOOR));
2038             /*         AVX1 does not support 256-bit integer operations, so now we go to 128-bit mode... */
2039             vfitab_lo        = _mm256_extractf128_si256(vfitab,0x0);
2040             vfitab_hi        = _mm256_extractf128_si256(vfitab,0x1);
2041             vfitab_lo        = _mm_slli_epi32(vfitab_lo,3);
2042             vfitab_hi        = _mm_slli_epi32(vfitab_hi,3);
2043
2044             /* REACTION-FIELD ELECTROSTATICS */
2045             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
2046
2047             /* CUBIC SPLINE TABLE DISPERSION */
2048             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2049                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2050             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2051                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2052             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2053                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2054             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2055                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2056             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2057             Heps             = _mm256_mul_ps(vfeps,H);
2058             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2059             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2060             fvdw6            = _mm256_mul_ps(c6_00,FF);
2061
2062             /* CUBIC SPLINE TABLE REPULSION */
2063             vfitab_lo        = _mm_add_epi32(vfitab_lo,ifour);
2064             vfitab_hi        = _mm_add_epi32(vfitab_hi,ifour);
2065             Y                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,0)),
2066                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,0)));
2067             F                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,1)),
2068                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,1)));
2069             G                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,2)),
2070                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,2)));
2071             H                = gmx_mm256_set_m128(_mm_load_ps(vftab + _mm_extract_epi32(vfitab_hi,3)),
2072                                                   _mm_load_ps(vftab + _mm_extract_epi32(vfitab_lo,3)));
2073             GMX_MM256_HALFTRANSPOSE4_PS(Y,F,G,H);
2074             Heps             = _mm256_mul_ps(vfeps,H);
2075             Fp               = _mm256_add_ps(F,_mm256_mul_ps(vfeps,_mm256_add_ps(G,Heps)));
2076             FF               = _mm256_add_ps(Fp,_mm256_mul_ps(vfeps,_mm256_add_ps(G,_mm256_add_ps(Heps,Heps))));
2077             fvdw12           = _mm256_mul_ps(c12_00,FF);
2078             fvdw             = _mm256_xor_ps(signbit,_mm256_mul_ps(_mm256_add_ps(fvdw6,fvdw12),_mm256_mul_ps(vftabscale,rinv00)));
2079
2080             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
2081
2082             fscal            = _mm256_add_ps(felec,fvdw);
2083
2084             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2085
2086             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2087
2088             /* Calculate temporary vectorial force */
2089             tx               = _mm256_mul_ps(fscal,dx00);
2090             ty               = _mm256_mul_ps(fscal,dy00);
2091             tz               = _mm256_mul_ps(fscal,dz00);
2092
2093             /* Update vectorial force */
2094             fix0             = _mm256_add_ps(fix0,tx);
2095             fiy0             = _mm256_add_ps(fiy0,ty);
2096             fiz0             = _mm256_add_ps(fiz0,tz);
2097
2098             fjx0             = _mm256_add_ps(fjx0,tx);
2099             fjy0             = _mm256_add_ps(fjy0,ty);
2100             fjz0             = _mm256_add_ps(fjz0,tz);
2101
2102             }
2103
2104             /**************************
2105              * CALCULATE INTERACTIONS *
2106              **************************/
2107
2108             if (gmx_mm256_any_lt(rsq01,rcutoff2))
2109             {
2110
2111             /* REACTION-FIELD ELECTROSTATICS */
2112             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
2113
2114             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
2115
2116             fscal            = felec;
2117
2118             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2119
2120             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2121
2122             /* Calculate temporary vectorial force */
2123             tx               = _mm256_mul_ps(fscal,dx01);
2124             ty               = _mm256_mul_ps(fscal,dy01);
2125             tz               = _mm256_mul_ps(fscal,dz01);
2126
2127             /* Update vectorial force */
2128             fix0             = _mm256_add_ps(fix0,tx);
2129             fiy0             = _mm256_add_ps(fiy0,ty);
2130             fiz0             = _mm256_add_ps(fiz0,tz);
2131
2132             fjx1             = _mm256_add_ps(fjx1,tx);
2133             fjy1             = _mm256_add_ps(fjy1,ty);
2134             fjz1             = _mm256_add_ps(fjz1,tz);
2135
2136             }
2137
2138             /**************************
2139              * CALCULATE INTERACTIONS *
2140              **************************/
2141
2142             if (gmx_mm256_any_lt(rsq02,rcutoff2))
2143             {
2144
2145             /* REACTION-FIELD ELECTROSTATICS */
2146             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
2147
2148             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
2149
2150             fscal            = felec;
2151
2152             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2153
2154             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2155
2156             /* Calculate temporary vectorial force */
2157             tx               = _mm256_mul_ps(fscal,dx02);
2158             ty               = _mm256_mul_ps(fscal,dy02);
2159             tz               = _mm256_mul_ps(fscal,dz02);
2160
2161             /* Update vectorial force */
2162             fix0             = _mm256_add_ps(fix0,tx);
2163             fiy0             = _mm256_add_ps(fiy0,ty);
2164             fiz0             = _mm256_add_ps(fiz0,tz);
2165
2166             fjx2             = _mm256_add_ps(fjx2,tx);
2167             fjy2             = _mm256_add_ps(fjy2,ty);
2168             fjz2             = _mm256_add_ps(fjz2,tz);
2169
2170             }
2171
2172             /**************************
2173              * CALCULATE INTERACTIONS *
2174              **************************/
2175
2176             if (gmx_mm256_any_lt(rsq10,rcutoff2))
2177             {
2178
2179             /* REACTION-FIELD ELECTROSTATICS */
2180             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
2181
2182             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
2183
2184             fscal            = felec;
2185
2186             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2187
2188             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2189
2190             /* Calculate temporary vectorial force */
2191             tx               = _mm256_mul_ps(fscal,dx10);
2192             ty               = _mm256_mul_ps(fscal,dy10);
2193             tz               = _mm256_mul_ps(fscal,dz10);
2194
2195             /* Update vectorial force */
2196             fix1             = _mm256_add_ps(fix1,tx);
2197             fiy1             = _mm256_add_ps(fiy1,ty);
2198             fiz1             = _mm256_add_ps(fiz1,tz);
2199
2200             fjx0             = _mm256_add_ps(fjx0,tx);
2201             fjy0             = _mm256_add_ps(fjy0,ty);
2202             fjz0             = _mm256_add_ps(fjz0,tz);
2203
2204             }
2205
2206             /**************************
2207              * CALCULATE INTERACTIONS *
2208              **************************/
2209
2210             if (gmx_mm256_any_lt(rsq11,rcutoff2))
2211             {
2212
2213             /* REACTION-FIELD ELECTROSTATICS */
2214             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2215
2216             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2217
2218             fscal            = felec;
2219
2220             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2221
2222             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2223
2224             /* Calculate temporary vectorial force */
2225             tx               = _mm256_mul_ps(fscal,dx11);
2226             ty               = _mm256_mul_ps(fscal,dy11);
2227             tz               = _mm256_mul_ps(fscal,dz11);
2228
2229             /* Update vectorial force */
2230             fix1             = _mm256_add_ps(fix1,tx);
2231             fiy1             = _mm256_add_ps(fiy1,ty);
2232             fiz1             = _mm256_add_ps(fiz1,tz);
2233
2234             fjx1             = _mm256_add_ps(fjx1,tx);
2235             fjy1             = _mm256_add_ps(fjy1,ty);
2236             fjz1             = _mm256_add_ps(fjz1,tz);
2237
2238             }
2239
2240             /**************************
2241              * CALCULATE INTERACTIONS *
2242              **************************/
2243
2244             if (gmx_mm256_any_lt(rsq12,rcutoff2))
2245             {
2246
2247             /* REACTION-FIELD ELECTROSTATICS */
2248             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2249
2250             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2251
2252             fscal            = felec;
2253
2254             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2255
2256             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2257
2258             /* Calculate temporary vectorial force */
2259             tx               = _mm256_mul_ps(fscal,dx12);
2260             ty               = _mm256_mul_ps(fscal,dy12);
2261             tz               = _mm256_mul_ps(fscal,dz12);
2262
2263             /* Update vectorial force */
2264             fix1             = _mm256_add_ps(fix1,tx);
2265             fiy1             = _mm256_add_ps(fiy1,ty);
2266             fiz1             = _mm256_add_ps(fiz1,tz);
2267
2268             fjx2             = _mm256_add_ps(fjx2,tx);
2269             fjy2             = _mm256_add_ps(fjy2,ty);
2270             fjz2             = _mm256_add_ps(fjz2,tz);
2271
2272             }
2273
2274             /**************************
2275              * CALCULATE INTERACTIONS *
2276              **************************/
2277
2278             if (gmx_mm256_any_lt(rsq20,rcutoff2))
2279             {
2280
2281             /* REACTION-FIELD ELECTROSTATICS */
2282             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
2283
2284             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
2285
2286             fscal            = felec;
2287
2288             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2289
2290             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2291
2292             /* Calculate temporary vectorial force */
2293             tx               = _mm256_mul_ps(fscal,dx20);
2294             ty               = _mm256_mul_ps(fscal,dy20);
2295             tz               = _mm256_mul_ps(fscal,dz20);
2296
2297             /* Update vectorial force */
2298             fix2             = _mm256_add_ps(fix2,tx);
2299             fiy2             = _mm256_add_ps(fiy2,ty);
2300             fiz2             = _mm256_add_ps(fiz2,tz);
2301
2302             fjx0             = _mm256_add_ps(fjx0,tx);
2303             fjy0             = _mm256_add_ps(fjy0,ty);
2304             fjz0             = _mm256_add_ps(fjz0,tz);
2305
2306             }
2307
2308             /**************************
2309              * CALCULATE INTERACTIONS *
2310              **************************/
2311
2312             if (gmx_mm256_any_lt(rsq21,rcutoff2))
2313             {
2314
2315             /* REACTION-FIELD ELECTROSTATICS */
2316             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2317
2318             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2319
2320             fscal            = felec;
2321
2322             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2323
2324             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2325
2326             /* Calculate temporary vectorial force */
2327             tx               = _mm256_mul_ps(fscal,dx21);
2328             ty               = _mm256_mul_ps(fscal,dy21);
2329             tz               = _mm256_mul_ps(fscal,dz21);
2330
2331             /* Update vectorial force */
2332             fix2             = _mm256_add_ps(fix2,tx);
2333             fiy2             = _mm256_add_ps(fiy2,ty);
2334             fiz2             = _mm256_add_ps(fiz2,tz);
2335
2336             fjx1             = _mm256_add_ps(fjx1,tx);
2337             fjy1             = _mm256_add_ps(fjy1,ty);
2338             fjz1             = _mm256_add_ps(fjz1,tz);
2339
2340             }
2341
2342             /**************************
2343              * CALCULATE INTERACTIONS *
2344              **************************/
2345
2346             if (gmx_mm256_any_lt(rsq22,rcutoff2))
2347             {
2348
2349             /* REACTION-FIELD ELECTROSTATICS */
2350             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2351
2352             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2353
2354             fscal            = felec;
2355
2356             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2357
2358             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2359
2360             /* Calculate temporary vectorial force */
2361             tx               = _mm256_mul_ps(fscal,dx22);
2362             ty               = _mm256_mul_ps(fscal,dy22);
2363             tz               = _mm256_mul_ps(fscal,dz22);
2364
2365             /* Update vectorial force */
2366             fix2             = _mm256_add_ps(fix2,tx);
2367             fiy2             = _mm256_add_ps(fiy2,ty);
2368             fiz2             = _mm256_add_ps(fiz2,tz);
2369
2370             fjx2             = _mm256_add_ps(fjx2,tx);
2371             fjy2             = _mm256_add_ps(fjy2,ty);
2372             fjz2             = _mm256_add_ps(fjz2,tz);
2373
2374             }
2375
2376             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2377             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2378             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2379             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2380             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2381             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2382             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2383             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2384
2385             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2386                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2387
2388             /* Inner loop uses 298 flops */
2389         }
2390
2391         /* End of innermost loop */
2392
2393         gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2394                                                  f+i_coord_offset,fshift+i_shift_offset);
2395
2396         /* Increment number of inner iterations */
2397         inneriter                  += j_index_end - j_index_start;
2398
2399         /* Outer loop uses 18 flops */
2400     }
2401
2402     /* Increment number of outer iterations */
2403     outeriter        += nri;
2404
2405     /* Update outer/inner flops */
2406
2407     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);
2408 }