gem5 v23.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
amo.test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 The Regents of the University of California
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <gtest/gtest.h>
32
33#include <string>
34#include <array>
35
36#include "base/amo.hh"
37
38using namespace gem5;
39
40void
41multiply2Op(int *b, int a)
42{
43 *b *= a;
44}
45
46void
47multiply3Op(int *b, int a, int c)
48{
49 *b *= a * c;
50}
51
52void
53addSubColumns(int *b, const std::array<int, 2>& a, const std::array<int, 2>& c)
54{
55 *b += a[0] + c[0];
56 *b -= a[1] + c[1];
57}
58
60{
61 // test with ints and strings
62 int test_int_smaller = 5;
63 int test_int_bigger = 15;
64 std::string test_string_smaller = "apple";
65 std::string test_string_bigger = "cat";
66
67 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpMin<int>(10);
69 new AtomicOpMin<std::string>("base");
70 amo_op_int->execute(&test_int_smaller);
71 amo_op_int->execute(&test_int_bigger);
72 amo_op_string->execute(&test_string_smaller);
73 amo_op_string->execute(&test_string_bigger);
74
75 EXPECT_EQ(test_int_smaller, 5);
76 EXPECT_EQ(test_int_bigger, 10);
77 EXPECT_EQ(test_string_smaller, "apple");
78 EXPECT_EQ(test_string_bigger, "base");
79}
80
82{
83 int test_int_smaller = 5;
84 int test_int_bigger = 15;
85 std::string test_string_smaller = "apple";
86 std::string test_string_bigger = "cat";
87
88 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpMax<int>(10);
90 new AtomicOpMax<std::string>("base");
91 amo_op_int->execute(&test_int_smaller);
92 amo_op_int->execute(&test_int_bigger);
93 amo_op_string->execute(&test_string_smaller);
94 amo_op_string->execute(&test_string_bigger);
95
96 EXPECT_EQ(test_int_smaller, 10);
97 EXPECT_EQ(test_int_bigger, 15);
98 EXPECT_EQ(test_string_smaller, "base");
99 EXPECT_EQ(test_string_bigger, "cat");
100}
101
103{
104 int test_int = 10;
105 char test_char = 'c';
106
109 amo_op_int->execute(&test_int);
110 amo_op_char->execute(&test_char);
111
112 EXPECT_EQ(test_int, 9);
113 EXPECT_EQ(test_char, 'b');
114}
115
117{
118 int test_int = 10;
119 char test_char = 'c';
120
123 amo_op_int->execute(&test_int);
124 amo_op_char->execute(&test_char);
125
126 EXPECT_EQ(test_int, 11);
127 EXPECT_EQ(test_char, 'd');
128}
129
131{
132 int test_int = 10;
133 char test_char = 'c';
134
135 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpSub<int>(2);
136 TypedAtomicOpFunctor<char> *amo_op_char = new AtomicOpSub<char>('a');
137 amo_op_int->execute(&test_int);
138 amo_op_char->execute(&test_char);
139
140 EXPECT_EQ(test_int, 8);
141 EXPECT_EQ(test_char, 2);
142}
143
145{
146 int test_int = 10;
147 char test_char = 'c';
148
149 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpAdd<int>(2);
150 TypedAtomicOpFunctor<char> *amo_op_char = new AtomicOpAdd<char>(2);
151 amo_op_int->execute(&test_int);
152 amo_op_char->execute(&test_char);
153
154 EXPECT_EQ(test_int, 12);
155 EXPECT_EQ(test_char, 'e');
156}
157
159{
160 int test_int = 10;
161 char test_char = 'c';
162
163 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpExch<int>(2);
164 TypedAtomicOpFunctor<char> *amo_op_char = new AtomicOpExch<char>('a');
165 amo_op_int->execute(&test_int);
166 amo_op_char->execute(&test_char);
167
168 EXPECT_EQ(test_int, 2);
169 EXPECT_EQ(test_char, 'a');
170}
171
173{
174 int test_int = 10;
175 char test_char = 'c';
176
177 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpXor<int>(2);
178 TypedAtomicOpFunctor<char> *amo_op_char = new AtomicOpXor<char>('a');
179 amo_op_int->execute(&test_int);
180 amo_op_char->execute(&test_char);
181
182 EXPECT_EQ(test_int, 8); // 1010 ^ 0010 = 1000
183 EXPECT_EQ(test_char, 2); // 99 ^ 97 = 2
184}
185
187{
188 int test_int = 8;
189 bool test_bool = true;
190
191 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpOr<int>(2);
192 TypedAtomicOpFunctor<bool> *amo_op_bool = new AtomicOpOr<bool>(false);
193 amo_op_int->execute(&test_int);
194 amo_op_bool->execute(&test_bool);
195
196 EXPECT_EQ(test_int, 10);
197 EXPECT_EQ(test_bool, true);
198}
199
201{
202 int test_int = 10;
203 char test_char = 'c';
204
205 TypedAtomicOpFunctor<int> *amo_op_int = new AtomicOpAnd<int>(6);
206 TypedAtomicOpFunctor<char> *amo_op_char = new AtomicOpAnd<char>('a');
207 amo_op_int->execute(&test_int);
208 amo_op_char->execute(&test_char);
209
210 EXPECT_EQ(test_int, 2);
211 EXPECT_EQ(test_char, 'a');
212}
213
215{
216 int test_int = 9;
217
218 TypedAtomicOpFunctor<int> *amo_op_int =
220 amo_op_int->execute(&test_int);
221
222 EXPECT_EQ(test_int, 81);
223}
224
226{
227 int test_int = 2;
228
229 TypedAtomicOpFunctor<int> *amo_op_int =
231 amo_op_int->execute(&test_int);
232
233 EXPECT_EQ(test_int, 24);
234}
235
237{
238 int test_int = 5;
239
240 std::array<int, 2> a = {6, 3};
241 std::array<int, 2> c = {10, 8};
242 TypedAtomicOpFunctor<int> *amo_op_int =
244 amo_op_int->execute(&test_int);
245
246 EXPECT_EQ(test_int, 10);
247}
void multiply2Op(int *b, int a)
Definition amo.test.cc:41
void multiply3Op(int *b, int a, int c)
Definition amo.test.cc:47
void addSubColumns(int *b, const std::array< int, 2 > &a, const std::array< int, 2 > &c)
Definition amo.test.cc:53
TEST(AmoTest, AtomicOpMin)
Definition amo.test.cc:59
virtual void execute(T *p)=0
Bitfield< 7 > b
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 8 > a
Definition misc_types.hh:66
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Mon Jul 10 2023 14:24:28 for gem5 by doxygen 1.9.7