tomasulo
Pure-Python simulator of Tomasulo's out-of-order instruction scheduling algorithm. Implements reservation stations, a Common Data Bus (CDB), and register renaming for computer architecture education.
Zero runtime dependencies. Requires Python 3.10+.
Installation
pip install tomasulo
Or with uv:
uv pip install tomasulo
Quick start
from tomasulo import Instruction, TomasuloSim, render_trace
program = [
Instruction(op="LOAD", dest="F6", src1="R2", src2="R0"),
Instruction(op="LOAD", dest="F2", src1="R3", src2="R0"),
Instruction(op="MUL", dest="F0", src1="F2", src2="F4"),
Instruction(op="SUB", dest="F8", src1="F6", src2="F2"),
Instruction(op="DIV", dest="F10", src1="F0", src2="F6"),
Instruction(op="ADD", dest="F6", src1="F8", src2="F2"),
]
sim = TomasuloSim(
stations={"add": 3, "mult": 2, "load": 3},
latencies={"ADD": 2, "SUB": 2, "MUL": 10, "DIV": 40, "LOAD": 2},
)
trace = sim.run(program=program)
print(render_trace(trace=trace))
Output:
# Op Dest Src1 Src2 Issue ExecComplete Write
---------------------------------------------------------------------
1 LOAD F6 R2 R0 1 3 4
2 LOAD F2 R3 R0 2 4 5
3 MUL F0 F2 F4 3 15 16
4 SUB F8 F6 F2 4 6 7
5 DIV F10 F0 F6 5 56 57
6 ADD F6 F8 F2 6 9 10
CLI
tomasulo examples/sample_program.txt
tomasulo examples/sample_program.txt --snapshots
tomasulo --help
Program file format -- one instruction per line:
# comments are ignored
LOAD F6 R2 R0
LOAD F2 R3 R0
MUL F0 F2 F4
SUB F8 F6 F2
DIV F10 F0 F6
ADD F6 F8 F2
Public API
@dataclass
class Instruction:
op: str # "ADD", "SUB", "MUL", "DIV", "LOAD"
dest: str # destination register e.g. "F0"
src1: str # first source register; for LOAD: base address register
src2: str # second source register; for LOAD: unused, pass "R0" by convention
@dataclass
class InstructionResult:
instruction: Instruction
issue_cycle: int
exec_complete_cycle: int
write_cycle: int
@dataclass
class Trace:
results: list[InstructionResult]
snapshots: list[CycleSnapshot]
class TomasuloSim:
def __init__(self, stations: dict[str, int], latencies: dict[str, int]) -> None: ...
def run(self, program: list[Instruction]) -> Trace: ...
def render_trace(trace: Trace) -> str: ...
Algorithm
Stage order each cycle: WRITE, then EXECUTE, then ISSUE.
Hazards handled:
- RAW: a station waits on the tag (Qj/Qk) of the station that will produce a missing operand. When that station broadcasts on the CDB the value is forwarded and the tag is cleared.
- WAR and WAW: handled by register renaming. Each issued instruction renames its destination to the station tag. Only the last writer commits to the register file.
- Structural: at most one result per cycle on the CDB. Ties broken by lowest station index (declaration order).
See docs/architecture.md for a full description.
Development
uv venv && uv pip install -e ".[dev]"
uv run pytest -q
uv run ruff check .
uv run mypy src
uv build
License
MIT. Copyright (c) 2026 Amaar Chughtai.
Metadata
Release files for tomasulo 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tomasulo-0.1.0.tar.gz | 20.9 kB | Without provenance | Details for tomasulo-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tomasulo-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tomasulo-0.1.0-py3-none-any.whl |
Total release size: 33.6 kB
Release files / tomasulo-0.1.0.tar.gz
| Download URL | tomasulo-0.1.0.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17f616acadcc71dba754767f5a164f6f8af5959194acfd22a235ecd5695392a7
|
|
BLAKE2b-256 checksum How to use checksums |
c30bbe0a4659dfc3a020cecd166149828a13d9f4e445e87f0e96ffde90cc445f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / tomasulo-0.1.0-py3-none-any.whl
| Download URL | tomasulo-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79b70e07751dd2c8cc76642a267e6144ecf9bc9851125083f3bc80710d2f930b
|
|
BLAKE2b-256 checksum How to use checksums |
cc213b51e1538467e4856d56ebb5691c94144325f6999d6f5f920c14aee36370
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for tomasulo 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.