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