Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_avx_128_fma_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_128_fma_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_128_fma_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_double
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
74     int              j_coord_offsetA,j_coord_offsetB;
75     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
76     real             rcutoff_scalar;
77     real             *shiftvec,*fshift,*x,*f;
78     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
79     int              vdwioffset0;
80     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81     int              vdwjidx0A,vdwjidx0B;
82     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
85     real             *charge;
86     int              nvdwtype;
87     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
88     int              *vdwtype;
89     real             *vdwparam;
90     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
91     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
92     __m128i          ewitab;
93     __m128d          ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
94     real             *ewtab;
95     __m128d          dummy_mask,cutoff_mask;
96     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
97     __m128d          one     = _mm_set1_pd(1.0);
98     __m128d          two     = _mm_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     facel            = _mm_set1_pd(fr->ic->epsfac);
111     charge           = mdatoms->chargeA;
112     nvdwtype         = fr->ntype;
113     vdwparam         = fr->nbfp;
114     vdwtype          = mdatoms->typeA;
115
116     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
117     ewtab            = fr->ic->tabq_coul_FDV0;
118     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
119     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
120
121     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
122     rcutoff_scalar   = fr->ic->rcoulomb;
123     rcutoff          = _mm_set1_pd(rcutoff_scalar);
124     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
125
126     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
127     rvdw             = _mm_set1_pd(fr->ic->rvdw);
128
129     /* Avoid stupid compiler warnings */
130     jnrA = jnrB = 0;
131     j_coord_offsetA = 0;
132     j_coord_offsetB = 0;
133
134     outeriter        = 0;
135     inneriter        = 0;
136
137     /* Start outer loop over neighborlists */
138     for(iidx=0; iidx<nri; iidx++)
139     {
140         /* Load shift vector for this list */
141         i_shift_offset   = DIM*shiftidx[iidx];
142
143         /* Load limits for loop over neighbors */
144         j_index_start    = jindex[iidx];
145         j_index_end      = jindex[iidx+1];
146
147         /* Get outer coordinate index */
148         inr              = iinr[iidx];
149         i_coord_offset   = DIM*inr;
150
151         /* Load i particle coords and add shift vector */
152         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
153
154         fix0             = _mm_setzero_pd();
155         fiy0             = _mm_setzero_pd();
156         fiz0             = _mm_setzero_pd();
157
158         /* Load parameters for i particles */
159         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
160         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
161
162         /* Reset potential sums */
163         velecsum         = _mm_setzero_pd();
164         vvdwsum          = _mm_setzero_pd();
165
166         /* Start inner kernel loop */
167         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
168         {
169
170             /* Get j neighbor index, and coordinate index */
171             jnrA             = jjnr[jidx];
172             jnrB             = jjnr[jidx+1];
173             j_coord_offsetA  = DIM*jnrA;
174             j_coord_offsetB  = DIM*jnrB;
175
176             /* load j atom coordinates */
177             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
178                                               &jx0,&jy0,&jz0);
179
180             /* Calculate displacement vector */
181             dx00             = _mm_sub_pd(ix0,jx0);
182             dy00             = _mm_sub_pd(iy0,jy0);
183             dz00             = _mm_sub_pd(iz0,jz0);
184
185             /* Calculate squared distance and things based on it */
186             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
187
188             rinv00           = avx128fma_invsqrt_d(rsq00);
189
190             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
191
192             /* Load parameters for j particles */
193             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
194             vdwjidx0A        = 2*vdwtype[jnrA+0];
195             vdwjidx0B        = 2*vdwtype[jnrB+0];
196
197             /**************************
198              * CALCULATE INTERACTIONS *
199              **************************/
200
201             if (gmx_mm_any_lt(rsq00,rcutoff2))
202             {
203
204             r00              = _mm_mul_pd(rsq00,rinv00);
205
206             /* Compute parameters for interactions between i and j atoms */
207             qq00             = _mm_mul_pd(iq0,jq0);
208             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
209                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
210
211             /* EWALD ELECTROSTATICS */
212
213             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
214             ewrt             = _mm_mul_pd(r00,ewtabscale);
215             ewitab           = _mm_cvttpd_epi32(ewrt);
216 #ifdef __XOP__
217             eweps            = _mm_frcz_pd(ewrt);
218 #else
219             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
220 #endif
221             twoeweps         = _mm_add_pd(eweps,eweps);
222             ewitab           = _mm_slli_epi32(ewitab,2);
223             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
224             ewtabD           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
225             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
226             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
227             ewtabFn          = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
228             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
229             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
230             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
231             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
232             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
233
234             /* LENNARD-JONES DISPERSION/REPULSION */
235
236             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
237             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
238             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
239             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
240                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
241             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
242
243             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
244
245             /* Update potential sum for this i atom from the interaction with this j atom. */
246             velec            = _mm_and_pd(velec,cutoff_mask);
247             velecsum         = _mm_add_pd(velecsum,velec);
248             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
249             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
250
251             fscal            = _mm_add_pd(felec,fvdw);
252
253             fscal            = _mm_and_pd(fscal,cutoff_mask);
254
255             /* Update vectorial force */
256             fix0             = _mm_macc_pd(dx00,fscal,fix0);
257             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
258             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
259             
260             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
261                                                    _mm_mul_pd(dx00,fscal),
262                                                    _mm_mul_pd(dy00,fscal),
263                                                    _mm_mul_pd(dz00,fscal));
264
265             }
266
267             /* Inner loop uses 67 flops */
268         }
269
270         if(jidx<j_index_end)
271         {
272
273             jnrA             = jjnr[jidx];
274             j_coord_offsetA  = DIM*jnrA;
275
276             /* load j atom coordinates */
277             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
278                                               &jx0,&jy0,&jz0);
279
280             /* Calculate displacement vector */
281             dx00             = _mm_sub_pd(ix0,jx0);
282             dy00             = _mm_sub_pd(iy0,jy0);
283             dz00             = _mm_sub_pd(iz0,jz0);
284
285             /* Calculate squared distance and things based on it */
286             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
287
288             rinv00           = avx128fma_invsqrt_d(rsq00);
289
290             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
291
292             /* Load parameters for j particles */
293             jq0              = _mm_load_sd(charge+jnrA+0);
294             vdwjidx0A        = 2*vdwtype[jnrA+0];
295
296             /**************************
297              * CALCULATE INTERACTIONS *
298              **************************/
299
300             if (gmx_mm_any_lt(rsq00,rcutoff2))
301             {
302
303             r00              = _mm_mul_pd(rsq00,rinv00);
304
305             /* Compute parameters for interactions between i and j atoms */
306             qq00             = _mm_mul_pd(iq0,jq0);
307             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
308
309             /* EWALD ELECTROSTATICS */
310
311             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
312             ewrt             = _mm_mul_pd(r00,ewtabscale);
313             ewitab           = _mm_cvttpd_epi32(ewrt);
314 #ifdef __XOP__
315             eweps            = _mm_frcz_pd(ewrt);
316 #else
317             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
318 #endif
319             twoeweps         = _mm_add_pd(eweps,eweps);
320             ewitab           = _mm_slli_epi32(ewitab,2);
321             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
322             ewtabD           = _mm_setzero_pd();
323             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
324             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
325             ewtabFn          = _mm_setzero_pd();
326             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
327             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
328             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
329             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
330             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
331
332             /* LENNARD-JONES DISPERSION/REPULSION */
333
334             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
335             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
336             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
337             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
338                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
339             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
340
341             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
342
343             /* Update potential sum for this i atom from the interaction with this j atom. */
344             velec            = _mm_and_pd(velec,cutoff_mask);
345             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
346             velecsum         = _mm_add_pd(velecsum,velec);
347             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
348             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
349             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
350
351             fscal            = _mm_add_pd(felec,fvdw);
352
353             fscal            = _mm_and_pd(fscal,cutoff_mask);
354
355             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
356
357             /* Update vectorial force */
358             fix0             = _mm_macc_pd(dx00,fscal,fix0);
359             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
360             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
361             
362             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
363                                                    _mm_mul_pd(dx00,fscal),
364                                                    _mm_mul_pd(dy00,fscal),
365                                                    _mm_mul_pd(dz00,fscal));
366
367             }
368
369             /* Inner loop uses 67 flops */
370         }
371
372         /* End of innermost loop */
373
374         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
375                                               f+i_coord_offset,fshift+i_shift_offset);
376
377         ggid                        = gid[iidx];
378         /* Update potential energies */
379         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
380         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
381
382         /* Increment number of inner iterations */
383         inneriter                  += j_index_end - j_index_start;
384
385         /* Outer loop uses 9 flops */
386     }
387
388     /* Increment number of outer iterations */
389     outeriter        += nri;
390
391     /* Update outer/inner flops */
392
393     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*67);
394 }
395 /*
396  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
397  * Electrostatics interaction: Ewald
398  * VdW interaction:            LennardJones
399  * Geometry:                   Particle-Particle
400  * Calculate force/pot:        Force
401  */
402 void
403 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_double
404                     (t_nblist                    * gmx_restrict       nlist,
405                      rvec                        * gmx_restrict          xx,
406                      rvec                        * gmx_restrict          ff,
407                      struct t_forcerec           * gmx_restrict          fr,
408                      t_mdatoms                   * gmx_restrict     mdatoms,
409                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
410                      t_nrnb                      * gmx_restrict        nrnb)
411 {
412     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
413      * just 0 for non-waters.
414      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
415      * jnr indices corresponding to data put in the four positions in the SIMD register.
416      */
417     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
418     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
419     int              jnrA,jnrB;
420     int              j_coord_offsetA,j_coord_offsetB;
421     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
422     real             rcutoff_scalar;
423     real             *shiftvec,*fshift,*x,*f;
424     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
425     int              vdwioffset0;
426     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
427     int              vdwjidx0A,vdwjidx0B;
428     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
429     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
430     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
431     real             *charge;
432     int              nvdwtype;
433     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
434     int              *vdwtype;
435     real             *vdwparam;
436     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
437     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
438     __m128i          ewitab;
439     __m128d          ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
440     real             *ewtab;
441     __m128d          dummy_mask,cutoff_mask;
442     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
443     __m128d          one     = _mm_set1_pd(1.0);
444     __m128d          two     = _mm_set1_pd(2.0);
445     x                = xx[0];
446     f                = ff[0];
447
448     nri              = nlist->nri;
449     iinr             = nlist->iinr;
450     jindex           = nlist->jindex;
451     jjnr             = nlist->jjnr;
452     shiftidx         = nlist->shift;
453     gid              = nlist->gid;
454     shiftvec         = fr->shift_vec[0];
455     fshift           = fr->fshift[0];
456     facel            = _mm_set1_pd(fr->ic->epsfac);
457     charge           = mdatoms->chargeA;
458     nvdwtype         = fr->ntype;
459     vdwparam         = fr->nbfp;
460     vdwtype          = mdatoms->typeA;
461
462     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
463     ewtab            = fr->ic->tabq_coul_F;
464     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
465     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
466
467     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
468     rcutoff_scalar   = fr->ic->rcoulomb;
469     rcutoff          = _mm_set1_pd(rcutoff_scalar);
470     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
471
472     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
473     rvdw             = _mm_set1_pd(fr->ic->rvdw);
474
475     /* Avoid stupid compiler warnings */
476     jnrA = jnrB = 0;
477     j_coord_offsetA = 0;
478     j_coord_offsetB = 0;
479
480     outeriter        = 0;
481     inneriter        = 0;
482
483     /* Start outer loop over neighborlists */
484     for(iidx=0; iidx<nri; iidx++)
485     {
486         /* Load shift vector for this list */
487         i_shift_offset   = DIM*shiftidx[iidx];
488
489         /* Load limits for loop over neighbors */
490         j_index_start    = jindex[iidx];
491         j_index_end      = jindex[iidx+1];
492
493         /* Get outer coordinate index */
494         inr              = iinr[iidx];
495         i_coord_offset   = DIM*inr;
496
497         /* Load i particle coords and add shift vector */
498         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
499
500         fix0             = _mm_setzero_pd();
501         fiy0             = _mm_setzero_pd();
502         fiz0             = _mm_setzero_pd();
503
504         /* Load parameters for i particles */
505         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
506         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
507
508         /* Start inner kernel loop */
509         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
510         {
511
512             /* Get j neighbor index, and coordinate index */
513             jnrA             = jjnr[jidx];
514             jnrB             = jjnr[jidx+1];
515             j_coord_offsetA  = DIM*jnrA;
516             j_coord_offsetB  = DIM*jnrB;
517
518             /* load j atom coordinates */
519             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
520                                               &jx0,&jy0,&jz0);
521
522             /* Calculate displacement vector */
523             dx00             = _mm_sub_pd(ix0,jx0);
524             dy00             = _mm_sub_pd(iy0,jy0);
525             dz00             = _mm_sub_pd(iz0,jz0);
526
527             /* Calculate squared distance and things based on it */
528             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
529
530             rinv00           = avx128fma_invsqrt_d(rsq00);
531
532             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
533
534             /* Load parameters for j particles */
535             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
536             vdwjidx0A        = 2*vdwtype[jnrA+0];
537             vdwjidx0B        = 2*vdwtype[jnrB+0];
538
539             /**************************
540              * CALCULATE INTERACTIONS *
541              **************************/
542
543             if (gmx_mm_any_lt(rsq00,rcutoff2))
544             {
545
546             r00              = _mm_mul_pd(rsq00,rinv00);
547
548             /* Compute parameters for interactions between i and j atoms */
549             qq00             = _mm_mul_pd(iq0,jq0);
550             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
551                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
552
553             /* EWALD ELECTROSTATICS */
554
555             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
556             ewrt             = _mm_mul_pd(r00,ewtabscale);
557             ewitab           = _mm_cvttpd_epi32(ewrt);
558 #ifdef __XOP__
559             eweps            = _mm_frcz_pd(ewrt);
560 #else
561             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
562 #endif
563             twoeweps         = _mm_add_pd(eweps,eweps);
564             gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
565                                          &ewtabF,&ewtabFn);
566             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
567             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
568
569             /* LENNARD-JONES DISPERSION/REPULSION */
570
571             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
572             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
573
574             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
575
576             fscal            = _mm_add_pd(felec,fvdw);
577
578             fscal            = _mm_and_pd(fscal,cutoff_mask);
579
580             /* Update vectorial force */
581             fix0             = _mm_macc_pd(dx00,fscal,fix0);
582             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
583             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
584             
585             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
586                                                    _mm_mul_pd(dx00,fscal),
587                                                    _mm_mul_pd(dy00,fscal),
588                                                    _mm_mul_pd(dz00,fscal));
589
590             }
591
592             /* Inner loop uses 49 flops */
593         }
594
595         if(jidx<j_index_end)
596         {
597
598             jnrA             = jjnr[jidx];
599             j_coord_offsetA  = DIM*jnrA;
600
601             /* load j atom coordinates */
602             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
603                                               &jx0,&jy0,&jz0);
604
605             /* Calculate displacement vector */
606             dx00             = _mm_sub_pd(ix0,jx0);
607             dy00             = _mm_sub_pd(iy0,jy0);
608             dz00             = _mm_sub_pd(iz0,jz0);
609
610             /* Calculate squared distance and things based on it */
611             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
612
613             rinv00           = avx128fma_invsqrt_d(rsq00);
614
615             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
616
617             /* Load parameters for j particles */
618             jq0              = _mm_load_sd(charge+jnrA+0);
619             vdwjidx0A        = 2*vdwtype[jnrA+0];
620
621             /**************************
622              * CALCULATE INTERACTIONS *
623              **************************/
624
625             if (gmx_mm_any_lt(rsq00,rcutoff2))
626             {
627
628             r00              = _mm_mul_pd(rsq00,rinv00);
629
630             /* Compute parameters for interactions between i and j atoms */
631             qq00             = _mm_mul_pd(iq0,jq0);
632             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
633
634             /* EWALD ELECTROSTATICS */
635
636             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
637             ewrt             = _mm_mul_pd(r00,ewtabscale);
638             ewitab           = _mm_cvttpd_epi32(ewrt);
639 #ifdef __XOP__
640             eweps            = _mm_frcz_pd(ewrt);
641 #else
642             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
643 #endif
644             twoeweps         = _mm_add_pd(eweps,eweps);
645             gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
646             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
647             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
648
649             /* LENNARD-JONES DISPERSION/REPULSION */
650
651             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
652             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
653
654             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
655
656             fscal            = _mm_add_pd(felec,fvdw);
657
658             fscal            = _mm_and_pd(fscal,cutoff_mask);
659
660             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
661
662             /* Update vectorial force */
663             fix0             = _mm_macc_pd(dx00,fscal,fix0);
664             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
665             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
666             
667             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
668                                                    _mm_mul_pd(dx00,fscal),
669                                                    _mm_mul_pd(dy00,fscal),
670                                                    _mm_mul_pd(dz00,fscal));
671
672             }
673
674             /* Inner loop uses 49 flops */
675         }
676
677         /* End of innermost loop */
678
679         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
680                                               f+i_coord_offset,fshift+i_shift_offset);
681
682         /* Increment number of inner iterations */
683         inneriter                  += j_index_end - j_index_start;
684
685         /* Outer loop uses 7 flops */
686     }
687
688     /* Increment number of outer iterations */
689     outeriter        += nri;
690
691     /* Update outer/inner flops */
692
693     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*49);
694 }