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