| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| library ieee; |
| use ieee.std_logic_1164.all; |
| use ieee.numeric_std.all; |
|
|
| library work; |
| use work.utils.all; |
| use work.common.all; |
| use work.decode_types.all; |
| use work.wishbone_types.all; |
|
|
| |
|
|
| entity icache is |
| generic ( |
| SIM : boolean := false; |
| HAS_FPU : boolean := true; |
| |
| LINE_SIZE : positive := 64; |
| |
| |
| |
| |
| |
| ROW_SIZE : positive := wishbone_data_bits / 8; |
| |
| NUM_LINES : positive := 32; |
| |
| NUM_WAYS : positive := 4; |
| |
| LOG_LENGTH : natural := 0 |
| ); |
| port ( |
| clk : in std_ulogic; |
| rst : in std_ulogic; |
|
|
| i_in : in Fetch1ToIcacheType; |
| i_out : out IcacheToDecode1Type; |
|
|
| stall_in : in std_ulogic; |
| stall_out : out std_ulogic; |
| flush_in : in std_ulogic; |
| inval_in : in std_ulogic; |
|
|
| wishbone_out : out wishbone_master_out; |
| wishbone_in : in wishbone_slave_out; |
|
|
| wb_snoop_in : in wishbone_master_out := wishbone_master_out_init; |
|
|
| events : out IcacheEventType; |
| log_out : out std_ulogic_vector(57 downto 0) |
| ); |
| end entity icache; |
|
|
| architecture rtl of icache is |
| constant ROW_SIZE_BITS : natural := ROW_SIZE*8; |
| |
| constant ROW_PER_LINE : natural := LINE_SIZE / ROW_SIZE; |
| |
| |
| constant BRAM_ROWS : natural := NUM_LINES * ROW_PER_LINE; |
| |
| constant INSN_PER_ROW : natural := ROW_SIZE_BITS / 32; |
| |
|
|
| |
| constant INSN_BITS : natural := log2(INSN_PER_ROW); |
| |
| constant ROW_BITS : natural := log2(BRAM_ROWS); |
| |
| constant ROW_LINEBITS : natural := log2(ROW_PER_LINE); |
| |
| constant LINE_OFF_BITS : natural := log2(LINE_SIZE); |
| |
| constant ROW_OFF_BITS : natural := log2(ROW_SIZE); |
| |
| constant INDEX_BITS : natural := log2(NUM_LINES); |
| |
| constant SET_SIZE_BITS : natural := LINE_OFF_BITS + INDEX_BITS; |
| |
| |
| constant TAG_BITS : natural := REAL_ADDR_BITS - SET_SIZE_BITS + 1; |
| |
| |
| constant WAY_BITS : natural := maximum(log2(NUM_WAYS), 1); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| subtype row_t is unsigned(ROW_BITS-1 downto 0); |
| subtype index_t is integer range 0 to NUM_LINES-1; |
| subtype index_sig_t is unsigned(INDEX_BITS-1 downto 0); |
| subtype way_t is integer range 0 to NUM_WAYS-1; |
| subtype way_sig_t is unsigned(WAY_BITS-1 downto 0); |
| subtype row_in_line_t is unsigned(ROW_LINEBITS-1 downto 0); |
|
|
| |
| |
| |
| |
| |
| |
| |
| constant PREDECODE_BITS : natural := 10; |
| constant INSN_IMAGE_BITS : natural := 26; |
| constant ICWORDLEN : natural := PREDECODE_BITS + INSN_IMAGE_BITS; |
| constant ROW_WIDTH : natural := INSN_PER_ROW * ICWORDLEN; |
|
|
| |
| subtype cache_row_t is std_ulogic_vector(ROW_WIDTH-1 downto 0); |
|
|
| |
| subtype cache_tag_t is std_logic_vector(TAG_BITS-1 downto 0); |
| type cache_tags_set_t is array(way_t) of cache_tag_t; |
| type cache_tags_array_t is array(index_t) of cache_tag_t; |
|
|
| |
| signal cache_tags_set : cache_tags_set_t; |
| |
| signal snoop_tags_set : cache_tags_set_t; |
| |
| signal tag_overwrite : std_ulogic_vector(NUM_WAYS - 1 downto 0); |
|
|
| |
| subtype cache_way_valids_t is std_ulogic_vector(NUM_WAYS-1 downto 0); |
| type cache_valids_t is array(index_t) of cache_way_valids_t; |
| type row_per_line_valid_t is array(0 to ROW_PER_LINE - 1) of std_ulogic; |
| signal cache_valids : cache_valids_t; |
|
|
| |
| type state_t is (IDLE, STOP_RELOAD, CLR_TAG, WAIT_ACK); |
|
|
| type reg_internal_t is record |
| |
| hit_way : way_sig_t; |
| hit_nia : std_ulogic_vector(63 downto 0); |
| hit_ra : real_addr_t; |
| hit_smark : std_ulogic; |
| hit_valid : std_ulogic; |
| big_endian: std_ulogic; |
| predicted : std_ulogic; |
| pred_ntaken: std_ulogic; |
|
|
| |
| state : state_t; |
| wb : wishbone_master_out; |
| store_way : way_sig_t; |
| store_index : index_sig_t; |
| recv_row : row_t; |
| recv_valid : std_ulogic; |
| store_row : row_t; |
| store_tag : cache_tag_t; |
| store_valid : std_ulogic; |
| end_row_ix : row_in_line_t; |
| rows_valid : row_per_line_valid_t; |
|
|
| stalled_hit : std_ulogic; |
| stalled_way : way_sig_t; |
|
|
| |
| fetch_failed : std_ulogic; |
| end record; |
|
|
| signal r : reg_internal_t; |
|
|
| signal ev : IcacheEventType; |
|
|
| |
| signal req_index : index_sig_t; |
| signal req_row : row_t; |
| signal req_hit_way : way_sig_t; |
| signal req_tag : cache_tag_t; |
| signal req_is_hit : std_ulogic; |
| signal req_is_miss : std_ulogic; |
| signal req_raddr : real_addr_t; |
|
|
| signal real_addr : real_addr_t; |
|
|
| |
| type cache_ram_out_t is array(way_t) of cache_row_t; |
| signal cache_out : cache_ram_out_t; |
| signal cache_wr_data : std_ulogic_vector(ROW_WIDTH - 1 downto 0); |
| signal wb_rd_data : std_ulogic_vector(ROW_SIZE_BITS - 1 downto 0); |
|
|
| |
| signal plru_victim : way_sig_t; |
|
|
| |
| signal snoop_valid : std_ulogic; |
| signal snoop_index : index_sig_t; |
| signal snoop_tag : cache_tag_t; |
| signal snoop_index2 : index_sig_t; |
| signal snoop_hits : cache_way_valids_t; |
|
|
| signal log_insn : std_ulogic_vector(35 downto 0); |
|
|
| |
| function get_index(addr: real_addr_t) return index_sig_t is |
| begin |
| return unsigned(addr(SET_SIZE_BITS - 1 downto LINE_OFF_BITS)); |
| end; |
|
|
| |
| function get_row(addr: std_ulogic_vector) return row_t is |
| begin |
| return unsigned(addr(SET_SIZE_BITS - 1 downto ROW_OFF_BITS)); |
| end; |
|
|
| |
| function get_row_of_line(row: row_t) return row_in_line_t is |
| begin |
| return row(ROW_LINEBITS-1 downto 0); |
| end; |
|
|
| |
| function is_last_row_wb_addr(wb_addr: wishbone_addr_type; last: row_in_line_t) return boolean is |
| begin |
| return unsigned(wb_addr(LINE_OFF_BITS - ROW_OFF_BITS - 1 downto 0)) = last; |
| end; |
|
|
| |
| function is_last_row(row: row_t; last: row_in_line_t) return boolean is |
| begin |
| return get_row_of_line(row) = last; |
| end; |
|
|
| |
| function next_row_wb_addr(wb_addr: wishbone_addr_type) |
| return std_ulogic_vector is |
| variable row_idx : std_ulogic_vector(ROW_LINEBITS-1 downto 0); |
| variable result : wishbone_addr_type; |
| begin |
| |
| row_idx := wb_addr(ROW_LINEBITS - 1 downto 0); |
| row_idx := std_ulogic_vector(unsigned(row_idx) + 1); |
| result := wb_addr; |
| result(ROW_LINEBITS - 1 downto 0) := row_idx; |
| return result; |
| end; |
|
|
| |
| |
| |
| |
| function next_row(row: row_t) return row_t is |
| variable row_v : std_ulogic_vector(ROW_BITS-1 downto 0); |
| variable row_idx : unsigned(ROW_LINEBITS-1 downto 0); |
| variable result : std_ulogic_vector(ROW_BITS-1 downto 0); |
| begin |
| row_v := std_ulogic_vector(row); |
| row_idx := row(ROW_LINEBITS-1 downto 0); |
| row_v(ROW_LINEBITS-1 downto 0) := std_ulogic_vector(row_idx + 1); |
| return unsigned(row_v); |
| end; |
|
|
| |
| function read_insn_word(addr: std_ulogic_vector(63 downto 0); |
| data: cache_row_t) return std_ulogic_vector is |
| variable word: integer range 0 to INSN_PER_ROW-1; |
| begin |
| assert not is_X(addr) severity failure; |
| word := to_integer(unsigned(addr(INSN_BITS+2-1 downto 2))); |
| return data(word * ICWORDLEN + ICWORDLEN - 1 downto word * ICWORDLEN); |
| end; |
|
|
| |
| function get_tag(addr: real_addr_t; endian: std_ulogic) return cache_tag_t is |
| begin |
| return endian & addr(addr'left downto SET_SIZE_BITS); |
| end; |
|
|
| begin |
|
|
| |
| process(all) |
| variable j: integer; |
| begin |
| if r.store_tag(TAG_BITS - 1) = '0' then |
| wb_rd_data <= wishbone_in.dat; |
| else |
| for ii in 0 to (wishbone_in.dat'length / 8) - 1 loop |
| j := ((ii / 4) * 4) + (3 - (ii mod 4)); |
| wb_rd_data(ii * 8 + 7 downto ii * 8) <= wishbone_in.dat(j * 8 + 7 downto j * 8); |
| end loop; |
| end if; |
| end process; |
|
|
| predecoder_0: entity work.predecoder |
| generic map ( |
| HAS_FPU => HAS_FPU, |
| WIDTH => INSN_PER_ROW, |
| ICODE_LEN => PREDECODE_BITS, |
| IMAGE_LEN => INSN_IMAGE_BITS |
| ) |
| port map ( |
| clk => clk, |
| valid_in => wishbone_in.ack, |
| insns_in => wb_rd_data, |
| icodes_out => cache_wr_data |
| ); |
|
|
| assert LINE_SIZE mod ROW_SIZE = 0; |
| assert ispow2(LINE_SIZE) report "LINE_SIZE not power of 2" severity FAILURE; |
| assert ispow2(NUM_LINES) report "NUM_LINES not power of 2" severity FAILURE; |
| assert ispow2(ROW_PER_LINE) report "ROW_PER_LINE not power of 2" severity FAILURE; |
| assert ispow2(INSN_PER_ROW) report "INSN_PER_ROW not power of 2" severity FAILURE; |
| assert (ROW_BITS = INDEX_BITS + ROW_LINEBITS) |
| report "geometry bits don't add up" severity FAILURE; |
| assert (LINE_OFF_BITS = ROW_OFF_BITS + ROW_LINEBITS) |
| report "geometry bits don't add up" severity FAILURE; |
| assert (REAL_ADDR_BITS + 1 = TAG_BITS + INDEX_BITS + LINE_OFF_BITS) |
| report "geometry bits don't add up" severity FAILURE; |
| assert (REAL_ADDR_BITS + 1 = TAG_BITS + ROW_BITS + ROW_OFF_BITS) |
| report "geometry bits don't add up" severity FAILURE; |
|
|
| sim_debug: if SIM generate |
| debug: process |
| begin |
| report "ROW_SIZE = " & natural'image(ROW_SIZE); |
| report "ROW_PER_LINE = " & natural'image(ROW_PER_LINE); |
| report "BRAM_ROWS = " & natural'image(BRAM_ROWS); |
| report "INSN_PER_ROW = " & natural'image(INSN_PER_ROW); |
| report "INSN_BITS = " & natural'image(INSN_BITS); |
| report "ROW_BITS = " & natural'image(ROW_BITS); |
| report "ROW_LINEBITS = " & natural'image(ROW_LINEBITS); |
| report "LINE_OFF_BITS = " & natural'image(LINE_OFF_BITS); |
| report "ROW_OFF_BITS = " & natural'image(ROW_OFF_BITS); |
| report "INDEX_BITS = " & natural'image(INDEX_BITS); |
| report "TAG_BITS = " & natural'image(TAG_BITS); |
| report "WAY_BITS = " & natural'image(WAY_BITS); |
| wait; |
| end process; |
| end generate; |
|
|
| |
| rams: for i in 0 to NUM_WAYS-1 generate |
| signal do_read : std_ulogic; |
| signal do_write : std_ulogic; |
| signal rd_addr : std_ulogic_vector(ROW_BITS-1 downto 0); |
| signal wr_addr : std_ulogic_vector(ROW_BITS-1 downto 0); |
| signal dout : cache_row_t; |
| signal wr_sel : std_ulogic_vector(0 downto 0); |
| signal ic_tags : cache_tags_array_t; |
| begin |
| |
| way: entity work.cache_ram |
| generic map ( |
| ROW_BITS => ROW_BITS, |
| WIDTH => ROW_WIDTH, |
| BYTEWID => ROW_WIDTH |
| ) |
| port map ( |
| clk => clk, |
| rd_en => do_read, |
| rd_addr => rd_addr, |
| rd_data => dout, |
| wr_sel => wr_sel, |
| wr_addr => wr_addr, |
| wr_data => cache_wr_data |
| ); |
| process(all) |
| begin |
| do_read <= not stall_in; |
| do_write <= '0'; |
| if r.recv_valid = '1' and r.store_way = to_unsigned(i, WAY_BITS) then |
| do_write <= '1'; |
| end if; |
| cache_out(i) <= dout; |
| rd_addr <= std_ulogic_vector(req_row); |
| wr_addr <= std_ulogic_vector(r.store_row); |
| wr_sel(0) <= do_write; |
| end process; |
|
|
| |
| |
| |
| process(clk) |
| variable replace_way : way_sig_t; |
| variable snoop_addr : real_addr_t; |
| variable next_raddr : real_addr_t; |
| begin |
| if rising_edge(clk) then |
| replace_way := to_unsigned(0, WAY_BITS); |
| if NUM_WAYS > 1 then |
| |
| replace_way := plru_victim; |
| end if; |
| |
| if flush_in = '1' or i_in.req = '0' or (stall_in = '0' and stall_out = '0') then |
| next_raddr := i_in.next_rpn & i_in.next_nia(MIN_LG_PGSZ - 1 downto 0); |
| cache_tags_set(i) <= ic_tags(to_integer(get_index(next_raddr))); |
| |
| tag_overwrite(i) <= '0'; |
| if r.state = CLR_TAG and r.store_index = get_index(next_raddr) and |
| to_unsigned(i, WAY_BITS) = replace_way then |
| tag_overwrite(i) <= '1'; |
| end if; |
| end if; |
|
|
| |
| if (wb_snoop_in.cyc and wb_snoop_in.stb and wb_snoop_in.we) = '1' then |
| snoop_addr := addr_to_real(wb_to_addr(wb_snoop_in.adr)); |
| snoop_tags_set(i) <= ic_tags(to_integer(get_index(snoop_addr))); |
| end if; |
|
|
| |
| if r.state = CLR_TAG and to_unsigned(i, WAY_BITS) = replace_way then |
| ic_tags(to_integer(r.store_index)) <= r.store_tag; |
| end if; |
|
|
| if rst = '1' then |
| tag_overwrite(i) <= '0'; |
| end if; |
| end if; |
| end process; |
| end generate; |
| |
| |
| maybe_plrus: if NUM_WAYS > 1 generate |
| type plru_array is array(index_t) of std_ulogic_vector(NUM_WAYS - 2 downto 0); |
| signal plru_ram : plru_array; |
| signal plru_cur : std_ulogic_vector(NUM_WAYS - 2 downto 0); |
| signal plru_upd : std_ulogic_vector(NUM_WAYS - 2 downto 0); |
| signal plru_acc : std_ulogic_vector(WAY_BITS-1 downto 0); |
| signal plru_out : std_ulogic_vector(WAY_BITS-1 downto 0); |
| begin |
| plru : entity work.plrufn |
| generic map ( |
| BITS => WAY_BITS |
| ) |
| port map ( |
| acc => plru_acc, |
| tree_in => plru_cur, |
| tree_out => plru_upd, |
| lru => plru_out |
| ); |
|
|
| process(all) |
| begin |
| |
| if is_X(r.hit_ra) then |
| plru_cur <= (others => 'X'); |
| else |
| plru_cur <= plru_ram(to_integer(get_index(r.hit_ra))); |
| end if; |
|
|
| |
| plru_acc <= std_ulogic_vector(r.hit_way); |
| plru_victim <= unsigned(plru_out); |
| end process; |
|
|
| |
| process(clk) |
| begin |
| if rising_edge(clk) then |
| if r.hit_valid = '1' then |
| assert not is_X(r.hit_ra) severity failure; |
| plru_ram(to_integer(get_index(r.hit_ra))) <= plru_upd; |
| end if; |
| end if; |
| end process; |
| end generate; |
|
|
| |
| icache_comb : process(all) |
| variable is_hit : std_ulogic; |
| variable hit_way : way_sig_t; |
| variable insn : std_ulogic_vector(ICWORDLEN - 1 downto 0); |
| variable icode : insn_code; |
| variable ra : real_addr_t; |
| begin |
| |
| ra := i_in.rpn & i_in.nia(MIN_LG_PGSZ - 1 downto 0); |
| real_addr <= ra; |
| req_index <= get_index(ra); |
| req_row <= get_row(ra); |
| req_tag <= get_tag(ra, i_in.big_endian); |
|
|
| |
| |
| |
| req_raddr <= ra(REAL_ADDR_BITS - 1 downto ROW_OFF_BITS) & |
| (ROW_OFF_BITS-1 downto 0 => '0'); |
|
|
| |
| hit_way := to_unsigned(0, WAY_BITS); |
| is_hit := '0'; |
| if i_in.req = '1' then |
| assert not is_X(req_index) and not is_X(req_row) severity failure; |
| end if; |
| for i in way_t loop |
| if i_in.req = '1' and |
| cache_valids(to_integer(req_index))(i) = '1' and |
| tag_overwrite(i) = '0' and |
| cache_tags_set(i) = req_tag then |
| hit_way := to_unsigned(i, WAY_BITS); |
| is_hit := '1'; |
| end if; |
| end loop; |
| if r.state = WAIT_ACK and r.store_valid = '1' and |
| req_index = r.store_index and |
| req_tag = r.store_tag and |
| r.rows_valid(to_integer(req_row(ROW_LINEBITS-1 downto 0))) = '1' then |
| is_hit := '1'; |
| hit_way := r.store_way; |
| end if; |
| if r.stalled_hit = '1' then |
| is_hit := '1'; |
| hit_way := r.stalled_way; |
| end if; |
|
|
| |
| if i_in.req = '1' and flush_in = '0' and rst = '0' then |
| req_is_hit <= is_hit; |
| req_is_miss <= not is_hit; |
| else |
| req_is_hit <= '0'; |
| req_is_miss <= '0'; |
| end if; |
| req_hit_way <= hit_way; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| icode := INSN_illegal; |
| if is_X(r.hit_way) then |
| insn := (others => 'X'); |
| else |
| insn := read_insn_word(r.hit_nia, cache_out(to_integer(r.hit_way))); |
| end if; |
| assert not (r.hit_valid = '1' and is_X(r.hit_way)) severity failure; |
| |
| |
| if is_X(insn) then |
| insn := (others => '0'); |
| elsif insn(ICWORDLEN - 1) = '0' then |
| icode := insn_code'val(to_integer(unsigned(insn(ICWORDLEN-1 downto INSN_IMAGE_BITS)))); |
| insn(31 downto 26) := recode_primary_opcode(icode); |
| end if; |
|
|
| i_out.insn <= insn(31 downto 0); |
| i_out.icode <= icode; |
| log_insn <= insn; |
| i_out.valid <= r.hit_valid; |
| i_out.nia <= r.hit_nia; |
| i_out.stop_mark <= r.hit_smark; |
| i_out.fetch_failed <= r.fetch_failed; |
| i_out.big_endian <= r.big_endian; |
| i_out.next_predicted <= r.predicted; |
| i_out.next_pred_ntaken <= r.pred_ntaken; |
|
|
| |
| stall_out <= i_in.req and not is_hit and not flush_in; |
|
|
| |
| wishbone_out <= r.wb; |
| end process; |
|
|
| |
| icache_hit : process(clk) |
| begin |
| if rising_edge(clk) then |
| |
| |
| if rst = '1' or flush_in = '1' then |
| r.hit_valid <= '0'; |
| r.stalled_hit <= '0'; |
| r.stalled_way <= to_unsigned(0, WAY_BITS); |
| r.fetch_failed <= '0'; |
| elsif stall_in = '1' then |
| if r.state = CLR_TAG then |
| r.stalled_hit <= '0'; |
| elsif req_is_hit = '1' then |
| |
| r.stalled_hit <= '1'; |
| r.stalled_way <= req_hit_way; |
| end if; |
| else |
| |
| |
| |
| r.hit_valid <= req_is_hit; |
| if req_is_hit = '1' then |
| r.hit_way <= req_hit_way; |
| |
| assert not is_X(i_in.nia) report "metavalue in NIA" severity FAILURE; |
|
|
| report "cache hit nia:" & to_hstring(i_in.nia) & |
| " IR:" & std_ulogic'image(i_in.virt_mode) & |
| " SM:" & std_ulogic'image(i_in.stop_mark) & |
| " idx:" & to_hstring(req_index) & |
| " tag:" & to_hstring(req_tag) & |
| " way:" & to_hstring(req_hit_way) & |
| " RA:" & to_hstring(real_addr); |
| end if; |
| r.stalled_hit <= '0'; |
| end if; |
| if stall_in = '0' then |
| |
| r.hit_smark <= i_in.stop_mark; |
| r.hit_nia <= i_in.nia; |
| r.hit_ra <= real_addr; |
| r.big_endian <= i_in.big_endian; |
| r.predicted <= i_in.predicted; |
| r.pred_ntaken <= i_in.pred_ntaken; |
| r.fetch_failed <= i_in.fetch_fail and not flush_in; |
| end if; |
| if i_out.valid = '1' then |
| assert not is_X(i_out.insn) severity failure; |
| end if; |
| end if; |
| end process; |
|
|
| |
| icache_miss : process(clk) |
| variable tagset : cache_tags_set_t; |
| variable tag : cache_tag_t; |
| variable snoop_addr : real_addr_t; |
| variable snoop_cache_tags : cache_tags_set_t; |
| variable replace_way : way_sig_t; |
| begin |
| if rising_edge(clk) then |
| ev.icache_miss <= '0'; |
| ev.itlb_miss_resolved <= '0'; |
| r.recv_valid <= '0'; |
| |
| if rst = '1' then |
| for i in index_t loop |
| cache_valids(i) <= (others => '0'); |
| end loop; |
| r.state <= IDLE; |
| r.wb.cyc <= '0'; |
| r.wb.stb <= '0'; |
|
|
| |
| r.wb.dat <= (others => '0'); |
| r.wb.sel <= "11111111"; |
| r.wb.we <= '0'; |
|
|
| |
| r.wb.adr <= (others => '0'); |
|
|
| snoop_valid <= '0'; |
| snoop_index <= to_unsigned(0, INDEX_BITS); |
| snoop_hits <= (others => '0'); |
| else |
| |
| |
| snoop_valid <= wb_snoop_in.cyc and wb_snoop_in.stb and wb_snoop_in.we; |
| snoop_addr := addr_to_real(wb_to_addr(wb_snoop_in.adr)); |
| snoop_index <= get_index(snoop_addr); |
| snoop_tag <= get_tag(snoop_addr, '0'); |
| snoop_hits <= (others => '0'); |
|
|
| |
| |
| if snoop_valid = '1' then |
| for i in way_t loop |
| tag := snoop_tags_set(i); |
| |
| tag(TAG_BITS - 1) := '0'; |
| if tag = snoop_tag then |
| snoop_hits(i) <= '1'; |
| end if; |
| end loop; |
| end if; |
| snoop_index2 <= snoop_index; |
|
|
| |
| if inval_in = '1' then |
| for i in index_t loop |
| cache_valids(i) <= (others => '0'); |
| end loop; |
| r.store_valid <= '0'; |
| else |
| |
| |
| for i in way_t loop |
| if snoop_hits(i) = '1' then |
| assert not is_X(snoop_index2) severity failure; |
| cache_valids(to_integer(snoop_index2))(i) <= '0'; |
| end if; |
| end loop; |
| end if; |
|
|
| |
| case r.state is |
| when IDLE => |
| |
| for i in 0 to ROW_PER_LINE - 1 loop |
| r.rows_valid(i) <= '0'; |
| end loop; |
|
|
| |
| if req_is_miss = '1' then |
| report "cache miss nia:" & to_hstring(i_in.nia) & |
| " IR:" & std_ulogic'image(i_in.virt_mode) & |
| " SM:" & std_ulogic'image(i_in.stop_mark) & |
| " idx:" & to_hstring(req_index) & |
| " tag:" & to_hstring(req_tag) & |
| " RA:" & to_hstring(real_addr); |
| ev.icache_miss <= '1'; |
|
|
| |
| r.store_index <= req_index; |
| r.recv_row <= get_row(req_raddr); |
| r.store_row <= get_row(req_raddr); |
| r.store_tag <= req_tag; |
| r.store_valid <= '1'; |
| r.end_row_ix <= get_row_of_line(get_row(req_raddr)) - 1; |
|
|
| |
| |
| |
| r.wb.adr <= addr_to_wb(req_raddr); |
| r.wb.cyc <= '1'; |
| r.wb.stb <= '1'; |
|
|
| |
| r.state <= CLR_TAG; |
| end if; |
|
|
| when CLR_TAG | WAIT_ACK => |
| assert not is_X(r.store_index) severity failure; |
| assert not is_X(r.store_row) severity failure; |
| assert not is_X(r.recv_row) severity failure; |
| if r.state = CLR_TAG then |
| replace_way := to_unsigned(0, WAY_BITS); |
| if NUM_WAYS > 1 then |
| |
| replace_way := plru_victim; |
| end if; |
| r.store_way <= replace_way; |
|
|
| |
| assert not is_X(replace_way) severity failure; |
| cache_valids(to_integer(r.store_index))(to_integer(replace_way)) <= '0'; |
|
|
| r.state <= WAIT_ACK; |
| end if; |
|
|
| |
| if r.recv_valid = '1' then |
| r.rows_valid(to_integer(r.store_row(ROW_LINEBITS-1 downto 0))) <= not inval_in; |
| if is_last_row(r.store_row, r.end_row_ix) then |
| |
| cache_valids(to_integer(r.store_index))(to_integer(r.store_way)) <= |
| r.store_valid and not inval_in; |
| |
| r.state <= IDLE; |
| end if; |
| |
| r.store_row <= r.recv_row; |
| end if; |
|
|
| |
| if wishbone_in.stall = '0' and r.wb.stb = '1' then |
| |
| |
| if is_last_row_wb_addr(r.wb.adr, r.end_row_ix) then |
| r.wb.stb <= '0'; |
| end if; |
|
|
| |
| r.wb.adr <= next_row_wb_addr(r.wb.adr); |
| end if; |
|
|
| |
| if inval_in = '1' then |
| r.wb.stb <= '0'; |
| r.state <= STOP_RELOAD; |
| end if; |
|
|
| |
| if wishbone_in.ack = '1' then |
| |
| if is_last_row(r.recv_row, r.end_row_ix) then |
| |
| r.wb.cyc <= '0'; |
| end if; |
| r.recv_valid <= '1'; |
|
|
| |
| r.recv_row <= next_row(r.recv_row); |
| end if; |
|
|
| when STOP_RELOAD => |
| |
| |
| if get_row_of_line(r.recv_row) = get_row_of_line(get_row(wb_to_addr(r.wb.adr))) then |
| r.wb.cyc <= '0'; |
| r.state <= IDLE; |
| end if; |
| if wishbone_in.ack = '1' then |
| |
| r.recv_row <= next_row(r.recv_row); |
| end if; |
| end case; |
| end if; |
| end if; |
| end process; |
|
|
| icache_log: if LOG_LENGTH > 0 generate |
| |
| signal log_data : std_ulogic_vector(57 downto 0); |
| begin |
| data_log: process(clk) |
| variable lway: way_sig_t; |
| variable wstate: std_ulogic; |
| begin |
| if rising_edge(clk) then |
| lway := req_hit_way; |
| wstate := '0'; |
| if r.state /= IDLE then |
| wstate := '1'; |
| end if; |
| log_data <= i_out.valid & |
| log_insn & |
| wishbone_in.ack & |
| r.wb.adr(2 downto 0) & |
| r.wb.stb & r.wb.cyc & |
| wishbone_in.stall & |
| stall_out & |
| r.fetch_failed & |
| r.hit_nia(5 downto 2) & |
| wstate & |
| std_ulogic_vector(resize(lway, 3)) & |
| req_is_hit & req_is_miss & |
| '1' & |
| '1'; |
| end if; |
| end process; |
| log_out <= log_data; |
| end generate; |
|
|
| events <= ev; |
|
|
| end; |
|
|