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

Side by Side Diff: src/runtime.cc

Issue 179059: Cache the results of slow math operations on machines that don't... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 3 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
« src/heap.cc ('K') | « src/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 4040 matching lines...) Expand 10 before | Expand all | Expand 10 after
4051 CONVERT_DOUBLE_CHECKED(x, args[0]); 4051 CONVERT_DOUBLE_CHECKED(x, args[0]);
4052 return Heap::AllocateHeapNumber(fabs(x)); 4052 return Heap::AllocateHeapNumber(fabs(x));
4053 } 4053 }
4054 4054
4055 4055
4056 static Object* Runtime_Math_acos(Arguments args) { 4056 static Object* Runtime_Math_acos(Arguments args) {
4057 NoHandleAllocation ha; 4057 NoHandleAllocation ha;
4058 ASSERT(args.length() == 1); 4058 ASSERT(args.length() == 1);
4059 4059
4060 CONVERT_DOUBLE_CHECKED(x, args[0]); 4060 CONVERT_DOUBLE_CHECKED(x, args[0]);
4061 return Heap::AllocateHeapNumber(acos(x)); 4061 return TranscendentalCache::Get(TranscendentalCache::ACOS, x);
4062 } 4062 }
4063 4063
4064 4064
4065 static Object* Runtime_Math_asin(Arguments args) { 4065 static Object* Runtime_Math_asin(Arguments args) {
4066 NoHandleAllocation ha; 4066 NoHandleAllocation ha;
4067 ASSERT(args.length() == 1); 4067 ASSERT(args.length() == 1);
4068 4068
4069 CONVERT_DOUBLE_CHECKED(x, args[0]); 4069 CONVERT_DOUBLE_CHECKED(x, args[0]);
4070 return Heap::AllocateHeapNumber(asin(x)); 4070 return TranscendentalCache::Get(TranscendentalCache::ASIN, x);
4071 } 4071 }
4072 4072
4073 4073
4074 static Object* Runtime_Math_atan(Arguments args) { 4074 static Object* Runtime_Math_atan(Arguments args) {
4075 NoHandleAllocation ha; 4075 NoHandleAllocation ha;
4076 ASSERT(args.length() == 1); 4076 ASSERT(args.length() == 1);
4077 4077
4078 CONVERT_DOUBLE_CHECKED(x, args[0]); 4078 CONVERT_DOUBLE_CHECKED(x, args[0]);
4079 return Heap::AllocateHeapNumber(atan(x)); 4079 return TranscendentalCache::Get(TranscendentalCache::ATAN, x);
4080 } 4080 }
4081 4081
4082 4082
4083 static Object* Runtime_Math_atan2(Arguments args) { 4083 static Object* Runtime_Math_atan2(Arguments args) {
4084 NoHandleAllocation ha; 4084 NoHandleAllocation ha;
4085 ASSERT(args.length() == 2); 4085 ASSERT(args.length() == 2);
4086 4086
4087 CONVERT_DOUBLE_CHECKED(x, args[0]); 4087 CONVERT_DOUBLE_CHECKED(x, args[0]);
4088 CONVERT_DOUBLE_CHECKED(y, args[1]); 4088 CONVERT_DOUBLE_CHECKED(y, args[1]);
4089 double result; 4089 double result;
(...skipping 20 matching lines...) Expand all
4110 CONVERT_DOUBLE_CHECKED(x, args[0]); 4110 CONVERT_DOUBLE_CHECKED(x, args[0]);
4111 return Heap::NumberFromDouble(ceiling(x)); 4111 return Heap::NumberFromDouble(ceiling(x));
4112 } 4112 }
4113 4113
4114 4114
4115 static Object* Runtime_Math_cos(Arguments args) { 4115 static Object* Runtime_Math_cos(Arguments args) {
4116 NoHandleAllocation ha; 4116 NoHandleAllocation ha;
4117 ASSERT(args.length() == 1); 4117 ASSERT(args.length() == 1);
4118 4118
4119 CONVERT_DOUBLE_CHECKED(x, args[0]); 4119 CONVERT_DOUBLE_CHECKED(x, args[0]);
4120 return Heap::AllocateHeapNumber(cos(x)); 4120 return TranscendentalCache::Get(TranscendentalCache::COS, x);
4121 } 4121 }
4122 4122
4123 4123
4124 static Object* Runtime_Math_exp(Arguments args) { 4124 static Object* Runtime_Math_exp(Arguments args) {
4125 NoHandleAllocation ha; 4125 NoHandleAllocation ha;
4126 ASSERT(args.length() == 1); 4126 ASSERT(args.length() == 1);
4127 4127
4128 CONVERT_DOUBLE_CHECKED(x, args[0]); 4128 CONVERT_DOUBLE_CHECKED(x, args[0]);
4129 return Heap::AllocateHeapNumber(exp(x)); 4129 return TranscendentalCache::Get(TranscendentalCache::EXP, x);
4130 } 4130 }
4131 4131
4132 4132
4133 static Object* Runtime_Math_floor(Arguments args) { 4133 static Object* Runtime_Math_floor(Arguments args) {
4134 NoHandleAllocation ha; 4134 NoHandleAllocation ha;
4135 ASSERT(args.length() == 1); 4135 ASSERT(args.length() == 1);
4136 4136
4137 CONVERT_DOUBLE_CHECKED(x, args[0]); 4137 CONVERT_DOUBLE_CHECKED(x, args[0]);
4138 return Heap::NumberFromDouble(floor(x)); 4138 return Heap::NumberFromDouble(floor(x));
4139 } 4139 }
4140 4140
4141 4141
4142 static Object* Runtime_Math_log(Arguments args) { 4142 static Object* Runtime_Math_log(Arguments args) {
4143 NoHandleAllocation ha; 4143 NoHandleAllocation ha;
4144 ASSERT(args.length() == 1); 4144 ASSERT(args.length() == 1);
4145 4145
4146 CONVERT_DOUBLE_CHECKED(x, args[0]); 4146 CONVERT_DOUBLE_CHECKED(x, args[0]);
4147 return Heap::AllocateHeapNumber(log(x)); 4147 return TranscendentalCache::Get(TranscendentalCache::LOG, x);
4148 } 4148 }
4149 4149
4150 4150
4151 // Helper function to compute x^y, where y is known to be an 4151 // Helper function to compute x^y, where y is known to be an
4152 // integer. Uses binary decomposition to limit the number of 4152 // integer. Uses binary decomposition to limit the number of
4153 // multiplications; see the discussion in "Hacker's Delight" by Henry 4153 // multiplications; see the discussion in "Hacker's Delight" by Henry
4154 // S. Warren, Jr., figure 11-6, page 213. 4154 // S. Warren, Jr., figure 11-6, page 213.
4155 static double powi(double x, int y) { 4155 static double powi(double x, int y) {
4156 ASSERT(y != kMinInt); 4156 ASSERT(y != kMinInt);
4157 unsigned n = (y < 0) ? -y : y; 4157 unsigned n = (y < 0) ? -y : y;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4225 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value(); 4225 if (signbit(x) && x >= -0.5) return Heap::minus_zero_value();
4226 return Heap::NumberFromDouble(floor(x + 0.5)); 4226 return Heap::NumberFromDouble(floor(x + 0.5));
4227 } 4227 }
4228 4228
4229 4229
4230 static Object* Runtime_Math_sin(Arguments args) { 4230 static Object* Runtime_Math_sin(Arguments args) {
4231 NoHandleAllocation ha; 4231 NoHandleAllocation ha;
4232 ASSERT(args.length() == 1); 4232 ASSERT(args.length() == 1);
4233 4233
4234 CONVERT_DOUBLE_CHECKED(x, args[0]); 4234 CONVERT_DOUBLE_CHECKED(x, args[0]);
4235 return Heap::AllocateHeapNumber(sin(x)); 4235 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
4236 } 4236 }
4237 4237
4238 4238
4239 static Object* Runtime_Math_sqrt(Arguments args) { 4239 static Object* Runtime_Math_sqrt(Arguments args) {
4240 NoHandleAllocation ha; 4240 NoHandleAllocation ha;
4241 ASSERT(args.length() == 1); 4241 ASSERT(args.length() == 1);
4242 4242
4243 CONVERT_DOUBLE_CHECKED(x, args[0]); 4243 CONVERT_DOUBLE_CHECKED(x, args[0]);
4244 return Heap::AllocateHeapNumber(sqrt(x)); 4244 return Heap::AllocateHeapNumber(sqrt(x));
4245 } 4245 }
4246 4246
4247 4247
4248 static Object* Runtime_Math_tan(Arguments args) { 4248 static Object* Runtime_Math_tan(Arguments args) {
4249 NoHandleAllocation ha; 4249 NoHandleAllocation ha;
4250 ASSERT(args.length() == 1); 4250 ASSERT(args.length() == 1);
4251 4251
4252 CONVERT_DOUBLE_CHECKED(x, args[0]); 4252 CONVERT_DOUBLE_CHECKED(x, args[0]);
4253 return Heap::AllocateHeapNumber(tan(x)); 4253 return TranscendentalCache::Get(TranscendentalCache::TAN, x);
4254 } 4254 }
4255 4255
4256 4256
4257 // The NewArguments function is only used when constructing the 4257 // The NewArguments function is only used when constructing the
4258 // arguments array when calling non-functions from JavaScript in 4258 // arguments array when calling non-functions from JavaScript in
4259 // runtime.js:CALL_NON_FUNCTION. 4259 // runtime.js:CALL_NON_FUNCTION.
4260 static Object* Runtime_NewArguments(Arguments args) { 4260 static Object* Runtime_NewArguments(Arguments args) {
4261 NoHandleAllocation ha; 4261 NoHandleAllocation ha;
4262 ASSERT(args.length() == 1); 4262 ASSERT(args.length() == 1);
4263 4263
(...skipping 3407 matching lines...) Expand 10 before | Expand all | Expand 10 after
7671 } else { 7671 } else {
7672 // Handle last resort GC and make sure to allow future allocations 7672 // Handle last resort GC and make sure to allow future allocations
7673 // to grow the heap without causing GCs (if possible). 7673 // to grow the heap without causing GCs (if possible).
7674 Counters::gc_last_resort_from_js.Increment(); 7674 Counters::gc_last_resort_from_js.Increment();
7675 Heap::CollectAllGarbage(false); 7675 Heap::CollectAllGarbage(false);
7676 } 7676 }
7677 } 7677 }
7678 7678
7679 7679
7680 } } // namespace v8::internal 7680 } } // namespace v8::internal
OLDNEW
« src/heap.cc ('K') | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698