Skip to content

Commit 0576d0c

Browse files
Merge pull request #12 from pulp-platform/ff-regfile
Added FF-based register file.
2 parents 877d676 + 01a68c2 commit 0576d0c

File tree

5 files changed

+130
-21
lines changed

5 files changed

+130
-21
lines changed

Bender.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sources:
1717
- rtl/hwpe_ctrl_interfaces.sv
1818
- rtl/hwpe_ctrl_package.sv
1919
# Level 1
20+
- rtl/hwpe_ctrl_regfile_ff.sv
2021
- rtl/hwpe_ctrl_regfile_latch.sv
2122
- rtl/hwpe_ctrl_seq_mult.sv
2223
- rtl/hwpe_ctrl_uloop.sv

rtl/hwpe_ctrl_regfile.sv

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
module hwpe_ctrl_regfile
1818
import hwpe_ctrl_package::*;
1919
#(
20+
parameter int unsigned REGFILE_SCM = 1,
2021
parameter int unsigned N_CONTEXT = REGFILE_N_CONTEXT,
2122
parameter int unsigned ID_WIDTH = 16,
2223
parameter int unsigned N_IO_REGS = 2,
@@ -101,9 +102,10 @@ module hwpe_ctrl_regfile
101102
logic [N_CONTEXT-1:0] wren_cxt;
102103

