From 6108ff16082b7d454bf9de93b7c5e2b53d627e68 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 28 Dec 2015 10:52:22 -0600 Subject: [PATCH] Use a 64-bit bitmap rather than a 32-bit bitmap. --- src/xenia/base/bit_map.cc | 26 +++++++++++++------------- src/xenia/base/bit_map.h | 18 +++++++++--------- src/xenia/kernel/kernel_state.cc | 5 +++-- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/xenia/base/bit_map.cc b/src/xenia/base/bit_map.cc index 77b56ce90..0cbb4c2d0 100644 --- a/src/xenia/base/bit_map.cc +++ b/src/xenia/base/bit_map.cc @@ -19,18 +19,18 @@ BitMap::BitMap() = default; BitMap::BitMap(size_t size_bits) { Resize(size_bits); } -BitMap::BitMap(uint32_t* data, size_t size_bits) { - assert_true(size_bits % 32 == 0); +BitMap::BitMap(uint64_t* data, size_t size_bits) { + assert_true(size_bits % kDataSizeBits == 0); - data_.resize(size_bits / 32); - std::memcpy(data_.data(), data, size_bits / 32); + data_.resize(size_bits / kDataSizeBits); + std::memcpy(data_.data(), data, size_bits / kDataSizeBits); } size_t BitMap::Acquire() { for (size_t i = 0; i < data_.size(); i++) { - uint32_t entry = 0; - uint32_t new_entry = 0; - int acquired_idx = -1; + uint64_t entry = 0; + uint64_t new_entry = 0; + int64_t acquired_idx = -1; do { entry = data_[i]; @@ -42,7 +42,7 @@ size_t BitMap::Acquire() { } // Entry has a free bit. Acquire it. - uint32_t bit = 1 << (kDataSizeBits - index - 1); + uint64_t bit = 1ull << (kDataSizeBits - index - 1); new_entry = entry & ~bit; assert_not_zero(entry & bit); @@ -62,10 +62,10 @@ void BitMap::Release(size_t index) { auto slot = index / kDataSizeBits; index -= slot * kDataSizeBits; - uint32_t bit = 1 << (kDataSizeBits - index - 1); + uint64_t bit = 1ull << (kDataSizeBits - index - 1); - uint32_t entry = 0; - uint32_t new_entry = 0; + uint64_t entry = 0; + uint64_t new_entry = 0; do { entry = data_[slot]; assert_zero(entry & bit); @@ -76,8 +76,8 @@ void BitMap::Release(size_t index) { void BitMap::Resize(size_t new_size_bits) { auto old_size = data_.size(); - assert_true(new_size_bits % 32 == 0); - data_.resize(new_size_bits / 32); + assert_true(new_size_bits % kDataSizeBits == 0); + data_.resize(new_size_bits / kDataSizeBits); // Initialize new entries. if (data_.size() > old_size) { diff --git a/src/xenia/base/bit_map.h b/src/xenia/base/bit_map.h index e25831970..e80ad93b6 100644 --- a/src/xenia/base/bit_map.h +++ b/src/xenia/base/bit_map.h @@ -20,13 +20,13 @@ class BitMap { public: BitMap(); - // Size is the number of entries, must be a multiple of 32. + // Size is the number of entries, must be a multiple of 64. BitMap(size_t size_bits); // Data does not have to be aligned to a 4-byte boundary, but it is // preferable. - // Size is the number of entries, must be a multiple of 32. - BitMap(uint32_t* data, size_t size_bits); + // Size is the number of entries, must be a multiple of 64. + BitMap(uint64_t* data, size_t size_bits); // (threadsafe) Acquires an entry and returns its index. Returns -1 if there // are no more free entries. @@ -35,19 +35,19 @@ class BitMap { // (threadsafe) Releases an entry by an index. void Release(size_t index); - // Resize the bitmap. Size is the number of entries, must be a multiple of 32. + // Resize the bitmap. Size is the number of entries, must be a multiple of 64. void Resize(size_t new_size_bits); // Sets all entries to free. void Reset(); - const std::vector data() const { return data_; } - std::vector& data() { return data_; } + const std::vector data() const { return data_; } + std::vector& data() { return data_; } private: - const static uint32_t kDataSize = 4; - const static uint32_t kDataSizeBits = kDataSize * 8; - std::vector data_; + const static size_t kDataSize = 8; + const static size_t kDataSizeBits = kDataSize * 8; + std::vector data_; }; } // namespace xe diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index 7823df3a3..94265d1c0 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -652,7 +652,7 @@ bool KernelState::Save(ByteStream* stream) { auto tls_bitmap = tls_bitmap_.data(); stream->Write(uint32_t(tls_bitmap.size())); for (size_t i = 0; i < tls_bitmap.size(); i++) { - stream->Write(tls_bitmap[i]); + stream->Write(tls_bitmap[i]); } // We save XThreads absolutely first, as they will execute code upon save @@ -699,6 +699,7 @@ bool KernelState::Save(ByteStream* stream) { stream->Write(object->type()); if (!object->Save(stream)) { XELOGD("Did not save object of type %d", object->type()); + assert_always(); // Revert backwards and overwrite if a save failed. stream->set_offset(prev_offset); @@ -724,7 +725,7 @@ bool KernelState::Restore(ByteStream* stream) { auto& tls_bitmap = tls_bitmap_.data(); tls_bitmap.resize(num_bitmap_entries); for (uint32_t i = 0; i < num_bitmap_entries; i++) { - tls_bitmap[i] = stream->Read(); + tls_bitmap[i] = stream->Read(); } uint32_t num_threads = stream->Read();