| 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 7743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7754 } | 7754 } |
| 7755 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(y); | 7755 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(y); |
| 7756 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 7756 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 7757 } | 7757 } |
| 7758 | 7758 |
| 7759 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) | 7759 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) |
| 7760 : StringCharacterStreamCompare(isolate->runtime_state(), x, y); | 7760 : StringCharacterStreamCompare(isolate->runtime_state(), x, y); |
| 7761 } | 7761 } |
| 7762 | 7762 |
| 7763 | 7763 |
| 7764 #define RUNTIME_UNARY_MATH(NAME) \ | 7764 #define RUNTIME_UNARY_MATH(Name, name) \ |
| 7765 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_##NAME) { \ | 7765 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math##Name) { \ |
| 7766 SealHandleScope shs(isolate); \ | 7766 SealHandleScope shs(isolate); \ |
| 7767 ASSERT(args.length() == 1); \ | 7767 ASSERT(args.length() == 1); \ |
| 7768 isolate->counters()->math_##NAME()->Increment(); \ | 7768 isolate->counters()->math_##name()->Increment(); \ |
| 7769 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \ | 7769 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \ |
| 7770 return isolate->heap()->AllocateHeapNumber(std::NAME(x)); \ | 7770 return isolate->heap()->AllocateHeapNumber(std::name(x)); \ |
| 7771 } | 7771 } |
| 7772 | 7772 |
| 7773 RUNTIME_UNARY_MATH(acos) | 7773 RUNTIME_UNARY_MATH(Acos, acos) |
| 7774 RUNTIME_UNARY_MATH(asin) | 7774 RUNTIME_UNARY_MATH(Asin, asin) |
| 7775 RUNTIME_UNARY_MATH(atan) | 7775 RUNTIME_UNARY_MATH(Atan, atan) |
| 7776 RUNTIME_UNARY_MATH(log) | 7776 RUNTIME_UNARY_MATH(Log, log) |
| 7777 #undef RUNTIME_UNARY_MATH | 7777 #undef RUNTIME_UNARY_MATH |
| 7778 | 7778 |
| 7779 | 7779 |
| 7780 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleHi) { | 7780 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleHi) { |
| 7781 SealHandleScope shs(isolate); | 7781 SealHandleScope shs(isolate); |
| 7782 ASSERT(args.length() == 1); | 7782 ASSERT(args.length() == 1); |
| 7783 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7783 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7784 uint64_t integer = double_to_uint64(x); | 7784 uint64_t integer = double_to_uint64(x); |
| 7785 integer = (integer >> 32) & 0xFFFFFFFFu; | 7785 integer = (integer >> 32) & 0xFFFFFFFFu; |
| 7786 return isolate->heap()->NumberFromDouble(static_cast<int32_t>(integer)); | 7786 return isolate->heap()->NumberFromDouble(static_cast<int32_t>(integer)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 7802 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); | 7802 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); |
| 7803 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); | 7803 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); |
| 7804 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; | 7804 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; |
| 7805 return isolate->heap()->AllocateHeapNumber(uint64_to_double(result)); | 7805 return isolate->heap()->AllocateHeapNumber(uint64_to_double(result)); |
| 7806 } | 7806 } |
| 7807 | 7807 |
| 7808 | 7808 |
| 7809 static const double kPiDividedBy4 = 0.78539816339744830962; | 7809 static const double kPiDividedBy4 = 0.78539816339744830962; |
| 7810 | 7810 |
| 7811 | 7811 |
| 7812 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) { | 7812 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathAtan2) { |
| 7813 SealHandleScope shs(isolate); | 7813 SealHandleScope shs(isolate); |
| 7814 ASSERT(args.length() == 2); | 7814 ASSERT(args.length() == 2); |
| 7815 isolate->counters()->math_atan2()->Increment(); | 7815 isolate->counters()->math_atan2()->Increment(); |
| 7816 | 7816 |
| 7817 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7817 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7818 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7818 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
| 7819 double result; | 7819 double result; |
| 7820 if (std::isinf(x) && std::isinf(y)) { | 7820 if (std::isinf(x) && std::isinf(y)) { |
| 7821 // Make sure that the result in case of two infinite arguments | 7821 // Make sure that the result in case of two infinite arguments |
| 7822 // is a multiple of Pi / 4. The sign of the result is determined | 7822 // is a multiple of Pi / 4. The sign of the result is determined |
| 7823 // by the first argument (x) and the sign of the second argument | 7823 // by the first argument (x) and the sign of the second argument |
| 7824 // determines the multiplier: one or three. | 7824 // determines the multiplier: one or three. |
| 7825 int multiplier = (x < 0) ? -1 : 1; | 7825 int multiplier = (x < 0) ? -1 : 1; |
| 7826 if (y < 0) multiplier *= 3; | 7826 if (y < 0) multiplier *= 3; |
| 7827 result = multiplier * kPiDividedBy4; | 7827 result = multiplier * kPiDividedBy4; |
| 7828 } else { | 7828 } else { |
| 7829 result = std::atan2(x, y); | 7829 result = std::atan2(x, y); |
| 7830 } | 7830 } |
| 7831 return isolate->heap()->AllocateHeapNumber(result); | 7831 return isolate->heap()->AllocateHeapNumber(result); |
| 7832 } | 7832 } |
| 7833 | 7833 |
| 7834 | 7834 |
| 7835 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_exp) { | 7835 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathExp) { |
| 7836 SealHandleScope shs(isolate); | 7836 SealHandleScope shs(isolate); |
| 7837 ASSERT(args.length() == 1); | 7837 ASSERT(args.length() == 1); |
| 7838 isolate->counters()->math_exp()->Increment(); | 7838 isolate->counters()->math_exp()->Increment(); |
| 7839 | 7839 |
| 7840 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7840 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7841 lazily_initialize_fast_exp(); | 7841 lazily_initialize_fast_exp(); |
| 7842 return isolate->heap()->NumberFromDouble(fast_exp(x)); | 7842 return isolate->heap()->NumberFromDouble(fast_exp(x)); |
| 7843 } | 7843 } |
| 7844 | 7844 |
| 7845 | 7845 |
| 7846 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_floor) { | 7846 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathFloor) { |
| 7847 SealHandleScope shs(isolate); | 7847 SealHandleScope shs(isolate); |
| 7848 ASSERT(args.length() == 1); | 7848 ASSERT(args.length() == 1); |
| 7849 isolate->counters()->math_floor()->Increment(); | 7849 isolate->counters()->math_floor()->Increment(); |
| 7850 | 7850 |
| 7851 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7851 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7852 return isolate->heap()->NumberFromDouble(std::floor(x)); | 7852 return isolate->heap()->NumberFromDouble(std::floor(x)); |
| 7853 } | 7853 } |
| 7854 | 7854 |
| 7855 | 7855 |
| 7856 // Slow version of Math.pow. We check for fast paths for special cases. | 7856 // Slow version of Math.pow. We check for fast paths for special cases. |
| 7857 // Used if SSE2/VFP3 is not available. | 7857 // Used if SSE2/VFP3 is not available. |
| 7858 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow) { | 7858 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_MathPowSlow) { |
| 7859 SealHandleScope shs(isolate); | 7859 SealHandleScope shs(isolate); |
| 7860 ASSERT(args.length() == 2); | 7860 ASSERT(args.length() == 2); |
| 7861 isolate->counters()->math_pow()->Increment(); | 7861 isolate->counters()->math_pow()->Increment(); |
| 7862 | 7862 |
| 7863 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7863 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7864 | 7864 |
| 7865 // If the second argument is a smi, it is much faster to call the | 7865 // If the second argument is a smi, it is much faster to call the |
| 7866 // custom powi() function than the generic pow(). | 7866 // custom powi() function than the generic pow(). |
| 7867 if (args[1]->IsSmi()) { | 7867 if (args[1]->IsSmi()) { |
| 7868 int y = args.smi_at(1); | 7868 int y = args.smi_at(1); |
| 7869 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); | 7869 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); |
| 7870 } | 7870 } |
| 7871 | 7871 |
| 7872 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7872 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
| 7873 double result = power_helper(x, y); | 7873 double result = power_helper(x, y); |
| 7874 if (std::isnan(result)) return isolate->heap()->nan_value(); | 7874 if (std::isnan(result)) return isolate->heap()->nan_value(); |
| 7875 return isolate->heap()->AllocateHeapNumber(result); | 7875 return isolate->heap()->AllocateHeapNumber(result); |
| 7876 } | 7876 } |
| 7877 | 7877 |
| 7878 | 7878 |
| 7879 // Fast version of Math.pow if we know that y is not an integer and y is not | 7879 // Fast version of Math.pow if we know that y is not an integer and y is not |
| 7880 // -0.5 or 0.5. Used as slow case from full codegen. | 7880 // -0.5 or 0.5. Used as slow case from full codegen. |
| 7881 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { | 7881 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_MathPow) { |
| 7882 SealHandleScope shs(isolate); | 7882 SealHandleScope shs(isolate); |
| 7883 ASSERT(args.length() == 2); | 7883 ASSERT(args.length() == 2); |
| 7884 isolate->counters()->math_pow()->Increment(); | 7884 isolate->counters()->math_pow()->Increment(); |
| 7885 | 7885 |
| 7886 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7886 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7887 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7887 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
| 7888 if (y == 0) { | 7888 if (y == 0) { |
| 7889 return Smi::FromInt(1); | 7889 return Smi::FromInt(1); |
| 7890 } else { | 7890 } else { |
| 7891 double result = power_double_double(x, y); | 7891 double result = power_double_double(x, y); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7931 return number; | 7931 return number; |
| 7932 } | 7932 } |
| 7933 | 7933 |
| 7934 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); | 7934 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); |
| 7935 | 7935 |
| 7936 // Do not call NumberFromDouble() to avoid extra checks. | 7936 // Do not call NumberFromDouble() to avoid extra checks. |
| 7937 return isolate->heap()->AllocateHeapNumber(std::floor(value + 0.5)); | 7937 return isolate->heap()->AllocateHeapNumber(std::floor(value + 0.5)); |
| 7938 } | 7938 } |
| 7939 | 7939 |
| 7940 | 7940 |
| 7941 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_sqrt) { | 7941 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathSqrt) { |
| 7942 SealHandleScope shs(isolate); | 7942 SealHandleScope shs(isolate); |
| 7943 ASSERT(args.length() == 1); | 7943 ASSERT(args.length() == 1); |
| 7944 isolate->counters()->math_sqrt()->Increment(); | 7944 isolate->counters()->math_sqrt()->Increment(); |
| 7945 | 7945 |
| 7946 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7946 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7947 return isolate->heap()->AllocateHeapNumber(fast_sqrt(x)); | 7947 return isolate->heap()->AllocateHeapNumber(fast_sqrt(x)); |
| 7948 } | 7948 } |
| 7949 | 7949 |
| 7950 | 7950 |
| 7951 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_fround) { | 7951 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathFround) { |
| 7952 SealHandleScope shs(isolate); | 7952 SealHandleScope shs(isolate); |
| 7953 ASSERT(args.length() == 1); | 7953 ASSERT(args.length() == 1); |
| 7954 | 7954 |
| 7955 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7955 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 7956 float xf = static_cast<float>(x); | 7956 float xf = static_cast<float>(x); |
| 7957 return isolate->heap()->AllocateHeapNumber(xf); | 7957 return isolate->heap()->AllocateHeapNumber(xf); |
| 7958 } | 7958 } |
| 7959 | 7959 |
| 7960 | 7960 |
| 7961 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { | 7961 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { |
| (...skipping 7214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15176 } | 15176 } |
| 15177 } | 15177 } |
| 15178 | 15178 |
| 15179 | 15179 |
| 15180 void Runtime::OutOfMemory() { | 15180 void Runtime::OutOfMemory() { |
| 15181 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); | 15181 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); |
| 15182 UNREACHABLE(); | 15182 UNREACHABLE(); |
| 15183 } | 15183 } |
| 15184 | 15184 |
| 15185 } } // namespace v8::internal | 15185 } } // namespace v8::internal |
| OLD | NEW |