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

Side by Side Diff: test/unittests/interpreter/bytecode-array-builder-unittest.cc

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase onto 3c1dc424d3f2f651ad Created 4 years, 9 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/interpreter/bytecode-array-builder.h" 7 #include "src/interpreter/bytecode-array-builder.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-register-allocator.h" 9 #include "src/interpreter/bytecode-register-allocator.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 // Emit control flow. Return must be the last instruction. 154 // Emit control flow. Return must be the last instruction.
155 BytecodeLabel start; 155 BytecodeLabel start;
156 builder.Bind(&start); 156 builder.Bind(&start);
157 // Short jumps with Imm8 operands 157 // Short jumps with Imm8 operands
158 builder.Jump(&start) 158 builder.Jump(&start)
159 .JumpIfNull(&start) 159 .JumpIfNull(&start)
160 .JumpIfUndefined(&start) 160 .JumpIfUndefined(&start)
161 .JumpIfNotHole(&start); 161 .JumpIfNotHole(&start);
162 162
163 // Longer jumps with constant operands
164 BytecodeLabel end[8];
165 builder.Jump(&end[0])
166 .LoadTrue()
167 .JumpIfTrue(&end[1])
168 .LoadTrue()
169 .JumpIfFalse(&end[2])
170 .LoadLiteral(Smi::FromInt(0))
171 .JumpIfTrue(&end[3])
172 .LoadLiteral(Smi::FromInt(0))
173 .JumpIfFalse(&end[4])
174 .JumpIfNull(&end[5])
175 .JumpIfUndefined(&end[6])
176 .JumpIfNotHole(&end[7]);
177
163 // Perform an operation that returns boolean value to 178 // Perform an operation that returns boolean value to
164 // generate JumpIfTrue/False 179 // generate JumpIfTrue/False
165 builder.CompareOperation(Token::Value::EQ, reg) 180 builder.CompareOperation(Token::Value::EQ, reg)
166 .JumpIfTrue(&start) 181 .JumpIfTrue(&start)
167 .CompareOperation(Token::Value::EQ, reg) 182 .CompareOperation(Token::Value::EQ, reg)
168 .JumpIfFalse(&start); 183 .JumpIfFalse(&start);
169 // Perform an operation that returns a non-boolean operation to 184 // Perform an operation that returns a non-boolean operation to
170 // generate JumpIfToBooleanTrue/False. 185 // generate JumpIfToBooleanTrue/False.
171 builder.BinaryOperation(Token::Value::ADD, reg) 186 builder.BinaryOperation(Token::Value::ADD, reg)
172 .JumpIfTrue(&start) 187 .JumpIfTrue(&start)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 for (int i = 0; i < 256; i++) { 230 for (int i = 0; i < 256; i++) {
216 // Emit junk in constant pool to force wide constant pool index. 231 // Emit junk in constant pool to force wide constant pool index.
217 builder.LoadLiteral(factory->NewNumber(2.5321 + i)); 232 builder.LoadLiteral(factory->NewNumber(2.5321 + i));
218 } 233 }
219 builder.LoadLiteral(Smi::FromInt(20000000)); 234 builder.LoadLiteral(Smi::FromInt(20000000));
220 Handle<String> wide_name = factory->NewStringFromStaticChars("var_wide_name"); 235 Handle<String> wide_name = factory->NewStringFromStaticChars("var_wide_name");
221 236
222 // Emit wide global load / store operations. 237 // Emit wide global load / store operations.
223 builder.LoadGlobal(name, 1024, TypeofMode::NOT_INSIDE_TYPEOF) 238 builder.LoadGlobal(name, 1024, TypeofMode::NOT_INSIDE_TYPEOF)
224 .LoadGlobal(name, 1024, TypeofMode::INSIDE_TYPEOF) 239 .LoadGlobal(name, 1024, TypeofMode::INSIDE_TYPEOF)
240 .LoadGlobal(name, 1024, TypeofMode::INSIDE_TYPEOF)
225 .StoreGlobal(name, 1024, LanguageMode::SLOPPY) 241 .StoreGlobal(name, 1024, LanguageMode::SLOPPY)
226 .StoreGlobal(wide_name, 1, LanguageMode::STRICT); 242 .StoreGlobal(wide_name, 1, LanguageMode::STRICT);
227 243
244 // Emit extra wide global load.
245 builder.LoadGlobal(name, 1024 * 1024, TypeofMode::NOT_INSIDE_TYPEOF);
246
228 // Emit wide load / store property operations. 247 // Emit wide load / store property operations.
229 builder.LoadNamedProperty(reg, wide_name, 0) 248 builder.LoadNamedProperty(reg, wide_name, 0)
230 .LoadKeyedProperty(reg, 2056) 249 .LoadKeyedProperty(reg, 2056)
231 .StoreNamedProperty(reg, wide_name, 0, LanguageMode::SLOPPY) 250 .StoreNamedProperty(reg, wide_name, 0, LanguageMode::SLOPPY)
232 .StoreKeyedProperty(reg, reg, 2056, LanguageMode::SLOPPY) 251 .StoreKeyedProperty(reg, reg, 2056, LanguageMode::SLOPPY)
233 .StoreNamedProperty(reg, wide_name, 0, LanguageMode::STRICT) 252 .StoreNamedProperty(reg, wide_name, 0, LanguageMode::STRICT)
234 .StoreKeyedProperty(reg, reg, 2056, LanguageMode::STRICT); 253 .StoreKeyedProperty(reg, reg, 2056, LanguageMode::STRICT);
235 254
236 // Emit wide context operations. 255 // Emit wide context operations.
237 builder.LoadContextSlot(reg, 1024).StoreContextSlot(reg, 1024); 256 builder.LoadContextSlot(reg, 1024).StoreContextSlot(reg, 1024);
(...skipping 26 matching lines...) Expand all
264 .CompareOperation(Token::Value::EQ, reg) 283 .CompareOperation(Token::Value::EQ, reg)
265 .JumpIfFalse(&start); 284 .JumpIfFalse(&start);
266 // Perform an operation that returns a non-boolean operation to 285 // Perform an operation that returns a non-boolean operation to
267 // generate JumpIfToBooleanTrue/False. 286 // generate JumpIfToBooleanTrue/False.
268 builder.BinaryOperation(Token::Value::ADD, reg) 287 builder.BinaryOperation(Token::Value::ADD, reg)
269 .JumpIfTrue(&start) 288 .JumpIfTrue(&start)
270 .BinaryOperation(Token::Value::ADD, reg) 289 .BinaryOperation(Token::Value::ADD, reg)
271 .JumpIfFalse(&start); 290 .JumpIfFalse(&start);
272 291
273 builder.Debugger(); 292 builder.Debugger();
274 293 for (size_t i = 0; i < arraysize(end); i++) {
294 builder.Bind(&end[i]);
295 }
275 builder.Return(); 296 builder.Return();
276 297
277 // Generate BytecodeArray. 298 // Generate BytecodeArray.
278 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); 299 Handle<BytecodeArray> the_array = builder.ToBytecodeArray();
279 CHECK_EQ(the_array->frame_size(), 300 CHECK_EQ(the_array->frame_size(),
280 (builder.fixed_and_temporary_register_count() + 301 builder.fixed_and_temporary_register_count() * kPointerSize);
281 builder.translation_register_count()) *
282 kPointerSize);
283 302
284 // Build scorecard of bytecodes encountered in the BytecodeArray. 303 // Build scorecard of bytecodes encountered in the BytecodeArray.
285 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); 304 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1);
305
286 Bytecode final_bytecode = Bytecode::kLdaZero; 306 Bytecode final_bytecode = Bytecode::kLdaZero;
287 int i = 0; 307 int i = 0;
288 while (i < the_array->length()) { 308 while (i < the_array->length()) {
289 uint8_t code = the_array->get(i); 309 uint8_t code = the_array->get(i);
290 scorecard[code] += 1; 310 scorecard[code] += 1;
291 final_bytecode = Bytecodes::FromByte(code); 311 final_bytecode = Bytecodes::FromByte(code);
292 i += Bytecodes::Size(Bytecodes::FromByte(code)); 312 int operand_scale = Bytecodes::GetPrefixBytecodeScale(final_bytecode);
313 if (operand_scale > 1) {
314 code = the_array->get(i + 1);
315 final_bytecode = Bytecodes::FromByte(code);
316 i += 1 + Bytecodes::Size(final_bytecode, operand_scale);
317 } else {
318 i += Bytecodes::Size(final_bytecode, operand_scale);
319 }
293 } 320 }
294 321
322 // Insert entry for illegal bytecode as this is never willingly emitted.
323 scorecard[Bytecodes::ToByte(Bytecode::kIllegal)] = 1;
324
295 // Check return occurs at the end and only once in the BytecodeArray. 325 // Check return occurs at the end and only once in the BytecodeArray.
296 CHECK_EQ(final_bytecode, Bytecode::kReturn); 326 CHECK_EQ(final_bytecode, Bytecode::kReturn);
297 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); 327 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1);
298 328
299 #define CHECK_BYTECODE_PRESENT(Name, ...) \ 329 #define CHECK_BYTECODE_PRESENT(Name, ...) \
300 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ 330 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \
301 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ 331 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \
302 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ 332 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \
303 } 333 }
304 BYTECODE_LIST(CHECK_BYTECODE_PRESENT) 334 BYTECODE_LIST(CHECK_BYTECODE_PRESENT)
(...skipping 17 matching lines...) Expand all
322 int total_registers = locals + contexts + temps; 352 int total_registers = locals + contexts + temps;
323 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize); 353 CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize);
324 } 354 }
325 } 355 }
326 } 356 }
327 } 357 }
328 358
329 359
330 TEST_F(BytecodeArrayBuilderTest, RegisterValues) { 360 TEST_F(BytecodeArrayBuilderTest, RegisterValues) {
331 int index = 1; 361 int index = 1;
332 uint8_t operand = static_cast<uint8_t>(-index); 362 int32_t operand = -index;
333 363
334 Register the_register(index); 364 Register the_register(index);
335 CHECK_EQ(the_register.index(), index); 365 CHECK_EQ(the_register.index(), index);
336 366
337 int actual_operand = the_register.ToOperand(); 367 int actual_operand = the_register.ToOperand();
338 CHECK_EQ(actual_operand, operand); 368 CHECK_EQ(actual_operand, operand);
339 369
340 int actual_index = Register::FromOperand(actual_operand).index(); 370 int actual_index = Register::FromOperand(actual_operand).index();
341 CHECK_EQ(actual_index, index); 371 CHECK_EQ(actual_index, index);
342 } 372 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 .JumpIfFalse(&label2) 553 .JumpIfFalse(&label2)
524 .Bind(&label3) 554 .Bind(&label3)
525 .BinaryOperation(Token::Value::ADD, reg) 555 .BinaryOperation(Token::Value::ADD, reg)
526 .JumpIfTrue(&label3) 556 .JumpIfTrue(&label3)
527 .Bind(&label4) 557 .Bind(&label4)
528 .BinaryOperation(Token::Value::ADD, reg) 558 .BinaryOperation(Token::Value::ADD, reg)
529 .JumpIfFalse(&label4); 559 .JumpIfFalse(&label4);
530 for (int i = 0; i < 63; i++) { 560 for (int i = 0; i < 63; i++) {
531 builder.Jump(&label4); 561 builder.Jump(&label4);
532 } 562 }
563
564 // Add padding to force wide backwards jumps.
565 for (int i = 0; i < 256; i++) {
566 builder.LoadTrue();
567 }
568
533 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4); 569 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4);
534 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3); 570 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3);
535 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2); 571 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2);
536 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1); 572 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1);
537 builder.Jump(&label0); 573 builder.Jump(&label0);
538 builder.Return(); 574 builder.Return();
539 575
540 Handle<BytecodeArray> array = builder.ToBytecodeArray(); 576 Handle<BytecodeArray> array = builder.ToBytecodeArray();
541 BytecodeArrayIterator iterator(array); 577 BytecodeArrayIterator iterator(array);
542 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 578 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
543 CHECK_EQ(iterator.GetImmediateOperand(0), 0); 579 CHECK_EQ(iterator.GetImmediateOperand(0), 0);
544 iterator.Advance(); 580 iterator.Advance();
545 // Ignore compare operation. 581 // Ignore compare operation.
546 iterator.Advance(); 582 iterator.Advance();
547 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); 583 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
584 CHECK_EQ(iterator.current_operand_scale(), 1);
548 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 585 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
549 iterator.Advance(); 586 iterator.Advance();
550 // Ignore compare operation. 587 // Ignore compare operation.
551 iterator.Advance(); 588 iterator.Advance();
552 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); 589 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
590 CHECK_EQ(iterator.current_operand_scale(), 1);
553 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 591 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
554 iterator.Advance(); 592 iterator.Advance();
555 // Ignore binary operation. 593 // Ignore binary operation.
556 iterator.Advance(); 594 iterator.Advance();
557 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); 595 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
596 CHECK_EQ(iterator.current_operand_scale(), 1);
558 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 597 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
559 iterator.Advance(); 598 iterator.Advance();
560 // Ignore binary operation. 599 // Ignore binary operation.
561 iterator.Advance(); 600 iterator.Advance();
562 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); 601 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
602 CHECK_EQ(iterator.current_operand_scale(), 1);
563 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 603 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
564 iterator.Advance(); 604 iterator.Advance();
565 for (int i = 0; i < 63; i++) { 605 for (int i = 0; i < 63; i++) {
566 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 606 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
607 CHECK_EQ(iterator.current_operand_scale(), 1);
567 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4); 608 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4);
568 iterator.Advance(); 609 iterator.Advance();
569 } 610 }
611 // Check padding to force wide backwards jumps.
612 for (int i = 0; i < 256; i++) {
613 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaTrue);
614 iterator.Advance();
615 }
570 // Ignore binary operation. 616 // Ignore binary operation.
571 iterator.Advance(); 617 iterator.Advance();
572 CHECK_EQ(iterator.current_bytecode(), 618 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse);
573 Bytecode::kJumpIfToBooleanFalseConstant); 619 CHECK_EQ(iterator.current_operand_scale(), 2);
574 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -132); 620 CHECK_EQ(iterator.GetImmediateOperand(0), -389);
575 iterator.Advance(); 621 iterator.Advance();
576 // Ignore binary operation. 622 // Ignore binary operation.
577 iterator.Advance(); 623 iterator.Advance();
578 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrueConstant); 624 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue);
579 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -140); 625 CHECK_EQ(iterator.current_operand_scale(), 2);
626 CHECK_EQ(iterator.GetImmediateOperand(0), -399);
580 iterator.Advance(); 627 iterator.Advance();
581 // Ignore compare operation. 628 // Ignore compare operation.
582 iterator.Advance(); 629 iterator.Advance();
583 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalseConstant); 630 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
584 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -148); 631 CHECK_EQ(iterator.current_operand_scale(), 2);
632 CHECK_EQ(iterator.GetImmediateOperand(0), -409);
585 iterator.Advance(); 633 iterator.Advance();
586 // Ignore compare operation. 634 // Ignore compare operation.
587 iterator.Advance(); 635 iterator.Advance();
588 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrueConstant); 636 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
589 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -156); 637 CHECK_EQ(iterator.current_operand_scale(), 2);
638 CHECK_EQ(iterator.GetImmediateOperand(0), -419);
590 iterator.Advance(); 639 iterator.Advance();
591 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpConstant); 640 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
592 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -160); 641 CHECK_EQ(iterator.current_operand_scale(), 2);
642 CHECK_EQ(iterator.GetImmediateOperand(0), -425);
593 iterator.Advance(); 643 iterator.Advance();
594 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); 644 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
595 iterator.Advance(); 645 iterator.Advance();
596 CHECK(iterator.done()); 646 CHECK(iterator.done());
597 } 647 }
598 648
599 649
600 TEST_F(BytecodeArrayBuilderTest, LabelReuse) { 650 TEST_F(BytecodeArrayBuilderTest, LabelReuse) {
601 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); 651 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0);
602 652
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 iterator.Advance(); 694 iterator.Advance();
645 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); 695 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
646 CHECK_EQ(iterator.GetImmediateOperand(0), -2); 696 CHECK_EQ(iterator.GetImmediateOperand(0), -2);
647 iterator.Advance(); 697 iterator.Advance();
648 } 698 }
649 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); 699 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
650 iterator.Advance(); 700 iterator.Advance();
651 CHECK(iterator.done()); 701 CHECK(iterator.done());
652 } 702 }
653 703
704 TEST_F(BytecodeArrayBuilderTest, OperandScales) {
705 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kByte), 1);
706 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kShort), 2);
707 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kQuad), 4);
708 CHECK_EQ(BytecodeArrayBuilder::OperandScale(
709 OperandSize::kShort, OperandSize::kShort, OperandSize::kShort,
710 OperandSize::kShort),
711 2);
712 CHECK_EQ(BytecodeArrayBuilder::OperandScale(
713 OperandSize::kQuad, OperandSize::kShort, OperandSize::kShort,
714 OperandSize::kShort),
715 4);
716 CHECK_EQ(BytecodeArrayBuilder::OperandScale(
717 OperandSize::kShort, OperandSize::kQuad, OperandSize::kShort,
718 OperandSize::kShort),
719 4);
720 CHECK_EQ(BytecodeArrayBuilder::OperandScale(
721 OperandSize::kShort, OperandSize::kShort, OperandSize::kQuad,
722 OperandSize::kShort),
723 4);
724 CHECK_EQ(BytecodeArrayBuilder::OperandScale(
725 OperandSize::kShort, OperandSize::kShort, OperandSize::kShort,
726 OperandSize::kQuad),
727 4);
728 }
729
730 TEST_F(BytecodeArrayBuilderTest, SizesForSignOperands) {
731 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(0) == OperandSize::kByte);
732 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8) ==
733 OperandSize::kByte);
734 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8) ==
735 OperandSize::kByte);
736 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8 + 1) ==
737 OperandSize::kShort);
738 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8 - 1) ==
739 OperandSize::kShort);
740 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16) ==
741 OperandSize::kShort);
742 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16) ==
743 OperandSize::kShort);
744 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16 + 1) ==
745 OperandSize::kQuad);
746 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16 - 1) ==
747 OperandSize::kQuad);
748 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt) ==
749 OperandSize::kQuad);
750 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt) ==
751 OperandSize::kQuad);
752 }
753
754 TEST_F(BytecodeArrayBuilderTest, SizesForUnsignOperands) {
755 // int overloads
756 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(0) == OperandSize::kByte);
757 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8) ==
758 OperandSize::kByte);
759 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8 + 1) ==
760 OperandSize::kShort);
761 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16) ==
762 OperandSize::kShort);
763 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16 + 1) ==
764 OperandSize::kQuad);
765 // size_t overloads
766 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(static_cast<size_t>(0)) ==
767 OperandSize::kByte);
768 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
769 static_cast<size_t>(kMaxUInt8)) == OperandSize::kByte);
770 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
771 static_cast<size_t>(kMaxUInt8 + 1)) == OperandSize::kShort);
772 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
773 static_cast<size_t>(kMaxUInt16)) == OperandSize::kShort);
774 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
775 static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad);
776 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(
777 static_cast<size_t>(kMaxUInt32)) == OperandSize::kQuad);
778 }
779
654 } // namespace interpreter 780 } // namespace interpreter
655 } // namespace internal 781 } // namespace internal
656 } // namespace v8 782 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698