Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: test/unittests/interpreter/bytecodes-unittest.cc

Issue 1947403002: [interpreter] Introduce bytecode generation pipeline. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Attempt to fix compilation with gcc/msvc and introduce nop to simplify source positions in peephole… Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bytecodes.h" 9 #include "src/interpreter/bytecodes.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Register r = Register::FromParameterIndex(i, parameter_count); 69 Register r = Register::FromParameterIndex(i, parameter_count);
70 uint32_t operand = r.ToOperand(); 70 uint32_t operand = r.ToOperand();
71 uint8_t index = static_cast<uint8_t>(operand); 71 uint8_t index = static_cast<uint8_t>(operand);
72 CHECK_LT(index, operand_count.size()); 72 CHECK_LT(index, operand_count.size());
73 operand_count[index] += 1; 73 operand_count[index] += 1;
74 CHECK_EQ(operand_count[index], 1); 74 CHECK_EQ(operand_count[index], 1);
75 } 75 }
76 } 76 }
77 77
78 TEST(OperandScaling, ScalableAndNonScalable) { 78 TEST(OperandScaling, ScalableAndNonScalable) {
79 for (OperandScale operand_scale = OperandScale::kSingle; 79 const OperandScale kOperandScales[] = {
80 operand_scale <= OperandScale::kMaxValid; 80 #define VALUE(Name, _) OperandScale::k##Name,
81 operand_scale = Bytecodes::NextOperandScale(operand_scale)) { 81 OPERAND_SCALE_LIST(VALUE)
82 #undef VALUE
83 };
84
85 for (OperandScale operand_scale : kOperandScales) {
82 int scale = static_cast<int>(operand_scale); 86 int scale = static_cast<int>(operand_scale);
83 CHECK_EQ(Bytecodes::Size(Bytecode::kCallRuntime, operand_scale), 87 CHECK_EQ(Bytecodes::Size(Bytecode::kCallRuntime, operand_scale),
84 1 + 2 + 2 * scale); 88 1 + 2 + 2 * scale);
85 CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, operand_scale), 89 CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, operand_scale),
86 1 + 2 * scale + 1); 90 1 + 2 * scale + 1);
87 CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + scale); 91 CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, operand_scale), 1 + scale);
88 } 92 }
89 } 93 }
90 94
91 TEST(Bytecodes, HasAnyRegisterOperands) { 95 TEST(Bytecodes, HasAnyRegisterOperands) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 301 }
298 302
299 TEST(Bytecodes, PrefixMappings) { 303 TEST(Bytecodes, PrefixMappings) {
300 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; 304 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide};
301 TRACED_FOREACH(Bytecode, prefix, prefixes) { 305 TRACED_FOREACH(Bytecode, prefix, prefixes) {
302 CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode( 306 CHECK_EQ(prefix, Bytecodes::OperandScaleToPrefixBytecode(
303 Bytecodes::PrefixBytecodeToOperandScale(prefix))); 307 Bytecodes::PrefixBytecodeToOperandScale(prefix)));
304 } 308 }
305 } 309 }
306 310
307 TEST(OperandScale, PrefixesScale) { 311 TEST(Bytecodes, OperandScales) {
308 CHECK(Bytecodes::NextOperandScale(OperandScale::kSingle) == 312 CHECK_EQ(Bytecodes::OperandSizesToScale(OperandSize::kByte),
309 OperandScale::kDouble); 313 OperandScale::kSingle);
310 CHECK(Bytecodes::NextOperandScale(OperandScale::kDouble) == 314 CHECK_EQ(Bytecodes::OperandSizesToScale(OperandSize::kShort),
311 OperandScale::kQuadruple); 315 OperandScale::kDouble);
312 CHECK(Bytecodes::NextOperandScale(OperandScale::kQuadruple) == 316 CHECK_EQ(Bytecodes::OperandSizesToScale(OperandSize::kQuad),
313 OperandScale::kInvalid); 317 OperandScale::kQuadruple);
318 CHECK_EQ(
319 Bytecodes::OperandSizesToScale(OperandSize::kShort, OperandSize::kShort,
320 OperandSize::kShort, OperandSize::kShort),
321 OperandScale::kDouble);
322 CHECK_EQ(
323 Bytecodes::OperandSizesToScale(OperandSize::kQuad, OperandSize::kShort,
324 OperandSize::kShort, OperandSize::kShort),
325 OperandScale::kQuadruple);
326 CHECK_EQ(
327 Bytecodes::OperandSizesToScale(OperandSize::kShort, OperandSize::kQuad,
328 OperandSize::kShort, OperandSize::kShort),
329 OperandScale::kQuadruple);
330 CHECK_EQ(
331 Bytecodes::OperandSizesToScale(OperandSize::kShort, OperandSize::kShort,
332 OperandSize::kQuad, OperandSize::kShort),
333 OperandScale::kQuadruple);
334 CHECK_EQ(
335 Bytecodes::OperandSizesToScale(OperandSize::kShort, OperandSize::kShort,
336 OperandSize::kShort, OperandSize::kQuad),
337 OperandScale::kQuadruple);
338 }
339
340 TEST(Bytecodes, SizesForSignedOperands) {
341 CHECK(Bytecodes::SizeForSignedOperand(0) == OperandSize::kByte);
342 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt8) == OperandSize::kByte);
343 CHECK(Bytecodes::SizeForSignedOperand(kMinInt8) == OperandSize::kByte);
344 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt8 + 1) == OperandSize::kShort);
345 CHECK(Bytecodes::SizeForSignedOperand(kMinInt8 - 1) == OperandSize::kShort);
346 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt16) == OperandSize::kShort);
347 CHECK(Bytecodes::SizeForSignedOperand(kMinInt16) == OperandSize::kShort);
348 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt16 + 1) == OperandSize::kQuad);
349 CHECK(Bytecodes::SizeForSignedOperand(kMinInt16 - 1) == OperandSize::kQuad);
350 CHECK(Bytecodes::SizeForSignedOperand(kMaxInt) == OperandSize::kQuad);
351 CHECK(Bytecodes::SizeForSignedOperand(kMinInt) == OperandSize::kQuad);
352 }
353
354 TEST(Bytecodes, SizesForUnsignedOperands) {
355 // int overloads
356 CHECK(Bytecodes::SizeForUnsignedOperand(0) == OperandSize::kByte);
357 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8) == OperandSize::kByte);
358 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt8 + 1) ==
359 OperandSize::kShort);
360 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16) == OperandSize::kShort);
361 CHECK(Bytecodes::SizeForUnsignedOperand(kMaxUInt16 + 1) ==
362 OperandSize::kQuad);
363 // size_t overloads
364 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(0)) ==
365 OperandSize::kByte);
366 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt8)) ==
367 OperandSize::kByte);
368 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt8 + 1)) ==
369 OperandSize::kShort);
370 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt16)) ==
371 OperandSize::kShort);
372 CHECK(Bytecodes::SizeForUnsignedOperand(
373 static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad);
374 CHECK(Bytecodes::SizeForUnsignedOperand(static_cast<size_t>(kMaxUInt32)) ==
375 OperandSize::kQuad);
314 } 376 }
315 377
316 TEST(OperandScale, PrefixesRequired) { 378 TEST(OperandScale, PrefixesRequired) {
317 CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle)); 379 CHECK(!Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kSingle));
318 CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble)); 380 CHECK(Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kDouble));
319 CHECK( 381 CHECK(
320 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple)); 382 Bytecodes::OperandScaleRequiresPrefixBytecode(OperandScale::kQuadruple));
321 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) == 383 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kDouble) ==
322 Bytecode::kWide); 384 Bytecode::kWide);
323 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) == 385 CHECK(Bytecodes::OperandScaleToPrefixBytecode(OperandScale::kQuadruple) ==
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); 417 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone));
356 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); 418 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead));
357 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); 419 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite));
358 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); 420 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite));
359 CHECK_EQ(names.size(), 4); 421 CHECK_EQ(names.size(), 4);
360 } 422 }
361 423
362 } // namespace interpreter 424 } // namespace interpreter
363 } // namespace internal 425 } // namespace internal
364 } // namespace v8 426 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698