Skip to content

Commit 0d45e9d

Browse files
committed
Merge branch 'development' of https://github.com/UCSBarchlab/PyRTL into development
2 parents acead1e + cf62cd5 commit 0d45e9d

25 files changed

+3735
-2751
lines changed

docs/analysis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Estimation
1818
1919
.. .. _estimate-ref:
2020
21-
.. automodule:: pyrtl.analysis.estimate
21+
.. automodule:: pyrtl.analysis
2222
:members:
2323
:show-inheritance:
2424
:special-members:

docs/export.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ Exporting and Importing Designs
66
Exporting Hardware Designs
77
--------------------------
88

9-
.. autofunction:: pyrtl.verilog.output_to_verilog
9+
.. autofunction:: pyrtl.importexport.output_to_verilog
1010

11-
.. autofunction:: pyrtl.inputoutput.output_to_firrtl
11+
.. autofunction:: pyrtl.importexport.output_to_firrtl
1212

1313
Exporting Testbenches
1414
------------------------
1515

16-
.. autofunction:: pyrtl.verilog.output_verilog_testbench
16+
.. autofunction:: pyrtl.importexport.output_verilog_testbench
1717

1818

1919
Importing Verilog
2020
-----------------
2121

22-
.. autofunction:: pyrtl.inputoutput.input_from_blif
22+
.. autofunction:: pyrtl.importexport.input_from_blif
2323

2424

2525
Outputting for Visualization
2626
---------------------------
2727

28-
.. autofunction:: pyrtl.inputoutput.output_to_trivialgraph
29-
.. autofunction:: pyrtl.inputoutput.output_to_graphviz
30-
.. autofunction:: pyrtl.inputoutput.graphviz_detailed_namer
31-
.. autofunction:: pyrtl.inputoutput.output_to_svg
32-
.. autofunction:: pyrtl.inputoutput.block_to_graphviz_string
33-
.. autofunction:: pyrtl.inputoutput.block_to_svg
34-
.. autofunction:: pyrtl.inputoutput.trace_to_html
35-
.. autofunction:: pyrtl.inputoutput.net_graph
28+
.. autofunction:: pyrtl.visualization.output_to_trivialgraph
29+
.. autofunction:: pyrtl.visualization.output_to_graphviz
30+
.. autofunction:: pyrtl.visualization.graphviz_detailed_namer
31+
.. autofunction:: pyrtl.visualization.output_to_svg
32+
.. autofunction:: pyrtl.visualization.block_to_graphviz_string
33+
.. autofunction:: pyrtl.visualization.block_to_svg
34+
.. autofunction:: pyrtl.visualization.trace_to_html
35+
.. autofunction:: pyrtl.visualization.net_graph
3636

examples/example7-synth-timing-draft.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
import pyrtl
11-
from pyrtl.analysis import estimate
1211

1312
# --- Part 1: Timing Analysis ------------------------------------------------
1413

@@ -27,7 +26,7 @@
2726

2827
# Generating timing analysis information
2928
print("Pre Synthesis:")
30-
timing = estimate.TimingAnalysis()
29+
timing = pyrtl.TimingAnalysis()
3130
timing.print_max_length()
3231

3332
# We are also able to print out the critical paths as well as get them
@@ -39,7 +38,7 @@
3938
# PyRTL also provides estimates for the area that would be used up if the
4039
# circuit was printed as an ASIC.
4140

42-
logic_area, mem_area = estimate.area_estimation(tech_in_nm=65)
41+
logic_area, mem_area = pyrtl.area_estimation(tech_in_nm=65)
4342
est_area = logic_area + mem_area
4443
print("Estimated Area of block", est_area, "sq mm")
4544
print()
@@ -58,7 +57,7 @@
5857
pyrtl.synthesize()
5958

6059
print("Pre Optimization:")
61-
timing = estimate.TimingAnalysis()
60+
timing = pyrtl.TimingAnalysis()
6261
timing.print_max_length()
6362
for net in pyrtl.working_block().logic:
6463
print(str(net))
@@ -73,7 +72,7 @@
7372

7473
# Now to see the difference
7574
print("Post Optimization:")
76-
timing = estimate.TimingAnalysis()
75+
timing = pyrtl.TimingAnalysis()
7776
timing.print_max_length()
7877

