# Cache ## 觀念 * Cache Size: C = S x E x B data bytes S = 2s sets E = 2e lines per set B = sb bytes per cache block (data) ![](https://hackmd.io/_uploads/SJXSiimMa.png =500x) ## 計算 ![](https://hackmd.io/_uploads/rJ75dcmzp.png) ![](https://hackmd.io/_uploads/SJXSiimMa.png =300x) Cache Size: C = S x E x B data bytes 已知: * L1D-Cache 8 way x6 * Cache Size = 32KBytes * 1 line = 64byte = 8word x 64bit作業系統 * disk = 1TB 計算: 32KBytes = sets x <font color=red>64B line</font> x <font color=red>8 way</font> Cache Size / line Size = blocks 32KB / 64B = <font color=red>512b blocks</font> 512b blocks / 8 way = <font color=red>64b sets</font> Disk = 1TB 2^10 x 2^10 x 2^10 x 2^10 = 2^40B -> <font color=red>全部40bit</font> | 全部 | tag | index | line offset | | -------- | -------- | -------- | -------- | | 40bit | ? | <font color=red>sets</font> 64=2^6 -> <font color=red>6bit</font> | <font color=red>line size</font> 64=2^6 -> <font color=red>6bit</font>| tag -> 40 - 6 - 6 = <font color=red>28</font> | vaild | tag | the data = line offset | | -------- | -------- | -------- | | 2b | 28b | 6Bx8=512b | 2 + 28 + 512 = 542b <font color=red>A: L1D-Cache = 542b x 512b blocks x 8快取數量</font>