2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015,2016, 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.
39 #include <gtest/gtest.h>
41 #include "gromacs/simd/simd.h"
42 #include "gromacs/utility/basedefinitions.h"
53 /*! \addtogroup module_simd */
56 TEST(SimdScalarUtilTest
, gatherLoadTranspose
)
58 real data
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
59 std::int32_t offset
= 1;
62 gatherLoadTranspose
<4>(data
, &offset
, &v0
, &v1
, &v2
, &v3
);
64 EXPECT_EQ(data
[4], v0
);
65 EXPECT_EQ(data
[5], v1
);
66 EXPECT_EQ(data
[6], v2
);
67 EXPECT_EQ(data
[7], v3
);
69 gatherLoadTranspose
<2>(data
, &offset
, &v0
, &v1
);
71 EXPECT_EQ(data
[2], v0
);
72 EXPECT_EQ(data
[3], v1
);
75 TEST(SimdScalarUtilTest
, gatherLoadUTranspose
)
77 real data
[6] = {1, 2, 3, 4, 5, 6};
78 std::int32_t offset
= 1;
81 gatherLoadUTranspose
<3>(data
, &offset
, &v0
, &v1
, &v2
);
83 EXPECT_EQ(data
[3], v0
);
84 EXPECT_EQ(data
[4], v1
);
85 EXPECT_EQ(data
[5], v2
);
88 TEST(SimdScalarUtilTest
, transposeScatterStoreU
)
90 real data
[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
91 std::int32_t offset
= 1;
96 transposeScatterStoreU
<3>(data
, &offset
, v0
, v1
, v2
);
98 EXPECT_EQ(real(0.0), data
[0]);
99 EXPECT_EQ(real(0.0), data
[1]);
100 EXPECT_EQ(real(0.0), data
[2]);
101 EXPECT_EQ(v0
, data
[3]);
102 EXPECT_EQ(v1
, data
[4]);
103 EXPECT_EQ(v2
, data
[5]);
104 EXPECT_EQ(real(0.0), data
[6]);
105 EXPECT_EQ(real(0.0), data
[7]);
106 EXPECT_EQ(real(0.0), data
[8]);
109 TEST(SimdScalarUtilTest
, transposeScatterIncrU
)
111 real data
[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
112 std::int32_t offset
= 1;
117 transposeScatterIncrU
<3>(data
, &offset
, v0
, v1
, v2
);
119 EXPECT_EQ(real(10), data
[0]);
120 EXPECT_EQ(real(20), data
[1]);
121 EXPECT_EQ(real(30), data
[2]);
122 EXPECT_EQ(real(41), data
[3]);
123 EXPECT_EQ(real(52), data
[4]);
124 EXPECT_EQ(real(63), data
[5]);
125 EXPECT_EQ(real(70), data
[6]);
126 EXPECT_EQ(real(80), data
[7]);
127 EXPECT_EQ(real(90), data
[8]);
130 TEST(SimdScalarUtilTest
, transposeScatterDecrU
)
132 real data
[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
133 std::int32_t offset
= 1;
138 transposeScatterDecrU
<3>(data
, &offset
, v0
, v1
, v2
);
140 EXPECT_EQ(real(10), data
[0]);
141 EXPECT_EQ(real(20), data
[1]);
142 EXPECT_EQ(real(30), data
[2]);
143 EXPECT_EQ(real(39), data
[3]);
144 EXPECT_EQ(real(48), data
[4]);
145 EXPECT_EQ(real(57), data
[5]);
146 EXPECT_EQ(real(70), data
[6]);
147 EXPECT_EQ(real(80), data
[7]);
148 EXPECT_EQ(real(90), data
[8]);
152 TEST(SimdScalarTest
, expandScalarsToTriplets
)
157 expandScalarsToTriplets(scalar
, &t0
, &t1
, &t2
);
159 EXPECT_EQ(scalar
, t0
);
160 EXPECT_EQ(scalar
, t1
);
161 EXPECT_EQ(scalar
, t2
);
164 TEST(SimdScalarUtilTest
, gatherLoadBySimdIntTranspose
)
166 real data
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
167 std::int32_t offset
= 1;
170 gatherLoadBySimdIntTranspose
<4>(data
, offset
, &v0
, &v1
, &v2
, &v3
);
172 EXPECT_EQ(data
[4], v0
);
173 EXPECT_EQ(data
[5], v1
);
174 EXPECT_EQ(data
[6], v2
);
175 EXPECT_EQ(data
[7], v3
);
177 gatherLoadBySimdIntTranspose
<2>(data
, offset
, &v0
, &v1
);
179 EXPECT_EQ(data
[2], v0
);
180 EXPECT_EQ(data
[3], v1
);
183 TEST(SimdScalarUtilTest
, gatherLoadUBySimdIntTranspose
)
185 real data
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
186 std::int32_t offset
= 1;
189 gatherLoadUBySimdIntTranspose
<4>(data
, offset
, &v0
, &v1
);
191 EXPECT_EQ(data
[4], v0
);
192 EXPECT_EQ(data
[5], v1
);
195 TEST(SimdScalarUtilTest
, reduceIncr4ReturnSum
)
197 real data
[6] = {0, 0, 0, 0, 0, 0};
204 sum
= reduceIncr4ReturnSum(data
+1, v0
, v1
, v2
, v3
);
206 EXPECT_EQ(real(0.0), data
[0]);
207 EXPECT_EQ(v0
, data
[1]);
208 EXPECT_EQ(v1
, data
[2]);
209 EXPECT_EQ(v2
, data
[3]);
210 EXPECT_EQ(v3
, data
[4]);
211 EXPECT_EQ(real(0.0), data
[5]);
213 EXPECT_EQ(real(v0
+v1
+v2
+v3
), sum
);
217 /*! \endcond internal */
219 } // namespace anonymous