Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_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 "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
54  * Electrostatics interaction: Ewald
55  * VdW interaction:            LJEwald
56  * Geometry:                   Water4-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_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              vdwioffset1;
88     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
89     int              vdwioffset2;
90     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91     int              vdwioffset3;
92     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
100     real             *charge;
101     int              nvdwtype;
102     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103     int              *vdwtype;
104     real             *vdwparam;
105     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
106     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
107     __m128           c6grid_00;
108     __m128           c6grid_10;
109     __m128           c6grid_20;
110     __m128           c6grid_30;
111     real             *vdwgridparam;
112     __m128           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
113     __m128           one_half = _mm_set1_ps(0.5);
114     __m128           minus_one = _mm_set1_ps(-1.0);
115     __m128i          ewitab;
116     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
117     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
118     real             *ewtab;
119     __m128           dummy_mask,cutoff_mask;
120     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
121     __m128           one     = _mm_set1_ps(1.0);
122     __m128           two     = _mm_set1_ps(2.0);
123     x                = xx[0];
124     f                = ff[0];
125
126     nri              = nlist->nri;
127     iinr             = nlist->iinr;
128     jindex           = nlist->jindex;
129     jjnr             = nlist->jjnr;
130     shiftidx         = nlist->shift;
131     gid              = nlist->gid;
132     shiftvec         = fr->shift_vec[0];
133     fshift           = fr->fshift[0];
134     facel            = _mm_set1_ps(fr->epsfac);
135     charge           = mdatoms->chargeA;
136     nvdwtype         = fr->ntype;
137     vdwparam         = fr->nbfp;
138     vdwtype          = mdatoms->typeA;
139     vdwgridparam     = fr->ljpme_c6grid;
140     sh_lj_ewald      = _mm_set1_ps(fr->ic->sh_lj_ewald);
141     ewclj            = _mm_set1_ps(fr->ewaldcoeff_lj);
142     ewclj2           = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
143
144     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
145     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
146     beta2            = _mm_mul_ps(beta,beta);
147     beta3            = _mm_mul_ps(beta,beta2);
148     ewtab            = fr->ic->tabq_coul_FDV0;
149     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
150     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
151
152     /* Setup water-specific parameters */
153     inr              = nlist->iinr[0];
154     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
155     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
156     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
157     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
158
159     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
160     rcutoff_scalar   = fr->rcoulomb;
161     rcutoff          = _mm_set1_ps(rcutoff_scalar);
162     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
163
164     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
165     rvdw             = _mm_set1_ps(fr->rvdw);
166
167     /* Avoid stupid compiler warnings */
168     jnrA = jnrB = jnrC = jnrD = 0;
169     j_coord_offsetA = 0;
170     j_coord_offsetB = 0;
171     j_coord_offsetC = 0;
172     j_coord_offsetD = 0;
173
174     outeriter        = 0;
175     inneriter        = 0;
176
177     for(iidx=0;iidx<4*DIM;iidx++)
178     {
179         scratch[iidx] = 0.0;
180     }
181
182     /* Start outer loop over neighborlists */
183     for(iidx=0; iidx<nri; iidx++)
184     {
185         /* Load shift vector for this list */
186         i_shift_offset   = DIM*shiftidx[iidx];
187
188         /* Load limits for loop over neighbors */
189         j_index_start    = jindex[iidx];
190         j_index_end      = jindex[iidx+1];
191
192         /* Get outer coordinate index */
193         inr              = iinr[iidx];
194         i_coord_offset   = DIM*inr;
195
196         /* Load i particle coords and add shift vector */
197         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
198                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
199
200         fix0             = _mm_setzero_ps();
201         fiy0             = _mm_setzero_ps();
202         fiz0             = _mm_setzero_ps();
203         fix1             = _mm_setzero_ps();
204         fiy1             = _mm_setzero_ps();
205         fiz1             = _mm_setzero_ps();
206         fix2             = _mm_setzero_ps();
207         fiy2             = _mm_setzero_ps();
208         fiz2             = _mm_setzero_ps();
209         fix3             = _mm_setzero_ps();
210         fiy3             = _mm_setzero_ps();
211         fiz3             = _mm_setzero_ps();
212
213         /* Reset potential sums */
214         velecsum         = _mm_setzero_ps();
215         vvdwsum          = _mm_setzero_ps();
216
217         /* Start inner kernel loop */
218         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
219         {
220
221             /* Get j neighbor index, and coordinate index */
222             jnrA             = jjnr[jidx];
223             jnrB             = jjnr[jidx+1];
224             jnrC             = jjnr[jidx+2];
225             jnrD             = jjnr[jidx+3];
226             j_coord_offsetA  = DIM*jnrA;
227             j_coord_offsetB  = DIM*jnrB;
228             j_coord_offsetC  = DIM*jnrC;
229             j_coord_offsetD  = DIM*jnrD;
230
231             /* load j atom coordinates */
232             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
233                                               x+j_coord_offsetC,x+j_coord_offsetD,
234                                               &jx0,&jy0,&jz0);
235
236             /* Calculate displacement vector */
237             dx00             = _mm_sub_ps(ix0,jx0);
238             dy00             = _mm_sub_ps(iy0,jy0);
239             dz00             = _mm_sub_ps(iz0,jz0);
240             dx10             = _mm_sub_ps(ix1,jx0);
241             dy10             = _mm_sub_ps(iy1,jy0);
242             dz10             = _mm_sub_ps(iz1,jz0);
243             dx20             = _mm_sub_ps(ix2,jx0);
244             dy20             = _mm_sub_ps(iy2,jy0);
245             dz20             = _mm_sub_ps(iz2,jz0);
246             dx30             = _mm_sub_ps(ix3,jx0);
247             dy30             = _mm_sub_ps(iy3,jy0);
248             dz30             = _mm_sub_ps(iz3,jz0);
249
250             /* Calculate squared distance and things based on it */
251             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
252             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
253             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
254             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
255
256             rinv00           = gmx_mm_invsqrt_ps(rsq00);
257             rinv10           = gmx_mm_invsqrt_ps(rsq10);
258             rinv20           = gmx_mm_invsqrt_ps(rsq20);
259             rinv30           = gmx_mm_invsqrt_ps(rsq30);
260
261             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
262             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
263             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
264             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
265
266             /* Load parameters for j particles */
267             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
268                                                               charge+jnrC+0,charge+jnrD+0);
269             vdwjidx0A        = 2*vdwtype[jnrA+0];
270             vdwjidx0B        = 2*vdwtype[jnrB+0];
271             vdwjidx0C        = 2*vdwtype[jnrC+0];
272             vdwjidx0D        = 2*vdwtype[jnrD+0];
273
274             fjx0             = _mm_setzero_ps();
275             fjy0             = _mm_setzero_ps();
276             fjz0             = _mm_setzero_ps();
277
278             /**************************
279              * CALCULATE INTERACTIONS *
280              **************************/
281
282             if (gmx_mm_any_lt(rsq00,rcutoff2))
283             {
284
285             r00              = _mm_mul_ps(rsq00,rinv00);
286
287             /* Compute parameters for interactions between i and j atoms */
288             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
289                                          vdwparam+vdwioffset0+vdwjidx0B,
290                                          vdwparam+vdwioffset0+vdwjidx0C,
291                                          vdwparam+vdwioffset0+vdwjidx0D,
292                                          &c6_00,&c12_00);
293
294             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
295                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
296                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
297                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
298
299             /* Analytical LJ-PME */
300             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
301             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
302             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
303             exponent         = gmx_simd_exp_r(ewcljrsq);
304             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
305             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
306             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
307             vvdw6            = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
308             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
309             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
310                                           _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
311             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
312             fvdw             = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
313
314             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
315
316             /* Update potential sum for this i atom from the interaction with this j atom. */
317             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
318             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
319
320             fscal            = fvdw;
321
322             fscal            = _mm_and_ps(fscal,cutoff_mask);
323
324              /* Update vectorial force */
325             fix0             = _mm_macc_ps(dx00,fscal,fix0);
326             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
327             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
328
329             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
330             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
331             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
332
333             }
334
335             /**************************
336              * CALCULATE INTERACTIONS *
337              **************************/
338
339             if (gmx_mm_any_lt(rsq10,rcutoff2))
340             {
341
342             r10              = _mm_mul_ps(rsq10,rinv10);
343
344             /* Compute parameters for interactions between i and j atoms */
345             qq10             = _mm_mul_ps(iq1,jq0);
346
347             /* EWALD ELECTROSTATICS */
348
349             /* Analytical PME correction */
350             zeta2            = _mm_mul_ps(beta2,rsq10);
351             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
352             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
353             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
354             felec            = _mm_mul_ps(qq10,felec);
355             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
356             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
357             velec            = _mm_mul_ps(qq10,velec);
358
359             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
360
361             /* Update potential sum for this i atom from the interaction with this j atom. */
362             velec            = _mm_and_ps(velec,cutoff_mask);
363             velecsum         = _mm_add_ps(velecsum,velec);
364
365             fscal            = felec;
366
367             fscal            = _mm_and_ps(fscal,cutoff_mask);
368
369              /* Update vectorial force */
370             fix1             = _mm_macc_ps(dx10,fscal,fix1);
371             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
372             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
373
374             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
375             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
376             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
377
378             }
379
380             /**************************
381              * CALCULATE INTERACTIONS *
382              **************************/
383
384             if (gmx_mm_any_lt(rsq20,rcutoff2))
385             {
386
387             r20              = _mm_mul_ps(rsq20,rinv20);
388
389             /* Compute parameters for interactions between i and j atoms */
390             qq20             = _mm_mul_ps(iq2,jq0);
391
392             /* EWALD ELECTROSTATICS */
393
394             /* Analytical PME correction */
395             zeta2            = _mm_mul_ps(beta2,rsq20);
396             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
397             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
398             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
399             felec            = _mm_mul_ps(qq20,felec);
400             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
401             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
402             velec            = _mm_mul_ps(qq20,velec);
403
404             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
405
406             /* Update potential sum for this i atom from the interaction with this j atom. */
407             velec            = _mm_and_ps(velec,cutoff_mask);
408             velecsum         = _mm_add_ps(velecsum,velec);
409
410             fscal            = felec;
411
412             fscal            = _mm_and_ps(fscal,cutoff_mask);
413
414              /* Update vectorial force */
415             fix2             = _mm_macc_ps(dx20,fscal,fix2);
416             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
417             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
418
419             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
420             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
421             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
422
423             }
424
425             /**************************
426              * CALCULATE INTERACTIONS *
427              **************************/
428
429             if (gmx_mm_any_lt(rsq30,rcutoff2))
430             {
431
432             r30              = _mm_mul_ps(rsq30,rinv30);
433
434             /* Compute parameters for interactions between i and j atoms */
435             qq30             = _mm_mul_ps(iq3,jq0);
436
437             /* EWALD ELECTROSTATICS */
438
439             /* Analytical PME correction */
440             zeta2            = _mm_mul_ps(beta2,rsq30);
441             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
442             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
443             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
444             felec            = _mm_mul_ps(qq30,felec);
445             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
446             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
447             velec            = _mm_mul_ps(qq30,velec);
448
449             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
450
451             /* Update potential sum for this i atom from the interaction with this j atom. */
452             velec            = _mm_and_ps(velec,cutoff_mask);
453             velecsum         = _mm_add_ps(velecsum,velec);
454
455             fscal            = felec;
456
457             fscal            = _mm_and_ps(fscal,cutoff_mask);
458
459              /* Update vectorial force */
460             fix3             = _mm_macc_ps(dx30,fscal,fix3);
461             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
462             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
463
464             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
465             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
466             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
467
468             }
469
470             fjptrA             = f+j_coord_offsetA;
471             fjptrB             = f+j_coord_offsetB;
472             fjptrC             = f+j_coord_offsetC;
473             fjptrD             = f+j_coord_offsetD;
474
475             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
476
477             /* Inner loop uses 158 flops */
478         }
479
480         if(jidx<j_index_end)
481         {
482
483             /* Get j neighbor index, and coordinate index */
484             jnrlistA         = jjnr[jidx];
485             jnrlistB         = jjnr[jidx+1];
486             jnrlistC         = jjnr[jidx+2];
487             jnrlistD         = jjnr[jidx+3];
488             /* Sign of each element will be negative for non-real atoms.
489              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
490              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
491              */
492             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
493             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
494             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
495             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
496             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
497             j_coord_offsetA  = DIM*jnrA;
498             j_coord_offsetB  = DIM*jnrB;
499             j_coord_offsetC  = DIM*jnrC;
500             j_coord_offsetD  = DIM*jnrD;
501
502             /* load j atom coordinates */
503             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
504                                               x+j_coord_offsetC,x+j_coord_offsetD,
505                                               &jx0,&jy0,&jz0);
506
507             /* Calculate displacement vector */
508             dx00             = _mm_sub_ps(ix0,jx0);
509             dy00             = _mm_sub_ps(iy0,jy0);
510             dz00             = _mm_sub_ps(iz0,jz0);
511             dx10             = _mm_sub_ps(ix1,jx0);
512             dy10             = _mm_sub_ps(iy1,jy0);
513             dz10             = _mm_sub_ps(iz1,jz0);
514             dx20             = _mm_sub_ps(ix2,jx0);
515             dy20             = _mm_sub_ps(iy2,jy0);
516             dz20             = _mm_sub_ps(iz2,jz0);
517             dx30             = _mm_sub_ps(ix3,jx0);
518             dy30             = _mm_sub_ps(iy3,jy0);
519             dz30             = _mm_sub_ps(iz3,jz0);
520
521             /* Calculate squared distance and things based on it */
522             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
523             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
524             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
525             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
526
527             rinv00           = gmx_mm_invsqrt_ps(rsq00);
528             rinv10           = gmx_mm_invsqrt_ps(rsq10);
529             rinv20           = gmx_mm_invsqrt_ps(rsq20);
530             rinv30           = gmx_mm_invsqrt_ps(rsq30);
531
532             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
533             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
534             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
535             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
536
537             /* Load parameters for j particles */
538             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
539                                                               charge+jnrC+0,charge+jnrD+0);
540             vdwjidx0A        = 2*vdwtype[jnrA+0];
541             vdwjidx0B        = 2*vdwtype[jnrB+0];
542             vdwjidx0C        = 2*vdwtype[jnrC+0];
543             vdwjidx0D        = 2*vdwtype[jnrD+0];
544
545             fjx0             = _mm_setzero_ps();
546             fjy0             = _mm_setzero_ps();
547             fjz0             = _mm_setzero_ps();
548
549             /**************************
550              * CALCULATE INTERACTIONS *
551              **************************/
552
553             if (gmx_mm_any_lt(rsq00,rcutoff2))
554             {
555
556             r00              = _mm_mul_ps(rsq00,rinv00);
557             r00              = _mm_andnot_ps(dummy_mask,r00);
558
559             /* Compute parameters for interactions between i and j atoms */
560             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
561                                          vdwparam+vdwioffset0+vdwjidx0B,
562                                          vdwparam+vdwioffset0+vdwjidx0C,
563                                          vdwparam+vdwioffset0+vdwjidx0D,
564                                          &c6_00,&c12_00);
565
566             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
567                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
568                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
569                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
570
571             /* Analytical LJ-PME */
572             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
573             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
574             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
575             exponent         = gmx_simd_exp_r(ewcljrsq);
576             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
577             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
578             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
579             vvdw6            = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
580             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
581             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
582                                           _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
583             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
584             fvdw             = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
585
586             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
587
588             /* Update potential sum for this i atom from the interaction with this j atom. */
589             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
590             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
591             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
592
593             fscal            = fvdw;
594
595             fscal            = _mm_and_ps(fscal,cutoff_mask);
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             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
605             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
606             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
607
608             }
609
610             /**************************
611              * CALCULATE INTERACTIONS *
612              **************************/
613
614             if (gmx_mm_any_lt(rsq10,rcutoff2))
615             {
616
617             r10              = _mm_mul_ps(rsq10,rinv10);
618             r10              = _mm_andnot_ps(dummy_mask,r10);
619
620             /* Compute parameters for interactions between i and j atoms */
621             qq10             = _mm_mul_ps(iq1,jq0);
622
623             /* EWALD ELECTROSTATICS */
624
625             /* Analytical PME correction */
626             zeta2            = _mm_mul_ps(beta2,rsq10);
627             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
628             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
629             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
630             felec            = _mm_mul_ps(qq10,felec);
631             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
632             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
633             velec            = _mm_mul_ps(qq10,velec);
634
635             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
636
637             /* Update potential sum for this i atom from the interaction with this j atom. */
638             velec            = _mm_and_ps(velec,cutoff_mask);
639             velec            = _mm_andnot_ps(dummy_mask,velec);
640             velecsum         = _mm_add_ps(velecsum,velec);
641
642             fscal            = felec;
643
644             fscal            = _mm_and_ps(fscal,cutoff_mask);
645
646             fscal            = _mm_andnot_ps(dummy_mask,fscal);
647
648              /* Update vectorial force */
649             fix1             = _mm_macc_ps(dx10,fscal,fix1);
650             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
651             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
652
653             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
654             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
655             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
656
657             }
658
659             /**************************
660              * CALCULATE INTERACTIONS *
661              **************************/
662
663             if (gmx_mm_any_lt(rsq20,rcutoff2))
664             {
665
666             r20              = _mm_mul_ps(rsq20,rinv20);
667             r20              = _mm_andnot_ps(dummy_mask,r20);
668
669             /* Compute parameters for interactions between i and j atoms */
670             qq20             = _mm_mul_ps(iq2,jq0);
671
672             /* EWALD ELECTROSTATICS */
673
674             /* Analytical PME correction */
675             zeta2            = _mm_mul_ps(beta2,rsq20);
676             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
677             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
678             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
679             felec            = _mm_mul_ps(qq20,felec);
680             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
681             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
682             velec            = _mm_mul_ps(qq20,velec);
683
684             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
685
686             /* Update potential sum for this i atom from the interaction with this j atom. */
687             velec            = _mm_and_ps(velec,cutoff_mask);
688             velec            = _mm_andnot_ps(dummy_mask,velec);
689             velecsum         = _mm_add_ps(velecsum,velec);
690
691             fscal            = felec;
692
693             fscal            = _mm_and_ps(fscal,cutoff_mask);
694
695             fscal            = _mm_andnot_ps(dummy_mask,fscal);
696
697              /* Update vectorial force */
698             fix2             = _mm_macc_ps(dx20,fscal,fix2);
699             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
700             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
701
702             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
703             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
704             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
705
706             }
707
708             /**************************
709              * CALCULATE INTERACTIONS *
710              **************************/
711
712             if (gmx_mm_any_lt(rsq30,rcutoff2))
713             {
714
715             r30              = _mm_mul_ps(rsq30,rinv30);
716             r30              = _mm_andnot_ps(dummy_mask,r30);
717
718             /* Compute parameters for interactions between i and j atoms */
719             qq30             = _mm_mul_ps(iq3,jq0);
720
721             /* EWALD ELECTROSTATICS */
722
723             /* Analytical PME correction */
724             zeta2            = _mm_mul_ps(beta2,rsq30);
725             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
726             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
727             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
728             felec            = _mm_mul_ps(qq30,felec);
729             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
730             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
731             velec            = _mm_mul_ps(qq30,velec);
732
733             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
734
735             /* Update potential sum for this i atom from the interaction with this j atom. */
736             velec            = _mm_and_ps(velec,cutoff_mask);
737             velec            = _mm_andnot_ps(dummy_mask,velec);
738             velecsum         = _mm_add_ps(velecsum,velec);
739
740             fscal            = felec;
741
742             fscal            = _mm_and_ps(fscal,cutoff_mask);
743
744             fscal            = _mm_andnot_ps(dummy_mask,fscal);
745
746              /* Update vectorial force */
747             fix3             = _mm_macc_ps(dx30,fscal,fix3);
748             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
749             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
750
751             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
752             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
753             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
754
755             }
756
757             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
758             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
759             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
760             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
761
762             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
763
764             /* Inner loop uses 162 flops */
765         }
766
767         /* End of innermost loop */
768
769         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
770                                               f+i_coord_offset,fshift+i_shift_offset);
771
772         ggid                        = gid[iidx];
773         /* Update potential energies */
774         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
775         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
776
777         /* Increment number of inner iterations */
778         inneriter                  += j_index_end - j_index_start;
779
780         /* Outer loop uses 26 flops */
781     }
782
783     /* Increment number of outer iterations */
784     outeriter        += nri;
785
786     /* Update outer/inner flops */
787
788     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*162);
789 }
790 /*
791  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
792  * Electrostatics interaction: Ewald
793  * VdW interaction:            LJEwald
794  * Geometry:                   Water4-Particle
795  * Calculate force/pot:        Force
796  */
797 void
798 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
799                     (t_nblist                    * gmx_restrict       nlist,
800                      rvec                        * gmx_restrict          xx,
801                      rvec                        * gmx_restrict          ff,
802                      t_forcerec                  * gmx_restrict          fr,
803                      t_mdatoms                   * gmx_restrict     mdatoms,
804                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
805                      t_nrnb                      * gmx_restrict        nrnb)
806 {
807     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
808      * just 0 for non-waters.
809      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
810      * jnr indices corresponding to data put in the four positions in the SIMD register.
811      */
812     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
813     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
814     int              jnrA,jnrB,jnrC,jnrD;
815     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
816     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
817     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
818     real             rcutoff_scalar;
819     real             *shiftvec,*fshift,*x,*f;
820     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
821     real             scratch[4*DIM];
822     __m128           fscal,rcutoff,rcutoff2,jidxall;
823     int              vdwioffset0;
824     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
825     int              vdwioffset1;
826     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
827     int              vdwioffset2;
828     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
829     int              vdwioffset3;
830     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
831     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
832     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
833     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
834     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
835     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
836     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
837     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
838     real             *charge;
839     int              nvdwtype;
840     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
841     int              *vdwtype;
842     real             *vdwparam;
843     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
844     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
845     __m128           c6grid_00;
846     __m128           c6grid_10;
847     __m128           c6grid_20;
848     __m128           c6grid_30;
849     real             *vdwgridparam;
850     __m128           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
851     __m128           one_half = _mm_set1_ps(0.5);
852     __m128           minus_one = _mm_set1_ps(-1.0);
853     __m128i          ewitab;
854     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
855     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
856     real             *ewtab;
857     __m128           dummy_mask,cutoff_mask;
858     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
859     __m128           one     = _mm_set1_ps(1.0);
860     __m128           two     = _mm_set1_ps(2.0);
861     x                = xx[0];
862     f                = ff[0];
863
864     nri              = nlist->nri;
865     iinr             = nlist->iinr;
866     jindex           = nlist->jindex;
867     jjnr             = nlist->jjnr;
868     shiftidx         = nlist->shift;
869     gid              = nlist->gid;
870     shiftvec         = fr->shift_vec[0];
871     fshift           = fr->fshift[0];
872     facel            = _mm_set1_ps(fr->epsfac);
873     charge           = mdatoms->chargeA;
874     nvdwtype         = fr->ntype;
875     vdwparam         = fr->nbfp;
876     vdwtype          = mdatoms->typeA;
877     vdwgridparam     = fr->ljpme_c6grid;
878     sh_lj_ewald      = _mm_set1_ps(fr->ic->sh_lj_ewald);
879     ewclj            = _mm_set1_ps(fr->ewaldcoeff_lj);
880     ewclj2           = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
881
882     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
883     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
884     beta2            = _mm_mul_ps(beta,beta);
885     beta3            = _mm_mul_ps(beta,beta2);
886     ewtab            = fr->ic->tabq_coul_F;
887     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
888     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
889
890     /* Setup water-specific parameters */
891     inr              = nlist->iinr[0];
892     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
893     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
894     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
895     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
896
897     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
898     rcutoff_scalar   = fr->rcoulomb;
899     rcutoff          = _mm_set1_ps(rcutoff_scalar);
900     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
901
902     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
903     rvdw             = _mm_set1_ps(fr->rvdw);
904
905     /* Avoid stupid compiler warnings */
906     jnrA = jnrB = jnrC = jnrD = 0;
907     j_coord_offsetA = 0;
908     j_coord_offsetB = 0;
909     j_coord_offsetC = 0;
910     j_coord_offsetD = 0;
911
912     outeriter        = 0;
913     inneriter        = 0;
914
915     for(iidx=0;iidx<4*DIM;iidx++)
916     {
917         scratch[iidx] = 0.0;
918     }
919
920     /* Start outer loop over neighborlists */
921     for(iidx=0; iidx<nri; iidx++)
922     {
923         /* Load shift vector for this list */
924         i_shift_offset   = DIM*shiftidx[iidx];
925
926         /* Load limits for loop over neighbors */
927         j_index_start    = jindex[iidx];
928         j_index_end      = jindex[iidx+1];
929
930         /* Get outer coordinate index */
931         inr              = iinr[iidx];
932         i_coord_offset   = DIM*inr;
933
934         /* Load i particle coords and add shift vector */
935         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
936                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
937
938         fix0             = _mm_setzero_ps();
939         fiy0             = _mm_setzero_ps();
940         fiz0             = _mm_setzero_ps();
941         fix1             = _mm_setzero_ps();
942         fiy1             = _mm_setzero_ps();
943         fiz1             = _mm_setzero_ps();
944         fix2             = _mm_setzero_ps();
945         fiy2             = _mm_setzero_ps();
946         fiz2             = _mm_setzero_ps();
947         fix3             = _mm_setzero_ps();
948         fiy3             = _mm_setzero_ps();
949         fiz3             = _mm_setzero_ps();
950
951         /* Start inner kernel loop */
952         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
953         {
954
955             /* Get j neighbor index, and coordinate index */
956             jnrA             = jjnr[jidx];
957             jnrB             = jjnr[jidx+1];
958             jnrC             = jjnr[jidx+2];
959             jnrD             = jjnr[jidx+3];
960             j_coord_offsetA  = DIM*jnrA;
961             j_coord_offsetB  = DIM*jnrB;
962             j_coord_offsetC  = DIM*jnrC;
963             j_coord_offsetD  = DIM*jnrD;
964
965             /* load j atom coordinates */
966             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
967                                               x+j_coord_offsetC,x+j_coord_offsetD,
968                                               &jx0,&jy0,&jz0);
969
970             /* Calculate displacement vector */
971             dx00             = _mm_sub_ps(ix0,jx0);
972             dy00             = _mm_sub_ps(iy0,jy0);
973             dz00             = _mm_sub_ps(iz0,jz0);
974             dx10             = _mm_sub_ps(ix1,jx0);
975             dy10             = _mm_sub_ps(iy1,jy0);
976             dz10             = _mm_sub_ps(iz1,jz0);
977             dx20             = _mm_sub_ps(ix2,jx0);
978             dy20             = _mm_sub_ps(iy2,jy0);
979             dz20             = _mm_sub_ps(iz2,jz0);
980             dx30             = _mm_sub_ps(ix3,jx0);
981             dy30             = _mm_sub_ps(iy3,jy0);
982             dz30             = _mm_sub_ps(iz3,jz0);
983
984             /* Calculate squared distance and things based on it */
985             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
986             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
987             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
988             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
989
990             rinv00           = gmx_mm_invsqrt_ps(rsq00);
991             rinv10           = gmx_mm_invsqrt_ps(rsq10);
992             rinv20           = gmx_mm_invsqrt_ps(rsq20);
993             rinv30           = gmx_mm_invsqrt_ps(rsq30);
994
995             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
996             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
997             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
998             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
999
1000             /* Load parameters for j particles */
1001             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1002                                                               charge+jnrC+0,charge+jnrD+0);
1003             vdwjidx0A        = 2*vdwtype[jnrA+0];
1004             vdwjidx0B        = 2*vdwtype[jnrB+0];
1005             vdwjidx0C        = 2*vdwtype[jnrC+0];
1006             vdwjidx0D        = 2*vdwtype[jnrD+0];
1007
1008             fjx0             = _mm_setzero_ps();
1009             fjy0             = _mm_setzero_ps();
1010             fjz0             = _mm_setzero_ps();
1011
1012             /**************************
1013              * CALCULATE INTERACTIONS *
1014              **************************/
1015
1016             if (gmx_mm_any_lt(rsq00,rcutoff2))
1017             {
1018
1019             r00              = _mm_mul_ps(rsq00,rinv00);
1020
1021             /* Compute parameters for interactions between i and j atoms */
1022             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1023                                          vdwparam+vdwioffset0+vdwjidx0B,
1024                                          vdwparam+vdwioffset0+vdwjidx0C,
1025                                          vdwparam+vdwioffset0+vdwjidx0D,
1026                                          &c6_00,&c12_00);
1027
1028             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1029                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
1030                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
1031                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
1032
1033             /* Analytical LJ-PME */
1034             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1035             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
1036             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1037             exponent         = gmx_simd_exp_r(ewcljrsq);
1038             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1039             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1040             /* f6A = 6 * C6grid * (1 - poly) */
1041             f6A              = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1042             /* f6B = C6grid * exponent * beta^6 */
1043             f6B              = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1044             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1045             fvdw              = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1046
1047             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1048
1049             fscal            = fvdw;
1050
1051             fscal            = _mm_and_ps(fscal,cutoff_mask);
1052
1053              /* Update vectorial force */
1054             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1055             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1056             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1057
1058             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1059             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1060             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1061
1062             }
1063
1064             /**************************
1065              * CALCULATE INTERACTIONS *
1066              **************************/
1067
1068             if (gmx_mm_any_lt(rsq10,rcutoff2))
1069             {
1070
1071             r10              = _mm_mul_ps(rsq10,rinv10);
1072
1073             /* Compute parameters for interactions between i and j atoms */
1074             qq10             = _mm_mul_ps(iq1,jq0);
1075
1076             /* EWALD ELECTROSTATICS */
1077
1078             /* Analytical PME correction */
1079             zeta2            = _mm_mul_ps(beta2,rsq10);
1080             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1081             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1082             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1083             felec            = _mm_mul_ps(qq10,felec);
1084
1085             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1086
1087             fscal            = felec;
1088
1089             fscal            = _mm_and_ps(fscal,cutoff_mask);
1090
1091              /* Update vectorial force */
1092             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1093             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1094             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1095
1096             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1097             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1098             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1099
1100             }
1101
1102             /**************************
1103              * CALCULATE INTERACTIONS *
1104              **************************/
1105
1106             if (gmx_mm_any_lt(rsq20,rcutoff2))
1107             {
1108
1109             r20              = _mm_mul_ps(rsq20,rinv20);
1110
1111             /* Compute parameters for interactions between i and j atoms */
1112             qq20             = _mm_mul_ps(iq2,jq0);
1113
1114             /* EWALD ELECTROSTATICS */
1115
1116             /* Analytical PME correction */
1117             zeta2            = _mm_mul_ps(beta2,rsq20);
1118             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1119             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1120             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1121             felec            = _mm_mul_ps(qq20,felec);
1122
1123             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1124
1125             fscal            = felec;
1126
1127             fscal            = _mm_and_ps(fscal,cutoff_mask);
1128
1129              /* Update vectorial force */
1130             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1131             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1132             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1133
1134             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1135             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1136             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1137
1138             }
1139
1140             /**************************
1141              * CALCULATE INTERACTIONS *
1142              **************************/
1143
1144             if (gmx_mm_any_lt(rsq30,rcutoff2))
1145             {
1146
1147             r30              = _mm_mul_ps(rsq30,rinv30);
1148
1149             /* Compute parameters for interactions between i and j atoms */
1150             qq30             = _mm_mul_ps(iq3,jq0);
1151
1152             /* EWALD ELECTROSTATICS */
1153
1154             /* Analytical PME correction */
1155             zeta2            = _mm_mul_ps(beta2,rsq30);
1156             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
1157             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1158             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1159             felec            = _mm_mul_ps(qq30,felec);
1160
1161             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1162
1163             fscal            = felec;
1164
1165             fscal            = _mm_and_ps(fscal,cutoff_mask);
1166
1167              /* Update vectorial force */
1168             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1169             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1170             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1171
1172             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1173             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1174             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1175
1176             }
1177
1178             fjptrA             = f+j_coord_offsetA;
1179             fjptrB             = f+j_coord_offsetB;
1180             fjptrC             = f+j_coord_offsetC;
1181             fjptrD             = f+j_coord_offsetD;
1182
1183             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1184
1185             /* Inner loop uses 143 flops */
1186         }
1187
1188         if(jidx<j_index_end)
1189         {
1190
1191             /* Get j neighbor index, and coordinate index */
1192             jnrlistA         = jjnr[jidx];
1193             jnrlistB         = jjnr[jidx+1];
1194             jnrlistC         = jjnr[jidx+2];
1195             jnrlistD         = jjnr[jidx+3];
1196             /* Sign of each element will be negative for non-real atoms.
1197              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1198              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1199              */
1200             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1201             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1202             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1203             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1204             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1205             j_coord_offsetA  = DIM*jnrA;
1206             j_coord_offsetB  = DIM*jnrB;
1207             j_coord_offsetC  = DIM*jnrC;
1208             j_coord_offsetD  = DIM*jnrD;
1209
1210             /* load j atom coordinates */
1211             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1212                                               x+j_coord_offsetC,x+j_coord_offsetD,
1213                                               &jx0,&jy0,&jz0);
1214
1215             /* Calculate displacement vector */
1216             dx00             = _mm_sub_ps(ix0,jx0);
1217             dy00             = _mm_sub_ps(iy0,jy0);
1218             dz00             = _mm_sub_ps(iz0,jz0);
1219             dx10             = _mm_sub_ps(ix1,jx0);
1220             dy10             = _mm_sub_ps(iy1,jy0);
1221             dz10             = _mm_sub_ps(iz1,jz0);
1222             dx20             = _mm_sub_ps(ix2,jx0);
1223             dy20             = _mm_sub_ps(iy2,jy0);
1224             dz20             = _mm_sub_ps(iz2,jz0);
1225             dx30             = _mm_sub_ps(ix3,jx0);
1226             dy30             = _mm_sub_ps(iy3,jy0);
1227             dz30             = _mm_sub_ps(iz3,jz0);
1228
1229             /* Calculate squared distance and things based on it */
1230             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1231             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1232             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1233             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1234
1235             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1236             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1237             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1238             rinv30           = gmx_mm_invsqrt_ps(rsq30);
1239
1240             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1241             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1242             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1243             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1244
1245             /* Load parameters for j particles */
1246             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1247                                                               charge+jnrC+0,charge+jnrD+0);
1248             vdwjidx0A        = 2*vdwtype[jnrA+0];
1249             vdwjidx0B        = 2*vdwtype[jnrB+0];
1250             vdwjidx0C        = 2*vdwtype[jnrC+0];
1251             vdwjidx0D        = 2*vdwtype[jnrD+0];
1252
1253             fjx0             = _mm_setzero_ps();
1254             fjy0             = _mm_setzero_ps();
1255             fjz0             = _mm_setzero_ps();
1256
1257             /**************************
1258              * CALCULATE INTERACTIONS *
1259              **************************/
1260
1261             if (gmx_mm_any_lt(rsq00,rcutoff2))
1262             {
1263
1264             r00              = _mm_mul_ps(rsq00,rinv00);
1265             r00              = _mm_andnot_ps(dummy_mask,r00);
1266
1267             /* Compute parameters for interactions between i and j atoms */
1268             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1269                                          vdwparam+vdwioffset0+vdwjidx0B,
1270                                          vdwparam+vdwioffset0+vdwjidx0C,
1271                                          vdwparam+vdwioffset0+vdwjidx0D,
1272                                          &c6_00,&c12_00);
1273
1274             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1275                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
1276                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
1277                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
1278
1279             /* Analytical LJ-PME */
1280             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1281             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
1282             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1283             exponent         = gmx_simd_exp_r(ewcljrsq);
1284             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1285             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1286             /* f6A = 6 * C6grid * (1 - poly) */
1287             f6A              = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1288             /* f6B = C6grid * exponent * beta^6 */
1289             f6B              = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1290             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1291             fvdw              = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1292
1293             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1294
1295             fscal            = fvdw;
1296
1297             fscal            = _mm_and_ps(fscal,cutoff_mask);
1298
1299             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1300
1301              /* Update vectorial force */
1302             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1303             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1304             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1305
1306             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1307             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1308             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1309
1310             }
1311
1312             /**************************
1313              * CALCULATE INTERACTIONS *
1314              **************************/
1315
1316             if (gmx_mm_any_lt(rsq10,rcutoff2))
1317             {
1318
1319             r10              = _mm_mul_ps(rsq10,rinv10);
1320             r10              = _mm_andnot_ps(dummy_mask,r10);
1321
1322             /* Compute parameters for interactions between i and j atoms */
1323             qq10             = _mm_mul_ps(iq1,jq0);
1324
1325             /* EWALD ELECTROSTATICS */
1326
1327             /* Analytical PME correction */
1328             zeta2            = _mm_mul_ps(beta2,rsq10);
1329             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1330             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1331             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1332             felec            = _mm_mul_ps(qq10,felec);
1333
1334             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1335
1336             fscal            = felec;
1337
1338             fscal            = _mm_and_ps(fscal,cutoff_mask);
1339
1340             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1341
1342              /* Update vectorial force */
1343             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1344             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1345             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1346
1347             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1348             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1349             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1350
1351             }
1352
1353             /**************************
1354              * CALCULATE INTERACTIONS *
1355              **************************/
1356
1357             if (gmx_mm_any_lt(rsq20,rcutoff2))
1358             {
1359
1360             r20              = _mm_mul_ps(rsq20,rinv20);
1361             r20              = _mm_andnot_ps(dummy_mask,r20);
1362
1363             /* Compute parameters for interactions between i and j atoms */
1364             qq20             = _mm_mul_ps(iq2,jq0);
1365
1366             /* EWALD ELECTROSTATICS */
1367
1368             /* Analytical PME correction */
1369             zeta2            = _mm_mul_ps(beta2,rsq20);
1370             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1371             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1372             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1373             felec            = _mm_mul_ps(qq20,felec);
1374
1375             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1376
1377             fscal            = felec;
1378
1379             fscal            = _mm_and_ps(fscal,cutoff_mask);
1380
1381             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1382
1383              /* Update vectorial force */
1384             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1385             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1386             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1387
1388             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1389             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1390             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1391
1392             }
1393
1394             /**************************
1395              * CALCULATE INTERACTIONS *
1396              **************************/
1397
1398             if (gmx_mm_any_lt(rsq30,rcutoff2))
1399             {
1400
1401             r30              = _mm_mul_ps(rsq30,rinv30);
1402             r30              = _mm_andnot_ps(dummy_mask,r30);
1403
1404             /* Compute parameters for interactions between i and j atoms */
1405             qq30             = _mm_mul_ps(iq3,jq0);
1406
1407             /* EWALD ELECTROSTATICS */
1408
1409             /* Analytical PME correction */
1410             zeta2            = _mm_mul_ps(beta2,rsq30);
1411             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
1412             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1413             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1414             felec            = _mm_mul_ps(qq30,felec);
1415
1416             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1417
1418             fscal            = felec;
1419
1420             fscal            = _mm_and_ps(fscal,cutoff_mask);
1421
1422             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1423
1424              /* Update vectorial force */
1425             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1426             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1427             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1428
1429             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1430             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1431             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1432
1433             }
1434
1435             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1436             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1437             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1438             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1439
1440             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1441
1442             /* Inner loop uses 147 flops */
1443         }
1444
1445         /* End of innermost loop */
1446
1447         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1448                                               f+i_coord_offset,fshift+i_shift_offset);
1449
1450         /* Increment number of inner iterations */
1451         inneriter                  += j_index_end - j_index_start;
1452
1453         /* Outer loop uses 24 flops */
1454     }
1455
1456     /* Increment number of outer iterations */
1457     outeriter        += nri;
1458
1459     /* Update outer/inner flops */
1460
1461     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*147);
1462 }