Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_avx_128_fma_single.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_single 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_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_VF_avx_128_fma_single
54  * Electrostatics interaction: None
55  * VdW interaction:            LJEwald
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_VF_avx_128_fma_single
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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90     int              nvdwtype;
91     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
92     int              *vdwtype;
93     real             *vdwparam;
94     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
95     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
96     __m128           c6grid_00;
97     real             *vdwgridparam;
98     __m128           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
99     __m128           one_half = _mm_set1_ps(0.5);
100     __m128           minus_one = _mm_set1_ps(-1.0);
101     __m128           dummy_mask,cutoff_mask;
102     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
103     __m128           one     = _mm_set1_ps(1.0);
104     __m128           two     = _mm_set1_ps(2.0);
105     x                = xx[0];
106     f                = ff[0];
107
108     nri              = nlist->nri;
109     iinr             = nlist->iinr;
110     jindex           = nlist->jindex;
111     jjnr             = nlist->jjnr;
112     shiftidx         = nlist->shift;
113     gid              = nlist->gid;
114     shiftvec         = fr->shift_vec[0];
115     fshift           = fr->fshift[0];
116     nvdwtype         = fr->ntype;
117     vdwparam         = fr->nbfp;
118     vdwtype          = mdatoms->typeA;
119     vdwgridparam     = fr->ljpme_c6grid;
120     sh_lj_ewald      = _mm_set1_ps(fr->ic->sh_lj_ewald);
121     ewclj            = _mm_set1_ps(fr->ewaldcoeff_lj);
122     ewclj2           = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
123
124     rcutoff_scalar   = fr->rvdw;
125     rcutoff          = _mm_set1_ps(rcutoff_scalar);
126     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
127
128     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
129     rvdw             = _mm_set1_ps(fr->rvdw);
130
131     /* Avoid stupid compiler warnings */
132     jnrA = jnrB = jnrC = jnrD = 0;
133     j_coord_offsetA = 0;
134     j_coord_offsetB = 0;
135     j_coord_offsetC = 0;
136     j_coord_offsetD = 0;
137
138     outeriter        = 0;
139     inneriter        = 0;
140
141     for(iidx=0;iidx<4*DIM;iidx++)
142     {
143         scratch[iidx] = 0.0;
144     }
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_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
162
163         fix0             = _mm_setzero_ps();
164         fiy0             = _mm_setzero_ps();
165         fiz0             = _mm_setzero_ps();
166
167         /* Load parameters for i particles */
168         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
169
170         /* Reset potential sums */
171         vvdwsum          = _mm_setzero_ps();
172
173         /* Start inner kernel loop */
174         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
175         {
176
177             /* Get j neighbor index, and coordinate index */
178             jnrA             = jjnr[jidx];
179             jnrB             = jjnr[jidx+1];
180             jnrC             = jjnr[jidx+2];
181             jnrD             = jjnr[jidx+3];
182             j_coord_offsetA  = DIM*jnrA;
183             j_coord_offsetB  = DIM*jnrB;
184             j_coord_offsetC  = DIM*jnrC;
185             j_coord_offsetD  = DIM*jnrD;
186
187             /* load j atom coordinates */
188             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
189                                               x+j_coord_offsetC,x+j_coord_offsetD,
190                                               &jx0,&jy0,&jz0);
191
192             /* Calculate displacement vector */
193             dx00             = _mm_sub_ps(ix0,jx0);
194             dy00             = _mm_sub_ps(iy0,jy0);
195             dz00             = _mm_sub_ps(iz0,jz0);
196
197             /* Calculate squared distance and things based on it */
198             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
199
200             rinv00           = gmx_mm_invsqrt_ps(rsq00);
201
202             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
203
204             /* Load parameters for j particles */
205             vdwjidx0A        = 2*vdwtype[jnrA+0];
206             vdwjidx0B        = 2*vdwtype[jnrB+0];
207             vdwjidx0C        = 2*vdwtype[jnrC+0];
208             vdwjidx0D        = 2*vdwtype[jnrD+0];
209
210             /**************************
211              * CALCULATE INTERACTIONS *
212              **************************/
213
214             if (gmx_mm_any_lt(rsq00,rcutoff2))
215             {
216
217             r00              = _mm_mul_ps(rsq00,rinv00);
218
219             /* Compute parameters for interactions between i and j atoms */
220             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
221                                          vdwparam+vdwioffset0+vdwjidx0B,
222                                          vdwparam+vdwioffset0+vdwjidx0C,
223                                          vdwparam+vdwioffset0+vdwjidx0D,
224                                          &c6_00,&c12_00);
225
226             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
227                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
228                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
229                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
230
231             /* Analytical LJ-PME */
232             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
233             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
234             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
235             exponent         = gmx_simd_exp_r(ewcljrsq);
236             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
237             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
238             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
239             vvdw6            = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
240             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
241             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
242                                           _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
243             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
244             fvdw             = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
245
246             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
247
248             /* Update potential sum for this i atom from the interaction with this j atom. */
249             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
250             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
251
252             fscal            = fvdw;
253
254             fscal            = _mm_and_ps(fscal,cutoff_mask);
255
256              /* Update vectorial force */
257             fix0             = _mm_macc_ps(dx00,fscal,fix0);
258             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
259             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
260
261             fjptrA             = f+j_coord_offsetA;
262             fjptrB             = f+j_coord_offsetB;
263             fjptrC             = f+j_coord_offsetC;
264             fjptrD             = f+j_coord_offsetD;
265             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
266                                                    _mm_mul_ps(dx00,fscal),
267                                                    _mm_mul_ps(dy00,fscal),
268                                                    _mm_mul_ps(dz00,fscal));
269
270             }
271
272             /* Inner loop uses 59 flops */
273         }
274
275         if(jidx<j_index_end)
276         {
277
278             /* Get j neighbor index, and coordinate index */
279             jnrlistA         = jjnr[jidx];
280             jnrlistB         = jjnr[jidx+1];
281             jnrlistC         = jjnr[jidx+2];
282             jnrlistD         = jjnr[jidx+3];
283             /* Sign of each element will be negative for non-real atoms.
284              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
285              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
286              */
287             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
288             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
289             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
290             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
291             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
292             j_coord_offsetA  = DIM*jnrA;
293             j_coord_offsetB  = DIM*jnrB;
294             j_coord_offsetC  = DIM*jnrC;
295             j_coord_offsetD  = DIM*jnrD;
296
297             /* load j atom coordinates */
298             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
299                                               x+j_coord_offsetC,x+j_coord_offsetD,
300                                               &jx0,&jy0,&jz0);
301
302             /* Calculate displacement vector */
303             dx00             = _mm_sub_ps(ix0,jx0);
304             dy00             = _mm_sub_ps(iy0,jy0);
305             dz00             = _mm_sub_ps(iz0,jz0);
306
307             /* Calculate squared distance and things based on it */
308             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
309
310             rinv00           = gmx_mm_invsqrt_ps(rsq00);
311
312             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
313
314             /* Load parameters for j particles */
315             vdwjidx0A        = 2*vdwtype[jnrA+0];
316             vdwjidx0B        = 2*vdwtype[jnrB+0];
317             vdwjidx0C        = 2*vdwtype[jnrC+0];
318             vdwjidx0D        = 2*vdwtype[jnrD+0];
319
320             /**************************
321              * CALCULATE INTERACTIONS *
322              **************************/
323
324             if (gmx_mm_any_lt(rsq00,rcutoff2))
325             {
326
327             r00              = _mm_mul_ps(rsq00,rinv00);
328             r00              = _mm_andnot_ps(dummy_mask,r00);
329
330             /* Compute parameters for interactions between i and j atoms */
331             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
332                                          vdwparam+vdwioffset0+vdwjidx0B,
333                                          vdwparam+vdwioffset0+vdwjidx0C,
334                                          vdwparam+vdwioffset0+vdwjidx0D,
335                                          &c6_00,&c12_00);
336
337             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
338                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
339                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
340                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
341
342             /* Analytical LJ-PME */
343             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
344             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
345             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
346             exponent         = gmx_simd_exp_r(ewcljrsq);
347             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
348             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
349             /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
350             vvdw6            = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
351             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
352             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
353                                           _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
354             /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
355             fvdw             = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
356
357             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
358
359             /* Update potential sum for this i atom from the interaction with this j atom. */
360             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
361             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
362             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
363
364             fscal            = fvdw;
365
366             fscal            = _mm_and_ps(fscal,cutoff_mask);
367
368             fscal            = _mm_andnot_ps(dummy_mask,fscal);
369
370              /* Update vectorial force */
371             fix0             = _mm_macc_ps(dx00,fscal,fix0);
372             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
373             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
374
375             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
376             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
377             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
378             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
379             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
380                                                    _mm_mul_ps(dx00,fscal),
381                                                    _mm_mul_ps(dy00,fscal),
382                                                    _mm_mul_ps(dz00,fscal));
383
384             }
385
386             /* Inner loop uses 60 flops */
387         }
388
389         /* End of innermost loop */
390
391         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
392                                               f+i_coord_offset,fshift+i_shift_offset);
393
394         ggid                        = gid[iidx];
395         /* Update potential energies */
396         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
397
398         /* Increment number of inner iterations */
399         inneriter                  += j_index_end - j_index_start;
400
401         /* Outer loop uses 7 flops */
402     }
403
404     /* Increment number of outer iterations */
405     outeriter        += nri;
406
407     /* Update outer/inner flops */
408
409     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*60);
410 }
411 /*
412  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_F_avx_128_fma_single
413  * Electrostatics interaction: None
414  * VdW interaction:            LJEwald
415  * Geometry:                   Particle-Particle
416  * Calculate force/pot:        Force
417  */
418 void
419 nb_kernel_ElecNone_VdwLJEwSh_GeomP1P1_F_avx_128_fma_single
420                     (t_nblist                    * gmx_restrict       nlist,
421                      rvec                        * gmx_restrict          xx,
422                      rvec                        * gmx_restrict          ff,
423                      t_forcerec                  * gmx_restrict          fr,
424                      t_mdatoms                   * gmx_restrict     mdatoms,
425                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
426                      t_nrnb                      * gmx_restrict        nrnb)
427 {
428     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
429      * just 0 for non-waters.
430      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
431      * jnr indices corresponding to data put in the four positions in the SIMD register.
432      */
433     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
434     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
435     int              jnrA,jnrB,jnrC,jnrD;
436     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
437     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
438     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
439     real             rcutoff_scalar;
440     real             *shiftvec,*fshift,*x,*f;
441     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
442     real             scratch[4*DIM];
443     __m128           fscal,rcutoff,rcutoff2,jidxall;
444     int              vdwioffset0;
445     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
446     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
447     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
448     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
449     int              nvdwtype;
450     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
451     int              *vdwtype;
452     real             *vdwparam;
453     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
454     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
455     __m128           c6grid_00;
456     real             *vdwgridparam;
457     __m128           ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
458     __m128           one_half = _mm_set1_ps(0.5);
459     __m128           minus_one = _mm_set1_ps(-1.0);
460     __m128           dummy_mask,cutoff_mask;
461     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
462     __m128           one     = _mm_set1_ps(1.0);
463     __m128           two     = _mm_set1_ps(2.0);
464     x                = xx[0];
465     f                = ff[0];
466
467     nri              = nlist->nri;
468     iinr             = nlist->iinr;
469     jindex           = nlist->jindex;
470     jjnr             = nlist->jjnr;
471     shiftidx         = nlist->shift;
472     gid              = nlist->gid;
473     shiftvec         = fr->shift_vec[0];
474     fshift           = fr->fshift[0];
475     nvdwtype         = fr->ntype;
476     vdwparam         = fr->nbfp;
477     vdwtype          = mdatoms->typeA;
478     vdwgridparam     = fr->ljpme_c6grid;
479     sh_lj_ewald      = _mm_set1_ps(fr->ic->sh_lj_ewald);
480     ewclj            = _mm_set1_ps(fr->ewaldcoeff_lj);
481     ewclj2           = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
482
483     rcutoff_scalar   = fr->rvdw;
484     rcutoff          = _mm_set1_ps(rcutoff_scalar);
485     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
486
487     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
488     rvdw             = _mm_set1_ps(fr->rvdw);
489
490     /* Avoid stupid compiler warnings */
491     jnrA = jnrB = jnrC = jnrD = 0;
492     j_coord_offsetA = 0;
493     j_coord_offsetB = 0;
494     j_coord_offsetC = 0;
495     j_coord_offsetD = 0;
496
497     outeriter        = 0;
498     inneriter        = 0;
499
500     for(iidx=0;iidx<4*DIM;iidx++)
501     {
502         scratch[iidx] = 0.0;
503     }
504
505     /* Start outer loop over neighborlists */
506     for(iidx=0; iidx<nri; iidx++)
507     {
508         /* Load shift vector for this list */
509         i_shift_offset   = DIM*shiftidx[iidx];
510
511         /* Load limits for loop over neighbors */
512         j_index_start    = jindex[iidx];
513         j_index_end      = jindex[iidx+1];
514
515         /* Get outer coordinate index */
516         inr              = iinr[iidx];
517         i_coord_offset   = DIM*inr;
518
519         /* Load i particle coords and add shift vector */
520         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
521
522         fix0             = _mm_setzero_ps();
523         fiy0             = _mm_setzero_ps();
524         fiz0             = _mm_setzero_ps();
525
526         /* Load parameters for i particles */
527         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
528
529         /* Start inner kernel loop */
530         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
531         {
532
533             /* Get j neighbor index, and coordinate index */
534             jnrA             = jjnr[jidx];
535             jnrB             = jjnr[jidx+1];
536             jnrC             = jjnr[jidx+2];
537             jnrD             = jjnr[jidx+3];
538             j_coord_offsetA  = DIM*jnrA;
539             j_coord_offsetB  = DIM*jnrB;
540             j_coord_offsetC  = DIM*jnrC;
541             j_coord_offsetD  = DIM*jnrD;
542
543             /* load j atom coordinates */
544             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
545                                               x+j_coord_offsetC,x+j_coord_offsetD,
546                                               &jx0,&jy0,&jz0);
547
548             /* Calculate displacement vector */
549             dx00             = _mm_sub_ps(ix0,jx0);
550             dy00             = _mm_sub_ps(iy0,jy0);
551             dz00             = _mm_sub_ps(iz0,jz0);
552
553             /* Calculate squared distance and things based on it */
554             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
555
556             rinv00           = gmx_mm_invsqrt_ps(rsq00);
557
558             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
559
560             /* Load parameters for j particles */
561             vdwjidx0A        = 2*vdwtype[jnrA+0];
562             vdwjidx0B        = 2*vdwtype[jnrB+0];
563             vdwjidx0C        = 2*vdwtype[jnrC+0];
564             vdwjidx0D        = 2*vdwtype[jnrD+0];
565
566             /**************************
567              * CALCULATE INTERACTIONS *
568              **************************/
569
570             if (gmx_mm_any_lt(rsq00,rcutoff2))
571             {
572
573             r00              = _mm_mul_ps(rsq00,rinv00);
574
575             /* Compute parameters for interactions between i and j atoms */
576             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
577                                          vdwparam+vdwioffset0+vdwjidx0B,
578                                          vdwparam+vdwioffset0+vdwjidx0C,
579                                          vdwparam+vdwioffset0+vdwjidx0D,
580                                          &c6_00,&c12_00);
581
582             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
583                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
584                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
585                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
586
587             /* Analytical LJ-PME */
588             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
589             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
590             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
591             exponent         = gmx_simd_exp_r(ewcljrsq);
592             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
593             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
594             /* f6A = 6 * C6grid * (1 - poly) */
595             f6A              = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
596             /* f6B = C6grid * exponent * beta^6 */
597             f6B              = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
598             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
599             fvdw              = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
600
601             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
602
603             fscal            = fvdw;
604
605             fscal            = _mm_and_ps(fscal,cutoff_mask);
606
607              /* Update vectorial force */
608             fix0             = _mm_macc_ps(dx00,fscal,fix0);
609             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
610             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
611
612             fjptrA             = f+j_coord_offsetA;
613             fjptrB             = f+j_coord_offsetB;
614             fjptrC             = f+j_coord_offsetC;
615             fjptrD             = f+j_coord_offsetD;
616             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
617                                                    _mm_mul_ps(dx00,fscal),
618                                                    _mm_mul_ps(dy00,fscal),
619                                                    _mm_mul_ps(dz00,fscal));
620
621             }
622
623             /* Inner loop uses 50 flops */
624         }
625
626         if(jidx<j_index_end)
627         {
628
629             /* Get j neighbor index, and coordinate index */
630             jnrlistA         = jjnr[jidx];
631             jnrlistB         = jjnr[jidx+1];
632             jnrlistC         = jjnr[jidx+2];
633             jnrlistD         = jjnr[jidx+3];
634             /* Sign of each element will be negative for non-real atoms.
635              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
636              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
637              */
638             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
639             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
640             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
641             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
642             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
643             j_coord_offsetA  = DIM*jnrA;
644             j_coord_offsetB  = DIM*jnrB;
645             j_coord_offsetC  = DIM*jnrC;
646             j_coord_offsetD  = DIM*jnrD;
647
648             /* load j atom coordinates */
649             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
650                                               x+j_coord_offsetC,x+j_coord_offsetD,
651                                               &jx0,&jy0,&jz0);
652
653             /* Calculate displacement vector */
654             dx00             = _mm_sub_ps(ix0,jx0);
655             dy00             = _mm_sub_ps(iy0,jy0);
656             dz00             = _mm_sub_ps(iz0,jz0);
657
658             /* Calculate squared distance and things based on it */
659             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
660
661             rinv00           = gmx_mm_invsqrt_ps(rsq00);
662
663             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
664
665             /* Load parameters for j particles */
666             vdwjidx0A        = 2*vdwtype[jnrA+0];
667             vdwjidx0B        = 2*vdwtype[jnrB+0];
668             vdwjidx0C        = 2*vdwtype[jnrC+0];
669             vdwjidx0D        = 2*vdwtype[jnrD+0];
670
671             /**************************
672              * CALCULATE INTERACTIONS *
673              **************************/
674
675             if (gmx_mm_any_lt(rsq00,rcutoff2))
676             {
677
678             r00              = _mm_mul_ps(rsq00,rinv00);
679             r00              = _mm_andnot_ps(dummy_mask,r00);
680
681             /* Compute parameters for interactions between i and j atoms */
682             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
683                                          vdwparam+vdwioffset0+vdwjidx0B,
684                                          vdwparam+vdwioffset0+vdwjidx0C,
685                                          vdwparam+vdwioffset0+vdwjidx0D,
686                                          &c6_00,&c12_00);
687
688             c6grid_00       = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
689                                                                vdwgridparam+vdwioffset0+vdwjidx0B,
690                                                                vdwgridparam+vdwioffset0+vdwjidx0C,
691                                                                vdwgridparam+vdwioffset0+vdwjidx0D);
692
693             /* Analytical LJ-PME */
694             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
695             ewcljrsq         = _mm_mul_ps(ewclj2,rsq00);
696             ewclj6           = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
697             exponent         = gmx_simd_exp_r(ewcljrsq);
698             /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
699             poly             = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
700             /* f6A = 6 * C6grid * (1 - poly) */
701             f6A              = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
702             /* f6B = C6grid * exponent * beta^6 */
703             f6B              = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
704             /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
705             fvdw              = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
706
707             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
708
709             fscal            = fvdw;
710
711             fscal            = _mm_and_ps(fscal,cutoff_mask);
712
713             fscal            = _mm_andnot_ps(dummy_mask,fscal);
714
715              /* Update vectorial force */
716             fix0             = _mm_macc_ps(dx00,fscal,fix0);
717             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
718             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
719
720             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
721             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
722             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
723             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
724             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
725                                                    _mm_mul_ps(dx00,fscal),
726                                                    _mm_mul_ps(dy00,fscal),
727                                                    _mm_mul_ps(dz00,fscal));
728
729             }
730
731             /* Inner loop uses 51 flops */
732         }
733
734         /* End of innermost loop */
735
736         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
737                                               f+i_coord_offset,fshift+i_shift_offset);
738
739         /* Increment number of inner iterations */
740         inneriter                  += j_index_end - j_index_start;
741
742         /* Outer loop uses 6 flops */
743     }
744
745     /* Increment number of outer iterations */
746     outeriter        += nri;
747
748     /* Update outer/inner flops */
749
750     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*51);
751 }