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