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