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