changeset f1a69b7246f7 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=f1a69b7246f7
description:
Base: Fixed shift amount in genrand() to work with large numbers
The previous version didn't work correctly with max integer values
(2^31-1 for
32-bit, 2^63-1 for 64bit version), causing "shift" to become -1. For
smaller
numbers, it wouldn't have caused functional errors, but would have
resulted in
more than necessary loops in the while loop. Special-cased cases when
(max + 1
== 0) to prevent the ceilLog2 functions from failing.
diffstat:
src/base/random.cc | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diffs (35 lines):
diff -r 776bc26ee1d4 -r f1a69b7246f7 src/base/random.cc
--- a/src/base/random.cc Mon Jan 09 18:08:20 2012 -0600
+++ b/src/base/random.cc Mon Jan 09 18:08:20 2012 -0600
@@ -29,6 +29,7 @@
* Ali Saidi
*/
+#include <limits>
#include "base/fenv.hh"
#include "base/intmath.hh"
#include "base/misc.hh"
@@ -67,7 +68,10 @@
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint32_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint32_t) * 8 - log);
uint32_t random;
@@ -83,7 +87,10 @@
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint64_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint64_t) * 8 - log);
uint64_t random;
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev