Ruby: Use uint32_t instead of uint32 everywhere
[gem5.git] / src / mem / ruby / common / DataBlock.cc
index c4d6d7a332b24b26c8b53ebc3b2f3b3a9db31e28..c71449dd028426b5ec46f3f375f4d458aab9ede7 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
  * All rights reserved.
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * $Id$
- */
-
-#include "DataBlock.hh"
+#include "mem/ruby/common/DataBlock.hh"
+#include "mem/ruby/system/System.hh"
 
-DataBlock::DataBlock()
+DataBlock::DataBlock(const DataBlock &cp)
 {
-  if (DATA_BLOCK || XACT_MEMORY) {
-    m_data.setSize(RubyConfig::dataBlockBytes());
-  }
-  clear();
+    m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
+    memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes());
+    m_alloc = true;
 }
 
-DataBlock::~DataBlock()
+void
+DataBlock::alloc()
 {
-
+    m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
+    m_alloc = true;
+    clear();
 }
 
-void DataBlock::clear()
+void
+DataBlock::clear()
 {
-  int size = m_data.size();
-  for (int i = 0; i < size; i++) {
-    m_data[i] = 0;
-  }
+    memset(m_data, 0, RubySystem::getBlockSizeBytes());
 }
 
-bool DataBlock::equal(const DataBlock& obj) const
+bool
+DataBlock::equal(const DataBlock& obj) const
 {
-  bool value = true;
-  int size = m_data.size();
-  for (int i = 0; i < size; i++) {
-    value = value && (m_data[i] == obj.m_data[i]);
-  }
-  return value;
+    return !memcmp(m_data, obj.m_data, RubySystem::getBlockSizeBytes());
 }
 
-void DataBlock::print(ostream& out) const
+void
+DataBlock::print(std::ostream& out) const
 {
-  int size = m_data.size();
-  for (int i = 0; i < size; i+=4) {
-    out << hex << *((uint32*)(&(m_data[i]))) << " ";
-  }
-  out << dec << "]" << flush;
+    using namespace std;
+
+    int size = RubySystem::getBlockSizeBytes();
+    out << "[ ";
+    for (int i = 0; i < size; i++) {
+        out << setw(2) << setfill('0') << hex << "0x" << (int)m_data[i] << " ";
+        out << setfill(' ');
+    }
+    out << dec << "]" << flush;
 }
 
-uint8 DataBlock::getByte(int whichByte) const
+const uint8_t*
+DataBlock::getData(int offset, int len) const
 {
-  if (DATA_BLOCK || XACT_MEMORY) {
-  return m_data[whichByte];
-  } else {
-    return 0;
-  }
+    assert(offset + len <= RubySystem::getBlockSizeBytes());
+    return &m_data[offset];
 }
 
-void DataBlock::setByte(int whichByte, uint8 data)
+void
+DataBlock::setData(uint8_t *data, int offset, int len)
 {
-  if (DATA_BLOCK || XACT_MEMORY) {
-    m_data[whichByte] = data;
-  }
+    assert(offset + len <= RubySystem::getBlockSizeBytes());
+    memcpy(&m_data[offset], data, len);
 }
 
+DataBlock &
+DataBlock::operator=(const DataBlock & obj)
+{
+    memcpy(m_data, obj.m_data, RubySystem::getBlockSizeBytes());
+    return *this;
+}