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