A behavioral hardware simulator
Project description
SimuHW
Overview
SimuHW is a behavioral hardware simulator provided as a Python module.
Python 3.11 or later is required.
Installation
Release Version
You can install the release version by the following command.
$ python -m pip install simuhw
Development Version
You can install the development version by the following commands.
$ cd simuhw # the repository root directory
$ make req
$ make clean
$ make dist
$ python -m pip install --no-index --find-links=./dist simuhw
Usage
Concept
- Word: a chunk of bits being transferred by wires.
- Device: a hardware element such as a wire, switching devices, and memory devices.
- Channel: a wire to transfer words.
- Memory: a memory device to memorize words associated with specific addresses.
- Port: an endpoint provided by a device to input or output words.
- Probe: an entity to record word values with the respective times, whenever the value of the word passing through a specific port or stored at a specific address in a memory changes.
Import of Module
To use SimuHW, import simuhw module. An example is shown below.
import simuhw as hw
Simulation of Hardware Devices
-
Create instances of the derived classes of
Deviceclass. As of version 0.3.0, the following device classes are available.- Utility
- Clock
- Channel
- Branch
- Elementary Combinational Circuit
- Elementary Sequential Circuit
- Counter
- Bit Operation
LeftShifterRightShifterArithmeticRightShifterLeftRotatorRightRotatorPopulationCounterLeadingZeroCounterTrailingZeroCounterBitReverserSIMD_LeftShifterSIMD_RightShifterSIMD_ArithmeticRightShifterSIMD_LeftRotatorSIMD_RightRotatorSIMD_PopulationCounterSIMD_LeadingZeroCounterSIMD_TrailingZeroCounterSIMD_BitReverser
- Integer Arithmetic
- Floating-Point Arithmetic
Available only if an appropriate version of
softfloatpymodule is found.float.FPNegatorfloat.FPAdderfloat.FPSubtractorfloat.FPMultiplierfloat.FPFusedMultiplyAdderfloat.FPDividerfloat.FPRemainderfloat.FPSquareRootfloat.FPComparatorfloat.FPClassifierfloat.FPToIntegerRounderfloat.FPToIntegerConverterfloat.FPToSignedIntegerConverterfloat.FPFromIntegerRounderfloat.FPFromSignedIntegerConverterfloat.FPConverterfloat.SIMD_FPNegatorfloat.SIMD_FPAdderfloat.SIMD_FPSubtractorfloat.SIMD_FPMultiplierfloat.SIMD_FPFusedMultiplyAdderfloat.SIMD_FPDividerfloat.SIMD_FPRemainderfloat.SIMD_FPSquareRootfloat.SIMD_FPComparatorfloat.SIMD_FPClassifierfloat.SIMD_FPToIntegerRounderfloat.SIMD_FPToIntegerConverterfloat.SIMD_FPToSignedIntegerConverterfloat.SIMD_FPFromIntegerConverterfloat.SIMD_FPFromSignedIntegerConverterfloat.SIMD_FPConverterfloat.riscv.FRec7float.riscv.FRSqrt7float.riscv.SIMD_FRec7float.riscv.SIMD_FRSqrt7
- Memory
An example is shown below.
width: int = 16 # Word size in bits source: hw.Source = hw.Source(width, [ (b'\x00\x01', 0.0e-9), (b'\xc1\x85', 3.0e-9), (b'\xd3\xbb', 6.0e-9), (b'\xf2\x3a', 10.0e-9) ]) drain: hw.Drain = hw.Drain(width)
-
Connect the output ports to the input ports of the device class instances. An example is shown below.
source.port_o.connect(drain.port_i)
-
Create instances of
ChannelProbeclass orMemoryProbeclass.ChannelProbeclass instances can be added to input ports or output ports, andMemoryProbeclass instances can be added to instances of the derived classes ofMemoryclass. An example is shown below.probe: hw.ChannelProbe = hw.ChannelProbe('out', width)
-
Add the probes to the ports or the memory. An example is shown below.
drain.port_i.add_probe(probe)
-
Create an instances of
LogicAnalyzerclass. An example is shown below.la: hw.LogicAnalyzer = hw.LogicAnalyzer()
-
Add the probes to the logic analyzer. An example is shown below.
la.add_probe(probe)
-
Create an instance of
Simulatorclass. An example is shown below.sim: hw.Simulator = hw.Simulator([source, drain])
-
Start the simulation. An example is shown below.
sim.start()
-
Save the word value change timings recorded in the probes to a VCD file. An example is shown below.
with open('test.vcd', mode='w') as file: la.save_as_vcd(file)
-
View the VCD file using a waveform viewer such as GTKWave.
The whole source code of the example above is shown below.
import simuhw as hw
width: int = 16 # Word size in bits
source: hw.Source = hw.Source(width, [
(b'\x00\x01', 0.0e-9),
(b'\xc1\x85', 3.0e-9),
(b'\xd3\xbb', 6.0e-9),
(b'\xf2\x3a', 10.0e-9)
])
drain: hw.Drain = hw.Drain(width)
source.port_o.connect(drain.port_i)
probe: hw.ChannelProbe = hw.ChannelProbe('out', width)
drain.port_i.add_probe(probe)
la: hw.LogicAnalyzer = hw.LogicAnalyzer()
la.add_probe(probe)
sim: hw.Simulator = hw.Simulator([source, drain])
sim.start()
with open('test.vcd', mode='w') as file:
la.save_as_vcd(file)
This example simulates a Source device and a Drain device which are connected directly, and saves word value change timings at the input port of the Drain device to the file test.vcd.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simuhw-0.4.1.tar.gz.
File metadata
- Download URL: simuhw-0.4.1.tar.gz
- Upload date:
- Size: 38.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00c52af53ed8191062f508b6fd86f4b4c7a5d7c04d8b6576803166011b92905c
|
|
| MD5 |
2852a6018d9c126c6bba77cd4c563994
|
|
| BLAKE2b-256 |
590625bedc79a4121b4e9c744ba53bd1b9b0002ceea5eabed0623bf178e17527
|
Provenance
The following attestation bundles were made for simuhw-0.4.1.tar.gz:
Publisher:
release.yml on arithy/simuhw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simuhw-0.4.1.tar.gz -
Subject digest:
00c52af53ed8191062f508b6fd86f4b4c7a5d7c04d8b6576803166011b92905c - Sigstore transparency entry: 799238150
- Sigstore integration time:
-
Permalink:
arithy/simuhw@70bb39fb0a4c2433eb3858006677f33a5f5488ae -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/arithy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@70bb39fb0a4c2433eb3858006677f33a5f5488ae -
Trigger Event:
release
-
Statement type:
File details
Details for the file simuhw-0.4.1-py3-none-any.whl.
File metadata
- Download URL: simuhw-0.4.1-py3-none-any.whl
- Upload date:
- Size: 114.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b10602f370ed59351b9a9af23a773faca41bd0b1f8ed11d590137ea62cee2ea2
|
|
| MD5 |
485cc902b095bf20491795a599cef592
|
|
| BLAKE2b-256 |
a29be58412dcb6dcbfe2752b7c9fcfb65c3c20d57939d909f5e6574691ec6505
|
Provenance
The following attestation bundles were made for simuhw-0.4.1-py3-none-any.whl:
Publisher:
release.yml on arithy/simuhw
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simuhw-0.4.1-py3-none-any.whl -
Subject digest:
b10602f370ed59351b9a9af23a773faca41bd0b1f8ed11d590137ea62cee2ea2 - Sigstore transparency entry: 799238156
- Sigstore integration time:
-
Permalink:
arithy/simuhw@70bb39fb0a4c2433eb3858006677f33a5f5488ae -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/arithy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@70bb39fb0a4c2433eb3858006677f33a5f5488ae -
Trigger Event:
release
-
Statement type: