OLD | NEW |
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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 HandleScope scope(isolate); | 28 HandleScope scope(isolate); |
29 DCHECK(args.length() == 1); | 29 DCHECK(args.length() == 1); |
30 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 30 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
31 uint64_t unsigned64 = double_to_uint64(x); | 31 uint64_t unsigned64 = double_to_uint64(x); |
32 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64); | 32 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64); |
33 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); | 33 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); |
34 return *isolate->factory()->NewNumber(signed32); | 34 return *isolate->factory()->NewNumber(signed32); |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 // Slow version of Math.pow. We check for fast paths for special cases. | |
39 // Used if VFP3 is not available. | |
40 RUNTIME_FUNCTION(Runtime_MathPow) { | |
41 HandleScope scope(isolate); | |
42 DCHECK(args.length() == 2); | |
43 isolate->counters()->math_pow_runtime()->Increment(); | |
44 | |
45 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
46 | |
47 // If the second argument is a smi, it is much faster to call the | |
48 // custom powi() function than the generic pow(). | |
49 if (args[1]->IsSmi()) { | |
50 int y = args.smi_at(1); | |
51 return *isolate->factory()->NewNumber(power_double_int(x, y)); | |
52 } | |
53 | |
54 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
55 double result = power_helper(isolate, x, y); | |
56 if (std::isnan(result)) return isolate->heap()->nan_value(); | |
57 return *isolate->factory()->NewNumber(result); | |
58 } | |
59 | |
60 | |
61 // Fast version of Math.pow if we know that y is not an integer and y is not | |
62 // -0.5 or 0.5. Used as slow case from full codegen. | |
63 RUNTIME_FUNCTION(Runtime_MathPowRT) { | |
64 HandleScope scope(isolate); | |
65 DCHECK(args.length() == 2); | |
66 isolate->counters()->math_pow_runtime()->Increment(); | |
67 | |
68 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
69 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | |
70 if (y == 0) { | |
71 return Smi::FromInt(1); | |
72 } else { | |
73 double result = power_double_double(x, y); | |
74 if (std::isnan(result)) return isolate->heap()->nan_value(); | |
75 return *isolate->factory()->NewNumber(result); | |
76 } | |
77 } | |
78 | |
79 | |
80 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { | 38 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { |
81 HandleScope scope(isolate); | 39 HandleScope scope(isolate); |
82 DCHECK(args.length() == 1); | 40 DCHECK(args.length() == 1); |
83 if (isolate->serializer_enabled()) { | 41 if (isolate->serializer_enabled()) { |
84 // Random numbers in the snapshot are not really that random. And we cannot | 42 // Random numbers in the snapshot are not really that random. And we cannot |
85 // return a typed array as it cannot be serialized. To make calling | 43 // return a typed array as it cannot be serialized. To make calling |
86 // Math.random possible when creating a custom startup snapshot, we simply | 44 // Math.random possible when creating a custom startup snapshot, we simply |
87 // return a normal array with a single random number. | 45 // return a normal array with a single random number. |
88 Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber( | 46 Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber( |
89 isolate->random_number_generator()->NextDouble()); | 47 isolate->random_number_generator()->NextDouble()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 base::RandomNumberGenerator::XorShift128(&state0, &state1); | 85 base::RandomNumberGenerator::XorShift128(&state0, &state1); |
128 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); | 86 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); |
129 } | 87 } |
130 // Persist current state. | 88 // Persist current state. |
131 array[kState0Offset] = uint64_to_double(state0); | 89 array[kState0Offset] = uint64_to_double(state0); |
132 array[kState1Offset] = uint64_to_double(state1); | 90 array[kState1Offset] = uint64_to_double(state1); |
133 return *typed_array; | 91 return *typed_array; |
134 } | 92 } |
135 } // namespace internal | 93 } // namespace internal |
136 } // namespace v8 | 94 } // namespace v8 |
OLD | NEW |