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_GeomW3W3_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_GeomW3W3_VF_avx_128_fma_single
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            None
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwNone_GeomW3W3_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     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
91     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
93     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
96     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
97     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
98     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
99     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
100     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
101     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
102     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
103     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
104     real             *charge;
105     __m128i          ewitab;
106     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
107     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
108     real             *ewtab;
109     __m128           dummy_mask,cutoff_mask;
110     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
111     __m128           one     = _mm_set1_ps(1.0);
112     __m128           two     = _mm_set1_ps(2.0);
113     x                = xx[0];
114     f                = ff[0];
115
116     nri              = nlist->nri;
117     iinr             = nlist->iinr;
118     jindex           = nlist->jindex;
119     jjnr             = nlist->jjnr;
120     shiftidx         = nlist->shift;
121     gid              = nlist->gid;
122     shiftvec         = fr->shift_vec[0];
123     fshift           = fr->fshift[0];
124     facel            = _mm_set1_ps(fr->ic->epsfac);
125     charge           = mdatoms->chargeA;
126
127     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
128     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
129     beta2            = _mm_mul_ps(beta,beta);
130     beta3            = _mm_mul_ps(beta,beta2);
131     ewtab            = fr->ic->tabq_coul_FDV0;
132     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
133     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
134
135     /* Setup water-specific parameters */
136     inr              = nlist->iinr[0];
137     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
138     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
139     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
140
141     jq0              = _mm_set1_ps(charge[inr+0]);
142     jq1              = _mm_set1_ps(charge[inr+1]);
143     jq2              = _mm_set1_ps(charge[inr+2]);
144     qq00             = _mm_mul_ps(iq0,jq0);
145     qq01             = _mm_mul_ps(iq0,jq1);
146     qq02             = _mm_mul_ps(iq0,jq2);
147     qq10             = _mm_mul_ps(iq1,jq0);
148     qq11             = _mm_mul_ps(iq1,jq1);
149     qq12             = _mm_mul_ps(iq1,jq2);
150     qq20             = _mm_mul_ps(iq2,jq0);
151     qq21             = _mm_mul_ps(iq2,jq1);
152     qq22             = _mm_mul_ps(iq2,jq2);
153
154     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
155     rcutoff_scalar   = fr->ic->rcoulomb;
156     rcutoff          = _mm_set1_ps(rcutoff_scalar);
157     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
158
159     /* Avoid stupid compiler warnings */
160     jnrA = jnrB = jnrC = jnrD = 0;
161     j_coord_offsetA = 0;
162     j_coord_offsetB = 0;
163     j_coord_offsetC = 0;
164     j_coord_offsetD = 0;
165
166     outeriter        = 0;
167     inneriter        = 0;
168
169     for(iidx=0;iidx<4*DIM;iidx++)
170     {
171         scratch[iidx] = 0.0;
172     }
173
174     /* Start outer loop over neighborlists */
175     for(iidx=0; iidx<nri; iidx++)
176     {
177         /* Load shift vector for this list */
178         i_shift_offset   = DIM*shiftidx[iidx];
179
180         /* Load limits for loop over neighbors */
181         j_index_start    = jindex[iidx];
182         j_index_end      = jindex[iidx+1];
183
184         /* Get outer coordinate index */
185         inr              = iinr[iidx];
186         i_coord_offset   = DIM*inr;
187
188         /* Load i particle coords and add shift vector */
189         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
190                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
191
192         fix0             = _mm_setzero_ps();
193         fiy0             = _mm_setzero_ps();
194         fiz0             = _mm_setzero_ps();
195         fix1             = _mm_setzero_ps();
196         fiy1             = _mm_setzero_ps();
197         fiz1             = _mm_setzero_ps();
198         fix2             = _mm_setzero_ps();
199         fiy2             = _mm_setzero_ps();
200         fiz2             = _mm_setzero_ps();
201
202         /* Reset potential sums */
203         velecsum         = _mm_setzero_ps();
204
205         /* Start inner kernel loop */
206         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
207         {
208
209             /* Get j neighbor index, and coordinate index */
210             jnrA             = jjnr[jidx];
211             jnrB             = jjnr[jidx+1];
212             jnrC             = jjnr[jidx+2];
213             jnrD             = jjnr[jidx+3];
214             j_coord_offsetA  = DIM*jnrA;
215             j_coord_offsetB  = DIM*jnrB;
216             j_coord_offsetC  = DIM*jnrC;
217             j_coord_offsetD  = DIM*jnrD;
218
219             /* load j atom coordinates */
220             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
221                                               x+j_coord_offsetC,x+j_coord_offsetD,
222                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
223
224             /* Calculate displacement vector */
225             dx00             = _mm_sub_ps(ix0,jx0);
226             dy00             = _mm_sub_ps(iy0,jy0);
227             dz00             = _mm_sub_ps(iz0,jz0);
228             dx01             = _mm_sub_ps(ix0,jx1);
229             dy01             = _mm_sub_ps(iy0,jy1);
230             dz01             = _mm_sub_ps(iz0,jz1);
231             dx02             = _mm_sub_ps(ix0,jx2);
232             dy02             = _mm_sub_ps(iy0,jy2);
233             dz02             = _mm_sub_ps(iz0,jz2);
234             dx10             = _mm_sub_ps(ix1,jx0);
235             dy10             = _mm_sub_ps(iy1,jy0);
236             dz10             = _mm_sub_ps(iz1,jz0);
237             dx11             = _mm_sub_ps(ix1,jx1);
238             dy11             = _mm_sub_ps(iy1,jy1);
239             dz11             = _mm_sub_ps(iz1,jz1);
240             dx12             = _mm_sub_ps(ix1,jx2);
241             dy12             = _mm_sub_ps(iy1,jy2);
242             dz12             = _mm_sub_ps(iz1,jz2);
243             dx20             = _mm_sub_ps(ix2,jx0);
244             dy20             = _mm_sub_ps(iy2,jy0);
245             dz20             = _mm_sub_ps(iz2,jz0);
246             dx21             = _mm_sub_ps(ix2,jx1);
247             dy21             = _mm_sub_ps(iy2,jy1);
248             dz21             = _mm_sub_ps(iz2,jz1);
249             dx22             = _mm_sub_ps(ix2,jx2);
250             dy22             = _mm_sub_ps(iy2,jy2);
251             dz22             = _mm_sub_ps(iz2,jz2);
252
253             /* Calculate squared distance and things based on it */
254             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
255             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
256             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
257             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
258             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
259             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
260             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
261             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
262             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
263
264             rinv00           = avx128fma_invsqrt_f(rsq00);
265             rinv01           = avx128fma_invsqrt_f(rsq01);
266             rinv02           = avx128fma_invsqrt_f(rsq02);
267             rinv10           = avx128fma_invsqrt_f(rsq10);
268             rinv11           = avx128fma_invsqrt_f(rsq11);
269             rinv12           = avx128fma_invsqrt_f(rsq12);
270             rinv20           = avx128fma_invsqrt_f(rsq20);
271             rinv21           = avx128fma_invsqrt_f(rsq21);
272             rinv22           = avx128fma_invsqrt_f(rsq22);
273
274             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
275             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
276             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
277             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
278             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
279             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
280             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
281             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
282             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
283
284             fjx0             = _mm_setzero_ps();
285             fjy0             = _mm_setzero_ps();
286             fjz0             = _mm_setzero_ps();
287             fjx1             = _mm_setzero_ps();
288             fjy1             = _mm_setzero_ps();
289             fjz1             = _mm_setzero_ps();
290             fjx2             = _mm_setzero_ps();
291             fjy2             = _mm_setzero_ps();
292             fjz2             = _mm_setzero_ps();
293
294             /**************************
295              * CALCULATE INTERACTIONS *
296              **************************/
297
298             if (gmx_mm_any_lt(rsq00,rcutoff2))
299             {
300
301             r00              = _mm_mul_ps(rsq00,rinv00);
302
303             /* EWALD ELECTROSTATICS */
304
305             /* Analytical PME correction */
306             zeta2            = _mm_mul_ps(beta2,rsq00);
307             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
308             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
309             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
310             felec            = _mm_mul_ps(qq00,felec);
311             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
312             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
313             velec            = _mm_mul_ps(qq00,velec);
314
315             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
316
317             /* Update potential sum for this i atom from the interaction with this j atom. */
318             velec            = _mm_and_ps(velec,cutoff_mask);
319             velecsum         = _mm_add_ps(velecsum,velec);
320
321             fscal            = felec;
322
323             fscal            = _mm_and_ps(fscal,cutoff_mask);
324
325              /* Update vectorial force */
326             fix0             = _mm_macc_ps(dx00,fscal,fix0);
327             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
328             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
329
330             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
331             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
332             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
333
334             }
335
336             /**************************
337              * CALCULATE INTERACTIONS *
338              **************************/
339
340             if (gmx_mm_any_lt(rsq01,rcutoff2))
341             {
342
343             r01              = _mm_mul_ps(rsq01,rinv01);
344
345             /* EWALD ELECTROSTATICS */
346
347             /* Analytical PME correction */
348             zeta2            = _mm_mul_ps(beta2,rsq01);
349             rinv3            = _mm_mul_ps(rinvsq01,rinv01);
350             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
351             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
352             felec            = _mm_mul_ps(qq01,felec);
353             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
354             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv01,sh_ewald));
355             velec            = _mm_mul_ps(qq01,velec);
356
357             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
358
359             /* Update potential sum for this i atom from the interaction with this j atom. */
360             velec            = _mm_and_ps(velec,cutoff_mask);
361             velecsum         = _mm_add_ps(velecsum,velec);
362
363             fscal            = felec;
364
365             fscal            = _mm_and_ps(fscal,cutoff_mask);
366
367              /* Update vectorial force */
368             fix0             = _mm_macc_ps(dx01,fscal,fix0);
369             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
370             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
371
372             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
373             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
374             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
375
376             }
377
378             /**************************
379              * CALCULATE INTERACTIONS *
380              **************************/
381
382             if (gmx_mm_any_lt(rsq02,rcutoff2))
383             {
384
385             r02              = _mm_mul_ps(rsq02,rinv02);
386
387             /* EWALD ELECTROSTATICS */
388
389             /* Analytical PME correction */
390             zeta2            = _mm_mul_ps(beta2,rsq02);
391             rinv3            = _mm_mul_ps(rinvsq02,rinv02);
392             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
393             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
394             felec            = _mm_mul_ps(qq02,felec);
395             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
396             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv02,sh_ewald));
397             velec            = _mm_mul_ps(qq02,velec);
398
399             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
400
401             /* Update potential sum for this i atom from the interaction with this j atom. */
402             velec            = _mm_and_ps(velec,cutoff_mask);
403             velecsum         = _mm_add_ps(velecsum,velec);
404
405             fscal            = felec;
406
407             fscal            = _mm_and_ps(fscal,cutoff_mask);
408
409              /* Update vectorial force */
410             fix0             = _mm_macc_ps(dx02,fscal,fix0);
411             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
412             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
413
414             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
415             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
416             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
417
418             }
419
420             /**************************
421              * CALCULATE INTERACTIONS *
422              **************************/
423
424             if (gmx_mm_any_lt(rsq10,rcutoff2))
425             {
426
427             r10              = _mm_mul_ps(rsq10,rinv10);
428
429             /* EWALD ELECTROSTATICS */
430
431             /* Analytical PME correction */
432             zeta2            = _mm_mul_ps(beta2,rsq10);
433             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
434             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
435             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
436             felec            = _mm_mul_ps(qq10,felec);
437             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
438             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
439             velec            = _mm_mul_ps(qq10,velec);
440
441             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
442
443             /* Update potential sum for this i atom from the interaction with this j atom. */
444             velec            = _mm_and_ps(velec,cutoff_mask);
445             velecsum         = _mm_add_ps(velecsum,velec);
446
447             fscal            = felec;
448
449             fscal            = _mm_and_ps(fscal,cutoff_mask);
450
451              /* Update vectorial force */
452             fix1             = _mm_macc_ps(dx10,fscal,fix1);
453             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
454             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
455
456             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
457             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
458             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
459
460             }
461
462             /**************************
463              * CALCULATE INTERACTIONS *
464              **************************/
465
466             if (gmx_mm_any_lt(rsq11,rcutoff2))
467             {
468
469             r11              = _mm_mul_ps(rsq11,rinv11);
470
471             /* EWALD ELECTROSTATICS */
472
473             /* Analytical PME correction */
474             zeta2            = _mm_mul_ps(beta2,rsq11);
475             rinv3            = _mm_mul_ps(rinvsq11,rinv11);
476             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
477             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
478             felec            = _mm_mul_ps(qq11,felec);
479             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
480             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv11,sh_ewald));
481             velec            = _mm_mul_ps(qq11,velec);
482
483             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
484
485             /* Update potential sum for this i atom from the interaction with this j atom. */
486             velec            = _mm_and_ps(velec,cutoff_mask);
487             velecsum         = _mm_add_ps(velecsum,velec);
488
489             fscal            = felec;
490
491             fscal            = _mm_and_ps(fscal,cutoff_mask);
492
493              /* Update vectorial force */
494             fix1             = _mm_macc_ps(dx11,fscal,fix1);
495             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
496             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
497
498             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
499             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
500             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
501
502             }
503
504             /**************************
505              * CALCULATE INTERACTIONS *
506              **************************/
507
508             if (gmx_mm_any_lt(rsq12,rcutoff2))
509             {
510
511             r12              = _mm_mul_ps(rsq12,rinv12);
512
513             /* EWALD ELECTROSTATICS */
514
515             /* Analytical PME correction */
516             zeta2            = _mm_mul_ps(beta2,rsq12);
517             rinv3            = _mm_mul_ps(rinvsq12,rinv12);
518             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
519             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
520             felec            = _mm_mul_ps(qq12,felec);
521             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
522             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv12,sh_ewald));
523             velec            = _mm_mul_ps(qq12,velec);
524
525             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
526
527             /* Update potential sum for this i atom from the interaction with this j atom. */
528             velec            = _mm_and_ps(velec,cutoff_mask);
529             velecsum         = _mm_add_ps(velecsum,velec);
530
531             fscal            = felec;
532
533             fscal            = _mm_and_ps(fscal,cutoff_mask);
534
535              /* Update vectorial force */
536             fix1             = _mm_macc_ps(dx12,fscal,fix1);
537             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
538             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
539
540             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
541             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
542             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
543
544             }
545
546             /**************************
547              * CALCULATE INTERACTIONS *
548              **************************/
549
550             if (gmx_mm_any_lt(rsq20,rcutoff2))
551             {
552
553             r20              = _mm_mul_ps(rsq20,rinv20);
554
555             /* EWALD ELECTROSTATICS */
556
557             /* Analytical PME correction */
558             zeta2            = _mm_mul_ps(beta2,rsq20);
559             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
560             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
561             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
562             felec            = _mm_mul_ps(qq20,felec);
563             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
564             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
565             velec            = _mm_mul_ps(qq20,velec);
566
567             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
568
569             /* Update potential sum for this i atom from the interaction with this j atom. */
570             velec            = _mm_and_ps(velec,cutoff_mask);
571             velecsum         = _mm_add_ps(velecsum,velec);
572
573             fscal            = felec;
574
575             fscal            = _mm_and_ps(fscal,cutoff_mask);
576
577              /* Update vectorial force */
578             fix2             = _mm_macc_ps(dx20,fscal,fix2);
579             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
580             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
581
582             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
583             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
584             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
585
586             }
587
588             /**************************
589              * CALCULATE INTERACTIONS *
590              **************************/
591
592             if (gmx_mm_any_lt(rsq21,rcutoff2))
593             {
594
595             r21              = _mm_mul_ps(rsq21,rinv21);
596
597             /* EWALD ELECTROSTATICS */
598
599             /* Analytical PME correction */
600             zeta2            = _mm_mul_ps(beta2,rsq21);
601             rinv3            = _mm_mul_ps(rinvsq21,rinv21);
602             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
603             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
604             felec            = _mm_mul_ps(qq21,felec);
605             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
606             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv21,sh_ewald));
607             velec            = _mm_mul_ps(qq21,velec);
608
609             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
610
611             /* Update potential sum for this i atom from the interaction with this j atom. */
612             velec            = _mm_and_ps(velec,cutoff_mask);
613             velecsum         = _mm_add_ps(velecsum,velec);
614
615             fscal            = felec;
616
617             fscal            = _mm_and_ps(fscal,cutoff_mask);
618
619              /* Update vectorial force */
620             fix2             = _mm_macc_ps(dx21,fscal,fix2);
621             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
622             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
623
624             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
625             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
626             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
627
628             }
629
630             /**************************
631              * CALCULATE INTERACTIONS *
632              **************************/
633
634             if (gmx_mm_any_lt(rsq22,rcutoff2))
635             {
636
637             r22              = _mm_mul_ps(rsq22,rinv22);
638
639             /* EWALD ELECTROSTATICS */
640
641             /* Analytical PME correction */
642             zeta2            = _mm_mul_ps(beta2,rsq22);
643             rinv3            = _mm_mul_ps(rinvsq22,rinv22);
644             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
645             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
646             felec            = _mm_mul_ps(qq22,felec);
647             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
648             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv22,sh_ewald));
649             velec            = _mm_mul_ps(qq22,velec);
650
651             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
652
653             /* Update potential sum for this i atom from the interaction with this j atom. */
654             velec            = _mm_and_ps(velec,cutoff_mask);
655             velecsum         = _mm_add_ps(velecsum,velec);
656
657             fscal            = felec;
658
659             fscal            = _mm_and_ps(fscal,cutoff_mask);
660
661              /* Update vectorial force */
662             fix2             = _mm_macc_ps(dx22,fscal,fix2);
663             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
664             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
665
666             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
667             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
668             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
669
670             }
671
672             fjptrA             = f+j_coord_offsetA;
673             fjptrB             = f+j_coord_offsetB;
674             fjptrC             = f+j_coord_offsetC;
675             fjptrD             = f+j_coord_offsetD;
676
677             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
678                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
679
680             /* Inner loop uses 297 flops */
681         }
682
683         if(jidx<j_index_end)
684         {
685
686             /* Get j neighbor index, and coordinate index */
687             jnrlistA         = jjnr[jidx];
688             jnrlistB         = jjnr[jidx+1];
689             jnrlistC         = jjnr[jidx+2];
690             jnrlistD         = jjnr[jidx+3];
691             /* Sign of each element will be negative for non-real atoms.
692              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
693              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
694              */
695             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
696             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
697             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
698             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
699             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
700             j_coord_offsetA  = DIM*jnrA;
701             j_coord_offsetB  = DIM*jnrB;
702             j_coord_offsetC  = DIM*jnrC;
703             j_coord_offsetD  = DIM*jnrD;
704
705             /* load j atom coordinates */
706             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
707                                               x+j_coord_offsetC,x+j_coord_offsetD,
708                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
709
710             /* Calculate displacement vector */
711             dx00             = _mm_sub_ps(ix0,jx0);
712             dy00             = _mm_sub_ps(iy0,jy0);
713             dz00             = _mm_sub_ps(iz0,jz0);
714             dx01             = _mm_sub_ps(ix0,jx1);
715             dy01             = _mm_sub_ps(iy0,jy1);
716             dz01             = _mm_sub_ps(iz0,jz1);
717             dx02             = _mm_sub_ps(ix0,jx2);
718             dy02             = _mm_sub_ps(iy0,jy2);
719             dz02             = _mm_sub_ps(iz0,jz2);
720             dx10             = _mm_sub_ps(ix1,jx0);
721             dy10             = _mm_sub_ps(iy1,jy0);
722             dz10             = _mm_sub_ps(iz1,jz0);
723             dx11             = _mm_sub_ps(ix1,jx1);
724             dy11             = _mm_sub_ps(iy1,jy1);
725             dz11             = _mm_sub_ps(iz1,jz1);
726             dx12             = _mm_sub_ps(ix1,jx2);
727             dy12             = _mm_sub_ps(iy1,jy2);
728             dz12             = _mm_sub_ps(iz1,jz2);
729             dx20             = _mm_sub_ps(ix2,jx0);
730             dy20             = _mm_sub_ps(iy2,jy0);
731             dz20             = _mm_sub_ps(iz2,jz0);
732             dx21             = _mm_sub_ps(ix2,jx1);
733             dy21             = _mm_sub_ps(iy2,jy1);
734             dz21             = _mm_sub_ps(iz2,jz1);
735             dx22             = _mm_sub_ps(ix2,jx2);
736             dy22             = _mm_sub_ps(iy2,jy2);
737             dz22             = _mm_sub_ps(iz2,jz2);
738
739             /* Calculate squared distance and things based on it */
740             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
741             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
742             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
743             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
744             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
745             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
746             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
747             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
748             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
749
750             rinv00           = avx128fma_invsqrt_f(rsq00);
751             rinv01           = avx128fma_invsqrt_f(rsq01);
752             rinv02           = avx128fma_invsqrt_f(rsq02);
753             rinv10           = avx128fma_invsqrt_f(rsq10);
754             rinv11           = avx128fma_invsqrt_f(rsq11);
755             rinv12           = avx128fma_invsqrt_f(rsq12);
756             rinv20           = avx128fma_invsqrt_f(rsq20);
757             rinv21           = avx128fma_invsqrt_f(rsq21);
758             rinv22           = avx128fma_invsqrt_f(rsq22);
759
760             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
761             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
762             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
763             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
764             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
765             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
766             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
767             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
768             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
769
770             fjx0             = _mm_setzero_ps();
771             fjy0             = _mm_setzero_ps();
772             fjz0             = _mm_setzero_ps();
773             fjx1             = _mm_setzero_ps();
774             fjy1             = _mm_setzero_ps();
775             fjz1             = _mm_setzero_ps();
776             fjx2             = _mm_setzero_ps();
777             fjy2             = _mm_setzero_ps();
778             fjz2             = _mm_setzero_ps();
779
780             /**************************
781              * CALCULATE INTERACTIONS *
782              **************************/
783
784             if (gmx_mm_any_lt(rsq00,rcutoff2))
785             {
786
787             r00              = _mm_mul_ps(rsq00,rinv00);
788             r00              = _mm_andnot_ps(dummy_mask,r00);
789
790             /* EWALD ELECTROSTATICS */
791
792             /* Analytical PME correction */
793             zeta2            = _mm_mul_ps(beta2,rsq00);
794             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
795             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
796             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
797             felec            = _mm_mul_ps(qq00,felec);
798             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
799             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
800             velec            = _mm_mul_ps(qq00,velec);
801
802             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
803
804             /* Update potential sum for this i atom from the interaction with this j atom. */
805             velec            = _mm_and_ps(velec,cutoff_mask);
806             velec            = _mm_andnot_ps(dummy_mask,velec);
807             velecsum         = _mm_add_ps(velecsum,velec);
808
809             fscal            = felec;
810
811             fscal            = _mm_and_ps(fscal,cutoff_mask);
812
813             fscal            = _mm_andnot_ps(dummy_mask,fscal);
814
815              /* Update vectorial force */
816             fix0             = _mm_macc_ps(dx00,fscal,fix0);
817             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
818             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
819
820             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
821             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
822             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
823
824             }
825
826             /**************************
827              * CALCULATE INTERACTIONS *
828              **************************/
829
830             if (gmx_mm_any_lt(rsq01,rcutoff2))
831             {
832
833             r01              = _mm_mul_ps(rsq01,rinv01);
834             r01              = _mm_andnot_ps(dummy_mask,r01);
835
836             /* EWALD ELECTROSTATICS */
837
838             /* Analytical PME correction */
839             zeta2            = _mm_mul_ps(beta2,rsq01);
840             rinv3            = _mm_mul_ps(rinvsq01,rinv01);
841             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
842             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
843             felec            = _mm_mul_ps(qq01,felec);
844             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
845             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv01,sh_ewald));
846             velec            = _mm_mul_ps(qq01,velec);
847
848             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
849
850             /* Update potential sum for this i atom from the interaction with this j atom. */
851             velec            = _mm_and_ps(velec,cutoff_mask);
852             velec            = _mm_andnot_ps(dummy_mask,velec);
853             velecsum         = _mm_add_ps(velecsum,velec);
854
855             fscal            = felec;
856
857             fscal            = _mm_and_ps(fscal,cutoff_mask);
858
859             fscal            = _mm_andnot_ps(dummy_mask,fscal);
860
861              /* Update vectorial force */
862             fix0             = _mm_macc_ps(dx01,fscal,fix0);
863             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
864             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
865
866             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
867             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
868             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
869
870             }
871
872             /**************************
873              * CALCULATE INTERACTIONS *
874              **************************/
875
876             if (gmx_mm_any_lt(rsq02,rcutoff2))
877             {
878
879             r02              = _mm_mul_ps(rsq02,rinv02);
880             r02              = _mm_andnot_ps(dummy_mask,r02);
881
882             /* EWALD ELECTROSTATICS */
883
884             /* Analytical PME correction */
885             zeta2            = _mm_mul_ps(beta2,rsq02);
886             rinv3            = _mm_mul_ps(rinvsq02,rinv02);
887             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
888             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
889             felec            = _mm_mul_ps(qq02,felec);
890             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
891             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv02,sh_ewald));
892             velec            = _mm_mul_ps(qq02,velec);
893
894             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
895
896             /* Update potential sum for this i atom from the interaction with this j atom. */
897             velec            = _mm_and_ps(velec,cutoff_mask);
898             velec            = _mm_andnot_ps(dummy_mask,velec);
899             velecsum         = _mm_add_ps(velecsum,velec);
900
901             fscal            = felec;
902
903             fscal            = _mm_and_ps(fscal,cutoff_mask);
904
905             fscal            = _mm_andnot_ps(dummy_mask,fscal);
906
907              /* Update vectorial force */
908             fix0             = _mm_macc_ps(dx02,fscal,fix0);
909             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
910             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
911
912             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
913             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
914             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
915
916             }
917
918             /**************************
919              * CALCULATE INTERACTIONS *
920              **************************/
921
922             if (gmx_mm_any_lt(rsq10,rcutoff2))
923             {
924
925             r10              = _mm_mul_ps(rsq10,rinv10);
926             r10              = _mm_andnot_ps(dummy_mask,r10);
927
928             /* EWALD ELECTROSTATICS */
929
930             /* Analytical PME correction */
931             zeta2            = _mm_mul_ps(beta2,rsq10);
932             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
933             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
934             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
935             felec            = _mm_mul_ps(qq10,felec);
936             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
937             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
938             velec            = _mm_mul_ps(qq10,velec);
939
940             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
941
942             /* Update potential sum for this i atom from the interaction with this j atom. */
943             velec            = _mm_and_ps(velec,cutoff_mask);
944             velec            = _mm_andnot_ps(dummy_mask,velec);
945             velecsum         = _mm_add_ps(velecsum,velec);
946
947             fscal            = felec;
948
949             fscal            = _mm_and_ps(fscal,cutoff_mask);
950
951             fscal            = _mm_andnot_ps(dummy_mask,fscal);
952
953              /* Update vectorial force */
954             fix1             = _mm_macc_ps(dx10,fscal,fix1);
955             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
956             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
957
958             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
959             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
960             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
961
962             }
963
964             /**************************
965              * CALCULATE INTERACTIONS *
966              **************************/
967
968             if (gmx_mm_any_lt(rsq11,rcutoff2))
969             {
970
971             r11              = _mm_mul_ps(rsq11,rinv11);
972             r11              = _mm_andnot_ps(dummy_mask,r11);
973
974             /* EWALD ELECTROSTATICS */
975
976             /* Analytical PME correction */
977             zeta2            = _mm_mul_ps(beta2,rsq11);
978             rinv3            = _mm_mul_ps(rinvsq11,rinv11);
979             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
980             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
981             felec            = _mm_mul_ps(qq11,felec);
982             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
983             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv11,sh_ewald));
984             velec            = _mm_mul_ps(qq11,velec);
985
986             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
987
988             /* Update potential sum for this i atom from the interaction with this j atom. */
989             velec            = _mm_and_ps(velec,cutoff_mask);
990             velec            = _mm_andnot_ps(dummy_mask,velec);
991             velecsum         = _mm_add_ps(velecsum,velec);
992
993             fscal            = felec;
994
995             fscal            = _mm_and_ps(fscal,cutoff_mask);
996
997             fscal            = _mm_andnot_ps(dummy_mask,fscal);
998
999              /* Update vectorial force */
1000             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1001             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1002             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1003
1004             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1005             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1006             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1007
1008             }
1009
1010             /**************************
1011              * CALCULATE INTERACTIONS *
1012              **************************/
1013
1014             if (gmx_mm_any_lt(rsq12,rcutoff2))
1015             {
1016
1017             r12              = _mm_mul_ps(rsq12,rinv12);
1018             r12              = _mm_andnot_ps(dummy_mask,r12);
1019
1020             /* EWALD ELECTROSTATICS */
1021
1022             /* Analytical PME correction */
1023             zeta2            = _mm_mul_ps(beta2,rsq12);
1024             rinv3            = _mm_mul_ps(rinvsq12,rinv12);
1025             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1026             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1027             felec            = _mm_mul_ps(qq12,felec);
1028             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
1029             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv12,sh_ewald));
1030             velec            = _mm_mul_ps(qq12,velec);
1031
1032             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1033
1034             /* Update potential sum for this i atom from the interaction with this j atom. */
1035             velec            = _mm_and_ps(velec,cutoff_mask);
1036             velec            = _mm_andnot_ps(dummy_mask,velec);
1037             velecsum         = _mm_add_ps(velecsum,velec);
1038
1039             fscal            = felec;
1040
1041             fscal            = _mm_and_ps(fscal,cutoff_mask);
1042
1043             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1044
1045              /* Update vectorial force */
1046             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1047             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1048             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1049
1050             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1051             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1052             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1053
1054             }
1055
1056             /**************************
1057              * CALCULATE INTERACTIONS *
1058              **************************/
1059
1060             if (gmx_mm_any_lt(rsq20,rcutoff2))
1061             {
1062
1063             r20              = _mm_mul_ps(rsq20,rinv20);
1064             r20              = _mm_andnot_ps(dummy_mask,r20);
1065
1066             /* EWALD ELECTROSTATICS */
1067
1068             /* Analytical PME correction */
1069             zeta2            = _mm_mul_ps(beta2,rsq20);
1070             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1071             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1072             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1073             felec            = _mm_mul_ps(qq20,felec);
1074             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
1075             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
1076             velec            = _mm_mul_ps(qq20,velec);
1077
1078             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1079
1080             /* Update potential sum for this i atom from the interaction with this j atom. */
1081             velec            = _mm_and_ps(velec,cutoff_mask);
1082             velec            = _mm_andnot_ps(dummy_mask,velec);
1083             velecsum         = _mm_add_ps(velecsum,velec);
1084
1085             fscal            = felec;
1086
1087             fscal            = _mm_and_ps(fscal,cutoff_mask);
1088
1089             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1090
1091              /* Update vectorial force */
1092             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1093             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1094             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1095
1096             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1097             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1098             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1099
1100             }
1101
1102             /**************************
1103              * CALCULATE INTERACTIONS *
1104              **************************/
1105
1106             if (gmx_mm_any_lt(rsq21,rcutoff2))
1107             {
1108
1109             r21              = _mm_mul_ps(rsq21,rinv21);
1110             r21              = _mm_andnot_ps(dummy_mask,r21);
1111
1112             /* EWALD ELECTROSTATICS */
1113
1114             /* Analytical PME correction */
1115             zeta2            = _mm_mul_ps(beta2,rsq21);
1116             rinv3            = _mm_mul_ps(rinvsq21,rinv21);
1117             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1118             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1119             felec            = _mm_mul_ps(qq21,felec);
1120             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
1121             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv21,sh_ewald));
1122             velec            = _mm_mul_ps(qq21,velec);
1123
1124             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1125
1126             /* Update potential sum for this i atom from the interaction with this j atom. */
1127             velec            = _mm_and_ps(velec,cutoff_mask);
1128             velec            = _mm_andnot_ps(dummy_mask,velec);
1129             velecsum         = _mm_add_ps(velecsum,velec);
1130
1131             fscal            = felec;
1132
1133             fscal            = _mm_and_ps(fscal,cutoff_mask);
1134
1135             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1136
1137              /* Update vectorial force */
1138             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1139             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1140             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1141
1142             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1143             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1144             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1145
1146             }
1147
1148             /**************************
1149              * CALCULATE INTERACTIONS *
1150              **************************/
1151
1152             if (gmx_mm_any_lt(rsq22,rcutoff2))
1153             {
1154
1155             r22              = _mm_mul_ps(rsq22,rinv22);
1156             r22              = _mm_andnot_ps(dummy_mask,r22);
1157
1158             /* EWALD ELECTROSTATICS */
1159
1160             /* Analytical PME correction */
1161             zeta2            = _mm_mul_ps(beta2,rsq22);
1162             rinv3            = _mm_mul_ps(rinvsq22,rinv22);
1163             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1164             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1165             felec            = _mm_mul_ps(qq22,felec);
1166             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
1167             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv22,sh_ewald));
1168             velec            = _mm_mul_ps(qq22,velec);
1169
1170             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1171
1172             /* Update potential sum for this i atom from the interaction with this j atom. */
1173             velec            = _mm_and_ps(velec,cutoff_mask);
1174             velec            = _mm_andnot_ps(dummy_mask,velec);
1175             velecsum         = _mm_add_ps(velecsum,velec);
1176
1177             fscal            = felec;
1178
1179             fscal            = _mm_and_ps(fscal,cutoff_mask);
1180
1181             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1182
1183              /* Update vectorial force */
1184             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1185             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1186             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1187
1188             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1189             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1190             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1191
1192             }
1193
1194             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1195             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1196             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1197             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1198
1199             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1200                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1201
1202             /* Inner loop uses 306 flops */
1203         }
1204
1205         /* End of innermost loop */
1206
1207         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1208                                               f+i_coord_offset,fshift+i_shift_offset);
1209
1210         ggid                        = gid[iidx];
1211         /* Update potential energies */
1212         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1213
1214         /* Increment number of inner iterations */
1215         inneriter                  += j_index_end - j_index_start;
1216
1217         /* Outer loop uses 19 flops */
1218     }
1219
1220     /* Increment number of outer iterations */
1221     outeriter        += nri;
1222
1223     /* Update outer/inner flops */
1224
1225     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_VF,outeriter*19 + inneriter*306);
1226 }
1227 /*
1228  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomW3W3_F_avx_128_fma_single
1229  * Electrostatics interaction: Ewald
1230  * VdW interaction:            None
1231  * Geometry:                   Water3-Water3
1232  * Calculate force/pot:        Force
1233  */
1234 void
1235 nb_kernel_ElecEwSh_VdwNone_GeomW3W3_F_avx_128_fma_single
1236                     (t_nblist                    * gmx_restrict       nlist,
1237                      rvec                        * gmx_restrict          xx,
1238                      rvec                        * gmx_restrict          ff,
1239                      struct t_forcerec           * gmx_restrict          fr,
1240                      t_mdatoms                   * gmx_restrict     mdatoms,
1241                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1242                      t_nrnb                      * gmx_restrict        nrnb)
1243 {
1244     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1245      * just 0 for non-waters.
1246      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1247      * jnr indices corresponding to data put in the four positions in the SIMD register.
1248      */
1249     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
1250     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1251     int              jnrA,jnrB,jnrC,jnrD;
1252     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1253     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1254     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
1255     real             rcutoff_scalar;
1256     real             *shiftvec,*fshift,*x,*f;
1257     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1258     real             scratch[4*DIM];
1259     __m128           fscal,rcutoff,rcutoff2,jidxall;
1260     int              vdwioffset0;
1261     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1262     int              vdwioffset1;
1263     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1264     int              vdwioffset2;
1265     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1266     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1267     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1268     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1269     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1270     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1271     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1272     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1273     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1274     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1275     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1276     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1277     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1278     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1279     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1280     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1281     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
1282     real             *charge;
1283     __m128i          ewitab;
1284     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
1285     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
1286     real             *ewtab;
1287     __m128           dummy_mask,cutoff_mask;
1288     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1289     __m128           one     = _mm_set1_ps(1.0);
1290     __m128           two     = _mm_set1_ps(2.0);
1291     x                = xx[0];
1292     f                = ff[0];
1293
1294     nri              = nlist->nri;
1295     iinr             = nlist->iinr;
1296     jindex           = nlist->jindex;
1297     jjnr             = nlist->jjnr;
1298     shiftidx         = nlist->shift;
1299     gid              = nlist->gid;
1300     shiftvec         = fr->shift_vec[0];
1301     fshift           = fr->fshift[0];
1302     facel            = _mm_set1_ps(fr->ic->epsfac);
1303     charge           = mdatoms->chargeA;
1304
1305     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
1306     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
1307     beta2            = _mm_mul_ps(beta,beta);
1308     beta3            = _mm_mul_ps(beta,beta2);
1309     ewtab            = fr->ic->tabq_coul_F;
1310     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
1311     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
1312
1313     /* Setup water-specific parameters */
1314     inr              = nlist->iinr[0];
1315     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1316     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1317     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1318
1319     jq0              = _mm_set1_ps(charge[inr+0]);
1320     jq1              = _mm_set1_ps(charge[inr+1]);
1321     jq2              = _mm_set1_ps(charge[inr+2]);
1322     qq00             = _mm_mul_ps(iq0,jq0);
1323     qq01             = _mm_mul_ps(iq0,jq1);
1324     qq02             = _mm_mul_ps(iq0,jq2);
1325     qq10             = _mm_mul_ps(iq1,jq0);
1326     qq11             = _mm_mul_ps(iq1,jq1);
1327     qq12             = _mm_mul_ps(iq1,jq2);
1328     qq20             = _mm_mul_ps(iq2,jq0);
1329     qq21             = _mm_mul_ps(iq2,jq1);
1330     qq22             = _mm_mul_ps(iq2,jq2);
1331
1332     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1333     rcutoff_scalar   = fr->ic->rcoulomb;
1334     rcutoff          = _mm_set1_ps(rcutoff_scalar);
1335     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
1336
1337     /* Avoid stupid compiler warnings */
1338     jnrA = jnrB = jnrC = jnrD = 0;
1339     j_coord_offsetA = 0;
1340     j_coord_offsetB = 0;
1341     j_coord_offsetC = 0;
1342     j_coord_offsetD = 0;
1343
1344     outeriter        = 0;
1345     inneriter        = 0;
1346
1347     for(iidx=0;iidx<4*DIM;iidx++)
1348     {
1349         scratch[iidx] = 0.0;
1350     }
1351
1352     /* Start outer loop over neighborlists */
1353     for(iidx=0; iidx<nri; iidx++)
1354     {
1355         /* Load shift vector for this list */
1356         i_shift_offset   = DIM*shiftidx[iidx];
1357
1358         /* Load limits for loop over neighbors */
1359         j_index_start    = jindex[iidx];
1360         j_index_end      = jindex[iidx+1];
1361
1362         /* Get outer coordinate index */
1363         inr              = iinr[iidx];
1364         i_coord_offset   = DIM*inr;
1365
1366         /* Load i particle coords and add shift vector */
1367         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1368                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1369
1370         fix0             = _mm_setzero_ps();
1371         fiy0             = _mm_setzero_ps();
1372         fiz0             = _mm_setzero_ps();
1373         fix1             = _mm_setzero_ps();
1374         fiy1             = _mm_setzero_ps();
1375         fiz1             = _mm_setzero_ps();
1376         fix2             = _mm_setzero_ps();
1377         fiy2             = _mm_setzero_ps();
1378         fiz2             = _mm_setzero_ps();
1379
1380         /* Start inner kernel loop */
1381         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1382         {
1383
1384             /* Get j neighbor index, and coordinate index */
1385             jnrA             = jjnr[jidx];
1386             jnrB             = jjnr[jidx+1];
1387             jnrC             = jjnr[jidx+2];
1388             jnrD             = jjnr[jidx+3];
1389             j_coord_offsetA  = DIM*jnrA;
1390             j_coord_offsetB  = DIM*jnrB;
1391             j_coord_offsetC  = DIM*jnrC;
1392             j_coord_offsetD  = DIM*jnrD;
1393
1394             /* load j atom coordinates */
1395             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1396                                               x+j_coord_offsetC,x+j_coord_offsetD,
1397                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1398
1399             /* Calculate displacement vector */
1400             dx00             = _mm_sub_ps(ix0,jx0);
1401             dy00             = _mm_sub_ps(iy0,jy0);
1402             dz00             = _mm_sub_ps(iz0,jz0);
1403             dx01             = _mm_sub_ps(ix0,jx1);
1404             dy01             = _mm_sub_ps(iy0,jy1);
1405             dz01             = _mm_sub_ps(iz0,jz1);
1406             dx02             = _mm_sub_ps(ix0,jx2);
1407             dy02             = _mm_sub_ps(iy0,jy2);
1408             dz02             = _mm_sub_ps(iz0,jz2);
1409             dx10             = _mm_sub_ps(ix1,jx0);
1410             dy10             = _mm_sub_ps(iy1,jy0);
1411             dz10             = _mm_sub_ps(iz1,jz0);
1412             dx11             = _mm_sub_ps(ix1,jx1);
1413             dy11             = _mm_sub_ps(iy1,jy1);
1414             dz11             = _mm_sub_ps(iz1,jz1);
1415             dx12             = _mm_sub_ps(ix1,jx2);
1416             dy12             = _mm_sub_ps(iy1,jy2);
1417             dz12             = _mm_sub_ps(iz1,jz2);
1418             dx20             = _mm_sub_ps(ix2,jx0);
1419             dy20             = _mm_sub_ps(iy2,jy0);
1420             dz20             = _mm_sub_ps(iz2,jz0);
1421             dx21             = _mm_sub_ps(ix2,jx1);
1422             dy21             = _mm_sub_ps(iy2,jy1);
1423             dz21             = _mm_sub_ps(iz2,jz1);
1424             dx22             = _mm_sub_ps(ix2,jx2);
1425             dy22             = _mm_sub_ps(iy2,jy2);
1426             dz22             = _mm_sub_ps(iz2,jz2);
1427
1428             /* Calculate squared distance and things based on it */
1429             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1430             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1431             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1432             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1433             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1434             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1435             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1436             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1437             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1438
1439             rinv00           = avx128fma_invsqrt_f(rsq00);
1440             rinv01           = avx128fma_invsqrt_f(rsq01);
1441             rinv02           = avx128fma_invsqrt_f(rsq02);
1442             rinv10           = avx128fma_invsqrt_f(rsq10);
1443             rinv11           = avx128fma_invsqrt_f(rsq11);
1444             rinv12           = avx128fma_invsqrt_f(rsq12);
1445             rinv20           = avx128fma_invsqrt_f(rsq20);
1446             rinv21           = avx128fma_invsqrt_f(rsq21);
1447             rinv22           = avx128fma_invsqrt_f(rsq22);
1448
1449             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1450             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1451             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1452             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1453             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1454             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1455             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1456             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1457             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1458
1459             fjx0             = _mm_setzero_ps();
1460             fjy0             = _mm_setzero_ps();
1461             fjz0             = _mm_setzero_ps();
1462             fjx1             = _mm_setzero_ps();
1463             fjy1             = _mm_setzero_ps();
1464             fjz1             = _mm_setzero_ps();
1465             fjx2             = _mm_setzero_ps();
1466             fjy2             = _mm_setzero_ps();
1467             fjz2             = _mm_setzero_ps();
1468
1469             /**************************
1470              * CALCULATE INTERACTIONS *
1471              **************************/
1472
1473             if (gmx_mm_any_lt(rsq00,rcutoff2))
1474             {
1475
1476             r00              = _mm_mul_ps(rsq00,rinv00);
1477
1478             /* EWALD ELECTROSTATICS */
1479
1480             /* Analytical PME correction */
1481             zeta2            = _mm_mul_ps(beta2,rsq00);
1482             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
1483             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1484             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1485             felec            = _mm_mul_ps(qq00,felec);
1486
1487             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1488
1489             fscal            = felec;
1490
1491             fscal            = _mm_and_ps(fscal,cutoff_mask);
1492
1493              /* Update vectorial force */
1494             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1495             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1496             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1497
1498             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1499             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1500             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1501
1502             }
1503
1504             /**************************
1505              * CALCULATE INTERACTIONS *
1506              **************************/
1507
1508             if (gmx_mm_any_lt(rsq01,rcutoff2))
1509             {
1510
1511             r01              = _mm_mul_ps(rsq01,rinv01);
1512
1513             /* EWALD ELECTROSTATICS */
1514
1515             /* Analytical PME correction */
1516             zeta2            = _mm_mul_ps(beta2,rsq01);
1517             rinv3            = _mm_mul_ps(rinvsq01,rinv01);
1518             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1519             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1520             felec            = _mm_mul_ps(qq01,felec);
1521
1522             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
1523
1524             fscal            = felec;
1525
1526             fscal            = _mm_and_ps(fscal,cutoff_mask);
1527
1528              /* Update vectorial force */
1529             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1530             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1531             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1532
1533             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1534             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1535             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1536
1537             }
1538
1539             /**************************
1540              * CALCULATE INTERACTIONS *
1541              **************************/
1542
1543             if (gmx_mm_any_lt(rsq02,rcutoff2))
1544             {
1545
1546             r02              = _mm_mul_ps(rsq02,rinv02);
1547
1548             /* EWALD ELECTROSTATICS */
1549
1550             /* Analytical PME correction */
1551             zeta2            = _mm_mul_ps(beta2,rsq02);
1552             rinv3            = _mm_mul_ps(rinvsq02,rinv02);
1553             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1554             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1555             felec            = _mm_mul_ps(qq02,felec);
1556
1557             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
1558
1559             fscal            = felec;
1560
1561             fscal            = _mm_and_ps(fscal,cutoff_mask);
1562
1563              /* Update vectorial force */
1564             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1565             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1566             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1567
1568             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1569             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1570             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1571
1572             }
1573
1574             /**************************
1575              * CALCULATE INTERACTIONS *
1576              **************************/
1577
1578             if (gmx_mm_any_lt(rsq10,rcutoff2))
1579             {
1580
1581             r10              = _mm_mul_ps(rsq10,rinv10);
1582
1583             /* EWALD ELECTROSTATICS */
1584
1585             /* Analytical PME correction */
1586             zeta2            = _mm_mul_ps(beta2,rsq10);
1587             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1588             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1589             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1590             felec            = _mm_mul_ps(qq10,felec);
1591
1592             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1593
1594             fscal            = felec;
1595
1596             fscal            = _mm_and_ps(fscal,cutoff_mask);
1597
1598              /* Update vectorial force */
1599             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1600             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1601             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1602
1603             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1604             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1605             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1606
1607             }
1608
1609             /**************************
1610              * CALCULATE INTERACTIONS *
1611              **************************/
1612
1613             if (gmx_mm_any_lt(rsq11,rcutoff2))
1614             {
1615
1616             r11              = _mm_mul_ps(rsq11,rinv11);
1617
1618             /* EWALD ELECTROSTATICS */
1619
1620             /* Analytical PME correction */
1621             zeta2            = _mm_mul_ps(beta2,rsq11);
1622             rinv3            = _mm_mul_ps(rinvsq11,rinv11);
1623             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1624             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1625             felec            = _mm_mul_ps(qq11,felec);
1626
1627             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
1628
1629             fscal            = felec;
1630
1631             fscal            = _mm_and_ps(fscal,cutoff_mask);
1632
1633              /* Update vectorial force */
1634             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1635             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1636             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1637
1638             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1639             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1640             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1641
1642             }
1643
1644             /**************************
1645              * CALCULATE INTERACTIONS *
1646              **************************/
1647
1648             if (gmx_mm_any_lt(rsq12,rcutoff2))
1649             {
1650
1651             r12              = _mm_mul_ps(rsq12,rinv12);
1652
1653             /* EWALD ELECTROSTATICS */
1654
1655             /* Analytical PME correction */
1656             zeta2            = _mm_mul_ps(beta2,rsq12);
1657             rinv3            = _mm_mul_ps(rinvsq12,rinv12);
1658             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1659             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1660             felec            = _mm_mul_ps(qq12,felec);
1661
1662             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1663
1664             fscal            = felec;
1665
1666             fscal            = _mm_and_ps(fscal,cutoff_mask);
1667
1668              /* Update vectorial force */
1669             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1670             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1671             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1672
1673             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1674             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1675             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1676
1677             }
1678
1679             /**************************
1680              * CALCULATE INTERACTIONS *
1681              **************************/
1682
1683             if (gmx_mm_any_lt(rsq20,rcutoff2))
1684             {
1685
1686             r20              = _mm_mul_ps(rsq20,rinv20);
1687
1688             /* EWALD ELECTROSTATICS */
1689
1690             /* Analytical PME correction */
1691             zeta2            = _mm_mul_ps(beta2,rsq20);
1692             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1693             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1694             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1695             felec            = _mm_mul_ps(qq20,felec);
1696
1697             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1698
1699             fscal            = felec;
1700
1701             fscal            = _mm_and_ps(fscal,cutoff_mask);
1702
1703              /* Update vectorial force */
1704             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1705             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1706             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1707
1708             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1709             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1710             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1711
1712             }
1713
1714             /**************************
1715              * CALCULATE INTERACTIONS *
1716              **************************/
1717
1718             if (gmx_mm_any_lt(rsq21,rcutoff2))
1719             {
1720
1721             r21              = _mm_mul_ps(rsq21,rinv21);
1722
1723             /* EWALD ELECTROSTATICS */
1724
1725             /* Analytical PME correction */
1726             zeta2            = _mm_mul_ps(beta2,rsq21);
1727             rinv3            = _mm_mul_ps(rinvsq21,rinv21);
1728             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1729             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1730             felec            = _mm_mul_ps(qq21,felec);
1731
1732             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1733
1734             fscal            = felec;
1735
1736             fscal            = _mm_and_ps(fscal,cutoff_mask);
1737
1738              /* Update vectorial force */
1739             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1740             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1741             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1742
1743             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1744             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1745             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1746
1747             }
1748
1749             /**************************
1750              * CALCULATE INTERACTIONS *
1751              **************************/
1752
1753             if (gmx_mm_any_lt(rsq22,rcutoff2))
1754             {
1755
1756             r22              = _mm_mul_ps(rsq22,rinv22);
1757
1758             /* EWALD ELECTROSTATICS */
1759
1760             /* Analytical PME correction */
1761             zeta2            = _mm_mul_ps(beta2,rsq22);
1762             rinv3            = _mm_mul_ps(rinvsq22,rinv22);
1763             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1764             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1765             felec            = _mm_mul_ps(qq22,felec);
1766
1767             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1768
1769             fscal            = felec;
1770
1771             fscal            = _mm_and_ps(fscal,cutoff_mask);
1772
1773              /* Update vectorial force */
1774             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1775             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1776             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1777
1778             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1779             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1780             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1781
1782             }
1783
1784             fjptrA             = f+j_coord_offsetA;
1785             fjptrB             = f+j_coord_offsetB;
1786             fjptrC             = f+j_coord_offsetC;
1787             fjptrD             = f+j_coord_offsetD;
1788
1789             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1790                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1791
1792             /* Inner loop uses 279 flops */
1793         }
1794
1795         if(jidx<j_index_end)
1796         {
1797
1798             /* Get j neighbor index, and coordinate index */
1799             jnrlistA         = jjnr[jidx];
1800             jnrlistB         = jjnr[jidx+1];
1801             jnrlistC         = jjnr[jidx+2];
1802             jnrlistD         = jjnr[jidx+3];
1803             /* Sign of each element will be negative for non-real atoms.
1804              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1805              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1806              */
1807             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1808             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1809             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1810             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1811             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1812             j_coord_offsetA  = DIM*jnrA;
1813             j_coord_offsetB  = DIM*jnrB;
1814             j_coord_offsetC  = DIM*jnrC;
1815             j_coord_offsetD  = DIM*jnrD;
1816
1817             /* load j atom coordinates */
1818             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1819                                               x+j_coord_offsetC,x+j_coord_offsetD,
1820                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1821
1822             /* Calculate displacement vector */
1823             dx00             = _mm_sub_ps(ix0,jx0);
1824             dy00             = _mm_sub_ps(iy0,jy0);
1825             dz00             = _mm_sub_ps(iz0,jz0);
1826             dx01             = _mm_sub_ps(ix0,jx1);
1827             dy01             = _mm_sub_ps(iy0,jy1);
1828             dz01             = _mm_sub_ps(iz0,jz1);
1829             dx02             = _mm_sub_ps(ix0,jx2);
1830             dy02             = _mm_sub_ps(iy0,jy2);
1831             dz02             = _mm_sub_ps(iz0,jz2);
1832             dx10             = _mm_sub_ps(ix1,jx0);
1833             dy10             = _mm_sub_ps(iy1,jy0);
1834             dz10             = _mm_sub_ps(iz1,jz0);
1835             dx11             = _mm_sub_ps(ix1,jx1);
1836             dy11             = _mm_sub_ps(iy1,jy1);
1837             dz11             = _mm_sub_ps(iz1,jz1);
1838             dx12             = _mm_sub_ps(ix1,jx2);
1839             dy12             = _mm_sub_ps(iy1,jy2);
1840             dz12             = _mm_sub_ps(iz1,jz2);
1841             dx20             = _mm_sub_ps(ix2,jx0);
1842             dy20             = _mm_sub_ps(iy2,jy0);
1843             dz20             = _mm_sub_ps(iz2,jz0);
1844             dx21             = _mm_sub_ps(ix2,jx1);
1845             dy21             = _mm_sub_ps(iy2,jy1);
1846             dz21             = _mm_sub_ps(iz2,jz1);
1847             dx22             = _mm_sub_ps(ix2,jx2);
1848             dy22             = _mm_sub_ps(iy2,jy2);
1849             dz22             = _mm_sub_ps(iz2,jz2);
1850
1851             /* Calculate squared distance and things based on it */
1852             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1853             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1854             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1855             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1856             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1857             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1858             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1859             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1860             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1861
1862             rinv00           = avx128fma_invsqrt_f(rsq00);
1863             rinv01           = avx128fma_invsqrt_f(rsq01);
1864             rinv02           = avx128fma_invsqrt_f(rsq02);
1865             rinv10           = avx128fma_invsqrt_f(rsq10);
1866             rinv11           = avx128fma_invsqrt_f(rsq11);
1867             rinv12           = avx128fma_invsqrt_f(rsq12);
1868             rinv20           = avx128fma_invsqrt_f(rsq20);
1869             rinv21           = avx128fma_invsqrt_f(rsq21);
1870             rinv22           = avx128fma_invsqrt_f(rsq22);
1871
1872             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1873             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1874             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1875             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1876             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1877             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1878             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1879             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1880             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1881
1882             fjx0             = _mm_setzero_ps();
1883             fjy0             = _mm_setzero_ps();
1884             fjz0             = _mm_setzero_ps();
1885             fjx1             = _mm_setzero_ps();
1886             fjy1             = _mm_setzero_ps();
1887             fjz1             = _mm_setzero_ps();
1888             fjx2             = _mm_setzero_ps();
1889             fjy2             = _mm_setzero_ps();
1890             fjz2             = _mm_setzero_ps();
1891
1892             /**************************
1893              * CALCULATE INTERACTIONS *
1894              **************************/
1895
1896             if (gmx_mm_any_lt(rsq00,rcutoff2))
1897             {
1898
1899             r00              = _mm_mul_ps(rsq00,rinv00);
1900             r00              = _mm_andnot_ps(dummy_mask,r00);
1901
1902             /* EWALD ELECTROSTATICS */
1903
1904             /* Analytical PME correction */
1905             zeta2            = _mm_mul_ps(beta2,rsq00);
1906             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
1907             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1908             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1909             felec            = _mm_mul_ps(qq00,felec);
1910
1911             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1912
1913             fscal            = felec;
1914
1915             fscal            = _mm_and_ps(fscal,cutoff_mask);
1916
1917             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1918
1919              /* Update vectorial force */
1920             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1921             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1922             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1923
1924             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1925             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1926             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1927
1928             }
1929
1930             /**************************
1931              * CALCULATE INTERACTIONS *
1932              **************************/
1933
1934             if (gmx_mm_any_lt(rsq01,rcutoff2))
1935             {
1936
1937             r01              = _mm_mul_ps(rsq01,rinv01);
1938             r01              = _mm_andnot_ps(dummy_mask,r01);
1939
1940             /* EWALD ELECTROSTATICS */
1941
1942             /* Analytical PME correction */
1943             zeta2            = _mm_mul_ps(beta2,rsq01);
1944             rinv3            = _mm_mul_ps(rinvsq01,rinv01);
1945             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1946             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1947             felec            = _mm_mul_ps(qq01,felec);
1948
1949             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
1950
1951             fscal            = felec;
1952
1953             fscal            = _mm_and_ps(fscal,cutoff_mask);
1954
1955             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1956
1957              /* Update vectorial force */
1958             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1959             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1960             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1961
1962             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1963             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1964             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1965
1966             }
1967
1968             /**************************
1969              * CALCULATE INTERACTIONS *
1970              **************************/
1971
1972             if (gmx_mm_any_lt(rsq02,rcutoff2))
1973             {
1974
1975             r02              = _mm_mul_ps(rsq02,rinv02);
1976             r02              = _mm_andnot_ps(dummy_mask,r02);
1977
1978             /* EWALD ELECTROSTATICS */
1979
1980             /* Analytical PME correction */
1981             zeta2            = _mm_mul_ps(beta2,rsq02);
1982             rinv3            = _mm_mul_ps(rinvsq02,rinv02);
1983             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
1984             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1985             felec            = _mm_mul_ps(qq02,felec);
1986
1987             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
1988
1989             fscal            = felec;
1990
1991             fscal            = _mm_and_ps(fscal,cutoff_mask);
1992
1993             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1994
1995              /* Update vectorial force */
1996             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1997             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1998             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1999
2000             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
2001             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
2002             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
2003
2004             }
2005
2006             /**************************
2007              * CALCULATE INTERACTIONS *
2008              **************************/
2009
2010             if (gmx_mm_any_lt(rsq10,rcutoff2))
2011             {
2012
2013             r10              = _mm_mul_ps(rsq10,rinv10);
2014             r10              = _mm_andnot_ps(dummy_mask,r10);
2015
2016             /* EWALD ELECTROSTATICS */
2017
2018             /* Analytical PME correction */
2019             zeta2            = _mm_mul_ps(beta2,rsq10);
2020             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
2021             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2022             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2023             felec            = _mm_mul_ps(qq10,felec);
2024
2025             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
2026
2027             fscal            = felec;
2028
2029             fscal            = _mm_and_ps(fscal,cutoff_mask);
2030
2031             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2032
2033              /* Update vectorial force */
2034             fix1             = _mm_macc_ps(dx10,fscal,fix1);
2035             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
2036             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
2037
2038             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
2039             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
2040             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
2041
2042             }
2043
2044             /**************************
2045              * CALCULATE INTERACTIONS *
2046              **************************/
2047
2048             if (gmx_mm_any_lt(rsq11,rcutoff2))
2049             {
2050
2051             r11              = _mm_mul_ps(rsq11,rinv11);
2052             r11              = _mm_andnot_ps(dummy_mask,r11);
2053
2054             /* EWALD ELECTROSTATICS */
2055
2056             /* Analytical PME correction */
2057             zeta2            = _mm_mul_ps(beta2,rsq11);
2058             rinv3            = _mm_mul_ps(rinvsq11,rinv11);
2059             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2060             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2061             felec            = _mm_mul_ps(qq11,felec);
2062
2063             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
2064
2065             fscal            = felec;
2066
2067             fscal            = _mm_and_ps(fscal,cutoff_mask);
2068
2069             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2070
2071              /* Update vectorial force */
2072             fix1             = _mm_macc_ps(dx11,fscal,fix1);
2073             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
2074             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
2075
2076             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
2077             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
2078             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
2079
2080             }
2081
2082             /**************************
2083              * CALCULATE INTERACTIONS *
2084              **************************/
2085
2086             if (gmx_mm_any_lt(rsq12,rcutoff2))
2087             {
2088
2089             r12              = _mm_mul_ps(rsq12,rinv12);
2090             r12              = _mm_andnot_ps(dummy_mask,r12);
2091
2092             /* EWALD ELECTROSTATICS */
2093
2094             /* Analytical PME correction */
2095             zeta2            = _mm_mul_ps(beta2,rsq12);
2096             rinv3            = _mm_mul_ps(rinvsq12,rinv12);
2097             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2098             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2099             felec            = _mm_mul_ps(qq12,felec);
2100
2101             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
2102
2103             fscal            = felec;
2104
2105             fscal            = _mm_and_ps(fscal,cutoff_mask);
2106
2107             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2108
2109              /* Update vectorial force */
2110             fix1             = _mm_macc_ps(dx12,fscal,fix1);
2111             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
2112             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
2113
2114             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
2115             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
2116             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
2117
2118             }
2119
2120             /**************************
2121              * CALCULATE INTERACTIONS *
2122              **************************/
2123
2124             if (gmx_mm_any_lt(rsq20,rcutoff2))
2125             {
2126
2127             r20              = _mm_mul_ps(rsq20,rinv20);
2128             r20              = _mm_andnot_ps(dummy_mask,r20);
2129
2130             /* EWALD ELECTROSTATICS */
2131
2132             /* Analytical PME correction */
2133             zeta2            = _mm_mul_ps(beta2,rsq20);
2134             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
2135             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2136             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2137             felec            = _mm_mul_ps(qq20,felec);
2138
2139             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
2140
2141             fscal            = felec;
2142
2143             fscal            = _mm_and_ps(fscal,cutoff_mask);
2144
2145             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2146
2147              /* Update vectorial force */
2148             fix2             = _mm_macc_ps(dx20,fscal,fix2);
2149             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
2150             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
2151
2152             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
2153             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
2154             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
2155
2156             }
2157
2158             /**************************
2159              * CALCULATE INTERACTIONS *
2160              **************************/
2161
2162             if (gmx_mm_any_lt(rsq21,rcutoff2))
2163             {
2164
2165             r21              = _mm_mul_ps(rsq21,rinv21);
2166             r21              = _mm_andnot_ps(dummy_mask,r21);
2167
2168             /* EWALD ELECTROSTATICS */
2169
2170             /* Analytical PME correction */
2171             zeta2            = _mm_mul_ps(beta2,rsq21);
2172             rinv3            = _mm_mul_ps(rinvsq21,rinv21);
2173             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2174             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2175             felec            = _mm_mul_ps(qq21,felec);
2176
2177             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
2178
2179             fscal            = felec;
2180
2181             fscal            = _mm_and_ps(fscal,cutoff_mask);
2182
2183             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2184
2185              /* Update vectorial force */
2186             fix2             = _mm_macc_ps(dx21,fscal,fix2);
2187             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
2188             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
2189
2190             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
2191             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
2192             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
2193
2194             }
2195
2196             /**************************
2197              * CALCULATE INTERACTIONS *
2198              **************************/
2199
2200             if (gmx_mm_any_lt(rsq22,rcutoff2))
2201             {
2202
2203             r22              = _mm_mul_ps(rsq22,rinv22);
2204             r22              = _mm_andnot_ps(dummy_mask,r22);
2205
2206             /* EWALD ELECTROSTATICS */
2207
2208             /* Analytical PME correction */
2209             zeta2            = _mm_mul_ps(beta2,rsq22);
2210             rinv3            = _mm_mul_ps(rinvsq22,rinv22);
2211             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
2212             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
2213             felec            = _mm_mul_ps(qq22,felec);
2214
2215             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
2216
2217             fscal            = felec;
2218
2219             fscal            = _mm_and_ps(fscal,cutoff_mask);
2220
2221             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2222
2223              /* Update vectorial force */
2224             fix2             = _mm_macc_ps(dx22,fscal,fix2);
2225             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
2226             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
2227
2228             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
2229             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
2230             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
2231
2232             }
2233
2234             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2235             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2236             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2237             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2238
2239             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2240                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2241
2242             /* Inner loop uses 288 flops */
2243         }
2244
2245         /* End of innermost loop */
2246
2247         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2248                                               f+i_coord_offset,fshift+i_shift_offset);
2249
2250         /* Increment number of inner iterations */
2251         inneriter                  += j_index_end - j_index_start;
2252
2253         /* Outer loop uses 18 flops */
2254     }
2255
2256     /* Increment number of outer iterations */
2257     outeriter        += nri;
2258
2259     /* Update outer/inner flops */
2260
2261     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_F,outeriter*18 + inneriter*288);
2262 }