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