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