b43fc297bb8288a427f5c6f7c459cf181501b306
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse4_1_double / nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_sse4_1_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 sse4_1_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_sse4_1_double.h"
48 #include "kernelutil_x86_sse4_1_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_VF_sse4_1_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_sse4_1_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     __m128d           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
93     real             *vdwgridparam;
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_add_pd(_mm_sub_pd(one,ewcljrsq),_mm_mul_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half)));
213             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
214             vvdw6            = _mm_mul_pd(_mm_sub_pd(c6_00,_mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly))),rinvsix);
215             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
216             vvdw             = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))),one_twelfth),
217                                _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_add_pd(_mm_mul_pd(c6_00,sh_vdw_invrcut6),_mm_mul_pd(c6grid_00,sh_lj_ewald))),one_sixth));
218             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
219             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,_mm_sub_pd(vvdw6,_mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6)))),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             /* Calculate temporary vectorial force */
232             tx               = _mm_mul_pd(fscal,dx00);
233             ty               = _mm_mul_pd(fscal,dy00);
234             tz               = _mm_mul_pd(fscal,dz00);
235
236             /* Update vectorial force */
237             fix0             = _mm_add_pd(fix0,tx);
238             fiy0             = _mm_add_pd(fiy0,ty);
239             fiz0             = _mm_add_pd(fiz0,tz);
240
241             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
242
243             }
244
245             /* Inner loop uses 61 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
285             c6grid_00       = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset0+vdwjidx0A);
286
287             /* Analytical LJ-PME */
288             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
289             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
290             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
291             exponent         = gmx_simd_exp_d(ewcljrsq);
292             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
293             poly             = _mm_mul_pd(exponent,_mm_add_pd(_mm_sub_pd(one,ewcljrsq),_mm_mul_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half)));
294             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
295             vvdw6            = _mm_mul_pd(_mm_sub_pd(c6_00,_mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly))),rinvsix);
296             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
297             vvdw             = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))),one_twelfth),
298                                _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_add_pd(_mm_mul_pd(c6_00,sh_vdw_invrcut6),_mm_mul_pd(c6grid_00,sh_lj_ewald))),one_sixth));
299             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
300             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,_mm_sub_pd(vvdw6,_mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6)))),rinvsq00);
301
302             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
303
304             /* Update potential sum for this i atom from the interaction with this j atom. */
305             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
306             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
307             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
308
309             fscal            = fvdw;
310
311             fscal            = _mm_and_pd(fscal,cutoff_mask);
312
313             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
314
315             /* Calculate temporary vectorial force */
316             tx               = _mm_mul_pd(fscal,dx00);
317             ty               = _mm_mul_pd(fscal,dy00);
318             tz               = _mm_mul_pd(fscal,dz00);
319
320             /* Update vectorial force */
321             fix0             = _mm_add_pd(fix0,tx);
322             fiy0             = _mm_add_pd(fiy0,ty);
323             fiz0             = _mm_add_pd(fiz0,tz);
324
325             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
326
327             }
328
329             /* Inner loop uses 61 flops */
330         }
331
332         /* End of innermost loop */
333
334         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
335                                               f+i_coord_offset,fshift+i_shift_offset);
336
337         ggid                        = gid[iidx];
338         /* Update potential energies */
339         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
340
341         /* Increment number of inner iterations */
342         inneriter                  += j_index_end - j_index_start;
343
344         /* Outer loop uses 7 flops */
345     }
346
347     /* Increment number of outer iterations */
348     outeriter        += nri;
349
350     /* Update outer/inner flops */
351
352     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*61);
353 }
354 /*
355  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_F_sse4_1_double
356  * Electrostatics interaction: None
357  * VdW interaction:            LJEwald
358  * Geometry:                   Particle-Particle
359  * Calculate force/pot:        Force
360  */
361 void
362 nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_F_sse4_1_double
363                     (t_nblist                    * gmx_restrict       nlist,
364                      rvec                        * gmx_restrict          xx,
365                      rvec                        * gmx_restrict          ff,
366                      t_forcerec                  * gmx_restrict          fr,
367                      t_mdatoms                   * gmx_restrict     mdatoms,
368                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
369                      t_nrnb                      * gmx_restrict        nrnb)
370 {
371     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
372      * just 0 for non-waters.
373      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
374      * jnr indices corresponding to data put in the four positions in the SIMD register.
375      */
376     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
377     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
378     int              jnrA,jnrB;
379     int              j_coord_offsetA,j_coord_offsetB;
380     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
381     real             rcutoff_scalar;
382     real             *shiftvec,*fshift,*x,*f;
383     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
384     int              vdwioffset0;
385     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
386     int              vdwjidx0A,vdwjidx0B;
387     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
388     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
389     int              nvdwtype;
390     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
391     int              *vdwtype;
392     real             *vdwparam;
393     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
394     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
395     __m128d           c6grid_00;
396     __m128d           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
397     real             *vdwgridparam;
398     __m128d           one_half = _mm_set1_pd(0.5);
399     __m128d           minus_one = _mm_set1_pd(-1.0);
400     __m128d          dummy_mask,cutoff_mask;
401     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
402     __m128d          one     = _mm_set1_pd(1.0);
403     __m128d          two     = _mm_set1_pd(2.0);
404     x                = xx[0];
405     f                = ff[0];
406
407     nri              = nlist->nri;
408     iinr             = nlist->iinr;
409     jindex           = nlist->jindex;
410     jjnr             = nlist->jjnr;
411     shiftidx         = nlist->shift;
412     gid              = nlist->gid;
413     shiftvec         = fr->shift_vec[0];
414     fshift           = fr->fshift[0];
415     nvdwtype         = fr->ntype;
416     vdwparam         = fr->nbfp;
417     vdwtype          = mdatoms->typeA;
418     vdwgridparam     = fr->ljpme_c6grid;
419     sh_lj_ewald      = _mm_set1_pd(fr->ic->sh_lj_ewald);
420     ewclj            = _mm_set1_pd(fr->ewaldcoeff_lj);
421     ewclj2           = _mm_mul_pd(minus_one,_mm_mul_pd(ewclj,ewclj));
422
423     rcutoff_scalar   = fr->rvdw;
424     rcutoff          = _mm_set1_pd(rcutoff_scalar);
425     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
426
427     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
428     rvdw             = _mm_set1_pd(fr->rvdw);
429
430     /* Avoid stupid compiler warnings */
431     jnrA = jnrB = 0;
432     j_coord_offsetA = 0;
433     j_coord_offsetB = 0;
434
435     outeriter        = 0;
436     inneriter        = 0;
437
438     /* Start outer loop over neighborlists */
439     for(iidx=0; iidx<nri; iidx++)
440     {
441         /* Load shift vector for this list */
442         i_shift_offset   = DIM*shiftidx[iidx];
443
444         /* Load limits for loop over neighbors */
445         j_index_start    = jindex[iidx];
446         j_index_end      = jindex[iidx+1];
447
448         /* Get outer coordinate index */
449         inr              = iinr[iidx];
450         i_coord_offset   = DIM*inr;
451
452         /* Load i particle coords and add shift vector */
453         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
454
455         fix0             = _mm_setzero_pd();
456         fiy0             = _mm_setzero_pd();
457         fiz0             = _mm_setzero_pd();
458
459         /* Load parameters for i particles */
460         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
461
462         /* Start inner kernel loop */
463         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
464         {
465
466             /* Get j neighbor index, and coordinate index */
467             jnrA             = jjnr[jidx];
468             jnrB             = jjnr[jidx+1];
469             j_coord_offsetA  = DIM*jnrA;
470             j_coord_offsetB  = DIM*jnrB;
471
472             /* load j atom coordinates */
473             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
474                                               &jx0,&jy0,&jz0);
475
476             /* Calculate displacement vector */
477             dx00             = _mm_sub_pd(ix0,jx0);
478             dy00             = _mm_sub_pd(iy0,jy0);
479             dz00             = _mm_sub_pd(iz0,jz0);
480
481             /* Calculate squared distance and things based on it */
482             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
483
484             rinv00           = gmx_mm_invsqrt_pd(rsq00);
485
486             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
487
488             /* Load parameters for j particles */
489             vdwjidx0A        = 2*vdwtype[jnrA+0];
490             vdwjidx0B        = 2*vdwtype[jnrB+0];
491
492             /**************************
493              * CALCULATE INTERACTIONS *
494              **************************/
495
496             if (gmx_mm_any_lt(rsq00,rcutoff2))
497             {
498
499             r00              = _mm_mul_pd(rsq00,rinv00);
500
501             /* Compute parameters for interactions between i and j atoms */
502             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
503                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
504             c6grid_00       = gmx_mm_load_2real_swizzle_pd(vdwgridparam+vdwioffset0+vdwjidx0A,
505                                                                vdwgridparam+vdwioffset0+vdwjidx0B);
506
507             /* Analytical LJ-PME */
508             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
509             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
510             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
511             exponent         = gmx_simd_exp_d(ewcljrsq);
512             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
513             poly             = _mm_mul_pd(exponent,_mm_add_pd(_mm_sub_pd(one,ewcljrsq),_mm_mul_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half)));
514             /* f6A = 6 * C6grid * (1 - poly) */
515             f6A              = _mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly));
516             /* f6B = C6grid * exponent * beta^6 */
517             f6B              = _mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6));
518             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
519             fvdw              = _mm_mul_pd(_mm_add_pd(_mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),_mm_sub_pd(c6_00,f6A)),rinvsix),f6B),rinvsq00);
520
521             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
522
523             fscal            = fvdw;
524
525             fscal            = _mm_and_pd(fscal,cutoff_mask);
526
527             /* Calculate temporary vectorial force */
528             tx               = _mm_mul_pd(fscal,dx00);
529             ty               = _mm_mul_pd(fscal,dy00);
530             tz               = _mm_mul_pd(fscal,dz00);
531
532             /* Update vectorial force */
533             fix0             = _mm_add_pd(fix0,tx);
534             fiy0             = _mm_add_pd(fiy0,ty);
535             fiz0             = _mm_add_pd(fiz0,tz);
536
537             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
538
539             }
540
541             /* Inner loop uses 49 flops */
542         }
543
544         if(jidx<j_index_end)
545         {
546
547             jnrA             = jjnr[jidx];
548             j_coord_offsetA  = DIM*jnrA;
549
550             /* load j atom coordinates */
551             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
552                                               &jx0,&jy0,&jz0);
553
554             /* Calculate displacement vector */
555             dx00             = _mm_sub_pd(ix0,jx0);
556             dy00             = _mm_sub_pd(iy0,jy0);
557             dz00             = _mm_sub_pd(iz0,jz0);
558
559             /* Calculate squared distance and things based on it */
560             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
561
562             rinv00           = gmx_mm_invsqrt_pd(rsq00);
563
564             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
565
566             /* Load parameters for j particles */
567             vdwjidx0A        = 2*vdwtype[jnrA+0];
568
569             /**************************
570              * CALCULATE INTERACTIONS *
571              **************************/
572
573             if (gmx_mm_any_lt(rsq00,rcutoff2))
574             {
575
576             r00              = _mm_mul_pd(rsq00,rinv00);
577
578             /* Compute parameters for interactions between i and j atoms */
579             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
580
581             c6grid_00       = gmx_mm_load_1real_pd(vdwgridparam+vdwioffset0+vdwjidx0A);
582
583             /* Analytical LJ-PME */
584             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
585             ewcljrsq         = _mm_mul_pd(ewclj2,rsq00);
586             ewclj6           = _mm_mul_pd(ewclj2,_mm_mul_pd(ewclj2,ewclj2));
587             exponent         = gmx_simd_exp_d(ewcljrsq);
588             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
589             poly             = _mm_mul_pd(exponent,_mm_add_pd(_mm_sub_pd(one,ewcljrsq),_mm_mul_pd(_mm_mul_pd(ewcljrsq,ewcljrsq),one_half)));
590             /* f6A = 6 * C6grid * (1 - poly) */
591             f6A              = _mm_mul_pd(c6grid_00,_mm_sub_pd(one,poly));
592             /* f6B = C6grid * exponent * beta^6 */
593             f6B              = _mm_mul_pd(_mm_mul_pd(c6grid_00,one_sixth),_mm_mul_pd(exponent,ewclj6));
594             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
595             fvdw              = _mm_mul_pd(_mm_add_pd(_mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),_mm_sub_pd(c6_00,f6A)),rinvsix),f6B),rinvsq00);
596
597             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
598
599             fscal            = fvdw;
600
601             fscal            = _mm_and_pd(fscal,cutoff_mask);
602
603             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
604
605             /* Calculate temporary vectorial force */
606             tx               = _mm_mul_pd(fscal,dx00);
607             ty               = _mm_mul_pd(fscal,dy00);
608             tz               = _mm_mul_pd(fscal,dz00);
609
610             /* Update vectorial force */
611             fix0             = _mm_add_pd(fix0,tx);
612             fiy0             = _mm_add_pd(fiy0,ty);
613             fiz0             = _mm_add_pd(fiz0,tz);
614
615             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
616
617             }
618
619             /* Inner loop uses 49 flops */
620         }
621
622         /* End of innermost loop */
623
624         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
625                                               f+i_coord_offset,fshift+i_shift_offset);
626
627         /* Increment number of inner iterations */
628         inneriter                  += j_index_end - j_index_start;
629
630         /* Outer loop uses 6 flops */
631     }
632
633     /* Increment number of outer iterations */
634     outeriter        += nri;
635
636     /* Update outer/inner flops */
637
638     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*49);
639 }