Pure-Python simulator of Tomasulo's out-of-order instruction scheduling: reservation stations, common data bus, and register renaming, with cycle-by-cycle traces for computer architecture education.
Project description
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.
Project details
Release history Release notifications | RSS feed
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 tomasulo-0.1.0.tar.gz.
File metadata
- Download URL: tomasulo-0.1.0.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17f616acadcc71dba754767f5a164f6f8af5959194acfd22a235ecd5695392a7
|
|
| MD5 |
08693d2391869d5d90c054b1dd80cfd0
|
|
| BLAKE2b-256 |
c30bbe0a4659dfc3a020cecd166149828a13d9f4e445e87f0e96ffde90cc445f
|
File details
Details for the file tomasulo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tomasulo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79b70e07751dd2c8cc76642a267e6144ecf9bc9851125083f3bc80710d2f930b
|
|
| MD5 |
241bd2bd9f81ca7614f1124de1d6e57f
|
|
| BLAKE2b-256 |
cc213b51e1538467e4856d56ebb5691c94144325f6999d6f5f920c14aee36370
|