Chromium Code Reviews| 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 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2565 Token::Value op) { | 2565 Token::Value op) { |
| 2566 BinaryOpIC::TypeInfo new_type = TypeInfoFromValue(value, op); | 2566 BinaryOpIC::TypeInfo new_type = TypeInfoFromValue(value, op); |
| 2567 if (old_type == BinaryOpIC::STRING) { | 2567 if (old_type == BinaryOpIC::STRING) { |
| 2568 if (new_type == BinaryOpIC::STRING) return new_type; | 2568 if (new_type == BinaryOpIC::STRING) return new_type; |
| 2569 return BinaryOpIC::GENERIC; | 2569 return BinaryOpIC::GENERIC; |
| 2570 } | 2570 } |
| 2571 return Max(old_type, new_type); | 2571 return Max(old_type, new_type); |
| 2572 } | 2572 } |
| 2573 | 2573 |
| 2574 | 2574 |
| 2575 static bool TryToInt32(Handle<Object> object, int32_t* result) { | |
| 2576 if (object->IsSmi()) { | |
| 2577 *result = Smi::cast(*object)->value(); | |
| 2578 return true; | |
| 2579 } | |
| 2580 if (object->IsHeapNumber()) { | |
| 2581 double value = HeapNumber::cast(*object)->value(); | |
| 2582 if (TypeInfo::IsInt32Double(value)) { | |
| 2583 *result = static_cast<int32_t>(value); | |
| 2584 return true; | |
| 2585 } | |
| 2586 } | |
| 2587 return false; | |
| 2588 } | |
| 2589 | |
| 2590 | |
| 2575 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { | 2591 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { |
| 2576 ASSERT(args.length() == 3); | 2592 ASSERT(args.length() == 3); |
| 2577 | 2593 |
| 2578 HandleScope scope(isolate); | 2594 HandleScope scope(isolate); |
| 2579 Handle<Object> left = args.at<Object>(0); | 2595 Handle<Object> left = args.at<Object>(0); |
| 2580 Handle<Object> right = args.at<Object>(1); | 2596 Handle<Object> right = args.at<Object>(1); |
| 2581 int key = args.smi_at(2); | 2597 int key = args.smi_at(2); |
| 2582 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); | 2598 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); |
| 2599 | |
| 2600 bool previous_has_fixed_right_arg = | |
| 2601 BinaryOpStub::decode_has_fixed_right_arg_from_minor_key(key); | |
| 2602 int previous_fixed_right_arg_value = | |
| 2603 BinaryOpStub::decode_fixed_right_arg_value_from_minor_key(key); | |
| 2604 | |
| 2605 int32_t value; | |
| 2606 bool new_has_fixed_right_arg = | |
| 2607 op == Token::MOD && | |
| 2608 TryToInt32(right, &value) && | |
| 2609 BinaryOpStub::can_encode_arg_value(value) && | |
| 2610 (!previous_has_fixed_right_arg || | |
|
Jakob Kummerow
2013/05/23 12:05:43
I still disagree with this condition, as discussed
Sven Panne
2013/05/23 14:39:20
Ooops, forgot that. Fixed.
| |
| 2611 previous_fixed_right_arg_value == value); | |
| 2612 int32_t new_fixed_right_arg_value = new_has_fixed_right_arg ? value : 1; | |
| 2613 | |
| 2583 BinaryOpIC::TypeInfo previous_left, previous_right, unused_previous_result; | 2614 BinaryOpIC::TypeInfo previous_left, previous_right, unused_previous_result; |
| 2584 BinaryOpStub::decode_types_from_minor_key( | 2615 BinaryOpStub::decode_types_from_minor_key( |
| 2585 key, &previous_left, &previous_right, &unused_previous_result); | 2616 key, &previous_left, &previous_right, &unused_previous_result); |
| 2586 | 2617 |
| 2587 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); | 2618 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); |
| 2588 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); | 2619 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); |
| 2589 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; | 2620 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; |
| 2590 | 2621 |
| 2591 // STRING is only used for ADD operations. | 2622 // STRING is only used for ADD operations. |
| 2592 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && | 2623 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && |
| 2593 op != Token::ADD) { | 2624 op != Token::ADD) { |
| 2594 new_left = new_right = BinaryOpIC::GENERIC; | 2625 new_left = new_right = BinaryOpIC::GENERIC; |
| 2595 } | 2626 } |
| 2596 | 2627 |
| 2597 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); | 2628 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); |
| 2598 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); | 2629 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); |
| 2599 | 2630 |
| 2600 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { | 2631 if (previous_has_fixed_right_arg == new_has_fixed_right_arg) { |
| 2601 if (op == Token::DIV || | 2632 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { |
| 2602 op == Token::MUL || | 2633 if (op == Token::DIV || |
| 2603 op == Token::SHR || | 2634 op == Token::MUL || |
| 2604 kSmiValueSize == 32) { | 2635 op == Token::SHR || |
| 2605 // Arithmetic on two Smi inputs has yielded a heap number. | 2636 kSmiValueSize == 32) { |
| 2606 // That is the only way to get here from the Smi stub. | 2637 // Arithmetic on two Smi inputs has yielded a heap number. |
| 2607 // With 32-bit Smis, all overflows give heap numbers, but with | 2638 // That is the only way to get here from the Smi stub. |
| 2608 // 31-bit Smis, most operations overflow to int32 results. | 2639 // With 32-bit Smis, all overflows give heap numbers, but with |
| 2609 result_type = BinaryOpIC::NUMBER; | 2640 // 31-bit Smis, most operations overflow to int32 results. |
| 2610 } else { | 2641 result_type = BinaryOpIC::NUMBER; |
| 2611 // Other operations on SMIs that overflow yield int32s. | 2642 } else { |
| 2612 result_type = BinaryOpIC::INT32; | 2643 // Other operations on SMIs that overflow yield int32s. |
| 2644 result_type = BinaryOpIC::INT32; | |
| 2645 } | |
| 2613 } | 2646 } |
| 2614 } | 2647 if (new_overall == BinaryOpIC::INT32 && |
| 2615 if (new_overall == BinaryOpIC::INT32 && | 2648 previous_overall == BinaryOpIC::INT32) { |
| 2616 previous_overall == BinaryOpIC::INT32) { | 2649 if (new_left == previous_left && new_right == previous_right) { |
| 2617 if (new_left == previous_left && new_right == previous_right) { | 2650 result_type = BinaryOpIC::NUMBER; |
| 2618 result_type = BinaryOpIC::NUMBER; | 2651 } |
| 2619 } | 2652 } |
| 2620 } | 2653 } |
| 2621 | 2654 |
| 2622 BinaryOpStub stub(key, new_left, new_right, result_type); | 2655 BinaryOpStub stub(key, new_left, new_right, result_type, |
| 2656 new_has_fixed_right_arg, new_fixed_right_arg_value); | |
| 2623 Handle<Code> code = stub.GetCode(isolate); | 2657 Handle<Code> code = stub.GetCode(isolate); |
| 2624 if (!code.is_null()) { | 2658 if (!code.is_null()) { |
| 2625 #ifdef DEBUG | 2659 #ifdef DEBUG |
| 2626 if (FLAG_trace_ic) { | 2660 if (FLAG_trace_ic) { |
| 2627 PrintF("[BinaryOpIC in "); | 2661 PrintF("[BinaryOpIC in "); |
| 2628 JavaScriptFrame::PrintTop(isolate, stdout, false, true); | 2662 JavaScriptFrame::PrintTop(isolate, stdout, false, true); |
| 2629 PrintF(" ((%s+%s)->((%s+%s)->%s))#%s @ %p]\n", | 2663 PrintF(" ((%s+%s", |
|
Sven Panne
2013/05/23 14:39:20
While debugging this, I cleaned this trace output
| |
| 2630 BinaryOpIC::GetName(previous_left), | 2664 BinaryOpIC::GetName(previous_left), |
| 2631 BinaryOpIC::GetName(previous_right), | 2665 BinaryOpIC::GetName(previous_right)); |
| 2666 if (previous_has_fixed_right_arg) { | |
| 2667 PrintF("{%d}", previous_fixed_right_arg_value); | |
| 2668 } | |
| 2669 PrintF(")->((%s+%s", | |
| 2632 BinaryOpIC::GetName(new_left), | 2670 BinaryOpIC::GetName(new_left), |
| 2633 BinaryOpIC::GetName(new_right), | 2671 BinaryOpIC::GetName(new_right)); |
| 2672 if (new_has_fixed_right_arg) { | |
| 2673 PrintF("{%d}", new_fixed_right_arg_value); | |
| 2674 } | |
| 2675 PrintF(")->%s))#%s @ %p]\n", | |
| 2634 BinaryOpIC::GetName(result_type), | 2676 BinaryOpIC::GetName(result_type), |
| 2635 Token::Name(op), | 2677 Token::Name(op), |
| 2636 static_cast<void*>(*code)); | 2678 static_cast<void*>(*code)); |
| 2637 } | 2679 } |
| 2638 #endif | 2680 #endif |
| 2639 BinaryOpIC ic(isolate); | 2681 BinaryOpIC ic(isolate); |
| 2640 ic.patch(*code); | 2682 ic.patch(*code); |
| 2641 | 2683 |
| 2642 // Activate inlined smi code. | 2684 // Activate inlined smi code. |
| 2643 if (previous_overall == BinaryOpIC::UNINITIALIZED) { | 2685 if (previous_overall == BinaryOpIC::UNINITIALIZED) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3002 #undef ADDR | 3044 #undef ADDR |
| 3003 }; | 3045 }; |
| 3004 | 3046 |
| 3005 | 3047 |
| 3006 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 3048 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 3007 return IC_utilities[id]; | 3049 return IC_utilities[id]; |
| 3008 } | 3050 } |
| 3009 | 3051 |
| 3010 | 3052 |
| 3011 } } // namespace v8::internal | 3053 } } // namespace v8::internal |
| OLD | NEW |