Fei wrote:
> Here is a question:
> "Given a combinational circuit, for each primary output, find the
> number of primary inputs that this output depends on."
>
> It is easy to do structual analysis for a small-size circuit. But for a
> circuit with million gates, we need to find a effecient way.
>
> Now assume a gate-level Verilog code for this circuit is given, I plan
> to write a script (e.g., Perl) to scan this Verilog code, then for each
> output, trace back to find the primary input on which it depends. But I
> am new to both Perl and Verilog. 
> So could you please give me any suggestion or any script example for
> references? or is there other way to address this problem effeceintly?
Look up "Boolean Decision Diagrams" (aka BDDs) on your
favorite search engine; I even saw a web page once which compared
several BDD packages (I don't have the URL handy).
If I were trying to solve this problem, I would use Perl (or
a C lexer/parser package) to scan the Verilog and pipe the output
to a BDD package, asking it to build BDDs for each of the module
output ports. From there, it shouldn't be too hard to write code
to "walk the BDD" for each output to see if an input is ignored
or if it "matters" to the output. The BDD package does most of
the hard work of reducing the Boolean logic so -- if an input
doesn't affect the output -- the BDD package should either
eliminate it from the BDD or figure out that the '0' & '1'
pointers of that input's node in the BDD tree point to the same
place.
I haven't worked with BDDs for several years; early BDD
packages created very large BDDs (running out of memory) for
parity trees & other circuits which generated a lot of XOR
gates/functions. If your Verilog has large parity trees, adders,
etc. -- anything which generates a lot of XOR functions, you may
wish to benchmark different BDD packages with large XOR circuits
to see which ones make the most sense for your application.