Changeset 145179 in webkit
- Timestamp:
- Mar 7, 2013 9:49:46 PM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/ThirdParty/ChangeLog
r143529 r145179 1 2013-03-07 Andrew Bortz <andrew@abortz.net> 2 3 Replace Mersenne Twister RNG with a simple but fast RNG 4 https://bugs.webkit.org/show_bug.cgi?id=111533 5 6 Reviewed by Adam Barth. 7 8 This code is no longer used. 9 10 * mt19937ar.c: Removed. 11 1 12 2013-02-20 Roger Fong <roger_fong@apple.com> 2 13 -
trunk/Source/WTF/ChangeLog
r145022 r145179 1 2013-03-07 Andrew Bortz <andrew@abortz.net> 2 3 Replace Mersenne Twister random number generator with a simpler one. 4 https://bugs.webkit.org/show_bug.cgi?id=111533 5 6 Reviewed by Adam Barth. 7 8 The new generator is only a single line long, but passes all the Diehard 9 statistical tests and runs ~3x faster than the Mersenne Twister, with a 10 guaranteed cycle length of 2^64 and only 8 bytes of state. 11 12 * wtf/Platform.h: Mersenne Twister defines are no longer needed 13 * wtf/RandomNumber.cpp: 14 (WTF::Internal::initializeRandomNumber): State initialization 15 (WTF::Internal::randomNumber): Actual implementation 16 (WTF::randomNumber): We don't need to fall back on rand()-based generator anymore, 17 so this code is greatly simplified. 18 * wtf/RandomNumber.h: 19 * wtf/RandomNumberSeed.h: 20 (WTF::initializeRandomNumberGenerator): This code is no longer needed. 21 Additionally, the code had an error, since rand() returns 32-bits, so each 22 initializationBuffer's upper 16-bits has more bits set than random. 23 1 24 2013-03-06 Adenilson Cavalcanti <cavalcantii@gmail.com> 2 25 -
trunk/Source/WTF/wtf/Platform.h
r144337 r145179 503 503 504 504 #if PLATFORM(BLACKBERRY) 505 #define WTF_USE_MERSENNE_TWISTER_19937 1506 505 #define WTF_USE_SKIA 1 507 506 #define WTF_USE_LOW_QUALITY_IMAGE_INTERPOLATION 1 … … 513 512 #define WTF_USE_CAIRO 1 514 513 #define ENABLE_GLOBAL_FASTMALLOC_NEW 0 515 #endif516 517 518 #if OS(WINCE)519 #define WTF_USE_MERSENNE_TWISTER_19937 1520 514 #endif 521 515 -
trunk/Source/WTF/wtf/RandomNumber.cpp
r111778 r145179 2 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 4 * Copyright (C) 2013 Andrew Bortz. All rights reserved. 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without … … 36 37 #include <stdlib.h> 37 38 38 #if USE(MERSENNE_TWISTER_19937) 39 extern "C" { 40 #include "mt19937ar.c" 39 namespace WTF { 40 41 #if !USE(OS_RANDOMNESS) 42 namespace Internal { 43 44 static uint64_t state; 45 46 void initializeRandomNumber(uint64_t seed) 47 { 48 state = seed; 49 } 50 51 // This random number generator comes from: Klimov, A. and Shamir, A., 52 // "A New Class of Invertible Mappings", Cryptographic Hardware and Embedded 53 // Systems 2002, http://dl.acm.org/citation.cfm?id=752741 54 // 55 // Very fast, very simple, and passes Diehard and other good statistical 56 // tests as strongly as cryptographically-secure random number generators (but 57 // is not itself cryptographically-secure). 58 uint32_t randomNumber() 59 { 60 state += (state * state) | 5; 61 return static_cast<uint32_t>(state >> 32); 62 } 63 41 64 } 42 65 #endif 43 44 namespace WTF {45 66 46 67 double randomNumber() … … 48 69 #if USE(OS_RANDOMNESS) 49 70 uint32_t bits = cryptographicallyRandomNumber(); 71 #else 72 uint32_t bits = Internal::randomNumber(); 73 #endif 50 74 return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0); 51 #else52 // Without OS_RANDOMNESS, we fall back to other random number generators53 // that might not be cryptographically secure. Ideally, most ports would54 // define USE(OS_RANDOMNESS).55 56 #if USE(MERSENNE_TWISTER_19937)57 return genrand_res53();58 #else59 uint32_t part1 = rand() & (RAND_MAX - 1);60 uint32_t part2 = rand() & (RAND_MAX - 1);61 // rand only provides 31 bits, and the low order bits of that aren't very random62 // so we take the high 26 bits of part 1, and the high 27 bits of part2.63 part1 >>= 5; // drop the low 5 bits64 part2 >>= 4; // drop the low 4 bits65 uint64_t fullRandom = part1;66 fullRandom <<= 27;67 fullRandom |= part2;68 69 // Mask off the low 53bits70 fullRandom &= (1LL << 53) - 1;71 return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);72 #endif73 #endif74 75 } 75 76 -
trunk/Source/WTF/wtf/RandomNumber.h
r111778 r145179 29 29 namespace WTF { 30 30 31 // Returns a pseudo-random number in the range [0, 1), attempts to be 32 // cryptographically secure if possible on the target platform 33 WTF_EXPORT_PRIVATE double randomNumber(); 31 #if !USE(OS_RANDOMNESS) 32 namespace Internal { 33 void initializeRandomNumber(uint64_t); 34 } 35 #endif 36 37 // Returns a pseudo-random number in the range [0, 1), attempts to be 38 // cryptographically secure if possible on the target platform 39 WTF_EXPORT_PRIVATE double randomNumber(); 34 40 35 41 } -
trunk/Source/WTF/wtf/RandomNumberSeed.h
r111778 r145179 27 27 #define WTF_RandomNumberSeed_h 28 28 29 #include "RandomNumber.h" 29 30 #include <stdlib.h> 30 31 #include <time.h> … … 39 40 #endif 40 41 41 #if USE(MERSENNE_TWISTER_19937)42 extern "C" {43 void init_by_array(unsigned long init_key[],int key_length);44 }45 #endif46 47 // Internal JavaScriptCore usage only48 42 namespace WTF { 49 43 … … 66 60 #endif 67 61 68 #if USE(MERSENNE_TWISTER_19937) 69 // use rand() to initialize the Mersenne Twister random number generator. 70 unsigned long initializationBuffer[4]; 71 initializationBuffer[0] = (rand() << 16) | rand(); 72 initializationBuffer[1] = (rand() << 16) | rand(); 73 initializationBuffer[2] = (rand() << 16) | rand(); 74 initializationBuffer[3] = (rand() << 16) | rand(); 75 init_by_array(initializationBuffer, 4); 62 #if !USE(OS_RANDOMNESS) 63 uint64_t seed = static_cast<uint64_t>(rand()) << 32 | static_cast<uint64_t>(rand()); 64 Internal::initializeRandomNumber(seed); 76 65 #endif 77 66 }
Note: See TracChangeset
for help on using the changeset viewer.