• communication through "signals" • actions triggered by "events" on signals • deterministic "by construction" • fine-grained control of data type bit widths Requirement: an HDL must natively support these characteristics
microthread programming language, with built-in determinism. • An HDL must also implement a hardware- friendly type system. • Warning: Many hardware designers don't want to hear that it's all just software programming!
Python library that supports the following features • Microthreads • Events that trigger actions • Deterministic communication • Hardware friendly type system
Signals implement value buffering: s = Signal(0) s.next = 5 • value updates occur automatically by a scheduler (a.k.a. the "simulator") • if all communication goes through Signals, the model is deterministic
events: ▪ value changes ▪ 0->1 transition (a "posedge") ▪ 1->0 transition (a "negedge") • Commonly used global synchronizing event: the "clock edge" • Other events exist, e.g. waiting for a delay
z, a, b, sel are Signal objects (outer scope) def mux(): while True: # loop forever yield a, b, sel # wait on a value change if sel: # of a, b, or sel z.next = a else: z.next = b
are implemented • use native Python features as much as possible, e.g.: ◦ lists for random access memory (RAM) ◦ tuples for read-only memory (ROM) • a hardware module is modeled by a function that returns generators • hierarchy is modeled by a submodule "call"
0); signal b: signed(3 downto 0); signal c: signed(4 downto 0); ... c <= a + b; Answer: test.vhd:24:10: no function declarations for operator "+": compilation error.
low-level, non-abstract types: signed/unsigned • mixed expressions are problematic • Verilog casts everything to unsigned! • VHDL's strong typing doesn't work well with low-level types
good old integers • the intbv class: "integer with bit vector capabilities" • specify range for implementation efficiency a = intbv(0, min=0, max=8) b = intbv(0, min=-8, max=8) • range boundaries reused in value assertions • slicing & indexing interface to access the bits z.next = a[2:0]
it compiles an HDL hardware model into a gate-level implementation • the entry point of a fully automated back-end • only a restricted HDL subset is synthesizable: the Register Transfer Level (RTL) • available from multiple vendors in all price categories (free to $$$) • Verilog and VHDL only!
MyHDL can be automatically converted to Verilog/VHDL • the convertor maintains the abstraction level • however, it supports some unique MyHDL features and automates some tedious tasks • creates readable VHDL/Verilog that integrates seamlessly in the design flow • the convertible subset is much broader than the synthesizable subset
b = Signal(intbv(0, min=-8, max=8)) c = Signal(intbv(0, min=-8, max=15)) c.next = a + b • Conversion to Verilog: c <= $signed({1'b0, a}) + b; • Conversion to VHDL: c <= signed(resize(a, 5)) + b; • The convertor does the casts and resizings, so you don't have to!
hardest task in hardware design • With MyHDL, hardware verification engineers benefit from Python's expressive power and ecosystem • Test-driven design (TTD) for hardware (with unittest, py.test...) • The foundation is an event-driven simulator provided by MyHDL
alternative, Python 2.7 compliant Python interpreter • JIT technology for speed-up • benchmark simulations run 8 - 20 faster • within speed range of commercial VHDL/Verilog simulators • overnight game changer for "free" :-)