Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecNone_VdwLJEw_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, 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/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEw_GeomP1P1_VF_avx_128_fma_double
54  * Electrostatics interaction: None
55  * VdW interaction:            LJEwald
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecNone_VdwLJEw_GeomP1P1_VF_avx_128_fma_double
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB;
77     int              j_coord_offsetA,j_coord_offsetB;
78     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
79     real             rcutoff_scalar;
80     real             *shiftvec,*fshift,*x,*f;
81     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     int              nvdwtype;
88     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89     int              *vdwtype;
90     real             *vdwparam;
91     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
92     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
93     __m128d           c6grid_00;
94     real             *vdwgridparam;
95     __m128d           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
96     __m128d           one_half  = _mm_set1_pd(0.5);
97     __m128d           minus_one = _mm_set1_pd(-1.0);
98     __m128d          dummy_mask,cutoff_mask;
99     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
100     __m128d          one     = _mm_set1_pd(1.0);
101     __m128d          two     = _mm_set1_pd(2.0);
102     x                = xx[0];
103     f                = ff[0];
104
105     nri              = nlist->nri;
106     iinr             = nlist->iinr;
107     jindex           = nlist->jindex;
108     jjnr             = nlist->jjnr;
109     shiftidx         = nlist->shift;
110     gid              = nlist->gid;
111     shiftvec         = fr->shift_vec[0];
112     fshift           = fr->fshift[0];
113     nvdwtype         = fr->ntype;
114     vdwparam         = fr->nbfp;
115     vdwtype          = mdatoms->typeA;
116     vdwgridparam     = fr->ljpme_c6grid;
117     sh_lj_ewald      = _mm_set1_pd(fr->ic->sh_lj_ewald);
118     ewclj            = _mm_set1_pd(fr->ewaldcoeff_lj);
119     ewclj2           = _mm_mul_pd(minus_one,_mm_mul_pd(ewclj,ewclj));
120
121     /* Avoid stupid compiler warnings */
122     jnrA = jnrB = 0;
123     j_coord_offsetA = 0;
124     j_coord_offsetB = 0;
125
126     outeriter        = 0;
127     inneriter        = 0;
128
129     /* Start outer loop over neighborlists */
130     for(iidx=0; iidx<nri; iidx++)
131     {
132         /* Load shift vector for this list */
133         i_shift_offset   = DIM*shiftidx[iidx];
134
135         /* Load limits for loop over neighbors */
136         j_index_start    = jindex[iidx];
137         j_index_end      = jindex[iidx+1];
138
139         /* Get outer coordinate index */
140         inr              = iinr[iidx];
141         i_coord_offset   = DIM*inr;
142
143         /* Load i particle coords and add shift vector */
144         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
145
146         fix0             = _mm_setzero_pd();
147         fiy0             = _mm_setzero_pd();
148         fiz0             = _mm_setzero_pd();
149
150         /* Load parameters for i particles */
151         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
152
153         /* Reset potential sums */
154         vvdwsum          = _mm_setzero_pd();
155
156         /* Start inner kernel loop */
157         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
158         {
159
160             /* Get j neighbor index, and coordinate index */
161             jnrA             = jjnr[jidx];
162             jnrB             = jjnr[jidx+1];
163             j_coord_offsetA  = DIM*jnrA;
164             j_coord_offsetB  = DIM*jnrB;
165
166             /* load j atom coordinates */
167             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
168                                               &jx0,&jy0,&jz0);
169
170             /* Calculate displacement vector */
171             dx00             = _mm_sub_pd(ix0,jx0);
172             dy00             = _mm_sub_pd(iy0,jy0);
173             dz00             = _mm_sub_pd(iz0,jz0);
174
175             /* Calculate squared distance and things based on it */
176             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
177
178             rinv00           = gmx_mm_invsqrt_pd(rsq00);
179
180             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
181
182             /* Load parameters for j particles */
183             vdwjidx0A        = 2*vdwtype[jnrA+0];
184             vdwjidx0B        = 2*vdwtype[jnrB+0];
185
186             /**************************
187              * CALCULATE INTERACTIONS *
188              **************************/
189
190             r00              = _mm_mul_pd(rsq00,rinv00);
191
192             /* Compute parameters for interactions between i and j atoms */
193             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
194                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
195             c6grid_00       = gmx_mm_load_2real_swizzle_pd(vdwgridparam+vdwioffset0+vdwjidx0A,
196                                                                vdwgridparam+vdwioffset0+vdwjidx0B);
197
198             /* Analytical LJ-PME */
199             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
200             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
201             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
202             exponent         = gmx_simd_exp_d(ewcljrsq);
203             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
204             poly             = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
205             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
206             vvdw6            = _mm_mul_pd(_mm_macc_pd(-c6grid_00,_mm_sub_pd(one,poly),c6_00),rinvsix);
207             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
208             vvdw             = _mm_msub_pd(vvdw12,one_twelfth,_mm_mul_pd(vvdw6,one_sixth));
209             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
210             fvdw             = _mm_mul_pd(_mm_add_pd(vvdw12,_mm_msub_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6),vvdw6)),rinvsq00);
211
212             /* Update potential sum for this i atom from the interaction with this j atom. */
213             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
214
215             fscal            = fvdw;
216
217             /* Update vectorial force */
218             fix0             = _mm_macc_pd(dx00,fscal,fix0);
219             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
220             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
221             
222             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
223                                                    _mm_mul_pd(dx00,fscal),
224                                                    _mm_mul_pd(dy00,fscal),
225                                                    _mm_mul_pd(dz00,fscal));
226
227             /* Inner loop uses 50 flops */
228         }
229
230         if(jidx<j_index_end)
231         {
232
233             jnrA             = jjnr[jidx];
234             j_coord_offsetA  = DIM*jnrA;
235
236             /* load j atom coordinates */
237             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
238                                               &jx0,&jy0,&jz0);
239
240             /* Calculate displacement vector */
241             dx00             = _mm_sub_pd(ix0,jx0);
242             dy00             = _mm_sub_pd(iy0,jy0);
243             dz00             = _mm_sub_pd(iz0,jz0);
244
245             /* Calculate squared distance and things based on it */
246             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
247
248             rinv00           = gmx_mm_invsqrt_pd(rsq00);
249
250             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
251
252             /* Load parameters for j particles */
253             vdwjidx0A        = 2*vdwtype[jnrA+0];
254
255             /**************************
256              * CALCULATE INTERACTIONS *
257              **************************/
258
259             r00              = _mm_mul_pd(rsq00,rinv00);
260
261             /* Compute parameters for interactions between i and j atoms */
262             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
263             c6grid_00       = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset0+vdwjidx0A);
264
265             /* Analytical LJ-PME */
266             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
267             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
268             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
269             exponent         = gmx_simd_exp_d(ewcljrsq);
270             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
271             poly             = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
272             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
273             vvdw6            = _mm_mul_pd(_mm_macc_pd(-c6grid_00,_mm_sub_pd(one,poly),c6_00),rinvsix);
274             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
275             vvdw             = _mm_msub_pd(vvdw12,one_twelfth,_mm_mul_pd(vvdw6,one_sixth));
276             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
277             fvdw             = _mm_mul_pd(_mm_add_pd(vvdw12,_mm_msub_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6),vvdw6)),rinvsq00);
278
279             /* Update potential sum for this i atom from the interaction with this j atom. */
280             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
281             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
282
283             fscal            = fvdw;
284
285             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
286
287             /* Update vectorial force */
288             fix0             = _mm_macc_pd(dx00,fscal,fix0);
289             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
290             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
291             
292             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
293                                                    _mm_mul_pd(dx00,fscal),
294                                                    _mm_mul_pd(dy00,fscal),
295                                                    _mm_mul_pd(dz00,fscal));
296
297             /* Inner loop uses 50 flops */
298         }
299
300         /* End of innermost loop */
301
302         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
303                                               f+i_coord_offset,fshift+i_shift_offset);
304
305         ggid                        = gid[iidx];
306         /* Update potential energies */
307         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
308
309         /* Increment number of inner iterations */
310         inneriter                  += j_index_end - j_index_start;
311
312         /* Outer loop uses 7 flops */
313     }
314
315     /* Increment number of outer iterations */
316     outeriter        += nri;
317
318     /* Update outer/inner flops */
319
320     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*50);
321 }
322 /*
323  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEw_GeomP1P1_F_avx_128_fma_double
324  * Electrostatics interaction: None
325  * VdW interaction:            LJEwald
326  * Geometry:                   Particle-Particle
327  * Calculate force/pot:        Force
328  */
329 void
330 nb_kernel_ElecNone_VdwLJEw_GeomP1P1_F_avx_128_fma_double
331                     (t_nblist                    * gmx_restrict       nlist,
332                      rvec                        * gmx_restrict          xx,
333                      rvec                        * gmx_restrict          ff,
334                      t_forcerec                  * gmx_restrict          fr,
335                      t_mdatoms                   * gmx_restrict     mdatoms,
336                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
337                      t_nrnb                      * gmx_restrict        nrnb)
338 {
339     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
340      * just 0 for non-waters.
341      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
342      * jnr indices corresponding to data put in the four positions in the SIMD register.
343      */
344     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
345     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
346     int              jnrA,jnrB;
347     int              j_coord_offsetA,j_coord_offsetB;
348     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
349     real             rcutoff_scalar;
350     real             *shiftvec,*fshift,*x,*f;
351     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
352     int              vdwioffset0;
353     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
354     int              vdwjidx0A,vdwjidx0B;
355     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
356     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
357     int              nvdwtype;
358     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
359     int              *vdwtype;
360     real             *vdwparam;
361     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
362     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
363     __m128d           c6grid_00;
364     real             *vdwgridparam;
365     __m128d           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
366     __m128d           one_half  = _mm_set1_pd(0.5);
367     __m128d           minus_one = _mm_set1_pd(-1.0);
368     __m128d          dummy_mask,cutoff_mask;
369     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
370     __m128d          one     = _mm_set1_pd(1.0);
371     __m128d          two     = _mm_set1_pd(2.0);
372     x                = xx[0];
373     f                = ff[0];
374
375     nri              = nlist->nri;
376     iinr             = nlist->iinr;
377     jindex           = nlist->jindex;
378     jjnr             = nlist->jjnr;
379     shiftidx         = nlist->shift;
380     gid              = nlist->gid;
381     shiftvec         = fr->shift_vec[0];
382     fshift           = fr->fshift[0];
383     nvdwtype         = fr->ntype;
384     vdwparam         = fr->nbfp;
385     vdwtype          = mdatoms->typeA;
386     vdwgridparam     = fr->ljpme_c6grid;
387     sh_lj_ewald      = _mm_set1_pd(fr->ic->sh_lj_ewald);
388     ewclj            = _mm_set1_pd(fr->ewaldcoeff_lj);
389     ewclj2           = _mm_mul_pd(minus_one,_mm_mul_pd(ewclj,ewclj));
390
391     /* Avoid stupid compiler warnings */
392     jnrA = jnrB = 0;
393     j_coord_offsetA = 0;
394     j_coord_offsetB = 0;
395
396     outeriter        = 0;
397     inneriter        = 0;
398
399     /* Start outer loop over neighborlists */
400     for(iidx=0; iidx<nri; iidx++)
401     {
402         /* Load shift vector for this list */
403         i_shift_offset   = DIM*shiftidx[iidx];
404
405         /* Load limits for loop over neighbors */
406         j_index_start    = jindex[iidx];
407         j_index_end      = jindex[iidx+1];
408
409         /* Get outer coordinate index */
410         inr              = iinr[iidx];
411         i_coord_offset   = DIM*inr;
412
413         /* Load i particle coords and add shift vector */
414         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
415
416         fix0             = _mm_setzero_pd();
417         fiy0             = _mm_setzero_pd();
418         fiz0             = _mm_setzero_pd();
419
420         /* Load parameters for i particles */
421         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
422
423         /* Start inner kernel loop */
424         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
425         {
426
427             /* Get j neighbor index, and coordinate index */
428             jnrA             = jjnr[jidx];
429             jnrB             = jjnr[jidx+1];
430             j_coord_offsetA  = DIM*jnrA;
431             j_coord_offsetB  = DIM*jnrB;
432
433             /* load j atom coordinates */
434             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
435                                               &jx0,&jy0,&jz0);
436
437             /* Calculate displacement vector */
438             dx00             = _mm_sub_pd(ix0,jx0);
439             dy00             = _mm_sub_pd(iy0,jy0);
440             dz00             = _mm_sub_pd(iz0,jz0);
441
442             /* Calculate squared distance and things based on it */
443             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
444
445             rinv00           = gmx_mm_invsqrt_pd(rsq00);
446
447             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
448
449             /* Load parameters for j particles */
450             vdwjidx0A        = 2*vdwtype[jnrA+0];
451             vdwjidx0B        = 2*vdwtype[jnrB+0];
452
453             /**************************
454              * CALCULATE INTERACTIONS *
455              **************************/
456
457             r00              = _mm_mul_pd(rsq00,rinv00);
458
459             /* Compute parameters for interactions between i and j atoms */
460             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
461                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
462             c6grid_00       = gmx_mm_load_2real_swizzle_pd(vdwgridparam+vdwioffset0+vdwjidx0A,
463                                                                vdwgridparam+vdwioffset0+vdwjidx0B);
464
465             /* Analytical LJ-PME */
466             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
467             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
468             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
469             exponent         = gmx_simd_exp_d(ewcljrsq);
470             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
471             poly             = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
472             /* f6A = 6 * C6grid * (1 - poly) */
473             f6A              = _mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly));
474             /* f6B = C6grid * exponent * beta^6 */
475             f6B              = _mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6));
476             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
477             fvdw              = _mm_mul_pd(_mm_macc_pd(_mm_msub_pd(c12_00,rinvsix,_mm_sub_pd(c6_00,f6A)),rinvsix,f6B),rinvsq00);
478
479             fscal            = fvdw;
480
481             /* Update vectorial force */
482             fix0             = _mm_macc_pd(dx00,fscal,fix0);
483             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
484             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
485             
486             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
487                                                    _mm_mul_pd(dx00,fscal),
488                                                    _mm_mul_pd(dy00,fscal),
489                                                    _mm_mul_pd(dz00,fscal));
490
491             /* Inner loop uses 47 flops */
492         }
493
494         if(jidx<j_index_end)
495         {
496
497             jnrA             = jjnr[jidx];
498             j_coord_offsetA  = DIM*jnrA;
499
500             /* load j atom coordinates */
501             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
502                                               &jx0,&jy0,&jz0);
503
504             /* Calculate displacement vector */
505             dx00             = _mm_sub_pd(ix0,jx0);
506             dy00             = _mm_sub_pd(iy0,jy0);
507             dz00             = _mm_sub_pd(iz0,jz0);
508
509             /* Calculate squared distance and things based on it */
510             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
511
512             rinv00           = gmx_mm_invsqrt_pd(rsq00);
513
514             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
515
516             /* Load parameters for j particles */
517             vdwjidx0A        = 2*vdwtype[jnrA+0];
518
519             /**************************
520              * CALCULATE INTERACTIONS *
521              **************************/
522
523             r00              = _mm_mul_pd(rsq00,rinv00);
524
525             /* Compute parameters for interactions between i and j atoms */
526             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
527             c6grid_00       = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset0+vdwjidx0A);
528
529             /* Analytical LJ-PME */
530             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
531             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
532             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
533             exponent         = gmx_simd_exp_d(ewcljrsq);
534             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
535             poly             = _mm_mul_pd(exponent,_mm_macc_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half,_mm_sub_pd(one,ewcljrsq)));
536             /* f6A = 6 * C6grid * (1 - poly) */
537             f6A              = _mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly));
538             /* f6B = C6grid * exponent * beta^6 */
539             f6B              = _mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6));
540             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
541             fvdw              = _mm_mul_pd(_mm_macc_pd(_mm_msub_pd(c12_00,rinvsix,_mm_sub_pd(c6_00,f6A)),rinvsix,f6B),rinvsq00);
542
543             fscal            = fvdw;
544
545             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
546
547             /* Update vectorial force */
548             fix0             = _mm_macc_pd(dx00,fscal,fix0);
549             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
550             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
551             
552             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
553                                                    _mm_mul_pd(dx00,fscal),
554                                                    _mm_mul_pd(dy00,fscal),
555                                                    _mm_mul_pd(dz00,fscal));
556
557             /* Inner loop uses 47 flops */
558         }
559
560         /* End of innermost loop */
561
562         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
563                                               f+i_coord_offset,fshift+i_shift_offset);
564
565         /* Increment number of inner iterations */
566         inneriter                  += j_index_end - j_index_start;
567
568         /* Outer loop uses 6 flops */
569     }
570
571     /* Increment number of outer iterations */
572     outeriter        += nri;
573
574     /* Update outer/inner flops */
575
576     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*47);
577 }