Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / simd / tests / simd4.cpp
blobfa98e148280cfa1041a122f1065cbbda829a0812
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015,2017,2018, 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.
35 #include "gmxpre.h"
37 #include "simd4.h"
39 #include "gromacs/simd/simd.h"
40 #include "gromacs/utility/basedefinitions.h"
42 #include "data.h"
44 #if GMX_SIMD
46 namespace gmx
48 namespace test
51 /*! \cond internal */
52 /*! \addtogroup module_simd */
53 /*! \{ */
55 #if GMX_SIMD4_HAVE_REAL
57 const Simd4Real rSimd4_c0c1c2 = setSimd4RealFrom3R( c0, c1, c2);
58 const Simd4Real rSimd4_c3c4c5 = setSimd4RealFrom3R( c3, c4, c5);
59 const Simd4Real rSimd4_c6c7c8 = setSimd4RealFrom3R( c6, c7, c8);
60 const Simd4Real rSimd4_c3c0c4 = setSimd4RealFrom3R( c3, c0, c4);
61 const Simd4Real rSimd4_c4c6c8 = setSimd4RealFrom3R( c4, c6, c8);
62 const Simd4Real rSimd4_c7c2c3 = setSimd4RealFrom3R( c7, c2, c3);
63 const Simd4Real rSimd4_m0m1m2 = setSimd4RealFrom3R(-c0, -c1, -c2);
64 const Simd4Real rSimd4_m3m0m4 = setSimd4RealFrom3R(-c3, -c0, -c4);
65 const Simd4Real rSimd4_2p25 = setSimd4RealFrom1R(2.25);
66 const Simd4Real rSimd4_3p75 = setSimd4RealFrom1R(3.75);
67 const Simd4Real rSimd4_m2p25 = setSimd4RealFrom1R(-2.25);
68 const Simd4Real rSimd4_m3p75 = setSimd4RealFrom1R(-3.75);
70 #if GMX_SIMD_HAVE_LOGICAL
71 // The numbers below all have exponent (2^0), which will not change with AND/OR operations.
72 // We also leave the last part of the mantissa as zeros, to avoid rounding issues in the compiler
73 #if GMX_DOUBLE
74 const Simd4Real rSimd4_logicalA = setSimd4RealFrom1R(1.3333333332557231188); // mantissa 01010101010101010101010101010101
75 const Simd4Real rSimd4_logicalB = setSimd4RealFrom1R(1.7999999998137354851); // mantissa 11001100110011001100110011001100
76 const Simd4Real rSimd4_logicalResultAnd = setSimd4RealFrom1R(1.266666666604578495); // mantissa 01000100010001000100010001000100
77 const Simd4Real rSimd4_logicalResultOr = setSimd4RealFrom1R(1.8666666664648801088); // mantissa 11011101110111011101110111011101
78 #else // GMX_DOUBLE
79 const Simd4Real rSimd4_logicalA = setSimd4RealFrom1R(1.3333282470703125); // mantissa 0101010101010101
80 const Simd4Real rSimd4_logicalB = setSimd4RealFrom1R(1.79998779296875); // mantissa 1100110011001100
81 const Simd4Real rSimd4_logicalResultAnd = setSimd4RealFrom1R(1.26666259765625); // mantissa 0100010001000100
82 const Simd4Real rSimd4_logicalResultOr = setSimd4RealFrom1R(1.8666534423828125); // mantissa 1101110111011101
83 #endif // GMX_DOUBLE
84 #endif // GMX_SIMD_HAVE_LOGICAL
86 ::std::vector<real>
87 simd4Real2Vector(const Simd4Real simd4)
89 alignas(GMX_SIMD_ALIGNMENT) real mem[GMX_SIMD4_WIDTH];
91 store4(mem, simd4);
92 std::vector<real> v(mem, mem+GMX_SIMD4_WIDTH);
94 return v;
97 Simd4Real
98 vector2Simd4Real(const std::vector<real> &v)
100 alignas(GMX_SIMD_ALIGNMENT) real mem[GMX_SIMD4_WIDTH];
102 for (int i = 0; i < GMX_SIMD4_WIDTH; i++)
104 mem[i] = v[i % v.size()]; // repeat vector contents to fill simd width
106 return load4(mem);
109 Simd4Real
110 setSimd4RealFrom3R(real r0, real r1, real r2)
112 std::vector<real> v(3);
113 v[0] = r0;
114 v[1] = r1;
115 v[2] = r2;
116 return vector2Simd4Real(v);
119 Simd4Real
120 setSimd4RealFrom1R(real value)
122 std::vector<real> v(GMX_SIMD4_WIDTH);
123 for (int i = 0; i < GMX_SIMD4_WIDTH; i++)
125 v[i] = value;
127 return vector2Simd4Real(v);
130 testing::AssertionResult
131 Simd4Test::compareSimd4RealUlp(const char * refExpr, const char * tstExpr,
132 const Simd4Real ref, const Simd4Real tst)
134 return compareVectorRealUlp(refExpr, tstExpr, simd4Real2Vector(ref), simd4Real2Vector(tst));
137 testing::AssertionResult
138 Simd4Test::compareSimd4RealEq(const char * refExpr, const char * tstExpr,
139 const Simd4Real ref, const Simd4Real tst)
141 return compareVectorEq(refExpr, tstExpr, simd4Real2Vector(ref), simd4Real2Vector(tst));
144 #endif // GMX_SIMD4_HAVE_REAL
146 /*! \} */
147 /*! \endcond */
149 } // namespace test
150 } // namespace gmx
152 #endif // GMX_SIMD