implemented plain-C SIMD macros for reference
[alexxy/gromacs.git] / src / mdlib / nbnxn_kernels / nbnxn_kernel_simd_utils.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2012, The GROMACS Development Team
6  * Copyright (c) 2012,2013, by the GROMACS development team, led by
7  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
8  * others, as listed in the AUTHORS file in the top-level source
9  * directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #ifndef _nbnxn_kernel_sse_utils_h_
38 #define _nbnxn_kernel_sse_utils_h_
39
40 /* This files contains all functions/macros for the SIMD kernels
41  * which have explicit dependencies on the j-cluster size and/or SIMD-width.
42  * The functionality which depends on the j-cluster size is:
43  *   LJ-parameter lookup
44  *   force table lookup
45  *   energy group pair energy storage
46  */
47
48
49 /* Include SIMD architecture specific versions of the 4/5 functions above */
50 #ifdef GMX_SIMD_REFERENCE_PLAIN_C
51 #include "nbnxn_kernel_simd_utils_ref.h"
52 #else
53 #ifdef GMX_X86_SSE2
54 /* Include x86 SSE2 compatible SIMD functions */
55 #if defined GMX_X86_AVX_256 && !defined GMX_USE_HALF_WIDTH_SIMD_HERE
56 #ifdef GMX_DOUBLE
57 #include "nbnxn_kernel_simd_utils_x86_256d.h"
58 #else
59 #include "nbnxn_kernel_simd_utils_x86_256s.h"
60 #endif
61 #else
62 #ifdef GMX_DOUBLE
63 #include "nbnxn_kernel_simd_utils_x86_128d.h"
64 #else
65 #include "nbnxn_kernel_simd_utils_x86_128s.h"
66 #endif
67 #endif
68 #endif
69 #endif
70
71
72 #ifdef UNROLLJ
73 /* Add energy register to possibly multiple terms in the energy array */
74 static inline void add_ener_grp(gmx_mm_pr e_S, real *v, const int *offset_jj)
75 {
76     int jj;
77
78     /* We need to balance the number of store operations with
79      * the rapidly increases number of combinations of energy groups.
80      * We add to a temporary buffer for 1 i-group vs 2 j-groups.
81      */
82     for (jj = 0; jj < (UNROLLJ/2); jj++)
83     {
84         gmx_mm_pr v_S;
85
86         v_S = gmx_load_pr(v+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE);
87         gmx_store_pr(v+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE, gmx_add_pr(v_S, e_S));
88     }
89 }
90 #endif
91
92 #if defined GMX_NBNXN_SIMD_2XNN && defined UNROLLJ
93 /* As add_ener_grp, but for two groups of UNROLLJ/2 stored in
94  * a single SIMD register.
95  */
96 static inline void
97 add_ener_grp_halves(gmx_mm_pr e_S, real *v0, real *v1, const int *offset_jj)
98 {
99     gmx_mm_hpr e_S0, e_S1;
100     int        jj;
101
102     gmx_pr_to_2hpr(e_S, &e_S0, &e_S1);
103
104     for (jj = 0; jj < (UNROLLJ/2); jj++)
105     {
106         gmx_mm_hpr v_S;
107
108         gmx_load_hpr(&v_S, v0+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE/2);
109         gmx_store_hpr(v0+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE/2, gmx_add_hpr(v_S, e_S0));
110     }
111     for (jj = 0; jj < (UNROLLJ/2); jj++)
112     {
113         gmx_mm_hpr v_S;
114
115         gmx_load_hpr(&v_S, v1+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE/2);
116         gmx_store_hpr(v1+offset_jj[jj]+jj*GMX_SIMD_WIDTH_HERE/2, gmx_add_hpr(v_S, e_S1));
117     }
118 }
119 #endif
120
121 #endif /* _nbnxn_kernel_sse_utils_h_ */