Properly finalize MPI on mdrun -version. Fixes #1313
[gromacs.git] / include / gmx_simd_vec.h
blob95dc0d611490cbd5999465d2ac4117d2fed471ab
1 /*
2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
38 /* The macros in this file are intended to be used for writing
39 * architecture-independent SIMD intrinsics code.
40 * To support a new architecture, adding macros here should be (nearly)
41 * all that is needed.
44 /* This file contains vector operation functions using SIMD intrinsics.
45 * gmx_simd_macros.h should be included before including this file.
48 #ifndef _gmx_simd_vec_h_
49 #define _gmx_simd_vec_h_
51 #ifndef _gmx_simd_macros_h_
52 #error "gmx_simd_macros.h was not included before including gmx_simd_vec.h"
53 #endif
56 /* x^2 + y^2 + z^2 */
57 static gmx_inline gmx_mm_pr
58 gmx_calc_rsq_pr(gmx_mm_pr x, gmx_mm_pr y, gmx_mm_pr z)
60 return gmx_madd_pr(z, z, gmx_madd_pr(y, y, gmx_mul_pr(x, x)));
63 /* inner-product of multiple vectors */
64 static gmx_inline gmx_mm_pr
65 gmx_iprod_pr(gmx_mm_pr ax, gmx_mm_pr ay, gmx_mm_pr az,
66 gmx_mm_pr bx, gmx_mm_pr by, gmx_mm_pr bz)
68 gmx_mm_pr ret;
70 ret = gmx_mul_pr(ax, bx);
71 ret = gmx_madd_pr(ay, by, ret);
72 ret = gmx_madd_pr(az, bz, ret);
74 return ret;
77 /* norm squared of multiple vectors */
78 static gmx_inline gmx_mm_pr
79 gmx_norm2_pr(gmx_mm_pr ax, gmx_mm_pr ay, gmx_mm_pr az)
81 gmx_mm_pr ret;
83 ret = gmx_mul_pr(ax, ax);
84 ret = gmx_madd_pr(ay, ay, ret);
85 ret = gmx_madd_pr(az, az, ret);
87 return ret;
90 /* cross-product of multiple vectors */
91 static gmx_inline void
92 gmx_cprod_pr(gmx_mm_pr ax, gmx_mm_pr ay, gmx_mm_pr az,
93 gmx_mm_pr bx, gmx_mm_pr by, gmx_mm_pr bz,
94 gmx_mm_pr *cx, gmx_mm_pr *cy, gmx_mm_pr *cz)
96 *cx = gmx_mul_pr(ay, bz);
97 *cx = gmx_nmsub_pr(az, by, *cx);
99 *cy = gmx_mul_pr(az, bx);
100 *cy = gmx_nmsub_pr(ax, bz, *cy);
102 *cz = gmx_mul_pr(ax, by);
103 *cz = gmx_nmsub_pr(ay, bx, *cz);
106 /* a + b + c + d (not really a vector operation, but where else put this?) */
107 static gmx_inline gmx_mm_pr
108 gmx_sum4_pr(gmx_mm_pr a, gmx_mm_pr b, gmx_mm_pr c, gmx_mm_pr d)
110 return gmx_add_pr(gmx_add_pr(a, b), gmx_add_pr(c, d));
114 #endif /* _gmx_simd_vec_h_ */