2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
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.
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.
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.
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.
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.
36 #ifndef GMX_SIMD_FOUR_WIDE_MACROS_REF_H
37 #define GMX_SIMD_FOUR_WIDE_MACROS_REF_H
39 /* This file contains a reference plain-C implementation of 4-wide SIMD.
40 * This code is only useful for testing and documentation.
41 * Either float or double precision is supported through gmx_simd4_real,
42 * which is set in gmx_simd4_macros.h
48 /* float/double SIMD register type */
50 gmx_simd4_real r[GMX_SIMD4_WIDTH];
53 /* boolean SIMD register type */
55 char r[GMX_SIMD4_WIDTH];
59 /* Load GMX_SIMD4_WIDTH reals for memory starting at r */
60 static gmx_inline gmx_simd4_ref_pr
61 gmx_simd4_ref_load_pr(const gmx_simd4_real *r)
66 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
74 /* Set all SIMD register elements to r */
75 static gmx_inline gmx_simd4_ref_pr
76 gmx_simd4_ref_set1_pr(gmx_simd4_real r)
81 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
89 /* Set all SIMD register elements to 0 */
90 static gmx_inline gmx_simd4_ref_pr
91 gmx_simd4_ref_setzero_pr()
96 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
104 static gmx_inline void
105 gmx_simd4_ref_store_pr(gmx_simd4_real *dest, gmx_simd4_ref_pr src)
109 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
115 static gmx_inline gmx_simd4_ref_pr
116 gmx_simd4_ref_add_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
121 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
123 c.r[i] = a.r[i] + b.r[i];
129 static gmx_inline gmx_simd4_ref_pr
130 gmx_simd4_ref_sub_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
135 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
137 c.r[i] = a.r[i] - b.r[i];
143 static gmx_inline gmx_simd4_ref_pr
144 gmx_simd4_ref_mul_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
149 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
151 c.r[i] = a.r[i]*b.r[i];
157 static gmx_inline gmx_simd4_ref_pr
158 gmx_simd4_ref_madd_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b, gmx_simd4_ref_pr c)
163 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
165 d.r[i] = a.r[i]*b.r[i] + c.r[i];
171 static gmx_inline gmx_simd4_ref_pr
172 gmx_simd4_ref_nmsub_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b, gmx_simd4_ref_pr c)
177 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
179 d.r[i] = -a.r[i]*b.r[i] + c.r[i];
185 static gmx_inline gmx_simd4_real
186 gmx_simd4_ref_dotproduct3(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
192 for (i = 0; i < 3; i++)
200 static gmx_inline gmx_simd4_ref_pr
201 gmx_simd4_ref_min_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
206 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
208 c.r[i] = (a.r[i] <= b.r[i] ? a.r[i] : b.r[i]);
214 static gmx_inline gmx_simd4_ref_pr
215 gmx_simd4_ref_max_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
220 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
222 c.r[i] = (a.r[i] >= b.r[i] ? a.r[i] : b.r[i]);
228 static gmx_inline gmx_simd4_ref_pr
229 gmx_simd4_ref_blendzero_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pb b)
234 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
236 c.r[i] = (b.r[i] ? a.r[i] : 0.0);
243 static gmx_inline gmx_simd4_ref_pb
244 gmx_simd4_ref_cmplt_pr(gmx_simd4_ref_pr a, gmx_simd4_ref_pr b)
249 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
251 c.r[i] = (a.r[i] < b.r[i]);
257 /* Logical AND on SIMD booleans */
258 static gmx_inline gmx_simd4_ref_pb
259 gmx_simd4_ref_and_pb(gmx_simd4_ref_pb a, gmx_simd4_ref_pb b)
264 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
266 c.r[i] = (a.r[i] && b.r[i]);
272 /* Logical OR on SIMD booleans */
273 static gmx_inline gmx_simd4_ref_pb
274 gmx_simd4_ref_or_pb(gmx_simd4_ref_pb a, gmx_simd4_ref_pb b)
279 for (i = 0; i < GMX_SIMD4_WIDTH; i++)
281 c.r[i] = (a.r[i] || b.r[i]);
287 /* gmx_simd_anytrue_b(x) returns if any of the boolean is x is True */
288 static gmx_inline int
289 gmx_simd4_ref_anytrue_pb(gmx_simd4_ref_pb a)
295 for (i = 0; i < GMX_SIMD4_WIDTH; i++)