Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_double / nb_kernel_ElecNone_VdwLJSh_GeomP1P1_avx_256_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017, 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_double kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 #include "kernelutil_x86_avx_256_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_avx_256_double
51  * Electrostatics interaction: None
52  * VdW interaction:            LennardJones
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_avx_256_double
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      struct t_forcerec           * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
67      * just 0 for non-waters.
68      * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
69      * jnr indices corresponding to data put in the four positions in the SIMD register.
70      */
71     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
72     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73     int              jnrA,jnrB,jnrC,jnrD;
74     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
76     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
78     real             rcutoff_scalar;
79     real             *shiftvec,*fshift,*x,*f;
80     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81     real             scratch[4*DIM];
82     __m256d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83     real *           vdwioffsetptr0;
84     __m256d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86     __m256d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87     __m256d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88     int              nvdwtype;
89     __m256d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
90     int              *vdwtype;
91     real             *vdwparam;
92     __m256d          one_sixth   = _mm256_set1_pd(1.0/6.0);
93     __m256d          one_twelfth = _mm256_set1_pd(1.0/12.0);
94     __m256d          dummy_mask,cutoff_mask;
95     __m128           tmpmask0,tmpmask1;
96     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
97     __m256d          one     = _mm256_set1_pd(1.0);
98     __m256d          two     = _mm256_set1_pd(2.0);
99     x                = xx[0];
100     f                = ff[0];
101
102     nri              = nlist->nri;
103     iinr             = nlist->iinr;
104     jindex           = nlist->jindex;
105     jjnr             = nlist->jjnr;
106     shiftidx         = nlist->shift;
107     gid              = nlist->gid;
108     shiftvec         = fr->shift_vec[0];
109     fshift           = fr->fshift[0];
110     nvdwtype         = fr->ntype;
111     vdwparam         = fr->nbfp;
112     vdwtype          = mdatoms->typeA;
113
114     rcutoff_scalar   = fr->ic->rvdw;
115     rcutoff          = _mm256_set1_pd(rcutoff_scalar);
116     rcutoff2         = _mm256_mul_pd(rcutoff,rcutoff);
117
118     sh_vdw_invrcut6  = _mm256_set1_pd(fr->ic->sh_invrc6);
119     rvdw             = _mm256_set1_pd(fr->ic->rvdw);
120
121     /* Avoid stupid compiler warnings */
122     jnrA = jnrB = jnrC = jnrD = 0;
123     j_coord_offsetA = 0;
124     j_coord_offsetB = 0;
125     j_coord_offsetC = 0;
126     j_coord_offsetD = 0;
127
128     outeriter        = 0;
129     inneriter        = 0;
130
131     for(iidx=0;iidx<4*DIM;iidx++)
132     {
133         scratch[iidx] = 0.0;
134     }
135
136     /* Start outer loop over neighborlists */
137     for(iidx=0; iidx<nri; iidx++)
138     {
139         /* Load shift vector for this list */
140         i_shift_offset   = DIM*shiftidx[iidx];
141
142         /* Load limits for loop over neighbors */
143         j_index_start    = jindex[iidx];
144         j_index_end      = jindex[iidx+1];
145
146         /* Get outer coordinate index */
147         inr              = iinr[iidx];
148         i_coord_offset   = DIM*inr;
149
150         /* Load i particle coords and add shift vector */
151         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
152
153         fix0             = _mm256_setzero_pd();
154         fiy0             = _mm256_setzero_pd();
155         fiz0             = _mm256_setzero_pd();
156
157         /* Load parameters for i particles */
158         vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
159
160         /* Reset potential sums */
161         vvdwsum          = _mm256_setzero_pd();
162
163         /* Start inner kernel loop */
164         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
165         {
166
167             /* Get j neighbor index, and coordinate index */
168             jnrA             = jjnr[jidx];
169             jnrB             = jjnr[jidx+1];
170             jnrC             = jjnr[jidx+2];
171             jnrD             = jjnr[jidx+3];
172             j_coord_offsetA  = DIM*jnrA;
173             j_coord_offsetB  = DIM*jnrB;
174             j_coord_offsetC  = DIM*jnrC;
175             j_coord_offsetD  = DIM*jnrD;
176
177             /* load j atom coordinates */
178             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
179                                                  x+j_coord_offsetC,x+j_coord_offsetD,
180                                                  &jx0,&jy0,&jz0);
181
182             /* Calculate displacement vector */
183             dx00             = _mm256_sub_pd(ix0,jx0);
184             dy00             = _mm256_sub_pd(iy0,jy0);
185             dz00             = _mm256_sub_pd(iz0,jz0);
186
187             /* Calculate squared distance and things based on it */
188             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
189
190             rinvsq00         = avx256_inv_d(rsq00);
191
192             /* Load parameters for j particles */
193             vdwjidx0A        = 2*vdwtype[jnrA+0];
194             vdwjidx0B        = 2*vdwtype[jnrB+0];
195             vdwjidx0C        = 2*vdwtype[jnrC+0];
196             vdwjidx0D        = 2*vdwtype[jnrD+0];
197
198             /**************************
199              * CALCULATE INTERACTIONS *
200              **************************/
201
202             if (gmx_mm256_any_lt(rsq00,rcutoff2))
203             {
204
205             /* Compute parameters for interactions between i and j atoms */
206             gmx_mm256_load_4pair_swizzle_pd(vdwioffsetptr0+vdwjidx0A,
207                                             vdwioffsetptr0+vdwjidx0B,
208                                             vdwioffsetptr0+vdwjidx0C,
209                                             vdwioffsetptr0+vdwjidx0D,
210                                             &c6_00,&c12_00);
211
212             /* LENNARD-JONES DISPERSION/REPULSION */
213
214             rinvsix          = _mm256_mul_pd(_mm256_mul_pd(rinvsq00,rinvsq00),rinvsq00);
215             vvdw6            = _mm256_mul_pd(c6_00,rinvsix);
216             vvdw12           = _mm256_mul_pd(c12_00,_mm256_mul_pd(rinvsix,rinvsix));
217             vvdw             = _mm256_sub_pd(_mm256_mul_pd( _mm256_sub_pd(vvdw12 , _mm256_mul_pd(c12_00,_mm256_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
218                                           _mm256_mul_pd( _mm256_sub_pd(vvdw6,_mm256_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
219             fvdw             = _mm256_mul_pd(_mm256_sub_pd(vvdw12,vvdw6),rinvsq00);
220
221             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
222
223             /* Update potential sum for this i atom from the interaction with this j atom. */
224             vvdw             = _mm256_and_pd(vvdw,cutoff_mask);
225             vvdwsum          = _mm256_add_pd(vvdwsum,vvdw);
226
227             fscal            = fvdw;
228
229             fscal            = _mm256_and_pd(fscal,cutoff_mask);
230
231             /* Calculate temporary vectorial force */
232             tx               = _mm256_mul_pd(fscal,dx00);
233             ty               = _mm256_mul_pd(fscal,dy00);
234             tz               = _mm256_mul_pd(fscal,dz00);
235
236             /* Update vectorial force */
237             fix0             = _mm256_add_pd(fix0,tx);
238             fiy0             = _mm256_add_pd(fiy0,ty);
239             fiz0             = _mm256_add_pd(fiz0,tz);
240
241             fjptrA             = f+j_coord_offsetA;
242             fjptrB             = f+j_coord_offsetB;
243             fjptrC             = f+j_coord_offsetC;
244             fjptrD             = f+j_coord_offsetD;
245             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
246
247             }
248
249             /* Inner loop uses 41 flops */
250         }
251
252         if(jidx<j_index_end)
253         {
254
255             /* Get j neighbor index, and coordinate index */
256             jnrlistA         = jjnr[jidx];
257             jnrlistB         = jjnr[jidx+1];
258             jnrlistC         = jjnr[jidx+2];
259             jnrlistD         = jjnr[jidx+3];
260             /* Sign of each element will be negative for non-real atoms.
261              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
262              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
263              */
264             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
265
266             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
267             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
268             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
269
270             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
271             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
272             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
273             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
274             j_coord_offsetA  = DIM*jnrA;
275             j_coord_offsetB  = DIM*jnrB;
276             j_coord_offsetC  = DIM*jnrC;
277             j_coord_offsetD  = DIM*jnrD;
278
279             /* load j atom coordinates */
280             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
281                                                  x+j_coord_offsetC,x+j_coord_offsetD,
282                                                  &jx0,&jy0,&jz0);
283
284             /* Calculate displacement vector */
285             dx00             = _mm256_sub_pd(ix0,jx0);
286             dy00             = _mm256_sub_pd(iy0,jy0);
287             dz00             = _mm256_sub_pd(iz0,jz0);
288
289             /* Calculate squared distance and things based on it */
290             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
291
292             rinvsq00         = avx256_inv_d(rsq00);
293
294             /* Load parameters for j particles */
295             vdwjidx0A        = 2*vdwtype[jnrA+0];
296             vdwjidx0B        = 2*vdwtype[jnrB+0];
297             vdwjidx0C        = 2*vdwtype[jnrC+0];
298             vdwjidx0D        = 2*vdwtype[jnrD+0];
299
300             /**************************
301              * CALCULATE INTERACTIONS *
302              **************************/
303
304             if (gmx_mm256_any_lt(rsq00,rcutoff2))
305             {
306
307             /* Compute parameters for interactions between i and j atoms */
308             gmx_mm256_load_4pair_swizzle_pd(vdwioffsetptr0+vdwjidx0A,
309                                             vdwioffsetptr0+vdwjidx0B,
310                                             vdwioffsetptr0+vdwjidx0C,
311                                             vdwioffsetptr0+vdwjidx0D,
312                                             &c6_00,&c12_00);
313
314             /* LENNARD-JONES DISPERSION/REPULSION */
315
316             rinvsix          = _mm256_mul_pd(_mm256_mul_pd(rinvsq00,rinvsq00),rinvsq00);
317             vvdw6            = _mm256_mul_pd(c6_00,rinvsix);
318             vvdw12           = _mm256_mul_pd(c12_00,_mm256_mul_pd(rinvsix,rinvsix));
319             vvdw             = _mm256_sub_pd(_mm256_mul_pd( _mm256_sub_pd(vvdw12 , _mm256_mul_pd(c12_00,_mm256_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
320                                           _mm256_mul_pd( _mm256_sub_pd(vvdw6,_mm256_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
321             fvdw             = _mm256_mul_pd(_mm256_sub_pd(vvdw12,vvdw6),rinvsq00);
322
323             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
324
325             /* Update potential sum for this i atom from the interaction with this j atom. */
326             vvdw             = _mm256_and_pd(vvdw,cutoff_mask);
327             vvdw             = _mm256_andnot_pd(dummy_mask,vvdw);
328             vvdwsum          = _mm256_add_pd(vvdwsum,vvdw);
329
330             fscal            = fvdw;
331
332             fscal            = _mm256_and_pd(fscal,cutoff_mask);
333
334             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
335
336             /* Calculate temporary vectorial force */
337             tx               = _mm256_mul_pd(fscal,dx00);
338             ty               = _mm256_mul_pd(fscal,dy00);
339             tz               = _mm256_mul_pd(fscal,dz00);
340
341             /* Update vectorial force */
342             fix0             = _mm256_add_pd(fix0,tx);
343             fiy0             = _mm256_add_pd(fiy0,ty);
344             fiz0             = _mm256_add_pd(fiz0,tz);
345
346             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
347             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
348             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
349             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
350             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
351
352             }
353
354             /* Inner loop uses 41 flops */
355         }
356
357         /* End of innermost loop */
358
359         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
360                                                  f+i_coord_offset,fshift+i_shift_offset);
361
362         ggid                        = gid[iidx];
363         /* Update potential energies */
364         gmx_mm256_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
365
366         /* Increment number of inner iterations */
367         inneriter                  += j_index_end - j_index_start;
368
369         /* Outer loop uses 7 flops */
370     }
371
372     /* Increment number of outer iterations */
373     outeriter        += nri;
374
375     /* Update outer/inner flops */
376
377     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*41);
378 }
379 /*
380  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_avx_256_double
381  * Electrostatics interaction: None
382  * VdW interaction:            LennardJones
383  * Geometry:                   Particle-Particle
384  * Calculate force/pot:        Force
385  */
386 void
387 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_avx_256_double
388                     (t_nblist                    * gmx_restrict       nlist,
389                      rvec                        * gmx_restrict          xx,
390                      rvec                        * gmx_restrict          ff,
391                      struct t_forcerec           * gmx_restrict          fr,
392                      t_mdatoms                   * gmx_restrict     mdatoms,
393                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
394                      t_nrnb                      * gmx_restrict        nrnb)
395 {
396     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
397      * just 0 for non-waters.
398      * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
399      * jnr indices corresponding to data put in the four positions in the SIMD register.
400      */
401     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
402     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
403     int              jnrA,jnrB,jnrC,jnrD;
404     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
405     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
406     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
407     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
408     real             rcutoff_scalar;
409     real             *shiftvec,*fshift,*x,*f;
410     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
411     real             scratch[4*DIM];
412     __m256d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
413     real *           vdwioffsetptr0;
414     __m256d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
415     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
416     __m256d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
417     __m256d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
418     int              nvdwtype;
419     __m256d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
420     int              *vdwtype;
421     real             *vdwparam;
422     __m256d          one_sixth   = _mm256_set1_pd(1.0/6.0);
423     __m256d          one_twelfth = _mm256_set1_pd(1.0/12.0);
424     __m256d          dummy_mask,cutoff_mask;
425     __m128           tmpmask0,tmpmask1;
426     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
427     __m256d          one     = _mm256_set1_pd(1.0);
428     __m256d          two     = _mm256_set1_pd(2.0);
429     x                = xx[0];
430     f                = ff[0];
431
432     nri              = nlist->nri;
433     iinr             = nlist->iinr;
434     jindex           = nlist->jindex;
435     jjnr             = nlist->jjnr;
436     shiftidx         = nlist->shift;
437     gid              = nlist->gid;
438     shiftvec         = fr->shift_vec[0];
439     fshift           = fr->fshift[0];
440     nvdwtype         = fr->ntype;
441     vdwparam         = fr->nbfp;
442     vdwtype          = mdatoms->typeA;
443
444     rcutoff_scalar   = fr->ic->rvdw;
445     rcutoff          = _mm256_set1_pd(rcutoff_scalar);
446     rcutoff2         = _mm256_mul_pd(rcutoff,rcutoff);
447
448     sh_vdw_invrcut6  = _mm256_set1_pd(fr->ic->sh_invrc6);
449     rvdw             = _mm256_set1_pd(fr->ic->rvdw);
450
451     /* Avoid stupid compiler warnings */
452     jnrA = jnrB = jnrC = jnrD = 0;
453     j_coord_offsetA = 0;
454     j_coord_offsetB = 0;
455     j_coord_offsetC = 0;
456     j_coord_offsetD = 0;
457
458     outeriter        = 0;
459     inneriter        = 0;
460
461     for(iidx=0;iidx<4*DIM;iidx++)
462     {
463         scratch[iidx] = 0.0;
464     }
465
466     /* Start outer loop over neighborlists */
467     for(iidx=0; iidx<nri; iidx++)
468     {
469         /* Load shift vector for this list */
470         i_shift_offset   = DIM*shiftidx[iidx];
471
472         /* Load limits for loop over neighbors */
473         j_index_start    = jindex[iidx];
474         j_index_end      = jindex[iidx+1];
475
476         /* Get outer coordinate index */
477         inr              = iinr[iidx];
478         i_coord_offset   = DIM*inr;
479
480         /* Load i particle coords and add shift vector */
481         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
482
483         fix0             = _mm256_setzero_pd();
484         fiy0             = _mm256_setzero_pd();
485         fiz0             = _mm256_setzero_pd();
486
487         /* Load parameters for i particles */
488         vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
489
490         /* Start inner kernel loop */
491         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
492         {
493
494             /* Get j neighbor index, and coordinate index */
495             jnrA             = jjnr[jidx];
496             jnrB             = jjnr[jidx+1];
497             jnrC             = jjnr[jidx+2];
498             jnrD             = jjnr[jidx+3];
499             j_coord_offsetA  = DIM*jnrA;
500             j_coord_offsetB  = DIM*jnrB;
501             j_coord_offsetC  = DIM*jnrC;
502             j_coord_offsetD  = DIM*jnrD;
503
504             /* load j atom coordinates */
505             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
506                                                  x+j_coord_offsetC,x+j_coord_offsetD,
507                                                  &jx0,&jy0,&jz0);
508
509             /* Calculate displacement vector */
510             dx00             = _mm256_sub_pd(ix0,jx0);
511             dy00             = _mm256_sub_pd(iy0,jy0);
512             dz00             = _mm256_sub_pd(iz0,jz0);
513
514             /* Calculate squared distance and things based on it */
515             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
516
517             rinvsq00         = avx256_inv_d(rsq00);
518
519             /* Load parameters for j particles */
520             vdwjidx0A        = 2*vdwtype[jnrA+0];
521             vdwjidx0B        = 2*vdwtype[jnrB+0];
522             vdwjidx0C        = 2*vdwtype[jnrC+0];
523             vdwjidx0D        = 2*vdwtype[jnrD+0];
524
525             /**************************
526              * CALCULATE INTERACTIONS *
527              **************************/
528
529             if (gmx_mm256_any_lt(rsq00,rcutoff2))
530             {
531
532             /* Compute parameters for interactions between i and j atoms */
533             gmx_mm256_load_4pair_swizzle_pd(vdwioffsetptr0+vdwjidx0A,
534                                             vdwioffsetptr0+vdwjidx0B,
535                                             vdwioffsetptr0+vdwjidx0C,
536                                             vdwioffsetptr0+vdwjidx0D,
537                                             &c6_00,&c12_00);
538
539             /* LENNARD-JONES DISPERSION/REPULSION */
540
541             rinvsix          = _mm256_mul_pd(_mm256_mul_pd(rinvsq00,rinvsq00),rinvsq00);
542             fvdw             = _mm256_mul_pd(_mm256_sub_pd(_mm256_mul_pd(c12_00,rinvsix),c6_00),_mm256_mul_pd(rinvsix,rinvsq00));
543
544             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
545
546             fscal            = fvdw;
547
548             fscal            = _mm256_and_pd(fscal,cutoff_mask);
549
550             /* Calculate temporary vectorial force */
551             tx               = _mm256_mul_pd(fscal,dx00);
552             ty               = _mm256_mul_pd(fscal,dy00);
553             tz               = _mm256_mul_pd(fscal,dz00);
554
555             /* Update vectorial force */
556             fix0             = _mm256_add_pd(fix0,tx);
557             fiy0             = _mm256_add_pd(fiy0,ty);
558             fiz0             = _mm256_add_pd(fiz0,tz);
559
560             fjptrA             = f+j_coord_offsetA;
561             fjptrB             = f+j_coord_offsetB;
562             fjptrC             = f+j_coord_offsetC;
563             fjptrD             = f+j_coord_offsetD;
564             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
565
566             }
567
568             /* Inner loop uses 30 flops */
569         }
570
571         if(jidx<j_index_end)
572         {
573
574             /* Get j neighbor index, and coordinate index */
575             jnrlistA         = jjnr[jidx];
576             jnrlistB         = jjnr[jidx+1];
577             jnrlistC         = jjnr[jidx+2];
578             jnrlistD         = jjnr[jidx+3];
579             /* Sign of each element will be negative for non-real atoms.
580              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
581              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
582              */
583             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
584
585             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
586             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
587             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
588
589             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
590             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
591             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
592             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
593             j_coord_offsetA  = DIM*jnrA;
594             j_coord_offsetB  = DIM*jnrB;
595             j_coord_offsetC  = DIM*jnrC;
596             j_coord_offsetD  = DIM*jnrD;
597
598             /* load j atom coordinates */
599             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
600                                                  x+j_coord_offsetC,x+j_coord_offsetD,
601                                                  &jx0,&jy0,&jz0);
602
603             /* Calculate displacement vector */
604             dx00             = _mm256_sub_pd(ix0,jx0);
605             dy00             = _mm256_sub_pd(iy0,jy0);
606             dz00             = _mm256_sub_pd(iz0,jz0);
607
608             /* Calculate squared distance and things based on it */
609             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
610
611             rinvsq00         = avx256_inv_d(rsq00);
612
613             /* Load parameters for j particles */
614             vdwjidx0A        = 2*vdwtype[jnrA+0];
615             vdwjidx0B        = 2*vdwtype[jnrB+0];
616             vdwjidx0C        = 2*vdwtype[jnrC+0];
617             vdwjidx0D        = 2*vdwtype[jnrD+0];
618
619             /**************************
620              * CALCULATE INTERACTIONS *
621              **************************/
622
623             if (gmx_mm256_any_lt(rsq00,rcutoff2))
624             {
625
626             /* Compute parameters for interactions between i and j atoms */
627             gmx_mm256_load_4pair_swizzle_pd(vdwioffsetptr0+vdwjidx0A,
628                                             vdwioffsetptr0+vdwjidx0B,
629                                             vdwioffsetptr0+vdwjidx0C,
630                                             vdwioffsetptr0+vdwjidx0D,
631                                             &c6_00,&c12_00);
632
633             /* LENNARD-JONES DISPERSION/REPULSION */
634
635             rinvsix          = _mm256_mul_pd(_mm256_mul_pd(rinvsq00,rinvsq00),rinvsq00);
636             fvdw             = _mm256_mul_pd(_mm256_sub_pd(_mm256_mul_pd(c12_00,rinvsix),c6_00),_mm256_mul_pd(rinvsix,rinvsq00));
637
638             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
639
640             fscal            = fvdw;
641
642             fscal            = _mm256_and_pd(fscal,cutoff_mask);
643
644             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
645
646             /* Calculate temporary vectorial force */
647             tx               = _mm256_mul_pd(fscal,dx00);
648             ty               = _mm256_mul_pd(fscal,dy00);
649             tz               = _mm256_mul_pd(fscal,dz00);
650
651             /* Update vectorial force */
652             fix0             = _mm256_add_pd(fix0,tx);
653             fiy0             = _mm256_add_pd(fiy0,ty);
654             fiz0             = _mm256_add_pd(fiz0,tz);
655
656             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
657             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
658             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
659             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
660             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
661
662             }
663
664             /* Inner loop uses 30 flops */
665         }
666
667         /* End of innermost loop */
668
669         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
670                                                  f+i_coord_offset,fshift+i_shift_offset);
671
672         /* Increment number of inner iterations */
673         inneriter                  += j_index_end - j_index_start;
674
675         /* Outer loop uses 6 flops */
676     }
677
678     /* Increment number of outer iterations */
679     outeriter        += nri;
680
681     /* Update outer/inner flops */
682
683     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*30);
684 }