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