Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 12315005: Constant fold math and string operations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: made ctors private Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "double.h"
30 #include "factory.h" 31 #include "factory.h"
31 #include "hydrogen.h" 32 #include "hydrogen.h"
32 33
33 #if V8_TARGET_ARCH_IA32 34 #if V8_TARGET_ARCH_IA32
34 #include "ia32/lithium-ia32.h" 35 #include "ia32/lithium-ia32.h"
35 #elif V8_TARGET_ARCH_X64 36 #elif V8_TARGET_ARCH_X64
36 #include "x64/lithium-x64.h" 37 #include "x64/lithium-x64.h"
37 #elif V8_TARGET_ARCH_ARM 38 #elif V8_TARGET_ARCH_ARM
38 #include "arm/lithium-arm.h" 39 #include "arm/lithium-arm.h"
39 #elif V8_TARGET_ARCH_MIPS 40 #elif V8_TARGET_ARCH_MIPS
(...skipping 2704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 2745
2745 2746
2746 #define H_CONSTANT_INT32(val) \ 2747 #define H_CONSTANT_INT32(val) \
2747 new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \ 2748 new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \
2748 Representation::Integer32()) 2749 Representation::Integer32())
2749 #define H_CONSTANT_DOUBLE(val) \ 2750 #define H_CONSTANT_DOUBLE(val) \
2750 new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \ 2751 new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \
2751 Representation::Double()) 2752 Representation::Double())
2752 2753
2753 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ 2754 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \
2754 HInstruction* HInstr::New##HInstr(Zone* zone, \ 2755 HInstruction* HInstr::New( \
2755 HValue* context, \ 2756 Zone* zone, HValue* context, HValue* left, HValue* right) { \
2756 HValue* left, \ 2757 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \
2757 HValue* right) { \
2758 if (left->IsConstant() && right->IsConstant()) { \
2759 HConstant* c_left = HConstant::cast(left); \ 2758 HConstant* c_left = HConstant::cast(left); \
2760 HConstant* c_right = HConstant::cast(right); \ 2759 HConstant* c_right = HConstant::cast(right); \
2761 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ 2760 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
2762 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \ 2761 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \
2763 if (TypeInfo::IsInt32Double(double_res)) { \ 2762 if (TypeInfo::IsInt32Double(double_res)) { \
2764 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); \ 2763 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); \
2765 } \ 2764 } \
2766 return H_CONSTANT_DOUBLE(double_res); \ 2765 return H_CONSTANT_DOUBLE(double_res); \
2767 } \ 2766 } \
2768 } \ 2767 } \
2769 return new(zone) HInstr(context, left, right); \ 2768 return new(zone) HInstr(context, left, right); \
2770 } 2769 }
2771 2770
2772 2771
2773 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +) 2772 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +)
2774 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *) 2773 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *)
2775 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -) 2774 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -)
2776 2775
2777 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR 2776 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR
2778 2777
2779 2778
2780 HInstruction* HMod::NewHMod(Zone* zone, 2779 HInstruction* HStringAdd::New(
2781 HValue* context, 2780 Zone* zone, HValue* context, HValue* left, HValue* right) {
2782 HValue* left, 2781 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2783 HValue* right) { 2782 HConstant* c_right = HConstant::cast(right);
2784 if (left->IsConstant() && right->IsConstant()) { 2783 HConstant* c_left = HConstant::cast(left);
2784 if (c_left->HasStringValue() && c_right->HasStringValue()) {
2785 return new(zone) HConstant(FACTORY->NewConsString(c_left->StringValue(),
2786 c_right->StringValue()),
2787 Representation::Tagged());
2788 }
2789 }
2790 return new(zone) HStringAdd(context, left, right);
2791 }
2792
2793
2794 HInstruction* HStringCharFromCode::New(
2795 Zone* zone, HValue* context, HValue* char_code) {
2796 if (FLAG_fold_constants && char_code->IsConstant()) {
2797 HConstant* c_code = HConstant::cast(char_code);
2798 if (c_code->HasNumberValue()) {
2799 if (isfinite(c_code->DoubleValue())) {
2800 uint32_t code = c_code->NumberValueAsInteger32() & 0xffff;
2801 return new(zone) HConstant(LookupSingleCharacterStringFromCode(code),
2802 Representation::Tagged());
2803 }
2804 return new(zone) HConstant(FACTORY->empty_string(),
2805 Representation::Tagged());
2806 }
2807 }
2808 return new(zone) HStringCharFromCode(context, char_code);
2809 }
2810
2811
2812 HInstruction* HStringLength::New(Zone* zone, HValue* string) {
2813 if (FLAG_fold_constants && string->IsConstant()) {
2814 HConstant* c_string = HConstant::cast(string);
2815 if (c_string->HasStringValue()) {
2816 return H_CONSTANT_INT32(c_string->StringValue()->length());
2817 }
2818 }
2819 return new(zone) HStringLength(string);
2820 }
2821
2822
2823 HInstruction* HUnaryMathOperation::New(
2824 Zone* zone, HValue* context, HValue* value, BuiltinFunctionId op) {
2825 do {
2826 if (!FLAG_fold_constants) break;
2827 if (!value->IsConstant()) break;
2828 HConstant* constant = HConstant::cast(value);
2829 if (!constant->HasNumberValue()) break;
2830 double d = constant->DoubleValue();
2831 if (isnan(d)) { // NaN poisons everything.
2832 return H_CONSTANT_DOUBLE(OS::nan_value());
2833 }
2834 if (isinf(d)) { // +Infinity and -Infinity.
2835 switch (op) {
2836 case kMathSin:
2837 case kMathCos:
2838 case kMathTan:
2839 return H_CONSTANT_DOUBLE(OS::nan_value());
2840 case kMathExp:
2841 return H_CONSTANT_DOUBLE((d > 0.0) ? d : 0.0);
2842 case kMathLog:
2843 case kMathSqrt:
2844 return H_CONSTANT_DOUBLE((d > 0.0) ? d : OS::nan_value());
2845 case kMathPowHalf:
2846 case kMathAbs:
2847 return H_CONSTANT_DOUBLE((d > 0.0) ? d : -d);
2848 case kMathRound:
2849 case kMathFloor:
2850 return H_CONSTANT_DOUBLE(d);
2851 default:
2852 UNREACHABLE();
2853 break;
2854 }
2855 }
2856 switch (op) {
2857 case kMathSin:
2858 return H_CONSTANT_DOUBLE(fast_sin(d));
2859 case kMathCos:
2860 return H_CONSTANT_DOUBLE(fast_cos(d));
2861 case kMathTan:
2862 return H_CONSTANT_DOUBLE(fast_tan(d));
2863 case kMathExp:
2864 return H_CONSTANT_DOUBLE(fast_exp(d));
2865 case kMathLog:
2866 return H_CONSTANT_DOUBLE(fast_log(d));
2867 case kMathSqrt:
2868 return H_CONSTANT_DOUBLE(fast_sqrt(d));
2869 case kMathPowHalf:
2870 return H_CONSTANT_DOUBLE(power_double_double(d, 0.5));
2871 case kMathAbs:
2872 return H_CONSTANT_DOUBLE((d >= 0.0) ? d + 0.0 : -d);
2873 case kMathRound:
2874 // -0.5 .. -0.0 round to -0.0.
2875 if ((d >= -0.5 && Double(d).Sign() < 0)) return H_CONSTANT_DOUBLE(-0.0);
2876 // Doubles are represented as Significant * 2 ^ Exponent. If the
2877 // Exponent is not negative, the double value is already an integer.
2878 if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d);
2879 return H_CONSTANT_DOUBLE(floor(d + 0.5));
2880 case kMathFloor:
2881 return H_CONSTANT_DOUBLE(floor(d));
2882 default:
2883 UNREACHABLE();
2884 break;
2885 }
2886 } while (false);
2887 return new(zone) HUnaryMathOperation(context, value, op);
2888 }
2889
2890
2891 HInstruction* HPower::New(Zone* zone, HValue* left, HValue* right) {
2892 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2893 HConstant* c_left = HConstant::cast(left);
2894 HConstant* c_right = HConstant::cast(right);
2895 if (c_left->HasNumberValue() && c_right->HasNumberValue()) {
2896 double result = power_helper(c_left->DoubleValue(),
2897 c_right->DoubleValue());
2898 return H_CONSTANT_DOUBLE(isnan(result) ? OS::nan_value() : result);
2899 }
2900 }
2901 return new(zone) HPower(left, right);
2902 }
2903
2904
2905 HInstruction* HMathMinMax::New(
2906 Zone* zone, HValue* context, HValue* left, HValue* right, Operation op) {
2907 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2908 HConstant* c_left = HConstant::cast(left);
2909 HConstant* c_right = HConstant::cast(right);
2910 if (c_left->HasNumberValue() && c_right->HasNumberValue()) {
2911 double d_left = c_left->DoubleValue();
2912 double d_right = c_right->DoubleValue();
2913 if (op == kMathMin) {
2914 if (d_left > d_right) return H_CONSTANT_DOUBLE(d_right);
2915 if (d_left < d_right) return H_CONSTANT_DOUBLE(d_left);
2916 if (d_left == d_right) {
2917 // Handle +0 and -0.
2918 return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_left
2919 : d_right);
2920 }
2921 } else {
2922 if (d_left < d_right) return H_CONSTANT_DOUBLE(d_right);
2923 if (d_left > d_right) return H_CONSTANT_DOUBLE(d_left);
2924 if (d_left == d_right) {
2925 // Handle +0 and -0.
2926 return H_CONSTANT_DOUBLE((Double(d_left).Sign() == -1) ? d_right
2927 : d_left);
2928 }
2929 }
2930 // All comparisons failed, must be NaN.
2931 return H_CONSTANT_DOUBLE(OS::nan_value());
2932 }
2933 }
2934 return new(zone) HMathMinMax(context, left, right, op);
2935 }
2936
2937
2938 HInstruction* HMod::New(
2939 Zone* zone, HValue* context, HValue* left, HValue* right) {
2940 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2785 HConstant* c_left = HConstant::cast(left); 2941 HConstant* c_left = HConstant::cast(left);
2786 HConstant* c_right = HConstant::cast(right); 2942 HConstant* c_right = HConstant::cast(right);
2787 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { 2943 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
2788 int32_t dividend = c_left->Integer32Value(); 2944 int32_t dividend = c_left->Integer32Value();
2789 int32_t divisor = c_right->Integer32Value(); 2945 int32_t divisor = c_right->Integer32Value();
2790 if (divisor != 0) { 2946 if (divisor != 0) {
2791 int32_t res = dividend % divisor; 2947 int32_t res = dividend % divisor;
2792 if ((res == 0) && (dividend < 0)) { 2948 if ((res == 0) && (dividend < 0)) {
2793 return H_CONSTANT_DOUBLE(-0.0); 2949 return H_CONSTANT_DOUBLE(-0.0);
2794 } 2950 }
2795 return H_CONSTANT_INT32(res); 2951 return H_CONSTANT_INT32(res);
2796 } 2952 }
2797 } 2953 }
2798 } 2954 }
2799 return new(zone) HMod(context, left, right); 2955 return new(zone) HMod(context, left, right);
2800 } 2956 }
2801 2957
2802 2958
2803 HInstruction* HDiv::NewHDiv(Zone* zone, 2959 HInstruction* HDiv::New(
2804 HValue* context, 2960 Zone* zone, HValue* context, HValue* left, HValue* right) {
2805 HValue* left,
2806 HValue* right) {
2807 // If left and right are constant values, try to return a constant value. 2961 // If left and right are constant values, try to return a constant value.
2808 if (left->IsConstant() && right->IsConstant()) { 2962 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2809 HConstant* c_left = HConstant::cast(left); 2963 HConstant* c_left = HConstant::cast(left);
2810 HConstant* c_right = HConstant::cast(right); 2964 HConstant* c_right = HConstant::cast(right);
2811 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { 2965 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
2812 if (c_right->DoubleValue() != 0) { 2966 if (c_right->DoubleValue() != 0) {
2813 double double_res = c_left->DoubleValue() / c_right->DoubleValue(); 2967 double double_res = c_left->DoubleValue() / c_right->DoubleValue();
2814 if (TypeInfo::IsInt32Double(double_res)) { 2968 if (TypeInfo::IsInt32Double(double_res)) {
2815 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); 2969 return H_CONSTANT_INT32(static_cast<int32_t>(double_res));
2816 } 2970 }
2817 return H_CONSTANT_DOUBLE(double_res); 2971 return H_CONSTANT_DOUBLE(double_res);
2972 } else {
2973 int sign = Double(c_left->DoubleValue()).Sign() *
2974 Double(c_right->DoubleValue()).Sign(); // Right could be -0.
2975 return H_CONSTANT_DOUBLE(sign * V8_INFINITY);
2818 } 2976 }
2819 } 2977 }
2820 } 2978 }
2821 return new(zone) HDiv(context, left, right); 2979 return new(zone) HDiv(context, left, right);
2822 } 2980 }
2823 2981
2824 2982
2825 HInstruction* HBitwise::NewHBitwise(Zone* zone, 2983 HInstruction* HBitwise::New(
2826 Token::Value op, 2984 Zone* zone, Token::Value op, HValue* context, HValue* left, HValue* right) {
2827 HValue* context, 2985 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2828 HValue* left,
2829 HValue* right) {
2830 if (left->IsConstant() && right->IsConstant()) {
2831 HConstant* c_left = HConstant::cast(left); 2986 HConstant* c_left = HConstant::cast(left);
2832 HConstant* c_right = HConstant::cast(right); 2987 HConstant* c_right = HConstant::cast(right);
2833 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { 2988 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
2834 int32_t result; 2989 int32_t result;
2835 int32_t v_left = c_left->NumberValueAsInteger32(); 2990 int32_t v_left = c_left->NumberValueAsInteger32();
2836 int32_t v_right = c_right->NumberValueAsInteger32(); 2991 int32_t v_right = c_right->NumberValueAsInteger32();
2837 switch (op) { 2992 switch (op) {
2838 case Token::BIT_XOR: 2993 case Token::BIT_XOR:
2839 result = v_left ^ v_right; 2994 result = v_left ^ v_right;
2840 break; 2995 break;
2841 case Token::BIT_AND: 2996 case Token::BIT_AND:
2842 result = v_left & v_right; 2997 result = v_left & v_right;
2843 break; 2998 break;
2844 case Token::BIT_OR: 2999 case Token::BIT_OR:
2845 result = v_left | v_right; 3000 result = v_left | v_right;
2846 break; 3001 break;
2847 default: 3002 default:
2848 result = 0; // Please the compiler. 3003 result = 0; // Please the compiler.
2849 UNREACHABLE(); 3004 UNREACHABLE();
2850 } 3005 }
2851 return H_CONSTANT_INT32(result); 3006 return H_CONSTANT_INT32(result);
2852 } 3007 }
2853 } 3008 }
2854 return new(zone) HBitwise(op, context, left, right); 3009 return new(zone) HBitwise(op, context, left, right);
2855 } 3010 }
2856 3011
2857 3012
2858 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \ 3013 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \
2859 HInstruction* HInstr::New##HInstr(Zone* zone, \ 3014 HInstruction* HInstr::New( \
2860 HValue* context, \ 3015 Zone* zone, HValue* context, HValue* left, HValue* right) { \
2861 HValue* left, \ 3016 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) { \
2862 HValue* right) { \
2863 if (left->IsConstant() && right->IsConstant()) { \
2864 HConstant* c_left = HConstant::cast(left); \ 3017 HConstant* c_left = HConstant::cast(left); \
2865 HConstant* c_right = HConstant::cast(right); \ 3018 HConstant* c_right = HConstant::cast(right); \
2866 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ 3019 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
2867 return H_CONSTANT_INT32(result); \ 3020 return H_CONSTANT_INT32(result); \
2868 } \ 3021 } \
2869 } \ 3022 } \
2870 return new(zone) HInstr(context, left, right); \ 3023 return new(zone) HInstr(context, left, right); \
2871 } 3024 }
2872 3025
2873 3026
2874 DEFINE_NEW_H_BITWISE_INSTR(HSar, 3027 DEFINE_NEW_H_BITWISE_INSTR(HSar,
2875 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f)) 3028 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f))
2876 DEFINE_NEW_H_BITWISE_INSTR(HShl, 3029 DEFINE_NEW_H_BITWISE_INSTR(HShl,
2877 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f)) 3030 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f))
2878 3031
2879 #undef DEFINE_NEW_H_BITWISE_INSTR 3032 #undef DEFINE_NEW_H_BITWISE_INSTR
2880 3033
2881 3034
2882 HInstruction* HShr::NewHShr(Zone* zone, 3035 HInstruction* HShr::New(
2883 HValue* context, 3036 Zone* zone, HValue* context, HValue* left, HValue* right) {
2884 HValue* left, 3037 if (FLAG_fold_constants && left->IsConstant() && right->IsConstant()) {
2885 HValue* right) {
2886 if (left->IsConstant() && right->IsConstant()) {
2887 HConstant* c_left = HConstant::cast(left); 3038 HConstant* c_left = HConstant::cast(left);
2888 HConstant* c_right = HConstant::cast(right); 3039 HConstant* c_right = HConstant::cast(right);
2889 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { 3040 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
2890 int32_t left_val = c_left->NumberValueAsInteger32(); 3041 int32_t left_val = c_left->NumberValueAsInteger32();
2891 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f; 3042 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f;
2892 if ((right_val == 0) && (left_val < 0)) { 3043 if ((right_val == 0) && (left_val < 0)) {
2893 return H_CONSTANT_DOUBLE( 3044 return H_CONSTANT_DOUBLE(
2894 static_cast<double>(static_cast<uint32_t>(left_val))); 3045 static_cast<double>(static_cast<uint32_t>(left_val)));
2895 } 3046 }
2896 return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val); 3047 return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 3211
3061 3212
3062 void HCheckFunction::Verify() { 3213 void HCheckFunction::Verify() {
3063 HInstruction::Verify(); 3214 HInstruction::Verify();
3064 ASSERT(HasNoUses()); 3215 ASSERT(HasNoUses());
3065 } 3216 }
3066 3217
3067 #endif 3218 #endif
3068 3219
3069 } } // namespace v8::internal 3220 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698