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