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