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

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