Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / simd / tests / simd4.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 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 #include "gmxpre.h"
36
37 #include "simd4.h"
38
39 namespace gmx
40 {
41 namespace test
42 {
43
44 /*! \cond internal */
45 /*! \addtogroup module_simd */
46 /*! \{ */
47
48 #ifdef GMX_SIMD4_HAVE_REAL
49
50 const gmx_simd4_real_t rSimd4_1_2_3    = setSimd4RealFrom3R(1, 2, 3);
51 const gmx_simd4_real_t rSimd4_4_5_6    = setSimd4RealFrom3R(4, 5, 6);
52 const gmx_simd4_real_t rSimd4_7_8_9    = setSimd4RealFrom3R(7, 8, 9);
53 const gmx_simd4_real_t rSimd4_5_7_9    = setSimd4RealFrom3R(5, 7, 9);
54 const gmx_simd4_real_t rSimd4_m1_m2_m3 = setSimd4RealFrom3R(-1, -2, -3);
55 const gmx_simd4_real_t rSimd4_3_1_4    = setSimd4RealFrom3R(3, 1, 4);
56 const gmx_simd4_real_t rSimd4_m3_m1_m4 = setSimd4RealFrom3R(-3, -1, -4);
57 const gmx_simd4_real_t rSimd4_2p25     = setSimd4RealFrom1R(2.25);
58 const gmx_simd4_real_t rSimd4_3p75     = setSimd4RealFrom1R(3.75);
59 const gmx_simd4_real_t rSimd4_m2p25    = setSimd4RealFrom1R(-2.25);
60 const gmx_simd4_real_t rSimd4_m3p75    = setSimd4RealFrom1R(-3.75);
61 const gmx_simd4_real_t rSimd4_Exp      = setSimd4RealFrom3R( 1.4055235171027452623914516e+18,
62                                                              5.3057102734253445623914516e-13,
63                                                              -2.1057102745623934534514516e+16);
64 #    if (defined GMX_SIMD_HAVE_DOUBLE) && (defined GMX_DOUBLE)
65 // Make sure we also test exponents outside single precision when we use double
66 const gmx_simd4_real_t  rSimd_ExpDouble = setSimd4RealFrom3R( 6.287393598732017379054414e+176,
67                                                               8.794495252903116023030553e-140,
68                                                               -3.637060701570496477655022e+202);
69 #    endif
70
71 ::std::vector<real>
72 simd4Real2Vector(const gmx_simd4_real_t simd4)
73 {
74     real                mem[GMX_SIMD4_WIDTH*2];
75     real *              p = gmx_simd4_align_r(mem);
76
77     gmx_simd4_store_r(p, simd4);
78     std::vector<real>   v(p, p+GMX_SIMD4_WIDTH);
79
80     return v;
81 }
82
83 gmx_simd4_real_t
84 vector2Simd4Real(const std::vector<real> &v)
85 {
86     real                mem[GMX_SIMD4_WIDTH*2];
87     real *              p = gmx_simd4_align_r(mem);
88
89     for (int i = 0; i < GMX_SIMD4_WIDTH; i++)
90     {
91         p[i] = v[i % v.size()];  // repeat vector contents to fill simd width
92     }
93     return gmx_simd4_load_r(p);
94 }
95
96 gmx_simd4_real_t
97 setSimd4RealFrom3R(real r0, real r1, real r2)
98 {
99     std::vector<real> v(3);
100     v[0] = r0;
101     v[1] = r1;
102     v[2] = r2;
103     return vector2Simd4Real(v);
104 }
105
106 gmx_simd4_real_t
107 setSimd4RealFrom1R(real value)
108 {
109     std::vector<real> v(GMX_SIMD4_WIDTH);
110     for (int i = 0; i < GMX_SIMD4_WIDTH; i++)
111     {
112         v[i] = value;
113     }
114     return vector2Simd4Real(v);
115 }
116
117 testing::AssertionResult
118 Simd4Test::compareSimd4RealUlp(const char *  refExpr,     const char *  tstExpr,
119                                const gmx_simd4_real_t ref, const gmx_simd4_real_t tst)
120 {
121     return compareVectorRealUlp(refExpr, tstExpr, simd4Real2Vector(ref), simd4Real2Vector(tst));
122 }
123
124 testing::AssertionResult
125 Simd4Test::compareSimd4RealEq(const char * refExpr, const char * tstExpr,
126                               const gmx_simd4_real_t ref, const gmx_simd4_real_t tst)
127 {
128     return compareVectorEq(refExpr, tstExpr, simd4Real2Vector(ref), simd4Real2Vector(tst));
129 }
130
131 #endif  // GMX_SIMD4_HAVE_REAL
132
133 /*! \} */
134 /*! \endcond */
135
136 }      // namespace
137 }      // namespace