From 7d9c36aae12e4ea5aad7ce7a28e94dc94c9d3c00 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 3 Jul 2020 12:06:15 -0600 Subject: [PATCH] use length instead of msb in bitstream manager for block bits to save memory --- .../src/bitstream_manager.cpp | 22 ++++++++++--------- .../libfpgabitstream/src/bitstream_manager.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp b/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp index b2d894427..d8622617d 100644 --- a/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp +++ b/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp @@ -78,11 +78,15 @@ std::vector BitstreamManager::block_bits(const ConfigBlockId& block VTR_ASSERT(true == valid_block_id(block_id)); size_t lsb = block_bit_id_lsbs_[block_id]; - size_t msb = block_bit_id_msbs_[block_id]; + size_t length = block_bit_lengths_[block_id]; - std::vector bits(msb - lsb + 1, ConfigBitId::INVALID()); + std::vector bits(length, ConfigBitId::INVALID()); - for (size_t i = lsb; i < msb + 1; ++i) { + if (0 == length) { + return bits; + } + + for (size_t i = lsb; i < lsb + length; ++i) { bits[i - lsb] = ConfigBitId(i); } @@ -152,7 +156,7 @@ ConfigBitId BitstreamManager::add_bit(const bool& bit_value) { void BitstreamManager::reserve_blocks(const size_t& num_blocks) { block_names_.reserve(num_blocks); block_bit_id_lsbs_.reserve(num_blocks); - block_bit_id_msbs_.reserve(num_blocks); + block_bit_lengths_.reserve(num_blocks); block_path_ids_.reserve(num_blocks); block_input_net_ids_.reserve(num_blocks); block_output_net_ids_.reserve(num_blocks); @@ -169,8 +173,8 @@ ConfigBlockId BitstreamManager::create_block() { /* Add a new bit, and allocate associated data structures */ num_blocks_++; block_names_.emplace_back(); - block_bit_id_lsbs_.emplace_back(0); - block_bit_id_msbs_.emplace_back(-1); + block_bit_id_lsbs_.emplace_back(-1); + block_bit_lengths_.emplace_back(0); block_path_ids_.push_back(-2); block_input_net_ids_.emplace_back(); block_output_net_ids_.emplace_back(); @@ -218,13 +222,11 @@ void BitstreamManager::add_block_bits(const ConfigBlockId& block, VTR_ASSERT(true == valid_block_id(block)); /* Add the bit to the block, record anchors in bit indexing for block-level searching */ - size_t lsb = num_bits_; - size_t msb = num_bits_ + block_bitstream.size() - 1; + block_bit_id_lsbs_[block] = num_bits_; + block_bit_lengths_[block] = block_bitstream.size(); for (const bool& bit : block_bitstream) { add_bit(bit); } - block_bit_id_lsbs_[block] = lsb; - block_bit_id_msbs_[block] = msb; } void BitstreamManager::add_path_id_to_block(const ConfigBlockId& block, const int& path_id) { diff --git a/libopenfpga/libfpgabitstream/src/bitstream_manager.h b/libopenfpga/libfpgabitstream/src/bitstream_manager.h index dd724fac9..fbc5d39c3 100644 --- a/libopenfpga/libfpgabitstream/src/bitstream_manager.h +++ b/libopenfpga/libfpgabitstream/src/bitstream_manager.h @@ -197,7 +197,7 @@ class BitstreamManager { size_t num_blocks_; std::unordered_set invalid_block_ids_; vtr::vector block_bit_id_lsbs_; - vtr::vector block_bit_id_msbs_; + vtr::vector block_bit_lengths_; /* Back-annotation for the bits */ /* Parent block of a bit in the Bitstream