template <typename T>
inline void USE(T) { }
+
+#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
+
+// The following macro works on both 32 and 64-bit platforms.
+// Usage: instead of writing 0x1234567890123456
+// write V8_2PART_UINT64_C(0x12345678,90123456);
+#define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
+
#endif // V8_BASE_MACROS_H_
# define V8_PTR_PREFIX ""
#endif
-// The following macro works on both 32 and 64-bit platforms.
-// Usage: instead of writing 0x1234567890123456
-// write V8_2PART_UINT64_C(0x12345678,90123456);
-#define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
-
#define V8PRIxPTR V8_PTR_PREFIX "x"
#define V8PRIdPTR V8_PTR_PREFIX "d"
#define V8PRIuPTR V8_PTR_PREFIX "u"
RandomNumberGenerator* Isolate::random_number_generator() {
if (random_number_generator_ == NULL) {
- random_number_generator_ = new RandomNumberGenerator;
+ if (FLAG_random_seed != 0) {
+ random_number_generator_ = new RandomNumberGenerator(FLAG_random_seed);
+ } else {
+ random_number_generator_ = new RandomNumberGenerator();
+ }
}
return random_number_generator_;
}
#include <string.h>
#include "src/allocation.h"
+#include "src/base/macros.h"
#include "src/checks.h"
#include "src/globals.h"
#include "src/list.h"
// ----------------------------------------------------------------------------
// General helper functions
-#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
-
// Returns true iff x is a power of 2. Cannot be used with the maximally
// negative value of the type T (the -1 overflows).
template <typename T>
--- /dev/null
+include_rules = [
+ "-src",
+ "+src/base",
+ "+src/platform",
+]
#include <stdio.h>
#include <stdlib.h>
-#include "src/flags.h"
+#include <new>
+
+#include "src/base/macros.h"
#include "src/platform/mutex.h"
#include "src/platform/time.h"
-#include "src/utils.h"
namespace v8 {
namespace internal {
RandomNumberGenerator::RandomNumberGenerator() {
- // Check --random-seed flag first.
- if (FLAG_random_seed != 0) {
- SetSeed(FLAG_random_seed);
- return;
- }
-
// Check if embedder supplied an entropy source.
{ LockGuard<Mutex> lock_guard(entropy_mutex.Pointer());
if (entropy_source != NULL) {
ASSERT_LE(0, max);
// Fast path if max is a power of 2.
- if (IsPowerOf2(max)) {
+ if (IS_POWER_OF_TWO(max)) {
return static_cast<int>((max * static_cast<int64_t>(Next(31))) >> 31);
}
#ifndef V8_UTILS_RANDOM_NUMBER_GENERATOR_H_
#define V8_UTILS_RANDOM_NUMBER_GENERATOR_H_
-#include "src/globals.h"
+#include "src/base/macros.h"
namespace v8 {
namespace internal {
#include "src/v8.h"
#include "src/utils/random-number-generator.h"
+#include "src/isolate-inl.h"
#include "test/cctest/cctest.h"
using namespace v8::internal;
TEST(RandomSeedFlagIsUsed) {
for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) {
FLAG_random_seed = kRandomSeeds[n];
- RandomNumberGenerator rng1;
+ v8::Isolate* i = v8::Isolate::New();
+ RandomNumberGenerator& rng1 =
+ *reinterpret_cast<Isolate*>(i)->random_number_generator();
RandomNumberGenerator rng2(kRandomSeeds[n]);
for (int k = 1; k <= kMaxRuns; ++k) {
int64_t i1, i2;
CHECK_EQ(rng2.NextInt(k), rng1.NextInt(k));
CHECK_EQ(rng2.NextDouble(), rng1.NextDouble());
}
+ i->Dispose();
}
}