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