From e0bbfa512cb57a84e9dafdb888bc8eaa90089c83 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 23 Apr 2006 04:26:13 +0000 Subject: [PATCH] Constant propagate addresses through NetRamDq read ports. --- cprop.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- functor.cc | 13 ++++++++++- functor.h | 8 ++++++- netlist.cc | 10 ++++++++- netlist.h | 9 +++++++- 5 files changed, 97 insertions(+), 6 deletions(-) diff --git a/cprop.cc b/cprop.cc index 5febd251e..ce081d329 100644 --- a/cprop.cc +++ b/cprop.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2003 Stephen Williams (steve@icarus.com) + * Copyright (c) 1998-2006 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: cprop.cc,v 1.47.2.4 2005/09/11 02:50:51 steve Exp $" +#ident "$Id: cprop.cc,v 1.47.2.5 2006/04/23 04:26:13 steve Exp $" #endif # include "config.h" @@ -25,6 +25,7 @@ # include "netlist.h" # include "netmisc.h" # include "functor.h" +# include "compiler.h" # include @@ -48,6 +49,8 @@ struct cprop_functor : public functor_t { virtual void lpm_logic(Design*des, NetLogic*obj); virtual void lpm_mux(Design*des, NetMux*obj); virtual void lpm_mux_large(Design*des, NetMux*obj); + virtual void lpm_ram_dq(Design*des, NetRamDq*obj); + bool lpm_ram_dq_const_address_(Design*des, NetRamDq*obj); }; void cprop_functor::signal(Design*des, NetNet*obj) @@ -1142,6 +1145,59 @@ void cprop_functor::lpm_mux_large(Design*des, NetMux*obj) count += 1; } +void cprop_functor::lpm_ram_dq(Design*des, NetRamDq*obj) +{ + if (lpm_ram_dq_const_address_(des,obj)) + return; + +} + +/* + * Try to evaluate a constant address input. If we find it, then + * replace the NetRamDq with a direct link to the addressed word. + */ +bool cprop_functor::lpm_ram_dq_const_address_(Design*des, NetRamDq*obj) +{ + NetMemory*mem = obj->mem(); + NetNet* reg = mem->reg_from_explode(); + + /* I only know how to do this on exploded memories. */ + if (reg == 0) + return false; + + verinum sel (0UL, obj->awidth()); + for (unsigned idx = 0 ; idx < obj->awidth() ; idx += 1) { + if (! obj->pin_Address(idx).nexus()->drivers_constant()) + return false; + + sel.set(idx, obj->pin_Address(idx).nexus()->driven_value()); + } + + unsigned long address = sel.as_ulong(); + + /* If the address is outside the ram, then leave this to the + code generator to figure out. */ + if (address >= obj->size()) + return false; + + + unsigned base = address * obj->width(); + assert(base+obj->width() <= reg->pin_count()); + + for (unsigned idx = 0 ; idx < obj->width() ; idx += 1) + connect(reg->pin(base+idx), obj->pin_Q(idx)); + + if (debug_cprop) { + cerr << obj->get_line() << ": debug: Replace read port with" + << " fixed link to word " << address << "." << endl; + } + + delete obj; + count += 1; + return true; +} + + /* * This functor looks to see if the constant is connected to nothing * but signals. If that is the case, delete the dangling constant and @@ -1260,6 +1316,9 @@ void cprop(Design*des) /* * $Log: cprop.cc,v $ + * Revision 1.47.2.5 2006/04/23 04:26:13 steve + * Constant propagate addresses through NetRamDq read ports. + * * Revision 1.47.2.4 2005/09/11 02:50:51 steve * Fix overly agressive constant propagation through MUX causing lost Z bits. * diff --git a/functor.cc b/functor.cc index cb2d3692b..5c3686a17 100644 --- a/functor.cc +++ b/functor.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: functor.cc,v 1.32 2004/10/04 01:10:53 steve Exp $" +#ident "$Id: functor.cc,v 1.32.2.1 2006/04/23 04:26:14 steve Exp $" #endif # include "config.h" @@ -79,6 +79,9 @@ void functor_t::lpm_mux(class Design*, class NetMux*) { } +void functor_t::lpm_ram_dq(class Design*, class NetRamDq*) +{ +} void NetScope::run_functor(Design*des, functor_t*fun) { @@ -206,6 +209,11 @@ void NetMux::functor_node(Design*des, functor_t*fun) fun->lpm_mux(des, this); } +void NetRamDq::functor_node(Design*des, functor_t*fun) +{ + fun->lpm_ram_dq(des, this); +} + proc_match_t::~proc_match_t() { } @@ -267,6 +275,9 @@ int proc_match_t::event_wait(NetEvWait*) /* * $Log: functor.cc,v $ + * Revision 1.32.2.1 2006/04/23 04:26:14 steve + * Constant propagate addresses through NetRamDq read ports. + * * Revision 1.32 2004/10/04 01:10:53 steve * Clean up spurious trailing white space. * diff --git a/functor.h b/functor.h index 2f143fd00..62bd589ec 100644 --- a/functor.h +++ b/functor.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: functor.h,v 1.20 2002/08/12 01:34:59 steve Exp $" +#ident "$Id: functor.h,v 1.20.2.1 2006/04/23 04:26:14 steve Exp $" #endif /* @@ -77,6 +77,9 @@ struct functor_t { /* This method is called for each MUX. */ virtual void lpm_mux(class Design*des, class NetMux*); + + /* This is called for eacm RamDq device. */ + virtual void lpm_ram_dq(class Design*des, class NetRamDq*); }; struct proc_match_t { @@ -92,6 +95,9 @@ struct proc_match_t { /* * $Log: functor.h,v $ + * Revision 1.20.2.1 2006/04/23 04:26:14 steve + * Constant propagate addresses through NetRamDq read ports. + * * Revision 1.20 2002/08/12 01:34:59 steve * conditional ident string using autoconfig. * diff --git a/netlist.cc b/netlist.cc index c2ea5daae..3b1376c46 100644 --- a/netlist.cc +++ b/netlist.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.cc,v 1.226.2.6 2006/04/16 19:26:38 steve Exp $" +#ident "$Id: netlist.cc,v 1.226.2.7 2006/04/23 04:26:14 steve Exp $" #endif # include "config.h" @@ -1625,6 +1625,11 @@ unsigned NetRamDq::size() const return 0; } +NetMemory* NetRamDq::mem() +{ + return mem_; +} + const NetMemory* NetRamDq::mem() const { return mem_; @@ -2481,6 +2486,9 @@ const NetProc*NetTaskDef::proc() const /* * $Log: netlist.cc,v $ + * Revision 1.226.2.7 2006/04/23 04:26:14 steve + * Constant propagate addresses through NetRamDq read ports. + * * Revision 1.226.2.6 2006/04/16 19:26:38 steve * Fix handling of exploded memories with partial or missing resets. * diff --git a/netlist.h b/netlist.h index d59200795..244fdcc82 100644 --- a/netlist.h +++ b/netlist.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.h,v 1.321.2.16 2006/04/16 19:26:38 steve Exp $" +#ident "$Id: netlist.h,v 1.321.2.17 2006/04/23 04:26:14 steve Exp $" #endif /* @@ -995,6 +995,8 @@ class NetRamDq : public NetNode { unsigned width() const; unsigned awidth() const; unsigned size() const; + + NetMemory*mem(); const NetMemory*mem() const; Link& pin_InClock(); @@ -1025,6 +1027,8 @@ class NetRamDq : public NetNode { // that are ports to the attached memory. unsigned count_partners() const; + void functor_node(Design*des, functor_t*fun); + private: NetMemory*mem_; NetRamDq*next_; @@ -3524,6 +3528,9 @@ extern ostream& operator << (ostream&, NetNet::Type); /* * $Log: netlist.h,v $ + * Revision 1.321.2.17 2006/04/23 04:26:14 steve + * Constant propagate addresses through NetRamDq read ports. + * * Revision 1.321.2.16 2006/04/16 19:26:38 steve * Fix handling of exploded memories with partial or missing resets. *