Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecNone_VdwLJ_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,2015,2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 #include "kernelutil_x86_avx_128_fma_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_avx_128_fma_double
51  * Electrostatics interaction: None
52  * VdW interaction:            LennardJones
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_avx_128_fma_double
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      struct t_forcerec           * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67      * just 0 for non-waters.
68      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69      * jnr indices corresponding to data put in the four positions in the SIMD register.
70      */
71     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
72     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73     int              jnrA,jnrB;
74     int              j_coord_offsetA,j_coord_offsetB;
75     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
76     real             rcutoff_scalar;
77     real             *shiftvec,*fshift,*x,*f;
78     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
79     int              vdwioffset0;
80     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81     int              vdwjidx0A,vdwjidx0B;
82     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84     int              nvdwtype;
85     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
86     int              *vdwtype;
87     real             *vdwparam;
88     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
89     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
90     __m128d          dummy_mask,cutoff_mask;
91     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
92     __m128d          one     = _mm_set1_pd(1.0);
93     __m128d          two     = _mm_set1_pd(2.0);
94     x                = xx[0];
95     f                = ff[0];
96
97     nri              = nlist->nri;
98     iinr             = nlist->iinr;
99     jindex           = nlist->jindex;
100     jjnr             = nlist->jjnr;
101     shiftidx         = nlist->shift;
102     gid              = nlist->gid;
103     shiftvec         = fr->shift_vec[0];
104     fshift           = fr->fshift[0];
105     nvdwtype         = fr->ntype;
106     vdwparam         = fr->nbfp;
107     vdwtype          = mdatoms->typeA;
108
109     /* Avoid stupid compiler warnings */
110     jnrA = jnrB = 0;
111     j_coord_offsetA = 0;
112     j_coord_offsetB = 0;
113
114     outeriter        = 0;
115     inneriter        = 0;
116
117     /* Start outer loop over neighborlists */
118     for(iidx=0; iidx<nri; iidx++)
119     {
120         /* Load shift vector for this list */
121         i_shift_offset   = DIM*shiftidx[iidx];
122
123         /* Load limits for loop over neighbors */
124         j_index_start    = jindex[iidx];
125         j_index_end      = jindex[iidx+1];
126
127         /* Get outer coordinate index */
128         inr              = iinr[iidx];
129         i_coord_offset   = DIM*inr;
130
131         /* Load i particle coords and add shift vector */
132         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
133
134         fix0             = _mm_setzero_pd();
135         fiy0             = _mm_setzero_pd();
136         fiz0             = _mm_setzero_pd();
137
138         /* Load parameters for i particles */
139         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
140
141         /* Reset potential sums */
142         vvdwsum          = _mm_setzero_pd();
143
144         /* Start inner kernel loop */
145         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
146         {
147
148             /* Get j neighbor index, and coordinate index */
149             jnrA             = jjnr[jidx];
150             jnrB             = jjnr[jidx+1];
151             j_coord_offsetA  = DIM*jnrA;
152             j_coord_offsetB  = DIM*jnrB;
153
154             /* load j atom coordinates */
155             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
156                                               &jx0,&jy0,&jz0);
157
158             /* Calculate displacement vector */
159             dx00             = _mm_sub_pd(ix0,jx0);
160             dy00             = _mm_sub_pd(iy0,jy0);
161             dz00             = _mm_sub_pd(iz0,jz0);
162
163             /* Calculate squared distance and things based on it */
164             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
165
166             rinvsq00         = avx128fma_inv_d(rsq00);
167
168             /* Load parameters for j particles */
169             vdwjidx0A        = 2*vdwtype[jnrA+0];
170             vdwjidx0B        = 2*vdwtype[jnrB+0];
171
172             /**************************
173              * CALCULATE INTERACTIONS *
174              **************************/
175
176             /* Compute parameters for interactions between i and j atoms */
177             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
178                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
179
180             /* LENNARD-JONES DISPERSION/REPULSION */
181
182             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
183             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
184             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
185             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
186             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
187
188             /* Update potential sum for this i atom from the interaction with this j atom. */
189             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
190
191             fscal            = fvdw;
192
193             /* Update vectorial force */
194             fix0             = _mm_macc_pd(dx00,fscal,fix0);
195             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
196             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
197             
198             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
199                                                    _mm_mul_pd(dx00,fscal),
200                                                    _mm_mul_pd(dy00,fscal),
201                                                    _mm_mul_pd(dz00,fscal));
202
203             /* Inner loop uses 35 flops */
204         }
205
206         if(jidx<j_index_end)
207         {
208
209             jnrA             = jjnr[jidx];
210             j_coord_offsetA  = DIM*jnrA;
211
212             /* load j atom coordinates */
213             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
214                                               &jx0,&jy0,&jz0);
215
216             /* Calculate displacement vector */
217             dx00             = _mm_sub_pd(ix0,jx0);
218             dy00             = _mm_sub_pd(iy0,jy0);
219             dz00             = _mm_sub_pd(iz0,jz0);
220
221             /* Calculate squared distance and things based on it */
222             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
223
224             rinvsq00         = avx128fma_inv_d(rsq00);
225
226             /* Load parameters for j particles */
227             vdwjidx0A        = 2*vdwtype[jnrA+0];
228
229             /**************************
230              * CALCULATE INTERACTIONS *
231              **************************/
232
233             /* Compute parameters for interactions between i and j atoms */
234             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
235
236             /* LENNARD-JONES DISPERSION/REPULSION */
237
238             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
239             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
240             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
241             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
242             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
243
244             /* Update potential sum for this i atom from the interaction with this j atom. */
245             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
246             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
247
248             fscal            = fvdw;
249
250             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
251
252             /* Update vectorial force */
253             fix0             = _mm_macc_pd(dx00,fscal,fix0);
254             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
255             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
256             
257             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
258                                                    _mm_mul_pd(dx00,fscal),
259                                                    _mm_mul_pd(dy00,fscal),
260                                                    _mm_mul_pd(dz00,fscal));
261
262             /* Inner loop uses 35 flops */
263         }
264
265         /* End of innermost loop */
266
267         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
268                                               f+i_coord_offset,fshift+i_shift_offset);
269
270         ggid                        = gid[iidx];
271         /* Update potential energies */
272         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
273
274         /* Increment number of inner iterations */
275         inneriter                  += j_index_end - j_index_start;
276
277         /* Outer loop uses 7 flops */
278     }
279
280     /* Increment number of outer iterations */
281     outeriter        += nri;
282
283     /* Update outer/inner flops */
284
285     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*35);
286 }
287 /*
288  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_avx_128_fma_double
289  * Electrostatics interaction: None
290  * VdW interaction:            LennardJones
291  * Geometry:                   Particle-Particle
292  * Calculate force/pot:        Force
293  */
294 void
295 nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_avx_128_fma_double
296                     (t_nblist                    * gmx_restrict       nlist,
297                      rvec                        * gmx_restrict          xx,
298                      rvec                        * gmx_restrict          ff,
299                      struct t_forcerec           * gmx_restrict          fr,
300                      t_mdatoms                   * gmx_restrict     mdatoms,
301                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
302                      t_nrnb                      * gmx_restrict        nrnb)
303 {
304     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
305      * just 0 for non-waters.
306      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
307      * jnr indices corresponding to data put in the four positions in the SIMD register.
308      */
309     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
310     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
311     int              jnrA,jnrB;
312     int              j_coord_offsetA,j_coord_offsetB;
313     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
314     real             rcutoff_scalar;
315     real             *shiftvec,*fshift,*x,*f;
316     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
317     int              vdwioffset0;
318     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
319     int              vdwjidx0A,vdwjidx0B;
320     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
321     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
322     int              nvdwtype;
323     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
324     int              *vdwtype;
325     real             *vdwparam;
326     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
327     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
328     __m128d          dummy_mask,cutoff_mask;
329     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
330     __m128d          one     = _mm_set1_pd(1.0);
331     __m128d          two     = _mm_set1_pd(2.0);
332     x                = xx[0];
333     f                = ff[0];
334
335     nri              = nlist->nri;
336     iinr             = nlist->iinr;
337     jindex           = nlist->jindex;
338     jjnr             = nlist->jjnr;
339     shiftidx         = nlist->shift;
340     gid              = nlist->gid;
341     shiftvec         = fr->shift_vec[0];
342     fshift           = fr->fshift[0];
343     nvdwtype         = fr->ntype;
344     vdwparam         = fr->nbfp;
345     vdwtype          = mdatoms->typeA;
346
347     /* Avoid stupid compiler warnings */
348     jnrA = jnrB = 0;
349     j_coord_offsetA = 0;
350     j_coord_offsetB = 0;
351
352     outeriter        = 0;
353     inneriter        = 0;
354
355     /* Start outer loop over neighborlists */
356     for(iidx=0; iidx<nri; iidx++)
357     {
358         /* Load shift vector for this list */
359         i_shift_offset   = DIM*shiftidx[iidx];
360
361         /* Load limits for loop over neighbors */
362         j_index_start    = jindex[iidx];
363         j_index_end      = jindex[iidx+1];
364
365         /* Get outer coordinate index */
366         inr              = iinr[iidx];
367         i_coord_offset   = DIM*inr;
368
369         /* Load i particle coords and add shift vector */
370         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
371
372         fix0             = _mm_setzero_pd();
373         fiy0             = _mm_setzero_pd();
374         fiz0             = _mm_setzero_pd();
375
376         /* Load parameters for i particles */
377         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
378
379         /* Start inner kernel loop */
380         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
381         {
382
383             /* Get j neighbor index, and coordinate index */
384             jnrA             = jjnr[jidx];
385             jnrB             = jjnr[jidx+1];
386             j_coord_offsetA  = DIM*jnrA;
387             j_coord_offsetB  = DIM*jnrB;
388
389             /* load j atom coordinates */
390             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
391                                               &jx0,&jy0,&jz0);
392
393             /* Calculate displacement vector */
394             dx00             = _mm_sub_pd(ix0,jx0);
395             dy00             = _mm_sub_pd(iy0,jy0);
396             dz00             = _mm_sub_pd(iz0,jz0);
397
398             /* Calculate squared distance and things based on it */
399             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
400
401             rinvsq00         = avx128fma_inv_d(rsq00);
402
403             /* Load parameters for j particles */
404             vdwjidx0A        = 2*vdwtype[jnrA+0];
405             vdwjidx0B        = 2*vdwtype[jnrB+0];
406
407             /**************************
408              * CALCULATE INTERACTIONS *
409              **************************/
410
411             /* Compute parameters for interactions between i and j atoms */
412             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
413                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
414
415             /* LENNARD-JONES DISPERSION/REPULSION */
416
417             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
418             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
419
420             fscal            = fvdw;
421
422             /* Update vectorial force */
423             fix0             = _mm_macc_pd(dx00,fscal,fix0);
424             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
425             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
426             
427             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
428                                                    _mm_mul_pd(dx00,fscal),
429                                                    _mm_mul_pd(dy00,fscal),
430                                                    _mm_mul_pd(dz00,fscal));
431
432             /* Inner loop uses 30 flops */
433         }
434
435         if(jidx<j_index_end)
436         {
437
438             jnrA             = jjnr[jidx];
439             j_coord_offsetA  = DIM*jnrA;
440
441             /* load j atom coordinates */
442             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
443                                               &jx0,&jy0,&jz0);
444
445             /* Calculate displacement vector */
446             dx00             = _mm_sub_pd(ix0,jx0);
447             dy00             = _mm_sub_pd(iy0,jy0);
448             dz00             = _mm_sub_pd(iz0,jz0);
449
450             /* Calculate squared distance and things based on it */
451             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
452
453             rinvsq00         = avx128fma_inv_d(rsq00);
454
455             /* Load parameters for j particles */
456             vdwjidx0A        = 2*vdwtype[jnrA+0];
457
458             /**************************
459              * CALCULATE INTERACTIONS *
460              **************************/
461
462             /* Compute parameters for interactions between i and j atoms */
463             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
464
465             /* LENNARD-JONES DISPERSION/REPULSION */
466
467             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
468             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
469
470             fscal            = fvdw;
471
472             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
473
474             /* Update vectorial force */
475             fix0             = _mm_macc_pd(dx00,fscal,fix0);
476             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
477             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
478             
479             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
480                                                    _mm_mul_pd(dx00,fscal),
481                                                    _mm_mul_pd(dy00,fscal),
482                                                    _mm_mul_pd(dz00,fscal));
483
484             /* Inner loop uses 30 flops */
485         }
486
487         /* End of innermost loop */
488
489         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
490                                               f+i_coord_offset,fshift+i_shift_offset);
491
492         /* Increment number of inner iterations */
493         inneriter                  += j_index_end - j_index_start;
494
495         /* Outer loop uses 6 flops */
496     }
497
498     /* Increment number of outer iterations */
499     outeriter        += nri;
500
501     /* Update outer/inner flops */
502
503     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*30);
504 }