5f4daaf41b8f39812572905f5d92ba9bee787b1b
[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 "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_avx_128_fma_double
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            LennardJones
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_VF_avx_128_fma_double
59                     (t_nblist                    * gmx_restrict       nlist,
60                      rvec                        * gmx_restrict          xx,
61                      rvec                        * gmx_restrict          ff,
62                      t_forcerec                  * gmx_restrict          fr,
63                      t_mdatoms                   * gmx_restrict     mdatoms,
64                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65                      t_nrnb                      * gmx_restrict        nrnb)
66 {
67     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68      * just 0 for non-waters.
69      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70      * jnr indices corresponding to data put in the four positions in the SIMD register.
71      */
72     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
73     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74     int              jnrA,jnrB;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwjidx0A,vdwjidx0B;
83     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
86     real             *charge;
87     int              nvdwtype;
88     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89     int              *vdwtype;
90     real             *vdwparam;
91     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
92     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
93     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
94     real             rswitch_scalar,d_scalar;
95     __m128d          dummy_mask,cutoff_mask;
96     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
97     __m128d          one     = _mm_set1_pd(1.0);
98     __m128d          two     = _mm_set1_pd(2.0);
99     x                = xx[0];
100     f                = ff[0];
101
102     nri              = nlist->nri;
103     iinr             = nlist->iinr;
104     jindex           = nlist->jindex;
105     jjnr             = nlist->jjnr;
106     shiftidx         = nlist->shift;
107     gid              = nlist->gid;
108     shiftvec         = fr->shift_vec[0];
109     fshift           = fr->fshift[0];
110     facel            = _mm_set1_pd(fr->epsfac);
111     charge           = mdatoms->chargeA;
112     krf              = _mm_set1_pd(fr->ic->k_rf);
113     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
114     crf              = _mm_set1_pd(fr->ic->c_rf);
115     nvdwtype         = fr->ntype;
116     vdwparam         = fr->nbfp;
117     vdwtype          = mdatoms->typeA;
118
119     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120     rcutoff_scalar   = fr->rcoulomb;
121     rcutoff          = _mm_set1_pd(rcutoff_scalar);
122     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
123
124     rswitch_scalar   = fr->rvdw_switch;
125     rswitch          = _mm_set1_pd(rswitch_scalar);
126     /* Setup switch parameters */
127     d_scalar         = rcutoff_scalar-rswitch_scalar;
128     d                = _mm_set1_pd(d_scalar);
129     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
130     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
131     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
132     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
133     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
134     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
135
136     /* Avoid stupid compiler warnings */
137     jnrA = jnrB = 0;
138     j_coord_offsetA = 0;
139     j_coord_offsetB = 0;
140
141     outeriter        = 0;
142     inneriter        = 0;
143
144     /* Start outer loop over neighborlists */
145     for(iidx=0; iidx<nri; iidx++)
146     {
147         /* Load shift vector for this list */
148         i_shift_offset   = DIM*shiftidx[iidx];
149
150         /* Load limits for loop over neighbors */
151         j_index_start    = jindex[iidx];
152         j_index_end      = jindex[iidx+1];
153
154         /* Get outer coordinate index */
155         inr              = iinr[iidx];
156         i_coord_offset   = DIM*inr;
157
158         /* Load i particle coords and add shift vector */
159         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
160
161         fix0             = _mm_setzero_pd();
162         fiy0             = _mm_setzero_pd();
163         fiz0             = _mm_setzero_pd();
164
165         /* Load parameters for i particles */
166         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
167         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
168
169         /* Reset potential sums */
170         velecsum         = _mm_setzero_pd();
171         vvdwsum          = _mm_setzero_pd();
172
173         /* Start inner kernel loop */
174         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
175         {
176
177             /* Get j neighbor index, and coordinate index */
178             jnrA             = jjnr[jidx];
179             jnrB             = jjnr[jidx+1];
180             j_coord_offsetA  = DIM*jnrA;
181             j_coord_offsetB  = DIM*jnrB;
182
183             /* load j atom coordinates */
184             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
185                                               &jx0,&jy0,&jz0);
186
187             /* Calculate displacement vector */
188             dx00             = _mm_sub_pd(ix0,jx0);
189             dy00             = _mm_sub_pd(iy0,jy0);
190             dz00             = _mm_sub_pd(iz0,jz0);
191
192             /* Calculate squared distance and things based on it */
193             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
194
195             rinv00           = gmx_mm_invsqrt_pd(rsq00);
196
197             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
198
199             /* Load parameters for j particles */
200             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
201             vdwjidx0A        = 2*vdwtype[jnrA+0];
202             vdwjidx0B        = 2*vdwtype[jnrB+0];
203
204             /**************************
205              * CALCULATE INTERACTIONS *
206              **************************/
207
208             if (gmx_mm_any_lt(rsq00,rcutoff2))
209             {
210
211             r00              = _mm_mul_pd(rsq00,rinv00);
212
213             /* Compute parameters for interactions between i and j atoms */
214             qq00             = _mm_mul_pd(iq0,jq0);
215             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
216                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
217
218             /* REACTION-FIELD ELECTROSTATICS */
219             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
220             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
221
222             /* LENNARD-JONES DISPERSION/REPULSION */
223
224             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
225             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
226             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
227             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
228             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
229
230             d                = _mm_sub_pd(r00,rswitch);
231             d                = _mm_max_pd(d,_mm_setzero_pd());
232             d2               = _mm_mul_pd(d,d);
233             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
234
235             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
236
237             /* Evaluate switch function */
238             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
239             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
240             vvdw             = _mm_mul_pd(vvdw,sw);
241             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
242
243             /* Update potential sum for this i atom from the interaction with this j atom. */
244             velec            = _mm_and_pd(velec,cutoff_mask);
245             velecsum         = _mm_add_pd(velecsum,velec);
246             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
247             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
248
249             fscal            = _mm_add_pd(felec,fvdw);
250
251             fscal            = _mm_and_pd(fscal,cutoff_mask);
252
253             /* Update vectorial force */
254             fix0             = _mm_macc_pd(dx00,fscal,fix0);
255             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
256             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
257             
258             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
259                                                    _mm_mul_pd(dx00,fscal),
260                                                    _mm_mul_pd(dy00,fscal),
261                                                    _mm_mul_pd(dz00,fscal));
262
263             }
264
265             /* Inner loop uses 73 flops */
266         }
267
268         if(jidx<j_index_end)
269         {
270
271             jnrA             = jjnr[jidx];
272             j_coord_offsetA  = DIM*jnrA;
273
274             /* load j atom coordinates */
275             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
276                                               &jx0,&jy0,&jz0);
277
278             /* Calculate displacement vector */
279             dx00             = _mm_sub_pd(ix0,jx0);
280             dy00             = _mm_sub_pd(iy0,jy0);
281             dz00             = _mm_sub_pd(iz0,jz0);
282
283             /* Calculate squared distance and things based on it */
284             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
285
286             rinv00           = gmx_mm_invsqrt_pd(rsq00);
287
288             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
289
290             /* Load parameters for j particles */
291             jq0              = _mm_load_sd(charge+jnrA+0);
292             vdwjidx0A        = 2*vdwtype[jnrA+0];
293
294             /**************************
295              * CALCULATE INTERACTIONS *
296              **************************/
297
298             if (gmx_mm_any_lt(rsq00,rcutoff2))
299             {
300
301             r00              = _mm_mul_pd(rsq00,rinv00);
302
303             /* Compute parameters for interactions between i and j atoms */
304             qq00             = _mm_mul_pd(iq0,jq0);
305             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
306
307             /* REACTION-FIELD ELECTROSTATICS */
308             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
309             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
310
311             /* LENNARD-JONES DISPERSION/REPULSION */
312
313             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
314             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
315             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
316             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
317             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
318
319             d                = _mm_sub_pd(r00,rswitch);
320             d                = _mm_max_pd(d,_mm_setzero_pd());
321             d2               = _mm_mul_pd(d,d);
322             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
323
324             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
325
326             /* Evaluate switch function */
327             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
328             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
329             vvdw             = _mm_mul_pd(vvdw,sw);
330             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
331
332             /* Update potential sum for this i atom from the interaction with this j atom. */
333             velec            = _mm_and_pd(velec,cutoff_mask);
334             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
335             velecsum         = _mm_add_pd(velecsum,velec);
336             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
337             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
338             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
339
340             fscal            = _mm_add_pd(felec,fvdw);
341
342             fscal            = _mm_and_pd(fscal,cutoff_mask);
343
344             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
345
346             /* Update vectorial force */
347             fix0             = _mm_macc_pd(dx00,fscal,fix0);
348             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
349             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
350             
351             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
352                                                    _mm_mul_pd(dx00,fscal),
353                                                    _mm_mul_pd(dy00,fscal),
354                                                    _mm_mul_pd(dz00,fscal));
355
356             }
357
358             /* Inner loop uses 73 flops */
359         }
360
361         /* End of innermost loop */
362
363         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
364                                               f+i_coord_offset,fshift+i_shift_offset);
365
366         ggid                        = gid[iidx];
367         /* Update potential energies */
368         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
369         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
370
371         /* Increment number of inner iterations */
372         inneriter                  += j_index_end - j_index_start;
373
374         /* Outer loop uses 9 flops */
375     }
376
377     /* Increment number of outer iterations */
378     outeriter        += nri;
379
380     /* Update outer/inner flops */
381
382     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*73);
383 }
384 /*
385  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_avx_128_fma_double
386  * Electrostatics interaction: ReactionField
387  * VdW interaction:            LennardJones
388  * Geometry:                   Particle-Particle
389  * Calculate force/pot:        Force
390  */
391 void
392 nb_kernel_ElecRFCut_VdwLJSw_GeomP1P1_F_avx_128_fma_double
393                     (t_nblist                    * gmx_restrict       nlist,
394                      rvec                        * gmx_restrict          xx,
395                      rvec                        * gmx_restrict          ff,
396                      t_forcerec                  * gmx_restrict          fr,
397                      t_mdatoms                   * gmx_restrict     mdatoms,
398                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
399                      t_nrnb                      * gmx_restrict        nrnb)
400 {
401     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
402      * just 0 for non-waters.
403      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
404      * jnr indices corresponding to data put in the four positions in the SIMD register.
405      */
406     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
407     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
408     int              jnrA,jnrB;
409     int              j_coord_offsetA,j_coord_offsetB;
410     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
411     real             rcutoff_scalar;
412     real             *shiftvec,*fshift,*x,*f;
413     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
414     int              vdwioffset0;
415     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
416     int              vdwjidx0A,vdwjidx0B;
417     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
418     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
419     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
420     real             *charge;
421     int              nvdwtype;
422     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
423     int              *vdwtype;
424     real             *vdwparam;
425     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
426     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
427     __m128d          rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
428     real             rswitch_scalar,d_scalar;
429     __m128d          dummy_mask,cutoff_mask;
430     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
431     __m128d          one     = _mm_set1_pd(1.0);
432     __m128d          two     = _mm_set1_pd(2.0);
433     x                = xx[0];
434     f                = ff[0];
435
436     nri              = nlist->nri;
437     iinr             = nlist->iinr;
438     jindex           = nlist->jindex;
439     jjnr             = nlist->jjnr;
440     shiftidx         = nlist->shift;
441     gid              = nlist->gid;
442     shiftvec         = fr->shift_vec[0];
443     fshift           = fr->fshift[0];
444     facel            = _mm_set1_pd(fr->epsfac);
445     charge           = mdatoms->chargeA;
446     krf              = _mm_set1_pd(fr->ic->k_rf);
447     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
448     crf              = _mm_set1_pd(fr->ic->c_rf);
449     nvdwtype         = fr->ntype;
450     vdwparam         = fr->nbfp;
451     vdwtype          = mdatoms->typeA;
452
453     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
454     rcutoff_scalar   = fr->rcoulomb;
455     rcutoff          = _mm_set1_pd(rcutoff_scalar);
456     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
457
458     rswitch_scalar   = fr->rvdw_switch;
459     rswitch          = _mm_set1_pd(rswitch_scalar);
460     /* Setup switch parameters */
461     d_scalar         = rcutoff_scalar-rswitch_scalar;
462     d                = _mm_set1_pd(d_scalar);
463     swV3             = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
464     swV4             = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
465     swV5             = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
466     swF2             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
467     swF3             = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
468     swF4             = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
469
470     /* Avoid stupid compiler warnings */
471     jnrA = jnrB = 0;
472     j_coord_offsetA = 0;
473     j_coord_offsetB = 0;
474
475     outeriter        = 0;
476     inneriter        = 0;
477
478     /* Start outer loop over neighborlists */
479     for(iidx=0; iidx<nri; iidx++)
480     {
481         /* Load shift vector for this list */
482         i_shift_offset   = DIM*shiftidx[iidx];
483
484         /* Load limits for loop over neighbors */
485         j_index_start    = jindex[iidx];
486         j_index_end      = jindex[iidx+1];
487
488         /* Get outer coordinate index */
489         inr              = iinr[iidx];
490         i_coord_offset   = DIM*inr;
491
492         /* Load i particle coords and add shift vector */
493         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
494
495         fix0             = _mm_setzero_pd();
496         fiy0             = _mm_setzero_pd();
497         fiz0             = _mm_setzero_pd();
498
499         /* Load parameters for i particles */
500         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
501         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
502
503         /* Start inner kernel loop */
504         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
505         {
506
507             /* Get j neighbor index, and coordinate index */
508             jnrA             = jjnr[jidx];
509             jnrB             = jjnr[jidx+1];
510             j_coord_offsetA  = DIM*jnrA;
511             j_coord_offsetB  = DIM*jnrB;
512
513             /* load j atom coordinates */
514             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
515                                               &jx0,&jy0,&jz0);
516
517             /* Calculate displacement vector */
518             dx00             = _mm_sub_pd(ix0,jx0);
519             dy00             = _mm_sub_pd(iy0,jy0);
520             dz00             = _mm_sub_pd(iz0,jz0);
521
522             /* Calculate squared distance and things based on it */
523             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
524
525             rinv00           = gmx_mm_invsqrt_pd(rsq00);
526
527             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
528
529             /* Load parameters for j particles */
530             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
531             vdwjidx0A        = 2*vdwtype[jnrA+0];
532             vdwjidx0B        = 2*vdwtype[jnrB+0];
533
534             /**************************
535              * CALCULATE INTERACTIONS *
536              **************************/
537
538             if (gmx_mm_any_lt(rsq00,rcutoff2))
539             {
540
541             r00              = _mm_mul_pd(rsq00,rinv00);
542
543             /* Compute parameters for interactions between i and j atoms */
544             qq00             = _mm_mul_pd(iq0,jq0);
545             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
546                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
547
548             /* REACTION-FIELD ELECTROSTATICS */
549             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
550
551             /* LENNARD-JONES DISPERSION/REPULSION */
552
553             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
554             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
555             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
556             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
557             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
558
559             d                = _mm_sub_pd(r00,rswitch);
560             d                = _mm_max_pd(d,_mm_setzero_pd());
561             d2               = _mm_mul_pd(d,d);
562             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
563
564             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
565
566             /* Evaluate switch function */
567             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
568             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
569             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
570
571             fscal            = _mm_add_pd(felec,fvdw);
572
573             fscal            = _mm_and_pd(fscal,cutoff_mask);
574
575             /* Update vectorial force */
576             fix0             = _mm_macc_pd(dx00,fscal,fix0);
577             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
578             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
579             
580             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
581                                                    _mm_mul_pd(dx00,fscal),
582                                                    _mm_mul_pd(dy00,fscal),
583                                                    _mm_mul_pd(dz00,fscal));
584
585             }
586
587             /* Inner loop uses 64 flops */
588         }
589
590         if(jidx<j_index_end)
591         {
592
593             jnrA             = jjnr[jidx];
594             j_coord_offsetA  = DIM*jnrA;
595
596             /* load j atom coordinates */
597             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
598                                               &jx0,&jy0,&jz0);
599
600             /* Calculate displacement vector */
601             dx00             = _mm_sub_pd(ix0,jx0);
602             dy00             = _mm_sub_pd(iy0,jy0);
603             dz00             = _mm_sub_pd(iz0,jz0);
604
605             /* Calculate squared distance and things based on it */
606             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
607
608             rinv00           = gmx_mm_invsqrt_pd(rsq00);
609
610             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
611
612             /* Load parameters for j particles */
613             jq0              = _mm_load_sd(charge+jnrA+0);
614             vdwjidx0A        = 2*vdwtype[jnrA+0];
615
616             /**************************
617              * CALCULATE INTERACTIONS *
618              **************************/
619
620             if (gmx_mm_any_lt(rsq00,rcutoff2))
621             {
622
623             r00              = _mm_mul_pd(rsq00,rinv00);
624
625             /* Compute parameters for interactions between i and j atoms */
626             qq00             = _mm_mul_pd(iq0,jq0);
627             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
628
629             /* REACTION-FIELD ELECTROSTATICS */
630             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
631
632             /* LENNARD-JONES DISPERSION/REPULSION */
633
634             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
635             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
636             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
637             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
638             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
639
640             d                = _mm_sub_pd(r00,rswitch);
641             d                = _mm_max_pd(d,_mm_setzero_pd());
642             d2               = _mm_mul_pd(d,d);
643             sw               = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_macc_pd(d,_mm_macc_pd(d,swV5,swV4),swV3))));
644
645             dsw              = _mm_mul_pd(d2,_mm_macc_pd(d,_mm_macc_pd(d,swF4,swF3),swF2));
646
647             /* Evaluate switch function */
648             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
649             fvdw             = _mm_msub_pd( fvdw,sw , _mm_mul_pd(rinv00,_mm_mul_pd(vvdw,dsw)) );
650             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
651
652             fscal            = _mm_add_pd(felec,fvdw);
653
654             fscal            = _mm_and_pd(fscal,cutoff_mask);
655
656             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
657
658             /* Update vectorial force */
659             fix0             = _mm_macc_pd(dx00,fscal,fix0);
660             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
661             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
662             
663             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
664                                                    _mm_mul_pd(dx00,fscal),
665                                                    _mm_mul_pd(dy00,fscal),
666                                                    _mm_mul_pd(dz00,fscal));
667
668             }
669
670             /* Inner loop uses 64 flops */
671         }
672
673         /* End of innermost loop */
674
675         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
676                                               f+i_coord_offset,fshift+i_shift_offset);
677
678         /* Increment number of inner iterations */
679         inneriter                  += j_index_end - j_index_start;
680
681         /* Outer loop uses 7 flops */
682     }
683
684     /* Increment number of outer iterations */
685     outeriter        += nri;
686
687     /* Update outer/inner flops */
688
689     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*64);
690 }