OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_cpu_regfile.vhd] - Diff between revs 73 and 74

Show entire file | Details | Blame | View Log

Rev 73 Rev 74
Line 73... Line 73...
  -- register file --
  -- register file --
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
  type   reg_file_t is array (31 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
  type   reg_file_emb_t is array (15 downto 0) of std_ulogic_vector(data_width_c-1 downto 0);
  signal reg_file     : reg_file_t;
  signal reg_file     : reg_file_t;
  signal reg_file_emb : reg_file_emb_t;
  signal reg_file_emb : reg_file_emb_t;
 
 
 
  -- access --
  signal rf_wdata     : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
  signal rf_wdata     : std_ulogic_vector(data_width_c-1 downto 0); -- actual write-back data
  signal rd_is_x0     : std_ulogic; -- writing to x0?
  signal rd_zero  : std_ulogic; -- writing to x0?
  signal opa_addr     : std_ulogic_vector(4 downto 0); -- rs1/dst address
  signal opa_addr     : std_ulogic_vector(4 downto 0); -- rs1/dst address
  signal opb_addr     : std_ulogic_vector(4 downto 0); -- rs2 address
  signal opb_addr     : std_ulogic_vector(4 downto 0); -- rs2 address
 
 
begin
begin
 
 
  -- Data Input Mux -------------------------------------------------------------------------
  -- Data Input Mux -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  input_mux: process(rd_is_x0, ctrl_i, alu_i, mem_i, csr_i, pc2_i)
  input_mux: process(rd_zero, ctrl_i, alu_i, mem_i, csr_i, pc2_i)
  begin
  begin
    if (rd_is_x0 = '1') then -- write zero if accessing x0 to "emulate" it is hardwired to zero
    if (rd_zero = '1') then -- write zero if accessing x0 to "emulate" it is hardwired to zero
      rf_wdata <= (others => '0'); -- TODO: FIXME! but how???
      rf_wdata <= (others => '0'); -- TODO: FIXME! but how???
    else
    else
      case ctrl_i(ctrl_rf_mux1_c downto ctrl_rf_mux0_c) is
      case ctrl_i(ctrl_rf_mux1_c downto ctrl_rf_mux0_c) is
        when rf_mux_alu_c => rf_wdata <= alu_i; -- ALU result
        when rf_mux_alu_c => rf_wdata <= alu_i; -- ALU result
        when rf_mux_mem_c => rf_wdata <= mem_i; -- memory read data
        when rf_mux_mem_c => rf_wdata <= mem_i; -- memory read data
Line 97... Line 99...
        when others       => rf_wdata <= alu_i;
        when others       => rf_wdata <= alu_i;
      end case;
      end case;
    end if;
    end if;
  end process input_mux;
  end process input_mux;
 
 
 
  -- writing to x0? --
 
  rd_zero <= '1' when (ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) = "00000") else '0';
 
 
 
 
  -- Register File Access -------------------------------------------------------------------
  -- Register File Access -------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  reg_file_rv32i: -- normal register file with 32 registers
  reg_file_rv32i: -- normal register file with 32 registers
  if (CPU_EXTENSION_RISCV_E = false) generate
  if (CPU_EXTENSION_RISCV_E = false) generate
Line 112... Line 117...
        end if;
        end if;
        rs1_o <= reg_file(to_integer(unsigned(opa_addr(4 downto 0))));
        rs1_o <= reg_file(to_integer(unsigned(opa_addr(4 downto 0))));
        rs2_o <= reg_file(to_integer(unsigned(opb_addr(4 downto 0))));
        rs2_o <= reg_file(to_integer(unsigned(opb_addr(4 downto 0))));
      end if;
      end if;
    end process rf_access;
    end process rf_access;
 
 
    -- writing to x0? --
 
    rd_is_x0 <= not or_reduce_f(ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c));
 
  end generate;
  end generate;
 
 
  reg_file_rv32e: -- embedded register file with 16 registers
  reg_file_rv32e: -- embedded register file with 16 registers
  if (CPU_EXTENSION_RISCV_E = true) generate
  if (CPU_EXTENSION_RISCV_E = true) generate
    rf_access: process(clk_i)
    rf_access: process(clk_i)
Line 129... Line 131...
        end if;
        end if;
        rs1_o <= reg_file_emb(to_integer(unsigned(opa_addr(3 downto 0))));
        rs1_o <= reg_file_emb(to_integer(unsigned(opa_addr(3 downto 0))));
        rs2_o <= reg_file_emb(to_integer(unsigned(opb_addr(3 downto 0))));
        rs2_o <= reg_file_emb(to_integer(unsigned(opb_addr(3 downto 0))));
      end if;
      end if;
    end process rf_access;
    end process rf_access;
 
 
    -- writing to x0? --
 
    rd_is_x0 <= not or_reduce_f(ctrl_i(ctrl_rf_rd_adr3_c downto ctrl_rf_rd_adr0_c));
 
  end generate;
  end generate;
 
 
  -- access addresses --
  -- access addresses --
  opa_addr <= ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) when (ctrl_i(ctrl_rf_wb_en_c) = '1') else
  opa_addr <= ctrl_i(ctrl_rf_rd_adr4_c downto ctrl_rf_rd_adr0_c) when (ctrl_i(ctrl_rf_wb_en_c) = '1') else
              ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c); -- rd/rs1
              ctrl_i(ctrl_rf_rs1_adr4_c downto ctrl_rf_rs1_adr0_c); -- rd/rs1

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.