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

Side by Side Diff: src/runtime.cc

Issue 14362023: Replace math.h with cmath (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 7 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/preparser.cc ('k') | src/strtod.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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "runtime.h" 58 #include "runtime.h"
59 #include "scopeinfo.h" 59 #include "scopeinfo.h"
60 #include "smart-pointers.h" 60 #include "smart-pointers.h"
61 #include "string-search.h" 61 #include "string-search.h"
62 #include "stub-cache.h" 62 #include "stub-cache.h"
63 #include "uri.h" 63 #include "uri.h"
64 #include "v8conversions.h" 64 #include "v8conversions.h"
65 #include "v8threads.h" 65 #include "v8threads.h"
66 #include "vm-state-inl.h" 66 #include "vm-state-inl.h"
67 67
68 #ifndef _STLP_VENDOR_CSTD
69 // STLPort doesn't import fpclassify and isless into the std namespace.
70 using std::fpclassify;
71 using std::isless;
72 #endif
73
68 namespace v8 { 74 namespace v8 {
69 namespace internal { 75 namespace internal {
70 76
71 77
72 #define RUNTIME_ASSERT(value) \ 78 #define RUNTIME_ASSERT(value) \
73 if (!(value)) return isolate->ThrowIllegalOperation(); 79 if (!(value)) return isolate->ThrowIllegalOperation();
74 80
75 // Cast the given object to a value of the specified type and store 81 // Cast the given object to a value of the specified type and store
76 // it in a variable with the given name. If the object is not of the 82 // it in a variable with the given name. If the object is not of the
77 // expected type call IllegalOperation and return. 83 // expected type call IllegalOperation and return.
(...skipping 3878 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 if (value >= 0 && value < radix) { 3962 if (value >= 0 && value < radix) {
3957 // Character array used for conversion. 3963 // Character array used for conversion.
3958 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 3964 static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
3959 return isolate->heap()-> 3965 return isolate->heap()->
3960 LookupSingleCharacterStringFromCode(kCharTable[value]); 3966 LookupSingleCharacterStringFromCode(kCharTable[value]);
3961 } 3967 }
3962 } 3968 }
3963 3969
3964 // Slow case. 3970 // Slow case.
3965 CONVERT_DOUBLE_ARG_CHECKED(value, 0); 3971 CONVERT_DOUBLE_ARG_CHECKED(value, 0);
3966 if (isnan(value)) { 3972 if (std::isnan(value)) {
3967 return *isolate->factory()->nan_string(); 3973 return *isolate->factory()->nan_string();
3968 } 3974 }
3969 if (isinf(value)) { 3975 if (std::isinf(value)) {
3970 if (value < 0) { 3976 if (value < 0) {
3971 return *isolate->factory()->minus_infinity_string(); 3977 return *isolate->factory()->minus_infinity_string();
3972 } 3978 }
3973 return *isolate->factory()->infinity_string(); 3979 return *isolate->factory()->infinity_string();
3974 } 3980 }
3975 char* str = DoubleToRadixCString(value, radix); 3981 char* str = DoubleToRadixCString(value, radix);
3976 MaybeObject* result = 3982 MaybeObject* result =
3977 isolate->heap()->AllocateStringFromOneByte(CStrVector(str)); 3983 isolate->heap()->AllocateStringFromOneByte(CStrVector(str));
3978 DeleteArray(str); 3984 DeleteArray(str);
3979 return result; 3985 return result;
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after
6597 return isolate->heap()->NumberFromInt32(ArithmeticShiftRight(x, y & 0x1f)); 6603 return isolate->heap()->NumberFromInt32(ArithmeticShiftRight(x, y & 0x1f));
6598 } 6604 }
6599 6605
6600 6606
6601 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberEquals) { 6607 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberEquals) {
6602 NoHandleAllocation ha(isolate); 6608 NoHandleAllocation ha(isolate);
6603 ASSERT(args.length() == 2); 6609 ASSERT(args.length() == 2);
6604 6610
6605 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 6611 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
6606 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 6612 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
6607 if (isnan(x)) return Smi::FromInt(NOT_EQUAL); 6613 if (std::isnan(x)) return Smi::FromInt(NOT_EQUAL);
6608 if (isnan(y)) return Smi::FromInt(NOT_EQUAL); 6614 if (std::isnan(y)) return Smi::FromInt(NOT_EQUAL);
6609 if (x == y) return Smi::FromInt(EQUAL); 6615 if (x == y) return Smi::FromInt(EQUAL);
6610 Object* result; 6616 Object* result;
6611 if ((fpclassify(x) == FP_ZERO) && (fpclassify(y) == FP_ZERO)) { 6617 if ((fpclassify(x) == FP_ZERO) && (fpclassify(y) == FP_ZERO)) {
6612 result = Smi::FromInt(EQUAL); 6618 result = Smi::FromInt(EQUAL);
6613 } else { 6619 } else {
6614 result = Smi::FromInt(NOT_EQUAL); 6620 result = Smi::FromInt(NOT_EQUAL);
6615 } 6621 }
6616 return result; 6622 return result;
6617 } 6623 }
6618 6624
(...skipping 15 matching lines...) Expand all
6634 return Smi::FromInt(not_equal); 6640 return Smi::FromInt(not_equal);
6635 } 6641 }
6636 6642
6637 6643
6638 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberCompare) { 6644 RUNTIME_FUNCTION(MaybeObject*, Runtime_NumberCompare) {
6639 NoHandleAllocation ha(isolate); 6645 NoHandleAllocation ha(isolate);
6640 ASSERT(args.length() == 3); 6646 ASSERT(args.length() == 3);
6641 6647
6642 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 6648 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
6643 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 6649 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
6644 if (isnan(x) || isnan(y)) return args[2]; 6650 if (std::isnan(x) || std::isnan(y)) return args[2];
6645 if (x == y) return Smi::FromInt(EQUAL); 6651 if (x == y) return Smi::FromInt(EQUAL);
6646 if (isless(x, y)) return Smi::FromInt(LESS); 6652 if (isless(x, y)) return Smi::FromInt(LESS);
6647 return Smi::FromInt(GREATER); 6653 return Smi::FromInt(GREATER);
6648 } 6654 }
6649 6655
6650 6656
6651 // Compare two Smis as if they were converted to strings and then 6657 // Compare two Smis as if they were converted to strings and then
6652 // compared lexicographically. 6658 // compared lexicographically.
6653 RUNTIME_FUNCTION(MaybeObject*, Runtime_SmiLexicographicCompare) { 6659 RUNTIME_FUNCTION(MaybeObject*, Runtime_SmiLexicographicCompare) {
6654 NoHandleAllocation ha(isolate); 6660 NoHandleAllocation ha(isolate);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
6857 6863
6858 6864
6859 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) { 6865 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_atan2) {
6860 NoHandleAllocation ha(isolate); 6866 NoHandleAllocation ha(isolate);
6861 ASSERT(args.length() == 2); 6867 ASSERT(args.length() == 2);
6862 isolate->counters()->math_atan2()->Increment(); 6868 isolate->counters()->math_atan2()->Increment();
6863 6869
6864 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 6870 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
6865 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 6871 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
6866 double result; 6872 double result;
6867 if (isinf(x) && isinf(y)) { 6873 if (std::isinf(x) && std::isinf(y)) {
6868 // Make sure that the result in case of two infinite arguments 6874 // Make sure that the result in case of two infinite arguments
6869 // is a multiple of Pi / 4. The sign of the result is determined 6875 // is a multiple of Pi / 4. The sign of the result is determined
6870 // by the first argument (x) and the sign of the second argument 6876 // by the first argument (x) and the sign of the second argument
6871 // determines the multiplier: one or three. 6877 // determines the multiplier: one or three.
6872 int multiplier = (x < 0) ? -1 : 1; 6878 int multiplier = (x < 0) ? -1 : 1;
6873 if (y < 0) multiplier *= 3; 6879 if (y < 0) multiplier *= 3;
6874 result = multiplier * kPiDividedBy4; 6880 result = multiplier * kPiDividedBy4;
6875 } else { 6881 } else {
6876 result = atan2(x, y); 6882 result = atan2(x, y);
6877 } 6883 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
6940 6946
6941 // If the second argument is a smi, it is much faster to call the 6947 // If the second argument is a smi, it is much faster to call the
6942 // custom powi() function than the generic pow(). 6948 // custom powi() function than the generic pow().
6943 if (args[1]->IsSmi()) { 6949 if (args[1]->IsSmi()) {
6944 int y = args.smi_at(1); 6950 int y = args.smi_at(1);
6945 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); 6951 return isolate->heap()->NumberFromDouble(power_double_int(x, y));
6946 } 6952 }
6947 6953
6948 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 6954 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
6949 double result = power_helper(x, y); 6955 double result = power_helper(x, y);
6950 if (isnan(result)) return isolate->heap()->nan_value(); 6956 if (std::isnan(result)) return isolate->heap()->nan_value();
6951 return isolate->heap()->AllocateHeapNumber(result); 6957 return isolate->heap()->AllocateHeapNumber(result);
6952 } 6958 }
6953 6959
6954 // Fast version of Math.pow if we know that y is not an integer and y is not 6960 // Fast version of Math.pow if we know that y is not an integer and y is not
6955 // -0.5 or 0.5. Used as slow case from full codegen. 6961 // -0.5 or 0.5. Used as slow case from full codegen.
6956 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { 6962 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) {
6957 NoHandleAllocation ha(isolate); 6963 NoHandleAllocation ha(isolate);
6958 ASSERT(args.length() == 2); 6964 ASSERT(args.length() == 2);
6959 isolate->counters()->math_pow()->Increment(); 6965 isolate->counters()->math_pow()->Increment();
6960 6966
6961 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 6967 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
6962 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 6968 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
6963 if (y == 0) { 6969 if (y == 0) {
6964 return Smi::FromInt(1); 6970 return Smi::FromInt(1);
6965 } else { 6971 } else {
6966 double result = power_double_double(x, y); 6972 double result = power_double_double(x, y);
6967 if (isnan(result)) return isolate->heap()->nan_value(); 6973 if (std::isnan(result)) return isolate->heap()->nan_value();
6968 return isolate->heap()->AllocateHeapNumber(result); 6974 return isolate->heap()->AllocateHeapNumber(result);
6969 } 6975 }
6970 } 6976 }
6971 6977
6972 6978
6973 RUNTIME_FUNCTION(MaybeObject*, Runtime_RoundNumber) { 6979 RUNTIME_FUNCTION(MaybeObject*, Runtime_RoundNumber) {
6974 NoHandleAllocation ha(isolate); 6980 NoHandleAllocation ha(isolate);
6975 ASSERT(args.length() == 1); 6981 ASSERT(args.length() == 1);
6976 isolate->counters()->math_round()->Increment(); 6982 isolate->counters()->math_round()->Increment();
6977 6983
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7059 ASSERT(args.length() == 3); 7065 ASSERT(args.length() == 3);
7060 7066
7061 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 0); 7067 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 0);
7062 CONVERT_DOUBLE_ARG_CHECKED(time, 1); 7068 CONVERT_DOUBLE_ARG_CHECKED(time, 1);
7063 CONVERT_SMI_ARG_CHECKED(is_utc, 2); 7069 CONVERT_SMI_ARG_CHECKED(is_utc, 2);
7064 7070
7065 DateCache* date_cache = isolate->date_cache(); 7071 DateCache* date_cache = isolate->date_cache();
7066 7072
7067 Object* value = NULL; 7073 Object* value = NULL;
7068 bool is_value_nan = false; 7074 bool is_value_nan = false;
7069 if (isnan(time)) { 7075 if (std::isnan(time)) {
7070 value = isolate->heap()->nan_value(); 7076 value = isolate->heap()->nan_value();
7071 is_value_nan = true; 7077 is_value_nan = true;
7072 } else if (!is_utc && 7078 } else if (!is_utc &&
7073 (time < -DateCache::kMaxTimeBeforeUTCInMs || 7079 (time < -DateCache::kMaxTimeBeforeUTCInMs ||
7074 time > DateCache::kMaxTimeBeforeUTCInMs)) { 7080 time > DateCache::kMaxTimeBeforeUTCInMs)) {
7075 value = isolate->heap()->nan_value(); 7081 value = isolate->heap()->nan_value();
7076 is_value_nan = true; 7082 is_value_nan = true;
7077 } else { 7083 } else {
7078 time = is_utc ? time : date_cache->ToUTC(static_cast<int64_t>(time)); 7084 time = is_utc ? time : date_cache->ToUTC(static_cast<int64_t>(time));
7079 if (time < -DateCache::kMaxTimeInMs || 7085 if (time < -DateCache::kMaxTimeInMs ||
(...skipping 6141 matching lines...) Expand 10 before | Expand all | Expand 10 after
13221 // Handle last resort GC and make sure to allow future allocations 13227 // Handle last resort GC and make sure to allow future allocations
13222 // to grow the heap without causing GCs (if possible). 13228 // to grow the heap without causing GCs (if possible).
13223 isolate->counters()->gc_last_resort_from_js()->Increment(); 13229 isolate->counters()->gc_last_resort_from_js()->Increment();
13224 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13230 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13225 "Runtime::PerformGC"); 13231 "Runtime::PerformGC");
13226 } 13232 }
13227 } 13233 }
13228 13234
13229 13235
13230 } } // namespace v8::internal 13236 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | src/strtod.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698