YouTube2Text

[CS61C FA20] Lecture 19.3 - Single-Cycle CPU Datapath II: Implementing Branches — Transcript

by CS 61C Departmental · 1,899 words · 346 segments · language en · Watch on YouTube

Full transcript

  1. 0:01[Music]
  2. 0:09welcome back to s5 cpu design
  3. 0:11we have designed more than 50
  4. 0:14of a data path or much more than 50 of
  5. 0:16the data path
  6. 0:18so far by adding instructions that we
  7. 0:21needed for
  8. 0:22our type i type and s-type instructions
  9. 0:25now we are going to
  10. 0:26add support for the branches which are
  11. 0:28slightly different
  12. 0:31remember branches what do branches do
  13. 0:34they compare the contents of the
  14. 0:36registers rs1 and rs2
  15. 0:39and depending on the condition of a
  16. 0:41branch
  17. 0:42update the program counter so if the
  18. 0:45branch condition is met
  19. 0:46the program counter is updated to a new
  20. 0:50address
  21. 0:50that is specified by as the offset
  22. 0:55immediate to the current
  23. 0:58value of the program counter if the
  24. 1:00branch condition is not met
  25. 1:03then it goes to the next instruction
  26. 1:05which is four bytes away
  27. 1:08instruction encoding for b types for
  28. 1:12b format encoding is similar
  29. 1:15to the s format except that the
  30. 1:18immediate now
  31. 1:19uses those 12 bits to encode
  32. 1:22a 13 bit range the last bit is
  33. 1:25always zero because we try to use this
  34. 1:29range to represent values of minus four
  35. 1:32thousand ninety six
  36. 1:33to plus four thousand ninety four in
  37. 1:36two by ten increments
  38. 1:41let's see how does our data path
  39. 1:44look like so far so we
  40. 1:47have our program counter that so far has
  41. 1:50ability only to be updated
  42. 1:52to the next instruction which is four
  43. 1:54bytes away we'll need to do something to
  44. 1:56that
  45. 1:56to enable this other update uh based on
  46. 1:59the outcome of the branch
  47. 2:00we have the instruction memory register
  48. 2:02file immediate
  49. 2:04computation alu for execution and the
  50. 2:08memory
  51. 2:10when we are looking at branches we
  52. 2:12clearly
  53. 2:13don't need to work with the memory so we
  54. 2:16will not be
  55. 2:16writing or reading anything from the
  56. 2:18memory we are also not updating the
  57. 2:20register file so
  58. 2:22a lot of that part of the data path will
  59. 2:25not
  60. 2:25be lit up but we need to do two things
  61. 2:29simultaneously for which we'll need
  62. 2:31resources
  63. 2:32we need to perform the branch
  64. 2:34computation and
  65. 2:36a branch condition evaluation and
  66. 2:39computation of the new address
  67. 2:42so in order to add branches we need to
  68. 2:45look at
  69. 2:46what functionality we need to have in
  70. 2:48our data path
  71. 2:50so the state changes not now by
  72. 2:53changing the contents of the registers
  73. 2:55or the memory
  74. 2:56this change of state is by changing the
  75. 2:59program counter
  76. 3:00problem counter takes two values after a
  77. 3:03completion of a branch
  78. 3:04it either is pc plus 4 or it is
  79. 3:07pc plus immediate or this immediate is
  80. 3:10of a new type
  81. 3:11is of the s type there are six different
  82. 3:14branch instructions
  83. 3:16bq and e blt bg and bgltu bgeu
  84. 3:21the last two being unsigned versions
  85. 3:24of the blt and bge
  86. 3:27that essentially evaluate conditions
  87. 3:30whether
  88. 3:31the contents of rs1 and rs2 are equal to
  89. 3:35each other
  90. 3:35not equal to each other less than
  91. 3:38greater or equal
  92. 3:39and so on so what does our data path
  93. 3:43need to do
  94. 3:44it needs to evaluate the
  95. 3:48the contents the the the contents of
  96. 3:51rs01 and rs2
  97. 3:54needs to compare them and then needs to
  98. 3:56compute
  99. 3:57pc plus the immediate but we have only
  100. 4:00one alu
  101. 4:01that we have been able to use so far uh
  102. 4:04so we need to add more hardware now you
  103. 4:06may want to think where
  104. 4:07which additional hard what should the
  105. 4:09additional hardware do
  106. 4:11should it be used to calculate pc plus
  107. 4:13immediate
  108. 4:14or to perform the comparison well we
  109. 4:16have a powerful alu that can do all
  110. 4:18kinds of things
  111. 4:19so let's not mess with that and it is
  112. 4:21already wired to
  113. 4:23calculate to take on the immediate
  114. 4:26so let's not touch that what we
  115. 4:29should add is a simpler hardware that is
  116. 4:32going to perform
  117. 4:34the branch comparison
  118. 4:37so let's take a look at how do we modify
  119. 4:40the data path
  120. 4:42here is our new data path it got a few
  121. 4:46new additions most notable one
  122. 4:49is that we have a multiplexer in front
  123. 4:52of a program counter that enables us
  124. 4:54to write either pc plus 4 or
  125. 4:57the new address then we have a
  126. 5:02a little bit bigger piece of hardware
  127. 5:03that does the branch comparison
  128. 5:06it takes one input whether the branch is
  129. 5:09signed or unsigned
  130. 5:11and produces two single bit outputs
  131. 5:15is if the values are equal or less than
  132. 5:19than each other and then we have one
  133. 5:21more multiplexer here in the data path
  134. 5:24this multiplexer enables us
  135. 5:27to feed to the a port of the alu the top
  136. 5:30part of the alu
  137. 5:31either the rs1 contents which is what we
  138. 5:34did before
  139. 5:36or the program counter so we are going
  140. 5:39to
  141. 5:40use the alu to add
  142. 5:43the immediate value to the program
  143. 5:47counter
  144. 5:48and we are going to take that output and
  145. 5:51write it back
  146. 5:52into the program counter
  147. 5:56there are a few things here additional
  148. 5:58things that need to
  149. 5:59happen we need to set the immediate
  150. 6:03select to
  151. 6:04the branch type of intermediate we meet
  152. 6:06that means we need to
  153. 6:07generate yet another type of an
  154. 6:09immediate in addition to ins type of
  155. 6:11immediates
  156. 6:12then we need to control the branch
  157. 6:15comparator
  158. 6:16with whether it's signed or unsigned
  159. 6:21based on decoding of the instruction and
  160. 6:24then we need to
  161. 6:25control this multiplexer as well in
  162. 6:27front
  163. 6:28of the a input to the alu
  164. 6:31what is inside the branch comparator
  165. 6:33well it is
  166. 6:35a piece of logic that compares the
  167. 6:37values that are in rs1 and rs2
  168. 6:40fairly straightforward and not very
  169. 6:43difficult to
  170. 6:44implement in logic
  171. 6:48notice that we are supporting
  172. 6:51six different branches two of them being
  173. 6:53variants of each other signed or
  174. 6:54unsigned
  175. 6:57but we have only two possible outcomes
  176. 7:00so
  177. 7:00out of these four basic types whether
  178. 7:03something is
  179. 7:03equal to other or less than we support
  180. 7:07the other ones
  181. 7:08directly because branch
  182. 7:12if greater or equal is exactly
  183. 7:15the opposite of branch on
  184. 7:18less than so if we just negate the
  185. 7:21output of
  186. 7:22branch on less than we get
  187. 7:26branch or if greater than or equal
  188. 7:29so that is it we have therefore
  189. 7:33one input single bit control and two
  190. 7:36outputs out of a branch comparator
  191. 7:41the other uh kind of important thing to
  192. 7:45to mention about branches
  193. 7:48and in encoding of immediates
  194. 7:51in b types is it's
  195. 7:55the difference of risk five from some
  196. 7:56other isas in other isas
  197. 7:59what you will find out is that the
  198. 8:01immediate value is
  199. 8:04the whole immediate value is shifted by
  200. 8:06one bit
  201. 8:08in the instruction encoding which
  202. 8:12requires us to use a multiplexer
  203. 8:15to you know a bunch
  204. 8:19a wide multiplexer that shifts
  205. 8:22left or right the what we would like to
  206. 8:26pick as an immediate from
  207. 8:28the instruction so
  208. 8:32there are 12 inputs to a multiplexer
  209. 8:35that produce 12 outputs but all of them
  210. 8:38are occupied
  211. 8:39risk five does it a little bit
  212. 8:40differently it keeps
  213. 8:42most of the immediate values 11 out of
  214. 8:4512 immediate values
  215. 8:47in the same place as what we have had in
  216. 8:50the s format and just moves
  217. 8:53one immediate value that's the rationale
  218. 8:56that we
  219. 8:57you know why we have that kind of an
  220. 8:59encoding that looked a little bit
  221. 9:00strange
  222. 9:01early on but as a result now we just
  223. 9:03need
  224. 9:04one multiplexer with two inputs
  225. 9:07to move that bit to the right position
  226. 9:11between the two formats so s immediate
  227. 9:14and b immediate are very similar to each
  228. 9:16other
  229. 9:16all we need to do is to place
  230. 9:19the eleventh immediate in the right spot
  231. 9:24please just take a look at that and
  232. 9:26convince yourself that this is true
  233. 9:29so just to recap immediate encoding we
  234. 9:32have
  235. 9:33seen three types of immediate so far i
  236. 9:35type
  237. 9:36as type and b type they're very similar
  238. 9:39to each other
  239. 9:40and when we produce the actual immediate
  240. 9:43that is
  241. 9:4431 bits 32 bits
  242. 9:47wide out of a 12 12-bit
  243. 9:50value that is encoded inside the
  244. 9:52instruction we
  245. 9:54do that in a similar fashion so
  246. 9:58we always sign extend the bottom parts
  247. 10:02between i immediates and s immediates
  248. 10:06are um are different
  249. 10:09so it's a one two-way multiplexer that
  250. 10:11we have seen before
  251. 10:12um and the b immediate shares the same
  252. 10:17idea the instructions
  253. 10:2030 to 20 firing the instruction bits 30
  254. 10:23to 25
  255. 10:24are in the same position instruction
  256. 10:26bits 11 to 80s are in the same position
  257. 10:28we just move the instruction bit 7
  258. 10:32to a different position so it's again
  259. 10:34one
  260. 10:36single bit two-way multiplexer
  261. 10:39and we always sign extend based on the
  262. 10:42most significant bit
  263. 10:46let's just light up the branch path and
  264. 10:49that will let us allow us to wrap up the
  265. 10:52discussion about the branches
  266. 10:54when so here is what happens in
  267. 10:58uh in when we're executing a branch
  268. 11:00instruction it is a little bit different
  269. 11:01than the instructions that we have seen
  270. 11:03so far well first fetch an instruction
  271. 11:07by pointing the program counter to
  272. 11:09instruction
  273. 11:10memory then
  274. 11:14we will point you know we will
  275. 11:18fetch that instruction and instruction
  276. 11:19will address appropriate fields
  277. 11:21in the register file we only care about
  278. 11:24the two source registers
  279. 11:26we don't care about the destination
  280. 11:27register and therefore
  281. 11:30register write enable is going to be
  282. 11:32disabled
  283. 11:33we also start implement
  284. 11:37the immediate generation through
  285. 11:40you know sign extension but not is this
  286. 11:44we prepare the next value of the program
  287. 11:47counter first
  288. 11:48we increment it by 4 because we may
  289. 11:52take that value or
  290. 11:55we send the program counter downstream
  291. 11:58to the alu we don't know what is going
  292. 12:00to be the outcome of the branch
  293. 12:02until we perform the comparison so we
  294. 12:05set the control
  295. 12:06here to be
  296. 12:10to correspond to that branch so
  297. 12:12immediate select is a b
  298. 12:14register write enable is zero um
  299. 12:17we send also a signal
  300. 12:20to the branch comparator should we
  301. 12:24have um unsigned or signed comparison
  302. 12:27um set the appropriate inputs uh
  303. 12:31to the to the multiplexers alu is still
  304. 12:33going to do the addition
  305. 12:35of the this time of a program counter
  306. 12:37value
  307. 12:38with the immediate and memory is going
  308. 12:41to be set to read
  309. 12:42we are not going to write to it we don't
  310. 12:44want to even accidentally write to it
  311. 12:46and we are going to disregard any output
  312. 12:49that might come out of that
  313. 12:53the next thing in in execution is
  314. 12:56we are going to get the outputs of the
  315. 13:00two registers rs1 and rs2
  316. 13:04we are going to perform branch
  317. 13:05comparison the output of a branch
  318. 13:07comparison
  319. 13:08is going to tell us what to do where
  320. 13:11does
  321. 13:12the pc go which is the next value of the
  322. 13:14pc that we need to
  323. 13:15take um alu is going to
  324. 13:20add the the immediate
  325. 13:23offset to the current value of the
  326. 13:25program counter
  327. 13:27and bring that over
  328. 13:30to the input of the multiplexer that is
  329. 13:32sitting in front of the program counter
  330. 13:34based on whether the branch is taken or
  331. 13:37not
  332. 13:38we update the program counter and that
  333. 13:40is it
  334. 13:41that completes the branch that is the
  335. 13:44only state
  336. 13:45that is being updated after quite a bit
  337. 13:48of lighting up of the data path
  338. 13:55this is it that we need to know
  339. 13:58about the branches we have added the
  340. 14:00data path that supports the branches
  341. 14:03and we'll see that we actually
  342. 14:06have now a huge majority of what we need
  343. 14:09to
  344. 14:10implement the rest of the instruction
  345. 14:12formats
  346. 14:13so we'll do that after a break

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 19.3 - Single-Cycle CPU Datapath II: Implementing Branches by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,899 words across 346 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 translate the transcript into 100+ languages.

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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.