Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_double / nb_kernel_ElecEw_VdwLJ_GeomP1P1_sse2_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS 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/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_sse2_double.h"
50 #include "kernelutil_x86_sse2_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_double
54  * Electrostatics interaction: Ewald
55  * VdW interaction:            LennardJones
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_double
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB;
77     int              j_coord_offsetA,j_coord_offsetB;
78     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
79     real             rcutoff_scalar;
80     real             *shiftvec,*fshift,*x,*f;
81     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
88     real             *charge;
89     int              nvdwtype;
90     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
91     int              *vdwtype;
92     real             *vdwparam;
93     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
94     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
95     __m128i          ewitab;
96     __m128d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
97     real             *ewtab;
98     __m128d          dummy_mask,cutoff_mask;
99     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
100     __m128d          one     = _mm_set1_pd(1.0);
101     __m128d          two     = _mm_set1_pd(2.0);
102     x                = xx[0];
103     f                = ff[0];
104
105     nri              = nlist->nri;
106     iinr             = nlist->iinr;
107     jindex           = nlist->jindex;
108     jjnr             = nlist->jjnr;
109     shiftidx         = nlist->shift;
110     gid              = nlist->gid;
111     shiftvec         = fr->shift_vec[0];
112     fshift           = fr->fshift[0];
113     facel            = _mm_set1_pd(fr->epsfac);
114     charge           = mdatoms->chargeA;
115     nvdwtype         = fr->ntype;
116     vdwparam         = fr->nbfp;
117     vdwtype          = mdatoms->typeA;
118
119     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
120     ewtab            = fr->ic->tabq_coul_FDV0;
121     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
122     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
123
124     /* Avoid stupid compiler warnings */
125     jnrA = jnrB = 0;
126     j_coord_offsetA = 0;
127     j_coord_offsetB = 0;
128
129     outeriter        = 0;
130     inneriter        = 0;
131
132     /* Start outer loop over neighborlists */
133     for(iidx=0; iidx<nri; iidx++)
134     {
135         /* Load shift vector for this list */
136         i_shift_offset   = DIM*shiftidx[iidx];
137
138         /* Load limits for loop over neighbors */
139         j_index_start    = jindex[iidx];
140         j_index_end      = jindex[iidx+1];
141
142         /* Get outer coordinate index */
143         inr              = iinr[iidx];
144         i_coord_offset   = DIM*inr;
145
146         /* Load i particle coords and add shift vector */
147         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
148
149         fix0             = _mm_setzero_pd();
150         fiy0             = _mm_setzero_pd();
151         fiz0             = _mm_setzero_pd();
152
153         /* Load parameters for i particles */
154         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
155         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
156
157         /* Reset potential sums */
158         velecsum         = _mm_setzero_pd();
159         vvdwsum          = _mm_setzero_pd();
160
161         /* Start inner kernel loop */
162         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
163         {
164
165             /* Get j neighbor index, and coordinate index */
166             jnrA             = jjnr[jidx];
167             jnrB             = jjnr[jidx+1];
168             j_coord_offsetA  = DIM*jnrA;
169             j_coord_offsetB  = DIM*jnrB;
170
171             /* load j atom coordinates */
172             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
173                                               &jx0,&jy0,&jz0);
174
175             /* Calculate displacement vector */
176             dx00             = _mm_sub_pd(ix0,jx0);
177             dy00             = _mm_sub_pd(iy0,jy0);
178             dz00             = _mm_sub_pd(iz0,jz0);
179
180             /* Calculate squared distance and things based on it */
181             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
182
183             rinv00           = gmx_mm_invsqrt_pd(rsq00);
184
185             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
186
187             /* Load parameters for j particles */
188             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
189             vdwjidx0A        = 2*vdwtype[jnrA+0];
190             vdwjidx0B        = 2*vdwtype[jnrB+0];
191
192             /**************************
193              * CALCULATE INTERACTIONS *
194              **************************/
195
196             r00              = _mm_mul_pd(rsq00,rinv00);
197
198             /* Compute parameters for interactions between i and j atoms */
199             qq00             = _mm_mul_pd(iq0,jq0);
200             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
201                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
202
203             /* EWALD ELECTROSTATICS */
204
205             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
206             ewrt             = _mm_mul_pd(r00,ewtabscale);
207             ewitab           = _mm_cvttpd_epi32(ewrt);
208             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
209             ewitab           = _mm_slli_epi32(ewitab,2);
210             ewtabF           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
211             ewtabD           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
212             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
213             ewtabV           = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
214             ewtabFn          = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
215             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
216             felec            = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
217             velec            = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
218             velec            = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
219             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
220
221             /* LENNARD-JONES DISPERSION/REPULSION */
222
223             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
224             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
225             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
226             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
227             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
228
229             /* Update potential sum for this i atom from the interaction with this j atom. */
230             velecsum         = _mm_add_pd(velecsum,velec);
231             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
232
233             fscal            = _mm_add_pd(felec,fvdw);
234
235             /* Calculate temporary vectorial force */
236             tx               = _mm_mul_pd(fscal,dx00);
237             ty               = _mm_mul_pd(fscal,dy00);
238             tz               = _mm_mul_pd(fscal,dz00);
239
240             /* Update vectorial force */
241             fix0             = _mm_add_pd(fix0,tx);
242             fiy0             = _mm_add_pd(fiy0,ty);
243             fiz0             = _mm_add_pd(fiz0,tz);
244
245             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
246
247             /* Inner loop uses 53 flops */
248         }
249
250         if(jidx<j_index_end)
251         {
252
253             jnrA             = jjnr[jidx];
254             j_coord_offsetA  = DIM*jnrA;
255
256             /* load j atom coordinates */
257             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
258                                               &jx0,&jy0,&jz0);
259
260             /* Calculate displacement vector */
261             dx00             = _mm_sub_pd(ix0,jx0);
262             dy00             = _mm_sub_pd(iy0,jy0);
263             dz00             = _mm_sub_pd(iz0,jz0);
264
265             /* Calculate squared distance and things based on it */
266             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
267
268             rinv00           = gmx_mm_invsqrt_pd(rsq00);
269
270             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
271
272             /* Load parameters for j particles */
273             jq0              = _mm_load_sd(charge+jnrA+0);
274             vdwjidx0A        = 2*vdwtype[jnrA+0];
275
276             /**************************
277              * CALCULATE INTERACTIONS *
278              **************************/
279
280             r00              = _mm_mul_pd(rsq00,rinv00);
281
282             /* Compute parameters for interactions between i and j atoms */
283             qq00             = _mm_mul_pd(iq0,jq0);
284             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
285
286             /* EWALD ELECTROSTATICS */
287
288             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
289             ewrt             = _mm_mul_pd(r00,ewtabscale);
290             ewitab           = _mm_cvttpd_epi32(ewrt);
291             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
292             ewitab           = _mm_slli_epi32(ewitab,2);
293             ewtabF           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
294             ewtabD           = _mm_setzero_pd();
295             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
296             ewtabV           = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
297             ewtabFn          = _mm_setzero_pd();
298             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
299             felec            = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
300             velec            = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
301             velec            = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
302             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
303
304             /* LENNARD-JONES DISPERSION/REPULSION */
305
306             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
307             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
308             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
309             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
310             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
311
312             /* Update potential sum for this i atom from the interaction with this j atom. */
313             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
314             velecsum         = _mm_add_pd(velecsum,velec);
315             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
316             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
317
318             fscal            = _mm_add_pd(felec,fvdw);
319
320             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
321
322             /* Calculate temporary vectorial force */
323             tx               = _mm_mul_pd(fscal,dx00);
324             ty               = _mm_mul_pd(fscal,dy00);
325             tz               = _mm_mul_pd(fscal,dz00);
326
327             /* Update vectorial force */
328             fix0             = _mm_add_pd(fix0,tx);
329             fiy0             = _mm_add_pd(fiy0,ty);
330             fiz0             = _mm_add_pd(fiz0,tz);
331
332             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
333
334             /* Inner loop uses 53 flops */
335         }
336
337         /* End of innermost loop */
338
339         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
340                                               f+i_coord_offset,fshift+i_shift_offset);
341
342         ggid                        = gid[iidx];
343         /* Update potential energies */
344         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
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 9 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_ELEC_VDW_VF,outeriter*9 + inneriter*53);
359 }
360 /*
361  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_double
362  * Electrostatics interaction: Ewald
363  * VdW interaction:            LennardJones
364  * Geometry:                   Particle-Particle
365  * Calculate force/pot:        Force
366  */
367 void
368 nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_double
369                     (t_nblist                    * gmx_restrict       nlist,
370                      rvec                        * gmx_restrict          xx,
371                      rvec                        * gmx_restrict          ff,
372                      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     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
396     real             *charge;
397     int              nvdwtype;
398     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
399     int              *vdwtype;
400     real             *vdwparam;
401     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
402     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
403     __m128i          ewitab;
404     __m128d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
405     real             *ewtab;
406     __m128d          dummy_mask,cutoff_mask;
407     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
408     __m128d          one     = _mm_set1_pd(1.0);
409     __m128d          two     = _mm_set1_pd(2.0);
410     x                = xx[0];
411     f                = ff[0];
412
413     nri              = nlist->nri;
414     iinr             = nlist->iinr;
415     jindex           = nlist->jindex;
416     jjnr             = nlist->jjnr;
417     shiftidx         = nlist->shift;
418     gid              = nlist->gid;
419     shiftvec         = fr->shift_vec[0];
420     fshift           = fr->fshift[0];
421     facel            = _mm_set1_pd(fr->epsfac);
422     charge           = mdatoms->chargeA;
423     nvdwtype         = fr->ntype;
424     vdwparam         = fr->nbfp;
425     vdwtype          = mdatoms->typeA;
426
427     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
428     ewtab            = fr->ic->tabq_coul_F;
429     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
430     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
431
432     /* Avoid stupid compiler warnings */
433     jnrA = jnrB = 0;
434     j_coord_offsetA = 0;
435     j_coord_offsetB = 0;
436
437     outeriter        = 0;
438     inneriter        = 0;
439
440     /* Start outer loop over neighborlists */
441     for(iidx=0; iidx<nri; iidx++)
442     {
443         /* Load shift vector for this list */
444         i_shift_offset   = DIM*shiftidx[iidx];
445
446         /* Load limits for loop over neighbors */
447         j_index_start    = jindex[iidx];
448         j_index_end      = jindex[iidx+1];
449
450         /* Get outer coordinate index */
451         inr              = iinr[iidx];
452         i_coord_offset   = DIM*inr;
453
454         /* Load i particle coords and add shift vector */
455         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
456
457         fix0             = _mm_setzero_pd();
458         fiy0             = _mm_setzero_pd();
459         fiz0             = _mm_setzero_pd();
460
461         /* Load parameters for i particles */
462         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
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           = gmx_mm_invsqrt_pd(rsq00);
488
489             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
490
491             /* Load parameters for j particles */
492             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
493             vdwjidx0A        = 2*vdwtype[jnrA+0];
494             vdwjidx0B        = 2*vdwtype[jnrB+0];
495
496             /**************************
497              * CALCULATE INTERACTIONS *
498              **************************/
499
500             r00              = _mm_mul_pd(rsq00,rinv00);
501
502             /* Compute parameters for interactions between i and j atoms */
503             qq00             = _mm_mul_pd(iq0,jq0);
504             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
505                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
506
507             /* EWALD ELECTROSTATICS */
508
509             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
510             ewrt             = _mm_mul_pd(r00,ewtabscale);
511             ewitab           = _mm_cvttpd_epi32(ewrt);
512             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
513             gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
514                                          &ewtabF,&ewtabFn);
515             felec            = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
516             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
517
518             /* LENNARD-JONES DISPERSION/REPULSION */
519
520             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
521             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
522
523             fscal            = _mm_add_pd(felec,fvdw);
524
525             /* Calculate temporary vectorial force */
526             tx               = _mm_mul_pd(fscal,dx00);
527             ty               = _mm_mul_pd(fscal,dy00);
528             tz               = _mm_mul_pd(fscal,dz00);
529
530             /* Update vectorial force */
531             fix0             = _mm_add_pd(fix0,tx);
532             fiy0             = _mm_add_pd(fiy0,ty);
533             fiz0             = _mm_add_pd(fiz0,tz);
534
535             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
536
537             /* Inner loop uses 43 flops */
538         }
539
540         if(jidx<j_index_end)
541         {
542
543             jnrA             = jjnr[jidx];
544             j_coord_offsetA  = DIM*jnrA;
545
546             /* load j atom coordinates */
547             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
548                                               &jx0,&jy0,&jz0);
549
550             /* Calculate displacement vector */
551             dx00             = _mm_sub_pd(ix0,jx0);
552             dy00             = _mm_sub_pd(iy0,jy0);
553             dz00             = _mm_sub_pd(iz0,jz0);
554
555             /* Calculate squared distance and things based on it */
556             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
557
558             rinv00           = gmx_mm_invsqrt_pd(rsq00);
559
560             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
561
562             /* Load parameters for j particles */
563             jq0              = _mm_load_sd(charge+jnrA+0);
564             vdwjidx0A        = 2*vdwtype[jnrA+0];
565
566             /**************************
567              * CALCULATE INTERACTIONS *
568              **************************/
569
570             r00              = _mm_mul_pd(rsq00,rinv00);
571
572             /* Compute parameters for interactions between i and j atoms */
573             qq00             = _mm_mul_pd(iq0,jq0);
574             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
575
576             /* EWALD ELECTROSTATICS */
577
578             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
579             ewrt             = _mm_mul_pd(r00,ewtabscale);
580             ewitab           = _mm_cvttpd_epi32(ewrt);
581             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
582             gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
583             felec            = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
584             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
585
586             /* LENNARD-JONES DISPERSION/REPULSION */
587
588             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
589             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
590
591             fscal            = _mm_add_pd(felec,fvdw);
592
593             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
594
595             /* Calculate temporary vectorial force */
596             tx               = _mm_mul_pd(fscal,dx00);
597             ty               = _mm_mul_pd(fscal,dy00);
598             tz               = _mm_mul_pd(fscal,dz00);
599
600             /* Update vectorial force */
601             fix0             = _mm_add_pd(fix0,tx);
602             fiy0             = _mm_add_pd(fiy0,ty);
603             fiz0             = _mm_add_pd(fiz0,tz);
604
605             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
606
607             /* Inner loop uses 43 flops */
608         }
609
610         /* End of innermost loop */
611
612         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
613                                               f+i_coord_offset,fshift+i_shift_offset);
614
615         /* Increment number of inner iterations */
616         inneriter                  += j_index_end - j_index_start;
617
618         /* Outer loop uses 7 flops */
619     }
620
621     /* Increment number of outer iterations */
622     outeriter        += nri;
623
624     /* Update outer/inner flops */
625
626     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*43);
627 }