OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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); |
286 Bytecode final_bytecode = Bytecode::kLdaZero; | 305 Bytecode final_bytecode = Bytecode::kLdaZero; |
287 int i = 0; | 306 int i = 0; |
288 while (i < the_array->length()) { | 307 while (i < the_array->length()) { |
289 uint8_t code = the_array->get(i); | 308 uint8_t code = the_array->get(i); |
290 scorecard[code] += 1; | 309 scorecard[code] += 1; |
291 final_bytecode = Bytecodes::FromByte(code); | 310 final_bytecode = Bytecodes::FromByte(code); |
292 i += Bytecodes::Size(Bytecodes::FromByte(code)); | 311 int operand_scale = Bytecodes::GetPrefixBytecodeScale(final_bytecode); |
| 312 if (operand_scale > 1) { |
| 313 code = the_array->get(i + 1); |
| 314 final_bytecode = Bytecodes::FromByte(code); |
| 315 i += 1 + Bytecodes::Size(final_bytecode, operand_scale); |
| 316 } else { |
| 317 i += Bytecodes::Size(final_bytecode, operand_scale); |
| 318 } |
293 } | 319 } |
294 | 320 |
295 // Check return occurs at the end and only once in the BytecodeArray. | 321 // Check return occurs at the end and only once in the BytecodeArray. |
296 CHECK_EQ(final_bytecode, Bytecode::kReturn); | 322 CHECK_EQ(final_bytecode, Bytecode::kReturn); |
297 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); | 323 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); |
298 | 324 |
299 #define CHECK_BYTECODE_PRESENT(Name, ...) \ | 325 #define CHECK_BYTECODE_PRESENT(Name, ...) \ |
300 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ | 326 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ |
301 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ | 327 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ |
302 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ | 328 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 .JumpIfFalse(&label2) | 549 .JumpIfFalse(&label2) |
524 .Bind(&label3) | 550 .Bind(&label3) |
525 .BinaryOperation(Token::Value::ADD, reg) | 551 .BinaryOperation(Token::Value::ADD, reg) |
526 .JumpIfTrue(&label3) | 552 .JumpIfTrue(&label3) |
527 .Bind(&label4) | 553 .Bind(&label4) |
528 .BinaryOperation(Token::Value::ADD, reg) | 554 .BinaryOperation(Token::Value::ADD, reg) |
529 .JumpIfFalse(&label4); | 555 .JumpIfFalse(&label4); |
530 for (int i = 0; i < 63; i++) { | 556 for (int i = 0; i < 63; i++) { |
531 builder.Jump(&label4); | 557 builder.Jump(&label4); |
532 } | 558 } |
| 559 |
| 560 // Add padding to force wide backwards jumps. |
| 561 for (int i = 0; i < 256; i++) { |
| 562 builder.LoadTrue(); |
| 563 } |
| 564 |
533 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4); | 565 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4); |
534 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3); | 566 builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3); |
535 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2); | 567 builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2); |
536 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1); | 568 builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1); |
537 builder.Jump(&label0); | 569 builder.Jump(&label0); |
538 builder.Return(); | 570 builder.Return(); |
539 | 571 |
540 Handle<BytecodeArray> array = builder.ToBytecodeArray(); | 572 Handle<BytecodeArray> array = builder.ToBytecodeArray(); |
541 BytecodeArrayIterator iterator(array); | 573 BytecodeArrayIterator iterator(array); |
542 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 574 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
543 CHECK_EQ(iterator.GetImmediateOperand(0), 0); | 575 CHECK_EQ(iterator.GetImmediateOperand(0), 0); |
544 iterator.Advance(); | 576 iterator.Advance(); |
545 // Ignore compare operation. | 577 // Ignore compare operation. |
546 iterator.Advance(); | 578 iterator.Advance(); |
547 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); | 579 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); |
| 580 CHECK_EQ(iterator.current_operand_scale(), 1); |
548 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 581 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
549 iterator.Advance(); | 582 iterator.Advance(); |
550 // Ignore compare operation. | 583 // Ignore compare operation. |
551 iterator.Advance(); | 584 iterator.Advance(); |
552 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); | 585 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); |
| 586 CHECK_EQ(iterator.current_operand_scale(), 1); |
553 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 587 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
554 iterator.Advance(); | 588 iterator.Advance(); |
555 // Ignore binary operation. | 589 // Ignore binary operation. |
556 iterator.Advance(); | 590 iterator.Advance(); |
557 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); | 591 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); |
| 592 CHECK_EQ(iterator.current_operand_scale(), 1); |
558 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 593 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
559 iterator.Advance(); | 594 iterator.Advance(); |
560 // Ignore binary operation. | 595 // Ignore binary operation. |
561 iterator.Advance(); | 596 iterator.Advance(); |
562 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); | 597 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); |
| 598 CHECK_EQ(iterator.current_operand_scale(), 1); |
563 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 599 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
564 iterator.Advance(); | 600 iterator.Advance(); |
565 for (int i = 0; i < 63; i++) { | 601 for (int i = 0; i < 63; i++) { |
566 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 602 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
| 603 CHECK_EQ(iterator.current_operand_scale(), 1); |
567 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4); | 604 CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4); |
568 iterator.Advance(); | 605 iterator.Advance(); |
569 } | 606 } |
| 607 // Check padding to force wide backwards jumps. |
| 608 for (int i = 0; i < 256; i++) { |
| 609 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaTrue); |
| 610 iterator.Advance(); |
| 611 } |
570 // Ignore binary operation. | 612 // Ignore binary operation. |
571 iterator.Advance(); | 613 iterator.Advance(); |
572 CHECK_EQ(iterator.current_bytecode(), | 614 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); |
573 Bytecode::kJumpIfToBooleanFalseConstant); | 615 CHECK_EQ(iterator.current_operand_scale(), 2); |
574 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -132); | 616 CHECK_EQ(iterator.GetImmediateOperand(0), -389); |
575 iterator.Advance(); | 617 iterator.Advance(); |
576 // Ignore binary operation. | 618 // Ignore binary operation. |
577 iterator.Advance(); | 619 iterator.Advance(); |
578 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrueConstant); | 620 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); |
579 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -140); | 621 CHECK_EQ(iterator.current_operand_scale(), 2); |
| 622 CHECK_EQ(iterator.GetImmediateOperand(0), -399); |
580 iterator.Advance(); | 623 iterator.Advance(); |
581 // Ignore compare operation. | 624 // Ignore compare operation. |
582 iterator.Advance(); | 625 iterator.Advance(); |
583 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalseConstant); | 626 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse); |
584 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -148); | 627 CHECK_EQ(iterator.current_operand_scale(), 2); |
| 628 CHECK_EQ(iterator.GetImmediateOperand(0), -409); |
585 iterator.Advance(); | 629 iterator.Advance(); |
586 // Ignore compare operation. | 630 // Ignore compare operation. |
587 iterator.Advance(); | 631 iterator.Advance(); |
588 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrueConstant); | 632 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue); |
589 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -156); | 633 CHECK_EQ(iterator.current_operand_scale(), 2); |
| 634 CHECK_EQ(iterator.GetImmediateOperand(0), -419); |
590 iterator.Advance(); | 635 iterator.Advance(); |
591 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpConstant); | 636 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
592 CHECK_EQ(Smi::cast(*iterator.GetConstantForIndexOperand(0))->value(), -160); | 637 CHECK_EQ(iterator.current_operand_scale(), 2); |
| 638 CHECK_EQ(iterator.GetImmediateOperand(0), -425); |
593 iterator.Advance(); | 639 iterator.Advance(); |
594 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 640 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
595 iterator.Advance(); | 641 iterator.Advance(); |
596 CHECK(iterator.done()); | 642 CHECK(iterator.done()); |
597 } | 643 } |
598 | 644 |
599 | 645 |
600 TEST_F(BytecodeArrayBuilderTest, LabelReuse) { | 646 TEST_F(BytecodeArrayBuilderTest, LabelReuse) { |
601 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); | 647 BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0); |
602 | 648 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 iterator.Advance(); | 690 iterator.Advance(); |
645 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); | 691 CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
646 CHECK_EQ(iterator.GetImmediateOperand(0), -2); | 692 CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
647 iterator.Advance(); | 693 iterator.Advance(); |
648 } | 694 } |
649 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 695 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
650 iterator.Advance(); | 696 iterator.Advance(); |
651 CHECK(iterator.done()); | 697 CHECK(iterator.done()); |
652 } | 698 } |
653 | 699 |
| 700 TEST_F(BytecodeArrayBuilderTest, OperandScales) { |
| 701 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kByte), 1); |
| 702 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kShort), 2); |
| 703 CHECK_EQ(BytecodeArrayBuilder::OperandScale(OperandSize::kQuad), 4); |
| 704 CHECK_EQ(BytecodeArrayBuilder::OperandScale( |
| 705 OperandSize::kShort, OperandSize::kShort, OperandSize::kShort, |
| 706 OperandSize::kShort), |
| 707 2); |
| 708 CHECK_EQ(BytecodeArrayBuilder::OperandScale( |
| 709 OperandSize::kQuad, OperandSize::kShort, OperandSize::kShort, |
| 710 OperandSize::kShort), |
| 711 4); |
| 712 CHECK_EQ(BytecodeArrayBuilder::OperandScale( |
| 713 OperandSize::kShort, OperandSize::kQuad, OperandSize::kShort, |
| 714 OperandSize::kShort), |
| 715 4); |
| 716 CHECK_EQ(BytecodeArrayBuilder::OperandScale( |
| 717 OperandSize::kShort, OperandSize::kShort, OperandSize::kQuad, |
| 718 OperandSize::kShort), |
| 719 4); |
| 720 CHECK_EQ(BytecodeArrayBuilder::OperandScale( |
| 721 OperandSize::kShort, OperandSize::kShort, OperandSize::kShort, |
| 722 OperandSize::kQuad), |
| 723 4); |
| 724 } |
| 725 |
| 726 TEST_F(BytecodeArrayBuilderTest, SizesForSignOperands) { |
| 727 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(0) == OperandSize::kByte); |
| 728 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8) == |
| 729 OperandSize::kByte); |
| 730 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8) == |
| 731 OperandSize::kByte); |
| 732 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt8 + 1) == |
| 733 OperandSize::kShort); |
| 734 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt8 - 1) == |
| 735 OperandSize::kShort); |
| 736 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16) == |
| 737 OperandSize::kShort); |
| 738 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16) == |
| 739 OperandSize::kShort); |
| 740 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt16 + 1) == |
| 741 OperandSize::kQuad); |
| 742 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt16 - 1) == |
| 743 OperandSize::kQuad); |
| 744 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMaxInt) == |
| 745 OperandSize::kQuad); |
| 746 CHECK(BytecodeArrayBuilder::SizeForSignedOperand(kMinInt) == |
| 747 OperandSize::kQuad); |
| 748 } |
| 749 |
| 750 TEST_F(BytecodeArrayBuilderTest, SizesForUnsignOperands) { |
| 751 // int overloads |
| 752 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(0) == OperandSize::kByte); |
| 753 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8) == |
| 754 OperandSize::kByte); |
| 755 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt8 + 1) == |
| 756 OperandSize::kShort); |
| 757 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16) == |
| 758 OperandSize::kShort); |
| 759 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(kMaxUInt16 + 1) == |
| 760 OperandSize::kQuad); |
| 761 // size_t overloads |
| 762 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand(static_cast<size_t>(0)) == |
| 763 OperandSize::kByte); |
| 764 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand( |
| 765 static_cast<size_t>(kMaxUInt8)) == OperandSize::kByte); |
| 766 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand( |
| 767 static_cast<size_t>(kMaxUInt8 + 1)) == OperandSize::kShort); |
| 768 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand( |
| 769 static_cast<size_t>(kMaxUInt16)) == OperandSize::kShort); |
| 770 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand( |
| 771 static_cast<size_t>(kMaxUInt16 + 1)) == OperandSize::kQuad); |
| 772 CHECK(BytecodeArrayBuilder::SizeForUnsignedOperand( |
| 773 static_cast<size_t>(kMaxUInt32)) == OperandSize::kQuad); |
| 774 } |
| 775 |
654 } // namespace interpreter | 776 } // namespace interpreter |
655 } // namespace internal | 777 } // namespace internal |
656 } // namespace v8 | 778 } // namespace v8 |
OLD | NEW |