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