Skip to content

Commit b5fc3cd

Browse files
committed
Reduce size of address offset
1 parent e10c685 commit b5fc3cd

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

cpu/cpu.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
117117
reg [3:0] rs2;
118118
reg [3:0] rd;
119119
reg [2:0] additional_mem_ops;
120-
reg [5:2] addr_offset;
120+
reg [3:2] addr_offset;
121121
reg mem_op_increment_reg;
122122

123123
reg interrupt_core;
@@ -166,13 +166,13 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
166166
is_system <= 0;
167167
instr_len <= 2'b10;
168168
additional_mem_ops <= 3'b000;
169-
addr_offset <= 4'b0000;
169+
addr_offset <= 2'b00;
170170
interrupt_core <= 0;
171171
end else if (any_additional_mem_ops && instr_complete_core && !stall_core) begin
172172
rs2 <= rs2 + {3'b000, mem_op_increment_reg};
173173
rd <= rd + 4'b0001;
174174
additional_mem_ops <= additional_mem_ops - 3'b001;
175-
addr_offset <= addr_offset + 4'b0001;
175+
addr_offset <= addr_offset + 2'b01;
176176
end else if (instr_complete_core && !any_additional_mem_ops && interrupt_pending) begin
177177
instr_valid <= 0;
178178
interrupt_core <= 1;
@@ -197,7 +197,7 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
197197
rs2 <= rs2_de;
198198
rd <= rd_de;
199199
additional_mem_ops <= additional_mem_ops_de;
200-
addr_offset <= 4'b0000;
200+
addr_offset <= 2'b00;
201201
mem_op_increment_reg <= mem_op_increment_reg_de;
202202
instr_valid <= !branch && !is_ret_de;
203203
end else begin
@@ -255,9 +255,9 @@ module tinyqv_cpu #(parameter NUM_REGS=16, parameter REG_ADDR_BITS=4) (
255255
// the address is routed
256256
data_addr[27:24] <= 4'b000;
257257
end else if (address_ready) begin
258-
// Cycle address within 64-byte window for additional mem op instructions.
258+
// Cycle address within 16-byte window for additional mem op instructions.
259259
// Note this only matters for peripherals - the memory controller ignores the address for data_continue.
260-
data_addr <= {addr_out[27:6], addr_out[5:2] + addr_offset, addr_out[1:0]};
260+
data_addr <= {addr_out[27:4], addr_out[3:2] + addr_offset, addr_out[1:0]};
261261
end
262262
end
263263

test/test_cpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def encode_cscxt(imm, reg_seg, num_regs):
505505

506506
await send_instr(dut, encode_cscxt(16, 1, 7), False, 2)
507507
for i in range(7):
508-
await expect_store(dut, 0x1000400 + ((0x10 + i*4) & 0x3F)) == data[i+3]
508+
await expect_store(dut, 0x1000410 + ((i*4) & 0xF)) == data[i+3]
509509

510510
for i in range(10):
511511
data[i] = random.randint(0, (1 << 32) - 1)
@@ -519,7 +519,7 @@ def encode_cscxt(imm, reg_seg, num_regs):
519519

520520
await send_instr(dut, encode_clcxt(-0x200 & 0x3F0, 1, 7), False, 2)
521521
for i in range(7):
522-
await expect_load(dut, 0x1000200 + i*4, data[i+3])
522+
await expect_load(dut, 0x1000200 + ((i*4) & 0xF), data[i+3])
523523

524524
for i in range(7):
525525
assert await read_reg(dut, i+9) == data[i+3]

0 commit comments

Comments
 (0)