-
Notifications
You must be signed in to change notification settings - Fork 0
/
regfile.vhd
87 lines (70 loc) · 2.38 KB
/
regfile.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-------------------------------------------------------
--! @regfile.vhd
--! @brief Descrição do RegFile do PoliLeg
--! @author Tiago M Lucio ([email protected])
--! @date 2022-06-12
-------------------------------------------------------
library ieee;
use ieee.numeric_bit.all;
entity d_register is
generic (
width : natural := 64;
reset_value : natural := 0
);
port (
clock, reset, load : in bit;
d : in bit_vector(width - 1 downto 0);
q : out bit_vector(width - 1 downto 0)
);
end entity d_register;
architecture arch of d_register is
begin
procD: process(clock, reset, load)
begin
if (reset = '1') then q <= bit_vector(to_unsigned(reset_value, width)); -- assíncrono
elsif (load = '1' and rising_edge(clock)) then q <= d; -- borda de subida do clock
end if;
end process procD;
end arch ; -- arch
library ieee;
use ieee.numeric_bit.all;
use ieee.math_real.all;
entity regfile is
generic (
reg_n: natural := 10;
word_s: natural := 64
);
port (
clock: in bit;
reset: in bit;
regWrite: in bit;
rr1, rr2, wr: in bit_vector(natural(ceil(log2(real(reg_n)))) - 1 downto 0);
d: in bit_vector(word_s - 1 downto 0);
q1, q2: out bit_vector(word_s - 1 downto 0)
);
end entity regfile;
architecture arch of regfile is
component d_register is
generic (
width : natural := 64;
reset_value : natural := 0
);
port (
clock, reset, load : in bit;
d : in bit_vector(width - 1 downto 0);
q : out bit_vector(width - 1 downto 0)
);
end component;
type BitVectorArray is array (natural range <>) of bit_vector(word_s - 1 downto 0);
signal load: bit_vector(reg_n - 1 downto 0);
signal q: BitVectorArray(0 to reg_n);
begin
regs : for i in 0 to reg_n-2 generate
load(i) <= '1' when (i = unsigned(wr)) and regWrite = '1' else
'0';
reg_i: d_register generic map (word_s) port map(clock, reset, load(i), d, q(i));
end generate ; -- regs
q(reg_n-1) <= (others => '0');
q1 <= q(to_integer(unsigned(rr1)));
q2 <= q(to_integer(unsigned(rr2)));
end arch ; -- arch