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