7978
for net in pyrtl.working_block().logic:

pyrtl/__init__.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
from .wire import Register
2121

2222
# helper functions
23-
2423
from .helperfuncs import input_list
2524
from .helperfuncs import output_list
2625
from .helperfuncs import register_list
2726
from .helperfuncs import wirevector_list
2827
from .helperfuncs import log2
2928
from .helperfuncs import truncate
3029
from .helperfuncs import match_bitpattern
30+
from .helperfuncs import bitpattern_to_val
3131
from .helperfuncs import chop
3232
from .helperfuncs import val_to_signed_integer
3333
from .helperfuncs import val_to_formatted_str
@@ -66,7 +66,6 @@
6666
from .corecircuits import shift_left_logical
6767
from .corecircuits import shift_right_logical
6868

69-
7069
# memory blocks
7170
from .memory import MemBlock
7271
from .memory import RomBlock
@@ -82,24 +81,24 @@
8281
from .simulation import SimulationTrace
8382
from .compilesim import CompiledSimulation
8483

85-
# input and output to file format routines
86-
from .inputoutput import input_from_blif
87-
from .inputoutput import output_to_trivialgraph
88-
from .inputoutput import graphviz_detailed_namer
89-
from .inputoutput import output_to_graphviz
90-
from .inputoutput import output_to_svg
91-
from .inputoutput import output_to_firrtl
92-
from .inputoutput import block_to_graphviz_string
93-
from .inputoutput import block_to_svg
94-
from .inputoutput import trace_to_html
95-
from .inputoutput import net_graph
84+
# block visualization output formats
85+
from .visualization import output_to_trivialgraph
86+
from .visualization import graphviz_detailed_namer
87+
from .visualization import output_to_graphviz
88+
from .visualization import output_to_svg
89+
from .visualization import block_to_graphviz_string
90+
from .visualization import block_to_svg
91+
from .visualization import trace_to_html
92+
from .visualization import net_graph
9693

97-
# extraction to verilog and verilog testbench
98-
from .verilog import output_to_verilog
99-
from .verilog import OutputToVerilog
100-
from .verilog import output_verilog_testbench
94+
# import from and export to file format routines
95+
from .importexport import output_to_verilog
96+
from .importexport import OutputToVerilog
97+
from .importexport import output_verilog_testbench
98+
from .importexport import input_from_blif
99+
from .importexport import output_to_firrtl
101100

102-
# different analysis and transform passes
101+
# different transform passes
103102
from .passes import common_subexp_elimination
104103
from .passes import constant_propagation
105104
from .passes import synthesize
@@ -109,4 +108,14 @@
109108
from .passes import one_bit_selects
110109
from .passes import two_way_concat
111110

112-
from .transform import net_transform, wire_transform, replace_wire, copy_block, clone_wire
111+
from .transform import net_transform
112+
from .transform import wire_transform
113+
from .transform import copy_block
114+
from .transform import clone_wire
115+
from .transform import replace_wires
116+
from .transform import replace_wire_fast
117+
118+
# analysis and estimation functions
119+
from .analysis import area_estimation
120+
from .analysis import TimingAnalysis
121+
from .analysis import yosys_area_delay

pyrtl/analysis/estimate.py renamed to pyrtl/analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import subprocess
1414
import sys
1515

16-
from ..core import working_block
17-
from ..wire import Input, Const, Register
18-
from ..pyrtlexceptions import PyrtlError, PyrtlInternalError
19-
from ..verilog import output_to_verilog
20-
from ..memory import RomBlock
21-
from ..helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
16+
from .core import working_block
17+
from .wire import Input, Const, Register
18+
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
19+
from .importexport import output_to_verilog
20+
from .memory import RomBlock
21+
from .helperfuncs import _currently_in_jupyter_notebook, _print_netlist_latex
2222

2323

2424
# --------------------------------------------------------------------

pyrtl/analysis/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

