logo资料库

2017计算机组成原理自主实验第四章Cache的实现报告.docx

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
[键入公司名称] 计算机组成原理实验报告 4.2Cache 的实现 班级:1536101 2017/5/7 [在此处键入文档的摘要。摘要通常是对文档内容的简短总结。在此处键入文档的摘要。 摘要通常是对文档内容的简短总结。]
一、实验要求 在实现2114存储芯片的基础上,按照P112,图4.50 实现cache 的基本功能,其中替换 机构和地址映射的方式可以自定。 二、实验原理 P112,图 4.50 Cache 基本结构: 三、实验设计 其中多向均为数组实现 映射方式:全相联映射 替换策略:滚动替换 Cache 中内存块 主存:64*64 Cache:4*64 其中 data 数据设置(16 downto 0) 两条数据线控制 Cache 块地址 四条数据线 2^4 作为标记位 四条数据线控制块内地址 设置 cs 为片选标记,we 为‘0’时,写有效,为‘1’时读有效;写入数据时,采用写直达 方式,同时将数据存入内存(SRAM 模拟内存)和 Cache,如果此时 Cache 数据已满(4 个 数据块中均有数据)则存入最后一块,并且之前的后三块数据一次前移,进行数据滚动。读 数据时,先进行判断,如果所需要数据存在于 Cache 中,直接调用,否则,将所需数据从内 存中调出,并存入 Cache。 四、设计步骤 1.首先完成 2114 的实现
2.在 2114 基础上加如 Cache 的实现 3.实现 Cache 与内存的初始化 4.(片选有效时)判断读写操作 (1)写操作 Cache 中未满的时候,直接将数据同时写入内存和 Cache 中 Cache 中已经写满,替换 Cache 中最后一块 (2)读操作 判断所需要的数据是否在 Cache 中,是则直接提出,否,则从内存中取出,并且替 换 Cache 最后一位 五、代码情况 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; tutorial is entity port( address:in std_logic_vector(9 downto 0); we:in std_logic; cs:in std_logic; data:in std_logic_vector(16 downto 0); readflag : out writeflag: out STD_LOGIC; data_out:out std_logic_vector(16 downto 0) ); STD_LOGIC; end tutorial; architecture Behavioral of tutorial is subtype byte is std_logic_vector(16 downto 0); subtype ram_range is integer range 0 to 1023; type Kmemory is array (ram_range) of byte; signal sram:Kmemory; --4 位 -- 1 K --1 K x 4 位
signal n :integer range 0 to 1023; TYPE memoryTYPE IS ARRAY(63 downto 0) OF std_logic_vector(16 downto 0); signal memory :memoryTYPE; TYPE pieceType IS ARRAY(3 downto 0) OF STD_LOGIC_VECTOR(16 downto 0); TYPE cacheRecord IS RECORD piece:pieceType; flag:STD_LOGIC_VECTOR(1 downto 0); end record; TYPE cacheType IS ARRAY(3 downto 0) OF cacheRecord; SIGNAL cache: cacheTYPE; signal operatex:STD_LOGIC; signal flag1: STD_LOGIC; signal flag2: STD_LOGIC; begin n <= conv_integer(address); process(operatex) begin if(flag2='1')then readflag<='0'; else readflag<='1'; end if; end process; process(cs,we,data,n) begin if (cs = '0') then if (we= '0') then memory(CONV_INTEGER(address))<=dina; --片选有效 --写有效 if(cache(CONV_INTEGER(address(3 downto 2))).flag=address(5 downto 4))then cache(CONV_INTEGER(address(3 2))).piece(CONV_INTEGER(address(1 downto 0)))<=dina; writeflag<='1'; downto
sram(n) <= data; end if; end if; 4))then if (we='1') then if(cache(CONV_INTEGER(address(3 downto 2))).flag=address(5 downto --读有效 data_out<=cache(CONV_INTEGER(address (3 downto 2))).piece(CONV_INTEGER(address (1 downto 0))); flag1<='1'; data_out <= sram(n); readflag <= '1'; else flag2<='1'; cache(CONV_INTEGER(address(3 downto 2))).flag<=address(5 downto 4); 2))).piece(0)<=memory(conv_integer(address(5 downto 2))*4); cache(CONV_INTEGER(address cache(CONV_INTEGER(address 2))).piece(1)<=memory(conv_integer(address(5 downto 2))*4+1); cache(CONV_INTEGER(address 2))).piece(2)<=memory(conv_integer(address(5 downto 2))*4+2); cache(CONV_INTEGER(address 2))).piece(3)<=memory(conv_integer(address(5 downto 2))*4+3); (3 (3 (3 (3 downto downto downto downto end if; end if; else data_out <= "ZZZZ"; flag1<='0'; flag2<='0'; end if; end process; end Behavioral; 六、仿真结论
七、实验总结 高速缓存存储器(Cache),是计算机组成中很重要的组成部件之一,它协调了 CPU 运 算速度和主存读取速度,使计算机的性能得到了飞跃性的提升。为避免程序的空等现象,提 升 Cache 的命中率迫在眉睫。Cache 可以大幅提高访存速度。
分享到:
收藏