Skip to content

Commit e8eedbe

Browse files
committed
Add XLEN parameter.
1 parent d6b3a2b commit e8eedbe

18 files changed

Lines changed: 1327 additions & 45 deletions

cpu/alu.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module tinyqv_shifter (
9292

9393
endmodule
9494

95-
module tinyqv_mul #(parameter B_BITS=16) (
95+
module tinyqv_mul #(parameter B_BITS) (
9696
input clk,
9797

9898
input [3:0] a,

cpu/core.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This core module takes decoded instructions and produces output data
44
*/
55

6-
module tinyqv_core #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
6+
module tinyqv_core #(parameter XLEN, parameter NUM_REGS, parameter REG_ADDR_BITS) (
77
input clk,
88
input rstn,
99

@@ -86,7 +86,7 @@ module tinyqv_core #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
8686

8787
reg [31:0] tmp_data;
8888

89-
tinyqv_registers #(.REG_ADDR_BITS(REG_ADDR_BITS), .NUM_REGS(NUM_REGS))
89+
tinyqv_registers #(.XLEN(XLEN), .NUM_REGS(NUM_REGS), .REG_ADDR_BITS(REG_ADDR_BITS))
9090
i_registers(clk, rstn, wr_en, counter, rs1, rs2, rd, data_rs1, data_rs2, data_rd, return_addr);
9191

9292

@@ -298,7 +298,7 @@ module tinyqv_core #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
298298
instr_retired <= instr_complete && !is_stall;
299299
end
300300
/* verilator lint_off PINMISSING */ // No carry
301-
tinyqv_counter i_instrret (
301+
tinyqv_counter #(.OUTPUT_WIDTH(4)) i_instrret (
302302
.clk(clk),
303303
.rstn(rstn),
304304
.add(instr_retired),

cpu/counter.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Counter register for TinyQV */
22

3-
module tinyqv_counter #(parameter OUTPUT_WIDTH=4) (
3+
module tinyqv_counter #(parameter OUTPUT_WIDTH) (
44
input clk,
55
input rstn,
66

cpu/cpu.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This CPU module interfaces with memory, the instruction decoder and the core.
44
*/
55

6-
module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
6+
module tinyqv_cpu #(parameter XLEN, parameter NUM_REGS, parameter REG_ADDR_BITS) (
77
input clk,
88
input rstn,
99

@@ -68,7 +68,7 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
6868
wire [2:0] additional_mem_ops_de;
6969
wire mem_op_increment_reg_de;
7070

71-
tinyqv_decoder i_decoder(
71+
tinyqv_decoder #(.XLEN(XLEN), .REG_ADDR_BITS(REG_ADDR_BITS)) i_decoder(
7272
.instr(instr),
7373
.imm(imm_de),
7474

@@ -294,7 +294,7 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
294294
was_early_branch <= early_branch && !branch;
295295
end
296296

297-
tinyqv_core #(.REG_ADDR_BITS(REG_ADDR_BITS), .NUM_REGS(NUM_REGS)) i_core(
297+
tinyqv_core #(.XLEN(XLEN), .NUM_REGS(NUM_REGS), .REG_ADDR_BITS(REG_ADDR_BITS)) i_core(
298298
.clk(clk),
299299
.rstn(rstn),
300300

cpu/decode.v

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Note parts of this are from the excellent FemtoRV by Bruno Levy et al.
44
*/
55

6-
module tinyqv_decoder #(parameter REG_ADDR_BITS=4) (
6+
module tinyqv_decoder #(parameter XLEN, parameter REG_ADDR_BITS) (
77
input [31:0] instr,
88

9-
output reg [31:0] imm,
9+
output reg [XLEN-1:0] imm,
1010

1111
output reg is_load,
1212
output reg is_alu_imm,
@@ -34,25 +34,25 @@ module tinyqv_decoder #(parameter REG_ADDR_BITS=4) (
3434
output reg mem_op_increment_reg
3535
);
3636

37-
wire [31:0] Uimm = { instr[31], instr[30:12], {12{1'b0}}};
38-
wire [31:0] Iimm = {{21{instr[31]}}, instr[30:20]};
39-
wire [31:0] Simm = {{21{instr[31]}}, instr[30:25],instr[11:7]};
40-
wire [31:0] Bimm = {{20{instr[31]}}, instr[7],instr[30:25],instr[11:8],1'b0};
41-
wire [31:0] Jimm = {{12{instr[31]}}, instr[19:12],instr[20],instr[30:21],1'b0};
37+
wire [XLEN-1:0] Uimm = {{XLEN-31{instr[31]}}, instr[30:12], {12{1'b0}}};
38+
wire [XLEN-1:0] Iimm = {{XLEN-11{instr[31]}}, instr[30:20]};
39+
wire [XLEN-1:0] Simm = {{XLEN-11{instr[31]}}, instr[30:25],instr[11:7]};
40+
wire [XLEN-1:0] Bimm = {{XLEN-12{instr[31]}}, instr[7],instr[30:25],instr[11:8],1'b0};
41+
wire [XLEN-1:0] Jimm = {{XLEN-20{instr[31]}}, instr[19:12],instr[20],instr[30:21],1'b0};
4242

4343
// Compressed immediates
44-
wire [31:0] CLWSPimm = {24'b0, instr[3:2], instr[12], instr[6:4], 2'b00};
45-
wire [31:0] CSWSPimm = {24'b0, instr[8:7], instr[12:9], 2'b00};
46-
wire [31:0] CLSWimm = {25'b0, instr[5], instr[12:10], instr[6], 2'b00}; // LW and SW
47-
wire [31:0] CLSHimm = {30'b0, instr[5], 1'b0}; // LH(U) and SH
48-
wire [31:0] CLSBimm = {30'b0, instr[5], instr[6]}; // LBU and SB
49-
wire [31:0] CJimm = {{21{instr[12]}}, instr[8], instr[10:9], instr[6], instr[7], instr[2], instr[11], instr[5:3], 1'b0};
50-
wire [31:0] CBimm = {{24{instr[12]}}, instr[6:5], instr[2], instr[11:10], instr[4:3], 1'b0};
51-
wire [31:0] CALUimm = {{27{instr[12]}}, instr[6:2]}; // ADDI, LI, shifts, ANDI
52-
wire [31:0] CLUIimm = {{15{instr[12]}}, instr[6:2], 12'b0};
53-
wire [31:0] CADDI16SPimm = {{23{instr[12]}}, instr[4:3], instr[5], instr[2], instr[6], 4'b0};
54-
wire [31:0] CADDI4SPimm = {22'b0, instr[10:7], instr[12:11], instr[5], instr[6], 2'b0};
55-
wire [31:0] CSCXTimm = {{23{instr[12]}}, instr[9:7], instr[10], instr[11], 4'b0};
44+
wire [XLEN-1:0] CLWSPimm = {{XLEN-8{1'b0}}, instr[3:2], instr[12], instr[6:4], 2'b00};
45+
wire [XLEN-1:0] CSWSPimm = {{XLEN-8{1'b0}}, instr[8:7], instr[12:9], 2'b00};
46+
wire [XLEN-1:0] CLSWimm = {{XLEN-7{1'b0}}, instr[5], instr[12:10], instr[6], 2'b00}; // LW and SW
47+
wire [XLEN-1:0] CLSHimm = {{XLEN-2{1'b0}}, instr[5], 1'b0}; // LH(U) and SH
48+
wire [XLEN-1:0] CLSBimm = {{XLEN-2{1'b0}}, instr[5], instr[6]}; // LBU and SB
49+
wire [XLEN-1:0] CJimm = {{XLEN-11{instr[12]}}, instr[8], instr[10:9], instr[6], instr[7], instr[2], instr[11], instr[5:3], 1'b0};
50+
wire [XLEN-1:0] CBimm = {{XLEN-8{instr[12]}}, instr[6:5], instr[2], instr[11:10], instr[4:3], 1'b0};
51+
wire [XLEN-1:0] CALUimm = {{XLEN-5{instr[12]}}, instr[6:2]}; // ADDI, LI, shifts, ANDI
52+
wire [XLEN-1:0] CLUIimm = {{XLEN-17{instr[12]}}, instr[6:2], 12'b0};
53+
wire [XLEN-1:0] CADDI16SPimm = {{XLEN-9{instr[12]}}, instr[4:3], instr[5], instr[2], instr[6], 4'b0};
54+
wire [XLEN-1:0] CADDI4SPimm = {{XLEN-10{1'b0}}, instr[10:7], instr[12:11], instr[5], instr[6], 2'b0};
55+
wire [XLEN-1:0] CSCXTimm = {{XLEN-9{instr[12]}}, instr[9:7], instr[10], instr[11], 4'b0};
5656

5757
always @(*) begin
5858
additional_mem_ops = 3'b000;

cpu/register.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
The read bit address is one ahead of write bit address, and both increment every clock.
88
*/
99

10-
module tinyqv_registers #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
10+
module tinyqv_registers #(parameter XLEN, parameter NUM_REGS, parameter REG_ADDR_BITS) (
1111
input clk,
1212
input rstn,
1313

@@ -26,7 +26,7 @@ module tinyqv_registers #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
2626
output [23:1] return_addr
2727
);
2828

29-
reg [31:0] registers [1:NUM_REGS-1];
29+
reg [XLEN-1:0] registers [1:NUM_REGS-1];
3030
wire [3:0] reg_access [0:2**REG_ADDR_BITS-1];
3131

3232
genvar i;

cpu/tinyqv.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
`define default_netname none
77

88
// TinyQV CPU and QSPI memory controller wrapper
9-
module tinyQV (
9+
module tinyQV #(parameter XLEN=32, parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
1010
input clk,
1111
input rstn,
1212

@@ -89,7 +89,7 @@ module tinyQV (
8989
reg rst_reg_n;
9090
always @(posedge clk) rst_reg_n <= rstn;
9191

92-
tinyqv_cpu cpu(
92+
tinyqv_cpu #(.XLEN(XLEN), .NUM_REGS(NUM_REGS), .REG_ADDR_BITS(REG_ADDR_BITS)) cpu(
9393
.clk(clk),
9494
.rstn(rst_reg_n),
9595

iceFUN/iceFUN.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ module tinyQV_top (
8787
wire data_ready;
8888
reg [31:0] data_from_read;
8989

90-
tinyQV i_tinyqv(
90+
tinyQV #(.XLEN(32), .NUM_REGS(16), .REG_ADDR_BITS(4)) i_tinyqv(
9191
.clk(clk),
9292
.rstn(rst_reg_n),
9393

pico_ice/pico_ice.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module tinyQV_top (
8686
wire debug_stop_txn;
8787
wire [3:0] debug_rd;
8888

89-
tinyQV i_tinyqv(
89+
tinyQV #(.XLEN(32), .NUM_REGS(16), .REG_ADDR_BITS(4)) i_tinyqv(
9090
.clk(clk),
9191
.rstn(rst_reg_n),
9292

test/tb_core.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ end
5757
wire [2:0] additional_mem_ops;
5858
wire mem_op_increment_reg;
5959

60-
tinyqv_decoder decoder(instr,
60+
tinyqv_decoder #(.XLEN(32), .REG_ADDR_BITS(4)) decoder(instr,
6161
imm,
6262

6363
is_load,
@@ -107,7 +107,7 @@ end
107107
wire debug_reg_wen;
108108
wire [3:0] debug_rd;
109109

110-
tinyqv_core core(clk,
110+
tinyqv_core #(.XLEN(32), .NUM_REGS(16), .REG_ADDR_BITS(4)) core(clk,
111111
rstn,
112112

113113
imm[counter+:4],
@@ -153,4 +153,4 @@ end
153153
debug_rd
154154
);
155155

156-
endmodule
156+
endmodule

0 commit comments

Comments
 (0)