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