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