Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/opto/test_regmask.cpp
41144 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "opto/opcodes.hpp"
27
#include "opto/regmask.hpp"
28
#include "unittest.hpp"
29
30
// Sanity tests for RegMask and RegMaskIterator
31
32
static void contains_expected_num_of_registers(const RegMask& rm, unsigned int expected) {
33
34
ASSERT_TRUE(rm.Size() == expected);
35
if (expected > 0) {
36
ASSERT_TRUE(rm.is_NotEmpty());
37
} else {
38
ASSERT_TRUE(!rm.is_NotEmpty());
39
ASSERT_TRUE(!rm.is_AllStack());
40
}
41
42
RegMaskIterator rmi(rm);
43
unsigned int count = 0;
44
OptoReg::Name reg = OptoReg::Bad;
45
while (rmi.has_next()) {
46
reg = rmi.next();
47
ASSERT_TRUE(OptoReg::is_valid(reg));
48
count++;
49
}
50
ASSERT_EQ(OptoReg::Bad, rmi.next());
51
ASSERT_TRUE(count == expected);
52
}
53
54
TEST_VM(RegMask, empty) {
55
RegMask rm;
56
contains_expected_num_of_registers(rm, 0);
57
}
58
59
TEST_VM(RegMask, iteration) {
60
RegMask rm;
61
rm.Insert(30);
62
rm.Insert(31);
63
rm.Insert(32);
64
rm.Insert(33);
65
rm.Insert(62);
66
rm.Insert(63);
67
rm.Insert(64);
68
rm.Insert(65);
69
70
RegMaskIterator rmi(rm);
71
ASSERT_TRUE(rmi.next() == OptoReg::Name(30));
72
ASSERT_TRUE(rmi.next() == OptoReg::Name(31));
73
ASSERT_TRUE(rmi.next() == OptoReg::Name(32));
74
ASSERT_TRUE(rmi.next() == OptoReg::Name(33));
75
ASSERT_TRUE(rmi.next() == OptoReg::Name(62));
76
ASSERT_TRUE(rmi.next() == OptoReg::Name(63));
77
ASSERT_TRUE(rmi.next() == OptoReg::Name(64));
78
ASSERT_TRUE(rmi.next() == OptoReg::Name(65));
79
ASSERT_FALSE(rmi.has_next());
80
}
81
82
TEST_VM(RegMask, Set_ALL) {
83
// Check that Set_All doesn't add bits outside of CHUNK_SIZE
84
RegMask rm;
85
rm.Set_All();
86
ASSERT_TRUE(rm.Size() == RegMask::CHUNK_SIZE);
87
ASSERT_TRUE(rm.is_NotEmpty());
88
// Set_All sets AllStack bit
89
ASSERT_TRUE(rm.is_AllStack());
90
contains_expected_num_of_registers(rm, RegMask::CHUNK_SIZE);
91
}
92
93
TEST_VM(RegMask, Clear) {
94
// Check that Clear doesn't leave any stray bits
95
RegMask rm;
96
rm.Set_All();
97
rm.Clear();
98
contains_expected_num_of_registers(rm, 0);
99
}
100
101
TEST_VM(RegMask, AND) {
102
RegMask rm1;
103
rm1.Insert(OptoReg::Name(1));
104
contains_expected_num_of_registers(rm1, 1);
105
ASSERT_TRUE(rm1.Member(OptoReg::Name(1)));
106
107
rm1.AND(rm1);
108
contains_expected_num_of_registers(rm1, 1);
109
110
RegMask rm2;
111
rm1.AND(rm2);
112
contains_expected_num_of_registers(rm1, 0);
113
contains_expected_num_of_registers(rm2, 0);
114
}
115
116
TEST_VM(RegMask, OR) {
117
RegMask rm1;
118
rm1.Insert(OptoReg::Name(1));
119
contains_expected_num_of_registers(rm1, 1);
120
ASSERT_TRUE(rm1.Member(OptoReg::Name(1)));
121
122
rm1.OR(rm1);
123
contains_expected_num_of_registers(rm1, 1);
124
125
RegMask rm2;
126
rm1.OR(rm2);
127
contains_expected_num_of_registers(rm1, 1);
128
contains_expected_num_of_registers(rm2, 0);
129
}
130
131
TEST_VM(RegMask, SUBTRACT) {
132
RegMask rm1;
133
RegMask rm2;
134
135
rm2.Set_All();
136
for (int i = 17; i < RegMask::CHUNK_SIZE; i++) {
137
rm1.Insert(i);
138
}
139
ASSERT_TRUE(rm1.is_AllStack());
140
rm2.SUBTRACT(rm1);
141
contains_expected_num_of_registers(rm1, RegMask::CHUNK_SIZE - 17);
142
contains_expected_num_of_registers(rm2, 17);
143
}
144
145
TEST_VM(RegMask, is_bound1) {
146
RegMask rm;
147
ASSERT_FALSE(rm.is_bound1());
148
for (int i = 0; i < RegMask::CHUNK_SIZE - 1; i++) {
149
rm.Insert(i);
150
ASSERT_TRUE(rm.is_bound1()) << "Index " << i;
151
ASSERT_TRUE(rm.is_bound(Op_RegI)) << "Index " << i;
152
contains_expected_num_of_registers(rm, 1);
153
rm.Remove(i);
154
}
155
// AllStack bit does not count as a bound register
156
rm.set_AllStack();
157
ASSERT_FALSE(rm.is_bound1());
158
}
159
160
TEST_VM(RegMask, is_bound_pair) {
161
RegMask rm;
162
ASSERT_TRUE(rm.is_bound_pair());
163
for (int i = 0; i < RegMask::CHUNK_SIZE - 2; i++) {
164
rm.Insert(i);
165
rm.Insert(i + 1);
166
ASSERT_TRUE(rm.is_bound_pair()) << "Index " << i;
167
ASSERT_TRUE(rm.is_bound_set(2)) << "Index " << i;
168
ASSERT_TRUE(rm.is_bound(Op_RegI)) << "Index " << i;
169
contains_expected_num_of_registers(rm, 2);
170
rm.Clear();
171
}
172
// A pair with the AllStack bit does not count as a bound pair
173
rm.Clear();
174
rm.Insert(RegMask::CHUNK_SIZE - 2);
175
rm.Insert(RegMask::CHUNK_SIZE - 1);
176
ASSERT_FALSE(rm.is_bound_pair());
177
}
178
179
TEST_VM(RegMask, is_bound_set) {
180
RegMask rm;
181
for (int size = 1; size <= 16; size++) {
182
ASSERT_TRUE(rm.is_bound_set(size));
183
for (int i = 0; i < RegMask::CHUNK_SIZE - size; i++) {
184
for (int j = i; j < i + size; j++) {
185
rm.Insert(j);
186
}
187
ASSERT_TRUE(rm.is_bound_set(size)) << "Size " << size << " Index " << i;
188
contains_expected_num_of_registers(rm, size);
189
rm.Clear();
190
}
191
// A set with the AllStack bit does not count as a bound set
192
for (int j = RegMask::CHUNK_SIZE - size; j < RegMask::CHUNK_SIZE; j++) {
193
rm.Insert(j);
194
}
195
ASSERT_FALSE(rm.is_bound_set(size));
196
rm.Clear();
197
}
198
}
199