π Comprehensive SystemVerilog learning repository with practical examples, detailed documentation, and hands-on exercises.
This repository contains a complete set of SystemVerilog verification labs covering fundamental to advanced topics. Each lab includes:
- β Complete, runnable code examples
- β Detailed README documentation
- β Practical, real-world scenarios
- β Icarus Verilog compatibility notes
- β Best practices and common pitfalls
- File:
lab1_signed_unsigned.sv(6.2K) - Topics: bit vs logic, signed vs unsigned, X/Z states, overflow detection
- Documentation: LAB1A_SIGNED_UNSIGNED_README.md
iverilog -g2012 -o lab1_signed_unsigned lab1_signed_unsigned.sv && vvp lab1_signed_unsigned- File:
lab1b_packed_array.sv(8.7K) - Topics: Multi-dimensional packed arrays, part-select, bitwise operations
- Documentation: LAB1B_PACKED_ARRAY_README.md
iverilog -g2012 -o lab1b_packed_array lab1b_packed_array.sv && vvp lab1b_packed_array- File:
lab1c_unpacked_array.sv(12K) - Topics: 2D matrices, image processing simulation, row/column operations
- Documentation: LAB1C_UNPACKED_ARRAY_README.md
iverilog -g2012 -o lab1c_unpacked_array lab1c_unpacked_array.sv && vvp lab1c_unpacked_array- File:
lab1d_unpacked_array.sv(19K) - Topics: Key-value storage, MAC address tables, sparse memory
- Documentation: LAB1D_ASSOCIATIVE_ARRAY_README.md
β οΈ Note: Icarus Verilog doesn't support associative arrays. Use Questa/VCS/Xcelium.
iverilog -g2012 -o lab1d_unpacked_array lab1d_unpacked_array.sv && vvp lab1d_unpacked_array- File:
lab1e_queue.sv(21K) - Topics: FIFO/LIFO buffers, push/pop operations, circular buffers, packet processing
- Documentation: LAB1E_QUEUE_README.md
iverilog -g2012 -o lab1e_queue lab1e_queue.sv && vvp lab1e_queue- File:
lab1f_tasks_functions.sv(16K) - Topics:
- ADC conversion function (real β 8-bit)
- Pulse generation task (clock-synchronized)
- Command execution task (ALU with queue)
- Enum, packed struct, automatic keyword
- Documentation: LAB1F_TASKS_FUNCTIONS_README.md
iverilog -g2012 -o lab1f_tasks_functions lab1f_tasks_functions.sv && vvp lab1f_tasks_functions# Install Icarus Verilog (Ubuntu/Debian)
sudo apt-get install iverilog
# Install Icarus Verilog (Fedora)
sudo dnf install iverilog
# Verify installation
iverilog -v# Clone the repository
git clone https://github.com/anoshyn/verification.git
cd verification
# Run all labs
./run_all_labs.sh
# Or run individually
iverilog -g2012 -o lab1a_signed_unsigned lab1a_signed_unsigned.sv && vvp lab1a_signed_unsigned
iverilog -g2012 -o lab1c_unpacked_array lab1c_unpacked_array.sv && vvp lab1c_unpacked_array
iverilog -g2012 -o lab1e_queue lab1e_queue.sv && vvp lab1e_queue
iverilog -g2012 -o lab1f_tasks_functions lab1f_tasks_functions.sv && vvp lab1f_tasks_functionsrm -f lab1a_signed_unsigned lab1b_packed_array lab1c_unpacked_array lab1d_unpacked_array lab1e_queue lab1f_tasks_functions- LAB1_SUMMARY.md - Complete overview of all labs with quick reference
Each lab has detailed documentation covering:
- Syntax and semantics
- Practical examples
- Best practices
- Common pitfalls
- Simulator compatibility notes
graph TD
A[Lab 1A: Data Types]
--> B[Lab 1A Extra: Packed Arrays]
A --> C[Lab 1B: Unpacked Arrays]
C --> D[Lab 1C: Associative Arrays]
C --> E[Lab 1D: Queue]
E --> F[Lab 1F: Tasks & Functions]
F --> G[Future: Classes & OOP]
G --> H[Future: UVM Framework]
- Lab 1A - Foundation: Data types, signed/unsigned
- Lab 1B - Packed arrays for synthesis
- Lab 1C - Unpacked arrays for testbenches
- Lab 1D - Dynamic queues for verification
- Lab 1E - Associative arrays (commercial simulators)
- Lab 1F - Functions and tasks for modularity
- β
bit,logic,logic signed,int - β 2-state vs 4-state (X/Z handling)
- β Sign extension vs Zero extension
- β Overflow detection and prevention
| Type | Size | Operations | Synthesis | Use Case |
|---|---|---|---|---|
| Packed | Fixed | Bitwise | β Yes | RTL design, ports |
| Unpacked | Fixed | Index | β No | Testbenches, memory |
| Associative | Dynamic | Key-value | β No | Lookup tables, sparse |
| Queue | Dynamic | Push/pop | β No | Buffers, FIFO/LIFO |
| Feature | Function | Task |
|---|---|---|
| Return value | β
return |
β Use output |
| Timing | β No #delay |
β Can use timing |
| Zero time | β Always | β Can consume time |
| Use for | Calculations | Sequences |
- Network Packet Buffer (Queue) - FIFO with priority insertion
- Image Processing (Unpacked Array) - 2D pixel matrix manipulation
- MAC Address Table (Associative) - Network switch simulation
- ADC Converter (Function) - Real to digital conversion
- Pulse Generator (Task) - Clock-synchronized signal generation
- ALU with Command Queue (Task + Queue) - Command processor
// Use appropriate types
logic signed [7:0] temperature; // For signed values
bit [7:0] counter; // For unsigned, 2-state
// Prevent overflow
logic [8:0] sum = a + b; // Extra bit for carry
// Use automatic for reentrant code
function automatic int calc(input int x);
// Local variables are automatic
endfunction// Mixing signed/unsigned without care
logic [7:0] a = -1; // Interpreted as 255!
// Insufficient bits for result
logic [7:0] sum = 8'd200 + 8'd100; // Overflow!
// Non-automatic for recursive functions
function int factorial(input int n); // Missing automatic!While Icarus Verilog is excellent for learning, some SystemVerilog features aren't supported:
β Not Supported:
- Associative arrays
%pformat specifier for queues- Queue of structs (workaround: separate queues)
- Aggregate initialization
'{1, 2, 3} - Queue comparison operators
β Workarounds Provided:
- Manual iteration for queue display
- Individual
push_back()for initialization - Separate queues for struct fields
For full SystemVerilog support, use:
- Synopsys VCS
- Mentor Questa
- Cadence Xcelium
- Total Labs: 6 (+ extras)
- Total Code: ~83K lines
- Total Documentation: ~73K documentation
- Code Examples: 100+
- Practical Scenarios: 15+
After completing these labs, you will be able to:
β
Choose appropriate data types for signed/unsigned values
β
Prevent and detect overflow conditions
β
Use packed arrays for synthesizable RTL design
β
Use unpacked arrays for testbench data structures
β
Implement dynamic queues for FIFO/LIFO buffers
β
Write functions for combinational logic
β
Write tasks for sequential operations with timing
β
Use enums and structs for clean code organization
β
Build realistic verification testbenches
- Lab 3: Classes and Object-Oriented Programming
- Lab 4: Interfaces and Modports
- Lab 5: Randomization and Constraints
- Lab 6: Functional Coverage
- Lab 7: Basic UVM Components
- Lab 8: UVM Testbench Architecture
- "SystemVerilog for Verification" by Chris Spear & Greg Tumbush
- "SystemVerilog for Design" by Stuart Sutherland
- "Writing Testbenches using SystemVerilog" by Janick Bergeron
Contributions are welcome! Please feel free to:
- Report issues
- Suggest improvements
- Add new examples
- Fix documentation typos
- Share your learning experience
Author: Andrii
Repository: github.com/anoshyn/verification
This project is for educational purposes. Feel free to use, modify, and share for learning SystemVerilog verification.
If you find these labs helpful, please β star this repository!
Last Updated: 20 ΠΆΠΎΠ²ΡΠ½Ρ 2025 Ρ.
SystemVerilog Standard: IEEE 1800-2012
Simulator: Icarus Verilog 12.0
Happy Learning! π