| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return *number; | 207 return *number; |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); | 210 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); |
| 211 | 211 |
| 212 // Do not call NumberFromDouble() to avoid extra checks. | 212 // Do not call NumberFromDouble() to avoid extra checks. |
| 213 return *isolate->factory()->NewNumber(Floor(value + 0.5)); | 213 return *isolate->factory()->NewNumber(Floor(value + 0.5)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 | 216 |
| 217 RUNTIME_FUNCTION(Runtime_MathSqrt) { | |
| 218 HandleScope scope(isolate); | |
| 219 DCHECK(args.length() == 1); | |
| 220 isolate->counters()->math_sqrt_runtime()->Increment(); | |
| 221 | |
| 222 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
| 223 lazily_initialize_fast_sqrt(isolate); | |
| 224 return *isolate->factory()->NewNumber(fast_sqrt(x, isolate)); | |
| 225 } | |
| 226 | |
| 227 | |
| 228 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { | 217 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { |
| 229 HandleScope scope(isolate); | 218 HandleScope scope(isolate); |
| 230 DCHECK(args.length() == 1); | 219 DCHECK(args.length() == 1); |
| 231 if (isolate->serializer_enabled()) { | 220 if (isolate->serializer_enabled()) { |
| 232 // Random numbers in the snapshot are not really that random. And we cannot | 221 // Random numbers in the snapshot are not really that random. And we cannot |
| 233 // return a typed array as it cannot be serialized. To make calling | 222 // return a typed array as it cannot be serialized. To make calling |
| 234 // Math.random possible when creating a custom startup snapshot, we simply | 223 // Math.random possible when creating a custom startup snapshot, we simply |
| 235 // return a normal array with a single random number. | 224 // return a normal array with a single random number. |
| 236 Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber( | 225 Handle<HeapNumber> random_number = isolate->factory()->NewHeapNumber( |
| 237 isolate->random_number_generator()->NextDouble()); | 226 isolate->random_number_generator()->NextDouble()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 base::RandomNumberGenerator::XorShift128(&state0, &state1); | 264 base::RandomNumberGenerator::XorShift128(&state0, &state1); |
| 276 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); | 265 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); |
| 277 } | 266 } |
| 278 // Persist current state. | 267 // Persist current state. |
| 279 array[kState0Offset] = uint64_to_double(state0); | 268 array[kState0Offset] = uint64_to_double(state0); |
| 280 array[kState1Offset] = uint64_to_double(state1); | 269 array[kState1Offset] = uint64_to_double(state1); |
| 281 return *typed_array; | 270 return *typed_array; |
| 282 } | 271 } |
| 283 } // namespace internal | 272 } // namespace internal |
| 284 } // namespace v8 | 273 } // namespace v8 |
| OLD | NEW |