Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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 "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
54  * Electrostatics interaction: Coulomb
55  * VdW interaction:            LennardJones
56  * Geometry:                   Water4-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwioffset1;
88     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
89     int              vdwioffset2;
90     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91     int              vdwioffset3;
92     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
100     real             *charge;
101     int              nvdwtype;
102     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103     int              *vdwtype;
104     real             *vdwparam;
105     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
106     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
107     __m128           dummy_mask,cutoff_mask;
108     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109     __m128           one     = _mm_set1_ps(1.0);
110     __m128           two     = _mm_set1_ps(2.0);
111     x                = xx[0];
112     f                = ff[0];
113
114     nri              = nlist->nri;
115     iinr             = nlist->iinr;
116     jindex           = nlist->jindex;
117     jjnr             = nlist->jjnr;
118     shiftidx         = nlist->shift;
119     gid              = nlist->gid;
120     shiftvec         = fr->shift_vec[0];
121     fshift           = fr->fshift[0];
122     facel            = _mm_set1_ps(fr->epsfac);
123     charge           = mdatoms->chargeA;
124     nvdwtype         = fr->ntype;
125     vdwparam         = fr->nbfp;
126     vdwtype          = mdatoms->typeA;
127
128     /* Setup water-specific parameters */
129     inr              = nlist->iinr[0];
130     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
131     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
132     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
133     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
134
135     /* Avoid stupid compiler warnings */
136     jnrA = jnrB = jnrC = jnrD = 0;
137     j_coord_offsetA = 0;
138     j_coord_offsetB = 0;
139     j_coord_offsetC = 0;
140     j_coord_offsetD = 0;
141
142     outeriter        = 0;
143     inneriter        = 0;
144
145     for(iidx=0;iidx<4*DIM;iidx++)
146     {
147         scratch[iidx] = 0.0;
148     }
149
150     /* Start outer loop over neighborlists */
151     for(iidx=0; iidx<nri; iidx++)
152     {
153         /* Load shift vector for this list */
154         i_shift_offset   = DIM*shiftidx[iidx];
155
156         /* Load limits for loop over neighbors */
157         j_index_start    = jindex[iidx];
158         j_index_end      = jindex[iidx+1];
159
160         /* Get outer coordinate index */
161         inr              = iinr[iidx];
162         i_coord_offset   = DIM*inr;
163
164         /* Load i particle coords and add shift vector */
165         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
166                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
167
168         fix0             = _mm_setzero_ps();
169         fiy0             = _mm_setzero_ps();
170         fiz0             = _mm_setzero_ps();
171         fix1             = _mm_setzero_ps();
172         fiy1             = _mm_setzero_ps();
173         fiz1             = _mm_setzero_ps();
174         fix2             = _mm_setzero_ps();
175         fiy2             = _mm_setzero_ps();
176         fiz2             = _mm_setzero_ps();
177         fix3             = _mm_setzero_ps();
178         fiy3             = _mm_setzero_ps();
179         fiz3             = _mm_setzero_ps();
180
181         /* Reset potential sums */
182         velecsum         = _mm_setzero_ps();
183         vvdwsum          = _mm_setzero_ps();
184
185         /* Start inner kernel loop */
186         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
187         {
188
189             /* Get j neighbor index, and coordinate index */
190             jnrA             = jjnr[jidx];
191             jnrB             = jjnr[jidx+1];
192             jnrC             = jjnr[jidx+2];
193             jnrD             = jjnr[jidx+3];
194             j_coord_offsetA  = DIM*jnrA;
195             j_coord_offsetB  = DIM*jnrB;
196             j_coord_offsetC  = DIM*jnrC;
197             j_coord_offsetD  = DIM*jnrD;
198
199             /* load j atom coordinates */
200             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
201                                               x+j_coord_offsetC,x+j_coord_offsetD,
202                                               &jx0,&jy0,&jz0);
203
204             /* Calculate displacement vector */
205             dx00             = _mm_sub_ps(ix0,jx0);
206             dy00             = _mm_sub_ps(iy0,jy0);
207             dz00             = _mm_sub_ps(iz0,jz0);
208             dx10             = _mm_sub_ps(ix1,jx0);
209             dy10             = _mm_sub_ps(iy1,jy0);
210             dz10             = _mm_sub_ps(iz1,jz0);
211             dx20             = _mm_sub_ps(ix2,jx0);
212             dy20             = _mm_sub_ps(iy2,jy0);
213             dz20             = _mm_sub_ps(iz2,jz0);
214             dx30             = _mm_sub_ps(ix3,jx0);
215             dy30             = _mm_sub_ps(iy3,jy0);
216             dz30             = _mm_sub_ps(iz3,jz0);
217
218             /* Calculate squared distance and things based on it */
219             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
220             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
221             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
222             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
223
224             rinv10           = gmx_mm_invsqrt_ps(rsq10);
225             rinv20           = gmx_mm_invsqrt_ps(rsq20);
226             rinv30           = gmx_mm_invsqrt_ps(rsq30);
227
228             rinvsq00         = gmx_mm_inv_ps(rsq00);
229             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
230             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
231             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
232
233             /* Load parameters for j particles */
234             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
235                                                               charge+jnrC+0,charge+jnrD+0);
236             vdwjidx0A        = 2*vdwtype[jnrA+0];
237             vdwjidx0B        = 2*vdwtype[jnrB+0];
238             vdwjidx0C        = 2*vdwtype[jnrC+0];
239             vdwjidx0D        = 2*vdwtype[jnrD+0];
240
241             fjx0             = _mm_setzero_ps();
242             fjy0             = _mm_setzero_ps();
243             fjz0             = _mm_setzero_ps();
244
245             /**************************
246              * CALCULATE INTERACTIONS *
247              **************************/
248
249             /* Compute parameters for interactions between i and j atoms */
250             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
251                                          vdwparam+vdwioffset0+vdwjidx0B,
252                                          vdwparam+vdwioffset0+vdwjidx0C,
253                                          vdwparam+vdwioffset0+vdwjidx0D,
254                                          &c6_00,&c12_00);
255
256             /* LENNARD-JONES DISPERSION/REPULSION */
257
258             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
259             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
260             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
261             vvdw             = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
262             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
263
264             /* Update potential sum for this i atom from the interaction with this j atom. */
265             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
266
267             fscal            = fvdw;
268
269              /* Update vectorial force */
270             fix0             = _mm_macc_ps(dx00,fscal,fix0);
271             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
272             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
273
274             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
275             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
276             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
277
278             /**************************
279              * CALCULATE INTERACTIONS *
280              **************************/
281
282             /* Compute parameters for interactions between i and j atoms */
283             qq10             = _mm_mul_ps(iq1,jq0);
284
285             /* COULOMB ELECTROSTATICS */
286             velec            = _mm_mul_ps(qq10,rinv10);
287             felec            = _mm_mul_ps(velec,rinvsq10);
288
289             /* Update potential sum for this i atom from the interaction with this j atom. */
290             velecsum         = _mm_add_ps(velecsum,velec);
291
292             fscal            = felec;
293
294              /* Update vectorial force */
295             fix1             = _mm_macc_ps(dx10,fscal,fix1);
296             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
297             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
298
299             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
300             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
301             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
302
303             /**************************
304              * CALCULATE INTERACTIONS *
305              **************************/
306
307             /* Compute parameters for interactions between i and j atoms */
308             qq20             = _mm_mul_ps(iq2,jq0);
309
310             /* COULOMB ELECTROSTATICS */
311             velec            = _mm_mul_ps(qq20,rinv20);
312             felec            = _mm_mul_ps(velec,rinvsq20);
313
314             /* Update potential sum for this i atom from the interaction with this j atom. */
315             velecsum         = _mm_add_ps(velecsum,velec);
316
317             fscal            = felec;
318
319              /* Update vectorial force */
320             fix2             = _mm_macc_ps(dx20,fscal,fix2);
321             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
322             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
323
324             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
325             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
326             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
327
328             /**************************
329              * CALCULATE INTERACTIONS *
330              **************************/
331
332             /* Compute parameters for interactions between i and j atoms */
333             qq30             = _mm_mul_ps(iq3,jq0);
334
335             /* COULOMB ELECTROSTATICS */
336             velec            = _mm_mul_ps(qq30,rinv30);
337             felec            = _mm_mul_ps(velec,rinvsq30);
338
339             /* Update potential sum for this i atom from the interaction with this j atom. */
340             velecsum         = _mm_add_ps(velecsum,velec);
341
342             fscal            = felec;
343
344              /* Update vectorial force */
345             fix3             = _mm_macc_ps(dx30,fscal,fix3);
346             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
347             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
348
349             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
350             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
351             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
352
353             fjptrA             = f+j_coord_offsetA;
354             fjptrB             = f+j_coord_offsetB;
355             fjptrC             = f+j_coord_offsetC;
356             fjptrD             = f+j_coord_offsetD;
357
358             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
359
360             /* Inner loop uses 128 flops */
361         }
362
363         if(jidx<j_index_end)
364         {
365
366             /* Get j neighbor index, and coordinate index */
367             jnrlistA         = jjnr[jidx];
368             jnrlistB         = jjnr[jidx+1];
369             jnrlistC         = jjnr[jidx+2];
370             jnrlistD         = jjnr[jidx+3];
371             /* Sign of each element will be negative for non-real atoms.
372              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
373              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
374              */
375             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
376             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
377             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
378             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
379             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
380             j_coord_offsetA  = DIM*jnrA;
381             j_coord_offsetB  = DIM*jnrB;
382             j_coord_offsetC  = DIM*jnrC;
383             j_coord_offsetD  = DIM*jnrD;
384
385             /* load j atom coordinates */
386             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
387                                               x+j_coord_offsetC,x+j_coord_offsetD,
388                                               &jx0,&jy0,&jz0);
389
390             /* Calculate displacement vector */
391             dx00             = _mm_sub_ps(ix0,jx0);
392             dy00             = _mm_sub_ps(iy0,jy0);
393             dz00             = _mm_sub_ps(iz0,jz0);
394             dx10             = _mm_sub_ps(ix1,jx0);
395             dy10             = _mm_sub_ps(iy1,jy0);
396             dz10             = _mm_sub_ps(iz1,jz0);
397             dx20             = _mm_sub_ps(ix2,jx0);
398             dy20             = _mm_sub_ps(iy2,jy0);
399             dz20             = _mm_sub_ps(iz2,jz0);
400             dx30             = _mm_sub_ps(ix3,jx0);
401             dy30             = _mm_sub_ps(iy3,jy0);
402             dz30             = _mm_sub_ps(iz3,jz0);
403
404             /* Calculate squared distance and things based on it */
405             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
406             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
407             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
408             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
409
410             rinv10           = gmx_mm_invsqrt_ps(rsq10);
411             rinv20           = gmx_mm_invsqrt_ps(rsq20);
412             rinv30           = gmx_mm_invsqrt_ps(rsq30);
413
414             rinvsq00         = gmx_mm_inv_ps(rsq00);
415             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
416             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
417             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
418
419             /* Load parameters for j particles */
420             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
421                                                               charge+jnrC+0,charge+jnrD+0);
422             vdwjidx0A        = 2*vdwtype[jnrA+0];
423             vdwjidx0B        = 2*vdwtype[jnrB+0];
424             vdwjidx0C        = 2*vdwtype[jnrC+0];
425             vdwjidx0D        = 2*vdwtype[jnrD+0];
426
427             fjx0             = _mm_setzero_ps();
428             fjy0             = _mm_setzero_ps();
429             fjz0             = _mm_setzero_ps();
430
431             /**************************
432              * CALCULATE INTERACTIONS *
433              **************************/
434
435             /* Compute parameters for interactions between i and j atoms */
436             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
437                                          vdwparam+vdwioffset0+vdwjidx0B,
438                                          vdwparam+vdwioffset0+vdwjidx0C,
439                                          vdwparam+vdwioffset0+vdwjidx0D,
440                                          &c6_00,&c12_00);
441
442             /* LENNARD-JONES DISPERSION/REPULSION */
443
444             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
445             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
446             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
447             vvdw             = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
448             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
449
450             /* Update potential sum for this i atom from the interaction with this j atom. */
451             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
452             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
453
454             fscal            = fvdw;
455
456             fscal            = _mm_andnot_ps(dummy_mask,fscal);
457
458              /* Update vectorial force */
459             fix0             = _mm_macc_ps(dx00,fscal,fix0);
460             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
461             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
462
463             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
464             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
465             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
466
467             /**************************
468              * CALCULATE INTERACTIONS *
469              **************************/
470
471             /* Compute parameters for interactions between i and j atoms */
472             qq10             = _mm_mul_ps(iq1,jq0);
473
474             /* COULOMB ELECTROSTATICS */
475             velec            = _mm_mul_ps(qq10,rinv10);
476             felec            = _mm_mul_ps(velec,rinvsq10);
477
478             /* Update potential sum for this i atom from the interaction with this j atom. */
479             velec            = _mm_andnot_ps(dummy_mask,velec);
480             velecsum         = _mm_add_ps(velecsum,velec);
481
482             fscal            = felec;
483
484             fscal            = _mm_andnot_ps(dummy_mask,fscal);
485
486              /* Update vectorial force */
487             fix1             = _mm_macc_ps(dx10,fscal,fix1);
488             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
489             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
490
491             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
492             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
493             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
494
495             /**************************
496              * CALCULATE INTERACTIONS *
497              **************************/
498
499             /* Compute parameters for interactions between i and j atoms */
500             qq20             = _mm_mul_ps(iq2,jq0);
501
502             /* COULOMB ELECTROSTATICS */
503             velec            = _mm_mul_ps(qq20,rinv20);
504             felec            = _mm_mul_ps(velec,rinvsq20);
505
506             /* Update potential sum for this i atom from the interaction with this j atom. */
507             velec            = _mm_andnot_ps(dummy_mask,velec);
508             velecsum         = _mm_add_ps(velecsum,velec);
509
510             fscal            = felec;
511
512             fscal            = _mm_andnot_ps(dummy_mask,fscal);
513
514              /* Update vectorial force */
515             fix2             = _mm_macc_ps(dx20,fscal,fix2);
516             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
517             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
518
519             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
520             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
521             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
522
523             /**************************
524              * CALCULATE INTERACTIONS *
525              **************************/
526
527             /* Compute parameters for interactions between i and j atoms */
528             qq30             = _mm_mul_ps(iq3,jq0);
529
530             /* COULOMB ELECTROSTATICS */
531             velec            = _mm_mul_ps(qq30,rinv30);
532             felec            = _mm_mul_ps(velec,rinvsq30);
533
534             /* Update potential sum for this i atom from the interaction with this j atom. */
535             velec            = _mm_andnot_ps(dummy_mask,velec);
536             velecsum         = _mm_add_ps(velecsum,velec);
537
538             fscal            = felec;
539
540             fscal            = _mm_andnot_ps(dummy_mask,fscal);
541
542              /* Update vectorial force */
543             fix3             = _mm_macc_ps(dx30,fscal,fix3);
544             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
545             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
546
547             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
548             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
549             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
550
551             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
552             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
553             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
554             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
555
556             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
557
558             /* Inner loop uses 128 flops */
559         }
560
561         /* End of innermost loop */
562
563         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
564                                               f+i_coord_offset,fshift+i_shift_offset);
565
566         ggid                        = gid[iidx];
567         /* Update potential energies */
568         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
569         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
570
571         /* Increment number of inner iterations */
572         inneriter                  += j_index_end - j_index_start;
573
574         /* Outer loop uses 26 flops */
575     }
576
577     /* Increment number of outer iterations */
578     outeriter        += nri;
579
580     /* Update outer/inner flops */
581
582     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*128);
583 }
584 /*
585  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
586  * Electrostatics interaction: Coulomb
587  * VdW interaction:            LennardJones
588  * Geometry:                   Water4-Particle
589  * Calculate force/pot:        Force
590  */
591 void
592 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
593                     (t_nblist                    * gmx_restrict       nlist,
594                      rvec                        * gmx_restrict          xx,
595                      rvec                        * gmx_restrict          ff,
596                      t_forcerec                  * gmx_restrict          fr,
597                      t_mdatoms                   * gmx_restrict     mdatoms,
598                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
599                      t_nrnb                      * gmx_restrict        nrnb)
600 {
601     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
602      * just 0 for non-waters.
603      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
604      * jnr indices corresponding to data put in the four positions in the SIMD register.
605      */
606     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
607     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
608     int              jnrA,jnrB,jnrC,jnrD;
609     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
610     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
611     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
612     real             rcutoff_scalar;
613     real             *shiftvec,*fshift,*x,*f;
614     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
615     real             scratch[4*DIM];
616     __m128           fscal,rcutoff,rcutoff2,jidxall;
617     int              vdwioffset0;
618     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
619     int              vdwioffset1;
620     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
621     int              vdwioffset2;
622     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
623     int              vdwioffset3;
624     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
625     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
626     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
627     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
628     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
629     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
630     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
631     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
632     real             *charge;
633     int              nvdwtype;
634     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
635     int              *vdwtype;
636     real             *vdwparam;
637     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
638     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
639     __m128           dummy_mask,cutoff_mask;
640     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
641     __m128           one     = _mm_set1_ps(1.0);
642     __m128           two     = _mm_set1_ps(2.0);
643     x                = xx[0];
644     f                = ff[0];
645
646     nri              = nlist->nri;
647     iinr             = nlist->iinr;
648     jindex           = nlist->jindex;
649     jjnr             = nlist->jjnr;
650     shiftidx         = nlist->shift;
651     gid              = nlist->gid;
652     shiftvec         = fr->shift_vec[0];
653     fshift           = fr->fshift[0];
654     facel            = _mm_set1_ps(fr->epsfac);
655     charge           = mdatoms->chargeA;
656     nvdwtype         = fr->ntype;
657     vdwparam         = fr->nbfp;
658     vdwtype          = mdatoms->typeA;
659
660     /* Setup water-specific parameters */
661     inr              = nlist->iinr[0];
662     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
663     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
664     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
665     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
666
667     /* Avoid stupid compiler warnings */
668     jnrA = jnrB = jnrC = jnrD = 0;
669     j_coord_offsetA = 0;
670     j_coord_offsetB = 0;
671     j_coord_offsetC = 0;
672     j_coord_offsetD = 0;
673
674     outeriter        = 0;
675     inneriter        = 0;
676
677     for(iidx=0;iidx<4*DIM;iidx++)
678     {
679         scratch[iidx] = 0.0;
680     }
681
682     /* Start outer loop over neighborlists */
683     for(iidx=0; iidx<nri; iidx++)
684     {
685         /* Load shift vector for this list */
686         i_shift_offset   = DIM*shiftidx[iidx];
687
688         /* Load limits for loop over neighbors */
689         j_index_start    = jindex[iidx];
690         j_index_end      = jindex[iidx+1];
691
692         /* Get outer coordinate index */
693         inr              = iinr[iidx];
694         i_coord_offset   = DIM*inr;
695
696         /* Load i particle coords and add shift vector */
697         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
698                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
699
700         fix0             = _mm_setzero_ps();
701         fiy0             = _mm_setzero_ps();
702         fiz0             = _mm_setzero_ps();
703         fix1             = _mm_setzero_ps();
704         fiy1             = _mm_setzero_ps();
705         fiz1             = _mm_setzero_ps();
706         fix2             = _mm_setzero_ps();
707         fiy2             = _mm_setzero_ps();
708         fiz2             = _mm_setzero_ps();
709         fix3             = _mm_setzero_ps();
710         fiy3             = _mm_setzero_ps();
711         fiz3             = _mm_setzero_ps();
712
713         /* Start inner kernel loop */
714         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
715         {
716
717             /* Get j neighbor index, and coordinate index */
718             jnrA             = jjnr[jidx];
719             jnrB             = jjnr[jidx+1];
720             jnrC             = jjnr[jidx+2];
721             jnrD             = jjnr[jidx+3];
722             j_coord_offsetA  = DIM*jnrA;
723             j_coord_offsetB  = DIM*jnrB;
724             j_coord_offsetC  = DIM*jnrC;
725             j_coord_offsetD  = DIM*jnrD;
726
727             /* load j atom coordinates */
728             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
729                                               x+j_coord_offsetC,x+j_coord_offsetD,
730                                               &jx0,&jy0,&jz0);
731
732             /* Calculate displacement vector */
733             dx00             = _mm_sub_ps(ix0,jx0);
734             dy00             = _mm_sub_ps(iy0,jy0);
735             dz00             = _mm_sub_ps(iz0,jz0);
736             dx10             = _mm_sub_ps(ix1,jx0);
737             dy10             = _mm_sub_ps(iy1,jy0);
738             dz10             = _mm_sub_ps(iz1,jz0);
739             dx20             = _mm_sub_ps(ix2,jx0);
740             dy20             = _mm_sub_ps(iy2,jy0);
741             dz20             = _mm_sub_ps(iz2,jz0);
742             dx30             = _mm_sub_ps(ix3,jx0);
743             dy30             = _mm_sub_ps(iy3,jy0);
744             dz30             = _mm_sub_ps(iz3,jz0);
745
746             /* Calculate squared distance and things based on it */
747             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
748             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
749             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
750             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
751
752             rinv10           = gmx_mm_invsqrt_ps(rsq10);
753             rinv20           = gmx_mm_invsqrt_ps(rsq20);
754             rinv30           = gmx_mm_invsqrt_ps(rsq30);
755
756             rinvsq00         = gmx_mm_inv_ps(rsq00);
757             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
758             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
759             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
760
761             /* Load parameters for j particles */
762             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
763                                                               charge+jnrC+0,charge+jnrD+0);
764             vdwjidx0A        = 2*vdwtype[jnrA+0];
765             vdwjidx0B        = 2*vdwtype[jnrB+0];
766             vdwjidx0C        = 2*vdwtype[jnrC+0];
767             vdwjidx0D        = 2*vdwtype[jnrD+0];
768
769             fjx0             = _mm_setzero_ps();
770             fjy0             = _mm_setzero_ps();
771             fjz0             = _mm_setzero_ps();
772
773             /**************************
774              * CALCULATE INTERACTIONS *
775              **************************/
776
777             /* Compute parameters for interactions between i and j atoms */
778             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
779                                          vdwparam+vdwioffset0+vdwjidx0B,
780                                          vdwparam+vdwioffset0+vdwjidx0C,
781                                          vdwparam+vdwioffset0+vdwjidx0D,
782                                          &c6_00,&c12_00);
783
784             /* LENNARD-JONES DISPERSION/REPULSION */
785
786             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
787             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
788
789             fscal            = fvdw;
790
791              /* Update vectorial force */
792             fix0             = _mm_macc_ps(dx00,fscal,fix0);
793             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
794             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
795
796             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
797             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
798             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
799
800             /**************************
801              * CALCULATE INTERACTIONS *
802              **************************/
803
804             /* Compute parameters for interactions between i and j atoms */
805             qq10             = _mm_mul_ps(iq1,jq0);
806
807             /* COULOMB ELECTROSTATICS */
808             velec            = _mm_mul_ps(qq10,rinv10);
809             felec            = _mm_mul_ps(velec,rinvsq10);
810
811             fscal            = felec;
812
813              /* Update vectorial force */
814             fix1             = _mm_macc_ps(dx10,fscal,fix1);
815             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
816             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
817
818             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
819             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
820             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
821
822             /**************************
823              * CALCULATE INTERACTIONS *
824              **************************/
825
826             /* Compute parameters for interactions between i and j atoms */
827             qq20             = _mm_mul_ps(iq2,jq0);
828
829             /* COULOMB ELECTROSTATICS */
830             velec            = _mm_mul_ps(qq20,rinv20);
831             felec            = _mm_mul_ps(velec,rinvsq20);
832
833             fscal            = felec;
834
835              /* Update vectorial force */
836             fix2             = _mm_macc_ps(dx20,fscal,fix2);
837             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
838             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
839
840             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
841             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
842             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
843
844             /**************************
845              * CALCULATE INTERACTIONS *
846              **************************/
847
848             /* Compute parameters for interactions between i and j atoms */
849             qq30             = _mm_mul_ps(iq3,jq0);
850
851             /* COULOMB ELECTROSTATICS */
852             velec            = _mm_mul_ps(qq30,rinv30);
853             felec            = _mm_mul_ps(velec,rinvsq30);
854
855             fscal            = felec;
856
857              /* Update vectorial force */
858             fix3             = _mm_macc_ps(dx30,fscal,fix3);
859             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
860             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
861
862             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
863             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
864             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
865
866             fjptrA             = f+j_coord_offsetA;
867             fjptrB             = f+j_coord_offsetB;
868             fjptrC             = f+j_coord_offsetC;
869             fjptrD             = f+j_coord_offsetD;
870
871             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
872
873             /* Inner loop uses 120 flops */
874         }
875
876         if(jidx<j_index_end)
877         {
878
879             /* Get j neighbor index, and coordinate index */
880             jnrlistA         = jjnr[jidx];
881             jnrlistB         = jjnr[jidx+1];
882             jnrlistC         = jjnr[jidx+2];
883             jnrlistD         = jjnr[jidx+3];
884             /* Sign of each element will be negative for non-real atoms.
885              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
886              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
887              */
888             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
889             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
890             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
891             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
892             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
893             j_coord_offsetA  = DIM*jnrA;
894             j_coord_offsetB  = DIM*jnrB;
895             j_coord_offsetC  = DIM*jnrC;
896             j_coord_offsetD  = DIM*jnrD;
897
898             /* load j atom coordinates */
899             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
900                                               x+j_coord_offsetC,x+j_coord_offsetD,
901                                               &jx0,&jy0,&jz0);
902
903             /* Calculate displacement vector */
904             dx00             = _mm_sub_ps(ix0,jx0);
905             dy00             = _mm_sub_ps(iy0,jy0);
906             dz00             = _mm_sub_ps(iz0,jz0);
907             dx10             = _mm_sub_ps(ix1,jx0);
908             dy10             = _mm_sub_ps(iy1,jy0);
909             dz10             = _mm_sub_ps(iz1,jz0);
910             dx20             = _mm_sub_ps(ix2,jx0);
911             dy20             = _mm_sub_ps(iy2,jy0);
912             dz20             = _mm_sub_ps(iz2,jz0);
913             dx30             = _mm_sub_ps(ix3,jx0);
914             dy30             = _mm_sub_ps(iy3,jy0);
915             dz30             = _mm_sub_ps(iz3,jz0);
916
917             /* Calculate squared distance and things based on it */
918             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
919             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
920             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
921             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
922
923             rinv10           = gmx_mm_invsqrt_ps(rsq10);
924             rinv20           = gmx_mm_invsqrt_ps(rsq20);
925             rinv30           = gmx_mm_invsqrt_ps(rsq30);
926
927             rinvsq00         = gmx_mm_inv_ps(rsq00);
928             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
929             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
930             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
931
932             /* Load parameters for j particles */
933             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
934                                                               charge+jnrC+0,charge+jnrD+0);
935             vdwjidx0A        = 2*vdwtype[jnrA+0];
936             vdwjidx0B        = 2*vdwtype[jnrB+0];
937             vdwjidx0C        = 2*vdwtype[jnrC+0];
938             vdwjidx0D        = 2*vdwtype[jnrD+0];
939
940             fjx0             = _mm_setzero_ps();
941             fjy0             = _mm_setzero_ps();
942             fjz0             = _mm_setzero_ps();
943
944             /**************************
945              * CALCULATE INTERACTIONS *
946              **************************/
947
948             /* Compute parameters for interactions between i and j atoms */
949             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
950                                          vdwparam+vdwioffset0+vdwjidx0B,
951                                          vdwparam+vdwioffset0+vdwjidx0C,
952                                          vdwparam+vdwioffset0+vdwjidx0D,
953                                          &c6_00,&c12_00);
954
955             /* LENNARD-JONES DISPERSION/REPULSION */
956
957             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
958             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
959
960             fscal            = fvdw;
961
962             fscal            = _mm_andnot_ps(dummy_mask,fscal);
963
964              /* Update vectorial force */
965             fix0             = _mm_macc_ps(dx00,fscal,fix0);
966             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
967             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
968
969             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
970             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
971             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
972
973             /**************************
974              * CALCULATE INTERACTIONS *
975              **************************/
976
977             /* Compute parameters for interactions between i and j atoms */
978             qq10             = _mm_mul_ps(iq1,jq0);
979
980             /* COULOMB ELECTROSTATICS */
981             velec            = _mm_mul_ps(qq10,rinv10);
982             felec            = _mm_mul_ps(velec,rinvsq10);
983
984             fscal            = felec;
985
986             fscal            = _mm_andnot_ps(dummy_mask,fscal);
987
988              /* Update vectorial force */
989             fix1             = _mm_macc_ps(dx10,fscal,fix1);
990             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
991             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
992
993             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
994             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
995             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
996
997             /**************************
998              * CALCULATE INTERACTIONS *
999              **************************/
1000
1001             /* Compute parameters for interactions between i and j atoms */
1002             qq20             = _mm_mul_ps(iq2,jq0);
1003
1004             /* COULOMB ELECTROSTATICS */
1005             velec            = _mm_mul_ps(qq20,rinv20);
1006             felec            = _mm_mul_ps(velec,rinvsq20);
1007
1008             fscal            = felec;
1009
1010             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1011
1012              /* Update vectorial force */
1013             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1014             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1015             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1016
1017             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1018             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1019             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1020
1021             /**************************
1022              * CALCULATE INTERACTIONS *
1023              **************************/
1024
1025             /* Compute parameters for interactions between i and j atoms */
1026             qq30             = _mm_mul_ps(iq3,jq0);
1027
1028             /* COULOMB ELECTROSTATICS */
1029             velec            = _mm_mul_ps(qq30,rinv30);
1030             felec            = _mm_mul_ps(velec,rinvsq30);
1031
1032             fscal            = felec;
1033
1034             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1035
1036              /* Update vectorial force */
1037             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1038             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1039             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1040
1041             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1042             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1043             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1044
1045             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1046             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1047             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1048             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1049
1050             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1051
1052             /* Inner loop uses 120 flops */
1053         }
1054
1055         /* End of innermost loop */
1056
1057         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1058                                               f+i_coord_offset,fshift+i_shift_offset);
1059
1060         /* Increment number of inner iterations */
1061         inneriter                  += j_index_end - j_index_start;
1062
1063         /* Outer loop uses 24 flops */
1064     }
1065
1066     /* Increment number of outer iterations */
1067     outeriter        += nri;
1068
1069     /* Update outer/inner flops */
1070
1071     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*120);
1072 }