From 5f721c3f844579dc391c1a1592c86530bc73384d Mon Sep 17 00:00:00 2001 From: "whesse@chromium.org" Date: Mon, 4 Jul 2011 11:34:29 +0000 Subject: [PATCH] Speed up V8 random number generator, reverting part of 8490. Return to previous random number generator, but mix more bits into output to hide hidden state better. Keep the multithreading fix that moves the PNG into isolate. BUG= TEST= Review URL: http://codereview.chromium.org/7250005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8524 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/isolate.h | 4 ++-- src/v8.cc | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/isolate.h b/src/isolate.h index 3e3bf36..be8141a 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -332,8 +332,8 @@ class HashMap; V(int, bad_char_shift_table, kUC16AlphabetSize) \ V(int, good_suffix_shift_table, (kBMMaxShift + 1)) \ V(int, suffix_table, (kBMMaxShift + 1)) \ - V(uint32_t, random_seed, 4) \ - V(uint32_t, private_random_seed, 4) \ + V(uint32_t, random_seed, 2) \ + V(uint32_t, private_random_seed, 2) \ ISOLATE_INIT_DEBUG_ARRAY_LIST(V) typedef List DebugObjectCache; diff --git a/src/v8.cc b/src/v8.cc index bd902e8..11af057 100644 --- a/src/v8.cc +++ b/src/v8.cc @@ -101,7 +101,7 @@ void V8::TearDown() { static void seed_random(uint32_t* state) { - for (int i = 0; i < 4; ++i) { + for (int i = 0; i < 2; ++i) { state[i] = FLAG_random_seed; while (state[i] == 0) { state[i] = random(); @@ -119,10 +119,8 @@ static uint32_t random_base(uint32_t* state) { // Mix the bits. Never replaces state[i] with 0 if it is nonzero. state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16); state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16); - state[2] = 23208 * (state[2] & 0xFFFF) + (state[2] >> 16); - state[3] = 27753 * (state[3] & 0xFFFF) + (state[3] >> 16); - return ((state[2] ^ state[3]) << 16) + ((state[0] ^ state[1]) & 0xFFFF); + return (state[0] << 14) + (state[1] & 0x3FFFF); } -- 2.7.4