From e4c9ad2b1775f044b88e05ff497c1e8c963f4cc4 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 13 Sep 2008 19:49:38 -0700 Subject: [PATCH] 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. --- net_link.cc | 25 ++++++++++++++++++------- netlist.cc | 12 +++++++++--- netlist.h | 9 +++++++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/net_link.cc b/net_link.cc index e36675905..7863f0377 100644 --- a/net_link.cc +++ b/net_link.cc @@ -141,14 +141,14 @@ verinum::V Link::get_init() const void Link::cur_link(NetPins*&net, unsigned &pin) { - net = node_; - pin = pin_; + net = get_obj(); + pin = get_pin(); } void Link::cur_link(const NetPins*&net, unsigned &pin) const { - net = node_; - pin = pin_; + net = get_obj(); + pin = get_pin(); } void Link::unlink() @@ -193,17 +193,28 @@ const Link* Link::next_nlink() 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() { - return node_; + if (pin_zero_) + return node_; + Link*tmp = this - pin_; + assert(tmp->pin_zero_); + return tmp->node_; } unsigned Link::get_pin() const { - return pin_; + if (pin_zero_) + return 0; + else + return pin_; } Nexus::Nexus() diff --git a/netlist.cc b/netlist.cc index 3951711a1..b4ce2697c 100644 --- a/netlist.cc +++ b/netlist.cc @@ -175,9 +175,12 @@ NetPins::NetPins(unsigned npins) : npins_(npins) { pins_ = new Link[npins_]; - for (unsigned idx = 0 ; idx < npins_ ; idx += 1) { - pins_[idx].node_ = this; - pins_[idx].pin_ = idx; + pins_[0].pin_zero_ = true; + pins_[0].node_ = this; + + 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 == 0? pins_[0].pin_zero_ : pins_[idx].pin_==idx); + return pins_[idx]; } const Link& NetPins::pin(unsigned idx) const { assert(idx < npins_); + assert(idx == 0? pins_[0].pin_zero_ : pins_[idx].pin_==idx); return pins_[idx]; } diff --git a/netlist.h b/netlist.h index 4eca81241..fc2d120f7 100644 --- a/netlist.h +++ b/netlist.h @@ -194,9 +194,11 @@ class Link { enum strength_t { HIGHZ, WEAK, PULL, STRONG, SUPPLY }; + private: // Only NetPins can create/delete Link objects Link(); ~Link(); + public: // Manipulate the link direction. void set_dir(DIR d); DIR get_dir() const; @@ -259,9 +261,12 @@ class Link { private: // The NetNode manages these. They point back to the // NetNode so that following the links can get me here. - NetPins *node_; - unsigned pin_; + union { + NetPins *node_; + unsigned pin_; + }; + bool pin_zero_ : 1; DIR dir_ : 2; strength_t drive0_ : 3; strength_t drive1_ : 3;