Remove redundant NetPins node pointer.

Remove redundant pointer to the containing NetPins object by keeping
the pointer only in the first Link (pin 0) of an array of links. In
this link, replace the pin number with the NetPins pointer, and set
a pins_zero_ flag to indicate that this has happened. This way, only
the first pin in a Link array will have the pointer to the NetPins
that contains the array, and the pointer takes up practically no space
at all.
This commit is contained in:
Stephen Williams 2008-09-13 19:49:38 -07:00
parent 0339e9eb1e
commit e4c9ad2b17
3 changed files with 34 additions and 12 deletions

View File

@ -141,14 +141,14 @@ verinum::V Link::get_init() const
void Link::cur_link(NetPins*&net, unsigned &pin) void Link::cur_link(NetPins*&net, unsigned &pin)
{ {
net = node_; net = get_obj();
pin = pin_; pin = get_pin();
} }
void Link::cur_link(const NetPins*&net, unsigned &pin) const void Link::cur_link(const NetPins*&net, unsigned &pin) const
{ {
net = node_; net = get_obj();
pin = pin_; pin = get_pin();
} }
void Link::unlink() void Link::unlink()
@ -193,17 +193,28 @@ const Link* Link::next_nlink() const
const NetPins*Link::get_obj() const const NetPins*Link::get_obj() const
{ {
return node_; if (pin_zero_)
return node_;
const Link*tmp = this - pin_;
assert(tmp->pin_zero_);
return tmp->node_;
} }
NetPins*Link::get_obj() NetPins*Link::get_obj()
{ {
return node_; if (pin_zero_)
return node_;
Link*tmp = this - pin_;
assert(tmp->pin_zero_);
return tmp->node_;
} }
unsigned Link::get_pin() const unsigned Link::get_pin() const
{ {
return pin_; if (pin_zero_)
return 0;
else
return pin_;
} }
Nexus::Nexus() Nexus::Nexus()

View File

@ -175,9 +175,12 @@ NetPins::NetPins(unsigned npins)
: npins_(npins) : npins_(npins)
{ {
pins_ = new Link[npins_]; pins_ = new Link[npins_];
for (unsigned idx = 0 ; idx < npins_ ; idx += 1) { pins_[0].pin_zero_ = true;
pins_[idx].node_ = this; pins_[0].node_ = this;
pins_[idx].pin_ = idx;
for (unsigned idx = 1 ; idx < npins_ ; idx += 1) {
pins_[idx].pin_zero_ = false;
pins_[idx].pin_ = idx;
} }
} }
@ -196,12 +199,15 @@ Link& NetPins::pin(unsigned idx)
} }
assert(idx < npins_); assert(idx < npins_);
assert(idx == 0? pins_[0].pin_zero_ : pins_[idx].pin_==idx);
return pins_[idx]; return pins_[idx];
} }
const Link& NetPins::pin(unsigned idx) const const Link& NetPins::pin(unsigned idx) const
{ {
assert(idx < npins_); assert(idx < npins_);
assert(idx == 0? pins_[0].pin_zero_ : pins_[idx].pin_==idx);
return pins_[idx]; return pins_[idx];
} }

View File

@ -194,9 +194,11 @@ class Link {
enum strength_t { HIGHZ, WEAK, PULL, STRONG, SUPPLY }; enum strength_t { HIGHZ, WEAK, PULL, STRONG, SUPPLY };
private: // Only NetPins can create/delete Link objects
Link(); Link();
~Link(); ~Link();
public:
// Manipulate the link direction. // Manipulate the link direction.
void set_dir(DIR d); void set_dir(DIR d);
DIR get_dir() const; DIR get_dir() const;
@ -259,9 +261,12 @@ class Link {
private: private:
// The NetNode manages these. They point back to the // The NetNode manages these. They point back to the
// NetNode so that following the links can get me here. // NetNode so that following the links can get me here.
NetPins *node_; union {
unsigned pin_; NetPins *node_;
unsigned pin_;
};
bool pin_zero_ : 1;
DIR dir_ : 2; DIR dir_ : 2;
strength_t drive0_ : 3; strength_t drive0_ : 3;
strength_t drive1_ : 3; strength_t drive1_ : 3;