Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEw_VdwLJ_GeomW3P1_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_ElecEw_VdwLJ_GeomW3P1_VF_avx_128_fma_single
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEw_VdwLJ_GeomW3P1_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              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
100     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
101     __m128i          ewitab;
102     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
103     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
104     real             *ewtab;
105     __m128           dummy_mask,cutoff_mask;
106     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107     __m128           one     = _mm_set1_ps(1.0);
108     __m128           two     = _mm_set1_ps(2.0);
109     x                = xx[0];
110     f                = ff[0];
111
112     nri              = nlist->nri;
113     iinr             = nlist->iinr;
114     jindex           = nlist->jindex;
115     jjnr             = nlist->jjnr;
116     shiftidx         = nlist->shift;
117     gid              = nlist->gid;
118     shiftvec         = fr->shift_vec[0];
119     fshift           = fr->fshift[0];
120     facel            = _mm_set1_ps(fr->ic->epsfac);
121     charge           = mdatoms->chargeA;
122     nvdwtype         = fr->ntype;
123     vdwparam         = fr->nbfp;
124     vdwtype          = mdatoms->typeA;
125
126     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
127     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
128     beta2            = _mm_mul_ps(beta,beta);
129     beta3            = _mm_mul_ps(beta,beta2);
130     ewtab            = fr->ic->tabq_coul_FDV0;
131     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
132     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
133
134     /* Setup water-specific parameters */
135     inr              = nlist->iinr[0];
136     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
137     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
138     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
139     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
140
141     /* Avoid stupid compiler warnings */
142     jnrA = jnrB = jnrC = jnrD = 0;
143     j_coord_offsetA = 0;
144     j_coord_offsetB = 0;
145     j_coord_offsetC = 0;
146     j_coord_offsetD = 0;
147
148     outeriter        = 0;
149     inneriter        = 0;
150
151     for(iidx=0;iidx<4*DIM;iidx++)
152     {
153         scratch[iidx] = 0.0;
154     }
155
156     /* Start outer loop over neighborlists */
157     for(iidx=0; iidx<nri; iidx++)
158     {
159         /* Load shift vector for this list */
160         i_shift_offset   = DIM*shiftidx[iidx];
161
162         /* Load limits for loop over neighbors */
163         j_index_start    = jindex[iidx];
164         j_index_end      = jindex[iidx+1];
165
166         /* Get outer coordinate index */
167         inr              = iinr[iidx];
168         i_coord_offset   = DIM*inr;
169
170         /* Load i particle coords and add shift vector */
171         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
172                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
173
174         fix0             = _mm_setzero_ps();
175         fiy0             = _mm_setzero_ps();
176         fiz0             = _mm_setzero_ps();
177         fix1             = _mm_setzero_ps();
178         fiy1             = _mm_setzero_ps();
179         fiz1             = _mm_setzero_ps();
180         fix2             = _mm_setzero_ps();
181         fiy2             = _mm_setzero_ps();
182         fiz2             = _mm_setzero_ps();
183
184         /* Reset potential sums */
185         velecsum         = _mm_setzero_ps();
186         vvdwsum          = _mm_setzero_ps();
187
188         /* Start inner kernel loop */
189         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
190         {
191
192             /* Get j neighbor index, and coordinate index */
193             jnrA             = jjnr[jidx];
194             jnrB             = jjnr[jidx+1];
195             jnrC             = jjnr[jidx+2];
196             jnrD             = jjnr[jidx+3];
197             j_coord_offsetA  = DIM*jnrA;
198             j_coord_offsetB  = DIM*jnrB;
199             j_coord_offsetC  = DIM*jnrC;
200             j_coord_offsetD  = DIM*jnrD;
201
202             /* load j atom coordinates */
203             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
204                                               x+j_coord_offsetC,x+j_coord_offsetD,
205                                               &jx0,&jy0,&jz0);
206
207             /* Calculate displacement vector */
208             dx00             = _mm_sub_ps(ix0,jx0);
209             dy00             = _mm_sub_ps(iy0,jy0);
210             dz00             = _mm_sub_ps(iz0,jz0);
211             dx10             = _mm_sub_ps(ix1,jx0);
212             dy10             = _mm_sub_ps(iy1,jy0);
213             dz10             = _mm_sub_ps(iz1,jz0);
214             dx20             = _mm_sub_ps(ix2,jx0);
215             dy20             = _mm_sub_ps(iy2,jy0);
216             dz20             = _mm_sub_ps(iz2,jz0);
217
218             /* Calculate squared distance and things based on it */
219             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
220             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
221             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
222
223             rinv00           = avx128fma_invsqrt_f(rsq00);
224             rinv10           = avx128fma_invsqrt_f(rsq10);
225             rinv20           = avx128fma_invsqrt_f(rsq20);
226
227             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
228             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
229             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
230
231             /* Load parameters for j particles */
232             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
233                                                               charge+jnrC+0,charge+jnrD+0);
234             vdwjidx0A        = 2*vdwtype[jnrA+0];
235             vdwjidx0B        = 2*vdwtype[jnrB+0];
236             vdwjidx0C        = 2*vdwtype[jnrC+0];
237             vdwjidx0D        = 2*vdwtype[jnrD+0];
238
239             fjx0             = _mm_setzero_ps();
240             fjy0             = _mm_setzero_ps();
241             fjz0             = _mm_setzero_ps();
242
243             /**************************
244              * CALCULATE INTERACTIONS *
245              **************************/
246
247             r00              = _mm_mul_ps(rsq00,rinv00);
248
249             /* Compute parameters for interactions between i and j atoms */
250             qq00             = _mm_mul_ps(iq0,jq0);
251             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
252                                          vdwparam+vdwioffset0+vdwjidx0B,
253                                          vdwparam+vdwioffset0+vdwjidx0C,
254                                          vdwparam+vdwioffset0+vdwjidx0D,
255                                          &c6_00,&c12_00);
256
257             /* EWALD ELECTROSTATICS */
258
259             /* Analytical PME correction */
260             zeta2            = _mm_mul_ps(beta2,rsq00);
261             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
262             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
263             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
264             felec            = _mm_mul_ps(qq00,felec);
265             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
266             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv00);
267             velec            = _mm_mul_ps(qq00,velec);
268
269             /* LENNARD-JONES DISPERSION/REPULSION */
270
271             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
272             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
273             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
274             vvdw             = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
275             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
276
277             /* Update potential sum for this i atom from the interaction with this j atom. */
278             velecsum         = _mm_add_ps(velecsum,velec);
279             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
280
281             fscal            = _mm_add_ps(felec,fvdw);
282
283              /* Update vectorial force */
284             fix0             = _mm_macc_ps(dx00,fscal,fix0);
285             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
286             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
287
288             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
289             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
290             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
291
292             /**************************
293              * CALCULATE INTERACTIONS *
294              **************************/
295
296             r10              = _mm_mul_ps(rsq10,rinv10);
297
298             /* Compute parameters for interactions between i and j atoms */
299             qq10             = _mm_mul_ps(iq1,jq0);
300
301             /* EWALD ELECTROSTATICS */
302
303             /* Analytical PME correction */
304             zeta2            = _mm_mul_ps(beta2,rsq10);
305             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
306             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
307             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
308             felec            = _mm_mul_ps(qq10,felec);
309             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
310             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv10);
311             velec            = _mm_mul_ps(qq10,velec);
312
313             /* Update potential sum for this i atom from the interaction with this j atom. */
314             velecsum         = _mm_add_ps(velecsum,velec);
315
316             fscal            = felec;
317
318              /* Update vectorial force */
319             fix1             = _mm_macc_ps(dx10,fscal,fix1);
320             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
321             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
322
323             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
324             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
325             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
326
327             /**************************
328              * CALCULATE INTERACTIONS *
329              **************************/
330
331             r20              = _mm_mul_ps(rsq20,rinv20);
332
333             /* Compute parameters for interactions between i and j atoms */
334             qq20             = _mm_mul_ps(iq2,jq0);
335
336             /* EWALD ELECTROSTATICS */
337
338             /* Analytical PME correction */
339             zeta2            = _mm_mul_ps(beta2,rsq20);
340             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
341             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
342             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
343             felec            = _mm_mul_ps(qq20,felec);
344             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
345             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv20);
346             velec            = _mm_mul_ps(qq20,velec);
347
348             /* Update potential sum for this i atom from the interaction with this j atom. */
349             velecsum         = _mm_add_ps(velecsum,velec);
350
351             fscal            = felec;
352
353              /* Update vectorial force */
354             fix2             = _mm_macc_ps(dx20,fscal,fix2);
355             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
356             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
357
358             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
359             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
360             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
361
362             fjptrA             = f+j_coord_offsetA;
363             fjptrB             = f+j_coord_offsetB;
364             fjptrC             = f+j_coord_offsetC;
365             fjptrD             = f+j_coord_offsetD;
366
367             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
368
369             /* Inner loop uses 99 flops */
370         }
371
372         if(jidx<j_index_end)
373         {
374
375             /* Get j neighbor index, and coordinate index */
376             jnrlistA         = jjnr[jidx];
377             jnrlistB         = jjnr[jidx+1];
378             jnrlistC         = jjnr[jidx+2];
379             jnrlistD         = jjnr[jidx+3];
380             /* Sign of each element will be negative for non-real atoms.
381              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
382              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
383              */
384             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
385             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
386             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
387             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
388             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
389             j_coord_offsetA  = DIM*jnrA;
390             j_coord_offsetB  = DIM*jnrB;
391             j_coord_offsetC  = DIM*jnrC;
392             j_coord_offsetD  = DIM*jnrD;
393
394             /* load j atom coordinates */
395             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
396                                               x+j_coord_offsetC,x+j_coord_offsetD,
397                                               &jx0,&jy0,&jz0);
398
399             /* Calculate displacement vector */
400             dx00             = _mm_sub_ps(ix0,jx0);
401             dy00             = _mm_sub_ps(iy0,jy0);
402             dz00             = _mm_sub_ps(iz0,jz0);
403             dx10             = _mm_sub_ps(ix1,jx0);
404             dy10             = _mm_sub_ps(iy1,jy0);
405             dz10             = _mm_sub_ps(iz1,jz0);
406             dx20             = _mm_sub_ps(ix2,jx0);
407             dy20             = _mm_sub_ps(iy2,jy0);
408             dz20             = _mm_sub_ps(iz2,jz0);
409
410             /* Calculate squared distance and things based on it */
411             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
412             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
413             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
414
415             rinv00           = avx128fma_invsqrt_f(rsq00);
416             rinv10           = avx128fma_invsqrt_f(rsq10);
417             rinv20           = avx128fma_invsqrt_f(rsq20);
418
419             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
420             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
421             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
422
423             /* Load parameters for j particles */
424             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
425                                                               charge+jnrC+0,charge+jnrD+0);
426             vdwjidx0A        = 2*vdwtype[jnrA+0];
427             vdwjidx0B        = 2*vdwtype[jnrB+0];
428             vdwjidx0C        = 2*vdwtype[jnrC+0];
429             vdwjidx0D        = 2*vdwtype[jnrD+0];
430
431             fjx0             = _mm_setzero_ps();
432             fjy0             = _mm_setzero_ps();
433             fjz0             = _mm_setzero_ps();
434
435             /**************************
436              * CALCULATE INTERACTIONS *
437              **************************/
438
439             r00              = _mm_mul_ps(rsq00,rinv00);
440             r00              = _mm_andnot_ps(dummy_mask,r00);
441
442             /* Compute parameters for interactions between i and j atoms */
443             qq00             = _mm_mul_ps(iq0,jq0);
444             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
445                                          vdwparam+vdwioffset0+vdwjidx0B,
446                                          vdwparam+vdwioffset0+vdwjidx0C,
447                                          vdwparam+vdwioffset0+vdwjidx0D,
448                                          &c6_00,&c12_00);
449
450             /* EWALD ELECTROSTATICS */
451
452             /* Analytical PME correction */
453             zeta2            = _mm_mul_ps(beta2,rsq00);
454             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
455             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
456             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
457             felec            = _mm_mul_ps(qq00,felec);
458             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
459             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv00);
460             velec            = _mm_mul_ps(qq00,velec);
461
462             /* LENNARD-JONES DISPERSION/REPULSION */
463
464             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
465             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
466             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
467             vvdw             = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
468             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
469
470             /* Update potential sum for this i atom from the interaction with this j atom. */
471             velec            = _mm_andnot_ps(dummy_mask,velec);
472             velecsum         = _mm_add_ps(velecsum,velec);
473             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
474             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
475
476             fscal            = _mm_add_ps(felec,fvdw);
477
478             fscal            = _mm_andnot_ps(dummy_mask,fscal);
479
480              /* Update vectorial force */
481             fix0             = _mm_macc_ps(dx00,fscal,fix0);
482             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
483             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
484
485             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
486             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
487             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
488
489             /**************************
490              * CALCULATE INTERACTIONS *
491              **************************/
492
493             r10              = _mm_mul_ps(rsq10,rinv10);
494             r10              = _mm_andnot_ps(dummy_mask,r10);
495
496             /* Compute parameters for interactions between i and j atoms */
497             qq10             = _mm_mul_ps(iq1,jq0);
498
499             /* EWALD ELECTROSTATICS */
500
501             /* Analytical PME correction */
502             zeta2            = _mm_mul_ps(beta2,rsq10);
503             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
504             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
505             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
506             felec            = _mm_mul_ps(qq10,felec);
507             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
508             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv10);
509             velec            = _mm_mul_ps(qq10,velec);
510
511             /* Update potential sum for this i atom from the interaction with this j atom. */
512             velec            = _mm_andnot_ps(dummy_mask,velec);
513             velecsum         = _mm_add_ps(velecsum,velec);
514
515             fscal            = felec;
516
517             fscal            = _mm_andnot_ps(dummy_mask,fscal);
518
519              /* Update vectorial force */
520             fix1             = _mm_macc_ps(dx10,fscal,fix1);
521             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
522             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
523
524             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
525             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
526             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
527
528             /**************************
529              * CALCULATE INTERACTIONS *
530              **************************/
531
532             r20              = _mm_mul_ps(rsq20,rinv20);
533             r20              = _mm_andnot_ps(dummy_mask,r20);
534
535             /* Compute parameters for interactions between i and j atoms */
536             qq20             = _mm_mul_ps(iq2,jq0);
537
538             /* EWALD ELECTROSTATICS */
539
540             /* Analytical PME correction */
541             zeta2            = _mm_mul_ps(beta2,rsq20);
542             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
543             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
544             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
545             felec            = _mm_mul_ps(qq20,felec);
546             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
547             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv20);
548             velec            = _mm_mul_ps(qq20,velec);
549
550             /* Update potential sum for this i atom from the interaction with this j atom. */
551             velec            = _mm_andnot_ps(dummy_mask,velec);
552             velecsum         = _mm_add_ps(velecsum,velec);
553
554             fscal            = felec;
555
556             fscal            = _mm_andnot_ps(dummy_mask,fscal);
557
558              /* Update vectorial force */
559             fix2             = _mm_macc_ps(dx20,fscal,fix2);
560             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
561             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
562
563             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
564             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
565             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
566
567             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
568             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
569             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
570             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
571
572             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
573
574             /* Inner loop uses 102 flops */
575         }
576
577         /* End of innermost loop */
578
579         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
580                                               f+i_coord_offset,fshift+i_shift_offset);
581
582         ggid                        = gid[iidx];
583         /* Update potential energies */
584         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
585         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
586
587         /* Increment number of inner iterations */
588         inneriter                  += j_index_end - j_index_start;
589
590         /* Outer loop uses 20 flops */
591     }
592
593     /* Increment number of outer iterations */
594     outeriter        += nri;
595
596     /* Update outer/inner flops */
597
598     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*102);
599 }
600 /*
601  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_avx_128_fma_single
602  * Electrostatics interaction: Ewald
603  * VdW interaction:            LennardJones
604  * Geometry:                   Water3-Particle
605  * Calculate force/pot:        Force
606  */
607 void
608 nb_kernel_ElecEw_VdwLJ_GeomW3P1_F_avx_128_fma_single
609                     (t_nblist                    * gmx_restrict       nlist,
610                      rvec                        * gmx_restrict          xx,
611                      rvec                        * gmx_restrict          ff,
612                      struct t_forcerec           * gmx_restrict          fr,
613                      t_mdatoms                   * gmx_restrict     mdatoms,
614                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
615                      t_nrnb                      * gmx_restrict        nrnb)
616 {
617     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
618      * just 0 for non-waters.
619      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
620      * jnr indices corresponding to data put in the four positions in the SIMD register.
621      */
622     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
623     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
624     int              jnrA,jnrB,jnrC,jnrD;
625     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
626     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
627     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
628     real             rcutoff_scalar;
629     real             *shiftvec,*fshift,*x,*f;
630     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
631     real             scratch[4*DIM];
632     __m128           fscal,rcutoff,rcutoff2,jidxall;
633     int              vdwioffset0;
634     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
635     int              vdwioffset1;
636     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
637     int              vdwioffset2;
638     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
639     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
640     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
641     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
642     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
643     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
644     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
645     real             *charge;
646     int              nvdwtype;
647     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
648     int              *vdwtype;
649     real             *vdwparam;
650     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
651     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
652     __m128i          ewitab;
653     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
654     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
655     real             *ewtab;
656     __m128           dummy_mask,cutoff_mask;
657     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
658     __m128           one     = _mm_set1_ps(1.0);
659     __m128           two     = _mm_set1_ps(2.0);
660     x                = xx[0];
661     f                = ff[0];
662
663     nri              = nlist->nri;
664     iinr             = nlist->iinr;
665     jindex           = nlist->jindex;
666     jjnr             = nlist->jjnr;
667     shiftidx         = nlist->shift;
668     gid              = nlist->gid;
669     shiftvec         = fr->shift_vec[0];
670     fshift           = fr->fshift[0];
671     facel            = _mm_set1_ps(fr->ic->epsfac);
672     charge           = mdatoms->chargeA;
673     nvdwtype         = fr->ntype;
674     vdwparam         = fr->nbfp;
675     vdwtype          = mdatoms->typeA;
676
677     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
678     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
679     beta2            = _mm_mul_ps(beta,beta);
680     beta3            = _mm_mul_ps(beta,beta2);
681     ewtab            = fr->ic->tabq_coul_F;
682     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
683     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
684
685     /* Setup water-specific parameters */
686     inr              = nlist->iinr[0];
687     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
688     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
689     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
690     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
691
692     /* Avoid stupid compiler warnings */
693     jnrA = jnrB = jnrC = jnrD = 0;
694     j_coord_offsetA = 0;
695     j_coord_offsetB = 0;
696     j_coord_offsetC = 0;
697     j_coord_offsetD = 0;
698
699     outeriter        = 0;
700     inneriter        = 0;
701
702     for(iidx=0;iidx<4*DIM;iidx++)
703     {
704         scratch[iidx] = 0.0;
705     }
706
707     /* Start outer loop over neighborlists */
708     for(iidx=0; iidx<nri; iidx++)
709     {
710         /* Load shift vector for this list */
711         i_shift_offset   = DIM*shiftidx[iidx];
712
713         /* Load limits for loop over neighbors */
714         j_index_start    = jindex[iidx];
715         j_index_end      = jindex[iidx+1];
716
717         /* Get outer coordinate index */
718         inr              = iinr[iidx];
719         i_coord_offset   = DIM*inr;
720
721         /* Load i particle coords and add shift vector */
722         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
723                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
724
725         fix0             = _mm_setzero_ps();
726         fiy0             = _mm_setzero_ps();
727         fiz0             = _mm_setzero_ps();
728         fix1             = _mm_setzero_ps();
729         fiy1             = _mm_setzero_ps();
730         fiz1             = _mm_setzero_ps();
731         fix2             = _mm_setzero_ps();
732         fiy2             = _mm_setzero_ps();
733         fiz2             = _mm_setzero_ps();
734
735         /* Start inner kernel loop */
736         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
737         {
738
739             /* Get j neighbor index, and coordinate index */
740             jnrA             = jjnr[jidx];
741             jnrB             = jjnr[jidx+1];
742             jnrC             = jjnr[jidx+2];
743             jnrD             = jjnr[jidx+3];
744             j_coord_offsetA  = DIM*jnrA;
745             j_coord_offsetB  = DIM*jnrB;
746             j_coord_offsetC  = DIM*jnrC;
747             j_coord_offsetD  = DIM*jnrD;
748
749             /* load j atom coordinates */
750             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
751                                               x+j_coord_offsetC,x+j_coord_offsetD,
752                                               &jx0,&jy0,&jz0);
753
754             /* Calculate displacement vector */
755             dx00             = _mm_sub_ps(ix0,jx0);
756             dy00             = _mm_sub_ps(iy0,jy0);
757             dz00             = _mm_sub_ps(iz0,jz0);
758             dx10             = _mm_sub_ps(ix1,jx0);
759             dy10             = _mm_sub_ps(iy1,jy0);
760             dz10             = _mm_sub_ps(iz1,jz0);
761             dx20             = _mm_sub_ps(ix2,jx0);
762             dy20             = _mm_sub_ps(iy2,jy0);
763             dz20             = _mm_sub_ps(iz2,jz0);
764
765             /* Calculate squared distance and things based on it */
766             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
767             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
768             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
769
770             rinv00           = avx128fma_invsqrt_f(rsq00);
771             rinv10           = avx128fma_invsqrt_f(rsq10);
772             rinv20           = avx128fma_invsqrt_f(rsq20);
773
774             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
775             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
776             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
777
778             /* Load parameters for j particles */
779             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
780                                                               charge+jnrC+0,charge+jnrD+0);
781             vdwjidx0A        = 2*vdwtype[jnrA+0];
782             vdwjidx0B        = 2*vdwtype[jnrB+0];
783             vdwjidx0C        = 2*vdwtype[jnrC+0];
784             vdwjidx0D        = 2*vdwtype[jnrD+0];
785
786             fjx0             = _mm_setzero_ps();
787             fjy0             = _mm_setzero_ps();
788             fjz0             = _mm_setzero_ps();
789
790             /**************************
791              * CALCULATE INTERACTIONS *
792              **************************/
793
794             r00              = _mm_mul_ps(rsq00,rinv00);
795
796             /* Compute parameters for interactions between i and j atoms */
797             qq00             = _mm_mul_ps(iq0,jq0);
798             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
799                                          vdwparam+vdwioffset0+vdwjidx0B,
800                                          vdwparam+vdwioffset0+vdwjidx0C,
801                                          vdwparam+vdwioffset0+vdwjidx0D,
802                                          &c6_00,&c12_00);
803
804             /* EWALD ELECTROSTATICS */
805
806             /* Analytical PME correction */
807             zeta2            = _mm_mul_ps(beta2,rsq00);
808             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
809             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
810             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
811             felec            = _mm_mul_ps(qq00,felec);
812
813             /* LENNARD-JONES DISPERSION/REPULSION */
814
815             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
816             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
817
818             fscal            = _mm_add_ps(felec,fvdw);
819
820              /* Update vectorial force */
821             fix0             = _mm_macc_ps(dx00,fscal,fix0);
822             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
823             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
824
825             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
826             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
827             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
828
829             /**************************
830              * CALCULATE INTERACTIONS *
831              **************************/
832
833             r10              = _mm_mul_ps(rsq10,rinv10);
834
835             /* Compute parameters for interactions between i and j atoms */
836             qq10             = _mm_mul_ps(iq1,jq0);
837
838             /* EWALD ELECTROSTATICS */
839
840             /* Analytical PME correction */
841             zeta2            = _mm_mul_ps(beta2,rsq10);
842             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
843             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
844             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
845             felec            = _mm_mul_ps(qq10,felec);
846
847             fscal            = felec;
848
849              /* Update vectorial force */
850             fix1             = _mm_macc_ps(dx10,fscal,fix1);
851             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
852             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
853
854             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
855             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
856             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
857
858             /**************************
859              * CALCULATE INTERACTIONS *
860              **************************/
861
862             r20              = _mm_mul_ps(rsq20,rinv20);
863
864             /* Compute parameters for interactions between i and j atoms */
865             qq20             = _mm_mul_ps(iq2,jq0);
866
867             /* EWALD ELECTROSTATICS */
868
869             /* Analytical PME correction */
870             zeta2            = _mm_mul_ps(beta2,rsq20);
871             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
872             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
873             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
874             felec            = _mm_mul_ps(qq20,felec);
875
876             fscal            = felec;
877
878              /* Update vectorial force */
879             fix2             = _mm_macc_ps(dx20,fscal,fix2);
880             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
881             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
882
883             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
884             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
885             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
886
887             fjptrA             = f+j_coord_offsetA;
888             fjptrB             = f+j_coord_offsetB;
889             fjptrC             = f+j_coord_offsetC;
890             fjptrD             = f+j_coord_offsetD;
891
892             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
893
894             /* Inner loop uses 91 flops */
895         }
896
897         if(jidx<j_index_end)
898         {
899
900             /* Get j neighbor index, and coordinate index */
901             jnrlistA         = jjnr[jidx];
902             jnrlistB         = jjnr[jidx+1];
903             jnrlistC         = jjnr[jidx+2];
904             jnrlistD         = jjnr[jidx+3];
905             /* Sign of each element will be negative for non-real atoms.
906              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
907              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
908              */
909             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
910             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
911             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
912             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
913             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
914             j_coord_offsetA  = DIM*jnrA;
915             j_coord_offsetB  = DIM*jnrB;
916             j_coord_offsetC  = DIM*jnrC;
917             j_coord_offsetD  = DIM*jnrD;
918
919             /* load j atom coordinates */
920             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
921                                               x+j_coord_offsetC,x+j_coord_offsetD,
922                                               &jx0,&jy0,&jz0);
923
924             /* Calculate displacement vector */
925             dx00             = _mm_sub_ps(ix0,jx0);
926             dy00             = _mm_sub_ps(iy0,jy0);
927             dz00             = _mm_sub_ps(iz0,jz0);
928             dx10             = _mm_sub_ps(ix1,jx0);
929             dy10             = _mm_sub_ps(iy1,jy0);
930             dz10             = _mm_sub_ps(iz1,jz0);
931             dx20             = _mm_sub_ps(ix2,jx0);
932             dy20             = _mm_sub_ps(iy2,jy0);
933             dz20             = _mm_sub_ps(iz2,jz0);
934
935             /* Calculate squared distance and things based on it */
936             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
937             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
938             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
939
940             rinv00           = avx128fma_invsqrt_f(rsq00);
941             rinv10           = avx128fma_invsqrt_f(rsq10);
942             rinv20           = avx128fma_invsqrt_f(rsq20);
943
944             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
945             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
946             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
947
948             /* Load parameters for j particles */
949             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
950                                                               charge+jnrC+0,charge+jnrD+0);
951             vdwjidx0A        = 2*vdwtype[jnrA+0];
952             vdwjidx0B        = 2*vdwtype[jnrB+0];
953             vdwjidx0C        = 2*vdwtype[jnrC+0];
954             vdwjidx0D        = 2*vdwtype[jnrD+0];
955
956             fjx0             = _mm_setzero_ps();
957             fjy0             = _mm_setzero_ps();
958             fjz0             = _mm_setzero_ps();
959
960             /**************************
961              * CALCULATE INTERACTIONS *
962              **************************/
963
964             r00              = _mm_mul_ps(rsq00,rinv00);
965             r00              = _mm_andnot_ps(dummy_mask,r00);
966
967             /* Compute parameters for interactions between i and j atoms */
968             qq00             = _mm_mul_ps(iq0,jq0);
969             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
970                                          vdwparam+vdwioffset0+vdwjidx0B,
971                                          vdwparam+vdwioffset0+vdwjidx0C,
972                                          vdwparam+vdwioffset0+vdwjidx0D,
973                                          &c6_00,&c12_00);
974
975             /* EWALD ELECTROSTATICS */
976
977             /* Analytical PME correction */
978             zeta2            = _mm_mul_ps(beta2,rsq00);
979             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
980             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
981             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
982             felec            = _mm_mul_ps(qq00,felec);
983
984             /* LENNARD-JONES DISPERSION/REPULSION */
985
986             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
987             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
988
989             fscal            = _mm_add_ps(felec,fvdw);
990
991             fscal            = _mm_andnot_ps(dummy_mask,fscal);
992
993              /* Update vectorial force */
994             fix0             = _mm_macc_ps(dx00,fscal,fix0);
995             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
996             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
997
998             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
999             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1000             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1001
1002             /**************************
1003              * CALCULATE INTERACTIONS *
1004              **************************/
1005
1006             r10              = _mm_mul_ps(rsq10,rinv10);
1007             r10              = _mm_andnot_ps(dummy_mask,r10);
1008
1009             /* Compute parameters for interactions between i and j atoms */
1010             qq10             = _mm_mul_ps(iq1,jq0);
1011
1012             /* EWALD ELECTROSTATICS */
1013
1014             /* Analytical PME correction */
1015             zeta2            = _mm_mul_ps(beta2,rsq10);
1016             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1017             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1018             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1019             felec            = _mm_mul_ps(qq10,felec);
1020
1021             fscal            = felec;
1022
1023             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1024
1025              /* Update vectorial force */
1026             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1027             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1028             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1029
1030             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1031             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1032             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1033
1034             /**************************
1035              * CALCULATE INTERACTIONS *
1036              **************************/
1037
1038             r20              = _mm_mul_ps(rsq20,rinv20);
1039             r20              = _mm_andnot_ps(dummy_mask,r20);
1040
1041             /* Compute parameters for interactions between i and j atoms */
1042             qq20             = _mm_mul_ps(iq2,jq0);
1043
1044             /* EWALD ELECTROSTATICS */
1045
1046             /* Analytical PME correction */
1047             zeta2            = _mm_mul_ps(beta2,rsq20);
1048             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1049             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1050             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1051             felec            = _mm_mul_ps(qq20,felec);
1052
1053             fscal            = felec;
1054
1055             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1056
1057              /* Update vectorial force */
1058             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1059             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1060             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1061
1062             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1063             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1064             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1065
1066             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1067             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1068             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1069             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1070
1071             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1072
1073             /* Inner loop uses 94 flops */
1074         }
1075
1076         /* End of innermost loop */
1077
1078         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1079                                               f+i_coord_offset,fshift+i_shift_offset);
1080
1081         /* Increment number of inner iterations */
1082         inneriter                  += j_index_end - j_index_start;
1083
1084         /* Outer loop uses 18 flops */
1085     }
1086
1087     /* Increment number of outer iterations */
1088     outeriter        += nri;
1089
1090     /* Update outer/inner flops */
1091
1092     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*94);
1093 }