YouTube2Text

[CS61C FA20] Lecture 26.1 - Caches III: Direct Mapped Example — Transcript

by CS 61C Departmental · 2,938 words · 454 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back halfway point let's do
  2. 0:03this
  3. 0:04let's see a real example where we talk
  4. 0:06about a direct map
  5. 0:08cache and poke at it with requests and
  6. 0:10have some hits
  7. 0:11and some misses and misses with block
  8. 0:13replacement and understand the valid bit
  9. 0:14and actually put it all together with an
  10. 0:16example
  11. 0:16it often doesn't ground itself until
  12. 0:18this lecture hope with this lecture
  13. 0:20feel free to watch you know watch this
  14. 0:21at half speed you'll get this
  15. 0:23so this is an example of a direct
  16. 0:26mapped cache let's do this okay
  17. 0:31boy guess what same problem i had before
  18. 0:3416 kibi bytes of data we should
  19. 0:37that was the last lecture we ended with
  20. 0:38that picture forward blocks again
  21. 0:41see the same thing we're going to work
  22. 0:43out the height with an area we did this
  23. 0:44already we already worked out those bits
  24. 0:45in the last problem
  25. 0:46i'm going to re read four addresses 14
  26. 0:50in hex 14 1c 34 and 80
  27. 0:5314. what happens that's what i'm going
  28. 0:56to do
  29. 0:56and now you'll see how to do every
  30. 0:58single thing we'll break it all up we'll
  31. 0:59do this for you
  32. 1:00and here's the memory values by the way
  33. 1:01just to let you know we're going to put
  34. 1:03some values
  35. 1:03you know whatever a is these are word
  36. 1:06wide okay these are words here we're
  37. 1:08talking about
  38. 1:08so a is some value of words not this
  39. 1:11doesn't mean
  40. 1:12a the hex value a means that lowercase a
  41. 1:15means
  42. 1:15some value of uh that's that we're going
  43. 1:18to label a
  44. 1:19and again a through d is the lower side
  45. 1:21and then in the 30s here in terms of the
  46. 1:23address it's e through h
  47. 1:25and in the 80 kind of 8 000 e range
  48. 1:29it's going to be i j k and l okay here
  49. 1:32to see why we choose those values
  50. 1:33in a second here we go here's my four
  51. 1:36values
  52. 1:3714 34 1 c 80 14. write out the 32 bits
  53. 1:42draw your columns where's your t where's
  54. 1:44your i
  55. 1:45where's your o how much is it we talked
  56. 1:47about before there's
  57. 1:4814 bits for my cache four bits are my
  58. 1:52offset
  59. 1:53that's one of 16 different bytes
  60. 1:5710 bits for my index that's one of a
  61. 1:59thousand twenty four different rows
  62. 2:01different blocks so where here here's my
  63. 2:04ten
  64. 2:05here's my four then how many is here in
  65. 2:08my tag well if it's 32-bit wide
  66. 2:10r you know risk 5 32 this is 14
  67. 2:13that must be an 18 bit okay
  68. 2:17tag so we kind of know that from before
  69. 2:20and by the way notice by the way here
  70. 2:21look the tags are all this is all zeros
  71. 2:23that's a zero that's a zero that's a
  72. 2:25zero that's a two
  73. 2:26so let's remember that for the future i
  74. 2:28have kind of the other if i'm if the
  75. 2:30range is in the eighties my tag's not
  76. 2:31going to be zero the other guys on the
  77. 2:33low side of memory
  78. 2:34this is on the higher side of memory um
  79. 2:37my indices are look okay that's like
  80. 2:38that's a row that's row one that's where
  81. 2:40one that's row three that's right so
  82. 2:42already kind of seeing this i'm gonna be
  83. 2:43poking at this in row one and row three
  84. 2:45and these are the different columns i'm
  85. 2:47getting that's a four
  86. 2:48that's a 12 that's a 4. okay that's a 4.
  87. 2:51by the way what why is what do i know
  88. 2:54about this
  89. 2:55all these are zeros i'm probably reading
  90. 2:57words here if i'm reading words
  91. 2:59if you remember the picture i showed you
  92. 3:00a second ago i think i watch
  93. 3:02these were word-wise this is four bytes
  94. 3:05wide
  95. 3:06so if i'm only reading load words you
  96. 3:08know i'm going to be word aligned in my
  97. 3:09memory accesses
  98. 3:10which is why all these guys are zeros
  99. 3:14that's pretty cool okay so all this
  100. 3:16starts to make sense once you play it up
  101. 3:18with it
  102. 3:19here's my picture beautiful there's my
  103. 3:21valve i need a valid bit
  104. 3:22what do i reset my valid for yes they're
  105. 3:24all zero
  106. 3:26what temperature here we go what's my
  107. 3:27temperature my cash freezing cold
  108. 3:30empty nothing there valid bid's telling
  109. 3:32me nobody's ever
  110. 3:33visited this guy before it is it is
  111. 3:35literally it's got that it's got the new
  112. 3:36cash smell i just
  113. 3:38cracked it open tennis you're gonna open
  114. 3:40like a tennis
  115. 3:41i have one here i'm pulling this out you
  116. 3:42ever open this guy
  117. 3:44open the thing new tennis ball smell
  118. 3:47okay that's a little weird but i usually
  119. 3:49do that when i open my tennis ball bags
  120. 3:50i got right got my new cash smell here
  121. 3:52okay give me here we go ready
  122. 3:54having some fun i'm just trying to make
  123. 3:55this fun for you guys all right
  124. 3:58let's do it we got four reads to do
  125. 4:00remember no rights here i'm just doing
  126. 4:01reads and it's simple direct map is the
  127. 4:03simplest kind of cache
  128. 4:04still this complexity to it but this is
  129. 4:05the simplest kind of cache without
  130. 4:07before we add more layers to complexity
  131. 4:09i'm reading memory address 14. i break
  132. 4:12it up what do i got
  133. 4:14i got a zero i got a one i got a four
  134. 4:17and by the way just so you know just so
  135. 4:19you know
  136. 4:21because i have four bits here in my
  137. 4:22offset this
  138. 4:24hexadecimal nibble is my offset
  139. 4:28instantly and this because i have this
  140. 4:31is 10 i think
  141. 4:32i said 10 bits right 1000 rows well 10
  142. 4:35bits is
  143. 4:36is kind of like well it's like this and
  144. 4:38then like
  145. 4:39half of that so just in the future if i
  146. 4:42i can almost read directly
  147. 4:44what my index is by reading
  148. 4:47kind of eight to ten bits here which are
  149. 4:50the lower two hex digits
  150. 4:52nibbles lower two hex nibbles and then
  151. 4:54half of the other ones so
  152. 4:56let's just give it a little taste of
  153. 4:57that okay so what happens
  154. 5:00i first got to figure out what row i'm
  155. 5:02in this is why we always start with i i
  156. 5:03think i mentioned last lecture or two
  157. 5:05lectures ago
  158. 5:05we start with my i what row am i in i
  159. 5:08look at my index i'm in row one
  160. 5:12before i tell you what's gonna happen
  161. 5:13see if you can predict what what the
  162. 5:14algorithm should be doing
  163. 5:15what does it do next can you can you
  164. 5:17figure it out
  165. 5:19you're right i look at the valid bit how
  166. 5:21we gotta check that first
  167. 5:22i don't okay this way this would be a
  168. 5:24great question on an exam i like that
  169. 5:26is the next thing you do if you look at
  170. 5:27the index the tag no if the valid
  171. 5:30is wrong if the valid is not wrong zero
  172. 5:32that tag could be garbage and
  173. 5:33might actually match my tag taking me
  174. 5:36down a path of code that i want to be
  175. 5:37that's the wrong thing to do
  176. 5:39check your tag first check your check
  177. 5:41let's go back
  178. 5:42check your valid bit first i have to do
  179. 5:44this check your valid bit first
  180. 5:46when it's zero it's not valid so
  181. 5:49cash miss had to do it just how to do
  182. 5:51this we're going to call it we're going
  183. 5:52to learn that this is called a
  184. 5:53compulsory miss
  185. 5:54i don't want to teach you that word i'll
  186. 5:55teach you that word a moment but it's
  187. 5:56like i got to take the miss when i got a
  188. 5:58when i was a zero valid bit
  189. 5:59i got nothing to do but a miss there's
  190. 6:01no way that i can have a hit there
  191. 6:03so i load the data in well how much when
  192. 6:06you're going to sacramento you might as
  193. 6:07well get some more stuff
  194. 6:09folks what kind of what kind of uh
  195. 6:11locality we're working with here
  196. 6:12temporal or spatial both
  197. 6:16it's a cache i'm remembering the guy i
  198. 6:18just visited that's the temporal part
  199. 6:20and i didn't just load a bite i loaded
  200. 6:21the bite and a word i should not little
  201. 6:24bite and it's neighbors a word
  202. 6:25and their neighbors three more words so
  203. 6:29there is some spatial locality i'm
  204. 6:31trying to exploit here with this
  205. 6:33wider block size okay
  206. 6:37i set my notice this oh i've got to set
  207. 6:39my valid bit don't forget to do that by
  208. 6:40the way if you're implementing a cache
  209. 6:41ever in hardware you forget to set your
  210. 6:43valid bid
  211. 6:43you'll never have any hits because it'll
  212. 6:45always be you'd always think it's cold
  213. 6:46when it's actually warming up
  214. 6:48so make sure you set your valid bit and
  215. 6:50what's last what's the next thing you do
  216. 6:53you got to return something it's a load
  217. 6:54word who you're returning well
  218. 6:56this value of 4 says look up here and
  219. 7:00grab
  220. 7:01the b and i return b okay
  221. 7:04this is these are bytes zero through
  222. 7:06three or that a
  223. 7:08a encompasses this whole thing is this
  224. 7:10is i always draw these dotted lines
  225. 7:12this is four bytes in here or a word if
  226. 7:15if i'm loading a word i'm going to load
  227. 7:16either this word or that word it's got
  228. 7:19to be
  229. 7:19it's got to be word aligned so i'm
  230. 7:21loading b because
  231. 7:22i i kind of ignore in a way i kind of
  232. 7:25ignore those bits because i'm learning
  233. 7:26words
  234. 7:27i ignore those bits that tells me the
  235. 7:30number
  236. 7:30starting from zero of the word i'm
  237. 7:32grabbing if it's all zeros it's a if
  238. 7:34it's zero one it's b
  239. 7:35so in a way you can actually look at
  240. 7:37this and if i'm loading words i ignore
  241. 7:39those lower bits
  242. 7:40just fyi so i return b so i had i got a
  243. 7:44cache miss
  244. 7:45loaded the block up and return to b
  245. 7:48that's the first request i got three
  246. 7:50more let's do it read
  247. 7:52one c okay what do i do again this is
  248. 7:55going to seem very boring once you've
  249. 7:56done a couple of these but for now
  250. 7:58let's go slowly well divide 1c up
  251. 8:02into the bits what's my tag zero what's
  252. 8:04my index
  253. 8:05one what's my offset 12. okay so think
  254. 8:09about that
  255. 8:10as we move forward here i check
  256. 8:13i go to my i take the index i take the
  257. 8:15little orange label and say
  258. 8:17go to my index always the i first it's i
  259. 8:19t o
  260. 8:20it's actually i process check my end
  261. 8:21actually i v t o really
  262. 8:23ooh ivto is the new mnemonic i need a
  263. 8:26new mnemonic for ivto
  264. 8:27index okay got that row
  265. 8:30v for valid then i tag
  266. 8:34hey the tag matches this means i read
  267. 8:37this
  268. 8:37block i read somebody from this block
  269. 8:39recently and
  270. 8:41nobody else in no other color did i read
  271. 8:43since that one
  272. 8:44i don't know how long it's been there it
  273. 8:46might be really dusty in cobwebs but
  274. 8:48i've read anybody else
  275. 8:49since i read that one so that's pretty
  276. 8:51cool um tag matches
  277. 8:54next thing as you know i v t the t is
  278. 8:57there
  279. 8:57and the o check your offset offsets goes
  280. 9:00go grab c
  281. 9:01and go grab the last word in that block
  282. 9:04and there's your d
  283. 9:05return your d so we return to b and a d
  284. 9:08we're doing pretty well
  285. 9:09we had one miss and we got a hit i love
  286. 9:12the caches
  287. 9:12already we're saving our time i didn't
  288. 9:14have to go to sacramento because when
  289. 9:15you went to sacramento you brought your
  290. 9:17neighbors i brought a b c d you only
  291. 9:18wanted b last time but i brought abcd
  292. 9:20guess what
  293. 9:21now i wanted d i love this this is just
  294. 9:23great
  295. 9:25all right here we go this is going to be
  296. 9:26trouble now 34
  297. 9:28okay let's try it so first thing divide
  298. 9:30the bits up
  299. 9:31and i already can see there's some
  300. 9:32problem is that my index is a three
  301. 9:35i've never visited three before so
  302. 9:37that's the same situation we can go
  303. 9:38faster
  304. 9:38i've never i've never seen this before
  305. 9:40it's not valid
  306. 9:42i load no valid data i load the guy in
  307. 9:45uh load the cache block set valid
  308. 9:48look at my offset return my f and i move
  309. 9:51on
  310. 9:52so we've said we've kind of seen that
  311. 9:53case before we did the first one
  312. 9:55here we go there's excited 80 14. here
  313. 9:59we go
  314. 9:59let's try it okay oh 80 14. that looks
  315. 10:02like
  316. 10:03this looks like a whole different a
  317. 10:04cache number i can tell that because the
  318. 10:07tag is different
  319. 10:08that tag is my cache number so we first
  320. 10:11go
  321. 10:11check my index ivto index is the second
  322. 10:14row or
  323. 10:15index number one
  324. 10:18how's my valid check data's valid so
  325. 10:21that's the second part v
  326. 10:23t check my tags tags don't match
  327. 10:28and these are only reads for now so this
  328. 10:30is a copy and because i'm only reading
  329. 10:32never writing i can just throw this away
  330. 10:34that's the key thing we're going to get
  331. 10:35this mor
  332. 10:36when i reveal the hood reveal the
  333. 10:38simplicity
  334. 10:39we're in a little rubber room for now
  335. 10:41once i make these rights
  336. 10:43well what if i've had this right and
  337. 10:44it's not the same as memory what do i do
  338. 10:46there can i throw it i can't throw it
  339. 10:47away because that's the most recent data
  340. 10:48is in the cache not
  341. 10:49all those the complexities we're not
  342. 10:50even talking about now so for now i just
  343. 10:53throw that away i got to throw that away
  344. 10:54it's a cache miss block replacement i
  345. 10:57got to load in
  346. 10:58whatever that block is whatever those 16
  347. 11:00bits were those four words
  348. 11:02from memory and replace abcd if you
  349. 11:04remember that before it is
  350. 11:06ijkl i've got an offset and again
  351. 11:10set my update the tag too don't forget
  352. 11:12by the way yeah make sure to update the
  353. 11:13tag just update the valid make sure to
  354. 11:15update the tag with if there's a new tag
  355. 11:16put your new tag there otherwise that'll
  356. 11:18be all wrong that would be really bad if
  357. 11:19you didn't up your
  358. 11:20date your tag um it would think it's the
  359. 11:22wrong place and that would be really
  360. 11:23inconsistent
  361. 11:24and now go to my offset ivto what's the
  362. 11:27last guy o
  363. 11:28offset is four grab my j return j that's
  364. 11:31not bad that is not bad for
  365. 11:35four things okay here we go now okay
  366. 11:37this is one of those cases almost like a
  367. 11:39clicker peer instruction question
  368. 11:43what if i gave you and the value of
  369. 11:45values could be a b c d e up to j k
  370. 11:47l before 30 okay
  371. 11:51and i'm going to ask you what if you
  372. 11:52read a 1c so i
  373. 11:54really encourage you very strongly to
  374. 11:57pause it right now
  375. 11:58pause the video try to do a read of 30
  376. 12:01i've added address at 30 and read it
  377. 12:03address 1c
  378. 12:05and we'll come back in a second
  379. 12:09and welcome back say hi i paused
  380. 12:11pretending like i was i pause here we go
  381. 12:13all right 30. we need to do it to get
  382. 12:15together here we go watch
  383. 12:16i'm not even gonna i'm gonna stay on
  384. 12:18this page i'm not even gonna need any
  385. 12:19help there's nothing on this page i'm
  386. 12:21doing it
  387. 12:22okay dan said okay dan said i-v-t-o
  388. 12:25i-v-t-o i there's my three
  389. 12:28so i go here my three v
  390. 12:32valid yes t
  391. 12:36that's a zero is that the same as that
  392. 12:38one
  393. 12:39yes oh
  394. 12:42oh i think i return e
  395. 12:46i'm feeling pretty good so this guy was
  396. 12:49return
  397. 12:50e okay
  398. 12:53how about nothing nothing i don't change
  399. 12:54anything i actually don't update at all
  400. 12:56just return e
  401. 12:57cash hit best possible case 1c
  402. 13:01divide it up ivto
  403. 13:05index one go back here so we go to my
  404. 13:09one
  405. 13:10v valid yep valid
  406. 13:13tag zero oh man
  407. 13:18what's the tag there are they the same
  408. 13:21that's not so good i'm not just saying
  409. 13:24so
  410. 13:24cash miss block replacement i got to
  411. 13:28swap it out
  412. 13:29do you remember what was in that first
  413. 13:30guy i believe it was a b c d
  414. 13:32so then i go here and
  415. 13:36by the way this was before i think i
  416. 13:37asked this before maybe i did i don't
  417. 13:39know
  418. 13:40uh i i want a
  419. 13:44i want to ask and i think it's going to
  420. 13:46be there this is going to be cross it
  421. 13:48off
  422. 13:49a cross it off b cross it off c
  423. 13:53cross it off d cross this off
  424. 13:57write the zero there and you wanted
  425. 14:00the 12 and that is i'm counting by this
  426. 14:03guy you wanted the 0 1 2
  427. 14:053 the last one and i think you return a
  428. 14:07d
  429. 14:08let's see how we did so i think what did
  430. 14:10i say i think we returned
  431. 14:12an e and a d i think that's what we did
  432. 14:15let's try it
  433. 14:17okay what we get
  434. 14:21i return an e return to d there's my
  435. 14:24values e and d
  436. 14:26huh what's the thing and they're perfect
  437. 14:28and then
  438. 14:31that's it that's not too hard that's not
  439. 14:33too hard if
  440. 14:34only there were a cache simulator that
  441. 14:37existed out there in the real world i
  442. 14:38could just play with
  443. 14:40and explore oh i wish it's just too bad
  444. 14:42that no one
  445. 14:43has written a simulator of a
  446. 14:46cache to ma'am well i guess i guess i
  447. 14:49guess
  448. 14:50that one doesn't exist out there it's
  449. 14:51just too bad that we don't have a cache
  450. 14:52simulator
  451. 14:53oh well and on a sad note no cash
  452. 14:55emitter out there
  453. 14:56as far as i know
  454. 15:00see the next lecture

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 26.1 - Caches III: Direct Mapped Example by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,938 words across 454 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.