bfa63a34c88cd85e564423adee5929aafd762bb0
[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 #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 "gromacs/math/vec.h"
47 #include "nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_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_avx_128_fma_double
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB;
77     int              j_coord_offsetA,j_coord_offsetB;
78     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
79     real             rcutoff_scalar;
80     real             *shiftvec,*fshift,*x,*f;
81     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     int              nvdwtype;
88     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89     int              *vdwtype;
90     real             *vdwparam;
91     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
92     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
93     __m128d          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_msub_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_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
220
221             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
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_msub_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             /* Update vectorial force */
238             fix0             = _mm_macc_pd(dx00,fscal,fix0);
239             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
240             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
241             
242             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
243                                                    _mm_mul_pd(dx00,fscal),
244                                                    _mm_mul_pd(dy00,fscal),
245                                                    _mm_mul_pd(dz00,fscal));
246
247             }
248
249             /* Inner loop uses 62 flops */
250         }
251
252         if(jidx<j_index_end)
253         {
254
255             jnrA             = jjnr[jidx];
256             j_coord_offsetA  = DIM*jnrA;
257
258             /* load j atom coordinates */
259             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
260                                               &jx0,&jy0,&jz0);
261
262             /* Calculate displacement vector */
263             dx00             = _mm_sub_pd(ix0,jx0);
264             dy00             = _mm_sub_pd(iy0,jy0);
265             dz00             = _mm_sub_pd(iz0,jz0);
266
267             /* Calculate squared distance and things based on it */
268             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
269
270             rinv00           = gmx_mm_invsqrt_pd(rsq00);
271
272             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
273
274             /* Load parameters for j particles */
275             vdwjidx0A        = 2*vdwtype[jnrA+0];
276
277             /**************************
278              * CALCULATE INTERACTIONS *
279              **************************/
280
281             if (gmx_mm_any_lt(rsq00,rcutoff2))
282             {
283
284             r00              = _mm_mul_pd(rsq00,rinv00);
285
286             /* Compute parameters for interactions between i and j atoms */
287             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
288
289             /* LENNARD-JONES DISPERSION/REPULSION */
290
291             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
292             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
293             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
294             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
295             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
296
297             d                = _mm_sub_pd(r00,rswitch);
298             d                = _mm_max_pd(d,_mm_setzero_pd());
299             d2               = _mm_mul_pd(d,d);
300             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
301
302             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
303
304             /* Evaluate switch function */
305             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
306             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
307             vvdw             = _mm_mul_pd(vvdw,sw);
308             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
309
310             /* Update potential sum for this i atom from the interaction with this j atom. */
311             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
312             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
313             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
314
315             fscal            = fvdw;
316
317             fscal            = _mm_and_pd(fscal,cutoff_mask);
318
319             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
320
321             /* Update vectorial force */
322             fix0             = _mm_macc_pd(dx00,fscal,fix0);
323             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
324             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
325             
326             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
327                                                    _mm_mul_pd(dx00,fscal),
328                                                    _mm_mul_pd(dy00,fscal),
329                                                    _mm_mul_pd(dz00,fscal));
330
331             }
332
333             /* Inner loop uses 62 flops */
334         }
335
336         /* End of innermost loop */
337
338         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
339                                               f+i_coord_offset,fshift+i_shift_offset);
340
341         ggid                        = gid[iidx];
342         /* Update potential energies */
343         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
344
345         /* Increment number of inner iterations */
346         inneriter                  += j_index_end - j_index_start;
347
348         /* Outer loop uses 7 flops */
349     }
350
351     /* Increment number of outer iterations */
352     outeriter        += nri;
353
354     /* Update outer/inner flops */
355
356     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*62);
357 }
358 /*
359  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_double
360  * Electrostatics interaction: None
361  * VdW interaction:            LennardJones
362  * Geometry:                   Particle-Particle
363  * Calculate force/pot:        Force
364  */
365 void
366 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_double
367                     (t_nblist                    * gmx_restrict       nlist,
368                      rvec                        * gmx_restrict          xx,
369                      rvec                        * gmx_restrict          ff,
370                      t_forcerec                  * gmx_restrict          fr,
371                      t_mdatoms                   * gmx_restrict     mdatoms,
372                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
373                      t_nrnb                      * gmx_restrict        nrnb)
374 {
375     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
376      * just 0 for non-waters.
377      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
378      * jnr indices corresponding to data put in the four positions in the SIMD register.
379      */
380     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
381     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
382     int              jnrA,jnrB;
383     int              j_coord_offsetA,j_coord_offsetB;
384     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
385     real             rcutoff_scalar;
386     real             *shiftvec,*fshift,*x,*f;
387     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
388     int              vdwioffset0;
389     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
390     int              vdwjidx0A,vdwjidx0B;
391     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
392     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
393     int              nvdwtype;
394     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
395     int              *vdwtype;
396     real             *vdwparam;
397     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
398     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
399     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
400     real             rswitch_scalar,d_scalar;
401     __m128d          dummy_mask,cutoff_mask;
402     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
403     __m128d          one     = _mm_set1_pd(1.0);
404     __m128d          two     = _mm_set1_pd(2.0);
405     x                = xx[0];
406     f                = ff[0];
407
408     nri              = nlist->nri;
409     iinr             = nlist->iinr;
410     jindex           = nlist->jindex;
411     jjnr             = nlist->jjnr;
412     shiftidx         = nlist->shift;
413     gid              = nlist->gid;
414     shiftvec         = fr->shift_vec[0];
415     fshift           = fr->fshift[0];
416     nvdwtype         = fr->ntype;
417     vdwparam         = fr->nbfp;
418     vdwtype          = mdatoms->typeA;
419
420     rcutoff_scalar   = fr->rvdw;
421     rcutoff          = _mm_set1_pd(rcutoff_scalar);
422     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
423
424     rswitch_scalar   = fr->rvdw_switch;
425     rswitch          = _mm_set1_pd(rswitch_scalar);
426     /* Setup switch parameters */
427     d_scalar         = rcutoff_scalar-rswitch_scalar;
428     d                = _mm_set1_pd(d_scalar);
429     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
430     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
431     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
432     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
433     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
434     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
435
436     /* Avoid stupid compiler warnings */
437     jnrA = jnrB = 0;
438     j_coord_offsetA = 0;
439     j_coord_offsetB = 0;
440
441     outeriter        = 0;
442     inneriter        = 0;
443
444     /* Start outer loop over neighborlists */
445     for(iidx=0; iidx<nri; iidx++)
446     {
447         /* Load shift vector for this list */
448         i_shift_offset   = DIM*shiftidx[iidx];
449
450         /* Load limits for loop over neighbors */
451         j_index_start    = jindex[iidx];
452         j_index_end      = jindex[iidx+1];
453
454         /* Get outer coordinate index */
455         inr              = iinr[iidx];
456         i_coord_offset   = DIM*inr;
457
458         /* Load i particle coords and add shift vector */
459         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
460
461         fix0             = _mm_setzero_pd();
462         fiy0             = _mm_setzero_pd();
463         fiz0             = _mm_setzero_pd();
464
465         /* Load parameters for i particles */
466         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
467
468         /* Start inner kernel loop */
469         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
470         {
471
472             /* Get j neighbor index, and coordinate index */
473             jnrA             = jjnr[jidx];
474             jnrB             = jjnr[jidx+1];
475             j_coord_offsetA  = DIM*jnrA;
476             j_coord_offsetB  = DIM*jnrB;
477
478             /* load j atom coordinates */
479             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
480                                               &jx0,&jy0,&jz0);
481
482             /* Calculate displacement vector */
483             dx00             = _mm_sub_pd(ix0,jx0);
484             dy00             = _mm_sub_pd(iy0,jy0);
485             dz00             = _mm_sub_pd(iz0,jz0);
486
487             /* Calculate squared distance and things based on it */
488             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
489
490             rinv00           = gmx_mm_invsqrt_pd(rsq00);
491
492             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
493
494             /* Load parameters for j particles */
495             vdwjidx0A        = 2*vdwtype[jnrA+0];
496             vdwjidx0B        = 2*vdwtype[jnrB+0];
497
498             /**************************
499              * CALCULATE INTERACTIONS *
500              **************************/
501
502             if (gmx_mm_any_lt(rsq00,rcutoff2))
503             {
504
505             r00              = _mm_mul_pd(rsq00,rinv00);
506
507             /* Compute parameters for interactions between i and j atoms */
508             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
509                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
510
511             /* LENNARD-JONES DISPERSION/REPULSION */
512
513             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
514             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
515             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
516             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
517             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
518
519             d                = _mm_sub_pd(r00,rswitch);
520             d                = _mm_max_pd(d,_mm_setzero_pd());
521             d2               = _mm_mul_pd(d,d);
522             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
523
524             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
525
526             /* Evaluate switch function */
527             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
528             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
529             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
530
531             fscal            = fvdw;
532
533             fscal            = _mm_and_pd(fscal,cutoff_mask);
534
535             /* Update vectorial force */
536             fix0             = _mm_macc_pd(dx00,fscal,fix0);
537             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
538             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
539             
540             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
541                                                    _mm_mul_pd(dx00,fscal),
542                                                    _mm_mul_pd(dy00,fscal),
543                                                    _mm_mul_pd(dz00,fscal));
544
545             }
546
547             /* Inner loop uses 59 flops */
548         }
549
550         if(jidx<j_index_end)
551         {
552
553             jnrA             = jjnr[jidx];
554             j_coord_offsetA  = DIM*jnrA;
555
556             /* load j atom coordinates */
557             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
558                                               &jx0,&jy0,&jz0);
559
560             /* Calculate displacement vector */
561             dx00             = _mm_sub_pd(ix0,jx0);
562             dy00             = _mm_sub_pd(iy0,jy0);
563             dz00             = _mm_sub_pd(iz0,jz0);
564
565             /* Calculate squared distance and things based on it */
566             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
567
568             rinv00           = gmx_mm_invsqrt_pd(rsq00);
569
570             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
571
572             /* Load parameters for j particles */
573             vdwjidx0A        = 2*vdwtype[jnrA+0];
574
575             /**************************
576              * CALCULATE INTERACTIONS *
577              **************************/
578
579             if (gmx_mm_any_lt(rsq00,rcutoff2))
580             {
581
582             r00              = _mm_mul_pd(rsq00,rinv00);
583
584             /* Compute parameters for interactions between i and j atoms */
585             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
586
587             /* LENNARD-JONES DISPERSION/REPULSION */
588
589             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
590             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
591             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
592             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
593             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
594
595             d                = _mm_sub_pd(r00,rswitch);
596             d                = _mm_max_pd(d,_mm_setzero_pd());
597             d2               = _mm_mul_pd(d,d);
598             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
599
600             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
601
602             /* Evaluate switch function */
603             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
604             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
605             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
606
607             fscal            = fvdw;
608
609             fscal            = _mm_and_pd(fscal,cutoff_mask);
610
611             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
612
613             /* Update vectorial force */
614             fix0             = _mm_macc_pd(dx00,fscal,fix0);
615             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
616             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
617             
618             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
619                                                    _mm_mul_pd(dx00,fscal),
620                                                    _mm_mul_pd(dy00,fscal),
621                                                    _mm_mul_pd(dz00,fscal));
622
623             }
624
625             /* Inner loop uses 59 flops */
626         }
627
628         /* End of innermost loop */
629
630         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
631                                               f+i_coord_offset,fshift+i_shift_offset);
632
633         /* Increment number of inner iterations */
634         inneriter                  += j_index_end - j_index_start;
635
636         /* Outer loop uses 6 flops */
637     }
638
639     /* Increment number of outer iterations */
640     outeriter        += nri;
641
642     /* Update outer/inner flops */
643
644     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*59);
645 }