S4 · Lesson 49 · Architecture lab
Renaming, dataflow timing and a limited common data bus, checked against reference simulators
Lesson 9 traced Tomasulo's algorithm by hand. Architects explore designs like it with timing simulators: programs that take an instruction trace and a machine description and compute when every instruction issues, executes and writes its result. In this lab you'll write one in three steps: first the renaming that finds each instruction's true producers, then the pure dataflow timing that renaming makes possible, then the effect of a single common data bus that can broadcast only one result per cycle. The tests compare your simulator with independently written reference simulators on random programs.
Predict
In the example program below, instruction 3 writes f0 again while instruction 1 still needs the old f0. With renaming, when can instruction 3 start executing?
As soon as it has issued. Instruction 3 is a load with no source registers; its only conflicts with earlier instructions are on the name f0 (a WAW with instruction 0 and a WAR with instruction 1). Renaming gives its result a new tag, so it starts in cycle 4, right after issuing in cycle 3, and writes in cycle 6, while instruction 1, issued earlier, is still waiting for its multiply to finish.
Name it
The program format
A program is a list of (op, dest, sources):
EX = [('ld', 'f0', []), # 0
('mul', 'f4', ['f0', 'f2']), # 1
('add', 'f6', ['f4', 'f8']), # 2
('ld', 'f0', []), # 3
('add', 'f2', ['f0', 'f0'])] # 4
LAT = {'add': 1, 'mul': 4, 'ld': 2, 'div': 10}
Registers never written in the program (f2 and f8 at first) are ready from the start.
The timing rules
- Producers: for each source, the latest earlier instruction whose destination is that register. Later writes to the same name don't matter (renaming).
- Issue: in order,
widthper cycle: instruction i issues in cyclei // width, into an unlimited supply of reservation stations. - Execute: an instruction starts in the first cycle that's after its issue cycle and after every producer's write cycle, and runs
lat[op]cycles; its result is ready to writelat[op]cycles after it starts. - Write: with an unlimited bus, at once. With
busesbuses, each cycle the oldest ready results are written, at mostbusesof them; the rest wait. A result written in cycle w can be used from cycle w + 1.
What you'll write
deps(prog): for each instruction, the sorted list of producer indices.schedule(prog, lat, width=1): each instruction's write cycle with an unlimited bus.schedule_cdb(prog, lat, width=1, buses=1): write cycles with a limited bus. Simulate cycle by cycle: start every instruction that can start, then write the oldest ready results.
Worked example
Work out the example's write cycles with one issue per cycle and an unlimited bus.
Show the solution
- Issue. With one issue per cycle, instructions 0 to 4 issue in cycles 0 to 4.
- Instruction 0 (load). It starts in cycle 1 and writes in 3.
- Instruction 1. It waits for 0: starts in 4, writes in 8.
- Instruction 2. It waits for 1: starts in 9, writes in 10.
- Instruction 3. It has no producers: starts in 4, writes in 6.
- Instruction 4. It waits for 3: starts in 7, writes in 8.
- Two issues per cycle. Instructions 3 and 4 issue two cycles earlier, in cycles 1 and 2, and write in 4 and 6.
Answer the write cycles are [3, 8, 10, 6, 8]; with two issues per cycle they become [3, 8, 10, 4, 6].
Worked example
With a single common data bus, what changes?
Show the solution
- The clash. In cycle 8, instructions 1 and 4 both have results ready.
- Oldest first. The older one, 1, takes the bus, and 4 writes in cycle 9.
- Instruction 2. It needed only instruction 1, so it's unaffected.
- In larger programs. In larger random programs, the single bus changed the timing of 39 out of 40 four-wide runs, which is why wide machines have several result buses.
Answer instruction 4 now writes in cycle 9 instead of 8, so the write cycles are [3, 8, 10, 6, 9].
Check
Step 1. Write deps(prog): each instruction's true producers.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write schedule(prog, lat, width): write cycles with an unlimited result bus.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write schedule_cdb(prog, lat, width, buses): write cycles with a limited common data bus.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a timing simulator need a model of the result bus, when the functional units are what do the work?
Every result has to be broadcast before any instruction that needs it can start, so the bus is on the path from every producer to every consumer. With unlimited buses, an instruction's timing depends only on its issue slot and on when its producers finish. With a single bus, results that finish in the same cycle must take turns, and each delayed result delays its consumers, which can delay their consumers in turn. A simulator that ignores the bus would predict a schedule the hardware can't achieve and overstate the benefit of a wide machine. Modeling the shared resources, buses, ports and stations, is what makes a timing simulator's numbers trustworthy.
Practice
Keep practicing
3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.