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