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