changeset 9ea24d102d66 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=9ea24d102d66
description:
        style: clean up ruby's Set class

        Further cleanup should probably be done to make this class be non-Ruby
        specific and put it in src/base.

        There are probably several cases where this class is used, std::bitset
        could be used instead.

diffstat:

 src/mem/ruby/common/NetDest.cc |    2 +-
 src/mem/ruby/common/Set.cc     |  651 +++++++++++++---------------------------
 src/mem/ruby/common/Set.hh     |  212 +++++--------
 3 files changed, 301 insertions(+), 564 deletions(-)

diffs (truncated from 1062 to 300 lines):

diff -r 84bd4089958b -r 9ea24d102d66 src/mem/ruby/common/NetDest.cc
--- a/src/mem/ruby/common/NetDest.cc    Tue May 25 20:15:44 2010 -0700
+++ b/src/mem/ruby/common/NetDest.cc    Tue Jun 01 11:38:56 2010 -0700
@@ -222,7 +222,7 @@
 {
     assert(m_bits.size() == other_netDest.getSize());
     for (int i = 0; i < m_bits.size(); i++) {
-        if (m_bits[i].intersectionIsNotEmpty(other_netDest.m_bits[i])) {
+        if (!m_bits[i].intersectionIsEmpty(other_netDest.m_bits[i])) {
             return true;
         }
     }
diff -r 84bd4089958b -r 9ea24d102d66 src/mem/ruby/common/Set.cc
--- a/src/mem/ruby/common/Set.cc        Tue May 25 20:15:44 2010 -0700
+++ b/src/mem/ruby/common/Set.cc        Tue Jun 01 11:38:56 2010 -0700
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
  * All rights reserved.
@@ -27,554 +26,340 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Set.cc
- *
- * Description: See Set.hh
- *
- * $Id: BigSet.cc 1.9 05/01/19 13:12:25-06:00 mi...@maya.cs.wisc.edu $
- *
- */
-
-// modified (rewritten) 05/20/05 by Dan Gibson to accomimdate FASTER >32 bit
-// set sizes
+// modified (rewritten) 05/20/05 by Dan Gibson to accomimdate FASTER
+// >32 bit set sizes
 
 #include "mem/ruby/common/Set.hh"
 #include "mem/ruby/system/System.hh"
 
-#if __amd64__ || __LP64__
-#define __64BITS__
-#else
-#define __32BITS__
-#endif
-
 Set::Set()
 {
-  m_p_nArray = NULL;
-  m_nArrayLen = 0;
-  m_nSize = 0;
+    m_p_nArray = NULL;
+    m_nArrayLen = 0;
+    m_nSize = 0;
 }
 
-// copy constructor
-Set::Set(const Set& obj) {
-  m_p_nArray = NULL;
-  setSize(obj.m_nSize);
+Set::Set(const Set& obj)
+{
+    m_p_nArray = NULL;
+    setSize(obj.m_nSize);
 
-  // copy from the host to this array
-  for(int i=0; i<m_nArrayLen; i++) {
-    m_p_nArray[i] = obj.m_p_nArray[i];
-  }
-
+    // copy from the host to this array
+    for (int i = 0; i < m_nArrayLen; i++)
+        m_p_nArray[i] = obj.m_p_nArray[i];
 }
 
 Set::Set(int size)
 {
-  m_p_nArray = NULL;
-  m_nArrayLen = 0;
-  m_nSize = 0;
-  if(size > 0) {
-    setSize(size);
-  }
+    m_p_nArray = NULL;
+    m_nArrayLen = 0;
+    m_nSize = 0;
+    if (size > 0)
+        setSize(size);
 }
 
-Set::~Set() {
-  if( (m_p_nArray != (&m_p_nArray_Static[0])) && (m_p_nArray != NULL))
-    delete [] m_p_nArray;
-  m_p_nArray = NULL;
+Set::~Set()
+{
+    if (m_p_nArray && m_p_nArray != &m_p_nArray_Static[0])
+        delete [] m_p_nArray;
+    m_p_nArray = NULL;
 }
 
+void
+Set::clearExcess()
+{
+    // now just ensure that no bits over the maximum size were set
+#ifdef _LP64
+    long mask = 0x7FFFFFFFFFFFFFFF;
+#else
+    long mask = 0x7FFFFFFF;
+#endif
 
-// /*
-//  * This function should set the bit corresponding to index
-//  * to 1.
-//  */
+    // the number of populated spaces in the higest-order array slot
+    // is: m_nSize % LONG_BITS, so the uppermost LONG_BITS -
+    // m_nSize%64 bits should be cleared
+    if ((m_nSize % LONG_BITS) != 0) {
+        for (int j = 0; j < 64 - (m_nSize & INDEX_MASK); j++) {
+            m_p_nArray[m_nArrayLen - 1] &= mask;
+            mask = mask >> 1;
+        }
+    }
+}
 
-// void Set::add(NodeID index)
-// {
-//   assert(index<m_nSize && index >= 0);
-
-// #ifdef __32BITS__
-//   m_p_nArray[index>>5] |= (1 << (index & 0x01F));
-// #else
-//   m_p_nArray[index>>6] |= (((unsigned long) 1) << (index & 0x03F));
-// #endif // __32BITS__
-
-// }
 
 /*
- * This function should set all the bits in the current set
- * that are already set in the parameter set
+ * This function should set all the bits in the current set that are
+ * already set in the parameter set
  */
-void Set::addSet(const Set& set)
+void
+Set::addSet(const Set& set)
 {
-  assert(getSize()==set.getSize());
-  for(int i=0; i<m_nArrayLen; i++) {
-    m_p_nArray[i] |= set.m_p_nArray[i];
-  }
-
+    assert(getSize()==set.getSize());
+    for (int i = 0; i < m_nArrayLen; i++)
+        m_p_nArray[i] |= set.m_p_nArray[i];
 }
 
 /*
- * This function should randomly assign 1 to the bits in the set--
- * it should not clear the bits bits first, though?
+ * This function should randomly assign 1 to the bits in the set--it
+ * should not clear the bits bits first, though?
  */
-void Set::addRandom()
+void
+Set::addRandom()
 {
 
-  for(int i=0; i<m_nArrayLen; i++) {
-    m_p_nArray[i] |= random() ^ (random() << 4); // this ensures that all 32 
bits are subject to random effects,
-                                                 // as RAND_MAX typically = 
0x7FFFFFFF
-  }
-
-  // now just ensure that no bits over the maximum size were set
-#ifdef __32BITS__
-  long mask = 0x7FFFFFFF;
-
-  // the number of populated spaces in the higest-order array slot is:
-  // m_nSize % 32, so the uppermost 32 - m_nSize%32 bits should be
-  // cleared
-
-  if((m_nSize % 32) != 0) {
-    for(int j=0; j<32-(m_nSize&0x01F); j++) {
-      m_p_nArray[m_nArrayLen-1] &= mask;
-      mask = mask >> 1;
+    for (int i = 0; i < m_nArrayLen; i++) {
+        // this ensures that all 32 bits are subject to random effects,
+        // as RAND_MAX typically = 0x7FFFFFFF
+        m_p_nArray[i] |= random() ^ (random() << 4);
     }
-  }
-#else
-  long mask = 0x7FFFFFFFFFFFFFFF;
-
-  // the number of populated spaces in the higest-order array slot is:
-  // m_nSize % 64, so the uppermost 64 - m_nSize%64 bits should be
-  // cleared
-
-  if((m_nSize % 64) != 0) {
-    for(int j=0; j<64-(m_nSize&0x03F); j++) {
-      m_p_nArray[m_nArrayLen-1] &= mask;
-      mask = mask >> 1;
-    }
-  }
-#endif // __32BITS__
-
+    clearExcess();
 }
 
-// /*
-//  * This function unsets the bit associated with index
-//  */
-// void Set::remove(NodeID index)
-// {
-//   assert(index<m_nSize && index>=0);
-
-// #ifdef __32BITS__
-//   m_p_nArray[index>>5] &= ~(0x00000001         << (index & 0x01F));
-// #else
-//   m_p_nArray[index>>6] &= ~(((unsigned long) 0x0000000000000001) << (index 
& 0x03F));
-// #endif // __32BITS__
-
-// }
-
-
 /*
  * This function clears bits that are =1 in the parameter set
  */
-void Set::removeSet(const Set& set)
+void
+Set::removeSet(const Set& set)
 {
-
-  assert(m_nSize==set.m_nSize);
-  for(int i=0; i<m_nArrayLen; i++) {
-    m_p_nArray[i] &= ~(set.m_p_nArray[i]);
-  }
-
+    assert(m_nSize == set.m_nSize);
+    for (int i = 0; i < m_nArrayLen; i++)
+        m_p_nArray[i] &= ~set.m_p_nArray[i];
 }
 
-// /*
-//  * This function clears all bits in the set
-//  */
-// void Set::clear()
-// {
-//   for(int i=0; i<m_nArrayLen; i++) {
-//     m_p_nArray[i] = 0;
-//   }
-// }
-
 /*
  * this function sets all bits in the set
  */
-void Set::broadcast()
+void
+Set::broadcast()
 {
+    for (int i = 0; i < m_nArrayLen; i++)
+        m_p_nArray[i] = -1; // note that -1 corresponds to all 1's in 2's comp.
 
-  for(int i=0; i<m_nArrayLen; i++) {
-    m_p_nArray[i] = -1; // note that -1 corresponds to all 1's in 2's comp.
-  }
-
-  // now just ensure that no bits over the maximum size were set
-#ifdef __32BITS__
-  long mask = 0x7FFFFFFF;
-
-  // the number of populated spaces in the higest-order array slot is:
-  // m_nSize % 32, so the uppermost 32 - m_nSize%32 bits should be
-  // cleared
-
-  if((m_nSize % 32) != 0) {
-    for(int j=0; j<32-(m_nSize&0x01F); j++) {
-      m_p_nArray[m_nArrayLen-1] &= mask;
-      mask = mask >> 1;
-    }
-  }
-#else
-  long mask = 0x7FFFFFFFFFFFFFFF;
-
-  // the number of populated spaces in the higest-order array slot is:
-  // m_nSize % 64, so the uppermost 64 - m_nSize%64 bits should be
-  // cleared
-
-  if((m_nSize % 64) != 0) {
-    for(int j=0; j<64-(m_nSize&0x03F); j++) {
-      m_p_nArray[m_nArrayLen-1] &= mask;
-      mask = mask >> 1;
-    }
-  }
-#endif // __32BITS__
-
+    clearExcess();
 }
_______________________________________________
m5-dev mailing list
m5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to