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