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