Use full path for legacyheaders
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEw_VdwNone_GeomP1P1_avx_128_fma_single.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_single kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_single
52  * Electrostatics interaction: Ewald
53  * VdW interaction:            None
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_128_fma_single
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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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,jnrC,jnrD;
75     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
78     real             rcutoff_scalar;
79     real             *shiftvec,*fshift,*x,*f;
80     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81     real             scratch[4*DIM];
82     __m128           fscal,rcutoff,rcutoff2,jidxall;
83     int              vdwioffset0;
84     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
89     real             *charge;
90     __m128i          ewitab;
91     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
92     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
93     real             *ewtab;
94     __m128           dummy_mask,cutoff_mask;
95     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
96     __m128           one     = _mm_set1_ps(1.0);
97     __m128           two     = _mm_set1_ps(2.0);
98     x                = xx[0];
99     f                = ff[0];
100
101     nri              = nlist->nri;
102     iinr             = nlist->iinr;
103     jindex           = nlist->jindex;
104     jjnr             = nlist->jjnr;
105     shiftidx         = nlist->shift;
106     gid              = nlist->gid;
107     shiftvec         = fr->shift_vec[0];
108     fshift           = fr->fshift[0];
109     facel            = _mm_set1_ps(fr->epsfac);
110     charge           = mdatoms->chargeA;
111
112     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
113     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
114     beta2            = _mm_mul_ps(beta,beta);
115     beta3            = _mm_mul_ps(beta,beta2);
116     ewtab            = fr->ic->tabq_coul_FDV0;
117     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
118     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
119
120     /* Avoid stupid compiler warnings */
121     jnrA = jnrB = jnrC = jnrD = 0;
122     j_coord_offsetA = 0;
123     j_coord_offsetB = 0;
124     j_coord_offsetC = 0;
125     j_coord_offsetD = 0;
126
127     outeriter        = 0;
128     inneriter        = 0;
129
130     for(iidx=0;iidx<4*DIM;iidx++)
131     {
132         scratch[iidx] = 0.0;
133     }
134
135     /* Start outer loop over neighborlists */
136     for(iidx=0; iidx<nri; iidx++)
137     {
138         /* Load shift vector for this list */
139         i_shift_offset   = DIM*shiftidx[iidx];
140
141         /* Load limits for loop over neighbors */
142         j_index_start    = jindex[iidx];
143         j_index_end      = jindex[iidx+1];
144
145         /* Get outer coordinate index */
146         inr              = iinr[iidx];
147         i_coord_offset   = DIM*inr;
148
149         /* Load i particle coords and add shift vector */
150         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
151
152         fix0             = _mm_setzero_ps();
153         fiy0             = _mm_setzero_ps();
154         fiz0             = _mm_setzero_ps();
155
156         /* Load parameters for i particles */
157         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
158
159         /* Reset potential sums */
160         velecsum         = _mm_setzero_ps();
161
162         /* Start inner kernel loop */
163         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
164         {
165
166             /* Get j neighbor index, and coordinate index */
167             jnrA             = jjnr[jidx];
168             jnrB             = jjnr[jidx+1];
169             jnrC             = jjnr[jidx+2];
170             jnrD             = jjnr[jidx+3];
171             j_coord_offsetA  = DIM*jnrA;
172             j_coord_offsetB  = DIM*jnrB;
173             j_coord_offsetC  = DIM*jnrC;
174             j_coord_offsetD  = DIM*jnrD;
175
176             /* load j atom coordinates */
177             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
178                                               x+j_coord_offsetC,x+j_coord_offsetD,
179                                               &jx0,&jy0,&jz0);
180
181             /* Calculate displacement vector */
182             dx00             = _mm_sub_ps(ix0,jx0);
183             dy00             = _mm_sub_ps(iy0,jy0);
184             dz00             = _mm_sub_ps(iz0,jz0);
185
186             /* Calculate squared distance and things based on it */
187             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
188
189             rinv00           = gmx_mm_invsqrt_ps(rsq00);
190
191             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
192
193             /* Load parameters for j particles */
194             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
195                                                               charge+jnrC+0,charge+jnrD+0);
196
197             /**************************
198              * CALCULATE INTERACTIONS *
199              **************************/
200
201             r00              = _mm_mul_ps(rsq00,rinv00);
202
203             /* Compute parameters for interactions between i and j atoms */
204             qq00             = _mm_mul_ps(iq0,jq0);
205
206             /* EWALD ELECTROSTATICS */
207
208             /* Analytical PME correction */
209             zeta2            = _mm_mul_ps(beta2,rsq00);
210             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
211             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
212             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
213             felec            = _mm_mul_ps(qq00,felec);
214             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
215             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv00);
216             velec            = _mm_mul_ps(qq00,velec);
217
218             /* Update potential sum for this i atom from the interaction with this j atom. */
219             velecsum         = _mm_add_ps(velecsum,velec);
220
221             fscal            = felec;
222
223              /* Update vectorial force */
224             fix0             = _mm_macc_ps(dx00,fscal,fix0);
225             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
226             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
227
228             fjptrA             = f+j_coord_offsetA;
229             fjptrB             = f+j_coord_offsetB;
230             fjptrC             = f+j_coord_offsetC;
231             fjptrD             = f+j_coord_offsetD;
232             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
233                                                    _mm_mul_ps(dx00,fscal),
234                                                    _mm_mul_ps(dy00,fscal),
235                                                    _mm_mul_ps(dz00,fscal));
236
237             /* Inner loop uses 29 flops */
238         }
239
240         if(jidx<j_index_end)
241         {
242
243             /* Get j neighbor index, and coordinate index */
244             jnrlistA         = jjnr[jidx];
245             jnrlistB         = jjnr[jidx+1];
246             jnrlistC         = jjnr[jidx+2];
247             jnrlistD         = jjnr[jidx+3];
248             /* Sign of each element will be negative for non-real atoms.
249              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
250              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
251              */
252             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
253             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
254             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
255             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
256             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
257             j_coord_offsetA  = DIM*jnrA;
258             j_coord_offsetB  = DIM*jnrB;
259             j_coord_offsetC  = DIM*jnrC;
260             j_coord_offsetD  = DIM*jnrD;
261
262             /* load j atom coordinates */
263             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
264                                               x+j_coord_offsetC,x+j_coord_offsetD,
265                                               &jx0,&jy0,&jz0);
266
267             /* Calculate displacement vector */
268             dx00             = _mm_sub_ps(ix0,jx0);
269             dy00             = _mm_sub_ps(iy0,jy0);
270             dz00             = _mm_sub_ps(iz0,jz0);
271
272             /* Calculate squared distance and things based on it */
273             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
274
275             rinv00           = gmx_mm_invsqrt_ps(rsq00);
276
277             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
278
279             /* Load parameters for j particles */
280             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
281                                                               charge+jnrC+0,charge+jnrD+0);
282
283             /**************************
284              * CALCULATE INTERACTIONS *
285              **************************/
286
287             r00              = _mm_mul_ps(rsq00,rinv00);
288             r00              = _mm_andnot_ps(dummy_mask,r00);
289
290             /* Compute parameters for interactions between i and j atoms */
291             qq00             = _mm_mul_ps(iq0,jq0);
292
293             /* EWALD ELECTROSTATICS */
294
295             /* Analytical PME correction */
296             zeta2            = _mm_mul_ps(beta2,rsq00);
297             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
298             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
299             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
300             felec            = _mm_mul_ps(qq00,felec);
301             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
302             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv00);
303             velec            = _mm_mul_ps(qq00,velec);
304
305             /* Update potential sum for this i atom from the interaction with this j atom. */
306             velec            = _mm_andnot_ps(dummy_mask,velec);
307             velecsum         = _mm_add_ps(velecsum,velec);
308
309             fscal            = felec;
310
311             fscal            = _mm_andnot_ps(dummy_mask,fscal);
312
313              /* Update vectorial force */
314             fix0             = _mm_macc_ps(dx00,fscal,fix0);
315             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
316             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
317
318             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
319             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
320             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
321             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
322             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
323                                                    _mm_mul_ps(dx00,fscal),
324                                                    _mm_mul_ps(dy00,fscal),
325                                                    _mm_mul_ps(dz00,fscal));
326
327             /* Inner loop uses 30 flops */
328         }
329
330         /* End of innermost loop */
331
332         gmx_mm_update_iforce_1atom_swizzle_ps(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_ps(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*30);
351 }
352 /*
353  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_single
354  * Electrostatics interaction: Ewald
355  * VdW interaction:            None
356  * Geometry:                   Particle-Particle
357  * Calculate force/pot:        Force
358  */
359 void
360 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_128_fma_single
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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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,jnrC,jnrD;
377     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
378     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
379     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
380     real             rcutoff_scalar;
381     real             *shiftvec,*fshift,*x,*f;
382     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
383     real             scratch[4*DIM];
384     __m128           fscal,rcutoff,rcutoff2,jidxall;
385     int              vdwioffset0;
386     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
387     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
388     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
389     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
390     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
391     real             *charge;
392     __m128i          ewitab;
393     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
394     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
395     real             *ewtab;
396     __m128           dummy_mask,cutoff_mask;
397     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
398     __m128           one     = _mm_set1_ps(1.0);
399     __m128           two     = _mm_set1_ps(2.0);
400     x                = xx[0];
401     f                = ff[0];
402
403     nri              = nlist->nri;
404     iinr             = nlist->iinr;
405     jindex           = nlist->jindex;
406     jjnr             = nlist->jjnr;
407     shiftidx         = nlist->shift;
408     gid              = nlist->gid;
409     shiftvec         = fr->shift_vec[0];
410     fshift           = fr->fshift[0];
411     facel            = _mm_set1_ps(fr->epsfac);
412     charge           = mdatoms->chargeA;
413
414     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
415     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
416     beta2            = _mm_mul_ps(beta,beta);
417     beta3            = _mm_mul_ps(beta,beta2);
418     ewtab            = fr->ic->tabq_coul_F;
419     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
420     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
421
422     /* Avoid stupid compiler warnings */
423     jnrA = jnrB = jnrC = jnrD = 0;
424     j_coord_offsetA = 0;
425     j_coord_offsetB = 0;
426     j_coord_offsetC = 0;
427     j_coord_offsetD = 0;
428
429     outeriter        = 0;
430     inneriter        = 0;
431
432     for(iidx=0;iidx<4*DIM;iidx++)
433     {
434         scratch[iidx] = 0.0;
435     }
436
437     /* Start outer loop over neighborlists */
438     for(iidx=0; iidx<nri; iidx++)
439     {
440         /* Load shift vector for this list */
441         i_shift_offset   = DIM*shiftidx[iidx];
442
443         /* Load limits for loop over neighbors */
444         j_index_start    = jindex[iidx];
445         j_index_end      = jindex[iidx+1];
446
447         /* Get outer coordinate index */
448         inr              = iinr[iidx];
449         i_coord_offset   = DIM*inr;
450
451         /* Load i particle coords and add shift vector */
452         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
453
454         fix0             = _mm_setzero_ps();
455         fiy0             = _mm_setzero_ps();
456         fiz0             = _mm_setzero_ps();
457
458         /* Load parameters for i particles */
459         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
460
461         /* Start inner kernel loop */
462         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
463         {
464
465             /* Get j neighbor index, and coordinate index */
466             jnrA             = jjnr[jidx];
467             jnrB             = jjnr[jidx+1];
468             jnrC             = jjnr[jidx+2];
469             jnrD             = jjnr[jidx+3];
470             j_coord_offsetA  = DIM*jnrA;
471             j_coord_offsetB  = DIM*jnrB;
472             j_coord_offsetC  = DIM*jnrC;
473             j_coord_offsetD  = DIM*jnrD;
474
475             /* load j atom coordinates */
476             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
477                                               x+j_coord_offsetC,x+j_coord_offsetD,
478                                               &jx0,&jy0,&jz0);
479
480             /* Calculate displacement vector */
481             dx00             = _mm_sub_ps(ix0,jx0);
482             dy00             = _mm_sub_ps(iy0,jy0);
483             dz00             = _mm_sub_ps(iz0,jz0);
484
485             /* Calculate squared distance and things based on it */
486             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
487
488             rinv00           = gmx_mm_invsqrt_ps(rsq00);
489
490             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
491
492             /* Load parameters for j particles */
493             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
494                                                               charge+jnrC+0,charge+jnrD+0);
495
496             /**************************
497              * CALCULATE INTERACTIONS *
498              **************************/
499
500             r00              = _mm_mul_ps(rsq00,rinv00);
501
502             /* Compute parameters for interactions between i and j atoms */
503             qq00             = _mm_mul_ps(iq0,jq0);
504
505             /* EWALD ELECTROSTATICS */
506
507             /* Analytical PME correction */
508             zeta2            = _mm_mul_ps(beta2,rsq00);
509             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
510             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
511             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
512             felec            = _mm_mul_ps(qq00,felec);
513
514             fscal            = felec;
515
516              /* Update vectorial force */
517             fix0             = _mm_macc_ps(dx00,fscal,fix0);
518             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
519             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
520
521             fjptrA             = f+j_coord_offsetA;
522             fjptrB             = f+j_coord_offsetB;
523             fjptrC             = f+j_coord_offsetC;
524             fjptrD             = f+j_coord_offsetD;
525             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
526                                                    _mm_mul_ps(dx00,fscal),
527                                                    _mm_mul_ps(dy00,fscal),
528                                                    _mm_mul_ps(dz00,fscal));
529
530             /* Inner loop uses 28 flops */
531         }
532
533         if(jidx<j_index_end)
534         {
535
536             /* Get j neighbor index, and coordinate index */
537             jnrlistA         = jjnr[jidx];
538             jnrlistB         = jjnr[jidx+1];
539             jnrlistC         = jjnr[jidx+2];
540             jnrlistD         = jjnr[jidx+3];
541             /* Sign of each element will be negative for non-real atoms.
542              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
543              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
544              */
545             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
546             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
547             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
548             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
549             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
550             j_coord_offsetA  = DIM*jnrA;
551             j_coord_offsetB  = DIM*jnrB;
552             j_coord_offsetC  = DIM*jnrC;
553             j_coord_offsetD  = DIM*jnrD;
554
555             /* load j atom coordinates */
556             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
557                                               x+j_coord_offsetC,x+j_coord_offsetD,
558                                               &jx0,&jy0,&jz0);
559
560             /* Calculate displacement vector */
561             dx00             = _mm_sub_ps(ix0,jx0);
562             dy00             = _mm_sub_ps(iy0,jy0);
563             dz00             = _mm_sub_ps(iz0,jz0);
564
565             /* Calculate squared distance and things based on it */
566             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
567
568             rinv00           = gmx_mm_invsqrt_ps(rsq00);
569
570             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
571
572             /* Load parameters for j particles */
573             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
574                                                               charge+jnrC+0,charge+jnrD+0);
575
576             /**************************
577              * CALCULATE INTERACTIONS *
578              **************************/
579
580             r00              = _mm_mul_ps(rsq00,rinv00);
581             r00              = _mm_andnot_ps(dummy_mask,r00);
582
583             /* Compute parameters for interactions between i and j atoms */
584             qq00             = _mm_mul_ps(iq0,jq0);
585
586             /* EWALD ELECTROSTATICS */
587
588             /* Analytical PME correction */
589             zeta2            = _mm_mul_ps(beta2,rsq00);
590             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
591             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
592             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
593             felec            = _mm_mul_ps(qq00,felec);
594
595             fscal            = felec;
596
597             fscal            = _mm_andnot_ps(dummy_mask,fscal);
598
599              /* Update vectorial force */
600             fix0             = _mm_macc_ps(dx00,fscal,fix0);
601             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
602             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
603
604             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
605             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
606             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
607             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
608             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
609                                                    _mm_mul_ps(dx00,fscal),
610                                                    _mm_mul_ps(dy00,fscal),
611                                                    _mm_mul_ps(dz00,fscal));
612
613             /* Inner loop uses 29 flops */
614         }
615
616         /* End of innermost loop */
617
618         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
619                                               f+i_coord_offset,fshift+i_shift_offset);
620
621         /* Increment number of inner iterations */
622         inneriter                  += j_index_end - j_index_start;
623
624         /* Outer loop uses 7 flops */
625     }
626
627     /* Increment number of outer iterations */
628     outeriter        += nri;
629
630     /* Update outer/inner flops */
631
632     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*29);
633 }