103104
hwpe_ctrl_regfile_latch_test_wrap #(
104-
.ADDR_WIDTH(SCM_ADDR_WIDTH),
105-
.DATA_WIDTH(32)
106-
) i_regfile_latch (
105+
.REGFILE_SCM ( REGFILE_SCM ),
106+
.ADDR_WIDTH ( SCM_ADDR_WIDTH ),
107+
.DATA_WIDTH ( 32 )
108+
) i_regfile (
107109
.clk ( clk_i ),
108110
.rst_n ( rst_ni ),
109111
.clear ( clear_i | r_clear_first_startup ),

rtl/hwpe_ctrl_regfile_ff.sv

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* hwpe_ctrl_regfile_latch.sv
3+
* Francesco Conti <fconti@iis.ee.ethz.ch>
4+
*
5+
* Copyright (C) 2014-2018 ETH Zurich, University of Bologna
6+
* Copyright and related rights are licensed under the Solderpad Hardware
7+
* License, Version 0.51 (the "License"); you may not use this file except in
8+
* compliance with the License. You may obtain a copy of the License at
9+
* http://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
10+
* or agreed to in writing, software, hardware and materials distributed under
11+
* this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*
15+
* Yvan Tortorella <yvan.tortorella@unibo.it>
16+
*
17+
*/
18+
19+
module hwpe_ctrl_regfile_ff #(
20+
parameter int unsigned AddrWidth = 5,
21+
parameter int unsigned DataWidth = 32,
22+
localparam int unsigned NumWords = 2**AddrWidth,
23+
localparam int unsigned NumByte = DataWidth/8
24+
)(
25+
input logic clk_i ,
26+
input logic rst_ni ,
27+
input logic clear_i,
28+
29+
// Read port
30+
input logic ReadEnable_i,
31+
input logic [AddrWidth-1:0] ReadAddr_i ,
32+
output logic [DataWidth-1:0] ReadData_o ,
33+
34+
// Write port
35+
input logic WriteEnable_i,
36+
input logic [AddrWidth-1:0] WriteAddr_i ,
37+
input logic [DataWidth-1:0] WriteData_i ,
38+
input logic [NumByte-1:0] WriteBE_i ,
39+
40+
// Memory content (false paths!)
41+
output logic [NumWords-1:0][DataWidth-1:0] MemContent_o
42+
);
43+
44+
logic [NumWords-1:0][DataWidth-1:0] data_d, data_q;
45+
46+
logic clk_int;
47+
logic enable, clkg_en;
48+
49+
assign enable = WriteEnable_i & (WriteAddr_i <= NumWords);
50+
51+
assign clkg_en = enable | clear_i;
52+
53+
assign ReadData_o = (ReadEnable_i && (ReadAddr_i <= NumWords)) ? data_q[ReadAddr_i] : '0;
54+
55+
tc_clk_gating i_we_clkg (
56+
.clk_i ( clk_i ),
57+
.en_i ( clkg_en ),
58+
.test_en_i ( 1'b0 ),
59+
.clk_o ( clk_int )
60+
);
61+
62+
for (genvar i = 0; i < NumWords; i++) begin
63+
for (genvar j = 0; j < NumByte; j++) begin
64+
assign data_d[i][j*8+:8] = (enable && (WriteAddr_i == i)) ? (WriteData_i[j*8+:8] & {8{WriteBE_i[j]}})
65+
: data_q[i][j*8+:8];
66+
end
67+
end
68+
69+
always_ff @(posedge clk_int, negedge rst_ni) begin
70+
if (~rst_ni)
71+
data_q <= '0;
72+
else begin
73+
if (clear_i)
74+
data_q <= '0;
75+
else
76+
data_q <= data_d;
77+
end
78+
end
79+
80+
for (genvar i = 0; i < NumWords; i++) begin
81+
assign MemContent_o[i] = data_q[i];
82+
end
83+
84+
endmodule : hwpe_ctrl_regfile_ff

rtl/hwpe_ctrl_regfile_latch_test_wrap.sv

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
module hwpe_ctrl_regfile_latch_test_wrap
1717
#(
18+
parameter int unsigned REGFILE_SCM = 1,
1819
parameter ADDR_WIDTH = 5,
1920
parameter DATA_WIDTH = 32,
2021
parameter NUM_BYTE = DATA_WIDTH/8
@@ -82,23 +83,42 @@ module hwpe_ctrl_regfile_latch_test_wrap
8283
end
8384

8485
assign Q_T = ReadData;
85-
86-
hwpe_ctrl_regfile_latch #(
87-
.ADDR_WIDTH ( ADDR_WIDTH ),
88-
.DATA_WIDTH ( DATA_WIDTH ),
89-
.NUM_BYTE ( NUM_BYTE )
90-
) hwpe_ctrl_regfile_latch_i (
91-
.clk ( clk ),
92-
.rst_n ( rst_n ),
93-
.clear ( clear ),
94-
.ReadEnable ( ReadEnable_muxed ),
95-
.ReadAddr ( ReadAddr_muxed ),
96-
.ReadData ( ReadData ),
97-
.WriteEnable ( WriteEnable_muxed ),
98-
.WriteAddr ( WriteAddr_muxed ),
99-
.WriteData ( WriteData_muxed ),
100-
.WriteBE ( WriteBE_muxed ),
101-
.MemContent ( MemContent )
102-
);
86+
87+
if (REGFILE_SCM == 1) begin : gen_scm_regfile
88+
hwpe_ctrl_regfile_latch #(
89+
.ADDR_WIDTH ( ADDR_WIDTH ),
90+
.DATA_WIDTH ( DATA_WIDTH ),
91+
.NUM_BYTE ( NUM_BYTE )
92+
) hwpe_ctrl_regfile_latch_i (
93+
.clk ( clk ),
94+
.rst_n ( rst_n ),
95+
.clear ( clear ),
96+
.ReadEnable ( ReadEnable_muxed ),
97+
.ReadAddr ( ReadAddr_muxed ),
98+
.ReadData ( ReadData ),
99+
.WriteEnable ( WriteEnable_muxed ),
100+
.WriteAddr ( WriteAddr_muxed ),
101+
.WriteData ( WriteData_muxed ),
102+
.WriteBE ( WriteBE_muxed ),
103+
.MemContent ( MemContent )
104+
);
105+
end else begin : gen_ff_regfile
106+
hwpe_ctrl_regfile_ff #(
107+
.AddrWidth ( ADDR_WIDTH ),
108+
.DataWidth ( DATA_WIDTH )
109+
) hwpe_ctrl_regfile_ff_i (
110+
.clk_i ( clk ),
111+
.rst_ni ( rst_n ),
112+
.clear_i ( clear ),
113+
.ReadEnable_i ( ReadEnable_muxed ),
114+
.ReadAddr_i ( ReadAddr_muxed ),
115+
.ReadData_o ( ReadData ),
116+
.WriteEnable_i ( WriteEnable_muxed ),
117+
.WriteAddr_i ( WriteAddr_muxed ),
118+
.WriteData_i ( WriteData_muxed ),
119+
.WriteBE_i ( WriteBE_muxed ),
120+
.MemContent_o ( MemContent )
121+
);
122+
end
103123

104124
endmodule // hwpe_ctrl_regfile_latch

rtl/hwpe_ctrl_slave.sv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
module hwpe_ctrl_slave
1818
import hwpe_ctrl_package::*;
1919
#(
20+
parameter int unsigned REGFILE_SCM = 1,
2021
parameter int unsigned N_CORES = 4,
2122
parameter int unsigned N_CONTEXT = 2,
2223
parameter int unsigned N_EVT = REGFILE_N_EVT,
@@ -240,6 +241,7 @@ module hwpe_ctrl_slave
240241
assign regfile_flags.running_context = running_context;
241242

242243
hwpe_ctrl_regfile #(
244+
.REGFILE_SCM ( REGFILE_SCM ),
243245
.N_CONTEXT ( N_CONTEXT ),
244246
.N_IO_REGS ( N_IO_REGS ),
245247
.N_GENERIC_REGS ( N_GENERIC_REGS ),

0 commit comments

Comments
 (0)