From 6faf377b5305f9dcc3c7b013c4d67f5accb92617 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 4 Jun 2009 23:21:12 -0700 Subject: types: clean up types, especially signed vs unsigned --- src/base/atomicio.cc | 4 ++-- src/base/chunk_generator.hh | 25 ++++++++++++++----------- src/base/crc.cc | 37 ++++++++++++++----------------------- src/base/fast_alloc.hh | 2 +- src/base/loader/symtab.cc | 2 +- src/base/match.cc | 2 +- src/base/remote_gdb.cc | 8 ++++---- src/base/sat_counter.cc | 2 +- src/base/sat_counter.hh | 6 ++++-- src/base/statistics.cc | 2 +- src/base/statistics.hh | 2 +- src/base/timebuf.hh | 18 +++++++++--------- 12 files changed, 53 insertions(+), 57 deletions(-) (limited to 'src/base') diff --git a/src/base/atomicio.cc b/src/base/atomicio.cc index 3f3e6d6f0..13eeca05b 100644 --- a/src/base/atomicio.cc +++ b/src/base/atomicio.cc @@ -37,7 +37,7 @@ ssize_t atomic_read(int fd, void *s, size_t n) { char *p = reinterpret_cast(s); - ssize_t pos = 0; + size_t pos = 0; // Keep reading until we've gotten all of the data. while (n > pos) { @@ -66,7 +66,7 @@ ssize_t atomic_write(int fd, const void *s, size_t n) { const char *p = reinterpret_cast(s); - ssize_t pos = 0; + size_t pos = 0; // Keep writing until we've written all of the data while (n > pos) { diff --git a/src/base/chunk_generator.hh b/src/base/chunk_generator.hh index d2ae45d1e..bc71a0569 100644 --- a/src/base/chunk_generator.hh +++ b/src/base/chunk_generator.hh @@ -37,8 +37,9 @@ */ #include + #include "base/intmath.hh" -#include "arch/isa_traits.hh" // for Addr +#include "base/types.hh" /** * This class takes an arbitrary memory region (address/length pair) @@ -61,13 +62,13 @@ class ChunkGenerator /** The starting address of the next chunk (after the current one). */ Addr nextAddr; /** The size of the current chunk (in bytes). */ - int curSize; + unsigned curSize; /** The number of bytes remaining in the region after the current chunk. */ - int sizeLeft; + unsigned sizeLeft; /** The start address so we can calculate offset in writing block. */ const Addr startAddr; /** The maximum chunk size, e.g., the cache block size or page size. */ - const int chunkSize; + const unsigned chunkSize; public: /** @@ -77,7 +78,7 @@ class ChunkGenerator * @param _chunkSize The size/alignment of chunks into which * the region should be decomposed. */ - ChunkGenerator(Addr _startAddr, int totalSize, int _chunkSize) + ChunkGenerator(Addr _startAddr, unsigned totalSize, unsigned _chunkSize) : startAddr(_startAddr), chunkSize(_chunkSize) { // chunkSize must be a power of two @@ -102,31 +103,33 @@ class ChunkGenerator } // how many bytes are left between curAddr and the end of this chunk? - int left_in_chunk = nextAddr - curAddr; + unsigned left_in_chunk = nextAddr - curAddr; curSize = std::min(totalSize, left_in_chunk); sizeLeft = totalSize - curSize; } /** Return starting address of current chunk. */ - Addr addr() { return curAddr; } + Addr addr() const { return curAddr; } /** Return size in bytes of current chunk. */ - int size() { return curSize; } + unsigned size() const { return curSize; } /** Number of bytes we have already chunked up. */ - int complete() { return curAddr - startAddr; } + unsigned complete() const { return curAddr - startAddr; } + /** * Are we done? That is, did the last call to next() advance * past the end of the region? * @return True if yes, false if more to go. */ - bool done() { return (curSize == 0); } + bool done() const { return (curSize == 0); } /** * Advance generator to next chunk. * @return True if successful, false if unsuccessful * (because we were at the last chunk). */ - bool next() + bool + next() { if (sizeLeft == 0) { curSize = 0; diff --git a/src/base/crc.cc b/src/base/crc.cc index d4b0de70e..6b04213c9 100644 --- a/src/base/crc.cc +++ b/src/base/crc.cc @@ -48,15 +48,12 @@ uint32_t crc32le(const uint8_t *buf, size_t len) { - uint32_t c, crc, carry; - size_t i, j; + uint32_t crc = 0xffffffffU; /* initial value */ - crc = 0xffffffffU; /* initial value */ - - for (i = 0; i < len; i++) { - c = buf[i]; - for (j = 0; j < 8; j++) { - carry = ((crc & 0x01) ? 1 : 0) ^ (c & 0x01); + for (size_t i = 0; i < len; i++) { + uint32_t c = buf[i]; + for (size_t j = 0; j < 8; j++) { + uint32_t carry = ((crc & 0x01) ? 1 : 0) ^ (c & 0x01); crc >>= 1; c >>= 1; if (carry) @@ -64,7 +61,7 @@ crc32le(const uint8_t *buf, size_t len) } } - return (crc); + return crc; } #else uint32_t @@ -76,33 +73,27 @@ crc32le(const uint8_t *buf, size_t len) 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; - uint32_t crc; - int i; - - crc = 0xffffffffU; /* initial value */ + uint32_t crc = 0xffffffffU; /* initial value */ - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { crc ^= buf[i]; crc = (crc >> 4) ^ crctab[crc & 0xf]; crc = (crc >> 4) ^ crctab[crc & 0xf]; } - return (crc); + return crc; } #endif uint32_t crc32be(const uint8_t *buf, size_t len) { - uint32_t c, crc, carry; - size_t i, j; - - crc = 0xffffffffU; /* initial value */ + uint32_t crc = 0xffffffffU; /* initial value */ - for (i = 0; i < len; i++) { - c = buf[i]; - for (j = 0; j < 8; j++) { - carry = ((crc & 0x80000000U) ? 1 : 0) ^ (c & 0x01); + for (size_t i = 0; i < len; i++) { + uint32_t c = buf[i]; + for (size_t j = 0; j < 8; j++) { + uint32_t carry = ((crc & 0x80000000U) ? 1 : 0) ^ (c & 0x01); crc <<= 1; c >>= 1; if (carry) diff --git a/src/base/fast_alloc.hh b/src/base/fast_alloc.hh index aa8fff130..41f6f248c 100644 --- a/src/base/fast_alloc.hh +++ b/src/base/fast_alloc.hh @@ -101,7 +101,7 @@ class FastAlloc // this class. There's no fundamental limit, but this limits the // size of the freeLists array. Let's not make this really huge // like in Blizzard. - static const int Max_Alloc_Size = 512; + static const size_t Max_Alloc_Size = 512; // Alloc_Quantum is the difference in size between adjacent // buckets in the free list array. diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc index d137477f4..7163260ec 100644 --- a/src/base/loader/symtab.cc +++ b/src/base/loader/symtab.cc @@ -80,7 +80,7 @@ SymbolTable::load(const string &filename) if (buffer.empty()) continue; - int idx = buffer.find(','); + string::size_type idx = buffer.find(','); if (idx == string::npos) return false; diff --git a/src/base/match.cc b/src/base/match.cc index 994209864..08ba5f20e 100644 --- a/src/base/match.cc +++ b/src/base/match.cc @@ -56,7 +56,7 @@ ObjectMatch::setExpression(const vector &expr) tokens.resize(0); } else { tokens.resize(expr.size()); - for (int i = 0; i < expr.size(); ++i) + for (vector::size_type i = 0; i < expr.size(); ++i) tokenize(tokens[i], expr[i], '.'); } } diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc index 93d86447e..6c301b10e 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -148,7 +148,7 @@ void debugger() { static int current_debugger = -1; - if (current_debugger >= 0 && current_debugger < debuggers.size()) { + if (current_debugger >= 0 && current_debugger < (int)debuggers.size()) { BaseRemoteGDB *gdb = debuggers[current_debugger]; if (!gdb->isattached()) gdb->listener->accept(); @@ -632,7 +632,7 @@ BaseRemoteGDB::trap(int type) size_t datalen, len; char data[GDBPacketBufLen + 1]; char *buffer; - int bufferSize; + size_t bufferSize; const char *p; char command, subcmd; string var; @@ -812,7 +812,7 @@ BaseRemoteGDB::trap(int type) goto out; case GDBCont: - if (p - data < datalen) { + if (p - data < (ptrdiff_t)datalen) { val = hex2i(&p); context->setPC(val); context->setNextPC(val + sizeof(MachInst)); @@ -831,7 +831,7 @@ BaseRemoteGDB::trap(int type) goto out; case GDBStep: - if (p - data < datalen) { + if (p - data < (ptrdiff_t)datalen) { val = hex2i(&p); context->setPC(val); context->setNextPC(val + sizeof(MachInst)); diff --git a/src/base/sat_counter.cc b/src/base/sat_counter.cc index 8980275eb..61815c112 100644 --- a/src/base/sat_counter.cc +++ b/src/base/sat_counter.cc @@ -66,7 +66,7 @@ SaturatingCounterPred::SaturatingCounterPred(string p_name, table = new unsigned[max_index + 1]; // Initialize with the right parameters & clear the counter - for (int i = 0; i <= max_index; ++i) + for (unsigned long i = 0; i <= max_index; ++i) table[i] = init_value; } diff --git a/src/base/sat_counter.hh b/src/base/sat_counter.hh index 38c4ec74f..963a39fc8 100644 --- a/src/base/sat_counter.hh +++ b/src/base/sat_counter.hh @@ -119,8 +119,10 @@ class SaturatingCounterPred : public GenericPredictor unsigned _zero_change = 1, unsigned _one_change = 1, unsigned _thresh = 1, unsigned _init_value = 0); - void clear() { - for (int i = 0; i <= max_index; ++i) + void + clear() + { + for (unsigned long i = 0; i <= max_index; ++i) table[i] = init_value; } diff --git a/src/base/statistics.cc b/src/base/statistics.cc index abe3b53bb..59013ed34 100644 --- a/src/base/statistics.cc +++ b/src/base/statistics.cc @@ -299,7 +299,7 @@ Formula::zero() const { VResult vec; result(vec); - for (off_t i = 0; i < vec.size(); ++i) + for (VResult::size_type i = 0; i < vec.size(); ++i) if (vec[i] != 0.0) return false; return true; diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 52c0111d8..0f001dccb 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -1365,7 +1365,7 @@ class DistStor data.underflow = underflow; data.overflow = overflow; - int buckets = params->buckets; + size_type buckets = params->buckets; data.cvec.resize(buckets); for (off_type i = 0; i < buckets; ++i) data.cvec[i] = cvec[i]; diff --git a/src/base/timebuf.hh b/src/base/timebuf.hh index 9f9fc32b5..b6f709d71 100644 --- a/src/base/timebuf.hh +++ b/src/base/timebuf.hh @@ -42,12 +42,12 @@ class TimeBuffer protected: int past; int future; - int size; + unsigned size; int _id; char *data; std::vector index; - int base; + unsigned base; void valid(int idx) { @@ -138,12 +138,12 @@ class TimeBuffer public: TimeBuffer(int p, int f) - : past(p), future(f), size(past + future + 1), + : past(p), future(f), size(past + future + 1), data(new char[size * sizeof(T)]), index(size), base(0) { assert(past >= 0 && future >= 0); char *ptr = data; - for (int i = 0; i < size; i++) { + for (unsigned i = 0; i < size; i++) { index[i] = ptr; std::memset(ptr, 0, sizeof(T)); new (ptr) T; @@ -160,7 +160,7 @@ class TimeBuffer ~TimeBuffer() { - for (int i = 0; i < size; ++i) + for (unsigned i = 0; i < size; ++i) (reinterpret_cast(index[i]))->~T(); delete [] data; } @@ -182,7 +182,7 @@ class TimeBuffer base = 0; int ptr = base + future; - if (ptr >= size) + if (ptr >= (int)size) ptr -= size; (reinterpret_cast(index[ptr]))->~T(); std::memset(index[ptr], 0, sizeof(T)); @@ -195,7 +195,7 @@ class TimeBuffer valid(idx); int vector_index = idx + base; - if (vector_index >= size) { + if (vector_index >= (int)size) { vector_index -= size; } else if (vector_index < 0) { vector_index += size; @@ -210,7 +210,7 @@ class TimeBuffer valid(idx); int vector_index = idx + base; - if (vector_index >= size) { + if (vector_index >= (int)size) { vector_index -= size; } else if (vector_index < 0) { vector_index += size; @@ -231,7 +231,7 @@ class TimeBuffer return wire(this, 0); } - int getSize() + unsigned getSize() { return size; } -- cgit v1.2.3