removed (harmless) left-over in nbnxn SIMD kernels
[alexxy/gromacs.git] / src / mdlib / nbnxn_kernels / nbnxn_kernel_file_generator / nbnxn_kernel_simd_template.c.pre
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include "typedefs.h"
6
7 #ifdef {0}
8
9 {1}
10 #include "gmx_simd_macros.h"
11 #include "gmx_simd_vec.h"
12 {2}
13 #define GMX_SIMD_J_UNROLL_SIZE {3}
14 #include "{4}"
15 #include "../nbnxn_kernel_common.h"
16 #include "gmx_omp_nthreads.h"
17 #include "types/force_flags.h"
18
19 /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
20  */
21 enum {{
22     coultRF, coultTAB, coultTAB_TWIN, coultEWALD, coultEWALD_TWIN, coultNR
23 }};
24
25 /* Declare and define the kernel function pointer lookup tables. */
26 static p_nbk_func_ener p_nbk_ener[coultNR][ljcrNR] =
27 {7}
28 static p_nbk_func_ener p_nbk_energrp[coultNR][ljcrNR] =
29 {8}
30 static p_nbk_func_noener p_nbk_noener[coultNR][ljcrNR] =
31 {9}
32
33 static void
34 reduce_group_energies(int ng, int ng_2log,
35                       const real *VSvdw, const real *VSc,
36                       real *Vvdw, real *Vc)
37 {{
38     const int unrollj      = GMX_SIMD_WIDTH_HERE/GMX_SIMD_J_UNROLL_SIZE;
39     const int unrollj_half = unrollj/2;
40     int       ng_p2, i, j, j0, j1, c, s;
41
42     ng_p2 = (1<<ng_2log);
43
44     /* The size of the x86 SIMD energy group buffer array is:
45      * ng*ng*ng_p2*unrollj_half*simd_width
46      */
47     for (i = 0; i < ng; i++)
48     {{
49         for (j = 0; j < ng; j++)
50         {{
51             Vvdw[i*ng+j] = 0;
52             Vc[i*ng+j]   = 0;
53         }}
54
55         for (j1 = 0; j1 < ng; j1++)
56         {{
57             for (j0 = 0; j0 < ng; j0++)
58             {{
59                 c = ((i*ng + j1)*ng_p2 + j0)*unrollj_half*unrollj;
60                 for (s = 0; s < unrollj_half; s++)
61                 {{
62                     Vvdw[i*ng+j0] += VSvdw[c+0];
63                     Vvdw[i*ng+j1] += VSvdw[c+1];
64                     Vc  [i*ng+j0] += VSc  [c+0];
65                     Vc  [i*ng+j1] += VSc  [c+1];
66                     c             += unrollj + 2;
67                 }}
68             }}
69         }}
70     }}
71 }}
72
73 #else /* {0} */
74
75 #include "gmx_fatal.h"
76
77 #endif /* {0} */
78
79 void
80 {5}(nbnxn_pairlist_set_t       *nbl_list,
81 {6}const nbnxn_atomdata_t     *nbat,
82 {6}const interaction_const_t  *ic,
83 {6}int                         ewald_excl,
84 {6}rvec                       *shift_vec,
85 {6}int                         force_flags,
86 {6}int                         clearF,
87 {6}real                       *fshift,
88 {6}real                       *Vc,
89 {6}real                       *Vvdw)
90 #ifdef {0}
91 {{
92     int                nnbl;
93     nbnxn_pairlist_t **nbl;
94     int                coult;
95     int                nb;
96
97     nnbl = nbl_list->nnbl;
98     nbl  = nbl_list->nbl;
99
100     if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
101     {{
102         coult = coultRF;
103     }}
104     else
105     {{
106         if (ewald_excl == ewaldexclTable)
107         {{
108             if (ic->rcoulomb == ic->rvdw)
109             {{
110                 coult = coultTAB;
111             }}
112             else
113             {{
114                 coult = coultTAB_TWIN;
115             }}
116         }}
117         else
118         {{
119             if (ic->rcoulomb == ic->rvdw)
120             {{
121                 coult = coultEWALD;
122             }}
123             else
124             {{
125                 coult = coultEWALD_TWIN;
126             }}
127         }}
128     }}
129
130 #pragma omp parallel for schedule(static) num_threads(gmx_omp_nthreads_get(emntNonbonded))
131     for (nb = 0; nb < nnbl; nb++)
132     {{
133         nbnxn_atomdata_output_t *out;
134         real                    *fshift_p;
135
136         out = &nbat->out[nb];
137
138         if (clearF == enbvClearFYes)
139         {{
140             clear_f(nbat, nb, out->f);
141         }}
142
143         if ((force_flags & GMX_FORCE_VIRIAL) && nnbl == 1)
144         {{
145             fshift_p = fshift;
146         }}
147         else
148         {{
149             fshift_p = out->fshift;
150
151             if (clearF == enbvClearFYes)
152             {{
153                 clear_fshift(fshift_p);
154             }}
155         }}
156
157         if (!(force_flags & GMX_FORCE_ENERGY))
158         {{
159             /* Don't calculate energies */
160             p_nbk_noener[coult][nbat->comb_rule](nbl[nb], nbat,
161                                                  ic,
162                                                  shift_vec,
163                                                  out->f,
164                                                  fshift_p);
165         }}
166         else if (out->nV == 1)
167         {{
168             /* No energy groups */
169             out->Vvdw[0] = 0;
170             out->Vc[0]   = 0;
171
172             p_nbk_ener[coult][nbat->comb_rule](nbl[nb], nbat,
173                                                ic,
174                                                shift_vec,
175                                                out->f,
176                                                fshift_p,
177                                                out->Vvdw,
178                                                out->Vc);
179         }}
180         else
181         {{
182             /* Calculate energy group contributions */
183             int i;
184
185             for (i = 0; i < out->nVS; i++)
186             {{
187                 out->VSvdw[i] = 0;
188             }}
189             for (i = 0; i < out->nVS; i++)
190             {{
191                 out->VSc[i] = 0;
192             }}
193
194             p_nbk_energrp[coult][nbat->comb_rule](nbl[nb], nbat,
195                                                   ic,
196                                                   shift_vec,
197                                                   out->f,
198                                                   fshift_p,
199                                                   out->VSvdw,
200                                                   out->VSc);
201
202             reduce_group_energies(nbat->nenergrp, nbat->neg_2log,
203                                   out->VSvdw, out->VSc,
204                                   out->Vvdw, out->Vc);
205         }}
206     }}
207
208     if (force_flags & GMX_FORCE_ENERGY)
209     {{
210         reduce_energies_over_lists(nbat, nnbl, Vvdw, Vc);
211     }}
212 }}
213 #else
214 {{
215     gmx_incons("{5} called when such kernels "
216                " are not enabled.");
217 }}
218 #endif
219 #undef GMX_SIMD_J_UNROLL_SIZE