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" |
11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { | 16 RUNTIME_FUNCTION(Runtime_GenerateRandomNumbers) { |
17 HandleScope scope(isolate); | 17 HandleScope scope(isolate); |
18 DCHECK(args.length() == 0); | 18 DCHECK_EQ(0, args.length()); |
19 | 19 |
20 Handle<Context> native_context = isolate->native_context(); | 20 Handle<Context> native_context = isolate->native_context(); |
21 DCHECK_EQ(0, native_context->math_random_index()->value()); | 21 DCHECK_EQ(0, native_context->math_random_index()->value()); |
22 | 22 |
23 static const int kCacheSize = 64; | 23 static const int kCacheSize = 64; |
24 static const int kState0Offset = kCacheSize - 1; | 24 static const int kState0Offset = kCacheSize - 1; |
25 static const int kState1Offset = kState0Offset - 1; | 25 static const int kState1Offset = kState0Offset - 1; |
26 // The index is decremented before used to access the cache. | 26 // The index is decremented before used to access the cache. |
27 static const int kInitialIndex = kState1Offset; | 27 static const int kInitialIndex = kState1Offset; |
28 | 28 |
(...skipping 25 matching lines...) Expand all Loading... |
54 raw_cache->set(i, base::RandomNumberGenerator::ToDouble(state0, state1)); | 54 raw_cache->set(i, base::RandomNumberGenerator::ToDouble(state0, state1)); |
55 } | 55 } |
56 | 56 |
57 // Persist current state. | 57 // Persist current state. |
58 raw_cache->set(kState0Offset, uint64_to_double(state0)); | 58 raw_cache->set(kState0Offset, uint64_to_double(state0)); |
59 raw_cache->set(kState1Offset, uint64_to_double(state1)); | 59 raw_cache->set(kState1Offset, uint64_to_double(state1)); |
60 return Smi::FromInt(kInitialIndex); | 60 return Smi::FromInt(kInitialIndex); |
61 } | 61 } |
62 } // namespace internal | 62 } // namespace internal |
63 } // namespace v8 | 63 } // namespace v8 |
OLD | NEW |