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