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