Python for ASIC/SoC Engineers¶
Goal of this tutorial¶
When learning a new programming language, two things occur.
- Your brain constantly tries to draw parallels with another language you are already familiar with. For ASIC engineers, this is SystemVerilog.
- With each new concept you learn, your mind searches for patterns and evaluates how you may apply it to your work.
This tutorial is designed to meet both these needs and address the typical demands and use cases of RTL design, DV, emulation, and validation engineers.
- In Chapter 1, we'll look at two common data structures: lists and dictionaries, and compare them to SystemVerilog queues and associative arrays.
- Chapter 2 focuses on numbers. We'll learn how to convert between
int
,hex
andbin
, and compare Python's random number generation capability to that of SystemVerilog. - The chapter on file access will show you how to work with JSON and CSV files.
- You will learn how to extract data from logs and reports, and create scripts that boost your workflow and productivity.
- Finally, this tutorial will help you formalize your knowledge, become a confident Python programmer, and produce code straight from your finger tips without needing to google the minor stuff.
Practicing examples¶
Here are two ways to practice the examples featured in this tutorial.
- Use an online Python interpreter
- Launch Python by entering
python3
in your Linux or MacOS terminal. This is the method used for the code in this tutorial. Here is an example of what you will see when you enterpython3
on a Linux terminal.% python3 Python 3.9.6 (default, Oct 4 2024, 08:01:31) Type "help", "copyright", "credits" or "license" for more information. >>> hex(500) '0x1f4' >>> '/'.join(['user', 'path', 'dir']) 'user/path/dir'
Table of contents¶
Chapter 1: Lists and dictionaries
Comparing the two main python data structures with SystemVerilog queues and associative arrays
Chapter 2: Numbers
Converting between int, hex and bin numbers, and generating random numbers
Work-In-Progress¶
Chapter 3: Strings and print formatting
Chapter 4: Control flow - if and for loops
Chapter 5: Working with files, paths and directories
Chapter 6: The right way to create a Python script
Chapter 7: Regular Expressions, Reading and Writing files
Chapter 8: Functions
Chapter 9: Subprocess.run
Chapter 10: Passing command line arguments with
argparse
Chapter 11: Bonus: Cool things you should be doing in your Python code
Appendix A: Code editors - VSCode, VIM
Appendix B: Installing packages with
pip
andvenv