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