YouTube2Text

W3 RISC V ISA I Part2 EN — Transcript

by Hasan Erdem Yantır · 5,568 words · 1,011 segments · language en · Watch on YouTube

Full transcript

  1. 0:02So,
  2. 0:04yeah, in here while when I call a
  3. 0:06function, I am registering the return
  4. 0:08address, and after this function runs,
  5. 0:12there is a return instructions. Always
  6. 0:14functions has return instructions, and
  7. 0:17this return instructions jumps to the
  8. 0:20location that I saved before, before
  9. 0:22calling this function. While or while
  10. 0:25while calling this function.
  11. 0:30We will see more detailed examples.
  12. 0:33Uh these are the extensions for INM. We
  13. 0:37We saw INM extensions. Uh there are
  14. 0:40floating point extensions, F and D
  15. 0:42extensions. F is for 32-bit floating
  16. 0:45point, and D is for 64 floating point.
  17. 0:48Uh these are the extensions, FD and Q. Q
  18. 0:52is 128-bit extensions, but no one is
  19. 0:55using 128-bit. 64-bit processors are
  20. 0:58enough for the current world. For this
  21. 1:00reason, there is no commercial 128-bit
  22. 1:03processor.
  23. 1:04So, in RISC-V,
  24. 1:07I mentioned that RISC-V has 32
  25. 1:09registers,
  26. 1:11but these registers are for integer
  27. 1:13values. If you want to also add a
  28. 1:15floating point uh
  29. 1:18instruction unit to your processors, you
  30. 1:20need to put also another set of register
  31. 1:23for floating point values. So, if you
  32. 1:26want to implement F and D
  33. 1:29extensions to your RISC-V processor, you
  34. 1:32need to add also another 32 32-bit
  35. 1:35registers
  36. 1:36to keep the floating point numbers.
  37. 1:38Because floating point numbers has
  38. 1:39different set of registers.
  39. 1:42So, in here, with is the highest
  40. 1:44precision. For example, F is implemented
  41. 1:47RF RVF implemented. This is the 32-bit.
  42. 1:52So, this is the floating point register.
  43. 1:54It starts from still same.
  44. 1:56Uh it starts from FD0 to FD F sorry F0
  45. 2:02to F31 but no in here F0 is not zero. F0
  46. 2:08can not can be different than zero. This
  47. 2:10is special case for the integer.
  48. 2:12So F0 it is all
  49. 2:15any value. It can keep any value between
  50. 2:17F0 and F31.
  51. 2:19So there are different floating point
  52. 2:22instructions.
  53. 2:23They are not important for this class,
  54. 2:25but I can just briefly say that for
  55. 2:28example addition, subtraction, division,
  56. 2:30square root, min, max.
  57. 2:32Uh there are some more instructions. For
  58. 2:34example, you can do an floating point
  59. 2:36operation. For example,
  60. 2:38you can do there are some floating point
  61. 2:41operations that you are doing operation
  62. 2:43between a floating point number and
  63. 2:45integer number. It uses for example an
  64. 2:48operand from integer register file.
  65. 2:51There are conversion operations. So in
  66. 2:54here for example, we have an example C
  67. 2:56code. Uh float we are if you're writing
  68. 2:59a C code and you
  69. 3:02define the variable as a float, then
  70. 3:05it runs the it does the operations on
  71. 3:08this variable as floating point.
  72. 3:11So in here for example, I have a scores
  73. 3:13array 200 size and in this for loop I am
  74. 3:17adding 10 point to each of them.
  75. 3:20So this is the risk-5 assembly code
  76. 3:22correspondence for it.
  77. 3:24Uh so in here I have a variable loop
  78. 3:26variable I. I starts with zero. So I
  79. 3:29assume that I is stored in S1 register.
  80. 3:32So I'm initializing it as a zero and
  81. 3:36T2 is another register.
  82. 3:39It keeps the maximum value 200 in here.
  83. 3:42And I have also another value 10. This
  84. 3:45is constant. I am keeping it in a T0
  85. 3:48register.
  86. 3:50This is the initialization.
  87. 3:52And in here
  88. 3:54I'm doing the
  89. 3:57uh this this this
  90. 4:00operation
  91. 4:01is converting this T0 register 10.
  92. 4:06This integer T0 value to floating point.
  93. 4:10So, this 10 integer 10 becomes floating
  94. 4:12point 10. So, this T0 10 is assigned to
  95. 4:16FT0 register. FT0 is a floating point
  96. 4:19register.
  97. 4:21So, it is
  98. 4:22uh signed word size.
  99. 4:25And
  100. 4:27in this for loop, for example, I am
  101. 4:29doing comparison. I am checking whether
  102. 4:32S1 becomes T2. T2 means 200. So, S1 as
  103. 4:36one at the beginning it was zero. So,
  104. 4:38I'm comparing
  105. 4:40branch greater or equal. So, comparing
  106. 4:42whether S1 is uh
  107. 4:44greater or equal to T1. I'm just doing
  108. 4:47this this
  109. 4:48calculation. And if it is so, I am
  110. 4:52jumping to down section, but if not
  111. 4:55I I continue from here.
  112. 4:58In here, I am doing uh shift left
  113. 5:00logical immediate.
  114. 5:02So, in here, I have a address, for
  115. 5:05example, in here S1 is an address.
  116. 5:08I am just multiplying it by four.
  117. 5:12Uh
  118. 5:13and adding it to T0.
  119. 5:23Okay, in here S1 is multiplied by four
  120. 5:27because this is
  121. 5:28shift left logical immediate. Sh- It
  122. 5:32means that multiply by four and writing
  123. 5:34it to T0.
  124. 5:36And this T0 is added by S0.
  125. 5:39So,
  126. 5:41S0 actually keeps the
  127. 5:44address of this array. So, S0 assume
  128. 5:48that S0 is the address of this array.
  129. 5:51So, at each time I am doing a floating
  130. 5:54point load operations from this
  131. 5:57value, T0 value.
  132. 6:00And doing the addition operation, it
  133. 6:02means that increasing it by 10 and then
  134. 6:04storing it back to the same location.
  135. 6:07This is floating point load word. This
  136. 6:09is floating point store word. I'm
  137. 6:12storing it back and then increasing the
  138. 6:14array pointer by one. And each time I am
  139. 6:17checking whether I I I am over the limit
  140. 6:20or not. If under the limit, I continue
  141. 6:22to run it. Uh the important point in
  142. 6:26here is that
  143. 6:27since memory is byte addressable and
  144. 6:30each time I am accessing a word
  145. 6:33in this case, while accessing this
  146. 6:36scores
  147. 6:37for example
  148. 6:38if I access score zero
  149. 6:40I assume that I access score zero
  150. 6:43after accessing score zero, if you want
  151. 6:46to access score one, you need to
  152. 6:47increase it by four. Because at each
  153. 6:50time this is word operation, I am
  154. 6:52accessing the four bytes. For this
  155. 6:54reason why I am doing in here multiply
  156. 6:56by four. So for example, scores one at
  157. 7:00point zero, scores one zero, sorry, at
  158. 7:04location zero, one at location four, two
  159. 7:08at location eight
  160. 7:09three at location 12. So, each time I am
  161. 7:13multiplying this
  162. 7:15array index by four to access the actual
  163. 7:17location of this word. Is it clear,
  164. 7:19right?
  165. 7:23Okay, this is floating point. Floating
  166. 7:24point is not important. It's just an
  167. 7:26introduction. We we will not deal with
  168. 7:29floating point in this class. And we
  169. 7:31will not implement floating point
  170. 7:32register also in our processor. We will
  171. 7:34only focus on the in integer part.
  172. 7:42So, at that point we can a break. This 4
  173. 7:44to 5 minutes. We can give a break 10
  174. 7:47minutes.
  175. 7:48And during that time also you can do
  176. 7:51quiz. You can do quiz. This quiz is
  177. 7:55is not assessing the your knowledge.
  178. 7:59It is just to know you, why you are
  179. 8:02taking this class.
  180. 8:04So, you can answer
  181. 8:07during the break.
  182. 8:10So, when you answer it, everyone will
  183. 8:13get 100.
  184. 8:15Because there is no correct answer.
  185. 9:08So, we can continue.
  186. 9:10There is also another extension named C
  187. 9:12extension.
  188. 9:14Uh I told you that all risk-5
  189. 9:17instructions is 32-bit, but this is not
  190. 9:21correct.
  191. 9:22Uh
  192. 9:22if you are using the C extension, then
  193. 9:26you can compress the instructions to
  194. 9:2816-bit also, but in some cases, not
  195. 9:31always.
  196. 9:32Uh if you are using the C extension,
  197. 9:35some instruction can be compressed to
  198. 9:3716-bit, but not 32.
  199. 9:40Either 32-bit or 16-bit.
  200. 9:44So, this extension is used for this
  201. 9:47purpose. So, some instructions can be
  202. 9:49decreased to 16-bit,
  203. 9:52but not all.
  204. 9:54In this case, I told you that in
  205. 9:58normal RISC-V, at each each instruction
  206. 10:0132-bit, so each time when I while
  207. 10:04switching to PC,
  208. 10:06I am adding four to two PC because it is
  209. 10:0932-bit, but in
  210. 10:11compressed version,
  211. 10:13if I run a compressed instruction, then
  212. 10:17next instruction is after PC plus two,
  213. 10:20after two bytes. Because instruction if
  214. 10:23instruction is compressed compressed, it
  215. 10:25is 16-bit instruction. So, the next PC
  216. 10:28is PC plus two in this case.
  217. 10:31But, not all instructions can be
  218. 10:34compressed. Only some of them can be
  219. 10:36compressed.
  220. 10:37So,
  221. 10:39it can replace common integer and
  222. 10:40floating point instructions with 16-bit
  223. 10:43values. Why people are doing it?
  224. 10:46Because assume that, for example, you
  225. 10:48compile a program, and this program is
  226. 10:5040 kilobyte, for example.
  227. 10:53And assume that some instructions can be
  228. 10:56compressed in in this program, so you
  229. 10:58can reduce its size to 30 kilobyte, for
  230. 11:01example, or 20 kilobyte, maximum 20
  231. 11:03kilobyte.
  232. 11:04So, it is people use it to to compress
  233. 11:07the instruction so that your compiled
  234. 11:10code is size of the compiled code is
  235. 11:12less than the uncompressed one.
  236. 11:16So, this is important because, for
  237. 11:17example, if you are using a
  238. 11:19microcontroller, and it has a limited
  239. 11:22space, then compressed version keeping
  240. 11:26the compressed instructions is nice
  241. 11:28because you are using less space.
  242. 11:31You have You need less memory
  243. 11:34requirement then.
  244. 11:36To compress instruction uses prefix C.
  245. 11:38For example, at this is 32-bit
  246. 11:42instruction.
  247. 11:43If you have a
  248. 11:46compressed version of this one, then it
  249. 11:48is C.at.
  250. 11:50It prefixed with C.
  251. 11:53And for example, in here the same code,
  252. 11:56this time I defined the scores as
  253. 11:59integer. So, if it is integer, then it
  254. 12:01means like this is integer scalar
  255. 12:04scalar integer.
  256. 12:06So,
  257. 12:08when I compile this code,
  258. 12:10then it generates the
  259. 12:12normal add instructions.
  260. 12:15And assume that while while compiling
  261. 12:19this code, I told that my processor also
  262. 12:22can
  263. 12:23support supports the C extension. So, it
  264. 12:26can run the compressed instruction also.
  265. 12:28By the way, this is optional. You can
  266. 12:30say that my processor is not supporting
  267. 12:32C extension, then no problem. All
  268. 12:35instructions becomes 32-bit.
  269. 12:37But if you want to compress the compiled
  270. 12:39programs and can be able to run it, then
  271. 12:43you need to add C extension. And assume
  272. 12:45that in here I compiled my program with
  273. 12:47C extension. And in this C extension,
  274. 12:51some of the operations can be
  275. 12:53compressed. Some of the instructions can
  276. 12:55be compressed and it's putting the
  277. 12:58compressed version of this instruction
  278. 13:00in this case.
  279. 13:05So, this is the same example program.
  280. 13:09So, in here there are some cases. For
  281. 13:11example, this add immediate, the
  282. 13:13compiler
  283. 13:15couldn't compress it because 200 was
  284. 13:17very big to fit in a compressed
  285. 13:19immediate format. Normally, instructions
  286. 13:2232-bit, but if you are compressing it,
  287. 13:24it is 16-bit. But in here
  288. 13:28200 is
  289. 13:2912-bit immediate value. The remaining is
  290. 13:334-bit, so it is impossible to fit this
  291. 13:35value.
  292. 13:36So,
  293. 13:37the compiler couldn't compress this
  294. 13:39instruction, for example, but it could
  295. 13:41it could compress this
  296. 13:43load immediate one.
  297. 13:47Uh
  298. 13:47c.l.i.1.
  299. 13:49This is initialization. Actually, it was
  300. 13:51at There you see it was at. I was doing
  301. 13:53s10
  302. 13:54uh zero. So, and initializing s1 as
  303. 13:57zero. It put another instruction named
  304. 14:00as c.l.e.
  305. 14:02For example, this is the load word
  306. 14:04version, but compressed one.
  307. 14:06So, in here I am doing the same
  308. 14:08operation, but I use the compressed
  309. 14:11version of it.
  310. 14:14For example, c.add immediate s04 is
  311. 14:16equivalent to add immediate s0 s04, for
  312. 14:19example.
  313. 14:21Also,
  314. 14:22this branch greater or equal couldn't be
  315. 14:25compressed, so in here we also couldn't
  316. 14:27compress it.
  317. 14:30How
  318. 14:31it is compressing? Actually, in
  319. 14:33compressed instructions, for example,
  320. 14:37uh
  321. 14:38compiler is doing so. In RISC-V
  322. 14:40specification, I can give further
  323. 14:42information. While
  324. 14:44in for example, compressed specification
  325. 14:46says that
  326. 14:48for example, if the register that you
  327. 14:50are using is between Assume that it is
  328. 14:52x0 and x7. Assume that. In this case,
  329. 14:563-bit is enough for register, right?
  330. 14:59Uh it says that if
  331. 15:01the operation is compressed,
  332. 15:03then register can be between zero and
  333. 15:06seven.
  334. 15:073-bit only. So, it separates only 3-bit
  335. 15:09for compressed instruction.
  336. 15:12But, for example, if you are using any
  337. 15:15register like x27,
  338. 15:18then it cannot compress this
  339. 15:19instruction.
  340. 15:21This is a special format.
  341. 15:24So, I will briefly mention about the
  342. 15:26privileged instruction set architecture.
  343. 15:28As I told you, privileged instruction
  344. 15:30set architecture is for the operating
  345. 15:32system.
  346. 15:33Uh but I am to mention it because there
  347. 15:35are some concepts that we need to take
  348. 15:37care, pay attention
  349. 15:40uh while looking to out-of-order
  350. 15:42processors. We will see later. For this
  351. 15:44reason, I will mention briefly about
  352. 15:45privileged instruction set architecture.
  353. 15:48But privileged is for running operating
  354. 15:50system.
  355. 15:51So,
  356. 15:53in RISC-V, there are privileged levels
  357. 15:55for operating system support.
  358. 15:58Uh generally, in a processor,
  359. 16:01processor is a machine. There is a
  360. 16:02machine level. Machine level is the
  361. 16:05uh lowest level. And in machine level,
  362. 16:08you can run anything. No protection.
  363. 16:11Uh because machine is the processor
  364. 16:12itself.
  365. 16:15One
  366. 16:16level upper, there is supervisor mode.
  367. 16:19And in this supervisor mode, uh
  368. 16:22operating system runs.
  369. 16:24And on top of the
  370. 16:26operating system, user programs run. For
  371. 16:28example, in this laptop, I have
  372. 16:30PowerPoint presentation. And this
  373. 16:32PowerPoint presentation runs on the uh
  374. 16:35user mode. In this user mode, for
  375. 16:37example, I have PowerPoint presentation.
  376. 16:41And in this laptop, I have Windows
  377. 16:43operating system. Windows operating
  378. 16:45system. And assume that this Windows
  379. 16:47operating system is running on RISC-V
  380. 16:49processor.
  381. 16:51So, PowerPoint is the user
  382. 16:54application that I am running.
  383. 16:56Uh Windows is the operating system
  384. 16:59running this PowerPoint.
  385. 17:00So,
  386. 17:02this privileged levels are required
  387. 17:04because
  388. 17:06this PowerPoint, for example, assume
  389. 17:08that PowerPoint is running, but at the
  390. 17:10same time, WhatsApp is running in here
  391. 17:12at the same time.
  392. 17:14This PowerPoint to don't access the data
  393. 17:17of WhatsApp. For this reason,
  394. 17:19while accessing the machine, we are
  395. 17:22going through the operating system and
  396. 17:25asking
  397. 17:27permission.
  398. 17:29So, for example, this PowerPoint says
  399. 17:30that I am running I am reading a data,
  400. 17:34for example, PowerPoint slides. I am
  401. 17:35reading this data. Can I read it? It
  402. 17:38asks the operating system. And if
  403. 17:40operating systems gives permission, then
  404. 17:43it can access the file and show us the
  405. 17:45presentation. Similar manner,
  406. 17:47WhatsApp, if it wants to access the
  407. 17:50data, it asks the operating system. In
  408. 17:52this way,
  409. 17:54assume that WhatsApp wants to access the
  410. 17:57data of PowerPoint, the operating system
  411. 17:59doesn't allow it. That's why there are
  412. 18:01privilege levels and this privilege
  413. 18:03extension of RISC-V defines these
  414. 18:05privilege levels and its standards.
  415. 18:08Uh this is a
  416. 18:09operating system concepts in a nutshell
  417. 18:12in a basic
  418. 18:13uh way.
  419. 18:15RISC-V has privilege levels for
  420. 18:17operating system support. Uh the
  421. 18:19architecture has many control and status
  422. 18:22registers
  423. 18:23uh in addition to normal register file.
  424. 18:26So, I mentioned you about the register
  425. 18:28file between X0 and X31. If you want to
  426. 18:31support operating system, you have to
  427. 18:33support different kinds of registers
  428. 18:35also.
  429. 18:36Uh but this is a different story.
  430. 18:39So, privilege levels limit access to
  431. 18:41memory or set certain instructions.
  432. 18:44Uh so, RISC-V privilege
  433. 18:46uh modes, as I told you, machine mode,
  434. 18:49it is the machine itself, the processor
  435. 18:51itself. It is the mode like you can
  436. 18:53access everything. No no Even you are
  437. 18:55not in machine mode, you are not asking
  438. 18:57any
  439. 18:58uh permission.
  440. 19:00Uh system mode, it is the supervisor
  441. 19:02mode, it is the operating the mode that
  442. 19:05operating system runs. User mode, the
  443. 19:07mode that we are running our own
  444. 19:09software as the user.
  445. 19:12There is a hypervisor mode, but this is
  446. 19:14different. No need to mention about it.
  447. 19:16Uh and
  448. 19:18all these
  449. 19:20privileged modes has some special
  450. 19:22registers that you are changing these
  451. 19:25registers to get access or to ask access
  452. 19:29to check whether can I access or not.
  453. 19:32These are all special registers. No need
  454. 19:34to
  455. 19:35worry about them.
  456. 19:37This is just a
  457. 19:38uh
  458. 19:39brief introduction.
  459. 19:41So, you will not also see. We will not
  460. 19:43see because we we are going to focus on
  461. 19:44the processor architecture itself. We
  462. 19:46will not uh
  463. 19:48go into these details. We will not deal
  464. 19:50with them.
  465. 19:52The important point in here is that for
  466. 19:54example, I told you that
  467. 19:57for example, I have a application in
  468. 20:00here.
  469. 20:01I have WhatsApp application and
  470. 20:04E-Nabu's application.
  471. 20:06E-Nabu's application has very sensitive
  472. 20:08information, health information for you.
  473. 20:11And WhatsApp is also working in here.
  474. 20:14In here,
  475. 20:15the important point that I told you is
  476. 20:18that while accessing the data,
  477. 20:21these two applications request access
  478. 20:23from the operating system. If operating
  479. 20:26system allows the access, it can get the
  480. 20:28data.
  481. 20:30So, what about assume that WhatsApp, by
  482. 20:32the way, made by Israel,
  483. 20:34wants to access your health data.
  484. 20:37It can access.
  485. 20:39In this way, it asks to operating system
  486. 20:42to access the data of this application,
  487. 20:44health application.
  488. 20:46And in this case, if it tries to
  489. 20:49access,
  490. 20:52operating system doesn't allow it and
  491. 20:55gives exception. It's named as
  492. 20:57exception.
  493. 20:58Because it has no right to access that,
  494. 21:01so it generates an exception.
  495. 21:03So, this concept is called as an
  496. 21:05exception. If you are trying to access a
  497. 21:08data or something and you have no
  498. 21:12right to access it, you are your program
  499. 21:15gets a exceptions. So, this
  500. 21:17exception is important exception
  501. 21:20concept is important. Exception means
  502. 21:22that unscheduled function to exception
  503. 21:25handler.
  504. 21:26Exception actually leads to unscheduled
  505. 21:28function call to exception handler.
  506. 21:32So,
  507. 21:34by the way, this is exception
  508. 21:37and there is also another kind of
  509. 21:40concept. It is interrupt.
  510. 21:44Interrupt is also
  511. 21:46Interrupt is not like exception.
  512. 21:48Exception is a problem problem. It says
  513. 21:51that there is a problem, so operating
  514. 21:52system needs to take care of it because
  515. 21:54for example, WhatsApp tries to access
  516. 21:56the some important data,
  517. 21:59but at that point operating system takes
  518. 22:01the control and manage this situation.
  519. 22:03But there is also another concept. It's
  520. 22:05called interrupt.
  521. 22:07Interrupt is the
  522. 22:09It is interrupt actually. So, it is like
  523. 22:12for example, when you press a keyboard
  524. 22:14keyboard, it's an interrupt to the
  525. 22:17processor.
  526. 22:18For example, while I am moving this
  527. 22:20mouse, it is an interrupt. It says that
  528. 22:24it says processor that user
  529. 22:26entered some data to the processor or
  530. 22:29user
  531. 22:31user did something. So, you need to be
  532. 22:34careful. You need to take care of what
  533. 22:37user is doing.
  534. 22:39So, this is the interrupt concept. But
  535. 22:41both exceptions and interrupts are
  536. 22:43classified as trap and trap means that
  537. 22:46the
  538. 22:47operating system needs to take control
  539. 22:50and do the according function. Do the
  540. 22:53according take the according actions.
  541. 22:55This is named as trap and trap is can be
  542. 22:59either exception or
  543. 23:01interrupt. Trap source can be either
  544. 23:03exception and interrupt.
  545. 23:06Exceptions can be synchronous by the way
  546. 23:10and can occur at run time and it is
  547. 23:13always associated with an instruction.
  548. 23:15For example, if you want to access a
  549. 23:16region and you have no access right,
  550. 23:19then it is with load operation because
  551. 23:21load operation generates this exception.
  552. 23:23It tries to load a data
  553. 23:25and then
  554. 23:26if it cannot load, it generates an
  555. 23:28exception. Interrupt is asynchronous.
  556. 23:31Like for example, this mouse click is
  557. 23:33this is for example interrupt. For
  558. 23:35example, this is interrupt. This is
  559. 23:36interrupt.
  560. 23:38So, it is asynchronous. We don't know.
  561. 23:40At any time it can happen. So, it is
  562. 23:43triggered externally like the user input
  563. 23:46and it is not associated with an
  564. 23:48instruction.
  565. 23:50So, but both of them
  566. 23:53is classified as a trap and trap means
  567. 23:55that the transfer of control to a trap
  568. 23:58handle caused by either an exception or
  569. 24:00interrupt.
  570. 24:03So,
  571. 24:04exceptions are caused by hardware.
  572. 24:08If caused by hardware, they are called
  573. 24:10at interrupt like keyboard press and if
  574. 24:13software,
  575. 24:15for example, while running an
  576. 24:17instruction
  577. 24:19processor read an 32-bit value, but it
  578. 24:23couldn't find the type of instruction
  579. 24:25for example. It is not add
  580. 24:27nor sub. So, we don't know the type of
  581. 24:30this instruction. So, it is undefined
  582. 24:32instruction. In this case also we are
  583. 24:33generating an exception because we don't
  584. 24:35know. We start we are running the code
  585. 24:38and we saw a
  586. 24:39instruction in code and we don't know
  587. 24:41what what it corresponds to. So, this is
  588. 24:43also kind of a
  589. 24:45exception.
  590. 24:46So, in a processor when exception
  591. 24:48occurs, the processor
  592. 24:50records the cause of the exception,
  593. 24:52jumps to the exception handler, and
  594. 24:54returns to the program. This is the all
  595. 24:57operating system is doing. Actually, all
  596. 24:59processor is doing. Whenever you reach a
  597. 25:02cause and see an exception, we are doing
  598. 25:05these steps.
  599. 25:09So, in order to handle the exception,
  600. 25:11there are different
  601. 25:13registers. No need to worry about them.
  602. 25:15They are not important. But, whenever we
  603. 25:17solve an exception, we are switching to
  604. 25:19M mode and in M mode, we are handling
  605. 25:23this exception. This is the important
  606. 25:25point.
  607. 25:27Uh there are some special
  608. 25:29control and status registers to handle
  609. 25:31the exceptions, but no need to deal with
  610. 25:34to go into the detail with them because
  611. 25:37they are not much important in this
  612. 25:38class. But, you need to just need to
  613. 25:41know the concept of trap, exception, and
  614. 25:44interrupt. This is the important because
  615. 25:46while looking to the out-of-order
  616. 25:48processors, these concepts will be
  617. 25:50important. For this reason, I am trying
  618. 25:52to teach you.
  619. 25:55So, whenever a processor detects an
  620. 25:57exception, it jumps to exception
  621. 25:59handler.
  622. 26:00And this exception handler then
  623. 26:02does the corresponding takes the
  624. 26:06corresponding actions.
  625. 26:10So, in here there is an example, but if
  626. 26:13you want you can inspect it, but no need
  627. 26:15for you for you right now. This is just
  628. 26:17an exception
  629. 26:19topic. And there are different kind of
  630. 26:21kind of exceptions. For example, if
  631. 26:23instruction address misaligned is this
  632. 26:25is an exception. For example, you are
  633. 26:27run trying to run an instruction
  634. 26:30uh but you have no access to in this
  635. 26:33instruction location in memory. This is
  636. 26:35also an exception. If the instruction
  637. 26:39that you read is illegal, you don't know
  638. 26:41what is it. This is illegal.
  639. 26:43Uh there's breakpoint. While
  640. 26:46the trying to do load,
  641. 26:48you can generate exception also.
  642. 26:52Uh in here there's an exception called
  643. 26:54handler example. If you want you can
  644. 26:56inspect at home, but no need to worry
  645. 26:59about it right now. This The important
  646. 27:01one is the exception concept in here
  647. 27:03because later we will see it
  648. 27:06in while
  649. 27:08looking to the auto folder processors.
  650. 27:11So, until now I
  651. 27:13show you the
  652. 27:15instructions,
  653. 27:17but I didn't mention about the S uh
  654. 27:20binary correspondence of these
  655. 27:22instructions. I show you assembly
  656. 27:24language instructions that we can read
  657. 27:26and understand. For example, like add,
  658. 27:28sub, uh shift less than, branch greater
  659. 27:31equal.
  660. 27:32Uh but there must be machine language
  661. 27:36correspondence of these instructions.
  662. 27:39Because
  663. 27:40computers are not reading like us. They
  664. 27:43are not looking to add add and
  665. 27:45understanding whether it is add.
  666. 27:48Computers are just looking to ones and
  667. 27:50zeros.
  668. 27:51And we told that in RISC-V
  669. 27:54each instruction
  670. 27:56is represented as binary and computers
  671. 27:59only understand ones and zeros.
  672. 28:01So, if the instruction is 32-bit,
  673. 28:05uh
  674. 28:07actually it reads 32-bit value and tries
  675. 28:10to try to understand what this 32-bit
  676. 28:14value represents as an instruction.
  677. 28:17RISC-V instructions are 32-bit if it
  678. 28:20supports compressed, it is 16-bit,
  679. 28:23but it's always 32-bit. By the way, in
  680. 28:26Intel, for example, instructions are
  681. 28:28variable. In Intel, for example, since
  682. 28:30this is a CISC architecture,
  683. 28:31instructions between 1 byte and
  684. 28:3516 or 17 byte between them. The
  685. 28:37instruction size is also changing in
  686. 28:39Intel, but in RISC-V instruction size is
  687. 28:42always
  688. 28:4432-bit. If you are supporting C
  689. 28:46extension, then it can be also 16-bit.
  690. 28:50In overall, there are four types of
  691. 28:52instruction formats. There are more
  692. 28:53types, but no problem. We can assume
  693. 28:55that there are four types of instruction
  694. 28:57types. R-type, I-type, S-type,
  695. 29:00and U-type.
  696. 29:03So, we can expect that R-type is the
  697. 29:07instruction type for register type
  698. 29:09operations. So, you remember
  699. 29:11Remember, there are some operations.
  700. 29:13This is the op code for example. And
  701. 29:16this op code is doing operation on these
  702. 29:19two registers. One of them is for
  703. 29:21example X2, X3. And result is going to
  704. 29:25X5, for example. It is doing some
  705. 29:28operation on X2 and X3 and resulting the
  706. 29:31result to X5. This kind of operations
  707. 29:34are R-type operations. And R-type
  708. 29:37operations are decoded
  709. 29:40encoded in a 32-bit instruction format
  710. 29:43in this way.
  711. 29:45So, in R-type operations, RS1, RS2,
  712. 29:48these are the source register. RD is the
  713. 29:50destination register. There are other
  714. 29:52fields, op, the operation code or op
  715. 29:54code, and there are function seven and
  716. 29:57function three fields. Function seven
  717. 29:59means it is a 7-bit.
  718. 30:01And function three is 3-bit.
  719. 30:04So, this op function seven and function
  720. 30:07three
  721. 30:08corresponds to the actually operation to
  722. 30:11be performed.
  723. 30:15to be performed.
  724. 30:17So, this is the 32-bit
  725. 30:20encoded operation format.
  726. 30:24Between This is
  727. 30:26between zero and 31-bit. So, when you
  728. 30:30look at this R-type operations, RD is in
  729. 30:33this field. In this 32-bit value, RD is
  730. 30:36between
  731. 30:37seven and 11 registers bit fields. RS1
  732. 30:41is between 15 19, and RS2 is in here.
  733. 30:44And op function three and function seven
  734. 30:47is stored in here in this location.
  735. 30:4925-31, 12-14, and 06.
  736. 30:54So, op function three and function seven
  737. 30:57describes what this operation is doing
  738. 31:00and this RS1, RS2, and RD are the
  739. 31:03register
  740. 31:04values. So, these are the five bits. Why
  741. 31:07it is five bits? Because I have 32
  742. 31:09register. 2 to the
  743. 31:11five is 32. So, I am encoding these 32
  744. 31:15values by five bits. For this reason,
  745. 31:17these are five bits values.
  746. 31:20So, this is the R-type coding. So, these
  747. 31:22are the examples. For example, addition,
  748. 31:25subtraction operation. When you look at
  749. 31:27it here, for example, for addition,
  750. 31:29function seven field is zero, function
  751. 31:31which field
  752. 31:32function three field is zero, operation
  753. 31:35field is 51.
  754. 31:36For example, for sub,
  755. 31:38operation is 51, function three is zero,
  756. 31:41but function seven is 32.
  757. 31:44But, whenever function seven is 32, it
  758. 31:46is sub. It is function zero with this
  759. 31:49function three and operation values,
  760. 31:51then it corresponds to add.
  761. 31:54So, this is for coding. For example, for
  762. 31:56add and sub instructions. And this is
  763. 31:59the binary versions. For example, if RD
  764. 32:01is 18, then when you look at here, this
  765. 32:0410010, it is corresponds to 18 in
  766. 32:07register. These are the exact 10
  767. 32:10representation. And
  768. 32:12in this in memory, we are storing these
  769. 32:15values and each time PC increases and
  770. 32:18runs these instructions. And cause this
  771. 32:20is we will encode
  772. 32:22Actually, we will decode these
  773. 32:23instructions and understand what this
  774. 32:24instruction is doing while this while
  775. 32:27designing our processor. We will not
  776. 32:30start
  777. 32:31We We don't start to design the
  778. 32:33processor. We will do it maybe we will
  779. 32:35start to do it maybe after two two
  780. 32:37weeks. Two or one weeks.
  781. 32:42So R-type
  782. 32:43it is the operations for op, for
  783. 32:46example, rd
  784. 32:48rs1 and immediate. For such kind of
  785. 32:52operations it is a R-type operation.
  786. 32:55And uh
  787. 32:56I-type operation
  788. 32:58three operands rs1, rd, and immediate.
  789. 33:01Uh it has no function seven.
  790. 33:04It has op and function three field and
  791. 33:06it is enough to
  792. 33:08uh corre- it is enough to encode to
  793. 33:11uh
  794. 33:12corresponding functionality.
  795. 33:14So, this is the I-type operation format.
  796. 33:20So, here there are I-type operations.
  797. 33:22Load, by the way, load are also I-type
  798. 33:26operation and this add immediate
  799. 33:28operations are I-type operations.
  800. 33:32SB-type it is used for store and branch
  801. 33:35operations. It has 12-bit immediate, by
  802. 33:39the way, still.
  803. 33:40Uh
  804. 33:41but it differ only immediate encoding.
  805. 33:43This is S-type. S-type operation in here
  806. 33:45function three in here.
  807. 33:47Immediate is a little bit different.
  808. 33:50The
  809. 33:51bits between 0 4 in here and 5 11 in
  810. 33:55here for S-type and for B-type
  811. 33:58it's a little bit distributed.
  812. 34:00And there is a reason why this is so.
  813. 34:03Uh because RISC-V tries to always put
  814. 34:08depending on the operation type
  815. 34:10irres- irrespective of the operation
  816. 34:13type, actually.
  817. 34:14Whether it is SB, I, or R these RS1
  818. 34:18fields are always in the same location.
  819. 34:20They try to keep these RS1, RS2 in the
  820. 34:22same location.
  821. 34:24Uh this is very good because at the end,
  822. 34:27while reading the RS1, whether it is SB
  823. 34:30or
  824. 34:31other types, you are always reading it
  825. 34:33from between 15 and 19. And while
  826. 34:36designing the processor hardware,
  827. 34:38this really increases the speed of the
  828. 34:41decode unit, your decode unit.
  829. 34:44But in B type, immediate is a little bit
  830. 34:46distributed, so you need to collect them
  831. 34:49while
  832. 34:50designing your processor.
  833. 34:54S type is This is a S type detail.
  834. 34:58Uh This is the operation. In here, there
  835. 35:00are S type operation examples.
  836. 35:02Uh store word, store half, and store
  837. 35:04byte. So, you can see it in here.
  838. 35:07Function three in here, for example,
  839. 35:10corresponds whether it is word, half, or
  840. 35:12byte.
  841. 35:14It's op op code is same, but depending
  842. 35:17on function three, its size is changing.
  843. 35:23This is B type, branch type operations.
  844. 35:26It is immediate is a little bit
  845. 35:28distributed. So, for example, immediate
  846. 35:31one
  847. 35:33between one four in here
  848. 35:36between five to 10 in here, then 11 is
  849. 35:39in here, and 12 in here.
  850. 35:41Why it is so?
  851. 35:43When you start to read the RISC-V
  852. 35:47uh
  853. 35:48extension documentation, you can
  854. 35:50understand because they are trying to
  855. 35:52keep the same field in the same location
  856. 35:54always. For example, in here, in RISC-V,
  857. 35:57they are always keeps the high
  858. 36:00significant bit in here at the end of
  859. 36:02the
  860. 36:03instruction in this 31-bit
  861. 36:06because it is very good while
  862. 36:10for example, if you want to do sign
  863. 36:11extension to immediate, you are you can
  864. 36:14always get it from this location. So,
  865. 36:16you can you will see that while
  866. 36:17designing the hardware, it makes
  867. 36:19everything easier.
  868. 36:23Uh by the way, branch
  869. 36:26has immediate between one and 12. It is
  870. 36:2912-bit immediate, but it has no zero
  871. 36:32bit.
  872. 36:33Uh because in branch type operations
  873. 36:38I can either jump to across 16-bit or
  874. 36:4232-bit boundaries.
  875. 36:45So, if
  876. 36:47I assume that if I am supporting
  877. 36:48compressed instruction, if I am jumping
  878. 36:5216-bit
  879. 36:54boundaries, then my least significant
  880. 36:57bit is always zero.
  881. 36:59Because this is byte addressable, and
  882. 37:01while changing the PC
  883. 37:04in compressed format, if I am supporting
  884. 37:07the compressed, my the least significant
  885. 37:10bit of the PC always is zero
  886. 37:13in byte addressable memory because at
  887. 37:15each time I am increasing the PC by 16
  888. 37:18by 6 6 by 16 or 32, and at each time the
  889. 37:23least significant bit is always zero. In
  890. 37:25this case, so there is no need to put
  891. 37:28another zero to immediate. So,
  892. 37:31in this case, for example, you can
  893. 37:33assume that implicitly there is a zero,
  894. 37:36and then you can just encode to between
  895. 37:401 and 12 for this field. So, you can use
  896. 37:44one more bit, actually. So, instead of,
  897. 37:47for example, because in in the
  898. 37:49instruction format, you have 12-bit
  899. 37:52available
  900. 37:53after this op function three registered,
  901. 37:57the left is 12-bit.
  902. 37:59And instead of using this 12-bit to
  903. 38:02encode between zero to 11
  904. 38:05while
  905. 38:07adding this
  906. 38:09uh immediate to PC,
  907. 38:11since its first bit is always zero,
  908. 38:15I can just encode it as between 1 and
  909. 38:1812. So, implicitly it is like keeping
  910. 38:2113-bit because it's
  911. 38:24least significant bit is always zero.
  912. 38:26So, I am assuming that least significant
  913. 38:27bit is always zero. So, I am storing it
  914. 38:30in here in between 1 and 12 in here. So,
  915. 38:34in this way I can jump between 13 bit
  916. 38:37values. Is it clear?
  917. 38:44So, this is the B type operations.
  918. 38:47B type is similar also because while
  919. 38:50switching the PC, the least significant
  920. 38:53bit is always zero. So, it's immediate
  921. 38:55field is also starts with one.
  922. 38:57And this is the encoding for B type. So,
  923. 38:59you you can inspect at the home. This is
  924. 39:01for example branch equal operation
  925. 39:03correspondence.
  926. 39:06Uh U or G type, it is upper immediate
  927. 39:08type. Upper immediate type is for load
  928. 39:10upper immediate. And there is also
  929. 39:12another instruction at upper immediate
  930. 39:14to PC. And these kind of instructions
  931. 39:17are using upper immediate type.
  932. 39:19Uh
  933. 39:20it's It has a huge immediate, 20 bit
  934. 39:24immediate.
  935. 39:25For this reason, 20 bit of this 32 bit
  936. 39:28value is separated for immediate and the
  937. 39:31rest is for opcode and
  938. 39:34destination register. And that's all.
  939. 39:37It can keep huge immediate. But look at
  940. 39:39always immediate fields are same in this
  941. 39:42operations.
  942. 39:45It has U and G type.
  943. 39:47The difference is between the
  944. 39:49immediate fields actually. This G type
  945. 39:52has distributed immediate. You can you
  946. 39:55you need to collect it while designing
  947. 39:56your CPU.
  948. 39:58And these are the examples for U type
  949. 40:02load upper immediate uh format. You can
  950. 40:04inspect it in detail.
  951. 40:07Uh G type is also similar but immediate
  952. 40:10is a little bit different. There is
  953. 40:11still op and rd field in here.
  954. 40:15And in here I have immediate field.
  955. 40:19And this immediate is also starts with
  956. 40:21one.
  957. 40:24Because in PC relative jumps, least
  958. 40:27significant bit is always zero.
  959. 40:36Uh
  960. 40:36by the way, jump and
  961. 40:40jump
  962. 40:41and link
  963. 40:44register operations are I type, not J
  964. 40:47type. Because in jump and link register
  965. 40:50operations, I have register field also
  966. 40:53as a RS field. So, this is I type.
  967. 40:56I don't know whether there's an example.
  968. 40:59Uh there's no example in here, but you
  969. 41:01can inspect
  970. 41:02JAL
  971. 41:04R operation, jump and link register
  972. 41:06operation is I type. Because it has a
  973. 41:0912-bit immediate, and it has a RD field
  974. 41:12also.
  975. 41:13So, in order to
  976. 41:15separate a place, reserve a place for
  977. 41:17this RD, its immediate is less than 20.
  978. 41:28So, in here there's an uh
  979. 41:30JAL operation.
  980. 41:33Yeah, this is this is Okay, this is JAL
  981. 41:35operation.
  982. 41:36Uh it is a it is jumping to function
  983. 41:38one.
  984. 41:39And also
  985. 41:41keeping the return address at RA RA
  986. 41:44register. RA maybe X2, X3, I don't know.
  987. 41:48You you can check it.
  988. 41:50So, this is the corresponding assembly
  989. 41:52for the encoding. So, this is the
  990. 41:54immediate field.
  991. 41:56So,
  992. 41:58when you look at here, this function one
  993. 42:00is
  994. 42:010x A67F8
  995. 42:04bytes past JAL. So,
  996. 42:07I'm keeping this value in the immediate
  997. 42:09field.
  998. 42:11Uh
  999. 42:13and this is a opcode.
  1000. 42:15In here, if opcode is 111, then it means
  1001. 42:19that this is a jump jump instruction and
  1002. 42:22its RD is
  1003. 42:24one.
  1004. 42:25It means that RA is X1, actually. So, it
  1005. 42:28is one because
  1006. 42:33So, do you have any questions about this
  1007. 42:36RISC-V
  1008. 42:37uh encodings?
  1009. 42:41You can ask in Turkish, also.
  1010. 42:43If no question, we can finish at this
  1011. 42:46point.

About this transcript

This page contains the full transcript of W3 RISC V ISA I Part2 EN by Hasan Erdem Yantır, generated from the public captions YouTube serves with the video. The transcript has 5,568 words across 1,011 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.