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