S449 of 55
0 XP
  1. Hook
  2. Predict
  3. Name it
  4. Check
  5. Explain

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?

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, width per cycle: instruction i issues in cycle i // 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 write lat[op] cycles after it starts.
  • Write: with an unlimited bus, at once. With buses buses, each cycle the oldest ready results are written, at most buses of them; the rest wait. A result written in cycle w can be used from cycle w + 1.

What you'll write

  1. deps(prog): for each instruction, the sorted list of producer indices.
  2. schedule(prog, lat, width=1): each instruction's write cycle with an unlimited bus.
  3. 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
  1. Issue. With one issue per cycle, instructions 0 to 4 issue in cycles 0 to 4.
  2. Instruction 0 (load). It starts in cycle 1 and writes in 3.
  3. Instruction 1. It waits for 0: starts in 4, writes in 8.
  4. Instruction 2. It waits for 1: starts in 9, writes in 10.
  5. Instruction 3. It has no producers: starts in 4, writes in 6.
  6. Instruction 4. It waits for 3: starts in 7, writes in 8.
  7. 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
  1. The clash. In cycle 8, instructions 1 and 4 both have results ready.
  2. Oldest first. The older one, 1, takes the bus, and 4 writes in cycle 9.
  3. Instruction 2. It needed only instruction 1, so it's unaffected.
  4. 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?

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.