Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / mdlib / nbnxn_kernels / simd_4xn / nbnxn_kernel_simd_4xn.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 Verlet kernel generator for
37  * kernel type 4xn.
38  */
39
40 #include "config.h"
41
42 #include "typedefs.h"
43
44 #include "gromacs/mdlib/nbnxn_simd.h"
45
46 #ifdef GMX_NBNXN_SIMD_4XN
47
48 #include "gromacs/simd/vector_operations.h"
49
50 #if !(GMX_SIMD_REAL_WIDTH == 2 || GMX_SIMD_REAL_WIDTH == 4 || GMX_SIMD_REAL_WIDTH == 8)
51 #error "unsupported SIMD width"
52 #endif
53
54 #define GMX_SIMD_J_UNROLL_SIZE 1
55 #include "nbnxn_kernel_simd_4xn.h"
56 #include "../nbnxn_kernel_common.h"
57 #include "gmx_omp_nthreads.h"
58 #include "types/force_flags.h"
59 #include "gromacs/utility/fatalerror.h"
60
61 /*! \brief Kinds of electrostatic treatments in SIMD Verlet kernels
62  */
63 enum {
64     coulktRF, coulktTAB, coulktTAB_TWIN, coulktEWALD, coulktEWALD_TWIN, coulktNR
65 };
66
67 /*! \brief Kinds of Van der Waals treatments in SIMD Verlet kernels
68  */
69 enum {
70     vdwktLJCUT_COMBGEOM, vdwktLJCUT_COMBLB, vdwktLJCUT_COMBNONE, vdwktLJFORCESWITCH, vdwktLJPOTSWITCH, vdwktLJEWALDCOMBGEOM, vdwktNR
71 };
72
73 /* Declare and define the kernel function pointer lookup tables.
74  * The minor index of the array goes over both the LJ combination rules,
75  * which is only supported by plain cut-off, and the LJ switch/PME functions.
76  */
77 static p_nbk_func_noener p_nbk_noener[coulktNR][vdwktNR] =
78 {
79     {
80         nbnxn_kernel_ElecRF_VdwLJCombGeom_F_4xn,
81         nbnxn_kernel_ElecRF_VdwLJCombLB_F_4xn,
82         nbnxn_kernel_ElecRF_VdwLJ_F_4xn,
83         nbnxn_kernel_ElecRF_VdwLJFSw_F_4xn,
84         nbnxn_kernel_ElecRF_VdwLJPSw_F_4xn,
85         nbnxn_kernel_ElecRF_VdwLJEwCombGeom_F_4xn,
86     },
87     {
88         nbnxn_kernel_ElecQSTab_VdwLJCombGeom_F_4xn,
89         nbnxn_kernel_ElecQSTab_VdwLJCombLB_F_4xn,
90         nbnxn_kernel_ElecQSTab_VdwLJ_F_4xn,
91         nbnxn_kernel_ElecQSTab_VdwLJFSw_F_4xn,
92         nbnxn_kernel_ElecQSTab_VdwLJPSw_F_4xn,
93         nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_F_4xn,
94     },
95     {
96         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombGeom_F_4xn,
97         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombLB_F_4xn,
98         nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_F_4xn,
99         nbnxn_kernel_ElecQSTabTwinCut_VdwLJFSw_F_4xn,
100         nbnxn_kernel_ElecQSTabTwinCut_VdwLJPSw_F_4xn,
101         nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_F_4xn,
102     },
103     {
104         nbnxn_kernel_ElecEw_VdwLJCombGeom_F_4xn,
105         nbnxn_kernel_ElecEw_VdwLJCombLB_F_4xn,
106         nbnxn_kernel_ElecEw_VdwLJ_F_4xn,
107         nbnxn_kernel_ElecEw_VdwLJFSw_F_4xn,
108         nbnxn_kernel_ElecEw_VdwLJPSw_F_4xn,
109         nbnxn_kernel_ElecEw_VdwLJEwCombGeom_F_4xn,
110     },
111     {
112         nbnxn_kernel_ElecEwTwinCut_VdwLJCombGeom_F_4xn,
113         nbnxn_kernel_ElecEwTwinCut_VdwLJCombLB_F_4xn,
114         nbnxn_kernel_ElecEwTwinCut_VdwLJ_F_4xn,
115         nbnxn_kernel_ElecEwTwinCut_VdwLJFSw_F_4xn,
116         nbnxn_kernel_ElecEwTwinCut_VdwLJPSw_F_4xn,
117         nbnxn_kernel_ElecEwTwinCut_VdwLJEwCombGeom_F_4xn,
118     },
119 };
120
121 static p_nbk_func_ener p_nbk_ener[coulktNR][vdwktNR] =
122 {
123     {
124         nbnxn_kernel_ElecRF_VdwLJCombGeom_VF_4xn,
125         nbnxn_kernel_ElecRF_VdwLJCombLB_VF_4xn,
126         nbnxn_kernel_ElecRF_VdwLJ_VF_4xn,
127         nbnxn_kernel_ElecRF_VdwLJFSw_VF_4xn,
128         nbnxn_kernel_ElecRF_VdwLJPSw_VF_4xn,
129         nbnxn_kernel_ElecRF_VdwLJEwCombGeom_VF_4xn,
130     },
131     {
132         nbnxn_kernel_ElecQSTab_VdwLJCombGeom_VF_4xn,
133         nbnxn_kernel_ElecQSTab_VdwLJCombLB_VF_4xn,
134         nbnxn_kernel_ElecQSTab_VdwLJ_VF_4xn,
135         nbnxn_kernel_ElecQSTab_VdwLJFSw_VF_4xn,
136         nbnxn_kernel_ElecQSTab_VdwLJPSw_VF_4xn,
137         nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_VF_4xn,
138     },
139     {
140         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombGeom_VF_4xn,
141         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombLB_VF_4xn,
142         nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_VF_4xn,
143         nbnxn_kernel_ElecQSTabTwinCut_VdwLJFSw_VF_4xn,
144         nbnxn_kernel_ElecQSTabTwinCut_VdwLJPSw_VF_4xn,
145         nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_VF_4xn,
146     },
147     {
148         nbnxn_kernel_ElecEw_VdwLJCombGeom_VF_4xn,
149         nbnxn_kernel_ElecEw_VdwLJCombLB_VF_4xn,
150         nbnxn_kernel_ElecEw_VdwLJ_VF_4xn,
151         nbnxn_kernel_ElecEw_VdwLJFSw_VF_4xn,
152         nbnxn_kernel_ElecEw_VdwLJPSw_VF_4xn,
153         nbnxn_kernel_ElecEw_VdwLJEwCombGeom_VF_4xn,
154     },
155     {
156         nbnxn_kernel_ElecEwTwinCut_VdwLJCombGeom_VF_4xn,
157         nbnxn_kernel_ElecEwTwinCut_VdwLJCombLB_VF_4xn,
158         nbnxn_kernel_ElecEwTwinCut_VdwLJ_VF_4xn,
159         nbnxn_kernel_ElecEwTwinCut_VdwLJFSw_VF_4xn,
160         nbnxn_kernel_ElecEwTwinCut_VdwLJPSw_VF_4xn,
161         nbnxn_kernel_ElecEwTwinCut_VdwLJEwCombGeom_VF_4xn,
162     },
163 };
164
165 static p_nbk_func_ener p_nbk_energrp[coulktNR][vdwktNR] =
166 {
167     {
168         nbnxn_kernel_ElecRF_VdwLJCombGeom_VgrpF_4xn,
169         nbnxn_kernel_ElecRF_VdwLJCombLB_VgrpF_4xn,
170         nbnxn_kernel_ElecRF_VdwLJ_VgrpF_4xn,
171         nbnxn_kernel_ElecRF_VdwLJFSw_VgrpF_4xn,
172         nbnxn_kernel_ElecRF_VdwLJPSw_VgrpF_4xn,
173         nbnxn_kernel_ElecRF_VdwLJEwCombGeom_VgrpF_4xn,
174     },
175     {
176         nbnxn_kernel_ElecQSTab_VdwLJCombGeom_VgrpF_4xn,
177         nbnxn_kernel_ElecQSTab_VdwLJCombLB_VgrpF_4xn,
178         nbnxn_kernel_ElecQSTab_VdwLJ_VgrpF_4xn,
179         nbnxn_kernel_ElecQSTab_VdwLJFSw_VgrpF_4xn,
180         nbnxn_kernel_ElecQSTab_VdwLJPSw_VgrpF_4xn,
181         nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_VgrpF_4xn,
182     },
183     {
184         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombGeom_VgrpF_4xn,
185         nbnxn_kernel_ElecQSTabTwinCut_VdwLJCombLB_VgrpF_4xn,
186         nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_VgrpF_4xn,
187         nbnxn_kernel_ElecQSTabTwinCut_VdwLJFSw_VgrpF_4xn,
188         nbnxn_kernel_ElecQSTabTwinCut_VdwLJPSw_VgrpF_4xn,
189         nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_VgrpF_4xn,
190     },
191     {
192         nbnxn_kernel_ElecEw_VdwLJCombGeom_VgrpF_4xn,
193         nbnxn_kernel_ElecEw_VdwLJCombLB_VgrpF_4xn,
194         nbnxn_kernel_ElecEw_VdwLJ_VgrpF_4xn,
195         nbnxn_kernel_ElecEw_VdwLJFSw_VgrpF_4xn,
196         nbnxn_kernel_ElecEw_VdwLJPSw_VgrpF_4xn,
197         nbnxn_kernel_ElecEw_VdwLJEwCombGeom_VgrpF_4xn,
198     },
199     {
200         nbnxn_kernel_ElecEwTwinCut_VdwLJCombGeom_VgrpF_4xn,
201         nbnxn_kernel_ElecEwTwinCut_VdwLJCombLB_VgrpF_4xn,
202         nbnxn_kernel_ElecEwTwinCut_VdwLJ_VgrpF_4xn,
203         nbnxn_kernel_ElecEwTwinCut_VdwLJFSw_VgrpF_4xn,
204         nbnxn_kernel_ElecEwTwinCut_VdwLJPSw_VgrpF_4xn,
205         nbnxn_kernel_ElecEwTwinCut_VdwLJEwCombGeom_VgrpF_4xn,
206     },
207 };
208
209
210 static void
211 reduce_group_energies(int ng, int ng_2log,
212                       const real *VSvdw, const real *VSc,
213                       real *Vvdw, real *Vc)
214 {
215     const int unrollj      = GMX_SIMD_REAL_WIDTH/GMX_SIMD_J_UNROLL_SIZE;
216     const int unrollj_half = unrollj/2;
217     int       ng_p2, i, j, j0, j1, c, s;
218
219     ng_p2 = (1<<ng_2log);
220
221     /* The size of the x86 SIMD energy group buffer array is:
222      * ng*ng*ng_p2*unrollj_half*simd_width
223      */
224     for (i = 0; i < ng; i++)
225     {
226         for (j = 0; j < ng; j++)
227         {
228             Vvdw[i*ng+j] = 0;
229             Vc[i*ng+j]   = 0;
230         }
231
232         for (j1 = 0; j1 < ng; j1++)
233         {
234             for (j0 = 0; j0 < ng; j0++)
235             {
236                 c = ((i*ng + j1)*ng_p2 + j0)*unrollj_half*unrollj;
237                 for (s = 0; s < unrollj_half; s++)
238                 {
239                     Vvdw[i*ng+j0] += VSvdw[c+0];
240                     Vvdw[i*ng+j1] += VSvdw[c+1];
241                     Vc  [i*ng+j0] += VSc  [c+0];
242                     Vc  [i*ng+j1] += VSc  [c+1];
243                     c             += unrollj + 2;
244                 }
245             }
246         }
247     }
248 }
249
250 #else /* GMX_NBNXN_SIMD_4XN */
251
252 #include "gromacs/utility/fatalerror.h"
253
254 #endif /* GMX_NBNXN_SIMD_4XN */
255
256 void
257 nbnxn_kernel_simd_4xn(nbnxn_pairlist_set_t      gmx_unused *nbl_list,
258                       const nbnxn_atomdata_t    gmx_unused *nbat,
259                       const interaction_const_t gmx_unused *ic,
260                       int                       gmx_unused  ewald_excl,
261                       rvec                      gmx_unused *shift_vec,
262                       int                       gmx_unused  force_flags,
263                       int                       gmx_unused  clearF,
264                       real                      gmx_unused *fshift,
265                       real                      gmx_unused *Vc,
266                       real                      gmx_unused *Vvdw)
267 #ifdef GMX_NBNXN_SIMD_4XN
268 {
269     int                nnbl;
270     nbnxn_pairlist_t **nbl;
271     int                coulkt, vdwkt = 0;
272     int                nb;
273
274     nnbl = nbl_list->nnbl;
275     nbl  = nbl_list->nbl;
276
277     if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
278     {
279         coulkt = coulktRF;
280     }
281     else
282     {
283         if (ewald_excl == ewaldexclTable)
284         {
285             if (ic->rcoulomb == ic->rvdw)
286             {
287                 coulkt = coulktTAB;
288             }
289             else
290             {
291                 coulkt = coulktTAB_TWIN;
292             }
293         }
294         else
295         {
296             if (ic->rcoulomb == ic->rvdw)
297             {
298                 coulkt = coulktEWALD;
299             }
300             else
301             {
302                 coulkt = coulktEWALD_TWIN;
303             }
304         }
305     }
306
307     if (ic->vdwtype == evdwCUT)
308     {
309         switch (ic->vdw_modifier)
310         {
311             case eintmodNONE:
312             case eintmodPOTSHIFT:
313                 switch (nbat->comb_rule)
314                 {
315                     case ljcrGEOM: vdwkt = vdwktLJCUT_COMBGEOM; break;
316                     case ljcrLB:   vdwkt = vdwktLJCUT_COMBLB;   break;
317                     case ljcrNONE: vdwkt = vdwktLJCUT_COMBNONE; break;
318                     default:       gmx_incons("Unknown combination rule");
319                 }
320                 break;
321             case eintmodFORCESWITCH:
322                 vdwkt = vdwktLJFORCESWITCH;
323                 break;
324             case eintmodPOTSWITCH:
325                 vdwkt = vdwktLJPOTSWITCH;
326                 break;
327             default:
328                 gmx_incons("Unsupported VdW interaction modifier");
329         }
330     }
331     else if (ic->vdwtype == evdwPME)
332     {
333         if (ic->ljpme_comb_rule == eljpmeLB)
334         {
335             gmx_incons("The nbnxn SIMD kernels don't suport LJ-PME with LB");
336         }
337         vdwkt = vdwktLJEWALDCOMBGEOM;
338     }
339     else
340     {
341         gmx_incons("Unsupported VdW interaction type");
342     }
343
344 #pragma omp parallel for schedule(static) num_threads(gmx_omp_nthreads_get(emntNonbonded))
345     for (nb = 0; nb < nnbl; nb++)
346     {
347         nbnxn_atomdata_output_t *out;
348         real                    *fshift_p;
349
350         out = &nbat->out[nb];
351
352         if (clearF == enbvClearFYes)
353         {
354             clear_f(nbat, nb, out->f);
355         }
356
357         if ((force_flags & GMX_FORCE_VIRIAL) && nnbl == 1)
358         {
359             fshift_p = fshift;
360         }
361         else
362         {
363             fshift_p = out->fshift;
364
365             if (clearF == enbvClearFYes)
366             {
367                 clear_fshift(fshift_p);
368             }
369         }
370
371         if (!(force_flags & GMX_FORCE_ENERGY))
372         {
373             /* Don't calculate energies */
374             p_nbk_noener[coulkt][vdwkt](nbl[nb], nbat,
375                                         ic,
376                                         shift_vec,
377                                         out->f,
378                                         fshift_p);
379         }
380         else if (out->nV == 1)
381         {
382             /* No energy groups */
383             out->Vvdw[0] = 0;
384             out->Vc[0]   = 0;
385
386             p_nbk_ener[coulkt][vdwkt](nbl[nb], nbat,
387                                       ic,
388                                       shift_vec,
389                                       out->f,
390                                       fshift_p,
391                                       out->Vvdw,
392                                       out->Vc);
393         }
394         else
395         {
396             /* Calculate energy group contributions */
397             int i;
398
399             for (i = 0; i < out->nVS; i++)
400             {
401                 out->VSvdw[i] = 0;
402             }
403             for (i = 0; i < out->nVS; i++)
404             {
405                 out->VSc[i] = 0;
406             }
407
408             p_nbk_energrp[coulkt][vdwkt](nbl[nb], nbat,
409                                          ic,
410                                          shift_vec,
411                                          out->f,
412                                          fshift_p,
413                                          out->VSvdw,
414                                          out->VSc);
415
416             reduce_group_energies(nbat->nenergrp, nbat->neg_2log,
417                                   out->VSvdw, out->VSc,
418                                   out->Vvdw, out->Vc);
419         }
420     }
421
422     if (force_flags & GMX_FORCE_ENERGY)
423     {
424         reduce_energies_over_lists(nbat, nnbl, Vvdw, Vc);
425     }
426 }
427 #else
428 {
429     gmx_incons("nbnxn_kernel_simd_4xn called when such kernels "
430                " are not enabled.");
431 }
432 #endif
433 #undef GMX_SIMD_J_UNROLL_SIZE