YouTube2Text

[CS61C FA20] Lecture 18.2 - Single-Cycle CPU Datapath I: Building a RISC-V Processor — Transcript

by CS 61C Departmental · 3,034 words · 555 segments · language en · Watch on YouTube

Full transcript

  1. 0:01[Music]
  2. 0:11welcome back to our
  3. 0:12module on designing a risk 5 cpu
  4. 0:16cpu is a digital system so based on the
  5. 0:20fundamental principles of designing
  6. 0:22digital logic
  7. 0:23we should be able to build one but how
  8. 0:26do we really go about
  9. 0:28building a cpu we have
  10. 0:31heard about state machines as a common
  11. 0:34way
  12. 0:35of describing digital logic or digital
  13. 0:38systems
  14. 0:39to be more precise so can we use a state
  15. 0:44machine
  16. 0:45to describe the cpu or to design a cpu
  17. 0:50it shouldn't be a surprise that the
  18. 0:52answer is yes
  19. 0:54we can view a cpu design as design of a
  20. 0:56state machine
  21. 1:00let's think of one instruction and then
  22. 1:02we can
  23. 1:03try to extrapolate that to all the
  24. 1:06instructions
  25. 1:07that we have in a cpu so state
  26. 1:11in a cpu is contained in the registers
  27. 1:14the memory and the program counter
  28. 1:16we don't have any other part of a cpu
  29. 1:20that
  30. 1:20stores you know source the data
  31. 1:25so that would set what would
  32. 1:28be combinational logic doing so for
  33. 1:30example
  34. 1:31in this case if we're doing an addition
  35. 1:33operation
  36. 1:35all relevant contents would be
  37. 1:39in the instruction memory that we have
  38. 1:41over here pointed
  39. 1:43we wouldn't care much about the contents
  40. 1:45of a data memory which is dmem
  41. 1:47but we would care about the registers
  42. 1:50and the program counter
  43. 1:54the contents of the registers and the
  44. 1:56program counter in the instruction
  45. 1:58memory
  46. 1:58would be used to perform the function to
  47. 2:02execute that instruction so if the
  48. 2:03instruction is
  49. 2:04a register based ad then this
  50. 2:06combinational logic
  51. 2:08would perform an ad based on the
  52. 2:11contents
  53. 2:12of the state elements
  54. 2:15and the result will be written back
  55. 2:19into the state elements into the
  56. 2:21registers and the memory
  57. 2:22and would update the program counter
  58. 2:26we can have a different bubble of
  59. 2:28combination logic
  60. 2:30for every instruction and one can
  61. 2:32imagine that we could build really a
  62. 2:34processor that way you know every single
  63. 2:36one of these 30 something instructions
  64. 2:38in rv32i
  65. 2:39would have its own delegated bubble of
  66. 2:41logic
  67. 2:42and then we would essentially use
  68. 2:45multiplexers
  69. 2:47and the select input on those
  70. 2:48multiplexers would be a type of
  71. 2:50instruction that we are executing
  72. 2:52and we would be updating the state based
  73. 2:54on these
  74. 2:57different outputs of these different
  75. 3:00combinational logic marks but that's not
  76. 3:01practical because
  77. 3:04many instructions are going to share the
  78. 3:07same data path
  79. 3:10so in general we are going to try to
  80. 3:12build this data path as a cloud
  81. 3:14of logic that can execute all the
  82. 3:16instructions so
  83. 3:18the instruction would would start
  84. 3:20executing
  85. 3:21on a tick of a clock on a rising edge of
  86. 3:24a clock
  87. 3:25go through the combinational logic
  88. 3:29and present the outputs of it back
  89. 3:33to the state elements on the next click
  90. 3:36could take overclock on the next rising
  91. 3:38edge of a clock we'll write it back
  92. 3:41as a new state in the state elements
  93. 3:44we'll keep doing that
  94. 3:46we by doing that sequence we would
  95. 3:48execute
  96. 3:50all instructions that we have now
  97. 3:54building one monolithic cloud of logic
  98. 3:57that would be executing all
  99. 3:58instructions is also not practical
  100. 4:03it's really hard to think of it that way
  101. 4:05it is hard to
  102. 4:06to to design that kind of a logic
  103. 4:11there is just too much stuff going on in
  104. 4:13there so
  105. 4:14a general solution to that is to break
  106. 4:17up
  107. 4:18instruction execution into phases and
  108. 4:20have
  109. 4:21a bubble of logic associated with each
  110. 4:24of these phases
  111. 4:26it's a lot easier to divide and conquer
  112. 4:28this particularly given
  113. 4:30the fact that all instructions have
  114. 4:33similar phases
  115. 4:35not all of them have all the phases of
  116. 4:37execution
  117. 4:38but most of all of them have at least
  118. 4:41some phases of that execution so
  119. 4:43to actually see what that what am i
  120. 4:45talking about let's take a look at
  121. 4:46common
  122. 4:47phases of execution that would
  123. 4:50correspond
  124. 4:51to separate stages in a data path
  125. 4:55so stage one would be instruction fetch
  126. 4:58stage two is instruction decode stage
  127. 5:01three is execute
  128. 5:02stage four is memory access and stage
  129. 5:05five
  130. 5:06is right back to registers what does
  131. 5:08this mean
  132. 5:09we're going to see it in a much more
  133. 5:11detail
  134. 5:12a bit later but i'll just give you a
  135. 5:14quick preview for now
  136. 5:16instruction fetch gets the instruction
  137. 5:19from the memory and
  138. 5:24stores it in a processor then
  139. 5:27instruction decode
  140. 5:28looks at that process that that
  141. 5:29instruction and
  142. 5:32determines what it is so decodes what is
  143. 5:35the operation that you would like to do
  144. 5:37in the execution stage
  145. 5:39we actually perform the operation
  146. 5:42commonly that may be done by the
  147. 5:46arithmetic logic unit and we'll find out
  148. 5:48that we are
  149. 5:49using arithmetic unit not just for
  150. 5:53calculating arithmetic and logic
  151. 5:55operations whether they're registered or
  152. 5:58immediate based but also for branches
  153. 6:03then in the fourth phase we would access
  154. 6:05the memory
  155. 6:06if we're doing any of these instructions
  156. 6:09that
  157. 6:09have to deal with the memory we would
  158. 6:11access the memory in the fourth stage
  159. 6:12these are
  160. 6:13loads and stores and finally
  161. 6:17in the fifth stage if we need to write
  162. 6:20back the content in
  163. 6:22in the registers like for example in
  164. 6:24case of loads
  165. 6:25we would complete this instruction in
  166. 6:28the fifth stage
  167. 6:30by writing back to the register
  168. 6:35let's take a look at schematically how
  169. 6:37does this look like
  170. 6:38so here is a diagram of
  171. 6:41a data path for a processor it's a very
  172. 6:44generic data path
  173. 6:46and it is shown here arranged
  174. 6:49are the the elements that we have seen
  175. 6:52before
  176. 6:52we have heard before but we haven't seen
  177. 6:54them really connected in a particular
  178. 6:56way
  179. 6:58um in the first stage we have a program
  180. 7:01counter
  181. 7:03then there is an instruction memory
  182. 7:05there is a register file
  183. 7:07alu and the data memory and in this case
  184. 7:11we are assuming that we have two
  185. 7:13separate memories
  186. 7:15instruction memory in the data memory
  187. 7:17although there are part of one physical
  188. 7:19memory but we
  189. 7:20are assuming that we are separately
  190. 7:23treating
  191. 7:24that part of the memory that contains
  192. 7:26instructions
  193. 7:28from a part of a memory that contains
  194. 7:29the data we'll see
  195. 7:31later why do we do that and how do we do
  196. 7:35that
  197. 7:38so um just to to get a little bit about
  198. 7:41the insight of what is going on in here
  199. 7:44um
  200. 7:44around there is some logic around the
  201. 7:46program counter so the program counter
  202. 7:49in when it is executing
  203. 7:52instructions in sequence will be
  204. 7:55incremented by four
  205. 7:56bytes to point to the next 32-bit word
  206. 8:00in risk 5. this mux here
  207. 8:03is to bypass that increment
  208. 8:07and write a branch target if the branch
  209. 8:11is to be taken in that way
  210. 8:14the program counter would be pointing to
  211. 8:16the instruction
  212. 8:18where the branch lands
  213. 8:21then we have an instruction memory that
  214. 8:25has instructions in there
  215. 8:28and these instructions will point
  216. 8:32to the registers that you would like to
  217. 8:34to work with so it would issue addresses
  218. 8:37that correspond to the destination
  219. 8:39register or
  220. 8:41first and second source registers
  221. 8:43finally we have the alu
  222. 8:46and the data memory and from the data
  223. 8:49memory
  224. 8:50there is this path where we write back
  225. 8:52to the registers let's take a look at
  226. 8:54the phases of
  227. 8:56execution and they're executed in
  228. 8:59sequence
  229. 9:00from the first one to the fifth one
  230. 9:02instruction fetch
  231. 9:04happens by the program counter pointing
  232. 9:06to the instruction memory
  233. 9:08that is all what it is about the fetch
  234. 9:10instruction pointer points to
  235. 9:12an allocation in the instruction memory
  236. 9:14where the next instruction is
  237. 9:15that's how we fetch the instruction then
  238. 9:18when we have that instruction
  239. 9:21we decode it um often
  240. 9:24that phase is associated with the
  241. 9:26register read because at the same time
  242. 9:28we know that our our formats of the
  243. 9:31instructions are rigid
  244. 9:33and particular parts of the instructions
  245. 9:35are going to be used
  246. 9:37as addresses to the register file
  247. 9:41in the third phase or stage
  248. 9:45of execution we
  249. 9:49will execute we will perform addition or
  250. 9:52subtraction
  251. 9:53or branch calculation
  252. 9:57then we will access the memory by
  253. 10:01using the result of the alu
  254. 10:05and then finally the result of
  255. 10:08the the the result of the memory access
  256. 10:11will be written back
  257. 10:12into the register file
  258. 10:15we're going to see this in much more
  259. 10:17detail in many many examples for
  260. 10:20every single one of the instructions or
  261. 10:22instruction types
  262. 10:23that we have introduced previously
  263. 10:28for now it is important to
  264. 10:31also understand this concept of a single
  265. 10:35cycle data path so all of these five
  266. 10:39phases of execution are going to happen
  267. 10:41during one clock cycle
  268. 10:43so on a we are going to start
  269. 10:45instruction execution
  270. 10:46on the first rising edge of a clock with
  271. 10:49the instruction fetch
  272. 10:50and we are going to write back the final
  273. 10:54result on the next rising edge of a
  274. 10:57clock
  275. 10:57so that at that point the registers will
  276. 11:00be updated
  277. 11:02and the program counter will be updated
  278. 11:05to contain the new
  279. 11:06address of the next instruction to be
  280. 11:08fetched
  281. 11:11later on we'll find out that we can
  282. 11:13break this up into multiple clock cycles
  283. 11:15but
  284. 11:15all of our discussion for the next few
  285. 11:18segments is going to be
  286. 11:22dealing with this what we call a single
  287. 11:24cycle data path
  288. 11:25where all five phases of execution
  289. 11:28happen
  290. 11:29within one clock cycle
  291. 11:35so how do we build the data path then we
  292. 11:37have seen some of these elements
  293. 11:39here are the components that we need we
  294. 11:41they're all familiar we have all seen
  295. 11:43them
  296. 11:44in the module on digital systems so
  297. 11:46combinatorial elements that we have
  298. 11:49um are adders multiplexers and alus
  299. 11:54that will be arranged like legos that's
  300. 11:57why this is
  301. 11:58so fun because we can do it essentially
  302. 12:00as assembling a lego kit
  303. 12:03and then we need to complement them with
  304. 12:05state elements
  305. 12:06which are the elements that store the
  306. 12:09data
  307. 12:10and the clocking methodology and for now
  308. 12:13we are sticking with a very simple
  309. 12:15clocking methodology that corresponds to
  310. 12:18a single cycle cpu
  311. 12:21let's talk a little talk a little bit
  312. 12:23about
  313. 12:24these state elements the first one that
  314. 12:27we'll definitely need
  315. 12:28is a register this register is
  316. 12:32again a fairly simple structure and we
  317. 12:34have seen it before
  318. 12:35it's a collection of flip flops if you
  319. 12:37will
  320. 12:38so a 32-bit register will consist of
  321. 12:4232 flip-flops and they're all going to
  322. 12:44be
  323. 12:45written together on the rising edge of a
  324. 12:48clock
  325. 12:48so in this case we have data in
  326. 12:52port into that register and data out
  327. 12:55port in that register we are labeling
  328. 12:59it as having a port that is in bits wide
  329. 13:03you know what does that mean well it is
  330. 13:06a shorthand notation
  331. 13:07for having n wires and most commonly
  332. 13:10in 32-bit data paths that number n
  333. 13:14is going to be 32.
  334. 13:17so we have data port that is 32
  335. 13:20wires wide into the register and data
  336. 13:24out port that is also 32 bit
  337. 13:27bits wide the register
  338. 13:31gets updated only on the rising edge of
  339. 13:33a clock so the new value gets
  340. 13:35written on the rising edge of the clock
  341. 13:38if
  342. 13:39the write enable signal is asserted
  343. 13:45if the the write enable signal is not
  344. 13:48asserted this if it is d asserted if it
  345. 13:50is equal to zero
  346. 13:52that the the values in the register will
  347. 13:54not change
  348. 13:56so let's recap that one more time
  349. 14:00we will change
  350. 14:03the values of the data on the port
  351. 14:07or bus data in
  352. 14:11on the rising edge of a clock that new
  353. 14:14value
  354. 14:15those new values will be written into
  355. 14:17the register
  356. 14:18and they will stay at the output of that
  357. 14:21register until the
  358. 14:22next clock cycle and that's it
  359. 14:27the next thing the next building block
  360. 14:30in this hierarchy
  361. 14:32is the register file register file is a
  362. 14:34collection of registers
  363. 14:36so register is a collection of flip
  364. 14:37flops register file is a collection of
  365. 14:40registers so
  366. 14:41in rb32i we need a register file
  367. 14:45with 32 registers to hold all the
  368. 14:47registers that we need
  369. 14:49for our architecture
  370. 14:53one thing to keep in mind that
  371. 14:56there is a limitation on how many
  372. 14:59registers we can access
  373. 15:00at a time um the wires
  374. 15:04you know when you get to the really
  375. 15:06integrity details of how we implement
  376. 15:08processors we'll find out that wires are
  377. 15:11a real
  378. 15:12challenge to fit to access in any
  379. 15:15possible
  380. 15:16order these registers
  381. 15:20in the architecture of risk five
  382. 15:24requires that we should be able to read
  383. 15:27two registers simultaneously out of a
  384. 15:30register file
  385. 15:32and that we can write to one of these
  386. 15:35registers
  387. 15:38so in short this would be called
  388. 15:41to read single write type of a register
  389. 15:45file
  390. 15:46to read single write
  391. 15:50the way how we access the register file
  392. 15:53is again
  393. 15:54by using the addresses and the buses
  394. 15:58there is one input bus that contains
  395. 16:01the new value that is going to be
  396. 16:03written in
  397. 16:04it and it is in risk five rb32i
  398. 16:0832 bits wide and there are two output
  399. 16:10buses
  400. 16:11bus a and bus b that will
  401. 16:14contain the
  402. 16:18the values that are in registers a and b
  403. 16:20or source registers
  404. 16:221 and 2.
  405. 16:25the way how we select which one of these
  406. 16:28two
  407. 16:29which of the 32 registers
  408. 16:33would put their data out on
  409. 16:36the bus a or bus b is by
  410. 16:40setting their addresses at these ports
  411. 16:43r a and rb
  412. 16:46so so when we select when we put a 5-bit
  413. 16:50number that corresponds to
  414. 16:52a 5-bit address of any of the 32
  415. 16:54registers
  416. 16:55on ra we are going to get the contents
  417. 16:58of that register
  418. 16:59on the bus a and correspondingly when we
  419. 17:02put an address over register
  420. 17:04on port rb we are going to get its
  421. 17:07contents
  422. 17:08on the output rp when we would like to
  423. 17:13write to a register we need to
  424. 17:16enable it for writing we don't want to
  425. 17:18scribble over the registers accidentally
  426. 17:20so we have to say that we mean it by
  427. 17:22asserting the right enable
  428. 17:24by putting the datum on the bus
  429. 17:27w setting the address of the register
  430. 17:30that we would like to write into
  431. 17:32on rw and the rising edge of the clock
  432. 17:35this
  433. 17:35value from bus w is going to be
  434. 17:37transferred to
  435. 17:39the corresponding register
  436. 17:44this is kind of a bit of a magic
  437. 17:47register file
  438. 17:48um we need only clock
  439. 17:52to write into it well we assume that
  440. 17:54every time we just assert
  441. 17:56the when as soon as we put the values
  442. 18:00our a and rb at its inputs at the edits
  443. 18:04at its address inputs the outputs are
  444. 18:07going to show up
  445. 18:08so we don't need a clock in order to
  446. 18:10read the register file
  447. 18:15there is of course some delay until
  448. 18:18these outputs show up
  449. 18:19we call that the access time
  450. 18:23then there are more state elements
  451. 18:26elements that contain the states we
  452. 18:28so we have a memory and memory is again
  453. 18:31fairly magical
  454. 18:34we have data in bus and date outbus
  455. 18:37and the address we also have a clock and
  456. 18:40write enabled it work
  457. 18:41very similarly to what we have had
  458. 18:43before
  459. 18:44so in this case we have multiplex
  460. 18:48read and write access to the memory what
  461. 18:51does that mean
  462. 18:52when we put an address here we
  463. 18:55and don't clock it the data will
  464. 18:58magically the corresponds to that
  465. 19:00address
  466. 19:00show up at the date outpus when we would
  467. 19:04like to write into the memory we will
  468. 19:05assert the right enable
  469. 19:07and on the next rising edge of a clock
  470. 19:10data in
  471. 19:12will be written into a corresponding
  472. 19:14memory location
  473. 19:16where the address corresponds to
  474. 19:23again there are delays associated with
  475. 19:25reading and writing the memories which
  476. 19:27we'll call
  477. 19:28read and write access times when needed
  478. 19:33so let's recap what is the state that is
  479. 19:36required by the rb32i isa
  480. 19:41each instruction during execution
  481. 19:46reads and updates the state of three
  482. 19:49sets of elements registers the program
  483. 19:52counter and the memory
  484. 19:54so registers or the register file
  485. 19:57holds 32 registers each
  486. 20:01being of 32 bits wide meaning that we
  487. 20:04have 1024
  488. 20:06total flip flops that are organized in
  489. 20:0932 registers where each of these 32
  490. 20:12registers is 32 bits wide
  491. 20:15the first register that you would like
  492. 20:16to add address or work with
  493. 20:19is specified by the rs1 field in the
  494. 20:22instruction the second register that you
  495. 20:24would like to read from
  496. 20:24is specified by the rs2 field so we have
  497. 20:28two
  498. 20:28read ports the right register or the
  499. 20:31destination where we would like to write
  500. 20:33the result
  501. 20:34to is specified by the rd field
  502. 20:37in the instruction and
  503. 20:41we know that x0 register is essentially
  504. 20:43a zero so we actually don't need to have
  505. 20:46flip flops in that row of the register
  506. 20:48file
  507. 20:49we can just connect all of those to zero
  508. 20:53we'll be anyways ignoring any request
  509. 20:55right
  510. 20:56there the next one
  511. 20:59the next state element is the program
  512. 21:01counter it's also a
  513. 21:0232-bit register that holds the address
  514. 21:05of the current instruction that we are
  515. 21:07executing
  516. 21:08and we are going to update it during the
  517. 21:10execution of every instruction to point
  518. 21:12to the next instruction that will be
  519. 21:14executing whether it's the next
  520. 21:16instruction
  521. 21:16sequence which is four bytes away or the
  522. 21:19target of a branch
  523. 21:21finally we have memory and we hinted
  524. 21:24that
  525. 21:25we when we are
  526. 21:30designing memory it's a monolithic piece
  527. 21:32where we store both
  528. 21:34the data and the program but for the
  529. 21:36purpose of designing a data path
  530. 21:38we break it up into two parts the
  531. 21:41instruction memory
  532. 21:42and the data memory there's still a
  533. 21:46part of the same physical memory but in
  534. 21:48all of our drawings we are going to
  535. 21:50treat it separately and we'll see a
  536. 21:52little bit later in
  537. 21:53just the next module
  538. 21:57that we enable that by using some pieces
  539. 22:01a concept called caches we'll have
  540. 22:04separate instruction and data caches
  541. 22:07which hold the copies of
  542. 22:10the corresponding parts of the main
  543. 22:12memory but will be on-chip
  544. 22:14and fast to access we are not
  545. 22:17going to discuss that for now we'll just
  546. 22:20imagine
  547. 22:21that we have two separate memories
  548. 22:25so instructions are read or fetched
  549. 22:28from the instruction memory which we'll
  550. 22:30call imem and
  551. 22:31load and store instructions access the
  552. 22:34data memory
  553. 22:35which is the daemon so we're now ready
  554. 22:38to actually build our first instruction
  555. 22:41we'll do that after the break

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 18.2 - Single-Cycle CPU Datapath I: Building a RISC-V Processor by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 3,034 words across 555 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.