2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015,2016,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.
39 #include <gtest/gtest.h>
41 #include "gromacs/simd/simd.h"
42 #include "gromacs/utility/basedefinitions.h"
44 #include "testutils/testasserts.h"
57 /*! \addtogroup module_simd */
60 TEST(SimdScalarUtilTest
, gatherLoadTranspose
)
62 real data
[8] = {c0
, c1
, c2
, c3
, c4
, c5
, c6
, c7
};
63 std::int32_t offset
= 1;
66 gatherLoadTranspose
<4>(data
, &offset
, &v0
, &v1
, &v2
, &v3
);
68 EXPECT_EQ(data
[4], v0
);
69 EXPECT_EQ(data
[5], v1
);
70 EXPECT_EQ(data
[6], v2
);
71 EXPECT_EQ(data
[7], v3
);
73 gatherLoadTranspose
<2>(data
, &offset
, &v0
, &v1
);
75 EXPECT_EQ(data
[2], v0
);
76 EXPECT_EQ(data
[3], v1
);
79 TEST(SimdScalarUtilTest
, gatherLoadUTranspose
)
81 real data
[6] = {c0
, c1
, c2
, c3
, c4
, c5
};
82 std::int32_t offset
= 1;
85 gatherLoadUTranspose
<3>(data
, &offset
, &v0
, &v1
, &v2
);
87 EXPECT_EQ(data
[3], v0
);
88 EXPECT_EQ(data
[4], v1
);
89 EXPECT_EQ(data
[5], v2
);
92 TEST(SimdScalarUtilTest
, transposeScatterStoreU
)
94 real data
[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
95 std::int32_t offset
= 1;
100 transposeScatterStoreU
<3>(data
, &offset
, v0
, v1
, v2
);
102 EXPECT_EQ(czero
, data
[0]);
103 EXPECT_EQ(czero
, data
[1]);
104 EXPECT_EQ(czero
, data
[2]);
105 EXPECT_EQ(v0
, data
[3]);
106 EXPECT_EQ(v1
, data
[4]);
107 EXPECT_EQ(v2
, data
[5]);
108 EXPECT_EQ(czero
, data
[6]);
109 EXPECT_EQ(czero
, data
[7]);
110 EXPECT_EQ(czero
, data
[8]);
113 TEST(SimdScalarUtilTest
, transposeScatterIncrU
)
115 real data
[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
116 std::int32_t offset
= 1;
121 transposeScatterIncrU
<3>(data
, &offset
, v0
, v1
, v2
);
123 EXPECT_EQ(real(10), data
[0]);
124 EXPECT_EQ(real(20), data
[1]);
125 EXPECT_EQ(real(30), data
[2]);
126 EXPECT_EQ(real(40+c1
), data
[3]);
127 EXPECT_EQ(real(50+c2
), data
[4]);
128 EXPECT_EQ(real(60+c3
), data
[5]);
129 EXPECT_EQ(real(70), data
[6]);
130 EXPECT_EQ(real(80), data
[7]);
131 EXPECT_EQ(real(90), data
[8]);
134 TEST(SimdScalarUtilTest
, transposeScatterDecrU
)
136 real data
[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
137 std::int32_t offset
= 1;
142 transposeScatterDecrU
<3>(data
, &offset
, v0
, v1
, v2
);
144 EXPECT_EQ(real(10), data
[0]);
145 EXPECT_EQ(real(20), data
[1]);
146 EXPECT_EQ(real(30), data
[2]);
147 EXPECT_EQ(real(40-c1
), data
[3]);
148 EXPECT_EQ(real(50-c2
), data
[4]);
149 EXPECT_EQ(real(60-c3
), data
[5]);
150 EXPECT_EQ(real(70), data
[6]);
151 EXPECT_EQ(real(80), data
[7]);
152 EXPECT_EQ(real(90), data
[8]);
156 TEST(SimdScalarTest
, expandScalarsToTriplets
)
161 expandScalarsToTriplets(scalar
, &t0
, &t1
, &t2
);
163 EXPECT_EQ(scalar
, t0
);
164 EXPECT_EQ(scalar
, t1
);
165 EXPECT_EQ(scalar
, t2
);
168 TEST(SimdScalarUtilTest
, gatherLoadBySimdIntTranspose
)
170 real data
[8] = {c0
, c1
, c2
, c3
, c4
, c5
, c6
, c7
};
171 std::int32_t offset
= 1;
174 gatherLoadBySimdIntTranspose
<4>(data
, offset
, &v0
, &v1
, &v2
, &v3
);
176 EXPECT_EQ(data
[4], v0
);
177 EXPECT_EQ(data
[5], v1
);
178 EXPECT_EQ(data
[6], v2
);
179 EXPECT_EQ(data
[7], v3
);
181 gatherLoadBySimdIntTranspose
<2>(data
, offset
, &v0
, &v1
);
183 EXPECT_EQ(data
[2], v0
);
184 EXPECT_EQ(data
[3], v1
);
187 TEST(SimdScalarUtilTest
, gatherLoadUBySimdIntTranspose
)
189 real data
[8] = {c0
, c1
, c2
, c3
, c4
, c5
, c6
, c7
};
190 std::int32_t offset
= 1;
193 gatherLoadUBySimdIntTranspose
<4>(data
, offset
, &v0
, &v1
);
195 EXPECT_EQ(data
[4], v0
);
196 EXPECT_EQ(data
[5], v1
);
199 TEST(SimdScalarUtilTest
, reduceIncr4ReturnSum
)
201 real data
[6] = {0, 0, 0, 0, 0, 0};
208 sum
= reduceIncr4ReturnSum(data
+1, v0
, v1
, v2
, v3
);
210 EXPECT_EQ(czero
, data
[0]);
211 EXPECT_EQ(v0
, data
[1]);
212 EXPECT_EQ(v1
, data
[2]);
213 EXPECT_EQ(v2
, data
[3]);
214 EXPECT_EQ(v3
, data
[4]);
215 EXPECT_EQ(czero
, data
[5]);
217 EXPECT_REAL_EQ_TOL(real(v0
+v1
+v2
+v3
), sum
, defaultRealTolerance());
221 /*! \endcond internal */