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