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