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