changeset 0002812cefe5 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=0002812cefe5
description:
        BASE: Fix genrand to generate both 0s and 1s when max equals one.
        previously was only generating 0s.

diffstat:

 src/base/random.cc |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (25 lines):

diff -r f5742240963f -r 0002812cefe5 src/base/random.cc
--- a/src/base/random.cc        Mon Aug 23 11:18:39 2010 -0500
+++ b/src/base/random.cc        Mon Aug 23 11:18:39 2010 -0500
@@ -65,7 +65,9 @@
 uint32_t
 Random::genrand(uint32_t max)
 {
-    int log = ceilLog2(max);
+    if (max == 0)
+        return 0;
+    int log = ceilLog2(max) + 1;
     int shift = (sizeof(uint32_t) * 8 - log);
     uint32_t random;
 
@@ -79,7 +81,9 @@
 uint64_t
 Random::genrand(uint64_t max)
 {
-    int log = ceilLog2(max);
+    if (max == 0)
+        return 0;
+    int log = ceilLog2(max) + 1;
     int shift = (sizeof(uint64_t) * 8 - log);
     uint64_t random;
 
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to