[CS61C FA20] Lecture 20.4 - Single-Cycle CPU Control: Control Logic Design — Transcript
Full transcript
- 0:08Hello and welcome back to our RISC-V CPU
- 0:11design module.
- 0:13In the past few segments, we walked
- 0:15through the execution of several
- 0:17instructions. And at moments, it might
- 0:20have felt repetitive and perhaps boring.
- 0:23But we wanted to accomplish two purposes
- 0:26by doing that.
- 0:28The first one was to get a good sense of
- 0:31how long does it take us to execute an
- 0:34instruction.
- 0:36And we actually ended up measuring that.
- 0:38That'll help us in the next module.
- 0:42But the second purpose was to get a
- 0:43really good
- 0:45handle on what is the control logic
- 0:47supposed to do.
- 0:49That's going to make this segment
- 0:52much easier to understand and make it
- 0:55look fairly straightforward.
- 0:59So, let's get into that.
- 1:01First, let's recap what do we expect
- 1:03control logic to do? Control logic can
- 1:05be viewed essentially as
- 1:07a lookup table. This is a lookup table
- 1:10with a bunch of
- 1:12rows and columns.
- 1:15Rows are the inputs, which would be the
- 1:18instructions that we would like to
- 1:19execute.
- 1:21The columns would be the control bits.
- 1:24So, each
- 1:26row input is an instruction that we are
- 1:29running along with the two more inputs.
- 1:32These are the branch compare comparison
- 1:35outcomes, whether the operands are equal
- 1:37or less than. Remember, those are the
- 1:38two arrows that were also pointing down
- 1:40into the control logic as the inputs. We
- 1:42need those to figure out how to select
- 1:45some of the control signals.
- 1:47And then each row has a particular set
- 1:50of control signals that are set
- 1:53that it needs to correctly execute.
- 1:55So, um our well
- 1:58familiar
- 2:00the instructions that are well familiar
- 2:01with is our ad.
- 2:03The ad has its control word
- 2:07encoded in the first row.
- 2:09So, we can view this as a word. It has a
- 2:13number of bits,
- 2:15about 15 of them.
- 2:19So, it simply says what is the control
- 2:21what are the control bits supposed to
- 2:23be. So, we know that PC cell is supposed
- 2:26to be pointing to the input that will
- 2:28take the next instruction plus four.
- 2:30Immediate select is don't care whether
- 2:31it says zero or one. Or
- 2:34actually this is a a three-bit value for
- 2:36the immediate select. So, they can be
- 2:38anything 000001
- 2:41010 and so on and it doesn't matter to
- 2:44us.
- 2:46Um
- 2:47also branch sign this does not matter
- 2:50either because we are not
- 2:52executing a branch. But, A cell and B
- 2:56cell signals do matter and they should
- 2:59be taking the inputs from the registers.
- 3:02ALU is a four-bit control signal
- 3:06because ALU can do quite a bit of stuff.
- 3:09In this case, we're going to encode it
- 3:12to do the addition.
- 3:13We're going to set
- 3:15its control bits to do the addition.
- 3:18And then
- 3:19memory read write is going to be set to
- 3:21read. Register write enable is going to
- 3:23be one. And finally, write back select
- 3:25is a two-bit control signal that will be
- 3:28set to write back from the ALU.
- 3:33So, how do we implement this control
- 3:35logic this essentially truth table?
- 3:37There are two options to do that. One of
- 3:39them is to use a read-only memory.
- 3:42The other option is to use the control
- 3:44combinational logic a bunch of ANDs and
- 3:46ORs.
- 3:48Read-only memory is
- 3:51like a standard memory that we have seen
- 3:52before
- 3:54except that we don't write into it.
- 3:57We just read from it. So, that's why
- 3:58it's called read-only.
- 4:01We actually write to it at a design time
- 4:04when we are designing this control
- 4:06logic. We populated it with ones and
- 4:08zeros, whatever we whatever we would
- 4:10like to see in particular control words.
- 4:14So, it's relatively easy to do that. And
- 4:17then, we will just read it by pointing
- 4:20to a particular control word that we
- 4:23would like to get out of this
- 4:25read-only memory.
- 4:28Um, so a designer can keep reprogramming
- 4:31it while designing it. And then, we can
- 4:34test it out by executing a whole bunch
- 4:36of instructions. It's really really
- 4:38easy. It's popular
- 4:40during prototyping.
- 4:42It is also popular popular when we are
- 4:44trying to perhaps add an extension. So,
- 4:47for example, you would like to add
- 4:49a compressed
- 4:51part of the instruction set, RISC-V
- 4:53instruction set. We have heard about
- 4:55compressed instructions before. So, we
- 4:56would just add that part of the table to
- 4:59our ROM and then try it out.
- 5:02In practice, when we design
- 5:05real chips,
- 5:07control will be designed as a bunch of
- 5:09ANDs and ORs because that's more compact
- 5:12and it is faster.
- 5:16But let's actually see what do we need
- 5:18in order to implement control logic.
- 5:21What kind of inputs do we need? Well, we
- 5:23need to to have a unique representation
- 5:25for every single one of these
- 5:27instructions and we need those two bits
- 5:30for the branch outcomes.
- 5:33Instructions are 32-bits wide, but the
- 5:36relevant information is stored in only
- 5:38nine bits. So, somebody can say that
- 5:40RISC-V I arbitrary to I is just a
- 5:44nine-bit ISA.
- 5:47Um, where are the relevant bits?
- 5:49The relevant bits are the upper five
- 5:52bits of the op code,
- 5:54the entire function three field, and
- 5:57that one bit from for from the function
- 6:01seven field, the 30th bit of the
- 6:03instruction. That is used for encoding
- 6:06some of the add subs and shifts.
- 6:11So, there is just a total of nine of
- 6:13them.
- 6:145 + 3 + 1. If we are going to add some
- 6:18instructions like a compressed
- 6:19instruction, we would need to take a
- 6:21look also at the
- 6:22last two bits or the least significant
- 6:24two bits.
- 6:26Uh, which one which are set to be one
- 6:29and one for RV32I.
- 6:34But, for now, since we're only dealing
- 6:37with RV32I instructions, in order to
- 6:40decode them, we just need those nine
- 6:44bits from the instruction and two
- 6:46additional bits,
- 6:48um, which are the branch outcomes. So,
- 6:50we would point
- 6:52to the ROM with an address that is 18
- 6:55bits wide and we are going to read out
- 6:58of that ROM a 15-bit control word. This
- 7:02control word word will contain one bit
- 7:05for a PC select, three bits for the
- 7:07immediate select, um, a bit for sign of
- 7:10a branch, a bit for A select and B
- 7:13select each. Um, ALU select will be a
- 7:17four-bit control signal.
- 7:19Uh, memory read write is a single
- 7:21control bit.
- 7:23Uh, register write enable is also a
- 7:25single control bit and finally write
- 7:27back select is a two-bit output.
- 7:31How does the ROM actually work inside?
- 7:34Um, it's it looks like a lookup table
- 7:38table literally. Um,
- 7:39we are going to address this lookup
- 7:42table with the same stuff that we have
- 7:45had in the additional original initial
- 7:48lookup table. Um, we are going to have
- 7:51instructions
- 7:53represented by the their nine-bit values
- 7:56plus two, um, bits that represent the
- 7:59branch um, outcomes. And then,
- 8:03um,
- 8:04in each row here will be a corresponding
- 8:07control word for those
- 8:10instructions.
- 8:11First, what we do, we decode
- 8:15the address.
- 8:17Um these
- 8:19inputs the the the
- 8:22the the the instruction types are binary
- 8:26encoded. Um the output of the address
- 8:29decoder is so-called one hot. Only one
- 8:32of these lines is going to light up. We
- 8:36are going to address only one control
- 8:38word, because that's what makes sense.
- 8:40We don't want to have two control two
- 8:42different control words. That would
- 8:43confuse the data path. We only produce
- 8:46one control word um for each instruction
- 8:50or in instruction branch combination.
- 8:53So, for example, our
- 8:55add would point to the first line in
- 8:58this read-only memory
- 9:00um and um
- 9:02um
- 9:04if we are executing an add,
- 9:06this is the only wire that is going to
- 9:08light up. That is this is the only wire
- 9:10that is going to be true. All the other
- 9:12ones are going to be zeros.
- 9:14So, the output of this
- 9:17controller, we are going to get a
- 9:20control word
- 9:22that only corresponds to an add.
- 9:26All the others ones are zeros.
- 9:31In a way, you can view this
- 9:35as an AND or structure. In order to only
- 9:39have one of these lines enabled, this
- 9:43address decoder has to be a fairly wide
- 9:46AND. And then, in order to form the
- 9:49output controller word,
- 9:51it can be just an OR. That's the
- 9:53simplest way to implement it. So, this
- 9:54is an AND or structure.
- 9:58In general,
- 9:59there is a lot of redundancy here. We
- 10:02You know, many of these um entries are
- 10:04going to be zeros. So, that's the idea
- 10:07of trying to simplify the the entire
- 10:09control logic into a smaller numbers
- 10:13number of ends and ors.
- 10:15So, in this case, let's take an example
- 10:18and what is perhaps the simplest
- 10:20encoding example that we have in our
- 10:23instruction set and that would be
- 10:25whether the branch is assigned or not.
- 10:29So, let's take a look at what encodes
- 10:32that we are dealing with a branch. These
- 10:34are the instruction bits 6 to 2. These
- 10:36five instruction bits are telling us
- 10:38that it's a branch if the values are 111
- 10:42and 11000.
- 10:46And then we need to find out in
- 10:50the func three field function three
- 10:52field what kind of a branch it is.
- 10:55So,
- 10:59when looking at these, the bottom two,
- 11:01the last two are the unsigned
- 11:04branches, BLTU and BGEU.
- 11:07What is common for them?
- 11:09The and different for the other
- 11:12instructions. Well, you can take a look
- 11:14at this middle bit, instruction three
- 11:16bit. It is true only for those two. So,
- 11:20that sets the signness of a branch.
- 11:23In order to decode this branch, we just
- 11:25need to look at that
- 11:28middle bit, instruction three bit, and
- 11:30it tells us whether the branch is signed
- 11:32or not.
- 11:34So, that control signal is essentially
- 11:36equal to instruction 13
- 11:38and the branch because, you know, this
- 11:40bit will be true for other types of
- 11:42instructions. In order to
- 11:45um
- 11:48decode the branch, right? I mean, the
- 11:49branch is encoded um with the
- 11:56lower bits.
- 12:00So, it is
- 12:02I
- 12:04six
- 12:07and
- 12:09I five
- 12:12and not
- 12:15I4
- 12:16and not
- 12:19I3
- 12:21and not
- 12:23I2.
- 12:25That is our branch.
- 12:31That tells us that decodes all the
- 12:33branch instructions. And then to just
- 12:37select that we are looking for an
- 12:39unsigned branch, we add that with the
- 12:42instruction bit 13. Fairly simple, isn't
- 12:45it?
- 12:46This is a wide
- 12:48um
- 12:50uh six-bit wide
- 12:52AND gate.
- 12:55Keep in mind that sometimes six-bit wide
- 12:57AND gates may not be the most practical
- 12:59thing to implement. So, we'll try to
- 13:00break this down typically into a couple
- 13:03of gates.
- 13:06That's what our Boolean man-
- 13:07manipulation is for, isn't it?
- 13:11Let's design the decode logic for add.
- 13:15So, add is just one line in this um
- 13:20uh in this truth table that has our nine
- 13:24bits. You know, here is our add.
- 13:28So, what we would do to
- 13:30decode that we are executing an add,
- 13:33well, we would just write down the
- 13:34expression that it is equal to
- 13:37um
- 13:38I30
- 13:40instruction bit being
- 13:42false, I14 is false, I13 is false, I12
- 13:47is false. All of them are zeros. And
- 13:49then we need to AND this with an R-type
- 13:51instruction.
- 13:53R-type is encoded as
- 13:58n-
- 14:00I6 being false, I5 being true, I4 being
- 14:04true,
- 14:05I3 being false, I2 being
- 14:10false. And that's it. Um we can If we If
- 14:13we other extensions, we would have to
- 14:16end this with 11 in the last bit
- 14:19positions, but we don't have to
- 14:22for the purpose of our project because
- 14:24we don't have any other instructions.
- 14:27And that's it. We have just
- 14:29finished all what we need to know about
- 14:31instruction decoding. And we have done
- 14:33more than that. We actually
- 14:36built a complete RISC-V processor.
- 14:39We should celebrate that, which we'll do
- 14:41after a bit of a break.
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 20.4 - Single-Cycle CPU Control: Control Logic Design by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,960 words across 338 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.