YouTube2Text

[CS61C FA20] Lecture 20.4 - Single-Cycle CPU Control: Control Logic Design — Transcript

by CS 61C Departmental · 1,960 words · 338 segments · language en · Watch on YouTube

Full transcript

  1. 0:08Hello and welcome back to our RISC-V CPU
  2. 0:11design module.
  3. 0:13In the past few segments, we walked
  4. 0:15through the execution of several
  5. 0:17instructions. And at moments, it might
  6. 0:20have felt repetitive and perhaps boring.
  7. 0:23But we wanted to accomplish two purposes
  8. 0:26by doing that.
  9. 0:28The first one was to get a good sense of
  10. 0:31how long does it take us to execute an
  11. 0:34instruction.
  12. 0:36And we actually ended up measuring that.
  13. 0:38That'll help us in the next module.
  14. 0:42But the second purpose was to get a
  15. 0:43really good
  16. 0:45handle on what is the control logic
  17. 0:47supposed to do.
  18. 0:49That's going to make this segment
  19. 0:52much easier to understand and make it
  20. 0:55look fairly straightforward.
  21. 0:59So, let's get into that.
  22. 1:01First, let's recap what do we expect
  23. 1:03control logic to do? Control logic can
  24. 1:05be viewed essentially as
  25. 1:07a lookup table. This is a lookup table
  26. 1:10with a bunch of
  27. 1:12rows and columns.
  28. 1:15Rows are the inputs, which would be the
  29. 1:18instructions that we would like to
  30. 1:19execute.
  31. 1:21The columns would be the control bits.
  32. 1:24So, each
  33. 1:26row input is an instruction that we are
  34. 1:29running along with the two more inputs.
  35. 1:32These are the branch compare comparison
  36. 1:35outcomes, whether the operands are equal
  37. 1:37or less than. Remember, those are the
  38. 1:38two arrows that were also pointing down
  39. 1:40into the control logic as the inputs. We
  40. 1:42need those to figure out how to select
  41. 1:45some of the control signals.
  42. 1:47And then each row has a particular set
  43. 1:50of control signals that are set
  44. 1:53that it needs to correctly execute.
  45. 1:55So, um our well
  46. 1:58familiar
  47. 2:00the instructions that are well familiar
  48. 2:01with is our ad.
  49. 2:03The ad has its control word
  50. 2:07encoded in the first row.
  51. 2:09So, we can view this as a word. It has a
  52. 2:13number of bits,
  53. 2:15about 15 of them.
  54. 2:19So, it simply says what is the control
  55. 2:21what are the control bits supposed to
  56. 2:23be. So, we know that PC cell is supposed
  57. 2:26to be pointing to the input that will
  58. 2:28take the next instruction plus four.
  59. 2:30Immediate select is don't care whether
  60. 2:31it says zero or one. Or
  61. 2:34actually this is a a three-bit value for
  62. 2:36the immediate select. So, they can be
  63. 2:38anything 000001
  64. 2:41010 and so on and it doesn't matter to
  65. 2:44us.
  66. 2:46Um
  67. 2:47also branch sign this does not matter
  68. 2:50either because we are not
  69. 2:52executing a branch. But, A cell and B
  70. 2:56cell signals do matter and they should
  71. 2:59be taking the inputs from the registers.
  72. 3:02ALU is a four-bit control signal
  73. 3:06because ALU can do quite a bit of stuff.
  74. 3:09In this case, we're going to encode it
  75. 3:12to do the addition.
  76. 3:13We're going to set
  77. 3:15its control bits to do the addition.
  78. 3:18And then
  79. 3:19memory read write is going to be set to
  80. 3:21read. Register write enable is going to
  81. 3:23be one. And finally, write back select
  82. 3:25is a two-bit control signal that will be
  83. 3:28set to write back from the ALU.
  84. 3:33So, how do we implement this control
  85. 3:35logic this essentially truth table?
  86. 3:37There are two options to do that. One of
  87. 3:39them is to use a read-only memory.
  88. 3:42The other option is to use the control
  89. 3:44combinational logic a bunch of ANDs and
  90. 3:46ORs.
  91. 3:48Read-only memory is
  92. 3:51like a standard memory that we have seen
  93. 3:52before
  94. 3:54except that we don't write into it.
  95. 3:57We just read from it. So, that's why
  96. 3:58it's called read-only.
  97. 4:01We actually write to it at a design time
  98. 4:04when we are designing this control
  99. 4:06logic. We populated it with ones and
  100. 4:08zeros, whatever we whatever we would
  101. 4:10like to see in particular control words.
  102. 4:14So, it's relatively easy to do that. And
  103. 4:17then, we will just read it by pointing
  104. 4:20to a particular control word that we
  105. 4:23would like to get out of this
  106. 4:25read-only memory.
  107. 4:28Um, so a designer can keep reprogramming
  108. 4:31it while designing it. And then, we can
  109. 4:34test it out by executing a whole bunch
  110. 4:36of instructions. It's really really
  111. 4:38easy. It's popular
  112. 4:40during prototyping.
  113. 4:42It is also popular popular when we are
  114. 4:44trying to perhaps add an extension. So,
  115. 4:47for example, you would like to add
  116. 4:49a compressed
  117. 4:51part of the instruction set, RISC-V
  118. 4:53instruction set. We have heard about
  119. 4:55compressed instructions before. So, we
  120. 4:56would just add that part of the table to
  121. 4:59our ROM and then try it out.
  122. 5:02In practice, when we design
  123. 5:05real chips,
  124. 5:07control will be designed as a bunch of
  125. 5:09ANDs and ORs because that's more compact
  126. 5:12and it is faster.
  127. 5:16But let's actually see what do we need
  128. 5:18in order to implement control logic.
  129. 5:21What kind of inputs do we need? Well, we
  130. 5:23need to to have a unique representation
  131. 5:25for every single one of these
  132. 5:27instructions and we need those two bits
  133. 5:30for the branch outcomes.
  134. 5:33Instructions are 32-bits wide, but the
  135. 5:36relevant information is stored in only
  136. 5:38nine bits. So, somebody can say that
  137. 5:40RISC-V I arbitrary to I is just a
  138. 5:44nine-bit ISA.
  139. 5:47Um, where are the relevant bits?
  140. 5:49The relevant bits are the upper five
  141. 5:52bits of the op code,
  142. 5:54the entire function three field, and
  143. 5:57that one bit from for from the function
  144. 6:01seven field, the 30th bit of the
  145. 6:03instruction. That is used for encoding
  146. 6:06some of the add subs and shifts.
  147. 6:11So, there is just a total of nine of
  148. 6:13them.
  149. 6:145 + 3 + 1. If we are going to add some
  150. 6:18instructions like a compressed
  151. 6:19instruction, we would need to take a
  152. 6:21look also at the
  153. 6:22last two bits or the least significant
  154. 6:24two bits.
  155. 6:26Uh, which one which are set to be one
  156. 6:29and one for RV32I.
  157. 6:34But, for now, since we're only dealing
  158. 6:37with RV32I instructions, in order to
  159. 6:40decode them, we just need those nine
  160. 6:44bits from the instruction and two
  161. 6:46additional bits,
  162. 6:48um, which are the branch outcomes. So,
  163. 6:50we would point
  164. 6:52to the ROM with an address that is 18
  165. 6:55bits wide and we are going to read out
  166. 6:58of that ROM a 15-bit control word. This
  167. 7:02control word word will contain one bit
  168. 7:05for a PC select, three bits for the
  169. 7:07immediate select, um, a bit for sign of
  170. 7:10a branch, a bit for A select and B
  171. 7:13select each. Um, ALU select will be a
  172. 7:17four-bit control signal.
  173. 7:19Uh, memory read write is a single
  174. 7:21control bit.
  175. 7:23Uh, register write enable is also a
  176. 7:25single control bit and finally write
  177. 7:27back select is a two-bit output.
  178. 7:31How does the ROM actually work inside?
  179. 7:34Um, it's it looks like a lookup table
  180. 7:38table literally. Um,
  181. 7:39we are going to address this lookup
  182. 7:42table with the same stuff that we have
  183. 7:45had in the additional original initial
  184. 7:48lookup table. Um, we are going to have
  185. 7:51instructions
  186. 7:53represented by the their nine-bit values
  187. 7:56plus two, um, bits that represent the
  188. 7:59branch um, outcomes. And then,
  189. 8:03um,
  190. 8:04in each row here will be a corresponding
  191. 8:07control word for those
  192. 8:10instructions.
  193. 8:11First, what we do, we decode
  194. 8:15the address.
  195. 8:17Um these
  196. 8:19inputs the the the
  197. 8:22the the the instruction types are binary
  198. 8:26encoded. Um the output of the address
  199. 8:29decoder is so-called one hot. Only one
  200. 8:32of these lines is going to light up. We
  201. 8:36are going to address only one control
  202. 8:38word, because that's what makes sense.
  203. 8:40We don't want to have two control two
  204. 8:42different control words. That would
  205. 8:43confuse the data path. We only produce
  206. 8:46one control word um for each instruction
  207. 8:50or in instruction branch combination.
  208. 8:53So, for example, our
  209. 8:55add would point to the first line in
  210. 8:58this read-only memory
  211. 9:00um and um
  212. 9:02um
  213. 9:04if we are executing an add,
  214. 9:06this is the only wire that is going to
  215. 9:08light up. That is this is the only wire
  216. 9:10that is going to be true. All the other
  217. 9:12ones are going to be zeros.
  218. 9:14So, the output of this
  219. 9:17controller, we are going to get a
  220. 9:20control word
  221. 9:22that only corresponds to an add.
  222. 9:26All the others ones are zeros.
  223. 9:31In a way, you can view this
  224. 9:35as an AND or structure. In order to only
  225. 9:39have one of these lines enabled, this
  226. 9:43address decoder has to be a fairly wide
  227. 9:46AND. And then, in order to form the
  228. 9:49output controller word,
  229. 9:51it can be just an OR. That's the
  230. 9:53simplest way to implement it. So, this
  231. 9:54is an AND or structure.
  232. 9:58In general,
  233. 9:59there is a lot of redundancy here. We
  234. 10:02You know, many of these um entries are
  235. 10:04going to be zeros. So, that's the idea
  236. 10:07of trying to simplify the the entire
  237. 10:09control logic into a smaller numbers
  238. 10:13number of ends and ors.
  239. 10:15So, in this case, let's take an example
  240. 10:18and what is perhaps the simplest
  241. 10:20encoding example that we have in our
  242. 10:23instruction set and that would be
  243. 10:25whether the branch is assigned or not.
  244. 10:29So, let's take a look at what encodes
  245. 10:32that we are dealing with a branch. These
  246. 10:34are the instruction bits 6 to 2. These
  247. 10:36five instruction bits are telling us
  248. 10:38that it's a branch if the values are 111
  249. 10:42and 11000.
  250. 10:46And then we need to find out in
  251. 10:50the func three field function three
  252. 10:52field what kind of a branch it is.
  253. 10:55So,
  254. 10:59when looking at these, the bottom two,
  255. 11:01the last two are the unsigned
  256. 11:04branches, BLTU and BGEU.
  257. 11:07What is common for them?
  258. 11:09The and different for the other
  259. 11:12instructions. Well, you can take a look
  260. 11:14at this middle bit, instruction three
  261. 11:16bit. It is true only for those two. So,
  262. 11:20that sets the signness of a branch.
  263. 11:23In order to decode this branch, we just
  264. 11:25need to look at that
  265. 11:28middle bit, instruction three bit, and
  266. 11:30it tells us whether the branch is signed
  267. 11:32or not.
  268. 11:34So, that control signal is essentially
  269. 11:36equal to instruction 13
  270. 11:38and the branch because, you know, this
  271. 11:40bit will be true for other types of
  272. 11:42instructions. In order to
  273. 11:45um
  274. 11:48decode the branch, right? I mean, the
  275. 11:49branch is encoded um with the
  276. 11:56lower bits.
  277. 12:00So, it is
  278. 12:02I
  279. 12:04six
  280. 12:07and
  281. 12:09I five
  282. 12:12and not
  283. 12:15I4
  284. 12:16and not
  285. 12:19I3
  286. 12:21and not
  287. 12:23I2.
  288. 12:25That is our branch.
  289. 12:31That tells us that decodes all the
  290. 12:33branch instructions. And then to just
  291. 12:37select that we are looking for an
  292. 12:39unsigned branch, we add that with the
  293. 12:42instruction bit 13. Fairly simple, isn't
  294. 12:45it?
  295. 12:46This is a wide
  296. 12:48um
  297. 12:50uh six-bit wide
  298. 12:52AND gate.
  299. 12:55Keep in mind that sometimes six-bit wide
  300. 12:57AND gates may not be the most practical
  301. 12:59thing to implement. So, we'll try to
  302. 13:00break this down typically into a couple
  303. 13:03of gates.
  304. 13:06That's what our Boolean man-
  305. 13:07manipulation is for, isn't it?
  306. 13:11Let's design the decode logic for add.
  307. 13:15So, add is just one line in this um
  308. 13:20uh in this truth table that has our nine
  309. 13:24bits. You know, here is our add.
  310. 13:28So, what we would do to
  311. 13:30decode that we are executing an add,
  312. 13:33well, we would just write down the
  313. 13:34expression that it is equal to
  314. 13:37um
  315. 13:38I30
  316. 13:40instruction bit being
  317. 13:42false, I14 is false, I13 is false, I12
  318. 13:47is false. All of them are zeros. And
  319. 13:49then we need to AND this with an R-type
  320. 13:51instruction.
  321. 13:53R-type is encoded as
  322. 13:58n-
  323. 14:00I6 being false, I5 being true, I4 being
  324. 14:04true,
  325. 14:05I3 being false, I2 being
  326. 14:10false. And that's it. Um we can If we If
  327. 14:13we other extensions, we would have to
  328. 14:16end this with 11 in the last bit
  329. 14:19positions, but we don't have to
  330. 14:22for the purpose of our project because
  331. 14:24we don't have any other instructions.
  332. 14:27And that's it. We have just
  333. 14:29finished all what we need to know about
  334. 14:31instruction decoding. And we have done
  335. 14:33more than that. We actually
  336. 14:36built a complete RISC-V processor.
  337. 14:39We should celebrate that, which we'll do
  338. 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.