gem5 v24.0.0.0
Loading...
Searching...
No Matches
vec_reg.test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <gtest/gtest.h>
39
41
42using namespace gem5;
43
44TEST(VecReg, Size)
45{
46 {
47 // Minimum size
49 ASSERT_EQ(1, vec.size());
50 }
51
52 {
53 // Medium size
54 constexpr size_t size = MaxVecRegLenInBytes / 2;
56 ASSERT_EQ(size, vec.size());
57 }
58
59 {
60 // Maximum size
62 ASSERT_EQ(MaxVecRegLenInBytes, vec.size());
63 }
64}
65
66TEST(VecReg, Zero)
67{
68 constexpr size_t size = 16;
70 auto *vec_ptr = vec.as<uint8_t>();
71
72 // Initializing with non-zero value
73 for (auto idx = 0; idx < size; idx++) {
74 vec_ptr[idx] = 0xAA;
75 }
76
77 // zeroing the vector
78 vec.zero();
79
80 // checking if every vector element is set to zero
81 for (auto idx = 0; idx < size; idx++) {
82 ASSERT_EQ(vec_ptr[idx], 0);
83 }
84}
85
86class TwoDifferentVecRegs : public testing::Test
87{
88 protected:
91 uint8_t *vec1_ptr;
92 uint8_t *vec2_ptr;
93
94 void
95 SetUp() override
96 {
97 vec1_ptr = vec1.as<uint8_t>();
98 vec2_ptr = vec2.as<uint8_t>();
99
100 // Initializing with non-zero value vector1
101 for (auto idx = 0; idx < vec1.size(); idx++) {
102 vec1_ptr[idx] = 0xAA;
103 }
104
105 // Initializing with zero value vector2
106 for (auto idx = 0; idx < vec2.size(); idx++) {
107 vec2_ptr[idx] = 0;
108 }
109 }
110};
111
112// Testing operator=
114{
115 // Copying the vector
116 vec2 = vec1;
117
118 // Checking if vector2 elements are 0xAA
119 for (auto idx = 0; idx < vec2.size(); idx++) {
120 ASSERT_EQ(vec2_ptr[idx], 0xAA);
121 }
122}
123
124// Testing operator==
126{
127 // Equality check
128 ASSERT_TRUE(vec1 == vec1);
129 ASSERT_TRUE(vec2 == vec2);
130 ASSERT_FALSE(vec1 == vec2);
131}
132
133// Testing operator!=
135{
136 // Inequality check
137 ASSERT_FALSE(vec1 != vec1);
138 ASSERT_FALSE(vec2 != vec2);
139 ASSERT_TRUE(vec1 != vec2);
140}
141
142// Testing operator<<
144{
145 {
146 std::ostringstream stream;
147 stream << vec1;
148 ASSERT_EQ(stream.str(), "[aaaaaaaa_aaaaaaaa_aaaaaaaa_aaaaaaaa]");
149 }
150
151 {
152 std::ostringstream stream;
153 stream << vec2;
154 ASSERT_EQ(stream.str(), "[00000000_00000000_00000000_00000000]");
155 }
156}
157
158// Testing ParseParam
160{
161 ParseParam<decltype(vec1)> parser;
162
163 parser.parse("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", vec1);
164 parser.parse("cccccccccccccccccccccccccccccccc", vec2);
165
166 for (auto idx = 0; idx < 2; idx++) {
167 ASSERT_EQ(vec1_ptr[idx], 0xbb);
168 ASSERT_EQ(vec2_ptr[idx], 0xcc);
169 }
170}
171
172// Testing ShowParam
174{
175 ShowParam<decltype(vec1)> parser;
176
177 {
178 std::stringstream ss;
179 parser.show(ss, vec1);
180 ASSERT_EQ(ss.str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
181 }
182
183 {
184 std::stringstream ss;
185 parser.show(ss, vec2);
186 ASSERT_EQ(ss.str(), "00000000000000000000000000000000");
187 }
188}
VecRegContainer< 16 > vec1
VecRegContainer< 16 > vec2
void SetUp() override
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
Definition vec_reg.hh:126
static constexpr size_t size()
Definition vec_reg.hh:133
VecElem * as()
View interposers.
Definition vec_reg.hh:191
Bitfield< 21 > ss
Definition misc_types.hh:60
Bitfield< 25 > vec
Definition misc.hh:113
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
constexpr unsigned MaxVecRegLenInBytes
Definition vec_reg.hh:115
static void show(std::ostream &os, const T &value)
Vector Registers layout specification.
TEST(VecReg, Size)
TEST_F(TwoDifferentVecRegs, Assignment)

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0