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

Side by Side Diff: src/runtime/runtime-maths.cc

Issue 1731543004: [builtins] Migrate a bunch of Math builtins to C++. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-numbers.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/base/utils/random-number-generator.h" 9 #include "src/base/utils/random-number-generator.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
11 #include "src/codegen.h" 11 #include "src/codegen.h"
12 #include "src/third_party/fdlibm/fdlibm.h" 12 #include "src/third_party/fdlibm/fdlibm.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 #define RUNTIME_UNARY_MATH(Name, name) \ 17 #define RUNTIME_UNARY_MATH(Name, name) \
18 RUNTIME_FUNCTION(Runtime_Math##Name) { \ 18 RUNTIME_FUNCTION(Runtime_Math##Name) { \
19 HandleScope scope(isolate); \ 19 HandleScope scope(isolate); \
20 DCHECK(args.length() == 1); \ 20 DCHECK(args.length() == 1); \
21 isolate->counters()->math_##name##_runtime()->Increment(); \ 21 isolate->counters()->math_##name##_runtime()->Increment(); \
22 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \ 22 CONVERT_DOUBLE_ARG_CHECKED(x, 0); \
23 return *isolate->factory()->NewHeapNumber(std::name(x)); \ 23 return *isolate->factory()->NewHeapNumber(std::name(x)); \
24 } 24 }
25 25
26 RUNTIME_UNARY_MATH(Acos, acos)
27 RUNTIME_UNARY_MATH(Asin, asin)
28 RUNTIME_UNARY_MATH(Atan, atan)
29 RUNTIME_UNARY_MATH(LogRT, log) 26 RUNTIME_UNARY_MATH(LogRT, log)
30 #undef RUNTIME_UNARY_MATH 27 #undef RUNTIME_UNARY_MATH
31 28
32 29
33 RUNTIME_FUNCTION(Runtime_DoubleHi) { 30 RUNTIME_FUNCTION(Runtime_DoubleHi) {
34 HandleScope scope(isolate); 31 HandleScope scope(isolate);
35 DCHECK(args.length() == 1); 32 DCHECK(args.length() == 1);
36 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 33 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
37 uint64_t unsigned64 = double_to_uint64(x); 34 uint64_t unsigned64 = double_to_uint64(x);
38 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64 >> 32); 35 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64 >> 32);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 HandleScope scope(isolate); 218 HandleScope scope(isolate);
222 DCHECK(args.length() == 1); 219 DCHECK(args.length() == 1);
223 isolate->counters()->math_sqrt_runtime()->Increment(); 220 isolate->counters()->math_sqrt_runtime()->Increment();
224 221
225 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 222 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
226 lazily_initialize_fast_sqrt(isolate); 223 lazily_initialize_fast_sqrt(isolate);
227 return *isolate->factory()->NewNumber(fast_sqrt(x, isolate)); 224 return *isolate->factory()->NewNumber(fast_sqrt(x, isolate));
228 } 225 }
229 226
230 227
231 RUNTIME_FUNCTION(Runtime_MathFround) {
232 HandleScope scope(isolate);
233 DCHECK(args.length() == 1);
234
235 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
236 float xf = DoubleToFloat32(x);
237 return *isolate->factory()->NewNumber(xf);
238 }
239
240
241 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { 228 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) {
242 HandleScope scope(isolate); 229 HandleScope scope(isolate);
243 DCHECK(args.length() == 1); 230 DCHECK(args.length() == 1);
244 // Random numbers in the snapshot are not really that random. 231 // Random numbers in the snapshot are not really that random.
245 DCHECK(!isolate->bootstrapper()->IsActive()); 232 DCHECK(!isolate->bootstrapper()->IsActive());
246 static const int kState0Offset = 0; 233 static const int kState0Offset = 0;
247 static const int kState1Offset = 1; 234 static const int kState1Offset = 1;
248 static const int kRandomBatchSize = 64; 235 static const int kRandomBatchSize = 64;
249 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_typed_array, 0); 236 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_typed_array, 0);
250 Handle<JSTypedArray> typed_array; 237 Handle<JSTypedArray> typed_array;
(...skipping 27 matching lines...) Expand all
278 base::RandomNumberGenerator::XorShift128(&state0, &state1); 265 base::RandomNumberGenerator::XorShift128(&state0, &state1);
279 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); 266 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1);
280 } 267 }
281 // Persist current state. 268 // Persist current state.
282 array[kState0Offset] = uint64_to_double(state0); 269 array[kState0Offset] = uint64_to_double(state0);
283 array[kState1Offset] = uint64_to_double(state1); 270 array[kState1Offset] = uint64_to_double(state1);
284 return *typed_array; 271 return *typed_array;
285 } 272 }
286 } // namespace internal 273 } // namespace internal
287 } // namespace v8 274 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-numbers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698