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