remove id vector in fabric bitstream database and replace with more memory efficient implementation
This commit is contained in:
parent
9f19c36a89
commit
9608cefa86
|
@ -9,12 +9,20 @@
|
||||||
/* begin namespace openfpga */
|
/* begin namespace openfpga */
|
||||||
namespace openfpga {
|
namespace openfpga {
|
||||||
|
|
||||||
|
/**************************************************
|
||||||
|
* Public Constructor
|
||||||
|
*************************************************/
|
||||||
|
FabricBitstream::FabricBitstream() {
|
||||||
|
num_bits_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
* Public Accessors : Aggregates
|
* Public Accessors : Aggregates
|
||||||
*************************************************/
|
*************************************************/
|
||||||
/* Find all the configuration bits */
|
/* Find all the configuration bits */
|
||||||
FabricBitstream::fabric_bit_range FabricBitstream::bits() const {
|
FabricBitstream::fabric_bit_range FabricBitstream::bits() const {
|
||||||
return vtr::make_range(bit_ids_.begin(), bit_ids_.end());
|
return vtr::make_range(fabric_bit_iterator(FabricBitId(0), invalid_bit_ids_),
|
||||||
|
fabric_bit_iterator(FabricBitId(num_bits_), invalid_bit_ids_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -56,16 +64,15 @@ char FabricBitstream::bit_din(const FabricBitId& bit_id) const {
|
||||||
* Public Mutators
|
* Public Mutators
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void FabricBitstream::reserve(const size_t& num_bits) {
|
void FabricBitstream::reserve(const size_t& num_bits) {
|
||||||
bit_ids_.reserve(num_bits);
|
|
||||||
config_bit_ids_.reserve(num_bits);
|
config_bit_ids_.reserve(num_bits);
|
||||||
bit_addresses_.reserve(num_bits);
|
bit_addresses_.reserve(num_bits);
|
||||||
bit_dins_.reserve(num_bits);
|
bit_dins_.reserve(num_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
FabricBitId FabricBitstream::add_bit(const ConfigBitId& config_bit_id) {
|
FabricBitId FabricBitstream::add_bit(const ConfigBitId& config_bit_id) {
|
||||||
FabricBitId bit = FabricBitId(bit_ids_.size());
|
FabricBitId bit = FabricBitId(num_bits_);
|
||||||
/* Add a new bit, and allocate associated data structures */
|
/* Add a new bit, and allocate associated data structures */
|
||||||
bit_ids_.push_back(bit);
|
num_bits_++;
|
||||||
config_bit_ids_.push_back(config_bit_id);
|
config_bit_ids_.push_back(config_bit_id);
|
||||||
bit_addresses_.emplace_back();
|
bit_addresses_.emplace_back();
|
||||||
bit_dins_.push_back(false);
|
bit_dins_.push_back(false);
|
||||||
|
@ -97,7 +104,6 @@ void FabricBitstream::set_bit_din(const FabricBitId& bit_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
void FabricBitstream::reverse() {
|
void FabricBitstream::reverse() {
|
||||||
std::reverse(config_bit_ids_.begin(), config_bit_ids_.end());
|
|
||||||
std::reverse(bit_addresses_.begin(), bit_addresses_.end());
|
std::reverse(bit_addresses_.begin(), bit_addresses_.end());
|
||||||
std::reverse(bit_dins_.begin(), bit_dins_.end());
|
std::reverse(bit_dins_.begin(), bit_dins_.end());
|
||||||
}
|
}
|
||||||
|
@ -106,7 +112,7 @@ void FabricBitstream::reverse() {
|
||||||
* Public Validators
|
* Public Validators
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
char FabricBitstream::valid_bit_id(const FabricBitId& bit_id) const {
|
char FabricBitstream::valid_bit_id(const FabricBitId& bit_id) const {
|
||||||
return (size_t(bit_id) < bit_ids_.size()) && (bit_id == bit_ids_[bit_id]);
|
return (size_t(bit_id) < num_bits_);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* end namespace openfpga */
|
} /* end namespace openfpga */
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#define FABRIC_BITSTREAM_H
|
#define FABRIC_BITSTREAM_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <unordered_map>
|
||||||
#include "vtr_vector.h"
|
#include "vtr_vector.h"
|
||||||
|
|
||||||
#include "bitstream_manager_fwd.h"
|
#include "bitstream_manager_fwd.h"
|
||||||
|
@ -38,11 +40,65 @@
|
||||||
namespace openfpga {
|
namespace openfpga {
|
||||||
|
|
||||||
class FabricBitstream {
|
class FabricBitstream {
|
||||||
|
public: /* Type implementations */
|
||||||
|
/*
|
||||||
|
* This class (forward delcared above) is a template used to represent a lazily calculated
|
||||||
|
* iterator of the specified ID type. The key assumption made is that the ID space is
|
||||||
|
* contiguous and can be walked by incrementing the underlying ID value. To account for
|
||||||
|
* invalid IDs, it keeps a reference to the invalid ID set and returns ID::INVALID() for
|
||||||
|
* ID values in the set.
|
||||||
|
*
|
||||||
|
* It is used to lazily create an iteration range (e.g. as returned by RRGraph::edges() RRGraph::nodes())
|
||||||
|
* just based on the count of allocated elements (i.e. RRGraph::num_nodes_ or RRGraph::num_edges_),
|
||||||
|
* and the set of any invalid IDs (i.e. RRGraph::invalid_node_ids_, RRGraph::invalid_edge_ids_).
|
||||||
|
*/
|
||||||
|
template<class ID>
|
||||||
|
class lazy_id_iterator : public std::iterator<std::bidirectional_iterator_tag, ID> {
|
||||||
|
public:
|
||||||
|
//Since we pass ID as a template to std::iterator we need to use an explicit 'typename'
|
||||||
|
//to bring the value_type and iterator names into scope
|
||||||
|
typedef typename std::iterator<std::bidirectional_iterator_tag, ID>::value_type value_type;
|
||||||
|
typedef typename std::iterator<std::bidirectional_iterator_tag, ID>::iterator iterator;
|
||||||
|
|
||||||
|
lazy_id_iterator(value_type init, const std::unordered_set<ID>& invalid_ids)
|
||||||
|
: value_(init)
|
||||||
|
, invalid_ids_(invalid_ids) {}
|
||||||
|
|
||||||
|
//Advance to the next ID value
|
||||||
|
iterator operator++() {
|
||||||
|
value_ = ID(size_t(value_) + 1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Advance to the previous ID value
|
||||||
|
iterator operator--() {
|
||||||
|
value_ = ID(size_t(value_) - 1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Dereference the iterator
|
||||||
|
value_type operator*() const { return (invalid_ids_.count(value_)) ? ID::INVALID() : value_; }
|
||||||
|
|
||||||
|
friend bool operator==(const lazy_id_iterator<ID> lhs, const lazy_id_iterator<ID> rhs) { return lhs.value_ == rhs.value_; }
|
||||||
|
friend bool operator!=(const lazy_id_iterator<ID> lhs, const lazy_id_iterator<ID> rhs) { return !(lhs == rhs); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
value_type value_;
|
||||||
|
const std::unordered_set<ID>& invalid_ids_;
|
||||||
|
};
|
||||||
|
|
||||||
public: /* Types and ranges */
|
public: /* Types and ranges */
|
||||||
typedef vtr::vector<FabricBitId, FabricBitId>::const_iterator fabric_bit_iterator;
|
//Lazy iterator utility forward declaration
|
||||||
|
template<class ID>
|
||||||
|
class lazy_id_iterator;
|
||||||
|
|
||||||
|
typedef lazy_id_iterator<FabricBitId> fabric_bit_iterator;
|
||||||
|
|
||||||
typedef vtr::Range<fabric_bit_iterator> fabric_bit_range;
|
typedef vtr::Range<fabric_bit_iterator> fabric_bit_range;
|
||||||
|
|
||||||
|
public: /* Public constructor */
|
||||||
|
FabricBitstream();
|
||||||
|
|
||||||
public: /* Public aggregators */
|
public: /* Public aggregators */
|
||||||
/* Find all the configuration bits */
|
/* Find all the configuration bits */
|
||||||
fabric_bit_range bits() const;
|
fabric_bit_range bits() const;
|
||||||
|
@ -88,7 +144,8 @@ class FabricBitstream {
|
||||||
|
|
||||||
private: /* Internal data */
|
private: /* Internal data */
|
||||||
/* Unique id of a bit in the Bitstream */
|
/* Unique id of a bit in the Bitstream */
|
||||||
vtr::vector<FabricBitId, FabricBitId> bit_ids_;
|
size_t num_bits_;
|
||||||
|
std::unordered_set<FabricBitId> invalid_bit_ids_;
|
||||||
vtr::vector<FabricBitId, ConfigBitId> config_bit_ids_;
|
vtr::vector<FabricBitId, ConfigBitId> config_bit_ids_;
|
||||||
|
|
||||||
/* Address bits: this is designed for memory decoders
|
/* Address bits: this is designed for memory decoders
|
||||||
|
|
Loading…
Reference in New Issue