YouTube2Text

The Engineering that Runs the Digital World šŸ› ļøāš™ļøšŸ’» How do CPUs Work? — Transcript

by Branch Education Ā· 5,072 words Ā· 316 segments Ā· language en Ā· Watch on YouTube

Full transcript

  1. 0:00Inside every desktop computer, smartphone,Ā  gaming console, laptop, or practically any
  2. 0:06other device you use on a daily basis is a CPUĀ  or Central Processing Unit, and in this video,
  3. 0:14we’re going to see how they work. A typicalĀ  processor for a powerful laptop like this one
  4. 0:20is built from billions of nanoscopic transistorsĀ  connected together using dozens of layers of wires
  5. 0:27and is essentially the brain of the device. But before we explore the microprocessor and
  6. 0:34all its complexity, let’s travel to the early daysĀ  of personal computers and video game consoles and
  7. 0:41compare the Apple 2e from 1983 to the modern-dayĀ  MacBook Pro. Inside the Apple 2e we find a chip
  8. 0:49called a 6502, which is considered one of theĀ  great-grandparents of all modern processors.
  9. 0:56This chip is built from 4528 transistors and canĀ  perform around 430 thousand calculations a second.
  10. 1:06While it could only run primitive applicationsĀ  and video games with simple graphics, this
  11. 1:12chip was the backbone of a generation of earlyĀ  computers and video game consoles such as the NES,
  12. 1:19the Commodore 64, and the Atari. Compare that toĀ  the MacBook Pro’s M1 processor which is built from
  13. 1:2816 billion transistors capable of performingĀ  around 3 trillion calculations a second,
  14. 1:35thus enabling it to generate expansiveĀ  3D worlds with immersive graphics.
  15. 1:41Despite these two chips being released around 45Ā  years apart, the underlying principles of how they
  16. 1:47work are rather similar. In a way, you can thinkĀ  of these devices as sharing a common section of
  17. 1:53technological DNA. In fact, if we were to openĀ  up a desktop computer and grab the CPU or the GPU
  18. 2:01inside the graphics card, or teardown a NintendoĀ  Switch or Smartphone and find the system on a chip
  19. 2:08or SoC, or even if you could make your way intoĀ  an AI Data Center and grab a state-of-the-art AI
  20. 2:15chip, you’d find that all of these processorsĀ  operate using the same underlying principles.
  21. 2:23In other words, both the Oregon Trail ofĀ  50 years ago and advanced AI algorithms
  22. 2:29run on processors with similarĀ  technological DNA, but of course,
  23. 2:34one of these chips is 10 billion times moreĀ  computationally powerful than the other.
  24. 2:41So, in this video, we’re going to take apartĀ  this microprocessor and find out exactly what
  25. 2:47the shared technological DNA is and how itĀ  enables CPUs to work. And just to be clear,
  26. 2:54the technological DNA is not transistors and it’sĀ  not logic gates, but rather it’s an architectural
  27. 3:03design and basic operational principle that’sĀ  fundamental to microprocessors and differentiates
  28. 3:10these chips from other integrated circuits.Ā  So, stick around, and let’s dive right in.
  29. 3:24This video is sponsored by Brilliant. Let’s begin with a quick 3D animated
  30. 3:31teardown of this Macbook Pro. When we open it up,Ā  we find a range of different components such as
  31. 3:37the touchpad, battery cells, speakers, a coolingĀ  fan, and the motherboard in the center. Mounted to
  32. 3:45the motherboard are the solid state drive or SSDĀ  Storage chips where all your files are saved and
  33. 3:52a range of other chips. Underneath the heat pipe,Ā  we find the DRAM which is the short term working
  34. 3:59memory and central processing unit. Let’s desolderĀ  the DRAM and CPU and open it up. Inside we find
  35. 4:07three parts: on the top is a protective cover thatĀ  conducts and dissipates heat, on the bottom is an
  36. 4:14interposer with thousands of connection pointsĀ  on either side and wires running inside of it,
  37. 4:20and soldered onto the interposer is the integratedĀ  circuit or IC which is also called a die and is
  38. 4:28the functional part of the CPU. On the die we canĀ  see the complex design of billions of transistors
  39. 4:35and wires organized into different sectionsĀ  such as the 4 high-performance computational
  40. 4:42cores, 4 energy-efficient cores, graphicsĀ  processing cores, cache memory and many other
  41. 4:49sections. Let’s zoom in on one of the performanceĀ  cores where we find that it’s separated into
  42. 4:56different functional blocks which we’ll add labelsĀ  to and then reorganize into an architectural
  43. 5:02diagram. This diagram illustrates how data andĀ  instructions move around a single processing core
  44. 5:09in the CPU and, although it’s rather complicated,Ā  you’ll understand how it works by the end of this
  45. 5:16video. But for now, let’s zoom in even furtherĀ  to get a nanoscopic view of a massive multilayer
  46. 5:22labyrinth of wires with the transistors atĀ  the very bottom. Here we see a group of 6
  47. 5:28transistors that are wired together to build anĀ  AND logic gate, and in this view we can see around
  48. 5:36650 transistors out of the total 16 billionĀ  that make up the overall chip. Understanding
  49. 5:44how billions of transistors work together toĀ  build a CPU capable of playing video games,
  50. 5:51watching movies or browsing the internet will takeĀ  a bit of work, so let’s start with an analogy.
  51. 5:58You may have heard that CPUs are like superĀ  powerful calculators. This analogy is only around
  52. 6:0520% complete as it’s missing some criticalĀ  parts, so let’s add them in to make a more
  53. 6:12accurate analogy. First, we’ll add a table for theĀ  calculator to sit on, along with a pencil and a
  54. 6:18sheet of paper. Next, we’ll add rows and rows ofĀ  bookshelves containing thousands of books along
  55. 6:26with a cart that can carry a small stack of booksĀ  between the shelves and the table. And finally,
  56. 6:33we’ll add an automated robot which we’ll callĀ  a control unit or controller. The controller
  57. 6:40can grab books from the bookshelves, move them toĀ  the cart and onto the table, and it can put them
  58. 6:46back. The controller can also read the contentsĀ  of each book, write on the paper and in the books,
  59. 6:53and use the calculator. You can think of theĀ  controller as a super-fast human, but we’re bad
  60. 7:00at animating humans, so it’s a robot instead. AndĀ  with that, we have all the parts for our analogy.
  61. 7:07Now let’s see how each part of our CPU analogyĀ  works. To start, the bookshelves are the storage
  62. 7:15devices in your computer, such as the SSD chips ,Ā  the cart represents the DRAM , and the table and
  63. 7:23its contents represent the CPU. On the CPU Table,Ā  there’s a small space for a single open book which
  64. 7:31is similar to the very limited capacityĀ  of the cache memory inside the CPU itself.
  65. 7:37Next, the single sheet of paper representsĀ  the Registers which are used for storing
  66. 7:43values or numbers that are actively being used.Ā  Specifically, on it are four general-purpose
  67. 7:50registers and a few more special locations whichĀ  we’ll discuss in a little bit. Additionally,
  68. 7:57the pencil is there to write and eraseĀ  things on the paper and in the books.
  69. 8:02Finally, the calculator represents the ArithmeticĀ  Logic Unit or ALU. This ALU calculator works using
  70. 8:10binary so there are only the digits zero andĀ  one and it can do simple functions like add,
  71. 8:17subtract or multiply two numbers. TheĀ  ALU calculator has many more functions
  72. 8:23that you may be unfamiliar with but are stillĀ  rather simple. For example, it can increase or
  73. 8:30decrease a number by one or the ALU can performĀ  bit shifts which is essentially taking a number
  74. 8:37and adding a zero to the end of it. In decimal,Ā  bit shifting is like multiplying a number by 10
  75. 8:44but in binary it’s equivalent to multiplying aĀ  number by two. The ALU can also perform logic
  76. 8:51functions on two numbers such as the logicalĀ  AND, OR, or Exclusive OR operations. For example,
  77. 8:59here is the logical AND operation for 2 binaryĀ  inputs and you can see that the output is the
  78. 9:06logical AND for each place value of the 2 inputs. However, more importantly, the ALU calculator can
  79. 9:14perform comparisons. For example, you canĀ  input two numbers and hit the comparison
  80. 9:20button to test whether the numbers are equal toĀ  one another and, if they are, then an equals flag
  81. 9:27goes up while the other comparison flags likeĀ  less than or greater than stay down. Finally,
  82. 9:34the ALU calculator’s display that outputs theĀ  result has a special name called the accumulator.
  83. 9:41So now that we’ve explained the various parts ofĀ  this analogy, how does it all work together? Well,
  84. 9:48the first step is to load a program that we wantĀ  to run, which is like moving a set of books from
  85. 9:53the bookshelves to the cart, and then moving aĀ  single book to the table and opening it up. It’s
  86. 10:00important to note that the DRAM cart and cacheĀ  memory on the table are both temporary and limited
  87. 10:07capacity locations, whereas the SSD bookshelvesĀ  can hold a lot more and are semi-permanent long
  88. 10:14term storage. Additionally, when the computer isĀ  turned off, there are no books in the DRAM or the
  89. 10:21CPU, but when the computer turns on, the cart andĀ  table are very actively shuffling books around.
  90. 10:29Let’s take a look at the contents of one of theĀ  books. Essentially, there are two types of pages:
  91. 10:35instructions and data. You can think of theĀ  instructions as the directions in a cookbook, with
  92. 10:41each step numbered sequentially across the pages.Ā  And, the pages of data contain a list of addresses
  93. 10:48with values stored at each address and are likeĀ  the ingredients that go into the recipe itself.
  94. 10:55Similar to cooking, you need both theĀ  recipe and ingredients to make it work,
  95. 11:00and just a few ingredients can be combinedĀ  in dozens of different ways using different
  96. 11:06recipes. But to not use an analogy insideĀ  another analogy, let’s drop the cooking one
  97. 11:13and focus on the books, table and calculator. Let’s start at the beginning of this program
  98. 11:19and flip to page one instruction one, which isĀ  called a ā€˜Load’ and is the most common type of
  99. 11:25instruction. This ā€˜load’ has us open the pagesĀ  of data and find a specific address. We then copy
  100. 11:34and write down the value stored at that addressĀ  into one of the general purpose registers on the
  101. 11:40sheet of paper. With instruction one completed, weĀ  move to instruction two, which is to increment the
  102. 11:48value in register zero by 1. So, we plug the valueĀ  into the ALU calculator and hit plus 1. The third
  103. 11:57instruction, called a ā€˜store’ instruction, isĀ  used to save or store the output of the calculator
  104. 12:03found in the accumulator display into the pagesĀ  of data in the same address it was in before.
  105. 12:10These simple yet very common instructions areĀ  equivalent to this line of code. Next we move
  106. 12:18onto instruction 4 and complete it and thenĀ  instruction 5 and so on, moving through the
  107. 12:24list of instructions which goes on and on and on. In order to keep track of which instruction is
  108. 12:31the next one to be completed, we use one of theĀ  special locations on the sheet of paper that we
  109. 12:37mentioned earlier called the Program Counter orĀ  PC, also called an Instruction Address Register
  110. 12:44or Instruction Pointer. Since the PC currentlyĀ  has a value of 5, we find instruction 5,
  111. 12:52complete it, and increase the program counterĀ  by one. Therefore, the next instruction to be
  112. 12:59completed will be instruction 6. However, what ifĀ  after completing instruction 6, we want to jump
  113. 13:06directly to instruction 42? Well, to do thisĀ  we use a jump instruction at 7 which directly
  114. 13:14sets the value in the program counter to a newĀ  number and in this case it’s 42. As a result, the
  115. 13:22sequence of instructions will be 5, 6, 7 which isĀ  the jump instruction, then 42, 43, 44 and so on.
  116. 13:32A similar set of instructions is called aĀ  conditional branch which is used for implementing
  117. 13:38IF statements, loops, and other conditional code.Ā  Let’s use an example of a FOR loop with a few
  118. 13:45simple lines of code inside of it. Quite simply,Ā  this loop is used to repeat the code inside of it
  119. 13:524 times. Here are the corresponding instructionsĀ  of the FOR loop along with the instructions for
  120. 13:59the code inside of it and we color coded each ofĀ  the elements to keep track of which specific lines
  121. 14:05of code result in the corresponding instructions.Ā  We’ll discuss how compilers turn code into
  122. 14:11instruction later in this video, but for nowĀ  let’s focus on the FOR loop and its instructions.
  123. 14:17Specifically, here’s where ā€˜i’ gets set to 0Ā  and stored in an address in the pages of data,
  124. 14:25here’s where ā€˜i’ is loaded from that addressĀ  and incremented by one, and here’s the contents
  125. 14:31of the loop. At the top, you can see the threeĀ  instructions, Load, Compare, and Branch greater
  126. 14:38than or Equal to. The Load first grabs the valueĀ  for ā€˜i’ and places it into register 0. Compare
  127. 14:47feeds ā€˜i’ stored in register 0 and a value of 4Ā  into the ALU and compares them, resulting in the
  128. 14:55applicable comparison flags being triggered. Next,Ā  branch greater than or equal to checks whether
  129. 15:03either the greater than or the equals flag is on,Ā  and if it is, it sets the program counter to 23,
  130. 15:11which corresponds to completing and leavingĀ  the loop. However when ā€˜i’ is less than 4 th
  131. 15:18ose flags aren’t triggered and the loop continues,Ā  until it hits the jump instruction at address 22,
  132. 15:26where the jump sets the program counter to 6Ā  which corresponds to the top of the for loop. As
  133. 15:33a result the loop will repeat a total of 4 times. Note that this code on the left is in C++,
  134. 15:42whereas the actual instructions completed by yourĀ  CPU are in a binary language called machine code,
  135. 15:49and the semi-readable version of the instructionsĀ  is called assembly, but we modified this assembly
  136. 15:56a little bit to make it more readable. One interesting note is that you may
  137. 16:00think that with everything a computer can doĀ  there must be tens of thousands of different
  138. 16:06instructions. Well actually the 6502 processorĀ  in the Apple 2e from 1983 could only complete 56
  139. 16:16different instructions whereas the modern M1 chipĀ  in the MacBook Pro can complete 354 instructions.
  140. 16:24Here’s the list of all the instructions eachĀ  chip can execute and if you take a good look,
  141. 16:30most of these instructions are rather simple.Ā  Let’s just think about that for a second. Every
  142. 16:37single thing you do on your computer can beĀ  constructed using only various sequences of 354
  143. 16:45different instructions. However many programs haveĀ  millions upon millions of lines of instructions,
  144. 16:52and hopefully, there aren’t any bugs in them. So now that we’ve discussed the range of possible
  145. 16:59instructions, let’s further explore how CPUsĀ  work. In order to complete an instruction there
  146. 17:06are always three key steps: Fetch, Decode,Ā  and Execute. The first step is Fetch and
  147. 17:14is where the controller uses the value in theĀ  program counter to search through the pages of
  148. 17:19instructions in the book for the correspondingĀ  instruction address. The controller then
  149. 17:24copies the instruction found at that addressĀ  into a special location called the current
  150. 17:29instruction register or CIR. At the same time theĀ  controller increases the program counter by 1.
  151. 17:38The second step is decode, and in this stepĀ  the current instruction is fed into a circuit
  152. 17:43called the instruction decoder. In our analogyĀ  from earlier, this decoder is a key part of the
  153. 17:49controller, and in essence it’s the circuitry thatĀ  reads in an instruction and both interprets what
  154. 17:56the machine code of an instruction actually does,Ā  and simultaneously produces the control signals to
  155. 18:03properly execute that instruction. Specifically,Ā  this instruction decoder circuit uses the binary
  156. 18:10values of the instruction and an incrediblyĀ  complex arrangement of logic gates to produce
  157. 18:16the corresponding control signals which areĀ  then sent to the different elements in the CPU.
  158. 18:22Instruction decoders are one of the moreĀ  complicated parts of the CPU but here’s an
  159. 18:27example along with a simplified explanation.Ā  Let’s say we have this ADD instruction in the
  160. 18:33current instruction register or CIR and it’s fedĀ  into the instruction decoder. The first part of
  161. 18:41the binary instruction specifies we want to useĀ  the ALU. With the ALU selected, the next 3 bits
  162. 18:49specify that we want to use the ADD function,Ā  and then the last 4 bits of the instruction
  163. 18:55indicates we want the values in register 0 andĀ  register 1 to be routed and sent to the ALU.
  164. 19:03Instruction decoding is considerably moreĀ  complicated than that but let’s move onto
  165. 19:08the third step which is Execute. DuringĀ  execute, using our example instruction,
  166. 19:15the control signals from the instruction decoderĀ  and an intricate set of electrical timing signals
  167. 19:22are used to first send the value in registerĀ  0 and then the value in register 1 to the ALU.
  168. 19:29The timing signals are used to accommodate theĀ  time it takes electricity to travel from the
  169. 19:35registers to the ALU and for transistors and logicĀ  gates to change their state, thereby ensuring the
  170. 19:42correct result at the output. After the values areĀ  input, the ALU adds the two numbers together, and
  171. 19:49a subsequent timing signal saves the result intoĀ  the accumulator, thus completing the Execute step.
  172. 19:57These three steps, Fetch, Decode, and Execute areĀ  used to complete a single line of instructions
  173. 20:05and once it’s completed, these steps repeat butĀ  using the new value in the program counter. In
  174. 20:12essence Fetch, Decode, and Execute form a cycleĀ  so let’s run through it again. During Fetch,
  175. 20:20the controller uses the program counter’s value toĀ  fetch the corresponding instruction and places it
  176. 20:26in the CIR and the program counter increasesĀ  by 1. Next during Decode the instruction’s
  177. 20:34binary is fed into the instruction decoderĀ  where a complex set of logic gates generate
  178. 20:40the correct electrical control signals forĀ  that instruction. Finally, during Execute,
  179. 20:46the instruction is completed using the controlĀ  signals and timing signals, and in this case,
  180. 20:52the value in the accumulator is stored backĀ  into a memory address which, using the analogy,
  181. 20:59is like writing the value from the calculatorĀ  display into a data location in the book. Then
  182. 21:05the Fetch, Decode, Execute cycle repeats againĀ  using the next program counter’s value and so on.
  183. 21:13The Fetch Decode Execute Cycle is used in everyĀ  processor no matter whether it’s the 6502 in
  184. 21:20the Apple2e or the M1 in the MacBook Pro. But ofĀ  course there are many differences such as the size
  185. 21:28of the cache, the registers, or functions on theĀ  ALU calculator and much more. We’ll explore the
  186. 21:35exact differences in a few minutes, but forĀ  now, one important detail is that the Fetch
  187. 21:41Decode Execute cycle uses your computer’s clockĀ  to regulate its pace. The 6502 chip had a One
  188. 21:49Megahertz clock which ticked away at a millionĀ  times a second and thus each step in the Fetch,
  189. 21:56Decode, Execute cycle took a microsecond.Ā  Additionally the 6502 was an 8-bit processor
  190. 22:03meaning the size of the registers and the ALU’sĀ  input and output were 8-bits wide. On the other
  191. 22:10hand, the M1 chip is a 64-bit processor, so itĀ  can handle much larger numbers and it uses a 3.2
  192. 22:19Gigahertz clock and therefore each step takes aĀ  third of a nanosecond. Additionally, the M1 chip,
  193. 22:26along with all modern chips, uses a techniqueĀ  called pipelining where multiple instructions are
  194. 22:33queued up resulting in fetch, decode, and executeĀ  for different program counter values and different
  195. 22:40instructions being completed at the same time. There are many other optimizations in modern
  196. 22:46processors that we’ll soon discussĀ  but it’s important to understand
  197. 22:50that from the second you turn on your laptop,Ā  smartphone, gaming console, GPU or AI Server,
  198. 22:57to the second you shut it off, the processorĀ  is continuously cycling through Fetch, Decode,
  199. 23:04Execute over and over using programs filled withĀ  instructions and data along with the CPUs clock
  200. 23:12to regulate its pace. In essence this Fetch,Ā  Decode, Execute cycle is the common section
  201. 23:19of technological DNA that has powered everyĀ  single processor built over the past 50 years.
  202. 23:26This cycle of steps is incredibly powerful,Ā  capable of performing trillions to quadrillions
  203. 23:33of mathematical operations every second inĀ  a single chip. But you may be wondering,
  204. 23:40are there alternatives to the Fetch Decode ExecuteĀ  cycle? Well, there’s a world of different kinds
  205. 23:47of microchips, but specifically, alternativesĀ  include Application Specific Integrated Circuits
  206. 23:54or ASICs such as these microchips found in thisĀ  bitcoin mining computer, or Field Programmable
  207. 24:01Gate Arrays or FPGAs which are the main chipsĀ  in a number automotive computers and cameras.
  208. 24:09Both ASICs and FPGAs don’t use the fetch andĀ  decode steps, but rather they perform repetitive
  209. 24:16operations by flowing data through a set patternĀ  of logic gates and execution units, making
  210. 24:22them highly optimized, but very inflexible. AndĀ  then even further from these chips, are Quantum
  211. 24:29Computers which are based on Qubits and QuantumĀ  circuits which we’ll discuss in future videos.
  212. 24:35But, now that we’ve covered the Fetch, Decode,Ā  Execute cycle, it’s important to discuss two more
  213. 24:41steps which are Memory and Writeback. Memory isĀ  analogous to moving books from the SSD bookshelves
  214. 24:49onto the DRAM cart and then onto the table orĀ  Cache Memory, and Writeback is like writing data
  215. 24:56into the books, and when space for a new book isĀ  needed on the table, the old book is placed back
  216. 25:02on the DRAM cart and eventually returned to theĀ  bookshelves. These two steps use another special
  217. 25:09location called the memory address register andĀ  are critical to a functioning computer, but they
  218. 25:15typically take a lot longer to complete than theĀ  Fetch Decode Execute steps, and therefore in some
  219. 25:21architectures and textbooks they’re includedĀ  in the cycle and sometimes they aren’t. We’re
  220. 25:27working on a separate video on how data movesĀ  around these memory locations, so stay tuned.
  221. 25:34Now that we’ve uncovered the technologicalĀ  DNA inside all processors, it’s important
  222. 25:40to note that, similar to the DNA found in theĀ  nucleus of the cell and there being multiple
  223. 25:46layers of biological organization and structureĀ  for all living things, there are many layers of
  224. 25:52complexity or abstraction between the FetchĀ  Decode Execute cycle and a computer running
  225. 25:58a video game or browsing the internet. IfĀ  you want to dive into some of the other
  226. 26:03layers and understand more about how computersĀ  work, we recommend you check out Brilliant
  227. 26:09which is the sponsor of this video. BrilliantĀ  has a massive library of interactive courses
  228. 26:15that include subjects like calculus, scientificĀ  thinking, circuits, programming in python, logic,
  229. 26:23data analysis, and many more topics that wouldĀ  take far too long to list. However, Brilliant is
  230. 26:30much more than a list of courses, rather it’sĀ  as if your favorite teacher who makes classes
  231. 26:36engaging is combined with your favorite video gameĀ  and then mixed with the knowledge from countless
  232. 26:42textbooks. The result would be Brilliant. Their mission is to create a world of
  233. 26:48better problem solvers, and every one of theirĀ  courses focuses on critical thinking through
  234. 26:54interactive games and lessons. Furthermore,Ā  with technology progressing faster than ever,
  235. 27:00Brilliant continuously updates their lessonsĀ  to anticipate what you need to know for your
  236. 27:06education and career. For example, they have aĀ  new course on AI and Large Language Models that
  237. 27:13explains how Generative AI works far betterĀ  than any other textbook or video out there.
  238. 27:19Develop your knowledge by learning a little everyĀ  day. You can start today by signing up for free
  239. 27:25using the link: Brilliant.org/BranchEducation,Ā  or by scanning the QR code on screen,
  240. 27:33and you’ll then have access to the wide range ofĀ  courses throughout their catalog. If you enjoy
  241. 27:39their content and decide to stay, the link in theĀ  description below will also save you 20% off an
  242. 27:46annual premium subscription, which will give youĀ  unlimited daily access to everything on Brilliant.
  243. 27:54Ok, so let’s quickly run through slightlyĀ  more advanced topics to finish up this video.
  244. 28:01Earlier we mentioned that the MacBook Pro’s M1Ā  chip can complete 354 different instructions.
  245. 28:09This set of instructions is called ArmV8.4 andĀ  it’s categorized as a RISC architecture or Reduced
  246. 28:17Instruction Set Computer. For example, here’s aĀ  simple game of Snake using 145 lines of C++ code.
  247. 28:26It’s the job of a compiler, which is a separateĀ  piece of software, to take this code along with
  248. 28:32ArmV8.4’s 354 RISC instructions, and generateĀ  a list of 676 assembly instructions equivalent
  249. 28:42to the machine code instructions that wouldĀ  be found in a book or program named snake.app
  250. 28:48The other common architecture found in Intel andĀ  AMD chips is called CISC, or Complex Instruction
  251. 28:55Set Computer and is composed of thousands ofĀ  different possible instructions. For example,
  252. 29:02here’s the equivalent snake program thatĀ  is compiled to run on an Intel or AMD Chip
  253. 29:07using CISC and x86-64bit instructions, andĀ  you can see it’s only 560 instructions now.
  254. 29:17A few key differences between RISC and CISCĀ  are that each RISC instruction is relatively
  255. 29:23simple and is executed at a consistently fastĀ  execution rate. Additionally, RISC architectures
  256. 29:30are more energy efficient and thus used inĀ  all smartphones, whereas CISC architectures
  257. 29:36have thousands of different instructions andĀ  pack a lot more into a single instruction.
  258. 29:42Additionally, the CISC instructionĀ  decoder is much more complicated,
  259. 29:47and individual instructions have a variableĀ  execution rate sometimes taking multiple clock
  260. 29:53cycles to execute. There are many additionalĀ  pros and cons to RISC vs CISC which we’ll save
  261. 30:00for yet another video, but we thought it worthĀ  mentioning these simplified differences here.
  262. 30:07Computer architecture is incredibly complicatedĀ  with many different facets and layers of
  263. 30:13complexity and we have plans to make more videosĀ  that dive into each of these topics, but it’s
  264. 30:19important to note that each video we make takesĀ  close to a combined 1100 hours of researching,
  265. 30:26script writing, modeling, animating and editing.Ā  For example, we spent over 250 hours tearing down
  266. 30:35these non-working computers we bought from Ebay,Ā  and meticulously rebuilding each of the 3D models
  267. 30:42in Blender. So, if you could take a few seconds toĀ  like this video, subscribe if you haven’t already,
  268. 30:49share this video with someone who might beĀ  curious as to how CPUs work, and most importantly,
  269. 30:55write a quick comment below it would help us outĀ  immensely. Just a few seconds of your time helps
  270. 31:02us far more than you think. So, thank you. In the final section of this video we’ll
  271. 31:09discuss this diagram we showed earlier and theĀ  architecture of modern processors such as the
  272. 31:15M1. In contrast, the analogy we’ve laid outĀ  is rather simple, and you’re probably thinking
  273. 31:22that there must be more components in an actualĀ  CPU. In fact, this analogy is actually pretty
  274. 31:29close to what’s happening inside an Apple2eĀ  Computer. Specifically, the floppy drives,
  275. 31:35are the bookshelves, and then when we open upĀ  this computer we see the DRAM chips, which are
  276. 31:40the cart, and then going inside the 6502 processorĀ  we find an integrated circuit or die which has the
  277. 31:49corresponding sections that we’ll organize intoĀ  an internal architectural diagram. In this diagram
  278. 31:56you can see the instruction decoder, ALU, theĀ  Program Counter, Current Instruction Register,
  279. 32:03the other registers and a few other sections.Ā  Specifically, here’s where the program counter
  280. 32:09is used to fetch an instruction, and here’s whereĀ  the instructions and data from the DRAM chips
  281. 32:16are bussed in and out. Finally, here’s whereĀ  the instructions are decoded and the control
  282. 32:23signals are generated. One note is that there’sĀ  no cache in the 6502 because the DRAM chips in
  283. 32:30the 80s were just as fast as the instructions,Ā  so the table in the analogy is even smaller.
  284. 32:37As we said at the beginning of this video,Ā  the 6502 chip is made from 4528 transistors,
  285. 32:46so let’s see what an M1 chip with 16 billionĀ  transistors would look like. To start,
  286. 32:53we have to significantly increase the size ofĀ  this table. Next, we have to section off areas
  287. 32:59for each of the performance and energy efficientĀ  cores, the GPU, and other areas. When we focus on
  288. 33:07one of the performance cores we see the complexĀ  diagram from earlier, so let’s discuss how this
  289. 33:13diagram compares to our analogy. Specifically,Ā  there’s a separate set of 64 kilobyte data and
  290. 33:21instruction caches. As mentioned earlier there’sĀ  a pipeline to queue 8 instructions per clock cycle
  291. 33:28and additional sections like a branch predictorĀ  to reduce issues with conditional branching and
  292. 33:34help the pipeline run smoothly. Here you canĀ  see the pipelined instruction decoder, and 32
  293. 33:40general purpose registers. One key difference isĀ  that the calculator is broken up into 8 separate
  294. 33:46smaller calculators each handling a few functions.Ā  Additionally, there’s a special section for load
  295. 33:54and store instructions. This is the layout of justĀ  a single core out of the 8 and there are entirely
  296. 34:00different architectures in the Graphics ProcessingĀ  Unit as well as inside the Neural Processing Unit.
  297. 34:07One important note is that the inclusionĀ  of these 3 types of processors along with
  298. 34:12hardware accelerators such as the mediaĀ  engine makes this M1 chip closer to a
  299. 34:18system on a chip or SoC than a traditional CPU.Ā  Similarly, all the processors in these devices,
  300. 34:26including the CPU in your desktop computer canĀ  be considered SoCs and therefore the difference
  301. 34:32is more a marketing term than a technical one. On a separate note it’s important to mention
  302. 34:38that the M1 along with all modern processors areĀ  proprietary designs and knowledge, and therefore
  303. 34:44the diagrams we’ve shown are close approximationsĀ  that we built using input from industry experts.
  304. 34:52Let’s finally discuss our analogy in the termsĀ  of GPU chips found in graphics cards. We have
  305. 34:59a separate video covering how graphics cardsĀ  work, but with respect to this analogy, a GPU
  306. 35:05CUDA core is actually very similar in complexityĀ  to the architecture of the 6502. Therefore with
  307. 35:1310,000 to 20,000 CUDA cores in a single GPU chip,Ā  it’s like having a massive array of 6502 cores.
  308. 35:22The difference is that GPUs typically useĀ  32-bit ALU calculators and perform single
  309. 35:29instruction multiple thread or SIMT calculationsĀ  where a single instruction is fetched, decoded,
  310. 35:36and then distributed to a batch of cores, andĀ  then those cores execute that instruction using
  311. 35:42different addresses and data. However, there areĀ  many more nuances to SIMT and GPU architecture,
  312. 35:48so let’s wrap up this video on how CPUs work. We’re thankful to all our Patreon and YouTube
  313. 35:56Membership Sponsors for supporting our videos.Ā  If you want to financially support our work,
  314. 36:01you can find the links in the description below. This is Branch Education, and we create 3D
  315. 36:08animations that dive deeply into the technologyĀ  that drives our modern world. Watch another Branch
  316. 36:14video by clicking one of these cards or clickĀ  here to subscribe. Thanks for watching to the end!

About this transcript

This page contains the full transcript of The Engineering that Runs the Digital World šŸ› ļøāš™ļøšŸ’» How do CPUs Work? by Branch Education, generated from the public captions YouTube serves with the video. The transcript has 5,072 words across 316 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.