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