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