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

Side by Side Diff: src/v8.cc

Issue 7250005: Speed up V8 random number generator, reverting part of 8490. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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
« no previous file with comments | « src/isolate.h ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 if (!has_been_setup_ || has_been_disposed_) return; 95 if (!has_been_setup_ || has_been_disposed_) return;
96 isolate->TearDown(); 96 isolate->TearDown();
97 97
98 is_running_ = false; 98 is_running_ = false;
99 has_been_disposed_ = true; 99 has_been_disposed_ = true;
100 } 100 }
101 101
102 102
103 static void seed_random(uint32_t* state) { 103 static void seed_random(uint32_t* state) {
104 for (int i = 0; i < 4; ++i) { 104 for (int i = 0; i < 2; ++i) {
105 state[i] = FLAG_random_seed; 105 state[i] = FLAG_random_seed;
106 while (state[i] == 0) { 106 while (state[i] == 0) {
107 state[i] = random(); 107 state[i] = random();
108 } 108 }
109 } 109 }
110 } 110 }
111 111
112 112
113 // Random number generator using George Marsaglia's MWC algorithm. 113 // Random number generator using George Marsaglia's MWC algorithm.
114 static uint32_t random_base(uint32_t* state) { 114 static uint32_t random_base(uint32_t* state) {
115 // Initialize seed using the system random(). 115 // Initialize seed using the system random().
116 // No non-zero seed will ever become zero again. 116 // No non-zero seed will ever become zero again.
117 if (state[0] == 0) seed_random(state); 117 if (state[0] == 0) seed_random(state);
118 118
119 // Mix the bits. Never replaces state[i] with 0 if it is nonzero. 119 // Mix the bits. Never replaces state[i] with 0 if it is nonzero.
120 state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16); 120 state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16);
121 state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16); 121 state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
122 state[2] = 23208 * (state[2] & 0xFFFF) + (state[2] >> 16);
123 state[3] = 27753 * (state[3] & 0xFFFF) + (state[3] >> 16);
124 122
125 return ((state[2] ^ state[3]) << 16) + ((state[0] ^ state[1]) & 0xFFFF); 123 return (state[0] << 14) + (state[1] & 0x3FFFF);
126 } 124 }
127 125
128 126
129 // Used by JavaScript APIs 127 // Used by JavaScript APIs
130 uint32_t V8::Random(Isolate* isolate) { 128 uint32_t V8::Random(Isolate* isolate) {
131 ASSERT(isolate == Isolate::Current()); 129 ASSERT(isolate == Isolate::Current());
132 return random_base(isolate->random_seed()); 130 return random_base(isolate->random_seed());
133 } 131 }
134 132
135 133
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 use_crankshaft_ = false; 194 use_crankshaft_ = false;
197 } 195 }
198 196
199 RuntimeProfiler::GlobalSetup(); 197 RuntimeProfiler::GlobalSetup();
200 198
201 // Peephole optimization might interfere with deoptimization. 199 // Peephole optimization might interfere with deoptimization.
202 FLAG_peephole_optimization = !use_crankshaft_; 200 FLAG_peephole_optimization = !use_crankshaft_;
203 } 201 }
204 202
205 } } // namespace v8::internal 203 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698