Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRF_VdwCSTab_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_ElecRF_VdwCSTab_GeomW3W3_VF_avx_128_fma_single
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            CubicSplineTable
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRF_VdwCSTab_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     int              nvdwtype;
106     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
107     int              *vdwtype;
108     real             *vdwparam;
109     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
110     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
111     __m128i          vfitab;
112     __m128i          ifour       = _mm_set1_epi32(4);
113     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
114     real             *vftab;
115     __m128           dummy_mask,cutoff_mask;
116     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
117     __m128           one     = _mm_set1_ps(1.0);
118     __m128           two     = _mm_set1_ps(2.0);
119     x                = xx[0];
120     f                = ff[0];
121
122     nri              = nlist->nri;
123     iinr             = nlist->iinr;
124     jindex           = nlist->jindex;
125     jjnr             = nlist->jjnr;
126     shiftidx         = nlist->shift;
127     gid              = nlist->gid;
128     shiftvec         = fr->shift_vec[0];
129     fshift           = fr->fshift[0];
130     facel            = _mm_set1_ps(fr->ic->epsfac);
131     charge           = mdatoms->chargeA;
132     krf              = _mm_set1_ps(fr->ic->k_rf);
133     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
134     crf              = _mm_set1_ps(fr->ic->c_rf);
135     nvdwtype         = fr->ntype;
136     vdwparam         = fr->nbfp;
137     vdwtype          = mdatoms->typeA;
138
139     vftab            = kernel_data->table_vdw->data;
140     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
141
142     /* Setup water-specific parameters */
143     inr              = nlist->iinr[0];
144     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
145     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
146     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
147     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
148
149     jq0              = _mm_set1_ps(charge[inr+0]);
150     jq1              = _mm_set1_ps(charge[inr+1]);
151     jq2              = _mm_set1_ps(charge[inr+2]);
152     vdwjidx0A        = 2*vdwtype[inr+0];
153     qq00             = _mm_mul_ps(iq0,jq0);
154     c6_00            = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
155     c12_00           = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
156     qq01             = _mm_mul_ps(iq0,jq1);
157     qq02             = _mm_mul_ps(iq0,jq2);
158     qq10             = _mm_mul_ps(iq1,jq0);
159     qq11             = _mm_mul_ps(iq1,jq1);
160     qq12             = _mm_mul_ps(iq1,jq2);
161     qq20             = _mm_mul_ps(iq2,jq0);
162     qq21             = _mm_mul_ps(iq2,jq1);
163     qq22             = _mm_mul_ps(iq2,jq2);
164
165     /* Avoid stupid compiler warnings */
166     jnrA = jnrB = jnrC = jnrD = 0;
167     j_coord_offsetA = 0;
168     j_coord_offsetB = 0;
169     j_coord_offsetC = 0;
170     j_coord_offsetD = 0;
171
172     outeriter        = 0;
173     inneriter        = 0;
174
175     for(iidx=0;iidx<4*DIM;iidx++)
176     {
177         scratch[iidx] = 0.0;
178     }
179
180     /* Start outer loop over neighborlists */
181     for(iidx=0; iidx<nri; iidx++)
182     {
183         /* Load shift vector for this list */
184         i_shift_offset   = DIM*shiftidx[iidx];
185
186         /* Load limits for loop over neighbors */
187         j_index_start    = jindex[iidx];
188         j_index_end      = jindex[iidx+1];
189
190         /* Get outer coordinate index */
191         inr              = iinr[iidx];
192         i_coord_offset   = DIM*inr;
193
194         /* Load i particle coords and add shift vector */
195         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
196                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
197
198         fix0             = _mm_setzero_ps();
199         fiy0             = _mm_setzero_ps();
200         fiz0             = _mm_setzero_ps();
201         fix1             = _mm_setzero_ps();
202         fiy1             = _mm_setzero_ps();
203         fiz1             = _mm_setzero_ps();
204         fix2             = _mm_setzero_ps();
205         fiy2             = _mm_setzero_ps();
206         fiz2             = _mm_setzero_ps();
207
208         /* Reset potential sums */
209         velecsum         = _mm_setzero_ps();
210         vvdwsum          = _mm_setzero_ps();
211
212         /* Start inner kernel loop */
213         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
214         {
215
216             /* Get j neighbor index, and coordinate index */
217             jnrA             = jjnr[jidx];
218             jnrB             = jjnr[jidx+1];
219             jnrC             = jjnr[jidx+2];
220             jnrD             = jjnr[jidx+3];
221             j_coord_offsetA  = DIM*jnrA;
222             j_coord_offsetB  = DIM*jnrB;
223             j_coord_offsetC  = DIM*jnrC;
224             j_coord_offsetD  = DIM*jnrD;
225
226             /* load j atom coordinates */
227             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
228                                               x+j_coord_offsetC,x+j_coord_offsetD,
229                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
230
231             /* Calculate displacement vector */
232             dx00             = _mm_sub_ps(ix0,jx0);
233             dy00             = _mm_sub_ps(iy0,jy0);
234             dz00             = _mm_sub_ps(iz0,jz0);
235             dx01             = _mm_sub_ps(ix0,jx1);
236             dy01             = _mm_sub_ps(iy0,jy1);
237             dz01             = _mm_sub_ps(iz0,jz1);
238             dx02             = _mm_sub_ps(ix0,jx2);
239             dy02             = _mm_sub_ps(iy0,jy2);
240             dz02             = _mm_sub_ps(iz0,jz2);
241             dx10             = _mm_sub_ps(ix1,jx0);
242             dy10             = _mm_sub_ps(iy1,jy0);
243             dz10             = _mm_sub_ps(iz1,jz0);
244             dx11             = _mm_sub_ps(ix1,jx1);
245             dy11             = _mm_sub_ps(iy1,jy1);
246             dz11             = _mm_sub_ps(iz1,jz1);
247             dx12             = _mm_sub_ps(ix1,jx2);
248             dy12             = _mm_sub_ps(iy1,jy2);
249             dz12             = _mm_sub_ps(iz1,jz2);
250             dx20             = _mm_sub_ps(ix2,jx0);
251             dy20             = _mm_sub_ps(iy2,jy0);
252             dz20             = _mm_sub_ps(iz2,jz0);
253             dx21             = _mm_sub_ps(ix2,jx1);
254             dy21             = _mm_sub_ps(iy2,jy1);
255             dz21             = _mm_sub_ps(iz2,jz1);
256             dx22             = _mm_sub_ps(ix2,jx2);
257             dy22             = _mm_sub_ps(iy2,jy2);
258             dz22             = _mm_sub_ps(iz2,jz2);
259
260             /* Calculate squared distance and things based on it */
261             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
262             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
263             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
264             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
265             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
266             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
267             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
268             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
269             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
270
271             rinv00           = avx128fma_invsqrt_f(rsq00);
272             rinv01           = avx128fma_invsqrt_f(rsq01);
273             rinv02           = avx128fma_invsqrt_f(rsq02);
274             rinv10           = avx128fma_invsqrt_f(rsq10);
275             rinv11           = avx128fma_invsqrt_f(rsq11);
276             rinv12           = avx128fma_invsqrt_f(rsq12);
277             rinv20           = avx128fma_invsqrt_f(rsq20);
278             rinv21           = avx128fma_invsqrt_f(rsq21);
279             rinv22           = avx128fma_invsqrt_f(rsq22);
280
281             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
282             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
283             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
284             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
285             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
286             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
287             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
288             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
289             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
290
291             fjx0             = _mm_setzero_ps();
292             fjy0             = _mm_setzero_ps();
293             fjz0             = _mm_setzero_ps();
294             fjx1             = _mm_setzero_ps();
295             fjy1             = _mm_setzero_ps();
296             fjz1             = _mm_setzero_ps();
297             fjx2             = _mm_setzero_ps();
298             fjy2             = _mm_setzero_ps();
299             fjz2             = _mm_setzero_ps();
300
301             /**************************
302              * CALCULATE INTERACTIONS *
303              **************************/
304
305             r00              = _mm_mul_ps(rsq00,rinv00);
306
307             /* Calculate table index by multiplying r with table scale and truncate to integer */
308             rt               = _mm_mul_ps(r00,vftabscale);
309             vfitab           = _mm_cvttps_epi32(rt);
310 #ifdef __XOP__
311             vfeps            = _mm_frcz_ps(rt);
312 #else
313             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
314 #endif
315             twovfeps         = _mm_add_ps(vfeps,vfeps);
316             vfitab           = _mm_slli_epi32(vfitab,3);
317
318             /* REACTION-FIELD ELECTROSTATICS */
319             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
320             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
321
322             /* CUBIC SPLINE TABLE DISPERSION */
323             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
324             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
325             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
326             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
327             _MM_TRANSPOSE4_PS(Y,F,G,H);
328             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
329             VV               = _mm_macc_ps(vfeps,Fp,Y);
330             vvdw6            = _mm_mul_ps(c6_00,VV);
331             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
332             fvdw6            = _mm_mul_ps(c6_00,FF);
333
334             /* CUBIC SPLINE TABLE REPULSION */
335             vfitab           = _mm_add_epi32(vfitab,ifour);
336             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
337             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
338             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
339             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
340             _MM_TRANSPOSE4_PS(Y,F,G,H);
341             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
342             VV               = _mm_macc_ps(vfeps,Fp,Y);
343             vvdw12           = _mm_mul_ps(c12_00,VV);
344             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
345             fvdw12           = _mm_mul_ps(c12_00,FF);
346             vvdw             = _mm_add_ps(vvdw12,vvdw6);
347             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
348
349             /* Update potential sum for this i atom from the interaction with this j atom. */
350             velecsum         = _mm_add_ps(velecsum,velec);
351             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
352
353             fscal            = _mm_add_ps(felec,fvdw);
354
355              /* Update vectorial force */
356             fix0             = _mm_macc_ps(dx00,fscal,fix0);
357             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
358             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
359
360             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
361             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
362             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
363
364             /**************************
365              * CALCULATE INTERACTIONS *
366              **************************/
367
368             /* REACTION-FIELD ELECTROSTATICS */
369             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
370             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
371
372             /* Update potential sum for this i atom from the interaction with this j atom. */
373             velecsum         = _mm_add_ps(velecsum,velec);
374
375             fscal            = felec;
376
377              /* Update vectorial force */
378             fix0             = _mm_macc_ps(dx01,fscal,fix0);
379             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
380             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
381
382             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
383             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
384             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
385
386             /**************************
387              * CALCULATE INTERACTIONS *
388              **************************/
389
390             /* REACTION-FIELD ELECTROSTATICS */
391             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
392             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
393
394             /* Update potential sum for this i atom from the interaction with this j atom. */
395             velecsum         = _mm_add_ps(velecsum,velec);
396
397             fscal            = felec;
398
399              /* Update vectorial force */
400             fix0             = _mm_macc_ps(dx02,fscal,fix0);
401             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
402             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
403
404             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
405             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
406             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
407
408             /**************************
409              * CALCULATE INTERACTIONS *
410              **************************/
411
412             /* REACTION-FIELD ELECTROSTATICS */
413             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
414             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
415
416             /* Update potential sum for this i atom from the interaction with this j atom. */
417             velecsum         = _mm_add_ps(velecsum,velec);
418
419             fscal            = felec;
420
421              /* Update vectorial force */
422             fix1             = _mm_macc_ps(dx10,fscal,fix1);
423             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
424             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
425
426             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
427             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
428             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
429
430             /**************************
431              * CALCULATE INTERACTIONS *
432              **************************/
433
434             /* REACTION-FIELD ELECTROSTATICS */
435             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
436             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
437
438             /* Update potential sum for this i atom from the interaction with this j atom. */
439             velecsum         = _mm_add_ps(velecsum,velec);
440
441             fscal            = felec;
442
443              /* Update vectorial force */
444             fix1             = _mm_macc_ps(dx11,fscal,fix1);
445             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
446             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
447
448             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
449             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
450             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
451
452             /**************************
453              * CALCULATE INTERACTIONS *
454              **************************/
455
456             /* REACTION-FIELD ELECTROSTATICS */
457             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
458             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
459
460             /* Update potential sum for this i atom from the interaction with this j atom. */
461             velecsum         = _mm_add_ps(velecsum,velec);
462
463             fscal            = felec;
464
465              /* Update vectorial force */
466             fix1             = _mm_macc_ps(dx12,fscal,fix1);
467             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
468             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
469
470             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
471             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
472             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
473
474             /**************************
475              * CALCULATE INTERACTIONS *
476              **************************/
477
478             /* REACTION-FIELD ELECTROSTATICS */
479             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
480             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
481
482             /* Update potential sum for this i atom from the interaction with this j atom. */
483             velecsum         = _mm_add_ps(velecsum,velec);
484
485             fscal            = felec;
486
487              /* Update vectorial force */
488             fix2             = _mm_macc_ps(dx20,fscal,fix2);
489             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
490             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
491
492             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
493             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
494             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
495
496             /**************************
497              * CALCULATE INTERACTIONS *
498              **************************/
499
500             /* REACTION-FIELD ELECTROSTATICS */
501             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
502             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
503
504             /* Update potential sum for this i atom from the interaction with this j atom. */
505             velecsum         = _mm_add_ps(velecsum,velec);
506
507             fscal            = felec;
508
509              /* Update vectorial force */
510             fix2             = _mm_macc_ps(dx21,fscal,fix2);
511             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
512             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
513
514             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
515             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
516             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             /* REACTION-FIELD ELECTROSTATICS */
523             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
524             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
525
526             /* Update potential sum for this i atom from the interaction with this j atom. */
527             velecsum         = _mm_add_ps(velecsum,velec);
528
529             fscal            = felec;
530
531              /* Update vectorial force */
532             fix2             = _mm_macc_ps(dx22,fscal,fix2);
533             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
534             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
535
536             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
537             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
538             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
539
540             fjptrA             = f+j_coord_offsetA;
541             fjptrB             = f+j_coord_offsetB;
542             fjptrC             = f+j_coord_offsetC;
543             fjptrD             = f+j_coord_offsetD;
544
545             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
546                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
547
548             /* Inner loop uses 350 flops */
549         }
550
551         if(jidx<j_index_end)
552         {
553
554             /* Get j neighbor index, and coordinate index */
555             jnrlistA         = jjnr[jidx];
556             jnrlistB         = jjnr[jidx+1];
557             jnrlistC         = jjnr[jidx+2];
558             jnrlistD         = jjnr[jidx+3];
559             /* Sign of each element will be negative for non-real atoms.
560              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
561              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
562              */
563             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
564             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
565             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
566             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
567             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
568             j_coord_offsetA  = DIM*jnrA;
569             j_coord_offsetB  = DIM*jnrB;
570             j_coord_offsetC  = DIM*jnrC;
571             j_coord_offsetD  = DIM*jnrD;
572
573             /* load j atom coordinates */
574             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
575                                               x+j_coord_offsetC,x+j_coord_offsetD,
576                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
577
578             /* Calculate displacement vector */
579             dx00             = _mm_sub_ps(ix0,jx0);
580             dy00             = _mm_sub_ps(iy0,jy0);
581             dz00             = _mm_sub_ps(iz0,jz0);
582             dx01             = _mm_sub_ps(ix0,jx1);
583             dy01             = _mm_sub_ps(iy0,jy1);
584             dz01             = _mm_sub_ps(iz0,jz1);
585             dx02             = _mm_sub_ps(ix0,jx2);
586             dy02             = _mm_sub_ps(iy0,jy2);
587             dz02             = _mm_sub_ps(iz0,jz2);
588             dx10             = _mm_sub_ps(ix1,jx0);
589             dy10             = _mm_sub_ps(iy1,jy0);
590             dz10             = _mm_sub_ps(iz1,jz0);
591             dx11             = _mm_sub_ps(ix1,jx1);
592             dy11             = _mm_sub_ps(iy1,jy1);
593             dz11             = _mm_sub_ps(iz1,jz1);
594             dx12             = _mm_sub_ps(ix1,jx2);
595             dy12             = _mm_sub_ps(iy1,jy2);
596             dz12             = _mm_sub_ps(iz1,jz2);
597             dx20             = _mm_sub_ps(ix2,jx0);
598             dy20             = _mm_sub_ps(iy2,jy0);
599             dz20             = _mm_sub_ps(iz2,jz0);
600             dx21             = _mm_sub_ps(ix2,jx1);
601             dy21             = _mm_sub_ps(iy2,jy1);
602             dz21             = _mm_sub_ps(iz2,jz1);
603             dx22             = _mm_sub_ps(ix2,jx2);
604             dy22             = _mm_sub_ps(iy2,jy2);
605             dz22             = _mm_sub_ps(iz2,jz2);
606
607             /* Calculate squared distance and things based on it */
608             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
609             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
610             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
611             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
612             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
613             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
614             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
615             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
616             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
617
618             rinv00           = avx128fma_invsqrt_f(rsq00);
619             rinv01           = avx128fma_invsqrt_f(rsq01);
620             rinv02           = avx128fma_invsqrt_f(rsq02);
621             rinv10           = avx128fma_invsqrt_f(rsq10);
622             rinv11           = avx128fma_invsqrt_f(rsq11);
623             rinv12           = avx128fma_invsqrt_f(rsq12);
624             rinv20           = avx128fma_invsqrt_f(rsq20);
625             rinv21           = avx128fma_invsqrt_f(rsq21);
626             rinv22           = avx128fma_invsqrt_f(rsq22);
627
628             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
629             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
630             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
631             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
632             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
633             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
634             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
635             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
636             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
637
638             fjx0             = _mm_setzero_ps();
639             fjy0             = _mm_setzero_ps();
640             fjz0             = _mm_setzero_ps();
641             fjx1             = _mm_setzero_ps();
642             fjy1             = _mm_setzero_ps();
643             fjz1             = _mm_setzero_ps();
644             fjx2             = _mm_setzero_ps();
645             fjy2             = _mm_setzero_ps();
646             fjz2             = _mm_setzero_ps();
647
648             /**************************
649              * CALCULATE INTERACTIONS *
650              **************************/
651
652             r00              = _mm_mul_ps(rsq00,rinv00);
653             r00              = _mm_andnot_ps(dummy_mask,r00);
654
655             /* Calculate table index by multiplying r with table scale and truncate to integer */
656             rt               = _mm_mul_ps(r00,vftabscale);
657             vfitab           = _mm_cvttps_epi32(rt);
658 #ifdef __XOP__
659             vfeps            = _mm_frcz_ps(rt);
660 #else
661             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
662 #endif
663             twovfeps         = _mm_add_ps(vfeps,vfeps);
664             vfitab           = _mm_slli_epi32(vfitab,3);
665
666             /* REACTION-FIELD ELECTROSTATICS */
667             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
668             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
669
670             /* CUBIC SPLINE TABLE DISPERSION */
671             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
672             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
673             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
674             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
675             _MM_TRANSPOSE4_PS(Y,F,G,H);
676             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
677             VV               = _mm_macc_ps(vfeps,Fp,Y);
678             vvdw6            = _mm_mul_ps(c6_00,VV);
679             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
680             fvdw6            = _mm_mul_ps(c6_00,FF);
681
682             /* CUBIC SPLINE TABLE REPULSION */
683             vfitab           = _mm_add_epi32(vfitab,ifour);
684             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
685             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
686             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
687             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
688             _MM_TRANSPOSE4_PS(Y,F,G,H);
689             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
690             VV               = _mm_macc_ps(vfeps,Fp,Y);
691             vvdw12           = _mm_mul_ps(c12_00,VV);
692             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
693             fvdw12           = _mm_mul_ps(c12_00,FF);
694             vvdw             = _mm_add_ps(vvdw12,vvdw6);
695             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
696
697             /* Update potential sum for this i atom from the interaction with this j atom. */
698             velec            = _mm_andnot_ps(dummy_mask,velec);
699             velecsum         = _mm_add_ps(velecsum,velec);
700             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
701             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
702
703             fscal            = _mm_add_ps(felec,fvdw);
704
705             fscal            = _mm_andnot_ps(dummy_mask,fscal);
706
707              /* Update vectorial force */
708             fix0             = _mm_macc_ps(dx00,fscal,fix0);
709             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
710             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
711
712             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
713             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
714             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
715
716             /**************************
717              * CALCULATE INTERACTIONS *
718              **************************/
719
720             /* REACTION-FIELD ELECTROSTATICS */
721             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
722             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
723
724             /* Update potential sum for this i atom from the interaction with this j atom. */
725             velec            = _mm_andnot_ps(dummy_mask,velec);
726             velecsum         = _mm_add_ps(velecsum,velec);
727
728             fscal            = felec;
729
730             fscal            = _mm_andnot_ps(dummy_mask,fscal);
731
732              /* Update vectorial force */
733             fix0             = _mm_macc_ps(dx01,fscal,fix0);
734             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
735             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
736
737             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
738             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
739             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
740
741             /**************************
742              * CALCULATE INTERACTIONS *
743              **************************/
744
745             /* REACTION-FIELD ELECTROSTATICS */
746             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
747             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
748
749             /* Update potential sum for this i atom from the interaction with this j atom. */
750             velec            = _mm_andnot_ps(dummy_mask,velec);
751             velecsum         = _mm_add_ps(velecsum,velec);
752
753             fscal            = felec;
754
755             fscal            = _mm_andnot_ps(dummy_mask,fscal);
756
757              /* Update vectorial force */
758             fix0             = _mm_macc_ps(dx02,fscal,fix0);
759             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
760             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
761
762             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
763             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
764             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
765
766             /**************************
767              * CALCULATE INTERACTIONS *
768              **************************/
769
770             /* REACTION-FIELD ELECTROSTATICS */
771             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
772             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
773
774             /* Update potential sum for this i atom from the interaction with this j atom. */
775             velec            = _mm_andnot_ps(dummy_mask,velec);
776             velecsum         = _mm_add_ps(velecsum,velec);
777
778             fscal            = felec;
779
780             fscal            = _mm_andnot_ps(dummy_mask,fscal);
781
782              /* Update vectorial force */
783             fix1             = _mm_macc_ps(dx10,fscal,fix1);
784             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
785             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
786
787             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
788             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
789             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
790
791             /**************************
792              * CALCULATE INTERACTIONS *
793              **************************/
794
795             /* REACTION-FIELD ELECTROSTATICS */
796             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
797             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
798
799             /* Update potential sum for this i atom from the interaction with this j atom. */
800             velec            = _mm_andnot_ps(dummy_mask,velec);
801             velecsum         = _mm_add_ps(velecsum,velec);
802
803             fscal            = felec;
804
805             fscal            = _mm_andnot_ps(dummy_mask,fscal);
806
807              /* Update vectorial force */
808             fix1             = _mm_macc_ps(dx11,fscal,fix1);
809             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
810             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
811
812             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
813             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
814             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
815
816             /**************************
817              * CALCULATE INTERACTIONS *
818              **************************/
819
820             /* REACTION-FIELD ELECTROSTATICS */
821             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
822             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
823
824             /* Update potential sum for this i atom from the interaction with this j atom. */
825             velec            = _mm_andnot_ps(dummy_mask,velec);
826             velecsum         = _mm_add_ps(velecsum,velec);
827
828             fscal            = felec;
829
830             fscal            = _mm_andnot_ps(dummy_mask,fscal);
831
832              /* Update vectorial force */
833             fix1             = _mm_macc_ps(dx12,fscal,fix1);
834             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
835             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
836
837             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
838             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
839             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
840
841             /**************************
842              * CALCULATE INTERACTIONS *
843              **************************/
844
845             /* REACTION-FIELD ELECTROSTATICS */
846             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
847             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
848
849             /* Update potential sum for this i atom from the interaction with this j atom. */
850             velec            = _mm_andnot_ps(dummy_mask,velec);
851             velecsum         = _mm_add_ps(velecsum,velec);
852
853             fscal            = felec;
854
855             fscal            = _mm_andnot_ps(dummy_mask,fscal);
856
857              /* Update vectorial force */
858             fix2             = _mm_macc_ps(dx20,fscal,fix2);
859             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
860             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
861
862             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
863             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
864             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
865
866             /**************************
867              * CALCULATE INTERACTIONS *
868              **************************/
869
870             /* REACTION-FIELD ELECTROSTATICS */
871             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
872             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
873
874             /* Update potential sum for this i atom from the interaction with this j atom. */
875             velec            = _mm_andnot_ps(dummy_mask,velec);
876             velecsum         = _mm_add_ps(velecsum,velec);
877
878             fscal            = felec;
879
880             fscal            = _mm_andnot_ps(dummy_mask,fscal);
881
882              /* Update vectorial force */
883             fix2             = _mm_macc_ps(dx21,fscal,fix2);
884             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
885             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
886
887             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
888             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
889             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
890
891             /**************************
892              * CALCULATE INTERACTIONS *
893              **************************/
894
895             /* REACTION-FIELD ELECTROSTATICS */
896             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
897             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
898
899             /* Update potential sum for this i atom from the interaction with this j atom. */
900             velec            = _mm_andnot_ps(dummy_mask,velec);
901             velecsum         = _mm_add_ps(velecsum,velec);
902
903             fscal            = felec;
904
905             fscal            = _mm_andnot_ps(dummy_mask,fscal);
906
907              /* Update vectorial force */
908             fix2             = _mm_macc_ps(dx22,fscal,fix2);
909             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
910             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
911
912             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
913             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
914             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
915
916             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
917             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
918             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
919             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
920
921             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
922                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
923
924             /* Inner loop uses 351 flops */
925         }
926
927         /* End of innermost loop */
928
929         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
930                                               f+i_coord_offset,fshift+i_shift_offset);
931
932         ggid                        = gid[iidx];
933         /* Update potential energies */
934         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
935         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
936
937         /* Increment number of inner iterations */
938         inneriter                  += j_index_end - j_index_start;
939
940         /* Outer loop uses 20 flops */
941     }
942
943     /* Increment number of outer iterations */
944     outeriter        += nri;
945
946     /* Update outer/inner flops */
947
948     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*351);
949 }
950 /*
951  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_avx_128_fma_single
952  * Electrostatics interaction: ReactionField
953  * VdW interaction:            CubicSplineTable
954  * Geometry:                   Water3-Water3
955  * Calculate force/pot:        Force
956  */
957 void
958 nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_avx_128_fma_single
959                     (t_nblist                    * gmx_restrict       nlist,
960                      rvec                        * gmx_restrict          xx,
961                      rvec                        * gmx_restrict          ff,
962                      struct t_forcerec           * gmx_restrict          fr,
963                      t_mdatoms                   * gmx_restrict     mdatoms,
964                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
965                      t_nrnb                      * gmx_restrict        nrnb)
966 {
967     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
968      * just 0 for non-waters.
969      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
970      * jnr indices corresponding to data put in the four positions in the SIMD register.
971      */
972     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
973     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
974     int              jnrA,jnrB,jnrC,jnrD;
975     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
976     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
977     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
978     real             rcutoff_scalar;
979     real             *shiftvec,*fshift,*x,*f;
980     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
981     real             scratch[4*DIM];
982     __m128           fscal,rcutoff,rcutoff2,jidxall;
983     int              vdwioffset0;
984     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
985     int              vdwioffset1;
986     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
987     int              vdwioffset2;
988     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
989     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
990     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
991     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
992     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
993     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
994     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
995     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
996     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
997     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
998     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
999     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1000     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1001     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1002     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1003     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1004     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
1005     real             *charge;
1006     int              nvdwtype;
1007     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1008     int              *vdwtype;
1009     real             *vdwparam;
1010     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
1011     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
1012     __m128i          vfitab;
1013     __m128i          ifour       = _mm_set1_epi32(4);
1014     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
1015     real             *vftab;
1016     __m128           dummy_mask,cutoff_mask;
1017     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1018     __m128           one     = _mm_set1_ps(1.0);
1019     __m128           two     = _mm_set1_ps(2.0);
1020     x                = xx[0];
1021     f                = ff[0];
1022
1023     nri              = nlist->nri;
1024     iinr             = nlist->iinr;
1025     jindex           = nlist->jindex;
1026     jjnr             = nlist->jjnr;
1027     shiftidx         = nlist->shift;
1028     gid              = nlist->gid;
1029     shiftvec         = fr->shift_vec[0];
1030     fshift           = fr->fshift[0];
1031     facel            = _mm_set1_ps(fr->ic->epsfac);
1032     charge           = mdatoms->chargeA;
1033     krf              = _mm_set1_ps(fr->ic->k_rf);
1034     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
1035     crf              = _mm_set1_ps(fr->ic->c_rf);
1036     nvdwtype         = fr->ntype;
1037     vdwparam         = fr->nbfp;
1038     vdwtype          = mdatoms->typeA;
1039
1040     vftab            = kernel_data->table_vdw->data;
1041     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
1042
1043     /* Setup water-specific parameters */
1044     inr              = nlist->iinr[0];
1045     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1046     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1047     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1048     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
1049
1050     jq0              = _mm_set1_ps(charge[inr+0]);
1051     jq1              = _mm_set1_ps(charge[inr+1]);
1052     jq2              = _mm_set1_ps(charge[inr+2]);
1053     vdwjidx0A        = 2*vdwtype[inr+0];
1054     qq00             = _mm_mul_ps(iq0,jq0);
1055     c6_00            = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1056     c12_00           = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1057     qq01             = _mm_mul_ps(iq0,jq1);
1058     qq02             = _mm_mul_ps(iq0,jq2);
1059     qq10             = _mm_mul_ps(iq1,jq0);
1060     qq11             = _mm_mul_ps(iq1,jq1);
1061     qq12             = _mm_mul_ps(iq1,jq2);
1062     qq20             = _mm_mul_ps(iq2,jq0);
1063     qq21             = _mm_mul_ps(iq2,jq1);
1064     qq22             = _mm_mul_ps(iq2,jq2);
1065
1066     /* Avoid stupid compiler warnings */
1067     jnrA = jnrB = jnrC = jnrD = 0;
1068     j_coord_offsetA = 0;
1069     j_coord_offsetB = 0;
1070     j_coord_offsetC = 0;
1071     j_coord_offsetD = 0;
1072
1073     outeriter        = 0;
1074     inneriter        = 0;
1075
1076     for(iidx=0;iidx<4*DIM;iidx++)
1077     {
1078         scratch[iidx] = 0.0;
1079     }
1080
1081     /* Start outer loop over neighborlists */
1082     for(iidx=0; iidx<nri; iidx++)
1083     {
1084         /* Load shift vector for this list */
1085         i_shift_offset   = DIM*shiftidx[iidx];
1086
1087         /* Load limits for loop over neighbors */
1088         j_index_start    = jindex[iidx];
1089         j_index_end      = jindex[iidx+1];
1090
1091         /* Get outer coordinate index */
1092         inr              = iinr[iidx];
1093         i_coord_offset   = DIM*inr;
1094
1095         /* Load i particle coords and add shift vector */
1096         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1097                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1098
1099         fix0             = _mm_setzero_ps();
1100         fiy0             = _mm_setzero_ps();
1101         fiz0             = _mm_setzero_ps();
1102         fix1             = _mm_setzero_ps();
1103         fiy1             = _mm_setzero_ps();
1104         fiz1             = _mm_setzero_ps();
1105         fix2             = _mm_setzero_ps();
1106         fiy2             = _mm_setzero_ps();
1107         fiz2             = _mm_setzero_ps();
1108
1109         /* Start inner kernel loop */
1110         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1111         {
1112
1113             /* Get j neighbor index, and coordinate index */
1114             jnrA             = jjnr[jidx];
1115             jnrB             = jjnr[jidx+1];
1116             jnrC             = jjnr[jidx+2];
1117             jnrD             = jjnr[jidx+3];
1118             j_coord_offsetA  = DIM*jnrA;
1119             j_coord_offsetB  = DIM*jnrB;
1120             j_coord_offsetC  = DIM*jnrC;
1121             j_coord_offsetD  = DIM*jnrD;
1122
1123             /* load j atom coordinates */
1124             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1125                                               x+j_coord_offsetC,x+j_coord_offsetD,
1126                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1127
1128             /* Calculate displacement vector */
1129             dx00             = _mm_sub_ps(ix0,jx0);
1130             dy00             = _mm_sub_ps(iy0,jy0);
1131             dz00             = _mm_sub_ps(iz0,jz0);
1132             dx01             = _mm_sub_ps(ix0,jx1);
1133             dy01             = _mm_sub_ps(iy0,jy1);
1134             dz01             = _mm_sub_ps(iz0,jz1);
1135             dx02             = _mm_sub_ps(ix0,jx2);
1136             dy02             = _mm_sub_ps(iy0,jy2);
1137             dz02             = _mm_sub_ps(iz0,jz2);
1138             dx10             = _mm_sub_ps(ix1,jx0);
1139             dy10             = _mm_sub_ps(iy1,jy0);
1140             dz10             = _mm_sub_ps(iz1,jz0);
1141             dx11             = _mm_sub_ps(ix1,jx1);
1142             dy11             = _mm_sub_ps(iy1,jy1);
1143             dz11             = _mm_sub_ps(iz1,jz1);
1144             dx12             = _mm_sub_ps(ix1,jx2);
1145             dy12             = _mm_sub_ps(iy1,jy2);
1146             dz12             = _mm_sub_ps(iz1,jz2);
1147             dx20             = _mm_sub_ps(ix2,jx0);
1148             dy20             = _mm_sub_ps(iy2,jy0);
1149             dz20             = _mm_sub_ps(iz2,jz0);
1150             dx21             = _mm_sub_ps(ix2,jx1);
1151             dy21             = _mm_sub_ps(iy2,jy1);
1152             dz21             = _mm_sub_ps(iz2,jz1);
1153             dx22             = _mm_sub_ps(ix2,jx2);
1154             dy22             = _mm_sub_ps(iy2,jy2);
1155             dz22             = _mm_sub_ps(iz2,jz2);
1156
1157             /* Calculate squared distance and things based on it */
1158             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1159             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1160             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1161             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1162             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1163             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1164             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1165             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1166             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1167
1168             rinv00           = avx128fma_invsqrt_f(rsq00);
1169             rinv01           = avx128fma_invsqrt_f(rsq01);
1170             rinv02           = avx128fma_invsqrt_f(rsq02);
1171             rinv10           = avx128fma_invsqrt_f(rsq10);
1172             rinv11           = avx128fma_invsqrt_f(rsq11);
1173             rinv12           = avx128fma_invsqrt_f(rsq12);
1174             rinv20           = avx128fma_invsqrt_f(rsq20);
1175             rinv21           = avx128fma_invsqrt_f(rsq21);
1176             rinv22           = avx128fma_invsqrt_f(rsq22);
1177
1178             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1179             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1180             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1181             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1182             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1183             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1184             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1185             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1186             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1187
1188             fjx0             = _mm_setzero_ps();
1189             fjy0             = _mm_setzero_ps();
1190             fjz0             = _mm_setzero_ps();
1191             fjx1             = _mm_setzero_ps();
1192             fjy1             = _mm_setzero_ps();
1193             fjz1             = _mm_setzero_ps();
1194             fjx2             = _mm_setzero_ps();
1195             fjy2             = _mm_setzero_ps();
1196             fjz2             = _mm_setzero_ps();
1197
1198             /**************************
1199              * CALCULATE INTERACTIONS *
1200              **************************/
1201
1202             r00              = _mm_mul_ps(rsq00,rinv00);
1203
1204             /* Calculate table index by multiplying r with table scale and truncate to integer */
1205             rt               = _mm_mul_ps(r00,vftabscale);
1206             vfitab           = _mm_cvttps_epi32(rt);
1207 #ifdef __XOP__
1208             vfeps            = _mm_frcz_ps(rt);
1209 #else
1210             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1211 #endif
1212             twovfeps         = _mm_add_ps(vfeps,vfeps);
1213             vfitab           = _mm_slli_epi32(vfitab,3);
1214
1215             /* REACTION-FIELD ELECTROSTATICS */
1216             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1217
1218             /* CUBIC SPLINE TABLE DISPERSION */
1219             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1220             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1221             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1222             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1223             _MM_TRANSPOSE4_PS(Y,F,G,H);
1224             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1225             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1226             fvdw6            = _mm_mul_ps(c6_00,FF);
1227
1228             /* CUBIC SPLINE TABLE REPULSION */
1229             vfitab           = _mm_add_epi32(vfitab,ifour);
1230             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1231             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1232             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1233             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1234             _MM_TRANSPOSE4_PS(Y,F,G,H);
1235             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1236             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1237             fvdw12           = _mm_mul_ps(c12_00,FF);
1238             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1239
1240             fscal            = _mm_add_ps(felec,fvdw);
1241
1242              /* Update vectorial force */
1243             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1244             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1245             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1246
1247             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1248             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1249             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1250
1251             /**************************
1252              * CALCULATE INTERACTIONS *
1253              **************************/
1254
1255             /* REACTION-FIELD ELECTROSTATICS */
1256             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1257
1258             fscal            = felec;
1259
1260              /* Update vectorial force */
1261             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1262             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1263             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1264
1265             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1266             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1267             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1268
1269             /**************************
1270              * CALCULATE INTERACTIONS *
1271              **************************/
1272
1273             /* REACTION-FIELD ELECTROSTATICS */
1274             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1275
1276             fscal            = felec;
1277
1278              /* Update vectorial force */
1279             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1280             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1281             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1282
1283             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1284             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1285             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1286
1287             /**************************
1288              * CALCULATE INTERACTIONS *
1289              **************************/
1290
1291             /* REACTION-FIELD ELECTROSTATICS */
1292             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1293
1294             fscal            = felec;
1295
1296              /* Update vectorial force */
1297             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1298             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1299             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1300
1301             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1302             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1303             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1304
1305             /**************************
1306              * CALCULATE INTERACTIONS *
1307              **************************/
1308
1309             /* REACTION-FIELD ELECTROSTATICS */
1310             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1311
1312             fscal            = felec;
1313
1314              /* Update vectorial force */
1315             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1316             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1317             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1318
1319             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1320             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1321             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1322
1323             /**************************
1324              * CALCULATE INTERACTIONS *
1325              **************************/
1326
1327             /* REACTION-FIELD ELECTROSTATICS */
1328             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1329
1330             fscal            = felec;
1331
1332              /* Update vectorial force */
1333             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1334             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1335             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1336
1337             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1338             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1339             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1340
1341             /**************************
1342              * CALCULATE INTERACTIONS *
1343              **************************/
1344
1345             /* REACTION-FIELD ELECTROSTATICS */
1346             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1347
1348             fscal            = felec;
1349
1350              /* Update vectorial force */
1351             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1352             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1353             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1354
1355             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1356             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1357             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1358
1359             /**************************
1360              * CALCULATE INTERACTIONS *
1361              **************************/
1362
1363             /* REACTION-FIELD ELECTROSTATICS */
1364             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1365
1366             fscal            = felec;
1367
1368              /* Update vectorial force */
1369             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1370             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1371             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1372
1373             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1374             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1375             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1376
1377             /**************************
1378              * CALCULATE INTERACTIONS *
1379              **************************/
1380
1381             /* REACTION-FIELD ELECTROSTATICS */
1382             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1383
1384             fscal            = felec;
1385
1386              /* Update vectorial force */
1387             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1388             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1389             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1390
1391             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1392             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1393             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1394
1395             fjptrA             = f+j_coord_offsetA;
1396             fjptrB             = f+j_coord_offsetB;
1397             fjptrC             = f+j_coord_offsetC;
1398             fjptrD             = f+j_coord_offsetD;
1399
1400             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1401                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1402
1403             /* Inner loop uses 297 flops */
1404         }
1405
1406         if(jidx<j_index_end)
1407         {
1408
1409             /* Get j neighbor index, and coordinate index */
1410             jnrlistA         = jjnr[jidx];
1411             jnrlistB         = jjnr[jidx+1];
1412             jnrlistC         = jjnr[jidx+2];
1413             jnrlistD         = jjnr[jidx+3];
1414             /* Sign of each element will be negative for non-real atoms.
1415              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1416              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1417              */
1418             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1419             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1420             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1421             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1422             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1423             j_coord_offsetA  = DIM*jnrA;
1424             j_coord_offsetB  = DIM*jnrB;
1425             j_coord_offsetC  = DIM*jnrC;
1426             j_coord_offsetD  = DIM*jnrD;
1427
1428             /* load j atom coordinates */
1429             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1430                                               x+j_coord_offsetC,x+j_coord_offsetD,
1431                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1432
1433             /* Calculate displacement vector */
1434             dx00             = _mm_sub_ps(ix0,jx0);
1435             dy00             = _mm_sub_ps(iy0,jy0);
1436             dz00             = _mm_sub_ps(iz0,jz0);
1437             dx01             = _mm_sub_ps(ix0,jx1);
1438             dy01             = _mm_sub_ps(iy0,jy1);
1439             dz01             = _mm_sub_ps(iz0,jz1);
1440             dx02             = _mm_sub_ps(ix0,jx2);
1441             dy02             = _mm_sub_ps(iy0,jy2);
1442             dz02             = _mm_sub_ps(iz0,jz2);
1443             dx10             = _mm_sub_ps(ix1,jx0);
1444             dy10             = _mm_sub_ps(iy1,jy0);
1445             dz10             = _mm_sub_ps(iz1,jz0);
1446             dx11             = _mm_sub_ps(ix1,jx1);
1447             dy11             = _mm_sub_ps(iy1,jy1);
1448             dz11             = _mm_sub_ps(iz1,jz1);
1449             dx12             = _mm_sub_ps(ix1,jx2);
1450             dy12             = _mm_sub_ps(iy1,jy2);
1451             dz12             = _mm_sub_ps(iz1,jz2);
1452             dx20             = _mm_sub_ps(ix2,jx0);
1453             dy20             = _mm_sub_ps(iy2,jy0);
1454             dz20             = _mm_sub_ps(iz2,jz0);
1455             dx21             = _mm_sub_ps(ix2,jx1);
1456             dy21             = _mm_sub_ps(iy2,jy1);
1457             dz21             = _mm_sub_ps(iz2,jz1);
1458             dx22             = _mm_sub_ps(ix2,jx2);
1459             dy22             = _mm_sub_ps(iy2,jy2);
1460             dz22             = _mm_sub_ps(iz2,jz2);
1461
1462             /* Calculate squared distance and things based on it */
1463             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1464             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1465             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1466             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1467             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1468             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1469             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1470             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1471             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1472
1473             rinv00           = avx128fma_invsqrt_f(rsq00);
1474             rinv01           = avx128fma_invsqrt_f(rsq01);
1475             rinv02           = avx128fma_invsqrt_f(rsq02);
1476             rinv10           = avx128fma_invsqrt_f(rsq10);
1477             rinv11           = avx128fma_invsqrt_f(rsq11);
1478             rinv12           = avx128fma_invsqrt_f(rsq12);
1479             rinv20           = avx128fma_invsqrt_f(rsq20);
1480             rinv21           = avx128fma_invsqrt_f(rsq21);
1481             rinv22           = avx128fma_invsqrt_f(rsq22);
1482
1483             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1484             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1485             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1486             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1487             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1488             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1489             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1490             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1491             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1492
1493             fjx0             = _mm_setzero_ps();
1494             fjy0             = _mm_setzero_ps();
1495             fjz0             = _mm_setzero_ps();
1496             fjx1             = _mm_setzero_ps();
1497             fjy1             = _mm_setzero_ps();
1498             fjz1             = _mm_setzero_ps();
1499             fjx2             = _mm_setzero_ps();
1500             fjy2             = _mm_setzero_ps();
1501             fjz2             = _mm_setzero_ps();
1502
1503             /**************************
1504              * CALCULATE INTERACTIONS *
1505              **************************/
1506
1507             r00              = _mm_mul_ps(rsq00,rinv00);
1508             r00              = _mm_andnot_ps(dummy_mask,r00);
1509
1510             /* Calculate table index by multiplying r with table scale and truncate to integer */
1511             rt               = _mm_mul_ps(r00,vftabscale);
1512             vfitab           = _mm_cvttps_epi32(rt);
1513 #ifdef __XOP__
1514             vfeps            = _mm_frcz_ps(rt);
1515 #else
1516             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1517 #endif
1518             twovfeps         = _mm_add_ps(vfeps,vfeps);
1519             vfitab           = _mm_slli_epi32(vfitab,3);
1520
1521             /* REACTION-FIELD ELECTROSTATICS */
1522             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1523
1524             /* CUBIC SPLINE TABLE DISPERSION */
1525             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1526             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1527             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1528             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1529             _MM_TRANSPOSE4_PS(Y,F,G,H);
1530             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1531             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1532             fvdw6            = _mm_mul_ps(c6_00,FF);
1533
1534             /* CUBIC SPLINE TABLE REPULSION */
1535             vfitab           = _mm_add_epi32(vfitab,ifour);
1536             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1537             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1538             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1539             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1540             _MM_TRANSPOSE4_PS(Y,F,G,H);
1541             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1542             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1543             fvdw12           = _mm_mul_ps(c12_00,FF);
1544             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1545
1546             fscal            = _mm_add_ps(felec,fvdw);
1547
1548             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1549
1550              /* Update vectorial force */
1551             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1552             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1553             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1554
1555             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1556             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1557             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1558
1559             /**************************
1560              * CALCULATE INTERACTIONS *
1561              **************************/
1562
1563             /* REACTION-FIELD ELECTROSTATICS */
1564             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1565
1566             fscal            = felec;
1567
1568             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1569
1570              /* Update vectorial force */
1571             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1572             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1573             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1574
1575             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1576             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1577             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1578
1579             /**************************
1580              * CALCULATE INTERACTIONS *
1581              **************************/
1582
1583             /* REACTION-FIELD ELECTROSTATICS */
1584             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1585
1586             fscal            = felec;
1587
1588             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1589
1590              /* Update vectorial force */
1591             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1592             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1593             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1594
1595             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1596             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1597             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1598
1599             /**************************
1600              * CALCULATE INTERACTIONS *
1601              **************************/
1602
1603             /* REACTION-FIELD ELECTROSTATICS */
1604             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1605
1606             fscal            = felec;
1607
1608             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1609
1610              /* Update vectorial force */
1611             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1612             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1613             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1614
1615             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1616             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1617             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1618
1619             /**************************
1620              * CALCULATE INTERACTIONS *
1621              **************************/
1622
1623             /* REACTION-FIELD ELECTROSTATICS */
1624             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1625
1626             fscal            = felec;
1627
1628             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1629
1630              /* Update vectorial force */
1631             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1632             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1633             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1634
1635             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1636             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1637             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1638
1639             /**************************
1640              * CALCULATE INTERACTIONS *
1641              **************************/
1642
1643             /* REACTION-FIELD ELECTROSTATICS */
1644             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1645
1646             fscal            = felec;
1647
1648             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1649
1650              /* Update vectorial force */
1651             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1652             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1653             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1654
1655             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1656             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1657             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1658
1659             /**************************
1660              * CALCULATE INTERACTIONS *
1661              **************************/
1662
1663             /* REACTION-FIELD ELECTROSTATICS */
1664             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1665
1666             fscal            = felec;
1667
1668             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1669
1670              /* Update vectorial force */
1671             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1672             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1673             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1674
1675             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1676             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1677             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1678
1679             /**************************
1680              * CALCULATE INTERACTIONS *
1681              **************************/
1682
1683             /* REACTION-FIELD ELECTROSTATICS */
1684             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1685
1686             fscal            = felec;
1687
1688             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1689
1690              /* Update vectorial force */
1691             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1692             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1693             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1694
1695             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1696             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1697             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1698
1699             /**************************
1700              * CALCULATE INTERACTIONS *
1701              **************************/
1702
1703             /* REACTION-FIELD ELECTROSTATICS */
1704             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1705
1706             fscal            = felec;
1707
1708             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1709
1710              /* Update vectorial force */
1711             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1712             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1713             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1714
1715             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1716             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1717             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1718
1719             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1720             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1721             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1722             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1723
1724             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1725                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1726
1727             /* Inner loop uses 298 flops */
1728         }
1729
1730         /* End of innermost loop */
1731
1732         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1733                                               f+i_coord_offset,fshift+i_shift_offset);
1734
1735         /* Increment number of inner iterations */
1736         inneriter                  += j_index_end - j_index_start;
1737
1738         /* Outer loop uses 18 flops */
1739     }
1740
1741     /* Increment number of outer iterations */
1742     outeriter        += nri;
1743
1744     /* Update outer/inner flops */
1745
1746     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);
1747 }