Registers¶
Registers… register something ? Who could guess ?
register_file¶
register_file.vhd
register_file module
Imports¶
Imports 2 elements
ieee std_logic_1164 numeric_std
Parameters¶
Parameters 2 elements
- • XLEN Type : INTEGER Default : 32
! @brief Configure the data width in the core.
- • REG_NB Type : INTEGER Default : 32
! @brief Configure the number of registers available. May be changed accordingly to configure for example the reduced instruction set.
Ports¶
Ports list 10 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clock |
Input |
! @brief clock enable from the core clock controller. Used to not create two clock domains from the master clock and the auxilliary clock. |
|
- |
Combinatorial |
- |
Fanout : 0 |
clock_en |
Input |
! @brief reset input, active low. When held to '0', the system will remain in the reset state until set to '1'. |
|
- |
Register clock |
- |
Fanout : 0 |
nRST |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
we |
Input |
! @brief Write address, as an integer. |
|
- |
Register clock |
- |
Fanout : 0 |
wa |
Input |
! @brief Write data, expressed as a vector of the same length as the the default value. |
|
Register clock |
- |
Fanout : 0 |
|
wd |
Input |
|
|
|
Register clock |
- |
Fanout : 0 |
ra1 |
Input |
! @brief Data for the first read port |
|
Combinatorial |
- |
Fanout : 0 |
|
rd1 |
Output |
! @brief Address for the second read port |
|
|
Combinatorial |
- |
Fanout : 1 |
ra2 |
Input |
! @brief Data for the second read port |
|
Combinatorial |
- |
Fanout : 0 |
|
rd2 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 1 |
Enums¶
Enum list 1 element
reg_array_t 0 values
! @brief Type definiton of the register array
Processes¶
Process list 1 element
• P1 Clocked Clocked by clock Reset by nRST
- -
Signals¶
Signals list 1 element
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
reg_array |
! @brief instantiation of the register array, to be used. |
|
- |
Register clock nRST |
Fanout : 0 |
Assignments¶
Instantiation templates¶
Instantiation templates 2 elements
register_file <name> #(
.XLEN ( 32),
.REG_NB ( 32)
)(
.clock (i_clock),
.clock_en (i_clock_en),
.nRST (i_nRST),
.we (i_we),
.wa (i_wa),
.wd (i_wd),
.ra1 (i_ra1),
.rd1 (i_rd1),
.ra2 (i_ra2),
.rd2 (i_rd2)
);
<name>: entity work.register_file
generic map (
XLEN => 32,
REG_NB => 32
)
port map (
clock => i_clock,
clock_en => i_clock_en,
nRST => i_nRST,
we => i_we,
wa => i_wa,
wd => i_wd,
ra1 => i_ra1,
rd1 => i_rd1,
ra2 => i_ra2,
rd2 => i_rd2
);
Source¶
Raw source Full file
--! @file src/core/core.vhd
--! @brief The base file that assemble all of the components of the core. Does not include any form of memory.
--! @author l.heywang <leonard.heywang@proton.me>
--! @date 05-10-2025
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
--!
ENTITY register_file IS
GENERIC (
--! @brief Configure the data width in the core.
XLEN : INTEGER := 32;
--! @brief Configure the number of registers available. May be changed accordingly to configure for example the reduced instruction set.
REG_NB : INTEGER := 32
);
PORT (
--------------------------------------------------------------------------------------------------------
-- Clocks & controls
--------------------------------------------------------------------------------------------------------
--! @brief clock input of the core. Must match the INPUT_FREQ generics within some tolerance.
clock : IN STD_LOGIC;
--! @brief clock enable from the core clock controller. Used to not create two clock domains from the master clock and the auxilliary clock.
clock_en : IN STD_LOGIC;
--! @brief reset input, active low. When held to '0', the system will remain in the reset state until set to '1'.
nRST : IN STD_LOGIC;
--------------------------------------------------------------------------------------------------------
-- Writing port
--------------------------------------------------------------------------------------------------------
--! @brief Write enable pin. Active high. Set to '1' to enable any write operation on the register file.
we : IN STD_LOGIC;
--! @brief Write address, as an integer.
wa : IN INTEGER RANGE 0 TO REG_NB - 1;
--! @brief Write data, expressed as a vector of the same length as the the default value.
wd : IN STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0);
--------------------------------------------------------------------------------------------------------
-- Reading ports
--------------------------------------------------------------------------------------------------------
--! @brief Address for the first read port
ra1 : IN INTEGER RANGE 0 TO REG_NB - 1;
--! @brief Data for the first read port
rd1 : OUT STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0);
--! @brief Address for the second read port
ra2 : IN INTEGER RANGE 0 TO REG_NB - 1;
--! @brief Data for the second read port
rd2 : OUT STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0)
);
END ENTITY;
ARCHITECTURE rtl OF register_file IS
--! @brief Type definiton of the register array
TYPE reg_array_t IS ARRAY (0 TO REG_NB - 1) OF STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0);
--! @brief instantiation of the register array, to be used.
SIGNAL reg_array : reg_array_t := (OTHERS => (OTHERS => '0'));
BEGIN
--========================================================================================
--! @brief P1 handle all of the write parts (since reading are done asynchronously).
--! @details
--! On each authorized rising edges, if we need to write (WE = '1') and the write
--! address is not 0 (as per the spec, this register could not be written),
--! update the register file.
--! On reset, the register file is initialized to 0x00000000 for all registers.
--========================================================================================
P1 : PROCESS (clock, nRST)
BEGIN
IF nRST = '0' THEN
reg_array <= (OTHERS => (OTHERS => '0'));
ELSIF rising_edge(clock) AND (clock_en = '1') THEN
IF (we = '1') AND (wa /= 0) THEN
reg_array(wa) <= wd;
END IF;
END IF;
END PROCESS;
-- asynchronous reads (combinational muxes)
rd1 <= (OTHERS => '0') WHEN ra1 = 0 ELSE
reg_array(ra1);
rd2 <= (OTHERS => '0') WHEN ra2 = 0 ELSE
reg_array(ra2);
END ARCHITECTURE;
register_file_tb¶
register_file_tb.vhd
register_file_tb testbench
Imports¶
Imports 2 elements
ieee std_logic_1164 numeric_std
Parameters¶
Parameters 2 elements
- • XLEN Type : INTEGER Default : 32
-
- • REG_NB Type : INTEGER Default : 32
-
Signals¶
Signals list 9 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
clock |
DUT ports |
|
- |
Combinatorial |
Fanout : 0 |
nRST |
|
|
- |
Combinatorial |
Fanout : 0 |
we |
|
|
- |
Combinatorial |
Fanout : 0 |
wa |
|
|
Combinatorial |
Fanout : 0 |
|
wd |
|
|
|
Combinatorial |
Fanout : 0 |
ra1 |
|
|
Combinatorial |
Fanout : 0 |
|
rd1 |
|
|
|
Combinatorial |
Fanout : 0 |
ra2 |
|
|
Combinatorial |
Fanout : 0 |
|
rd2 |
|
|
|
Combinatorial |
Fanout : 0 |
Modules¶
Processes¶
Process list 1 element
• Process 1
Source¶
Raw source Full file
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY register_file_tb IS
END ENTITY;
ARCHITECTURE sim OF register_file_tb IS
CONSTANT XLEN : INTEGER := 32;
CONSTANT REG_NB : INTEGER := 32;
-- DUT ports
SIGNAL clock : STD_LOGIC := '0';
SIGNAL nRST : STD_LOGIC := '0';
SIGNAL we : STD_LOGIC := '0';
SIGNAL wa : INTEGER RANGE 0 TO REG_NB - 1 := 0;
SIGNAL wd : STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0) := (OTHERS => '0');
SIGNAL ra1 : INTEGER RANGE 0 TO REG_NB - 1 := 0;
SIGNAL rd1 : STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0);
SIGNAL ra2 : INTEGER RANGE 0 TO REG_NB - 1 := 0;
SIGNAL rd2 : STD_LOGIC_VECTOR(XLEN - 1 DOWNTO 0);
BEGIN
-----------------------------------------------------------------------
-- DUT instance
-----------------------------------------------------------------------
UUT : ENTITY work.register_file(rtl)
GENERIC MAP(
XLEN => XLEN,
REG_NB => REG_NB
)
PORT MAP(
clock => clock,
nRST => nRST,
we => we,
wa => wa,
wd => wd,
ra1 => ra1,
rd1 => rd1,
ra2 => ra2,
rd2 => rd2
);
-----------------------------------------------------------------------
-- clock generation (10 ns period)
-----------------------------------------------------------------------
clock <= NOT clock AFTER 5 ns;
-----------------------------------------------------------------------
-- stimulus
-----------------------------------------------------------------------
PROCESS
BEGIN
-- hold reset
nRST <= '0';
WAIT FOR 20 ns;
nRST <= '1';
WAIT FOR 10 ns;
-- write some values
FOR i IN 1 TO 5 LOOP
wa <= i;
wd <= STD_LOGIC_VECTOR(to_unsigned(i * 16#10#, XLEN));
we <= '1';
WAIT UNTIL rising_edge(clock);
END LOOP;
we <= '0';
-- read them back
FOR i IN 0 TO 5 LOOP
ra1 <= i;
ra2 <= (i + 1) MOD REG_NB;
WAIT FOR 10 ns;
REPORT "ra1=" & INTEGER'image(i) &
" rd1=" & INTEGER'image(to_integer(unsigned(rd1))) &
" | ra2=" & INTEGER'image((i + 1) MOD REG_NB) &
" rd2=" & INTEGER'image(to_integer(unsigned(rd2)));
END LOOP;
WAIT;
END PROCESS;
END ARCHITECTURE;