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