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