ruby: set: replace long by unsigned long

UBSan complains about negative value being shifted
This commit is contained in:
Nilay Vaish 2015-04-29 22:35:22 -05:00
parent 4333549575
commit 3a2731fb8c
3 changed files with 18 additions and 14 deletions

View file

@ -73,9 +73,9 @@ Set::clearExcess()
{ {
// now just ensure that no bits over the maximum size were set // now just ensure that no bits over the maximum size were set
#ifdef _LP64 #ifdef _LP64
long mask = 0x7FFFFFFFFFFFFFFF; unsigned long mask = 0x7FFFFFFFFFFFFFFF;
#else #else
long mask = 0x7FFFFFFF; unsigned long mask = 0x7FFFFFFF;
#endif #endif
// the number of populated spaces in the higest-order array slot // the number of populated spaces in the higest-order array slot
@ -132,10 +132,9 @@ int
Set::count() const Set::count() const
{ {
int counter = 0; int counter = 0;
long mask;
for (int i = 0; i < m_nArrayLen; i++) { for (int i = 0; i < m_nArrayLen; i++) {
mask = (long)0x01; unsigned long mask = 0x01;
for (int j = 0; j < LONG_BITS; j++) { for (int j = 0; j < LONG_BITS; j++) {
// FIXME - significant performance loss when array // FIXME - significant performance loss when array
@ -172,14 +171,13 @@ NodeID
Set::smallestElement() const Set::smallestElement() const
{ {
assert(count() > 0); assert(count() > 0);
long x;
for (int i = 0; i < m_nArrayLen; i++) { for (int i = 0; i < m_nArrayLen; i++) {
if (m_p_nArray[i] != 0) { if (m_p_nArray[i] != 0) {
// the least-set bit must be in here // the least-set bit must be in here
x = m_p_nArray[i]; unsigned long x = m_p_nArray[i];
for (int j = 0; j < LONG_BITS; j++) { for (int j = 0; j < LONG_BITS; j++) {
if (x & (unsigned long)1) { if (x & 1) {
return LONG_BITS * i + j; return LONG_BITS * i + j;
} }
@ -212,7 +210,7 @@ Set::isBroadcast() const
} }
// now check the last word, which may not be fully loaded // now check the last word, which may not be fully loaded
long mask = 1; unsigned long mask = 1;
for (int j = 0; j < (m_nSize % LONG_BITS); j++) { for (int j = 0; j < (m_nSize % LONG_BITS); j++) {
if ((mask & m_p_nArray[m_nArrayLen-1]) == 0) { if ((mask & m_p_nArray[m_nArrayLen-1]) == 0) {
return false; return false;
@ -306,7 +304,7 @@ Set::setSize(int size)
if (m_p_nArray && m_p_nArray != &m_p_nArray_Static[0]) if (m_p_nArray && m_p_nArray != &m_p_nArray_Static[0])
delete [] m_p_nArray; delete [] m_p_nArray;
m_p_nArray = new long[m_nArrayLen]; m_p_nArray = new unsigned long[m_nArrayLen];
} }
clear(); clear();

View file

@ -62,10 +62,12 @@ class Set
// 64 bits if the -m64 parameter is passed to g++, which it is // 64 bits if the -m64 parameter is passed to g++, which it is
// for an AMD opteron under our configuration // for an AMD opteron under our configuration
long *m_p_nArray; // an word array to hold the bits in the set // an word array to hold the bits in the set
long m_p_nArray_Static[NUMBER_WORDS_PER_SET]; unsigned long *m_p_nArray;
unsigned long m_p_nArray_Static[NUMBER_WORDS_PER_SET];
static const int LONG_BITS = std::numeric_limits<long>::digits + 1; static const int LONG_BITS =
std::numeric_limits<unsigned long>::digits + 1;
static const int INDEX_SHIFT = LONG_BITS == 64 ? 6 : 5; static const int INDEX_SHIFT = LONG_BITS == 64 ? 6 : 5;
static const int INDEX_MASK = (1 << INDEX_SHIFT) - 1; static const int INDEX_MASK = (1 << INDEX_SHIFT) - 1;

View file

@ -31,6 +31,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <stack>
#include "mem/packet.hh" #include "mem/packet.hh"
@ -44,12 +45,14 @@ class Message
: m_time(curTime), : m_time(curTime),
m_LastEnqueueTime(curTime), m_LastEnqueueTime(curTime),
m_DelayedTicks(0) m_DelayedTicks(0)
{ } {
timeStamps.push(curTime);
}
Message(const Message &other) Message(const Message &other)
: m_time(other.m_time), : m_time(other.m_time),
m_LastEnqueueTime(other.m_LastEnqueueTime), m_LastEnqueueTime(other.m_LastEnqueueTime),
m_DelayedTicks(other.m_DelayedTicks) m_DelayedTicks(other.m_DelayedTicks), timeStamps(other.timeStamps)
{ } { }
virtual ~Message() { } virtual ~Message() { }
@ -90,6 +93,7 @@ class Message
Tick m_time; Tick m_time;
Tick m_LastEnqueueTime; // my last enqueue time Tick m_LastEnqueueTime; // my last enqueue time
Tick m_DelayedTicks; // my delayed cycles Tick m_DelayedTicks; // my delayed cycles
std::stack<Tick> timeStamps;
}; };
inline std::ostream& inline std::ostream&