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