Use full path for legacyheaders
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecNone_VdwLJSw_GeomP1P1_avx_128_fma_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_double
52  * Electrostatics interaction: None
53  * VdW interaction:            LennardJones
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_double
59                     (t_nblist                    * gmx_restrict       nlist,
60                      rvec                        * gmx_restrict          xx,
61                      rvec                        * gmx_restrict          ff,
62                      t_forcerec                  * gmx_restrict          fr,
63                      t_mdatoms                   * gmx_restrict     mdatoms,
64                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65                      t_nrnb                      * gmx_restrict        nrnb)
66 {
67     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68      * just 0 for non-waters.
69      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70      * jnr indices corresponding to data put in the four positions in the SIMD register.
71      */
72     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
73     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74     int              jnrA,jnrB;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwjidx0A,vdwjidx0B;
83     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85     int              nvdwtype;
86     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
87     int              *vdwtype;
88     real             *vdwparam;
89     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
90     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
91     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
92     real             rswitch_scalar,d_scalar;
93     __m128d          dummy_mask,cutoff_mask;
94     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
95     __m128d          one     = _mm_set1_pd(1.0);
96     __m128d          two     = _mm_set1_pd(2.0);
97     x                = xx[0];
98     f                = ff[0];
99
100     nri              = nlist->nri;
101     iinr             = nlist->iinr;
102     jindex           = nlist->jindex;
103     jjnr             = nlist->jjnr;
104     shiftidx         = nlist->shift;
105     gid              = nlist->gid;
106     shiftvec         = fr->shift_vec[0];
107     fshift           = fr->fshift[0];
108     nvdwtype         = fr->ntype;
109     vdwparam         = fr->nbfp;
110     vdwtype          = mdatoms->typeA;
111
112     rcutoff_scalar   = fr->rvdw;
113     rcutoff          = _mm_set1_pd(rcutoff_scalar);
114     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
115
116     rswitch_scalar   = fr->rvdw_switch;
117     rswitch          = _mm_set1_pd(rswitch_scalar);
118     /* Setup switch parameters */
119     d_scalar         = rcutoff_scalar-rswitch_scalar;
120     d                = _mm_set1_pd(d_scalar);
121     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
122     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
123     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
124     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
125     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
126     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
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
206             /* LENNARD-JONES DISPERSION/REPULSION */
207
208             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
209             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
210             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
211             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
212             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
213
214             d                = _mm_sub_pd(r00,rswitch);
215             d                = _mm_max_pd(d,_mm_setzero_pd());
216             d2               = _mm_mul_pd(d,d);
217             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
218
219             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
220
221             /* Evaluate switch function */
222             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
223             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
224             vvdw             = _mm_mul_pd(vvdw,sw);
225             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
226
227             /* Update potential sum for this i atom from the interaction with this j atom. */
228             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
229             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
230
231             fscal            = fvdw;
232
233             fscal            = _mm_and_pd(fscal,cutoff_mask);
234
235             /* Update vectorial force */
236             fix0             = _mm_macc_pd(dx00,fscal,fix0);
237             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
238             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
239             
240             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
241                                                    _mm_mul_pd(dx00,fscal),
242                                                    _mm_mul_pd(dy00,fscal),
243                                                    _mm_mul_pd(dz00,fscal));
244
245             }
246
247             /* Inner loop uses 62 flops */
248         }
249
250         if(jidx<j_index_end)
251         {
252
253             jnrA             = jjnr[jidx];
254             j_coord_offsetA  = DIM*jnrA;
255
256             /* load j atom coordinates */
257             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
258                                               &jx0,&jy0,&jz0);
259
260             /* Calculate displacement vector */
261             dx00             = _mm_sub_pd(ix0,jx0);
262             dy00             = _mm_sub_pd(iy0,jy0);
263             dz00             = _mm_sub_pd(iz0,jz0);
264
265             /* Calculate squared distance and things based on it */
266             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
267
268             rinv00           = gmx_mm_invsqrt_pd(rsq00);
269
270             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
271
272             /* Load parameters for j particles */
273             vdwjidx0A        = 2*vdwtype[jnrA+0];
274
275             /**************************
276              * CALCULATE INTERACTIONS *
277              **************************/
278
279             if (gmx_mm_any_lt(rsq00,rcutoff2))
280             {
281
282             r00              = _mm_mul_pd(rsq00,rinv00);
283
284             /* Compute parameters for interactions between i and j atoms */
285             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
286
287             /* LENNARD-JONES DISPERSION/REPULSION */
288
289             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
290             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
291             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
292             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
293             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
294
295             d                = _mm_sub_pd(r00,rswitch);
296             d                = _mm_max_pd(d,_mm_setzero_pd());
297             d2               = _mm_mul_pd(d,d);
298             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
299
300             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
301
302             /* Evaluate switch function */
303             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
304             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
305             vvdw             = _mm_mul_pd(vvdw,sw);
306             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
307
308             /* Update potential sum for this i atom from the interaction with this j atom. */
309             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
310             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
311             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
312
313             fscal            = fvdw;
314
315             fscal            = _mm_and_pd(fscal,cutoff_mask);
316
317             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
318
319             /* Update vectorial force */
320             fix0             = _mm_macc_pd(dx00,fscal,fix0);
321             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
322             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
323             
324             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
325                                                    _mm_mul_pd(dx00,fscal),
326                                                    _mm_mul_pd(dy00,fscal),
327                                                    _mm_mul_pd(dz00,fscal));
328
329             }
330
331             /* Inner loop uses 62 flops */
332         }
333
334         /* End of innermost loop */
335
336         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
337                                               f+i_coord_offset,fshift+i_shift_offset);
338
339         ggid                        = gid[iidx];
340         /* Update potential energies */
341         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
342
343         /* Increment number of inner iterations */
344         inneriter                  += j_index_end - j_index_start;
345
346         /* Outer loop uses 7 flops */
347     }
348
349     /* Increment number of outer iterations */
350     outeriter        += nri;
351
352     /* Update outer/inner flops */
353
354     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*62);
355 }
356 /*
357  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_double
358  * Electrostatics interaction: None
359  * VdW interaction:            LennardJones
360  * Geometry:                   Particle-Particle
361  * Calculate force/pot:        Force
362  */
363 void
364 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_double
365                     (t_nblist                    * gmx_restrict       nlist,
366                      rvec                        * gmx_restrict          xx,
367                      rvec                        * gmx_restrict          ff,
368                      t_forcerec                  * gmx_restrict          fr,
369                      t_mdatoms                   * gmx_restrict     mdatoms,
370                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
371                      t_nrnb                      * gmx_restrict        nrnb)
372 {
373     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
374      * just 0 for non-waters.
375      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
376      * jnr indices corresponding to data put in the four positions in the SIMD register.
377      */
378     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
379     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
380     int              jnrA,jnrB;
381     int              j_coord_offsetA,j_coord_offsetB;
382     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
383     real             rcutoff_scalar;
384     real             *shiftvec,*fshift,*x,*f;
385     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
386     int              vdwioffset0;
387     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
388     int              vdwjidx0A,vdwjidx0B;
389     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
390     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
391     int              nvdwtype;
392     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
393     int              *vdwtype;
394     real             *vdwparam;
395     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
396     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
397     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
398     real             rswitch_scalar,d_scalar;
399     __m128d          dummy_mask,cutoff_mask;
400     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
401     __m128d          one     = _mm_set1_pd(1.0);
402     __m128d          two     = _mm_set1_pd(2.0);
403     x                = xx[0];
404     f                = ff[0];
405
406     nri              = nlist->nri;
407     iinr             = nlist->iinr;
408     jindex           = nlist->jindex;
409     jjnr             = nlist->jjnr;
410     shiftidx         = nlist->shift;
411     gid              = nlist->gid;
412     shiftvec         = fr->shift_vec[0];
413     fshift           = fr->fshift[0];
414     nvdwtype         = fr->ntype;
415     vdwparam         = fr->nbfp;
416     vdwtype          = mdatoms->typeA;
417
418     rcutoff_scalar   = fr->rvdw;
419     rcutoff          = _mm_set1_pd(rcutoff_scalar);
420     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
421
422     rswitch_scalar   = fr->rvdw_switch;
423     rswitch          = _mm_set1_pd(rswitch_scalar);
424     /* Setup switch parameters */
425     d_scalar         = rcutoff_scalar-rswitch_scalar;
426     d                = _mm_set1_pd(d_scalar);
427     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
428     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
429     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
430     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
431     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
432     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
433
434     /* Avoid stupid compiler warnings */
435     jnrA = jnrB = 0;
436     j_coord_offsetA = 0;
437     j_coord_offsetB = 0;
438
439     outeriter        = 0;
440     inneriter        = 0;
441
442     /* Start outer loop over neighborlists */
443     for(iidx=0; iidx<nri; iidx++)
444     {
445         /* Load shift vector for this list */
446         i_shift_offset   = DIM*shiftidx[iidx];
447
448         /* Load limits for loop over neighbors */
449         j_index_start    = jindex[iidx];
450         j_index_end      = jindex[iidx+1];
451
452         /* Get outer coordinate index */
453         inr              = iinr[iidx];
454         i_coord_offset   = DIM*inr;
455
456         /* Load i particle coords and add shift vector */
457         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
458
459         fix0             = _mm_setzero_pd();
460         fiy0             = _mm_setzero_pd();
461         fiz0             = _mm_setzero_pd();
462
463         /* Load parameters for i particles */
464         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
465
466         /* Start inner kernel loop */
467         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
468         {
469
470             /* Get j neighbor index, and coordinate index */
471             jnrA             = jjnr[jidx];
472             jnrB             = jjnr[jidx+1];
473             j_coord_offsetA  = DIM*jnrA;
474             j_coord_offsetB  = DIM*jnrB;
475
476             /* load j atom coordinates */
477             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
478                                               &jx0,&jy0,&jz0);
479
480             /* Calculate displacement vector */
481             dx00             = _mm_sub_pd(ix0,jx0);
482             dy00             = _mm_sub_pd(iy0,jy0);
483             dz00             = _mm_sub_pd(iz0,jz0);
484
485             /* Calculate squared distance and things based on it */
486             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
487
488             rinv00           = gmx_mm_invsqrt_pd(rsq00);
489
490             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
491
492             /* Load parameters for j particles */
493             vdwjidx0A        = 2*vdwtype[jnrA+0];
494             vdwjidx0B        = 2*vdwtype[jnrB+0];
495
496             /**************************
497              * CALCULATE INTERACTIONS *
498              **************************/
499
500             if (gmx_mm_any_lt(rsq00,rcutoff2))
501             {
502
503             r00              = _mm_mul_pd(rsq00,rinv00);
504
505             /* Compute parameters for interactions between i and j atoms */
506             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
507                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
508
509             /* LENNARD-JONES DISPERSION/REPULSION */
510
511             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
512             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
513             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
514             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
515             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
516
517             d                = _mm_sub_pd(r00,rswitch);
518             d                = _mm_max_pd(d,_mm_setzero_pd());
519             d2               = _mm_mul_pd(d,d);
520             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
521
522             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
523
524             /* Evaluate switch function */
525             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
526             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
527             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
528
529             fscal            = fvdw;
530
531             fscal            = _mm_and_pd(fscal,cutoff_mask);
532
533             /* Update vectorial force */
534             fix0             = _mm_macc_pd(dx00,fscal,fix0);
535             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
536             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
537             
538             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
539                                                    _mm_mul_pd(dx00,fscal),
540                                                    _mm_mul_pd(dy00,fscal),
541                                                    _mm_mul_pd(dz00,fscal));
542
543             }
544
545             /* Inner loop uses 59 flops */
546         }
547
548         if(jidx<j_index_end)
549         {
550
551             jnrA             = jjnr[jidx];
552             j_coord_offsetA  = DIM*jnrA;
553
554             /* load j atom coordinates */
555             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
556                                               &jx0,&jy0,&jz0);
557
558             /* Calculate displacement vector */
559             dx00             = _mm_sub_pd(ix0,jx0);
560             dy00             = _mm_sub_pd(iy0,jy0);
561             dz00             = _mm_sub_pd(iz0,jz0);
562
563             /* Calculate squared distance and things based on it */
564             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
565
566             rinv00           = gmx_mm_invsqrt_pd(rsq00);
567
568             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
569
570             /* Load parameters for j particles */
571             vdwjidx0A        = 2*vdwtype[jnrA+0];
572
573             /**************************
574              * CALCULATE INTERACTIONS *
575              **************************/
576
577             if (gmx_mm_any_lt(rsq00,rcutoff2))
578             {
579
580             r00              = _mm_mul_pd(rsq00,rinv00);
581
582             /* Compute parameters for interactions between i and j atoms */
583             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
584
585             /* LENNARD-JONES DISPERSION/REPULSION */
586
587             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
588             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
589             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
590             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
591             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
592
593             d                = _mm_sub_pd(r00,rswitch);
594             d                = _mm_max_pd(d,_mm_setzero_pd());
595             d2               = _mm_mul_pd(d,d);
596             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
597
598             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
599
600             /* Evaluate switch function */
601             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
602             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
603             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
604
605             fscal            = fvdw;
606
607             fscal            = _mm_and_pd(fscal,cutoff_mask);
608
609             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
610
611             /* Update vectorial force */
612             fix0             = _mm_macc_pd(dx00,fscal,fix0);
613             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
614             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
615             
616             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
617                                                    _mm_mul_pd(dx00,fscal),
618                                                    _mm_mul_pd(dy00,fscal),
619                                                    _mm_mul_pd(dz00,fscal));
620
621             }
622
623             /* Inner loop uses 59 flops */
624         }
625
626         /* End of innermost loop */
627
628         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
629                                               f+i_coord_offset,fshift+i_shift_offset);
630
631         /* Increment number of inner iterations */
632         inneriter                  += j_index_end - j_index_start;
633
634         /* Outer loop uses 6 flops */
635     }
636
637     /* Increment number of outer iterations */
638     outeriter        += nri;
639
640     /* Update outer/inner flops */
641
642     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*59);
643 }