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