Ruby: Use uint8_t instead of uint8 everywhere

This commit is contained in:
Nilay Vaish 2012-09-11 09:23:56 -05:00
parent 5cdf221d8c
commit f00347a20f
11 changed files with 52 additions and 54 deletions

View file

@ -189,7 +189,7 @@ Check::initiateAction()
// } // }
PacketPtr pkt = new Packet(req, cmd); PacketPtr pkt = new Packet(req, cmd);
uint8_t* writeData = new uint8_t; uint8_t *writeData = new uint8_t;
*writeData = m_value + m_store_count; *writeData = m_value + m_store_count;
pkt->dataDynamic(writeData); pkt->dataDynamic(writeData);
@ -245,7 +245,7 @@ Check::initiateCheck()
req->setThreadContext(index, 0); req->setThreadContext(index, 0);
PacketPtr pkt = new Packet(req, MemCmd::ReadReq); PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
uint8_t* dataArray = new uint8_t[CHECK_SIZE]; uint8_t *dataArray = new uint8_t[CHECK_SIZE];
pkt->dataDynamicArray(dataArray); pkt->dataDynamicArray(dataArray);
// push the subblock onto the sender state. The sequencer will // push the subblock onto the sender state. The sequencer will
@ -306,7 +306,7 @@ Check::performCallback(NodeID proc, SubBlock* data)
DPRINTF(RubyTest, "Check callback\n"); DPRINTF(RubyTest, "Check callback\n");
// Perform load/check // Perform load/check
for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) { for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
if (uint8(m_value + byte_number) != data->getByte(byte_number)) { if (uint8_t(m_value + byte_number) != data->getByte(byte_number)) {
panic("Action/check failure: proc: %d address: %s data: %s " panic("Action/check failure: proc: %d address: %s data: %s "
"byte_number: %d m_value+byte_number: %d byte: %d %s" "byte_number: %d m_value+byte_number: %d byte: %d %s"
"Time: %d\n", "Time: %d\n",

View file

@ -68,7 +68,7 @@ class Check
void debugPrint(); void debugPrint();
TesterStatus m_status; TesterStatus m_status;
uint8 m_value; uint8_t m_value;
int m_store_count; int m_store_count;
NodeID m_initiatingNode; NodeID m_initiatingNode;
Address m_address; Address m_address;

View file

@ -31,7 +31,7 @@
DataBlock::DataBlock(const DataBlock &cp) DataBlock::DataBlock(const DataBlock &cp)
{ {
m_data = new uint8[RubySystem::getBlockSizeBytes()]; m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes()); memcpy(m_data, cp.m_data, RubySystem::getBlockSizeBytes());
m_alloc = true; m_alloc = true;
} }
@ -39,7 +39,7 @@ DataBlock::DataBlock(const DataBlock &cp)
void void
DataBlock::alloc() DataBlock::alloc()
{ {
m_data = new uint8[RubySystem::getBlockSizeBytes()]; m_data = new uint8_t[RubySystem::getBlockSizeBytes()];
m_alloc = true; m_alloc = true;
clear(); clear();
} }
@ -70,7 +70,7 @@ DataBlock::print(std::ostream& out) const
out << dec << "]" << flush; out << dec << "]" << flush;
} }
const uint8* const uint8_t*
DataBlock::getData(int offset, int len) const DataBlock::getData(int offset, int len) const
{ {
assert(offset + len <= RubySystem::getBlockSizeBytes()); assert(offset + len <= RubySystem::getBlockSizeBytes());
@ -78,7 +78,7 @@ DataBlock::getData(int offset, int len) const
} }
void void
DataBlock::setData(uint8* data, int offset, int len) DataBlock::setData(uint8_t *data, int offset, int len)
{ {
assert(offset + len <= RubySystem::getBlockSizeBytes()); assert(offset + len <= RubySystem::getBlockSizeBytes());
memcpy(&m_data[offset], data, len); memcpy(&m_data[offset], data, len);

View file

@ -29,12 +29,12 @@
#ifndef __MEM_RUBY_COMMON_DATABLOCK_HH__ #ifndef __MEM_RUBY_COMMON_DATABLOCK_HH__
#define __MEM_RUBY_COMMON_DATABLOCK_HH__ #define __MEM_RUBY_COMMON_DATABLOCK_HH__
#include <inttypes.h>
#include <cassert> #include <cassert>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include "mem/ruby/common/TypeDefines.hh"
class DataBlock class DataBlock
{ {
public: public:
@ -53,25 +53,25 @@ class DataBlock
DataBlock& operator=(const DataBlock& obj); DataBlock& operator=(const DataBlock& obj);
void assign(uint8* data); void assign(uint8_t *data);
void clear(); void clear();
uint8 getByte(int whichByte) const; uint8_t getByte(int whichByte) const;
const uint8* getData(int offset, int len) const; const uint8_t *getData(int offset, int len) const;
void setByte(int whichByte, uint8 data); void setByte(int whichByte, uint8_t data);
void setData(uint8* data, int offset, int len); void setData(uint8_t *data, int offset, int len);
void copyPartial(const DataBlock & dblk, int offset, int len); void copyPartial(const DataBlock & dblk, int offset, int len);
bool equal(const DataBlock& obj) const; bool equal(const DataBlock& obj) const;
void print(std::ostream& out) const; void print(std::ostream& out) const;
private: private:
void alloc(); void alloc();
uint8* m_data; uint8_t *m_data;
bool m_alloc; bool m_alloc;
}; };
inline void inline void
DataBlock::assign(uint8* data) DataBlock::assign(uint8_t *data)
{ {
assert(data != NULL); assert(data != NULL);
if (m_alloc) { if (m_alloc) {
@ -81,14 +81,14 @@ DataBlock::assign(uint8* data)
m_alloc = false; m_alloc = false;
} }
inline uint8 inline uint8_t
DataBlock::getByte(int whichByte) const DataBlock::getByte(int whichByte) const
{ {
return m_data[whichByte]; return m_data[whichByte];
} }
inline void inline void
DataBlock::setByte(int whichByte, uint8 data) DataBlock::setByte(int whichByte, uint8_t data)
{ {
m_data[whichByte] = data; m_data[whichByte] = data;
} }

View file

@ -48,12 +48,12 @@ class SubBlock
int getSize() const { return m_data.size(); } int getSize() const { return m_data.size(); }
void resize(int size) { m_data.resize(size); } void resize(int size) { m_data.resize(size); }
uint8 getByte(int offset) const { return m_data[offset]; } uint8_t getByte(int offset) const { return m_data[offset]; }
void setByte(int offset, uint8 data) { m_data[offset] = data; } void setByte(int offset, uint8_t data) { m_data[offset] = data; }
// Shorthands // Shorthands
uint8 readByte() const { return getByte(0); } uint8_t readByte() const { return getByte(0); }
void writeByte(uint8 data) { setByte(0, data); } void writeByte(uint8_t data) { setByte(0, data); }
// Merging to and from DataBlocks - We only need to worry about // Merging to and from DataBlocks - We only need to worry about
// updates when we are using DataBlocks // updates when we are using DataBlocks

View file

@ -30,8 +30,6 @@
#ifndef TYPEDEFINES_H #ifndef TYPEDEFINES_H
#define TYPEDEFINES_H #define TYPEDEFINES_H
typedef unsigned char uint8;
typedef unsigned int uint32; typedef unsigned int uint32;
typedef unsigned long long uint64; typedef unsigned long long uint64;

View file

@ -43,7 +43,7 @@ struct DMARequest
bool write; bool write;
int bytes_completed; int bytes_completed;
int bytes_issued; int bytes_issued;
uint8* data; uint8_t *data;
PacketPtr pkt; PacketPtr pkt;
}; };

View file

@ -48,16 +48,16 @@ class MemoryVector
void resize(uint64 size); // destructive void resize(uint64 size); // destructive
void write(const Address & paddr, uint8* data, int len); void write(const Address & paddr, uint8_t *data, int len);
uint8* read(const Address & paddr, uint8* data, int len); uint8_t *read(const Address & paddr, uint8_t *data, int len);
uint32 collatePages(uint8* &raw_data); uint32 collatePages(uint8_t *&raw_data);
void populatePages(uint8* raw_data); void populatePages(uint8_t *raw_data);
private: private:
uint8* getBlockPtr(const PhysAddress & addr); uint8_t *getBlockPtr(const PhysAddress & addr);
uint64 m_size; uint64 m_size;
uint8** m_pages; uint8_t **m_pages;
uint32 m_num_pages; uint32 m_num_pages;
const uint32 m_page_offset_mask; const uint32 m_page_offset_mask;
static const uint32 PAGE_SIZE = 4096; static const uint32 PAGE_SIZE = 4096;
@ -104,12 +104,12 @@ MemoryVector::resize(uint64 size)
m_size = size; m_size = size;
assert(size%PAGE_SIZE == 0); assert(size%PAGE_SIZE == 0);
m_num_pages = size >> 12; m_num_pages = size >> 12;
m_pages = new uint8*[m_num_pages]; m_pages = new uint8_t*[m_num_pages];
memset(m_pages, 0, m_num_pages * sizeof(uint8*)); memset(m_pages, 0, m_num_pages * sizeof(uint8_t*));
} }
inline void inline void
MemoryVector::write(const Address & paddr, uint8* data, int len) MemoryVector::write(const Address & paddr, uint8_t *data, int len)
{ {
assert(paddr.getAddress() + len <= m_size); assert(paddr.getAddress() + len <= m_size);
uint32 page_num = paddr.getAddress() >> 12; uint32 page_num = paddr.getAddress() >> 12;
@ -123,7 +123,7 @@ MemoryVector::write(const Address & paddr, uint8* data, int len)
} }
if (all_zeros) if (all_zeros)
return; return;
m_pages[page_num] = new uint8[PAGE_SIZE]; m_pages[page_num] = new uint8_t[PAGE_SIZE];
memset(m_pages[page_num], 0, PAGE_SIZE); memset(m_pages[page_num], 0, PAGE_SIZE);
uint32 offset = paddr.getAddress() & m_page_offset_mask; uint32 offset = paddr.getAddress() & m_page_offset_mask;
memcpy(&m_pages[page_num][offset], data, len); memcpy(&m_pages[page_num][offset], data, len);
@ -133,8 +133,8 @@ MemoryVector::write(const Address & paddr, uint8* data, int len)
} }
} }
inline uint8* inline uint8_t*
MemoryVector::read(const Address & paddr, uint8* data, int len) MemoryVector::read(const Address & paddr, uint8_t *data, int len)
{ {
assert(paddr.getAddress() + len <= m_size); assert(paddr.getAddress() + len <= m_size);
uint32 page_num = paddr.getAddress() >> 12; uint32 page_num = paddr.getAddress() >> 12;
@ -147,12 +147,12 @@ MemoryVector::read(const Address & paddr, uint8* data, int len)
return data; return data;
} }
inline uint8* inline uint8_t*
MemoryVector::getBlockPtr(const PhysAddress & paddr) MemoryVector::getBlockPtr(const PhysAddress & paddr)
{ {
uint32 page_num = paddr.getAddress() >> 12; uint32 page_num = paddr.getAddress() >> 12;
if (m_pages[page_num] == 0) { if (m_pages[page_num] == 0) {
m_pages[page_num] = new uint8[PAGE_SIZE]; m_pages[page_num] = new uint8_t[PAGE_SIZE];
memset(m_pages[page_num], 0, PAGE_SIZE); memset(m_pages[page_num], 0, PAGE_SIZE);
} }
return &m_pages[page_num][paddr.getAddress()&m_page_offset_mask]; return &m_pages[page_num][paddr.getAddress()&m_page_offset_mask];
@ -167,7 +167,7 @@ MemoryVector::getBlockPtr(const PhysAddress & paddr)
*/ */
inline uint32 inline uint32
MemoryVector::collatePages(uint8* &raw_data) MemoryVector::collatePages(uint8_t *&raw_data)
{ {
uint32 num_zero_pages = 0; uint32 num_zero_pages = 0;
uint32 data_size = 0; uint32 data_size = 0;
@ -177,9 +177,9 @@ MemoryVector::collatePages(uint8* &raw_data)
if (m_pages[i] == 0) num_zero_pages++; if (m_pages[i] == 0) num_zero_pages++;
} }
raw_data = new uint8[ sizeof(uint32) /* number of pages*/ raw_data = new uint8_t[sizeof(uint32) /* number of pages*/ +
+ m_num_pages /* whether the page is all zeros */ m_num_pages /* whether the page is all zeros */ +
+ PAGE_SIZE * (m_num_pages - num_zero_pages)]; PAGE_SIZE * (m_num_pages - num_zero_pages)];
/* Write the number of pages to be stored. */ /* Write the number of pages to be stored. */
memcpy(raw_data, &m_num_pages, sizeof(uint32)); memcpy(raw_data, &m_num_pages, sizeof(uint32));
@ -210,7 +210,7 @@ MemoryVector::collatePages(uint8* &raw_data)
* in the checkpoint. * in the checkpoint.
*/ */
inline void inline void
MemoryVector::populatePages(uint8* raw_data) MemoryVector::populatePages(uint8_t *raw_data)
{ {
uint32 data_size = 0; uint32 data_size = 0;
uint32 num_pages = 0; uint32 num_pages = 0;
@ -226,7 +226,7 @@ MemoryVector::populatePages(uint8* raw_data)
{ {
assert(m_pages[i] == 0); assert(m_pages[i] == 0);
if (raw_data[data_size] != 0) { if (raw_data[data_size] != 0) {
m_pages[i] = new uint8[PAGE_SIZE]; m_pages[i] = new uint8_t[PAGE_SIZE];
memcpy(m_pages[i], raw_data + data_size + 1, PAGE_SIZE); memcpy(m_pages[i], raw_data + data_size + 1, PAGE_SIZE);
data_size += PAGE_SIZE; data_size += PAGE_SIZE;
} }

View file

@ -275,7 +275,7 @@ RubyPort::M5Port::doFunctionalRead(PacketPtr pkt)
} }
assert(num_rw <= 1); assert(num_rw <= 1);
uint8* data = pkt->getPtr<uint8_t>(true); uint8_t *data = pkt->getPtr<uint8_t>(true);
unsigned int size_in_bytes = pkt->getSize(); unsigned int size_in_bytes = pkt->getSize();
unsigned startByte = address.getAddress() - line_address.getAddress(); unsigned startByte = address.getAddress() - line_address.getAddress();
@ -387,7 +387,7 @@ RubyPort::M5Port::doFunctionalWrite(PacketPtr pkt)
num_busy, num_ro, num_rw); num_busy, num_ro, num_rw);
assert(num_rw <= 1); assert(num_rw <= 1);
uint8* data = pkt->getPtr<uint8_t>(true); uint8_t *data = pkt->getPtr<uint8_t>(true);
unsigned int size_in_bytes = pkt->getSize(); unsigned int size_in_bytes = pkt->getSize();
unsigned startByte = addr.getAddress() - line_addr.getAddress(); unsigned startByte = addr.getAddress() - line_addr.getAddress();

View file

@ -150,7 +150,7 @@ RubySystem::printStats(ostream& out)
} }
void void
RubySystem::writeCompressedTrace(uint8* raw_data, string filename, RubySystem::writeCompressedTrace(uint8_t *raw_data, string filename,
uint64 uncompressed_trace_size) uint64 uncompressed_trace_size)
{ {
// Create the checkpoint file for the memory // Create the checkpoint file for the memory
@ -231,7 +231,7 @@ RubySystem::serialize(std::ostream &os)
// Restore curTick // Restore curTick
curTick(curtick_original); curTick(curtick_original);
uint8* raw_data = NULL; uint8_t *raw_data = NULL;
if (m_mem_vec_ptr != NULL) { if (m_mem_vec_ptr != NULL) {
uint64 memory_trace_size = m_mem_vec_ptr->collatePages(raw_data); uint64 memory_trace_size = m_mem_vec_ptr->collatePages(raw_data);
@ -264,7 +264,7 @@ RubySystem::serialize(std::ostream &os)
} }
void void
RubySystem::readCompressedTrace(string filename, uint8*& raw_data, RubySystem::readCompressedTrace(string filename, uint8_t *&raw_data,
uint64& uncompressed_trace_size) uint64& uncompressed_trace_size)
{ {
// Read the trace file // Read the trace file
@ -303,7 +303,7 @@ RubySystem::unserialize(Checkpoint *cp, const string &section)
// value of curTick() // value of curTick()
// //
clearStats(); clearStats();
uint8* uncompressed_trace = NULL; uint8_t *uncompressed_trace = NULL;
if (m_mem_vec_ptr != NULL) { if (m_mem_vec_ptr != NULL) {
string memory_trace_file; string memory_trace_file;

View file

@ -135,9 +135,9 @@ class RubySystem : public ClockedObject
static void printSystemConfig(std::ostream& out); static void printSystemConfig(std::ostream& out);
void readCompressedTrace(std::string filename, void readCompressedTrace(std::string filename,
uint8*& raw_data, uint8_t *&raw_data,
uint64& uncompressed_trace_size); uint64& uncompressed_trace_size);
void writeCompressedTrace(uint8* raw_data, std::string file, void writeCompressedTrace(uint8_t *raw_data, std::string file,
uint64 uncompressed_trace_size); uint64 uncompressed_trace_size);
private: private: