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