OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 2635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2646 if (new_type == BinaryOpIC::STRING) return new_type; | 2646 if (new_type == BinaryOpIC::STRING) return new_type; |
2647 return BinaryOpIC::GENERIC; | 2647 return BinaryOpIC::GENERIC; |
2648 } | 2648 } |
2649 return Max(old_type, new_type); | 2649 return Max(old_type, new_type); |
2650 } | 2650 } |
2651 | 2651 |
2652 | 2652 |
2653 #ifdef DEBUG | 2653 #ifdef DEBUG |
2654 static void TraceBinaryOp(BinaryOpIC::TypeInfo left, | 2654 static void TraceBinaryOp(BinaryOpIC::TypeInfo left, |
2655 BinaryOpIC::TypeInfo right, | 2655 BinaryOpIC::TypeInfo right, |
2656 bool has_fixed_right_arg, | 2656 Maybe<int32_t> fixed_right_arg, |
2657 int32_t fixed_right_arg_value, | |
2658 BinaryOpIC::TypeInfo result) { | 2657 BinaryOpIC::TypeInfo result) { |
2659 PrintF("%s*%s", BinaryOpIC::GetName(left), BinaryOpIC::GetName(right)); | 2658 PrintF("%s*%s", BinaryOpIC::GetName(left), BinaryOpIC::GetName(right)); |
2660 if (has_fixed_right_arg) PrintF("{%d}", fixed_right_arg_value); | 2659 if (fixed_right_arg.has_value) PrintF("{%d}", fixed_right_arg.value); |
2661 PrintF("->%s", BinaryOpIC::GetName(result)); | 2660 PrintF("->%s", BinaryOpIC::GetName(result)); |
2662 } | 2661 } |
2663 #endif | 2662 #endif |
2664 | 2663 |
2665 | 2664 |
2666 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { | 2665 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { |
2667 ASSERT(args.length() == 3); | 2666 ASSERT(args.length() == 3); |
2668 | 2667 |
2669 HandleScope scope(isolate); | 2668 HandleScope scope(isolate); |
2670 Handle<Object> left = args.at<Object>(0); | 2669 Handle<Object> left = args.at<Object>(0); |
(...skipping 11 matching lines...) Expand all Loading... |
2682 | 2681 |
2683 // STRING is only used for ADD operations. | 2682 // STRING is only used for ADD operations. |
2684 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && | 2683 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && |
2685 op != Token::ADD) { | 2684 op != Token::ADD) { |
2686 new_left = new_right = BinaryOpIC::GENERIC; | 2685 new_left = new_right = BinaryOpIC::GENERIC; |
2687 } | 2686 } |
2688 | 2687 |
2689 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); | 2688 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); |
2690 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); | 2689 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); |
2691 | 2690 |
2692 bool previous_has_fixed_right_arg = | 2691 Maybe<int> previous_fixed_right_arg = |
2693 BinaryOpStub::decode_has_fixed_right_arg_from_minor_key(key); | 2692 BinaryOpStub::decode_fixed_right_arg_from_minor_key(key); |
2694 int previous_fixed_right_arg_value = | |
2695 BinaryOpStub::decode_fixed_right_arg_value_from_minor_key(key); | |
2696 | 2693 |
2697 int32_t value; | 2694 int32_t value; |
2698 bool new_has_fixed_right_arg = | 2695 bool new_has_fixed_right_arg = |
2699 op == Token::MOD && | 2696 op == Token::MOD && |
2700 right->ToInt32(&value) && | 2697 right->ToInt32(&value) && |
2701 BinaryOpStub::can_encode_arg_value(value) && | 2698 BinaryOpStub::can_encode_arg_value(value) && |
2702 (previous_overall == BinaryOpIC::UNINITIALIZED || | 2699 (previous_overall == BinaryOpIC::UNINITIALIZED || |
2703 (previous_has_fixed_right_arg && | 2700 (previous_fixed_right_arg.has_value && |
2704 previous_fixed_right_arg_value == value)); | 2701 previous_fixed_right_arg.value == value)); |
2705 int32_t new_fixed_right_arg_value = new_has_fixed_right_arg ? value : 1; | 2702 Maybe<int32_t> new_fixed_right_arg( |
| 2703 new_has_fixed_right_arg, new_has_fixed_right_arg ? value : 1); |
2706 | 2704 |
2707 if (previous_has_fixed_right_arg == new_has_fixed_right_arg) { | 2705 if (previous_fixed_right_arg.has_value == new_fixed_right_arg.has_value) { |
2708 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { | 2706 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { |
2709 if (op == Token::DIV || | 2707 if (op == Token::DIV || |
2710 op == Token::MUL || | 2708 op == Token::MUL || |
2711 op == Token::SHR || | 2709 op == Token::SHR || |
2712 kSmiValueSize == 32) { | 2710 kSmiValueSize == 32) { |
2713 // Arithmetic on two Smi inputs has yielded a heap number. | 2711 // Arithmetic on two Smi inputs has yielded a heap number. |
2714 // That is the only way to get here from the Smi stub. | 2712 // That is the only way to get here from the Smi stub. |
2715 // With 32-bit Smis, all overflows give heap numbers, but with | 2713 // With 32-bit Smis, all overflows give heap numbers, but with |
2716 // 31-bit Smis, most operations overflow to int32 results. | 2714 // 31-bit Smis, most operations overflow to int32 results. |
2717 result_type = BinaryOpIC::NUMBER; | 2715 result_type = BinaryOpIC::NUMBER; |
2718 } else { | 2716 } else { |
2719 // Other operations on SMIs that overflow yield int32s. | 2717 // Other operations on SMIs that overflow yield int32s. |
2720 result_type = BinaryOpIC::INT32; | 2718 result_type = BinaryOpIC::INT32; |
2721 } | 2719 } |
2722 } | 2720 } |
2723 if (new_overall == BinaryOpIC::INT32 && | 2721 if (new_overall == BinaryOpIC::INT32 && |
2724 previous_overall == BinaryOpIC::INT32) { | 2722 previous_overall == BinaryOpIC::INT32) { |
2725 if (new_left == previous_left && new_right == previous_right) { | 2723 if (new_left == previous_left && new_right == previous_right) { |
2726 result_type = BinaryOpIC::NUMBER; | 2724 result_type = BinaryOpIC::NUMBER; |
2727 } | 2725 } |
2728 } | 2726 } |
2729 } | 2727 } |
2730 | 2728 |
2731 BinaryOpStub stub(key, new_left, new_right, result_type, | 2729 BinaryOpStub stub(key, new_left, new_right, result_type, new_fixed_right_arg); |
2732 new_has_fixed_right_arg, new_fixed_right_arg_value); | |
2733 Handle<Code> code = stub.GetCode(isolate); | 2730 Handle<Code> code = stub.GetCode(isolate); |
2734 if (!code.is_null()) { | 2731 if (!code.is_null()) { |
2735 #ifdef DEBUG | 2732 #ifdef DEBUG |
2736 if (FLAG_trace_ic) { | 2733 if (FLAG_trace_ic) { |
2737 PrintF("[BinaryOpIC in "); | 2734 PrintF("[BinaryOpIC in "); |
2738 JavaScriptFrame::PrintTop(isolate, stdout, false, true); | 2735 JavaScriptFrame::PrintTop(isolate, stdout, false, true); |
2739 PrintF(" "); | 2736 PrintF(" "); |
2740 TraceBinaryOp(previous_left, previous_right, previous_has_fixed_right_arg, | 2737 TraceBinaryOp(previous_left, previous_right, previous_fixed_right_arg, |
2741 previous_fixed_right_arg_value, previous_result); | 2738 previous_result); |
2742 PrintF(" => "); | 2739 PrintF(" => "); |
2743 TraceBinaryOp(new_left, new_right, new_has_fixed_right_arg, | 2740 TraceBinaryOp(new_left, new_right, new_fixed_right_arg, result_type); |
2744 new_fixed_right_arg_value, result_type); | |
2745 PrintF(" #%s @ %p]\n", Token::Name(op), static_cast<void*>(*code)); | 2741 PrintF(" #%s @ %p]\n", Token::Name(op), static_cast<void*>(*code)); |
2746 } | 2742 } |
2747 #endif | 2743 #endif |
2748 BinaryOpIC ic(isolate); | 2744 BinaryOpIC ic(isolate); |
2749 ic.patch(*code); | 2745 ic.patch(*code); |
2750 | 2746 |
2751 // Activate inlined smi code. | 2747 // Activate inlined smi code. |
2752 if (previous_overall == BinaryOpIC::UNINITIALIZED) { | 2748 if (previous_overall == BinaryOpIC::UNINITIALIZED) { |
2753 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); | 2749 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); |
2754 } | 2750 } |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3136 #undef ADDR | 3132 #undef ADDR |
3137 }; | 3133 }; |
3138 | 3134 |
3139 | 3135 |
3140 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 3136 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
3141 return IC_utilities[id]; | 3137 return IC_utilities[id]; |
3142 } | 3138 } |
3143 | 3139 |
3144 | 3140 |
3145 } } // namespace v8::internal | 3141 } } // namespace v8::internal |
OLD | NEW |