OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/interpreter/bytecode-register.h" | 9 #include "src/interpreter/bytecode-register.h" |
10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 | 155 |
156 TEST(Bytecodes, PrefixMappings) { | 156 TEST(Bytecodes, PrefixMappings) { |
157 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; | 157 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; |
158 TRACED_FOREACH(Bytecode, prefix, prefixes) { | 158 TRACED_FOREACH(Bytecode, prefix, prefixes) { |
159 CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode( | 159 CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode( |
160 Bytecodes::PrefixBytecodeToOperandScale(prefix))); | 160 Bytecodes::PrefixBytecodeToOperandScale(prefix))); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 TEST(Bytecodes, SizesForSignedOperands) { | 164 TEST(Bytecodes, ScaleForSignedOperand) { |
165 CHECK(Bytecodes::SizeForSignedOperand(0) == OperandSize::kByte); | 165 CHECK(Bytecodes::ScaleForSignedOperand(0) == OperandScale::kSingle); |
166 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt8) == OperandSize::kByte); | 166 CHECK(Bytecodes::ScaleForSignedOperand(kMaxInt8) == OperandScale::kSingle); |
167 CHECK(Bytecodes::SizeForSignedOperand(kMinInt8) == OperandSize::kByte); | 167 CHECK(Bytecodes::ScaleForSignedOperand(kMinInt8) == OperandScale::kSingle); |
168 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt8 + 1) == OperandSize::kShort); | 168 CHECK(Bytecodes::ScaleForSignedOperand(kMaxInt8 + 1) == |
169 CHECK(Bytecodes::SizeForSignedOperand(kMinInt8 - 1) == OperandSize::kShort); | 169 OperandScale::kDouble); |
170 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt16) == OperandSize::kShort); | 170 CHECK(Bytecodes::ScaleForSignedOperand(kMinInt8 - 1) == |
171 CHECK(Bytecodes::SizeForSignedOperand(kMinInt16) == OperandSize::kShort); | 171 OperandScale::kDouble); |
172 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt16 + 1) == OperandSize::kQuad); | 172 CHECK(Bytecodes::ScaleForSignedOperand(kMaxInt16) == OperandScale::kDouble); |
173 CHECK(Bytecodes::SizeForSignedOperand(kMinInt16 - 1) == OperandSize::kQuad); | 173 CHECK(Bytecodes::ScaleForSignedOperand(kMinInt16) == OperandScale::kDouble); |
174 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt) == OperandSize::kQuad); | 174 CHECK(Bytecodes::ScaleForSignedOperand(kMaxInt16 + 1) == |
175 CHECK(Bytecodes::SizeForSignedOperand(kMinInt) == OperandSize::kQuad); | 175 OperandScale::kQuadruple); |
| 176 CHECK(Bytecodes::ScaleForSignedOperand(kMinInt16 - 1) == |
| 177 OperandScale::kQuadruple); |
| 178 CHECK(Bytecodes::ScaleForSignedOperand(kMaxInt) == OperandScale::kQuadruple); |
| 179 CHECK(Bytecodes::ScaleForSignedOperand(kMinInt) == OperandScale::kQuadruple); |
| 180 } |
| 181 |
| 182 TEST(Bytecodes, ScaleForUnsignedOperands) { |
| 183 // int overloads |
| 184 CHECK(Bytecodes::ScaleForUnsignedOperand(0) == OperandScale::kSingle); |
| 185 CHECK(Bytecodes::ScaleForUnsignedOperand(kMaxUInt8) == OperandScale::kSingle); |
| 186 CHECK(Bytecodes::ScaleForUnsignedOperand(kMaxUInt8 + 1) == |
| 187 OperandScale::kDouble); |
| 188 CHECK(Bytecodes::ScaleForUnsignedOperand(kMaxUInt16) == |
| 189 OperandScale::kDouble); |
| 190 CHECK(Bytecodes::ScaleForUnsignedOperand(kMaxUInt16 + 1) == |
| 191 OperandScale::kQuadruple); |
| 192 // size_t overloads |
| 193 CHECK(Bytecodes::ScaleForUnsignedOperand(static_cast<size_t>(0)) == |
| 194 OperandScale::kSingle); |
| 195 CHECK(Bytecodes::ScaleForUnsignedOperand(static_cast<size_t>(kMaxUInt8)) == |
| 196 OperandScale::kSingle); |
| 197 CHECK(Bytecodes::ScaleForUnsignedOperand( |
| 198 static_cast<size_t>(kMaxUInt8 + 1)) == OperandScale::kDouble); |
| 199 CHECK(Bytecodes::ScaleForUnsignedOperand(static_cast<size_t>(kMaxUInt16)) == |
| 200 OperandScale::kDouble); |
| 201 CHECK(Bytecodes::ScaleForUnsignedOperand( |
| 202 static_cast<size_t>(kMaxUInt16 + 1)) == OperandScale::kQuadruple); |
| 203 CHECK(Bytecodes::ScaleForUnsignedOperand(static_cast<size_t>(kMaxUInt32)) == |
| 204 OperandScale::kQuadruple); |
176 } | 205 } |
177 | 206 |
178 TEST(Bytecodes, SizesForUnsignedOperands) { | 207 TEST(Bytecodes, SizesForUnsignedOperands) { |
179 // int overloads | 208 // int overloads |
180 CHECK(Bytecodes::SizeForUnsignedOperand(0) == OperandSize::kByte); | 209 CHECK(Bytecodes::SizeForUnsignedOperand(0) == OperandSize::kByte); |
181 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8) == OperandSize::kByte); | 210 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8) == OperandSize::kByte); |
182 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8 + 1) == | 211 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8 + 1) == |
183 OperandSize::kShort); | 212 OperandSize::kShort); |
184 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16) == OperandSize::kShort); | 213 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16) == OperandSize::kShort); |
185 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16 + 1) == | 214 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16 + 1) == |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 CHECK(!Bytecodes::ReadsAccumulator(Bytecode::kLdar)); | 258 CHECK(!Bytecodes::ReadsAccumulator(Bytecode::kLdar)); |
230 CHECK(Bytecodes::WritesAccumulator(Bytecode::kLdar)); | 259 CHECK(Bytecodes::WritesAccumulator(Bytecode::kLdar)); |
231 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kLdar), | 260 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kLdar), |
232 AccumulatorUse::kWrite); | 261 AccumulatorUse::kWrite); |
233 CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd)); | 262 CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd)); |
234 CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd)); | 263 CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd)); |
235 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd), | 264 CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd), |
236 AccumulatorUse::kReadWrite); | 265 AccumulatorUse::kReadWrite); |
237 } | 266 } |
238 | 267 |
239 TEST(AccumulatorUse, AccumulatorUseToString) { | |
240 std::set<std::string> names; | |
241 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); | |
242 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); | |
243 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); | |
244 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); | |
245 CHECK_EQ(names.size(), 4); | |
246 } | |
247 } // namespace interpreter | 268 } // namespace interpreter |
248 } // namespace internal | 269 } // namespace internal |
249 } // namespace v8 | 270 } // namespace v8 |
OLD | NEW |