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