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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 | 1140 |
1141 const char* HUnaryMathOperation::OpName() const { | 1141 const char* HUnaryMathOperation::OpName() const { |
1142 switch (op()) { | 1142 switch (op()) { |
1143 case kMathFloor: return "floor"; | 1143 case kMathFloor: return "floor"; |
1144 case kMathRound: return "round"; | 1144 case kMathRound: return "round"; |
1145 case kMathAbs: return "abs"; | 1145 case kMathAbs: return "abs"; |
1146 case kMathLog: return "log"; | 1146 case kMathLog: return "log"; |
1147 case kMathExp: return "exp"; | 1147 case kMathExp: return "exp"; |
1148 case kMathSqrt: return "sqrt"; | 1148 case kMathSqrt: return "sqrt"; |
1149 case kMathPowHalf: return "pow-half"; | 1149 case kMathPowHalf: return "pow-half"; |
| 1150 case kMathClz32: return "clz32"; |
1150 default: | 1151 default: |
1151 UNREACHABLE(); | 1152 UNREACHABLE(); |
1152 return NULL; | 1153 return NULL; |
1153 } | 1154 } |
1154 } | 1155 } |
1155 | 1156 |
1156 | 1157 |
1157 Range* HUnaryMathOperation::InferRange(Zone* zone) { | 1158 Range* HUnaryMathOperation::InferRange(Zone* zone) { |
1158 Representation r = representation(); | 1159 Representation r = representation(); |
| 1160 if (op() == kMathClz32) return new(zone) Range(0, 32); |
1159 if (r.IsSmiOrInteger32() && value()->HasRange()) { | 1161 if (r.IsSmiOrInteger32() && value()->HasRange()) { |
1160 if (op() == kMathAbs) { | 1162 if (op() == kMathAbs) { |
1161 int upper = value()->range()->upper(); | 1163 int upper = value()->range()->upper(); |
1162 int lower = value()->range()->lower(); | 1164 int lower = value()->range()->lower(); |
1163 bool spans_zero = value()->range()->CanBeZero(); | 1165 bool spans_zero = value()->range()->CanBeZero(); |
1164 // Math.abs(kMinInt) overflows its representation, on which the | 1166 // Math.abs(kMinInt) overflows its representation, on which the |
1165 // instruction deopts. Hence clamp it to kMaxInt. | 1167 // instruction deopts. Hence clamp it to kMaxInt. |
1166 int abs_upper = upper == kMinInt ? kMaxInt : abs(upper); | 1168 int abs_upper = upper == kMinInt ? kMaxInt : abs(upper); |
1167 int abs_lower = lower == kMinInt ? kMaxInt : abs(lower); | 1169 int abs_lower = lower == kMinInt ? kMaxInt : abs(lower); |
1168 Range* result = | 1170 Range* result = |
(...skipping 2749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3918 return H_CONSTANT_DOUBLE((d > 0.0) ? d : 0.0); | 3920 return H_CONSTANT_DOUBLE((d > 0.0) ? d : 0.0); |
3919 case kMathLog: | 3921 case kMathLog: |
3920 case kMathSqrt: | 3922 case kMathSqrt: |
3921 return H_CONSTANT_DOUBLE((d > 0.0) ? d : OS::nan_value()); | 3923 return H_CONSTANT_DOUBLE((d > 0.0) ? d : OS::nan_value()); |
3922 case kMathPowHalf: | 3924 case kMathPowHalf: |
3923 case kMathAbs: | 3925 case kMathAbs: |
3924 return H_CONSTANT_DOUBLE((d > 0.0) ? d : -d); | 3926 return H_CONSTANT_DOUBLE((d > 0.0) ? d : -d); |
3925 case kMathRound: | 3927 case kMathRound: |
3926 case kMathFloor: | 3928 case kMathFloor: |
3927 return H_CONSTANT_DOUBLE(d); | 3929 return H_CONSTANT_DOUBLE(d); |
| 3930 case kMathClz32: |
| 3931 return H_CONSTANT_INT(32); |
3928 default: | 3932 default: |
3929 UNREACHABLE(); | 3933 UNREACHABLE(); |
3930 break; | 3934 break; |
3931 } | 3935 } |
3932 } | 3936 } |
3933 switch (op) { | 3937 switch (op) { |
3934 case kMathExp: | 3938 case kMathExp: |
3935 return H_CONSTANT_DOUBLE(fast_exp(d)); | 3939 return H_CONSTANT_DOUBLE(fast_exp(d)); |
3936 case kMathLog: | 3940 case kMathLog: |
3937 return H_CONSTANT_DOUBLE(std::log(d)); | 3941 return H_CONSTANT_DOUBLE(std::log(d)); |
3938 case kMathSqrt: | 3942 case kMathSqrt: |
3939 return H_CONSTANT_DOUBLE(fast_sqrt(d)); | 3943 return H_CONSTANT_DOUBLE(fast_sqrt(d)); |
3940 case kMathPowHalf: | 3944 case kMathPowHalf: |
3941 return H_CONSTANT_DOUBLE(power_double_double(d, 0.5)); | 3945 return H_CONSTANT_DOUBLE(power_double_double(d, 0.5)); |
3942 case kMathAbs: | 3946 case kMathAbs: |
3943 return H_CONSTANT_DOUBLE((d >= 0.0) ? d + 0.0 : -d); | 3947 return H_CONSTANT_DOUBLE((d >= 0.0) ? d + 0.0 : -d); |
3944 case kMathRound: | 3948 case kMathRound: |
3945 // -0.5 .. -0.0 round to -0.0. | 3949 // -0.5 .. -0.0 round to -0.0. |
3946 if ((d >= -0.5 && Double(d).Sign() < 0)) return H_CONSTANT_DOUBLE(-0.0); | 3950 if ((d >= -0.5 && Double(d).Sign() < 0)) return H_CONSTANT_DOUBLE(-0.0); |
3947 // Doubles are represented as Significant * 2 ^ Exponent. If the | 3951 // Doubles are represented as Significant * 2 ^ Exponent. If the |
3948 // Exponent is not negative, the double value is already an integer. | 3952 // Exponent is not negative, the double value is already an integer. |
3949 if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d); | 3953 if (Double(d).Exponent() >= 0) return H_CONSTANT_DOUBLE(d); |
3950 return H_CONSTANT_DOUBLE(std::floor(d + 0.5)); | 3954 return H_CONSTANT_DOUBLE(std::floor(d + 0.5)); |
3951 case kMathFloor: | 3955 case kMathFloor: |
3952 return H_CONSTANT_DOUBLE(std::floor(d)); | 3956 return H_CONSTANT_DOUBLE(std::floor(d)); |
| 3957 case kMathClz32: { |
| 3958 uint32_t i = static_cast<uint32_t>(constant->Integer32Value()); |
| 3959 return H_CONSTANT_INT( |
| 3960 (i == 0) ? 32 : CompilerIntrinsics::CountLeadingZeros(i)); |
| 3961 } |
3953 default: | 3962 default: |
3954 UNREACHABLE(); | 3963 UNREACHABLE(); |
3955 break; | 3964 break; |
3956 } | 3965 } |
3957 } while (false); | 3966 } while (false); |
3958 return new(zone) HUnaryMathOperation(context, value, op); | 3967 return new(zone) HUnaryMathOperation(context, value, op); |
3959 } | 3968 } |
3960 | 3969 |
3961 | 3970 |
3962 HInstruction* HPower::New(Zone* zone, | 3971 HInstruction* HPower::New(Zone* zone, |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4514 break; | 4523 break; |
4515 case kExternalMemory: | 4524 case kExternalMemory: |
4516 stream->Add("[external-memory]"); | 4525 stream->Add("[external-memory]"); |
4517 break; | 4526 break; |
4518 } | 4527 } |
4519 | 4528 |
4520 stream->Add("@%d", offset()); | 4529 stream->Add("@%d", offset()); |
4521 } | 4530 } |
4522 | 4531 |
4523 } } // namespace v8::internal | 4532 } } // namespace v8::internal |
OLD | NEW |