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