Skip to content

Commit 060af12

Browse files
committed
syn: Adjust BundleView to Bundle conversion
Signed-off-by: Martin Povišer <povik@cutebit.org>
1 parent 7acc9e6 commit 060af12

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/syn/src/ir/Bundle.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Bundle::Bundle(BundleView bv) : tag_(kEmpty), width_(0), net_(Net::zero())
2525
net_ = bv[0];
2626
return;
2727
}
28+
29+
if (bv.isGuaranteedConsecutive()) {
30+
tag_ = kConsecutive;
31+
width_ = bv.width();
32+
net_ = bv[0];
33+
return;
34+
}
35+
2836
std::vector<Net> nets;
2937
nets.reserve(bv.width());
3038
for (uint32_t i = 0; i < bv.width(); i++) {

src/syn/src/ir/Bundle.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ class Bundle
149149
class BundleView
150150
{
151151
public:
152-
BundleView(Net net) : net_(net), Bundle_(nullptr), offset_(0), width_(1) {}
152+
BundleView(Net net) : net_(net), bundle_(nullptr), offset_(0), width_(1) {}
153153

154154
BundleView(const Bundle& Bundle)
155-
: net_(Net::zero()), Bundle_(&Bundle), offset_(0), width_(Bundle.width())
155+
: net_(Net::zero()), bundle_(&Bundle), offset_(0), width_(Bundle.width())
156156
{
157157
}
158158

159159
BundleView(const Bundle& Bundle, uint32_t offset, uint32_t len)
160-
: net_(Net::zero()), Bundle_(&Bundle), offset_(offset), width_(len)
160+
: net_(Net::zero()), bundle_(&Bundle), offset_(offset), width_(len)
161161
{
162162
}
163163

164164
// Consecutive nets starting at base.
165165
BundleView(Net base, uint32_t len)
166-
: net_(base), Bundle_(nullptr), offset_(0), width_(len)
166+
: net_(base), bundle_(nullptr), offset_(0), width_(len)
167167
{
168168
}
169169

@@ -182,8 +182,8 @@ class BundleView
182182

183183
Net operator[](uint32_t i) const
184184
{
185-
if (Bundle_) {
186-
return (*Bundle_)[offset_ + i];
185+
if (bundle_) {
186+
return (*bundle_)[offset_ + i];
187187
}
188188
return Net(net_.id_ + i);
189189
}
@@ -211,8 +211,8 @@ class BundleView
211211

212212
BundleView slice(uint32_t offset, uint32_t len) const
213213
{
214-
if (Bundle_) {
215-
return BundleView(*Bundle_, offset_ + offset, len);
214+
if (bundle_) {
215+
return BundleView(*bundle_, offset_ + offset, len);
216216
}
217217
if (len == 0) {
218218
return BundleView(Net::zero(), nullptr, 0, 0);
@@ -222,14 +222,19 @@ class BundleView
222222

223223
bool isConst() const;
224224

225+
protected:
226+
// For optimized construction of Bundle from BundleView
227+
bool isGuaranteedConsecutive() const { return bundle_ == nullptr; }
228+
friend class Bundle;
229+
225230
private:
226231
BundleView(Net net, const Bundle* Bundle, uint32_t offset, uint32_t len)
227-
: net_(net), Bundle_(Bundle), offset_(offset), width_(len)
232+
: net_(net), bundle_(Bundle), offset_(offset), width_(len)
228233
{
229234
}
230235

231236
Net net_;
232-
const Bundle* Bundle_;
237+
const Bundle* bundle_;
233238
uint32_t offset_;
234239
uint32_t width_;
235240
};

0 commit comments

Comments
 (0)