This project implements a parameterized floating point unit in SystemVerilog with both cocotb (Python) and SystemVerilog testbenches. The verification framework leverages multiple reference models including NumPy's floating-point implementation, direct x86 FPU instructions, and a pure Python model for comprehensive verification.
fpu_design/ # Project root
├── rtl/
│ └── fpu.sv # Main FPU RTL implementation
├── tb/
│ ├── fpu_operations.py # Python FP operations and verification models
│ ├── test_fpu.py # Basic cocotb testbench
│ └── test_fpu_comprehensive.py # Comprehensive cocotb testbench
├── tb_sv/
│ └── fpu_tb.sv # SystemVerilog testbench
├── sim/
│ └── run_tests.py # Legacy test runner
├── fpu_verification/ # Python verification package
│ ├── __init__.py
│ └── sim/
│ ├── __init__.py
│ └── run_tests.py # Main test runner with simulator configuration
├── requirements.txt # Python package dependencies
└── pyproject.toml # Python package configuration
- IEEE-754 compliant floating-point operations
- Parameterized design:
- Configurable exponent width (default: 8 bits)
- Configurable mantissa width (default: 23 bits)
- Supported operations:
- Addition (000)
- Subtraction (001)
- Multiplication (010)
- Division (011)
- Pipelined architecture for higher throughput
- Clock gating for dynamic power reduction
- Operand isolation for static power optimization
- Leading zero detection with priority encoder
- Carry-save adder for efficient addition/subtraction
- Overflow/Underflow detection
- NaN handling
- Infinity arithmetic
- Denormal number support
The verification framework employs three different reference models for comprehensive testing:
-
NumPy Reference Model
- Uses NumPy's highly optimized floating-point implementation
- Provides IEEE-754 compliant results
- Handles special cases (NaN, Infinity, denormals)
-
x86 FPU Instructions
- Direct access to x86 hardware FPU via ctypes
- Hardware-accelerated floating-point operations
- Provides real hardware reference results
-
Pure Python Model
- Bit-exact floating-point implementation
- Full visibility into internal operations
- Useful for debugging and edge cases
- Automatic test vector generation
- Special case testing (NaN, Infinity, denormals)
- Comprehensive coverage collection
- Waveform generation for debugging
- Performance benchmarking against reference models
- Install UV (Python package installer):
pip install uv
- Install Icarus Verilog (or your preferred simulator):
# For Ubuntu/Debian
sudo apt-get install iverilog
# For macOS
brew install icarus-verilog
# For other systems, visit: http://iverilog.icarus.com/
- Create a new virtual environment:
uv venv
- Activate the virtual environment:
# On Linux/macOS
source .venv/bin/activate
# On Windows
.venv\Scripts\activate
- Install the project in development mode:
uv pip install -e .
The project includes two types of testbenches: SystemVerilog and Python (cocotb). You can run them separately or together using the test runner.
The test runner supports running both SystemVerilog and cocotb tests:
# Run all tests (both SystemVerilog and cocotb)
uv pip run run-fpu-tests
# Run only SystemVerilog testbench
uv pip run run-fpu-tests --testbench sv
# Run only cocotb tests
uv pip run run-fpu-tests --testbench cocotb
# Use a different simulator
uv pip run run-fpu-tests --sim verilator
- SystemVerilog testbench outputs are in
sim_build_sv/
- cocotb test outputs are in
sim_build_cocotb/
- Waveforms are generated in the respective build directories
- Self-contained SystemVerilog testbench
- Includes built-in test vector generation
- Comprehensive assertion coverage
- Direct hardware signal monitoring
- Uses multiple reference models (NumPy, x86, Python)
- Automated test vector generation
- Special case testing
- Performance benchmarking
- Python-based coverage collection
SIM
: Choose simulator (default: icarus)- Supported: icarus, verilator
HDL_TOPLEVEL_LANG
: HDL language (default: verilog)- Supported: verilog, systemverilog
EXPONENT_WIDTH
: Width of exponent field (default: 8)MANTISSA_WIDTH
: Width of mantissa field (default: 23)CLOCK_GATING_EN
: Enable clock gating (default: 1)OPERAND_ISOLATION_EN
: Enable operand isolation (default: 1)
Waveform files (.vcd) are generated in the sim_build directory. You can view them using:
- GTKWave:
gtkwave sim_build/wave.vcd
- Create a new branch:
git checkout -b feature/your-feature-name
- Make changes and ensure tests pass:
uv pip run pytest
- Format code before committing:
uv pip run black .
uv pip run isort .
- If you encounter import errors:
# Reinstall the package
uv pip install -e .
- If simulator is not found:
# Verify simulator installation
which iverilog # for Icarus Verilog
- For waveform viewing issues:
# Install GTKWave
sudo apt-get install gtkwave # Ubuntu/Debian
brew install gtkwave # macOS
- Natnael Kahssay
MIT License