OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_ARM_CODEGEN_ARM_H_ | 28 #ifndef V8_ARM_CODEGEN_ARM_H_ |
29 #define V8_ARM_CODEGEN_ARM_H_ | 29 #define V8_ARM_CODEGEN_ARM_H_ |
30 | 30 |
| 31 #include "ic-inl.h" |
| 32 |
31 namespace v8 { | 33 namespace v8 { |
32 namespace internal { | 34 namespace internal { |
33 | 35 |
34 // Forward declarations | 36 // Forward declarations |
35 class CompilationInfo; | 37 class CompilationInfo; |
36 class DeferredCode; | 38 class DeferredCode; |
37 class RegisterAllocator; | 39 class RegisterAllocator; |
38 class RegisterFile; | 40 class RegisterFile; |
39 | 41 |
40 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 42 enum InitState { CONST_INIT, NOT_CONST_INIT }; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 467 |
466 class GenericBinaryOpStub : public CodeStub { | 468 class GenericBinaryOpStub : public CodeStub { |
467 public: | 469 public: |
468 GenericBinaryOpStub(Token::Value op, | 470 GenericBinaryOpStub(Token::Value op, |
469 OverwriteMode mode, | 471 OverwriteMode mode, |
470 int constant_rhs = CodeGenerator::kUnknownIntValue) | 472 int constant_rhs = CodeGenerator::kUnknownIntValue) |
471 : op_(op), | 473 : op_(op), |
472 mode_(mode), | 474 mode_(mode), |
473 constant_rhs_(constant_rhs), | 475 constant_rhs_(constant_rhs), |
474 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)), | 476 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)), |
| 477 runtime_operands_type_(BinaryOpIC::DEFAULT), |
| 478 name_(NULL) { } |
| 479 |
| 480 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info) |
| 481 : op_(OpBits::decode(key)), |
| 482 mode_(ModeBits::decode(key)), |
| 483 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))), |
| 484 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)), |
| 485 runtime_operands_type_(type_info), |
475 name_(NULL) { } | 486 name_(NULL) { } |
476 | 487 |
477 private: | 488 private: |
478 Token::Value op_; | 489 Token::Value op_; |
479 OverwriteMode mode_; | 490 OverwriteMode mode_; |
480 int constant_rhs_; | 491 int constant_rhs_; |
481 bool specialized_on_rhs_; | 492 bool specialized_on_rhs_; |
| 493 BinaryOpIC::TypeInfo runtime_operands_type_; |
482 char* name_; | 494 char* name_; |
483 | 495 |
484 static const int kMaxKnownRhs = 0x40000000; | 496 static const int kMaxKnownRhs = 0x40000000; |
485 | 497 |
486 // Minor key encoding in 16 bits. | 498 // Minor key encoding in 18 bits. |
487 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; | 499 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
488 class OpBits: public BitField<Token::Value, 2, 6> {}; | 500 class OpBits: public BitField<Token::Value, 2, 6> {}; |
489 class KnownIntBits: public BitField<int, 8, 8> {}; | 501 class KnownIntBits: public BitField<int, 8, 8> {}; |
| 502 class TypeInfoBits: public BitField<int, 16, 2> {}; |
490 | 503 |
491 Major MajorKey() { return GenericBinaryOp; } | 504 Major MajorKey() { return GenericBinaryOp; } |
492 int MinorKey() { | 505 int MinorKey() { |
493 // Encode the parameters in a unique 16 bit value. | 506 // Encode the parameters in a unique 18 bit value. |
494 return OpBits::encode(op_) | 507 return OpBits::encode(op_) |
495 | ModeBits::encode(mode_) | 508 | ModeBits::encode(mode_) |
496 | KnownIntBits::encode(MinorKeyForKnownInt()); | 509 | KnownIntBits::encode(MinorKeyForKnownInt()) |
| 510 | TypeInfoBits::encode(runtime_operands_type_); |
497 } | 511 } |
498 | 512 |
499 void Generate(MacroAssembler* masm); | 513 void Generate(MacroAssembler* masm); |
500 void HandleNonSmiBitwiseOp(MacroAssembler* masm); | 514 void HandleNonSmiBitwiseOp(MacroAssembler* masm); |
| 515 void HandleBinaryOpSlowCases(MacroAssembler* masm, |
| 516 Label* not_smi, |
| 517 const Builtins::JavaScript& builtin); |
| 518 void GenerateTypeTransition(MacroAssembler* masm); |
501 | 519 |
502 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) { | 520 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) { |
503 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false; | 521 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false; |
504 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3; | 522 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3; |
505 if (op == Token::MOD) { | 523 if (op == Token::MOD) { |
506 if (constant_rhs <= 1) return false; | 524 if (constant_rhs <= 1) return false; |
507 if (constant_rhs <= 10) return true; | 525 if (constant_rhs <= 10) return true; |
508 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true; | 526 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true; |
509 return false; | 527 return false; |
510 } | 528 } |
511 return false; | 529 return false; |
512 } | 530 } |
513 | 531 |
514 int MinorKeyForKnownInt() { | 532 int MinorKeyForKnownInt() { |
515 if (!specialized_on_rhs_) return 0; | 533 if (!specialized_on_rhs_) return 0; |
516 if (constant_rhs_ <= 10) return constant_rhs_ + 1; | 534 if (constant_rhs_ <= 10) return constant_rhs_ + 1; |
517 ASSERT(IsPowerOf2(constant_rhs_)); | 535 ASSERT(IsPowerOf2(constant_rhs_)); |
518 int key = 12; | 536 int key = 12; |
519 int d = constant_rhs_; | 537 int d = constant_rhs_; |
520 while ((d & 1) == 0) { | 538 while ((d & 1) == 0) { |
521 key++; | 539 key++; |
522 d >>= 1; | 540 d >>= 1; |
523 } | 541 } |
524 return key; | 542 return key; |
525 } | 543 } |
526 | 544 |
| 545 int KnownBitsForMinorKey(int key) { |
| 546 if (!key) return 0; |
| 547 if (key <= 11) return key - 1; |
| 548 int d = 1; |
| 549 while (key != 12) { |
| 550 key--; |
| 551 d <<= 1; |
| 552 } |
| 553 return d; |
| 554 } |
| 555 |
| 556 bool ShouldGenerateSmiCode() { |
| 557 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) && |
| 558 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS && |
| 559 runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 560 } |
| 561 |
| 562 bool ShouldGenerateFPCode() { |
| 563 return runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 564 } |
| 565 |
| 566 virtual int GetCodeKind() { return Code::BINARY_OP_IC; } |
| 567 |
| 568 virtual InlineCacheState GetICState() { |
| 569 return BinaryOpIC::ToState(runtime_operands_type_); |
| 570 } |
| 571 |
527 const char* GetName(); | 572 const char* GetName(); |
528 | 573 |
529 #ifdef DEBUG | 574 #ifdef DEBUG |
530 void Print() { | 575 void Print() { |
531 if (!specialized_on_rhs_) { | 576 if (!specialized_on_rhs_) { |
532 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_)); | 577 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_)); |
533 } else { | 578 } else { |
534 PrintF("GenericBinaryOpStub (%s by %d)\n", | 579 PrintF("GenericBinaryOpStub (%s by %d)\n", |
535 Token::String(op_), | 580 Token::String(op_), |
536 constant_rhs_); | 581 constant_rhs_); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 void Print() { | 734 void Print() { |
690 PrintF("NumberToStringStub\n"); | 735 PrintF("NumberToStringStub\n"); |
691 } | 736 } |
692 #endif | 737 #endif |
693 }; | 738 }; |
694 | 739 |
695 | 740 |
696 } } // namespace v8::internal | 741 } } // namespace v8::internal |
697 | 742 |
698 #endif // V8_ARM_CODEGEN_ARM_H_ | 743 #endif // V8_ARM_CODEGEN_ARM_H_ |
OLD | NEW |