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