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