Lecture 11 - Datapath
Goals
- Learn the purpose of the register file
- Learn the purpose of the ALU
- Learn how the register file and the ALU interact
- Learn the purpose of the clock
Imagining code
We are going to take a little look ahead at where we are going -- we want to build a computer that we can program. So it needs to be able to support the kinds of things that we write in our programs
Let’s look at a stupid-simple "program" and see if we can draw parallels to circuitry we’ve seen
here’s the program:
x = y + z
I can identify three "things" going on here
- we have variables whose values we are reading
- we have another variable whose value we are writing
- we have addition
do we have circuitry that can remember values such that we can later read them? yep: registers and can we change the values stored in these registers? yep can we do addition? yep
so what we need is at least three registers (one for each of x, y, and z)
we need an adder
we need to connect the output of two of the registers to the inputs of the adder
and the output of the adder to the input of the third register
then when we toggle the clock input on the register, the sum of y and z will be stored in the register we’ve designated to hold x
this is kind of awesome: we now have circuitry that performs computation that clearly resembles the exact kind of code you yourself have written
but let’s not stop
here’s the next line of code:
y = z + x
this introduces complications
we’re not going to be able to hard-wire the y register to the input of the adder
we have to be able to choose which registers get sent as inputs to the adder
likewise, we have to be able to choose with register gets the result of the adder
this is a job for muxes (one to select which register’s value is sent to the first input of the adder and a second to select which register’s value is sent to the second input of the adder)
and a decoder, to select which of the registers should be written (review the 4-by-3-memory circuit from lecture 08 to see how we did this)
next wrinkle is minor:
z = x + x
both operands might come from the same register!
fairly easy to implement in circuitry, though
in fact, the muxes we proposed previously magically take care of it
what about this one:
z = z + x
this works because we can let the z and x flow through the circuit such that the sum is ready on the wire leading to the z register, and then tick the clock
because the register stores a new value only on the rising edge, it grabs the result right then, before the new value of z can flow through the circuit
thus this line doesn’t present a problem either
this one is trickier:
y = z ^ x
how do we (efficiently) support operations other than addition? bit-wise XOR in this case, not
good news: we can (and should) reuse the circuitry that allows us to choose operands
but now that we have a second operation, we need some way to choose among outputs (ie, whether y reads its value from the adder or the xor, or any other function the computer supports)
we need to make a choice about which output to pass on to the register that will store the result? Sounds like... a mux!
The Clock
We introduced the clock a couple of lectures back, but it is time to talk about it a little bit more
As we discussed, the clock is a a simple oscillator that is cycling back and forth with regularity and at a fixed speed
there is some magic physics and material science involved here and a crystalline structure that oscillates in predictable ways when voltage is applied to it
I've waved my hands a little bit about why we need such a thing, but now that we are starting to have some basic computer circuitry we can gain a little more insight
Think about this sequence of instructions
x = x + y
z = w + x
we have already discussed why an edge-triggered circuit is essential for storing the right value of x
in the first line
Let's talk about the second line, or rather the time in between the two lines
As I've said a few times, it takes time for signal to pass through wires and gates.
As soon as the clock edge goes high, storing the new value of x
, the race is on
we need to get the new value of x
(as well as y
) propagated out of the register file, over to the ALU, through the adder and then back to the register file in time for the next rising edge of the clock. If the new value doesn't make it in time, z
will have the wrong value and the entire world will be topsy turvy (or our computer program won't run properly at least)
Setting the clock speed is thus fairly important
- should be slow enough to provide plenty of time for the slowest signal to make it through the circuit
- but the faster the clock, the faster instructions can be carried out
The clocks in modern processors run three to four billion times a second (this is why. a processor might be described as a 4 GHz machine -- it describes the clock speed)
To achieve these speeds, there has been constant pressure to make components smaller and smaller and pack them in tighter and tighter, which allows signal to propagate faster
Mechanical level
vocabulary
Skills
Last updated 04/05/2023