Presentation is loading. Please wait.

Presentation is loading. Please wait.

RTL design in python: porting the mMIPS

Similar presentations

Presentation on theme: "RTL design in python: porting the mMIPS"— Presentation transcript:

1 RTL design in python: porting the mMIPS
Jos Huisken June 25th, 2013 Title: RTL design in python: porting the mMIPS. Abstract: Can you do RTL design in a general purpose programming language? Yes, you can very conveniently with Python using an open-source package named MyHDL. In this presentation I will introduce MyHDL and share the experience in porting the mMIPS from SystemC. After introducing the basic MyHDL modelling techniques, where Python generators are used to model hardware concurrency, we'll address shortly (co-)simulation and the connection with Xilinx and Cadence design environments using the mMIPS. The real convenience however of enabling RTL design in a general purpose programming language is in high level modelling and verification. For instance verification against Matlab style specifications can be performed within a single program.

2 What is Python?

3 What is Python? A general purpose programming language
Growing in popularity Interpreted language (bytecode-interpretive) Multi-paradigm Clean object-oriented Functional – in the LISP tradition Structural (procedural-imperative) Extremely readable syntax Very high-level Lists Dictionaries (associative arrays) Extensive documentation

4 What is MyHDL? A Python package which enables hardware description
Open-source project Batteries included (more on this later)

5 MyHDL Extends Python MyHDL is Python Using Python constructs to extend
Object Oriented Signal, intbv Generators Micro-thread like, enables concurrency behavior Resumable functions that maintain state Decorators Meta-programming “Macro” mechanism Modifies a function / generator @always_seq

6 Why use MyHDL Manage Complex Designs New to Digital Hardware Design
Scripting Languages Intensively Used Modern Software Development Techniques for Hardware Design Algorithm Development and HDL Design in a Single Environment Require Both Verilog and VHDL VHDL Too Verbose SystemVerilog Too Complicated You Been TCL’d too much

7 What MyHDL is NOT Not arbitrary Python to silicon
Not a radically new approach Not a synthesis tool Not an IP block library Not only for implementation Not well suited for accurate time simulation

8 Abstraction Levels

9 Register Transfer Register Transfer Level (RTL) abstraction
This is the commonly excepted description of mainstream HDLs: Verilog and VHDL Describes the operations between registers MyHDL operates at the Register Transfer Level (RTL) MyHDL extends Python for hardware description

10 MyHDL Types intbv Signal Convertible types
Bit vector type, an integer with bit vector properties Signal Deterministic communication, see it as a VHDL signal Convertible types bool int tuple of int list of bool and list of intbv

11 MyHDL Generators A Python generator is a resumable function
Generators are the core of MyHDL Provide the similar functionality as a VHDL process or Verilog always block yield in a generator

12 Python generator: Fibonacci
# function version def fibon(n): a = b = 1 result = [] for i in xrange(n): result.append(a) a, b = b, a + b return result fibon(8) [1, 1, 2, 3, 5, 8, 13, 21] # generator version def fibon(n): a = b = 1 result = [] for i in xrange(n): yield a a, b = b, a + b for x in fibon(8): print x,

13 MyHDL Decorators MyHDL Decorators
“creates ready-to-simulate generators from local function definitions” @instance @always(sensitivity list) @always_seq(clock,reset) @always_comb

14 Python decorator @mydecorator def myfunc(): return # is equivalent to myfunc = mydecorator(myfunc) def verbose(origfunc): # make new func def newfunc(*args, **kwargs): print “entering”, origfunc.__name__ origfunc(*args, **kwargs) print “exiting”, origfunc.__name__ return newfunc @verbose def myfunc(s): print s myfunc(‘hoi’) entering myfunc hoi exiting myfunc A decorator is a function (mydecorator) that takes a function object as an argument, and returns a function object as a return value. @mydecorator: just syntactic sugar

15 MyHDL Flow

16 MyHDL Conversion MyHDL has a convertible subset Pragmatic
Convert to Verilog Convert to VHDL Pragmatic Standard FPGA / ASIC flow after conversion

17 Anatomy of a MyHDL Module

18 Simple adder in myhdl

19 A register

20 ALU waveform, using gtkwave

21 Verilog co-simulation
Icarus Verilog Cadence ncsim Cadence ncsim, CMOS90 netlist Select icarus/verilog implementation:

22 Generated: add.v

23 mMIPS in MyHDL Single cycle mini-mini MIPS Multi cycle mini MIPS ……

24 Ecosystem import pylab import matplotlib

25 Digital Filter

26 IIR Type I Digital Filter
1 def m_iir_type1(clock,reset,x,y,ts,B=None,A=None): 2 # make sure B and A are ints and make it a ROM (tuple of ints) 3 b0,b1,b2 = map(int,B) 4 a0,a1,a2 = map(int,A) 5 6 ffd = [Signal(intbv(0, min=x.min, max=x.max)) for ii in (0,0)] 7 fbd = [Signal(intbv(0, min=x.min, max=x.max)) for ii in (0,0)] 8 # intermidiate result, resize from here 9 ysop = Signal(intbv(0, min=dmin, max=dmax)) 10 reset=reset) 12 def hdl(): 13 if ts: 14 ffd[1].next = ffd[0] 15 ffd[0].next = x fbd[1].next = fbd[0] 18 fbd[0].next = ysop//Am # truncate (>>) # extra pipeline on the output at clock 21 = (b0*x) + (b1*ffd[0]) + (b2*ffd[1]) - \ 22 (a1*fbd[0]) - (a2*fbd[1]) # truncate to the output word format 25 = ysop//Am # truncate (>>) return hdl

27 Simulation

28 Test Frameworks Test frameworks are easy Enables new levels or reuse
Test Driven Design (TDD) Existing test environments py.test nose unittest

29 Example: fpgalink Test code Application code Host interface software
Connect the host software to the DUT Host driver + USB controller FPGA logic (HDL) External models and checkers Physical transducers

30 Conclusion Python MyHDL mMIPS
Easy to learn Batteries included MyHDL Hardware description in Python Powerful environment, ecosystem Verification simplified and fun mMIPS Ported from SystemC Simulated and Co-Simulated, not fully verified Synthesized: ISE (untested) and Cadence rc (co-simulated) Python: allows (…) matlab style interaction

31 Short MyHDL History Jan Decaluwe
Creator of MyHDL Founder & Board Member Easic Created MyHDL between First Release on SourceForge Sep 30, 2003 MyHDL ASIC

32 Acknowledgement You guys Christopher Felton
for hosting and providing the mMips Christopher Felton Several slides came from him!

33 Resources ?? Any Further Questions ??
And an invitation to join (still) password protected: ?? Any Further Questions ??

Download ppt "RTL design in python: porting the mMIPS"

Similar presentations

Ads by Google