tomasulo 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tomasulo-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- tomasulo-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +28 -0
- tomasulo-0.1.0/.github/workflows/ci.yml +39 -0
- tomasulo-0.1.0/.gitignore +42 -0
- tomasulo-0.1.0/CHANGELOG.md +20 -0
- tomasulo-0.1.0/CLAUDE.md +63 -0
- tomasulo-0.1.0/CODE_OF_CONDUCT.md +35 -0
- tomasulo-0.1.0/CONTRIBUTING.md +44 -0
- tomasulo-0.1.0/LICENSE +21 -0
- tomasulo-0.1.0/PKG-INFO +179 -0
- tomasulo-0.1.0/README.md +127 -0
- tomasulo-0.1.0/SECURITY.md +30 -0
- tomasulo-0.1.0/assets/.gitkeep +0 -0
- tomasulo-0.1.0/docs/architecture.md +142 -0
- tomasulo-0.1.0/docs/charter.md +45 -0
- tomasulo-0.1.0/examples/README.md +41 -0
- tomasulo-0.1.0/examples/sample_program.txt +10 -0
- tomasulo-0.1.0/pyproject.toml +65 -0
- tomasulo-0.1.0/src/tomasulo/__init__.py +24 -0
- tomasulo-0.1.0/src/tomasulo/cli.py +210 -0
- tomasulo-0.1.0/src/tomasulo/model.py +118 -0
- tomasulo-0.1.0/src/tomasulo/py.typed +0 -0
- tomasulo-0.1.0/src/tomasulo/simulator.py +311 -0
- tomasulo-0.1.0/src/tomasulo/trace.py +61 -0
- tomasulo-0.1.0/tests/__init__.py +0 -0
- tomasulo-0.1.0/tests/test_simulator.py +481 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Report incorrect simulation output or a crash
|
|
4
|
+
title: "bug: "
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
A clear description of the bug.
|
|
12
|
+
|
|
13
|
+
## Program / input
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
# Paste the instruction program or Python snippet that triggers the bug
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Expected behavior
|
|
20
|
+
|
|
21
|
+
What should happen (include expected cycle numbers if it is a trace bug).
|
|
22
|
+
|
|
23
|
+
## Actual behavior
|
|
24
|
+
|
|
25
|
+
What actually happens. Include the full output or traceback.
|
|
26
|
+
|
|
27
|
+
## Environment
|
|
28
|
+
|
|
29
|
+
- tomasulo version:
|
|
30
|
+
- Python version:
|
|
31
|
+
- OS:
|
|
32
|
+
|
|
33
|
+
## Additional context
|
|
34
|
+
|
|
35
|
+
Any other information that might help diagnose the issue.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest a new feature or improvement
|
|
4
|
+
title: "feat: "
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ""
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
A clear, one-sentence description of the feature.
|
|
12
|
+
|
|
13
|
+
## Motivation
|
|
14
|
+
|
|
15
|
+
Why is this feature useful? What problem does it solve?
|
|
16
|
+
|
|
17
|
+
## Proposed design
|
|
18
|
+
|
|
19
|
+
If you have a concrete design in mind, describe it here. API changes,
|
|
20
|
+
new CLI flags, algorithm extensions, etc.
|
|
21
|
+
|
|
22
|
+
## Alternatives considered
|
|
23
|
+
|
|
24
|
+
What alternatives did you consider and why did you rule them out?
|
|
25
|
+
|
|
26
|
+
## Additional context
|
|
27
|
+
|
|
28
|
+
Any other context, references, or screenshots.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v4
|
|
23
|
+
with:
|
|
24
|
+
version: "latest"
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
run: uv python install ${{ matrix.python-version }}
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: uv pip install -e ".[dev]"
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: uv run pytest -q
|
|
34
|
+
|
|
35
|
+
- name: Lint
|
|
36
|
+
run: uv run ruff check .
|
|
37
|
+
|
|
38
|
+
- name: Type check
|
|
39
|
+
run: uv run mypy src
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
*.so
|
|
7
|
+
*.egg
|
|
8
|
+
*.egg-info/
|
|
9
|
+
dist/
|
|
10
|
+
build/
|
|
11
|
+
.eggs/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
env/
|
|
17
|
+
|
|
18
|
+
# uv
|
|
19
|
+
uv.lock
|
|
20
|
+
|
|
21
|
+
# Type checking
|
|
22
|
+
.mypy_cache/
|
|
23
|
+
.dmypy.json
|
|
24
|
+
|
|
25
|
+
# Testing
|
|
26
|
+
.pytest_cache/
|
|
27
|
+
.coverage
|
|
28
|
+
htmlcov/
|
|
29
|
+
|
|
30
|
+
# Editors
|
|
31
|
+
.vscode/
|
|
32
|
+
.idea/
|
|
33
|
+
*.swp
|
|
34
|
+
*.swo
|
|
35
|
+
*~
|
|
36
|
+
|
|
37
|
+
# macOS
|
|
38
|
+
.DS_Store
|
|
39
|
+
|
|
40
|
+
# Distribution
|
|
41
|
+
*.whl
|
|
42
|
+
*.tar.gz
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-06-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `Instruction`, `InstructionResult`, `StationState`, `RegisterStatus`,
|
|
13
|
+
`CycleSnapshot`, and `Trace` dataclasses in `tomasulo.model`.
|
|
14
|
+
- `TomasuloSim` class implementing the classic Tomasulo algorithm with
|
|
15
|
+
reservation stations, CDB, and register renaming.
|
|
16
|
+
- `render_trace` function for human-readable timing tables.
|
|
17
|
+
- `tomasulo` CLI entry point that reads a plain text program file and
|
|
18
|
+
prints a timing table; supports `--snapshots` for per-cycle detail.
|
|
19
|
+
- Full test suite with golden trace and invariant checks.
|
|
20
|
+
- CI workflow for Python 3.10, 3.11, 3.12, 3.13.
|
tomasulo-0.1.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# tomasulo
|
|
2
|
+
|
|
3
|
+
Pure-Python simulator of Tomasulo's out-of-order instruction scheduling
|
|
4
|
+
algorithm. Zero runtime dependencies. For computer architecture education.
|
|
5
|
+
|
|
6
|
+
## Commands
|
|
7
|
+
|
|
8
|
+
- Create env and install: `uv venv && uv pip install -e ".[dev]"`
|
|
9
|
+
- Test: `uv run pytest -q`
|
|
10
|
+
- Lint: `uv run ruff check .` (format with `uv run ruff format .`)
|
|
11
|
+
- Types: `uv run mypy src`
|
|
12
|
+
- Build: `uv build` (then `uv run --with twine twine check dist/*` before publishing)
|
|
13
|
+
- Run the CLI: `uv run tomasulo examples/sample_program.txt`
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
`src/tomasulo/`:
|
|
18
|
+
- `model.py` -- dataclasses: Instruction, InstructionResult, StationState,
|
|
19
|
+
RegisterStatus, CycleSnapshot, Trace
|
|
20
|
+
- `simulator.py` -- TomasuloSim class; the core engine with _Station internal
|
|
21
|
+
state
|
|
22
|
+
- `trace.py` -- render_trace() for human-readable timing tables
|
|
23
|
+
- `cli.py` -- argparse CLI; run(argv) is testable, main() is the console entry
|
|
24
|
+
- `__init__.py` -- public surface
|
|
25
|
+
|
|
26
|
+
See `docs/architecture.md` for the algorithm, stage ordering, and hazard
|
|
27
|
+
handling.
|
|
28
|
+
|
|
29
|
+
## Algorithm stage order (critical)
|
|
30
|
+
|
|
31
|
+
Each cycle: **WRITE first, then EXECUTE, then ISSUE.**
|
|
32
|
+
|
|
33
|
+
The next-cycle rule: if a station's operands become ready during the WRITE
|
|
34
|
+
phase of cycle N, the station starts executing in cycle N+1, not cycle N.
|
|
35
|
+
This is enforced by setting `remaining` in a second pass after EXECUTE, not
|
|
36
|
+
during WRITE.
|
|
37
|
+
|
|
38
|
+
## Conventions
|
|
39
|
+
|
|
40
|
+
- No default parameter values anywhere in the public API.
|
|
41
|
+
- No em dash characters in code, comments, or docs (use -- or commas).
|
|
42
|
+
- No TODOs in committed code.
|
|
43
|
+
- All computed values are 0.0 (value model -- scheduling only, not arithmetic).
|
|
44
|
+
- Station tag tie-break for CDB: lowest index in declaration order wins.
|
|
45
|
+
|
|
46
|
+
## Testing rules
|
|
47
|
+
|
|
48
|
+
- Golden trace tests verify exact cycle numbers for the classic 6-instruction
|
|
49
|
+
program with standard latencies and station counts.
|
|
50
|
+
- Invariant tests verify algorithm properties (RAW, WAW, structural stall).
|
|
51
|
+
- Bug fixes start with a failing test.
|
|
52
|
+
|
|
53
|
+
## Release
|
|
54
|
+
|
|
55
|
+
- Semantic versioning; update `CHANGELOG.md` and `__version__`.
|
|
56
|
+
- Gates: `uv run pytest && uv run ruff check . && uv run mypy src && uv build && uv run --with twine twine check dist/*`.
|
|
57
|
+
- Tag `vX.Y.Z`, GitHub release. Do NOT publish to PyPI without explicit review.
|
|
58
|
+
|
|
59
|
+
## Style
|
|
60
|
+
|
|
61
|
+
- No em dash characters in docs, comments, or commit messages.
|
|
62
|
+
- Comments explain non-obvious reasoning only.
|
|
63
|
+
- Commit format: `type(scope): description`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our pledge
|
|
4
|
+
|
|
5
|
+
We pledge to make participation in this project a harassment-free experience
|
|
6
|
+
for everyone, regardless of age, body size, disability, ethnicity, gender
|
|
7
|
+
identity and expression, level of experience, nationality, personal appearance,
|
|
8
|
+
race, religion, or sexual identity and orientation.
|
|
9
|
+
|
|
10
|
+
## Our standards
|
|
11
|
+
|
|
12
|
+
Examples of behavior that contributes to a positive environment:
|
|
13
|
+
|
|
14
|
+
- Using welcoming and inclusive language.
|
|
15
|
+
- Being respectful of differing viewpoints and experiences.
|
|
16
|
+
- Gracefully accepting constructive criticism.
|
|
17
|
+
- Focusing on what is best for the community.
|
|
18
|
+
|
|
19
|
+
Examples of unacceptable behavior:
|
|
20
|
+
|
|
21
|
+
- Trolling, insulting comments, and personal or political attacks.
|
|
22
|
+
- Public or private harassment.
|
|
23
|
+
- Publishing others' private information without explicit permission.
|
|
24
|
+
- Other conduct that could reasonably be considered inappropriate in a
|
|
25
|
+
professional setting.
|
|
26
|
+
|
|
27
|
+
## Enforcement
|
|
28
|
+
|
|
29
|
+
Project maintainers are responsible for clarifying and enforcing standards of
|
|
30
|
+
acceptable behavior. Instances of abusive, harassing, or otherwise
|
|
31
|
+
unacceptable behavior may be reported by opening an issue or contacting the
|
|
32
|
+
maintainer directly.
|
|
33
|
+
|
|
34
|
+
This Code of Conduct is adapted from the
|
|
35
|
+
[Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Contributions are welcome. Please open an issue first to discuss significant
|
|
4
|
+
changes before submitting a pull request.
|
|
5
|
+
|
|
6
|
+
## Development setup
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
git clone https://github.com/amaar-mc/tomasulo.git
|
|
10
|
+
cd tomasulo
|
|
11
|
+
uv venv && uv pip install -e ".[dev]"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Gates (all must pass)
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
uv run pytest -q
|
|
18
|
+
uv run ruff check .
|
|
19
|
+
uv run mypy src
|
|
20
|
+
uv build
|
|
21
|
+
uv run --with twine twine check dist/*
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Code style
|
|
25
|
+
|
|
26
|
+
- Line length: 100.
|
|
27
|
+
- Type hints on every function signature and class attribute.
|
|
28
|
+
- Google-style docstrings.
|
|
29
|
+
- No default parameter values in public functions or constructors.
|
|
30
|
+
- No em dash characters in code, comments, or docs (use -- or commas).
|
|
31
|
+
- No TODOs left in committed code.
|
|
32
|
+
|
|
33
|
+
## Commit messages
|
|
34
|
+
|
|
35
|
+
Format: `type(scope): description`
|
|
36
|
+
|
|
37
|
+
Examples: `feat(simulator): add WAW hazard detection`, `fix(trace): correct
|
|
38
|
+
snapshot cycle numbering`.
|
|
39
|
+
|
|
40
|
+
## Testing
|
|
41
|
+
|
|
42
|
+
- Bug fixes must include a failing test first.
|
|
43
|
+
- Test behavior, not implementation internals.
|
|
44
|
+
- Keep test coverage above 90%.
|
tomasulo-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Amaar Chughtai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tomasulo-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tomasulo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 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.
|
|
5
|
+
Project-URL: Homepage, https://github.com/amaar-mc/tomasulo
|
|
6
|
+
Project-URL: Repository, https://github.com/amaar-mc/tomasulo
|
|
7
|
+
Project-URL: Issues, https://github.com/amaar-mc/tomasulo/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/amaar-mc/tomasulo/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Amaar Chughtai
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 Amaar Chughtai
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: common-data-bus,computer-architecture,cpu-simulator,education,instruction-scheduling,out-of-order,register-renaming,reservation-stations,simulation,tomasulo
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Intended Audience :: Education
|
|
35
|
+
Classifier: Intended Audience :: Science/Research
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Topic :: Education
|
|
43
|
+
Classifier: Topic :: Scientific/Engineering
|
|
44
|
+
Classifier: Typing :: Typed
|
|
45
|
+
Requires-Python: >=3.10
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: hatchling>=1.25; extra == 'dev'
|
|
48
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
50
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
|
|
53
|
+
# tomasulo
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
Zero runtime dependencies. Requires Python 3.10+.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
pip install tomasulo
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
uv pip install tomasulo
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from tomasulo import Instruction, TomasuloSim, render_trace
|
|
75
|
+
|
|
76
|
+
program = [
|
|
77
|
+
Instruction(op="LOAD", dest="F6", src1="R2", src2="R0"),
|
|
78
|
+
Instruction(op="LOAD", dest="F2", src1="R3", src2="R0"),
|
|
79
|
+
Instruction(op="MUL", dest="F0", src1="F2", src2="F4"),
|
|
80
|
+
Instruction(op="SUB", dest="F8", src1="F6", src2="F2"),
|
|
81
|
+
Instruction(op="DIV", dest="F10", src1="F0", src2="F6"),
|
|
82
|
+
Instruction(op="ADD", dest="F6", src1="F8", src2="F2"),
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
sim = TomasuloSim(
|
|
86
|
+
stations={"add": 3, "mult": 2, "load": 3},
|
|
87
|
+
latencies={"ADD": 2, "SUB": 2, "MUL": 10, "DIV": 40, "LOAD": 2},
|
|
88
|
+
)
|
|
89
|
+
trace = sim.run(program=program)
|
|
90
|
+
print(render_trace(trace=trace))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Output:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
# Op Dest Src1 Src2 Issue ExecComplete Write
|
|
97
|
+
---------------------------------------------------------------------
|
|
98
|
+
1 LOAD F6 R2 R0 1 3 4
|
|
99
|
+
2 LOAD F2 R3 R0 2 4 5
|
|
100
|
+
3 MUL F0 F2 F4 3 15 16
|
|
101
|
+
4 SUB F8 F6 F2 4 6 7
|
|
102
|
+
5 DIV F10 F0 F6 5 56 57
|
|
103
|
+
6 ADD F6 F8 F2 6 9 10
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## CLI
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
tomasulo examples/sample_program.txt
|
|
110
|
+
tomasulo examples/sample_program.txt --snapshots
|
|
111
|
+
tomasulo --help
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Program file format -- one instruction per line:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
# comments are ignored
|
|
118
|
+
LOAD F6 R2 R0
|
|
119
|
+
LOAD F2 R3 R0
|
|
120
|
+
MUL F0 F2 F4
|
|
121
|
+
SUB F8 F6 F2
|
|
122
|
+
DIV F10 F0 F6
|
|
123
|
+
ADD F6 F8 F2
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Public API
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
@dataclass
|
|
130
|
+
class Instruction:
|
|
131
|
+
op: str # "ADD", "SUB", "MUL", "DIV", "LOAD"
|
|
132
|
+
dest: str # destination register e.g. "F0"
|
|
133
|
+
src1: str # first source register; for LOAD: base address register
|
|
134
|
+
src2: str # second source register; for LOAD: unused, pass "R0" by convention
|
|
135
|
+
|
|
136
|
+
@dataclass
|
|
137
|
+
class InstructionResult:
|
|
138
|
+
instruction: Instruction
|
|
139
|
+
issue_cycle: int
|
|
140
|
+
exec_complete_cycle: int
|
|
141
|
+
write_cycle: int
|
|
142
|
+
|
|
143
|
+
@dataclass
|
|
144
|
+
class Trace:
|
|
145
|
+
results: list[InstructionResult]
|
|
146
|
+
snapshots: list[CycleSnapshot]
|
|
147
|
+
|
|
148
|
+
class TomasuloSim:
|
|
149
|
+
def __init__(self, stations: dict[str, int], latencies: dict[str, int]) -> None: ...
|
|
150
|
+
def run(self, program: list[Instruction]) -> Trace: ...
|
|
151
|
+
|
|
152
|
+
def render_trace(trace: Trace) -> str: ...
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Algorithm
|
|
156
|
+
|
|
157
|
+
Stage order each cycle: **WRITE, then EXECUTE, then ISSUE.**
|
|
158
|
+
|
|
159
|
+
Hazards handled:
|
|
160
|
+
|
|
161
|
+
- **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.
|
|
162
|
+
- **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.
|
|
163
|
+
- **Structural**: at most one result per cycle on the CDB. Ties broken by lowest station index (declaration order).
|
|
164
|
+
|
|
165
|
+
See `docs/architecture.md` for a full description.
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
uv venv && uv pip install -e ".[dev]"
|
|
171
|
+
uv run pytest -q
|
|
172
|
+
uv run ruff check .
|
|
173
|
+
uv run mypy src
|
|
174
|
+
uv build
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT. Copyright (c) 2026 Amaar Chughtai.
|
tomasulo-0.1.0/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# tomasulo
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
Zero runtime dependencies. Requires Python 3.10+.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install tomasulo
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or with [uv](https://github.com/astral-sh/uv):
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
uv pip install tomasulo
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from tomasulo import Instruction, TomasuloSim, render_trace
|
|
23
|
+
|
|
24
|
+
program = [
|
|
25
|
+
Instruction(op="LOAD", dest="F6", src1="R2", src2="R0"),
|
|
26
|
+
Instruction(op="LOAD", dest="F2", src1="R3", src2="R0"),
|
|
27
|
+
Instruction(op="MUL", dest="F0", src1="F2", src2="F4"),
|
|
28
|
+
Instruction(op="SUB", dest="F8", src1="F6", src2="F2"),
|
|
29
|
+
Instruction(op="DIV", dest="F10", src1="F0", src2="F6"),
|
|
30
|
+
Instruction(op="ADD", dest="F6", src1="F8", src2="F2"),
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
sim = TomasuloSim(
|
|
34
|
+
stations={"add": 3, "mult": 2, "load": 3},
|
|
35
|
+
latencies={"ADD": 2, "SUB": 2, "MUL": 10, "DIV": 40, "LOAD": 2},
|
|
36
|
+
)
|
|
37
|
+
trace = sim.run(program=program)
|
|
38
|
+
print(render_trace(trace=trace))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Output:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
# Op Dest Src1 Src2 Issue ExecComplete Write
|
|
45
|
+
---------------------------------------------------------------------
|
|
46
|
+
1 LOAD F6 R2 R0 1 3 4
|
|
47
|
+
2 LOAD F2 R3 R0 2 4 5
|
|
48
|
+
3 MUL F0 F2 F4 3 15 16
|
|
49
|
+
4 SUB F8 F6 F2 4 6 7
|
|
50
|
+
5 DIV F10 F0 F6 5 56 57
|
|
51
|
+
6 ADD F6 F8 F2 6 9 10
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## CLI
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
tomasulo examples/sample_program.txt
|
|
58
|
+
tomasulo examples/sample_program.txt --snapshots
|
|
59
|
+
tomasulo --help
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Program file format -- one instruction per line:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
# comments are ignored
|
|
66
|
+
LOAD F6 R2 R0
|
|
67
|
+
LOAD F2 R3 R0
|
|
68
|
+
MUL F0 F2 F4
|
|
69
|
+
SUB F8 F6 F2
|
|
70
|
+
DIV F10 F0 F6
|
|
71
|
+
ADD F6 F8 F2
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Public API
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
@dataclass
|
|
78
|
+
class Instruction:
|
|
79
|
+
op: str # "ADD", "SUB", "MUL", "DIV", "LOAD"
|
|
80
|
+
dest: str # destination register e.g. "F0"
|
|
81
|
+
src1: str # first source register; for LOAD: base address register
|
|
82
|
+
src2: str # second source register; for LOAD: unused, pass "R0" by convention
|
|
83
|
+
|
|
84
|
+
@dataclass
|
|
85
|
+
class InstructionResult:
|
|
86
|
+
instruction: Instruction
|
|
87
|
+
issue_cycle: int
|
|
88
|
+
exec_complete_cycle: int
|
|
89
|
+
write_cycle: int
|
|
90
|
+
|
|
91
|
+
@dataclass
|
|
92
|
+
class Trace:
|
|
93
|
+
results: list[InstructionResult]
|
|
94
|
+
snapshots: list[CycleSnapshot]
|
|
95
|
+
|
|
96
|
+
class TomasuloSim:
|
|
97
|
+
def __init__(self, stations: dict[str, int], latencies: dict[str, int]) -> None: ...
|
|
98
|
+
def run(self, program: list[Instruction]) -> Trace: ...
|
|
99
|
+
|
|
100
|
+
def render_trace(trace: Trace) -> str: ...
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Algorithm
|
|
104
|
+
|
|
105
|
+
Stage order each cycle: **WRITE, then EXECUTE, then ISSUE.**
|
|
106
|
+
|
|
107
|
+
Hazards handled:
|
|
108
|
+
|
|
109
|
+
- **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.
|
|
110
|
+
- **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.
|
|
111
|
+
- **Structural**: at most one result per cycle on the CDB. Ties broken by lowest station index (declaration order).
|
|
112
|
+
|
|
113
|
+
See `docs/architecture.md` for a full description.
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
uv venv && uv pip install -e ".[dev]"
|
|
119
|
+
uv run pytest -q
|
|
120
|
+
uv run ruff check .
|
|
121
|
+
uv run mypy src
|
|
122
|
+
uv build
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT. Copyright (c) 2026 Amaar Chughtai.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Only the latest release receives security fixes.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
|---------|-----------|
|
|
9
|
+
| 0.1.x | Yes |
|
|
10
|
+
|
|
11
|
+
## Reporting a vulnerability
|
|
12
|
+
|
|
13
|
+
Please do not report security vulnerabilities through public GitHub issues.
|
|
14
|
+
|
|
15
|
+
Instead, open a [GitHub Security Advisory](https://github.com/amaar-mc/tomasulo/security/advisories/new)
|
|
16
|
+
or email the maintainer directly. You should receive a response within 72 hours.
|
|
17
|
+
|
|
18
|
+
Include as much of the following as possible:
|
|
19
|
+
|
|
20
|
+
- Type of issue (e.g. arbitrary code execution, path traversal).
|
|
21
|
+
- Affected source files with line numbers.
|
|
22
|
+
- Steps to reproduce.
|
|
23
|
+
- Proof-of-concept or exploit code (if available).
|
|
24
|
+
- Impact assessment.
|
|
25
|
+
|
|
26
|
+
## Notes
|
|
27
|
+
|
|
28
|
+
`tomasulo` is a pure simulation library with no network I/O, no file writes
|
|
29
|
+
outside of explicit CLI invocations, and no execution of user-provided code.
|
|
30
|
+
The primary attack surface is the instruction text parser in `cli.py`.
|
|
File without changes
|