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