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