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