Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_avx_128_fma_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/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_GeomP1P1_VF_avx_128_fma_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            LennardJones
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_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              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
88     real             *charge;
89     int              nvdwtype;
90     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
91     int              *vdwtype;
92     real             *vdwparam;
93     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
94     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
95     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
96     real             rswitch_scalar,d_scalar;
97     __m128d          dummy_mask,cutoff_mask;
98     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
99     __m128d          one     = _mm_set1_pd(1.0);
100     __m128d          two     = _mm_set1_pd(2.0);
101     x                = xx[0];
102     f                = ff[0];
103
104     nri              = nlist->nri;
105     iinr             = nlist->iinr;
106     jindex           = nlist->jindex;
107     jjnr             = nlist->jjnr;
108     shiftidx         = nlist->shift;
109     gid              = nlist->gid;
110     shiftvec         = fr->shift_vec[0];
111     fshift           = fr->fshift[0];
112     facel            = _mm_set1_pd(fr->epsfac);
113     charge           = mdatoms->chargeA;
114     krf              = _mm_set1_pd(fr->ic->k_rf);
115     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
116     crf              = _mm_set1_pd(fr->ic->c_rf);
117     nvdwtype         = fr->ntype;
118     vdwparam         = fr->nbfp;
119     vdwtype          = mdatoms->typeA;
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_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
162
163         fix0             = _mm_setzero_pd();
164         fiy0             = _mm_setzero_pd();
165         fiz0             = _mm_setzero_pd();
166
167         /* Load parameters for i particles */
168         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
169         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
170
171         /* Reset potential sums */
172         velecsum         = _mm_setzero_pd();
173         vvdwsum          = _mm_setzero_pd();
174
175         /* Start inner kernel loop */
176         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
177         {
178
179             /* Get j neighbor index, and coordinate index */
180             jnrA             = jjnr[jidx];
181             jnrB             = jjnr[jidx+1];
182             j_coord_offsetA  = DIM*jnrA;
183             j_coord_offsetB  = DIM*jnrB;
184
185             /* load j atom coordinates */
186             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
187                                               &jx0,&jy0,&jz0);
188
189             /* Calculate displacement vector */
190             dx00             = _mm_sub_pd(ix0,jx0);
191             dy00             = _mm_sub_pd(iy0,jy0);
192             dz00             = _mm_sub_pd(iz0,jz0);
193
194             /* Calculate squared distance and things based on it */
195             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
196
197             rinv00           = gmx_mm_invsqrt_pd(rsq00);
198
199             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
200
201             /* Load parameters for j particles */
202             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
203             vdwjidx0A        = 2*vdwtype[jnrA+0];
204             vdwjidx0B        = 2*vdwtype[jnrB+0];
205
206             /**************************
207              * CALCULATE INTERACTIONS *
208              **************************/
209
210             if (gmx_mm_any_lt(rsq00,rcutoff2))
211             {
212
213             r00              = _mm_mul_pd(rsq00,rinv00);
214
215             /* Compute parameters for interactions between i and j atoms */
216             qq00             = _mm_mul_pd(iq0,jq0);
217             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
218                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
219
220             /* REACTION-FIELD ELECTROSTATICS */
221             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
222             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
223
224             /* LENNARD-JONES DISPERSION/REPULSION */
225
226             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
227             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
228             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
229             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
230             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
231
232             d                = _mm_sub_pd(r00,rswitch);
233             d                = _mm_max_pd(d,_mm_setzero_pd());
234             d2               = _mm_mul_pd(d,d);
235             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
236
237             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
238
239             /* Evaluate switch function */
240             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
241             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
242             vvdw             = _mm_mul_pd(vvdw,sw);
243             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
244
245             /* Update potential sum for this i atom from the interaction with this j atom. */
246             velec            = _mm_and_pd(velec,cutoff_mask);
247             velecsum         = _mm_add_pd(velecsum,velec);
248             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
249             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
250
251             fscal            = _mm_add_pd(felec,fvdw);
252
253             fscal            = _mm_and_pd(fscal,cutoff_mask);
254
255             /* Update vectorial force */
256             fix0             = _mm_macc_pd(dx00,fscal,fix0);
257             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
258             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
259             
260             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
261                                                    _mm_mul_pd(dx00,fscal),
262                                                    _mm_mul_pd(dy00,fscal),
263                                                    _mm_mul_pd(dz00,fscal));
264
265             }
266
267             /* Inner loop uses 73 flops */
268         }
269
270         if(jidx<j_index_end)
271         {
272
273             jnrA             = jjnr[jidx];
274             j_coord_offsetA  = DIM*jnrA;
275
276             /* load j atom coordinates */
277             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
278                                               &jx0,&jy0,&jz0);
279
280             /* Calculate displacement vector */
281             dx00             = _mm_sub_pd(ix0,jx0);
282             dy00             = _mm_sub_pd(iy0,jy0);
283             dz00             = _mm_sub_pd(iz0,jz0);
284
285             /* Calculate squared distance and things based on it */
286             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
287
288             rinv00           = gmx_mm_invsqrt_pd(rsq00);
289
290             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
291
292             /* Load parameters for j particles */
293             jq0              = _mm_load_sd(charge+jnrA+0);
294             vdwjidx0A        = 2*vdwtype[jnrA+0];
295
296             /**************************
297              * CALCULATE INTERACTIONS *
298              **************************/
299
300             if (gmx_mm_any_lt(rsq00,rcutoff2))
301             {
302
303             r00              = _mm_mul_pd(rsq00,rinv00);
304
305             /* Compute parameters for interactions between i and j atoms */
306             qq00             = _mm_mul_pd(iq0,jq0);
307             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
308
309             /* REACTION-FIELD ELECTROSTATICS */
310             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
311             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
312
313             /* LENNARD-JONES DISPERSION/REPULSION */
314
315             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
316             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
317             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
318             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
319             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
320
321             d                = _mm_sub_pd(r00,rswitch);
322             d                = _mm_max_pd(d,_mm_setzero_pd());
323             d2               = _mm_mul_pd(d,d);
324             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
325
326             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
327
328             /* Evaluate switch function */
329             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
330             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
331             vvdw             = _mm_mul_pd(vvdw,sw);
332             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
333
334             /* Update potential sum for this i atom from the interaction with this j atom. */
335             velec            = _mm_and_pd(velec,cutoff_mask);
336             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
337             velecsum         = _mm_add_pd(velecsum,velec);
338             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
339             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
340             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
341
342             fscal            = _mm_add_pd(felec,fvdw);
343
344             fscal            = _mm_and_pd(fscal,cutoff_mask);
345
346             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
347
348             /* Update vectorial force */
349             fix0             = _mm_macc_pd(dx00,fscal,fix0);
350             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
351             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
352             
353             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
354                                                    _mm_mul_pd(dx00,fscal),
355                                                    _mm_mul_pd(dy00,fscal),
356                                                    _mm_mul_pd(dz00,fscal));
357
358             }
359
360             /* Inner loop uses 73 flops */
361         }
362
363         /* End of innermost loop */
364
365         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
366                                               f+i_coord_offset,fshift+i_shift_offset);
367
368         ggid                        = gid[iidx];
369         /* Update potential energies */
370         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
371         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
372
373         /* Increment number of inner iterations */
374         inneriter                  += j_index_end - j_index_start;
375
376         /* Outer loop uses 9 flops */
377     }
378
379     /* Increment number of outer iterations */
380     outeriter        += nri;
381
382     /* Update outer/inner flops */
383
384     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*73);
385 }
386 /*
387  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_avx_128_fma_double
388  * Electrostatics interaction: ReactionField
389  * VdW interaction:            LennardJones
390  * Geometry:                   Particle-Particle
391  * Calculate force/pot:        Force
392  */
393 void
394 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_avx_128_fma_double
395                     (t_nblist                    * gmx_restrict       nlist,
396                      rvec                        * gmx_restrict          xx,
397                      rvec                        * gmx_restrict          ff,
398                      t_forcerec                  * gmx_restrict          fr,
399                      t_mdatoms                   * gmx_restrict     mdatoms,
400                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
401                      t_nrnb                      * gmx_restrict        nrnb)
402 {
403     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
404      * just 0 for non-waters.
405      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
406      * jnr indices corresponding to data put in the four positions in the SIMD register.
407      */
408     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
409     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
410     int              jnrA,jnrB;
411     int              j_coord_offsetA,j_coord_offsetB;
412     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
413     real             rcutoff_scalar;
414     real             *shiftvec,*fshift,*x,*f;
415     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
416     int              vdwioffset0;
417     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
418     int              vdwjidx0A,vdwjidx0B;
419     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
420     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
421     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
422     real             *charge;
423     int              nvdwtype;
424     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
425     int              *vdwtype;
426     real             *vdwparam;
427     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
428     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
429     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
430     real             rswitch_scalar,d_scalar;
431     __m128d          dummy_mask,cutoff_mask;
432     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
433     __m128d          one     = _mm_set1_pd(1.0);
434     __m128d          two     = _mm_set1_pd(2.0);
435     x                = xx[0];
436     f                = ff[0];
437
438     nri              = nlist->nri;
439     iinr             = nlist->iinr;
440     jindex           = nlist->jindex;
441     jjnr             = nlist->jjnr;
442     shiftidx         = nlist->shift;
443     gid              = nlist->gid;
444     shiftvec         = fr->shift_vec[0];
445     fshift           = fr->fshift[0];
446     facel            = _mm_set1_pd(fr->epsfac);
447     charge           = mdatoms->chargeA;
448     krf              = _mm_set1_pd(fr->ic->k_rf);
449     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
450     crf              = _mm_set1_pd(fr->ic->c_rf);
451     nvdwtype         = fr->ntype;
452     vdwparam         = fr->nbfp;
453     vdwtype          = mdatoms->typeA;
454
455     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
456     rcutoff_scalar   = fr->rcoulomb;
457     rcutoff          = _mm_set1_pd(rcutoff_scalar);
458     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
459
460     rswitch_scalar   = fr->rvdw_switch;
461     rswitch          = _mm_set1_pd(rswitch_scalar);
462     /* Setup switch parameters */
463     d_scalar         = rcutoff_scalar-rswitch_scalar;
464     d                = _mm_set1_pd(d_scalar);
465     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
466     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
467     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
468     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
469     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
470     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
471
472     /* Avoid stupid compiler warnings */
473     jnrA = jnrB = 0;
474     j_coord_offsetA = 0;
475     j_coord_offsetB = 0;
476
477     outeriter        = 0;
478     inneriter        = 0;
479
480     /* Start outer loop over neighborlists */
481     for(iidx=0; iidx<nri; iidx++)
482     {
483         /* Load shift vector for this list */
484         i_shift_offset   = DIM*shiftidx[iidx];
485
486         /* Load limits for loop over neighbors */
487         j_index_start    = jindex[iidx];
488         j_index_end      = jindex[iidx+1];
489
490         /* Get outer coordinate index */
491         inr              = iinr[iidx];
492         i_coord_offset   = DIM*inr;
493
494         /* Load i particle coords and add shift vector */
495         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
496
497         fix0             = _mm_setzero_pd();
498         fiy0             = _mm_setzero_pd();
499         fiz0             = _mm_setzero_pd();
500
501         /* Load parameters for i particles */
502         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
503         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
504
505         /* Start inner kernel loop */
506         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
507         {
508
509             /* Get j neighbor index, and coordinate index */
510             jnrA             = jjnr[jidx];
511             jnrB             = jjnr[jidx+1];
512             j_coord_offsetA  = DIM*jnrA;
513             j_coord_offsetB  = DIM*jnrB;
514
515             /* load j atom coordinates */
516             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
517                                               &jx0,&jy0,&jz0);
518
519             /* Calculate displacement vector */
520             dx00             = _mm_sub_pd(ix0,jx0);
521             dy00             = _mm_sub_pd(iy0,jy0);
522             dz00             = _mm_sub_pd(iz0,jz0);
523
524             /* Calculate squared distance and things based on it */
525             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
526
527             rinv00           = gmx_mm_invsqrt_pd(rsq00);
528
529             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
530
531             /* Load parameters for j particles */
532             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
533             vdwjidx0A        = 2*vdwtype[jnrA+0];
534             vdwjidx0B        = 2*vdwtype[jnrB+0];
535
536             /**************************
537              * CALCULATE INTERACTIONS *
538              **************************/
539
540             if (gmx_mm_any_lt(rsq00,rcutoff2))
541             {
542
543             r00              = _mm_mul_pd(rsq00,rinv00);
544
545             /* Compute parameters for interactions between i and j atoms */
546             qq00             = _mm_mul_pd(iq0,jq0);
547             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
548                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
549
550             /* REACTION-FIELD ELECTROSTATICS */
551             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
552
553             /* LENNARD-JONES DISPERSION/REPULSION */
554
555             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
556             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
557             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
558             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
559             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
560
561             d                = _mm_sub_pd(r00,rswitch);
562             d                = _mm_max_pd(d,_mm_setzero_pd());
563             d2               = _mm_mul_pd(d,d);
564             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
565
566             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
567
568             /* Evaluate switch function */
569             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
570             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
571             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
572
573             fscal            = _mm_add_pd(felec,fvdw);
574
575             fscal            = _mm_and_pd(fscal,cutoff_mask);
576
577             /* Update vectorial force */
578             fix0             = _mm_macc_pd(dx00,fscal,fix0);
579             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
580             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
581             
582             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
583                                                    _mm_mul_pd(dx00,fscal),
584                                                    _mm_mul_pd(dy00,fscal),
585                                                    _mm_mul_pd(dz00,fscal));
586
587             }
588
589             /* Inner loop uses 64 flops */
590         }
591
592         if(jidx<j_index_end)
593         {
594
595             jnrA             = jjnr[jidx];
596             j_coord_offsetA  = DIM*jnrA;
597
598             /* load j atom coordinates */
599             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
600                                               &jx0,&jy0,&jz0);
601
602             /* Calculate displacement vector */
603             dx00             = _mm_sub_pd(ix0,jx0);
604             dy00             = _mm_sub_pd(iy0,jy0);
605             dz00             = _mm_sub_pd(iz0,jz0);
606
607             /* Calculate squared distance and things based on it */
608             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
609
610             rinv00           = gmx_mm_invsqrt_pd(rsq00);
611
612             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
613
614             /* Load parameters for j particles */
615             jq0              = _mm_load_sd(charge+jnrA+0);
616             vdwjidx0A        = 2*vdwtype[jnrA+0];
617
618             /**************************
619              * CALCULATE INTERACTIONS *
620              **************************/
621
622             if (gmx_mm_any_lt(rsq00,rcutoff2))
623             {
624
625             r00              = _mm_mul_pd(rsq00,rinv00);
626
627             /* Compute parameters for interactions between i and j atoms */
628             qq00             = _mm_mul_pd(iq0,jq0);
629             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
630
631             /* REACTION-FIELD ELECTROSTATICS */
632             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
633
634             /* LENNARD-JONES DISPERSION/REPULSION */
635
636             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
637             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
638             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
639             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
640             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
641
642             d                = _mm_sub_pd(r00,rswitch);
643             d                = _mm_max_pd(d,_mm_setzero_pd());
644             d2               = _mm_mul_pd(d,d);
645             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
646
647             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
648
649             /* Evaluate switch function */
650             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
651             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
652             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
653
654             fscal            = _mm_add_pd(felec,fvdw);
655
656             fscal            = _mm_and_pd(fscal,cutoff_mask);
657
658             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
659
660             /* Update vectorial force */
661             fix0             = _mm_macc_pd(dx00,fscal,fix0);
662             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
663             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
664             
665             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
666                                                    _mm_mul_pd(dx00,fscal),
667                                                    _mm_mul_pd(dy00,fscal),
668                                                    _mm_mul_pd(dz00,fscal));
669
670             }
671
672             /* Inner loop uses 64 flops */
673         }
674
675         /* End of innermost loop */
676
677         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
678                                               f+i_coord_offset,fshift+i_shift_offset);
679
680         /* Increment number of inner iterations */
681         inneriter                  += j_index_end - j_index_start;
682
683         /* Outer loop uses 7 flops */
684     }
685
686     /* Increment number of outer iterations */
687     outeriter        += nri;
688
689     /* Update outer/inner flops */
690
691     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*64);
692 }