pyrtl/conditional.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,33 @@
3434
is a context manager (under which conditional assignements can be made), and "otherwise",
3535
which is an instance that stands in for a 'fall through' case. The details of how these
3636
should be used, and the difference between normal assignments and condtional assignments,
37-
described in more detail in the state machine example from in prytl/examples.
37+
described in more detail in the state machine example in examples/example3-statemachine.py.
38+
39+
There are instances where you might want a wirevector to be set to a certain value in all
40+
but certain with blocks. For example, say you have a processor with a PC register that is
41+
normally updated to PC + 1 after each cycle, except when the current instruction is
42+
a branch or jump. You could represent that as follows::
43+
44+
pc = pyrtl.Register(32)
45+
instr = pyrtl.WireVector(32)
46+
res = pyrtl.WireVector(32)
47+
48+
op = instr[:7]
49+
ADD = 0b0110011
50+
JMP = 0b1101111
51+
52+
with conditional_assignment(
53+
defaults={
54+
pc: pc + 1,
55+
res: 0
56+
}
57+
):
58+
with op == ADD:
59+
res |= instr[15:20] + instr[20:25]
60+
# pc will be updated to pc + 1
61+
with op == JMP:
62+
pc.next |= pc + instr[7:]
63+
# res will be set to 0
3864
3965
In addition to the conditional context, there is a helper function "currently_under_condition"
4066
which will test if the code where it is called is currently elaborating hardware
@@ -67,6 +93,13 @@ def currently_under_condition():
6793
# instances (hopefully the only and unchanging instances) of the following two types.
6894

6995
class _ConditionalAssignment(object):
96+
def __init__(self):
97+
self.defaults = {}
98+
99+
def __call__(self, defaults):
100+
self.defaults = defaults
101+
return self
102+
70103
""" Context providing funcitionality of "conditional_assignment". """
71104
def __enter__(self):
72105
global _depth
@@ -75,7 +108,7 @@ def __enter__(self):
75108

76109
def __exit__(self, *exc_info):
77110
try:
78-
_finalize()
111+
_finalize(self.defaults)
79112
finally:
80113
# even if the above finalization throws an error we need to
81114
# reset the state to prevent errors from bleeding over
@@ -181,7 +214,7 @@ def _pred_sets_are_in_conflict(pred_set_a, pred_set_b):
181214
return True
182215

183216

184-
def _finalize():
217+
def _finalize(defaults):
185218
"""Build the required muxes and call back to WireVector to finalize the wirevector build."""
186219
from .memory import MemBlock
187220
from pyrtl.corecircuits import select
@@ -203,13 +236,13 @@ def _finalize():
203236
# handle wirevector and register assignments
204237
else:
205238
if isinstance(lhs, Register):
206-
if hasattr(lhs, 'condition_default'):
207-
result = lhs.condition_default
239+
if lhs in defaults:
240+
result = defaults[lhs]
208241
else:
209242
result = lhs # default for registers is "self"
210243
elif isinstance(lhs, WireVector):
211-
if hasattr(lhs, 'condition_default'):
212-
result = lhs.condition_default
244+
if lhs in defaults:
245+
result = defaults[lhs]
213246
else:
214247
result = 0 # default for wire is "0"
215248
else:

pyrtl/core.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def add_wire_dst(edge, node):
460460

461461
def _repr_svg_(self):
462462
""" IPython display support for Block. """
463-
from .inputoutput import block_to_svg
463+
from .visualization import block_to_svg
464464
return block_to_svg(self)
465465

466466
def __iter__(self):
@@ -730,11 +730,21 @@ def sanity_check_net(self, net):
730730
class PostSynthBlock(Block):
731731
""" This is a block with extra metadata required to maintain the
732732
pre-synthesis interface during post-synthesis.
733+
734+
It currently holds the following instance attributes:
735+
736+
* *.io_map*: a map from old IO wirevector to a list of new IO wirevectors it maps to;
737+
this is a list because for unmerged io vectors, each old N-bit IO wirevector maps
738+
to N new 1-bit IO wirevectors.
739+
* *.reg_map*: a map from old register to a list of new registers; a list because post-synthesis,
740+
each N-bit register has been mapped to N 1-bit registers
741+
* *.mem_map*: a map from old memory block to the new memory block
733742
"""
734743

735744
def __init__(self):
736745
super(PostSynthBlock, self).__init__()
737-
self.io_map = {}
746+
self.io_map = collections.defaultdict(list)
747+
self.reg_map = collections.defaultdict(list)
738748
self.mem_map = {}
739749

740750

0 commit comments

Comments
 (0)