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

Side by Side Diff: src/runtime.cc

Issue 212763008: Clean up runtime functions for Maths. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/runtime.h ('k') | src/x64/code-stubs-x64.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
(...skipping 7741 matching lines...) Expand 10 before | Expand all | Expand 10 after
7752 } 7752 }
7753 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(y); 7753 { MaybeObject* maybe_obj = isolate->heap()->PrepareForCompare(y);
7754 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 7754 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
7755 } 7755 }
7756 7756
7757 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) 7757 return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
7758 : StringCharacterStreamCompare(isolate->runtime_state(), x, y); 7758 : StringCharacterStreamCompare(isolate->runtime_state(), x, y);
7759 } 7759 }
7760 7760
7761 7761
7762 #define RUNTIME_UNARY_MATH(NAME) \ 7762 #define RUNTIME_UNARY_MATH(Name, name) \
7763 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_##NAME) { \ 7763 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math##Name) { \
7764 SealHandleScope shs(isolate); \ 7764 SealHandleScope shs(isolate); \
7765 ASSERT(args.length() == 1); \ 7765 ASSERT(args.length() == 1); \
7766 isolate->counters()->math_##NAME()->Increment(); \ 7766 isolate->counters()->math_##name()->Increment(); \
7767 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \ 7767 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \
7768 return isolate->heap()->AllocateHeapNumber(std::NAME(x)); \ 7768 return isolate->heap()->AllocateHeapNumber(std::name(x)); \
7769 } 7769 }
7770 7770
7771 RUNTIME_UNARY_MATH(acos) 7771 RUNTIME_UNARY_MATH(Acos, acos)
7772 RUNTIME_UNARY_MATH(asin) 7772 RUNTIME_UNARY_MATH(Asin, asin)
7773 RUNTIME_UNARY_MATH(atan) 7773 RUNTIME_UNARY_MATH(Atan, atan)
7774 RUNTIME_UNARY_MATH(log)
7775 #undef RUNTIME_UNARY_MATH 7774 #undef RUNTIME_UNARY_MATH
7776 7775
7777 7776
7777 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathLog) {
Dmitry Lomov 2014/03/27 14:11:03 Isn't this a RUNTIME_UNARY_MATH(Log, log)?
Yang 2014/03/27 14:45:29 Correct. At some point I was playing with marking
7778 SealHandleScope shs(isolate);
7779 ASSERT(args.length() == 1);
7780 isolate->counters()->math_log()->Increment();
7781 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7782 return isolate->heap()->AllocateHeapNumber(std::log(x));
7783 }
7784
7785
7778 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleHi) { 7786 RUNTIME_FUNCTION(MaybeObject*, Runtime_DoubleHi) {
7779 SealHandleScope shs(isolate); 7787 SealHandleScope shs(isolate);
7780 ASSERT(args.length() == 1); 7788 ASSERT(args.length() == 1);
7781 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7789 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7782 uint64_t integer = double_to_uint64(x); 7790 uint64_t integer = double_to_uint64(x);
7783 integer = (integer >> 32) & 0xFFFFFFFFu; 7791 integer = (integer >> 32) & 0xFFFFFFFFu;
7784 return isolate->heap()->NumberFromDouble(static_cast<int32_t>(integer)); 7792 return isolate->heap()->NumberFromDouble(static_cast<int32_t>(integer));
7785 } 7793 }
7786 7794
7787 7795
(...skipping 12 matching lines...) Expand all
7800 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); 7808 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]);
7801 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); 7809 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]);
7802 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; 7810 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo;
7803 return isolate->heap()->AllocateHeapNumber(uint64_to_double(result)); 7811 return isolate->heap()->AllocateHeapNumber(uint64_to_double(result));
7804 } 7812 }
7805 7813
7806 7814
7807 static const double kPiDividedBy4 = 0.78539816339744830962; 7815 static const double kPiDividedBy4 = 0.78539816339744830962;
7808 7816
7809 7817
7810 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) { 7818 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathAtan2) {
7811 SealHandleScope shs(isolate); 7819 SealHandleScope shs(isolate);
7812 ASSERT(args.length() == 2); 7820 ASSERT(args.length() == 2);
7813 isolate->counters()->math_atan2()->Increment(); 7821 isolate->counters()->math_atan2()->Increment();
7814 7822
7815 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7823 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7816 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7824 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7817 double result; 7825 double result;
7818 if (std::isinf(x) && std::isinf(y)) { 7826 if (std::isinf(x) && std::isinf(y)) {
7819 // Make sure that the result in case of two infinite arguments 7827 // Make sure that the result in case of two infinite arguments
7820 // is a multiple of Pi / 4. The sign of the result is determined 7828 // is a multiple of Pi / 4. The sign of the result is determined
7821 // by the first argument (x) and the sign of the second argument 7829 // by the first argument (x) and the sign of the second argument
7822 // determines the multiplier: one or three. 7830 // determines the multiplier: one or three.
7823 int multiplier = (x < 0) ? -1 : 1; 7831 int multiplier = (x < 0) ? -1 : 1;
7824 if (y < 0) multiplier *= 3; 7832 if (y < 0) multiplier *= 3;
7825 result = multiplier * kPiDividedBy4; 7833 result = multiplier * kPiDividedBy4;
7826 } else { 7834 } else {
7827 result = std::atan2(x, y); 7835 result = std::atan2(x, y);
7828 } 7836 }
7829 return isolate->heap()->AllocateHeapNumber(result); 7837 return isolate->heap()->AllocateHeapNumber(result);
7830 } 7838 }
7831 7839
7832 7840
7833 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_exp) { 7841 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathExp) {
7834 SealHandleScope shs(isolate); 7842 SealHandleScope shs(isolate);
7835 ASSERT(args.length() == 1); 7843 ASSERT(args.length() == 1);
7836 isolate->counters()->math_exp()->Increment(); 7844 isolate->counters()->math_exp()->Increment();
7837 7845
7838 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7846 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7839 lazily_initialize_fast_exp(); 7847 lazily_initialize_fast_exp();
7840 return isolate->heap()->NumberFromDouble(fast_exp(x)); 7848 return isolate->heap()->NumberFromDouble(fast_exp(x));
7841 } 7849 }
7842 7850
7843 7851
7844 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_floor) { 7852 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathFloor) {
7845 SealHandleScope shs(isolate); 7853 SealHandleScope shs(isolate);
7846 ASSERT(args.length() == 1); 7854 ASSERT(args.length() == 1);
7847 isolate->counters()->math_floor()->Increment(); 7855 isolate->counters()->math_floor()->Increment();
7848 7856
7849 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7857 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7850 return isolate->heap()->NumberFromDouble(std::floor(x)); 7858 return isolate->heap()->NumberFromDouble(std::floor(x));
7851 } 7859 }
7852 7860
7853 7861
7854 // Slow version of Math.pow. We check for fast paths for special cases. 7862 // Slow version of Math.pow. We check for fast paths for special cases.
7855 // Used if SSE2/VFP3 is not available. 7863 // Used if SSE2/VFP3 is not available.
7856 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow) { 7864 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_MathPowSlow) {
7857 SealHandleScope shs(isolate); 7865 SealHandleScope shs(isolate);
7858 ASSERT(args.length() == 2); 7866 ASSERT(args.length() == 2);
7859 isolate->counters()->math_pow()->Increment(); 7867 isolate->counters()->math_pow()->Increment();
7860 7868
7861 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7869 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7862 7870
7863 // If the second argument is a smi, it is much faster to call the 7871 // If the second argument is a smi, it is much faster to call the
7864 // custom powi() function than the generic pow(). 7872 // custom powi() function than the generic pow().
7865 if (args[1]->IsSmi()) { 7873 if (args[1]->IsSmi()) {
7866 int y = args.smi_at(1); 7874 int y = args.smi_at(1);
7867 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); 7875 return isolate->heap()->NumberFromDouble(power_double_int(x, y));
7868 } 7876 }
7869 7877
7870 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7878 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7871 double result = power_helper(x, y); 7879 double result = power_helper(x, y);
7872 if (std::isnan(result)) return isolate->heap()->nan_value(); 7880 if (std::isnan(result)) return isolate->heap()->nan_value();
7873 return isolate->heap()->AllocateHeapNumber(result); 7881 return isolate->heap()->AllocateHeapNumber(result);
7874 } 7882 }
7875 7883
7876 7884
7877 // Fast version of Math.pow if we know that y is not an integer and y is not 7885 // Fast version of Math.pow if we know that y is not an integer and y is not
7878 // -0.5 or 0.5. Used as slow case from full codegen. 7886 // -0.5 or 0.5. Used as slow case from full codegen.
7879 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { 7887 RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_MathPow) {
7880 SealHandleScope shs(isolate); 7888 SealHandleScope shs(isolate);
7881 ASSERT(args.length() == 2); 7889 ASSERT(args.length() == 2);
7882 isolate->counters()->math_pow()->Increment(); 7890 isolate->counters()->math_pow()->Increment();
7883 7891
7884 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7892 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7885 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7893 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7886 if (y == 0) { 7894 if (y == 0) {
7887 return Smi::FromInt(1); 7895 return Smi::FromInt(1);
7888 } else { 7896 } else {
7889 double result = power_double_double(x, y); 7897 double result = power_double_double(x, y);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7929 return number; 7937 return number;
7930 } 7938 }
7931 7939
7932 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); 7940 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value();
7933 7941
7934 // Do not call NumberFromDouble() to avoid extra checks. 7942 // Do not call NumberFromDouble() to avoid extra checks.
7935 return isolate->heap()->AllocateHeapNumber(std::floor(value + 0.5)); 7943 return isolate->heap()->AllocateHeapNumber(std::floor(value + 0.5));
7936 } 7944 }
7937 7945
7938 7946
7939 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_sqrt) { 7947 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathSqrt) {
7940 SealHandleScope shs(isolate); 7948 SealHandleScope shs(isolate);
7941 ASSERT(args.length() == 1); 7949 ASSERT(args.length() == 1);
7942 isolate->counters()->math_sqrt()->Increment(); 7950 isolate->counters()->math_sqrt()->Increment();
7943 7951
7944 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7952 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7945 return isolate->heap()->AllocateHeapNumber(fast_sqrt(x)); 7953 return isolate->heap()->AllocateHeapNumber(fast_sqrt(x));
7946 } 7954 }
7947 7955
7948 7956
7949 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_fround) { 7957 RUNTIME_FUNCTION(MaybeObject*, Runtime_MathFround) {
7950 SealHandleScope shs(isolate); 7958 SealHandleScope shs(isolate);
7951 ASSERT(args.length() == 1); 7959 ASSERT(args.length() == 1);
7952 7960
7953 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7961 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7954 float xf = static_cast<float>(x); 7962 float xf = static_cast<float>(x);
7955 return isolate->heap()->AllocateHeapNumber(xf); 7963 return isolate->heap()->AllocateHeapNumber(xf);
7956 } 7964 }
7957 7965
7958 7966
7959 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { 7967 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) {
(...skipping 7214 matching lines...) Expand 10 before | Expand all | Expand 10 after
15174 } 15182 }
15175 } 15183 }
15176 15184
15177 15185
15178 void Runtime::OutOfMemory() { 15186 void Runtime::OutOfMemory() {
15179 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); 15187 Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);
15180 UNREACHABLE(); 15188 UNREACHABLE();
15181 } 15189 }
15182 15190
15183 } } // namespace v8::internal 15191 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698