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