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