34f413e64fe624f755912cf9b4049f55fd5cd3b3
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse4_1_double / nb_kernel_ElecNone_VdwLJ_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 "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "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_VdwLJ_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_VdwLJ_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          dummy_mask,cutoff_mask;
92     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
93     __m128d          one     = _mm_set1_pd(1.0);
94     __m128d          two     = _mm_set1_pd(2.0);
95     x                = xx[0];
96     f                = ff[0];
97
98     nri              = nlist->nri;
99     iinr             = nlist->iinr;
100     jindex           = nlist->jindex;
101     jjnr             = nlist->jjnr;
102     shiftidx         = nlist->shift;
103     gid              = nlist->gid;
104     shiftvec         = fr->shift_vec[0];
105     fshift           = fr->fshift[0];
106     nvdwtype         = fr->ntype;
107     vdwparam         = fr->nbfp;
108     vdwtype          = mdatoms->typeA;
109
110     /* Avoid stupid compiler warnings */
111     jnrA = jnrB = 0;
112     j_coord_offsetA = 0;
113     j_coord_offsetB = 0;
114
115     outeriter        = 0;
116     inneriter        = 0;
117
118     /* Start outer loop over neighborlists */
119     for(iidx=0; iidx<nri; iidx++)
120     {
121         /* Load shift vector for this list */
122         i_shift_offset   = DIM*shiftidx[iidx];
123
124         /* Load limits for loop over neighbors */
125         j_index_start    = jindex[iidx];
126         j_index_end      = jindex[iidx+1];
127
128         /* Get outer coordinate index */
129         inr              = iinr[iidx];
130         i_coord_offset   = DIM*inr;
131
132         /* Load i particle coords and add shift vector */
133         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
134
135         fix0             = _mm_setzero_pd();
136         fiy0             = _mm_setzero_pd();
137         fiz0             = _mm_setzero_pd();
138
139         /* Load parameters for i particles */
140         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
141
142         /* Reset potential sums */
143         vvdwsum          = _mm_setzero_pd();
144
145         /* Start inner kernel loop */
146         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
147         {
148
149             /* Get j neighbor index, and coordinate index */
150             jnrA             = jjnr[jidx];
151             jnrB             = jjnr[jidx+1];
152             j_coord_offsetA  = DIM*jnrA;
153             j_coord_offsetB  = DIM*jnrB;
154
155             /* load j atom coordinates */
156             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
157                                               &jx0,&jy0,&jz0);
158
159             /* Calculate displacement vector */
160             dx00             = _mm_sub_pd(ix0,jx0);
161             dy00             = _mm_sub_pd(iy0,jy0);
162             dz00             = _mm_sub_pd(iz0,jz0);
163
164             /* Calculate squared distance and things based on it */
165             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
166
167             rinvsq00         = gmx_mm_inv_pd(rsq00);
168
169             /* Load parameters for j particles */
170             vdwjidx0A        = 2*vdwtype[jnrA+0];
171             vdwjidx0B        = 2*vdwtype[jnrB+0];
172
173             /**************************
174              * CALCULATE INTERACTIONS *
175              **************************/
176
177             /* Compute parameters for interactions between i and j atoms */
178             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
179                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
180
181             /* LENNARD-JONES DISPERSION/REPULSION */
182
183             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
184             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
185             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
186             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
187             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
188
189             /* Update potential sum for this i atom from the interaction with this j atom. */
190             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
191
192             fscal            = fvdw;
193
194             /* Calculate temporary vectorial force */
195             tx               = _mm_mul_pd(fscal,dx00);
196             ty               = _mm_mul_pd(fscal,dy00);
197             tz               = _mm_mul_pd(fscal,dz00);
198
199             /* Update vectorial force */
200             fix0             = _mm_add_pd(fix0,tx);
201             fiy0             = _mm_add_pd(fiy0,ty);
202             fiz0             = _mm_add_pd(fiz0,tz);
203
204             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
205
206             /* Inner loop uses 32 flops */
207         }
208
209         if(jidx<j_index_end)
210         {
211
212             jnrA             = jjnr[jidx];
213             j_coord_offsetA  = DIM*jnrA;
214
215             /* load j atom coordinates */
216             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
217                                               &jx0,&jy0,&jz0);
218
219             /* Calculate displacement vector */
220             dx00             = _mm_sub_pd(ix0,jx0);
221             dy00             = _mm_sub_pd(iy0,jy0);
222             dz00             = _mm_sub_pd(iz0,jz0);
223
224             /* Calculate squared distance and things based on it */
225             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
226
227             rinvsq00         = gmx_mm_inv_pd(rsq00);
228
229             /* Load parameters for j particles */
230             vdwjidx0A        = 2*vdwtype[jnrA+0];
231
232             /**************************
233              * CALCULATE INTERACTIONS *
234              **************************/
235
236             /* Compute parameters for interactions between i and j atoms */
237             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
238
239             /* LENNARD-JONES DISPERSION/REPULSION */
240
241             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
242             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
243             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
244             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
245             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
246
247             /* Update potential sum for this i atom from the interaction with this j atom. */
248             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
249             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
250
251             fscal            = fvdw;
252
253             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
254
255             /* Calculate temporary vectorial force */
256             tx               = _mm_mul_pd(fscal,dx00);
257             ty               = _mm_mul_pd(fscal,dy00);
258             tz               = _mm_mul_pd(fscal,dz00);
259
260             /* Update vectorial force */
261             fix0             = _mm_add_pd(fix0,tx);
262             fiy0             = _mm_add_pd(fiy0,ty);
263             fiz0             = _mm_add_pd(fiz0,tz);
264
265             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
266
267             /* Inner loop uses 32 flops */
268         }
269
270         /* End of innermost loop */
271
272         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
273                                               f+i_coord_offset,fshift+i_shift_offset);
274
275         ggid                        = gid[iidx];
276         /* Update potential energies */
277         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
278
279         /* Increment number of inner iterations */
280         inneriter                  += j_index_end - j_index_start;
281
282         /* Outer loop uses 7 flops */
283     }
284
285     /* Increment number of outer iterations */
286     outeriter        += nri;
287
288     /* Update outer/inner flops */
289
290     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*32);
291 }
292 /*
293  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse4_1_double
294  * Electrostatics interaction: None
295  * VdW interaction:            LennardJones
296  * Geometry:                   Particle-Particle
297  * Calculate force/pot:        Force
298  */
299 void
300 nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse4_1_double
301                     (t_nblist                    * gmx_restrict       nlist,
302                      rvec                        * gmx_restrict          xx,
303                      rvec                        * gmx_restrict          ff,
304                      t_forcerec                  * gmx_restrict          fr,
305                      t_mdatoms                   * gmx_restrict     mdatoms,
306                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
307                      t_nrnb                      * gmx_restrict        nrnb)
308 {
309     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
310      * just 0 for non-waters.
311      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
312      * jnr indices corresponding to data put in the four positions in the SIMD register.
313      */
314     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
315     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
316     int              jnrA,jnrB;
317     int              j_coord_offsetA,j_coord_offsetB;
318     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
319     real             rcutoff_scalar;
320     real             *shiftvec,*fshift,*x,*f;
321     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
322     int              vdwioffset0;
323     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
324     int              vdwjidx0A,vdwjidx0B;
325     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
326     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
327     int              nvdwtype;
328     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
329     int              *vdwtype;
330     real             *vdwparam;
331     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
332     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
333     __m128d          dummy_mask,cutoff_mask;
334     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
335     __m128d          one     = _mm_set1_pd(1.0);
336     __m128d          two     = _mm_set1_pd(2.0);
337     x                = xx[0];
338     f                = ff[0];
339
340     nri              = nlist->nri;
341     iinr             = nlist->iinr;
342     jindex           = nlist->jindex;
343     jjnr             = nlist->jjnr;
344     shiftidx         = nlist->shift;
345     gid              = nlist->gid;
346     shiftvec         = fr->shift_vec[0];
347     fshift           = fr->fshift[0];
348     nvdwtype         = fr->ntype;
349     vdwparam         = fr->nbfp;
350     vdwtype          = mdatoms->typeA;
351
352     /* Avoid stupid compiler warnings */
353     jnrA = jnrB = 0;
354     j_coord_offsetA = 0;
355     j_coord_offsetB = 0;
356
357     outeriter        = 0;
358     inneriter        = 0;
359
360     /* Start outer loop over neighborlists */
361     for(iidx=0; iidx<nri; iidx++)
362     {
363         /* Load shift vector for this list */
364         i_shift_offset   = DIM*shiftidx[iidx];
365
366         /* Load limits for loop over neighbors */
367         j_index_start    = jindex[iidx];
368         j_index_end      = jindex[iidx+1];
369
370         /* Get outer coordinate index */
371         inr              = iinr[iidx];
372         i_coord_offset   = DIM*inr;
373
374         /* Load i particle coords and add shift vector */
375         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
376
377         fix0             = _mm_setzero_pd();
378         fiy0             = _mm_setzero_pd();
379         fiz0             = _mm_setzero_pd();
380
381         /* Load parameters for i particles */
382         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
383
384         /* Start inner kernel loop */
385         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
386         {
387
388             /* Get j neighbor index, and coordinate index */
389             jnrA             = jjnr[jidx];
390             jnrB             = jjnr[jidx+1];
391             j_coord_offsetA  = DIM*jnrA;
392             j_coord_offsetB  = DIM*jnrB;
393
394             /* load j atom coordinates */
395             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
396                                               &jx0,&jy0,&jz0);
397
398             /* Calculate displacement vector */
399             dx00             = _mm_sub_pd(ix0,jx0);
400             dy00             = _mm_sub_pd(iy0,jy0);
401             dz00             = _mm_sub_pd(iz0,jz0);
402
403             /* Calculate squared distance and things based on it */
404             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
405
406             rinvsq00         = gmx_mm_inv_pd(rsq00);
407
408             /* Load parameters for j particles */
409             vdwjidx0A        = 2*vdwtype[jnrA+0];
410             vdwjidx0B        = 2*vdwtype[jnrB+0];
411
412             /**************************
413              * CALCULATE INTERACTIONS *
414              **************************/
415
416             /* Compute parameters for interactions between i and j atoms */
417             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
418                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
419
420             /* LENNARD-JONES DISPERSION/REPULSION */
421
422             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
423             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
424
425             fscal            = fvdw;
426
427             /* Calculate temporary vectorial force */
428             tx               = _mm_mul_pd(fscal,dx00);
429             ty               = _mm_mul_pd(fscal,dy00);
430             tz               = _mm_mul_pd(fscal,dz00);
431
432             /* Update vectorial force */
433             fix0             = _mm_add_pd(fix0,tx);
434             fiy0             = _mm_add_pd(fiy0,ty);
435             fiz0             = _mm_add_pd(fiz0,tz);
436
437             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
438
439             /* Inner loop uses 27 flops */
440         }
441
442         if(jidx<j_index_end)
443         {
444
445             jnrA             = jjnr[jidx];
446             j_coord_offsetA  = DIM*jnrA;
447
448             /* load j atom coordinates */
449             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
450                                               &jx0,&jy0,&jz0);
451
452             /* Calculate displacement vector */
453             dx00             = _mm_sub_pd(ix0,jx0);
454             dy00             = _mm_sub_pd(iy0,jy0);
455             dz00             = _mm_sub_pd(iz0,jz0);
456
457             /* Calculate squared distance and things based on it */
458             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
459
460             rinvsq00         = gmx_mm_inv_pd(rsq00);
461
462             /* Load parameters for j particles */
463             vdwjidx0A        = 2*vdwtype[jnrA+0];
464
465             /**************************
466              * CALCULATE INTERACTIONS *
467              **************************/
468
469             /* Compute parameters for interactions between i and j atoms */
470             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
471
472             /* LENNARD-JONES DISPERSION/REPULSION */
473
474             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
475             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
476
477             fscal            = fvdw;
478
479             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
480
481             /* Calculate temporary vectorial force */
482             tx               = _mm_mul_pd(fscal,dx00);
483             ty               = _mm_mul_pd(fscal,dy00);
484             tz               = _mm_mul_pd(fscal,dz00);
485
486             /* Update vectorial force */
487             fix0             = _mm_add_pd(fix0,tx);
488             fiy0             = _mm_add_pd(fiy0,ty);
489             fiz0             = _mm_add_pd(fiz0,tz);
490
491             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
492
493             /* Inner loop uses 27 flops */
494         }
495
496         /* End of innermost loop */
497
498         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
499                                               f+i_coord_offset,fshift+i_shift_offset);
500
501         /* Increment number of inner iterations */
502         inneriter                  += j_index_end - j_index_start;
503
504         /* Outer loop uses 6 flops */
505     }
506
507     /* Increment number of outer iterations */
508     outeriter        += nri;
509
510     /* Update outer/inner flops */
511
512     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*27);
513 }