Core¶
Structure¶
This time, the core is much more organized for the reader.
Utilities¶
clock¶
clock.sv
clock module
Imports¶
Imports 3 elements
core_config_pkg CLK_DIV_MAX CLK_DIV_THRES CLK_DIV_WIDTH
Ports¶
Ports list 3 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
clk_en |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
Signals¶
Signals list 1 element
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
cnt |
Storages signals |
|
|
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
clock <name> (
.clk (i_clk),
.rst_n (i_rst_n),
.clk_en (i_clk_en)
);
<name>: entity work.clock
port map (
clk => i_clk,
rst_n => i_rst_n,
clk_en => i_clk_en
);
Source¶
Raw source Full file
/*
* File : rtl/core/clock.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the clock module. It generate the
* clk_en signal, which will synchronize the stages
* transfers.
*/
`timescale 1ns / 1ps
import core_config_pkg::CLK_DIV_MAX;
import core_config_pkg::CLK_DIV_THRES;
import core_config_pkg::CLK_DIV_WIDTH;
module clock (
input logic clk,
input logic rst_n,
output logic clk_en
);
// Storages signals
logic [CLK_DIV_WIDTH:0] cnt;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
cnt <= 0;
clk_en <= 0;
end else begin
// Handle counter evolution
if (cnt >= CLK_DIV_MAX[CLK_DIV_WIDTH:0]) begin
cnt <= 0;
end else begin
cnt <= cnt + 1;
end
// Handle output state
if (cnt < CLK_DIV_THRES[CLK_DIV_WIDTH:0]) begin
clk_en <= 1;
end else begin
clk_en <= 0;
end
end
end
endmodule
delay¶
delay.sv
delay module
Imports¶
Imports 1 element
core_config_pkg IF_LATENCY
Parameters¶
Parameters 1 element
- • WIDTH Type : logic Default : 32
We don't use XLEN here, to enable the synth of single bit delay lines.
Ports¶
Ports list 5 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
clk_en |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
din |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
dout |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
Signals¶
Signals list 1 element
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
shift_reg |
Internal shift register |
|
|
Combinatorial |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
delay <name> #(
.WIDTH (32)
)(
.clk (i_clk),
.clk_en (i_clk_en),
.rst_n (i_rst_n),
.din (i_din),
.dout (i_dout)
);
<name>: entity work.delay
generic map (
WIDTH => 32
)
port map (
clk => i_clk,
clk_en => i_clk_en,
rst_n => i_rst_n,
din => i_din,
dout => i_dout
);
Source¶
Raw source Full file
/*
* File : rtl/core/delay.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define a delay line, used to synchronize address and
* some commands bits arround the ROM. This prevent from forcing
* manual delays to the user.
*/
`timescale 1ns / 1ps
import core_config_pkg::IF_LATENCY;
module delay #(
parameter int WIDTH = 32 // We don't use XLEN here, to enable the synth of single bit delay lines.
) (
input logic clk,
input logic clk_en,
input logic rst_n,
input logic [(WIDTH - 1) : 0] din,
output logic [(WIDTH - 1) : 0] dout
);
// Internal shift register
logic [(WIDTH - 1) : 0] shift_reg[(IF_LATENCY - 1) : 0];
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
for (int i = 0; i < IF_LATENCY; i++) shift_reg[i] <= '0;
end else if (clk_en) begin
shift_reg[0] <= din;
for (int i = 1; i < IF_LATENCY; i++) shift_reg[i] <= shift_reg[i-1];
end
end
assign dout = shift_reg[IF_LATENCY-1];
endmodule
reset¶
reset.sv
reset module
Imports¶
Imports 1 element
core_config_pkg RST_TICK_CNT
Ports¶
Ports list 3 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
system clock |
|
- |
Combinatorial |
- |
Fanout : 0 |
rst 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
rst_in |
Input |
sync active-high reset output |
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_out |
Output |
|
|
- |
Register clk |
- |
Fanout : 0 |
Processes¶
Process list 3 elements
• Process 1 Combinatorial
• Process 2 Clocked Clocked by clk Reset by rst_in
- -
• Process 3 Clocked Clocked by clk
- -
Signals¶
Signals list 3 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
sync_rst |
|
|
Register clk rst_in |
Fanout : 0 |
|
reset_active |
internal "we are in reset" flag |
|
- |
Register clk |
Fanout : 0 |
counter |
|
|
- |
Register clk |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
reset <name> (
.clk (i_clk),
.rst_in (i_rst_in),
.rst_out (i_rst_out)
);
<name>: entity work.reset
port map (
clk => i_clk,
rst_in => i_rst_in,
rst_out => i_rst_out
);
Source¶
Raw source Full file
/*
* File : rtl/reset.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date :
*
* Brief : This file define the behavior of the reset controller,
* A module that will ensure at least RST_TICK_CNT clock cycles
* are elapsed in reset state. This state is accesed by de-asserting
* rst_in input, or, at natural reset.
*/
`timescale 1ns / 1ps
import core_config_pkg::RST_TICK_CNT;
module reset (
input logic clk, // system clock
input logic rst_in, // async active-low input reset (from button, POR, etc.)
output logic rst_out // sync active-high reset output
);
// -------------------------------------------------------------------------
// Internal signals
// -------------------------------------------------------------------------
logic [1:0] sync_rst; // two-flop synchronizer
logic reset_active; // internal "we are in reset" flag
integer counter; // countdown register
// -------------------------------------------------------------------------
// Power-up initialization (for simulation and synthesis)
// -------------------------------------------------------------------------
initial begin
sync_rst = 2'b00;
reset_active = 1'b1;
counter = core_config_pkg::RST_TICK_CNT;
rst_out = 1'b1;
end
// -------------------------------------------------------------------------
// Asynchronous input synchronization
// Ensures rstrst_in_in_n is safely synchronized to clk domain.
// -------------------------------------------------------------------------
always_ff @(posedge clk or negedge rst_in) begin
if (!rst_in) sync_rst <= 2'b00; // immediate async assertion
else sync_rst <= {sync_rst[0], 1'b1}; // synchronize release
end
// -------------------------------------------------------------------------
// Reset pulse generator
// Ensures rst_out stays asserted for at least RST_TICK_CNT cycles after
// rst_in goes high (deasserted) and during any reset.
// -------------------------------------------------------------------------
always_ff @(posedge clk) begin
if (sync_rst[1] == 0) begin
// External reset active -> restart counter
reset_active <= 1'b1;
counter <= RST_TICK_CNT;
rst_out <= 1'b0;
end else if (reset_active) begin
// Continue holding reset for at least N cycles
if (counter > 0) begin
counter <= counter - 1;
rst_out <= 1'b0;
end else begin
reset_active <= 1'b0;
rst_out <= 1'b1;
end
end else begin
rst_out <= 1'b1;
end
end
endmodule
endianess¶
endianess.sv
endianess module
Imports¶
Imports 1 element
core_config_pkg XLEN
Ports¶
Ports list 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
in |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
out |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Combinatorial
- -
Instantiation templates¶
Instantiation templates 2 elements
endianess <name> (
.in (i_in),
.out (i_out)
);
<name>: entity work.endianess
port map (
in => i_in,
out => i_out
);
Source¶
Raw source Full file
/*
* File : rtl/core/endianess.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file is not really a module, because it's only used
* to perform the endianess swapping process. This is needed to
* ensure some coherency between the standard (Little Endian) and
* the natural (Big Endian). Swap is then realised on the IOs of the
* core, and, on some peripherals.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
module endianess (
input logic [XLEN-1:0] in,
output logic [XLEN-1:0] out
);
always_comb begin
for (int i = 0; i < (XLEN / 8); i++) begin
out[i*8+:8] = in[((XLEN/8-1-i)*8)+:8];
end
end
endmodule
;
Counters¶
counter¶
counter.sv
counter module
Imports¶
Imports 4 elements
core_config_pkg PERF_CNT_LEN PERF_CNT_PORT PERF_CNT_INC XLEN
Ports¶
Ports list 6 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
clk_en |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
enable |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
outL |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
outH |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
Signals¶
Signals list 1 element
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
cnt |
Internal counter |
|
|
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
counter <name> (
.clk (i_clk),
.clk_en (i_clk_en),
.rst_n (i_rst_n),
.enable (i_enable),
.outL (i_outL),
.outH (i_outH)
);
<name>: entity work.counter
port map (
clk => i_clk,
clk_en => i_clk_en,
rst_n => i_rst_n,
enable => i_enable,
outL => i_outL,
outH => i_outH
);
Source¶
Raw source Full file
/*
* File : rtl/core/counter.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define a PERF_CNT_LEN bits counter, used
* for performance monitoring of the core.
* It's output could a single 64 bits outL, or two 32 bits
* outL and outH, which the 32 LSB and 32 MSB respectively.
*/
`timescale 1ns / 1ps
import core_config_pkg::PERF_CNT_LEN;
import core_config_pkg::PERF_CNT_PORT;
import core_config_pkg::PERF_CNT_INC;
import core_config_pkg::XLEN;
module counter (
input logic clk,
input logic clk_en,
input logic rst_n,
input logic enable,
output logic [(XLEN - 1) : 0] outL,
output logic [(XLEN - 1) : 0] outH
);
// Internal counter
logic [(PERF_CNT_LEN - 1) : 0] cnt;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
cnt <= 0;
end else if (clk_en) begin
if (enable) begin
cnt <= cnt + {32'b0, core_config_pkg::PERF_CNT_INC};
end
end
end
generate
// Assigning outputs depending on the core configuration
if (core_config_pkg::PERF_CNT_PORT == 1) begin : gen_dualport
assign outL[core_config_pkg::XLEN-1:0] =
cnt[((core_config_pkg::PERF_CNT_LEN / 2) - 1) : 0]; // 32 LSB
assign outH[core_config_pkg::XLEN-1:0] =
cnt[(core_config_pkg::PERF_CNT_LEN - 1) : (core_config_pkg::PERF_CNT_LEN / 2)]; // 32 MSB
end else begin : gen_singleport
assign outL[(core_config_pkg::PERF_CNT_LEN - 1) : 0] =
cnt[(core_config_pkg::PERF_CNT_LEN - 1) : 0]; // 64 LSB
assign outH = 0; // 0
end
endgenerate
endmodule
pcounter¶
pcounter.sv
pcounter module
Imports¶
Imports 4 elements
core_config_pkg IF_MAX_ADDR IF_INC XLEN IF_BASE_ADDR
Ports¶
Ports list 10 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
clk_en |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
enable |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
load |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
load2 |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
loaded |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
loaded2 |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
ovf |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
address |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
Instantiation templates¶
Instantiation templates 2 elements
pcounter <name> (
.clk (i_clk),
.clk_en (i_clk_en),
.rst_n (i_rst_n),
.enable (i_enable),
.load (i_load),
.load2 (i_load2),
.loaded (i_loaded),
.loaded2 (i_loaded2),
.ovf (i_ovf),
.address (i_address)
);
<name>: entity work.pcounter
port map (
clk => i_clk,
clk_en => i_clk_en,
rst_n => i_rst_n,
enable => i_enable,
load => i_load,
load2 => i_load2,
loaded => i_loaded,
loaded2 => i_loaded2,
ovf => i_ovf,
address => i_address
);
Source¶
Raw source Full file
/*
* File : rtl/core/pcounter.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the program counter, the module that handle the
* computing of the next address to be executed.
* It has two inputs ports, for different level of priority between the
* commit unit and the branch prediction unit.
*/
`timescale 1ns / 1ps
import core_config_pkg::IF_MAX_ADDR;
import core_config_pkg::IF_INC;
import core_config_pkg::XLEN;
import core_config_pkg::IF_BASE_ADDR;
/*
* The "legacy" load input as the precedence over the load2 port.
* This is needed to ensure a branch mis-predicted will always be handled,
* because in that case, the branch prediction unit would not behave correctly.
*/
module pcounter (
input logic clk,
input logic clk_en,
input logic rst_n,
input logic enable,
input logic load,
input logic load2,
input logic [(XLEN - 1) : 0] loaded,
input logic [(XLEN - 1) : 0] loaded2,
output logic ovf,
output logic [(XLEN - 1) : 0] address
);
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
address <= IF_BASE_ADDR;
ovf <= 0;
end else if (clk_en) begin
if (load) begin
address <= loaded;
end else if (load2 && !load) begin
address <= loaded2;
end else if (enable) begin
if (address < (IF_MAX_ADDR - IF_INC)) begin
address <= address + IF_INC;
ovf <= 0;
end else begin
ovf <= 1;
end
end
end
end
endmodule
Prediction & Decoder¶
decoder¶
decoder.sv
decoder module
Imports¶
Imports 5 elements
core_config_pkg IF_LEN XLEN REG_ADDR_W opcodes_t decoders_t
Ports¶
Ports list 15 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
clk_en |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
instruction |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
rs1 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
rs2 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
rd |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
imm |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
opcode |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
illegal |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
decoded_cnt |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
i 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
i_address |
Input |
Busy input from later stages. |
|
|
Register clk |
- |
Fanout : 0 |
i_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
o 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
o_busy |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
o_address |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
Processes¶
Process list 4 elements
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
• Process 2 Combinatorial
- -
• Process 3 Clocked Clocked by clk Reset by rst_n
- -
• Process 4 Combinatorial
- -
Signals¶
Signals list 10 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
first_flag |
|
|
- |
Register clk rst_n |
Fanout : 0 |
decoder_illegal |
|
|
- |
Register clk rst_n |
Fanout : 0 |
selected_decoder |
|
|
- |
Register clk rst_n |
Fanout : 0 |
dec_illegal2 |
|
|
- |
Combinatorial |
Fanout : 0 |
r0 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
r0_instruction |
|
|
|
Register clk rst_n |
Fanout : 0 |
r0_addr |
|
|
|
Register clk rst_n |
Fanout : 0 |
r1 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
r1_addr |
|
|
|
Register clk rst_n |
Fanout : 0 |
r1_instruction |
|
|
|
Register clk rst_n |
Fanout : 0 |
r 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
r_selected_decoder |
|
|
- |
Register clk rst_n |
Fanout : 0 |
r_decoder_illegal |
|
|
- |
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
decoder <name> (
.clk (i_clk),
.clk_en (i_clk_en),
.rst_n (i_rst_n),
.instruction (i_instruction),
.i_address (i_i_address),
.i_busy (i_i_busy),
.o_busy (i_o_busy),
.rs1 (i_rs1),
.rs2 (i_rs2),
.rd (i_rd),
.imm (i_imm),
.o_address (i_o_address),
.opcode (i_opcode),
.illegal (i_illegal),
.decoded_cnt (i_decoded_cnt)
);
<name>: entity work.decoder
port map (
clk => i_clk,
clk_en => i_clk_en,
rst_n => i_rst_n,
instruction => i_instruction,
i_address => i_i_address,
i_busy => i_i_busy,
o_busy => i_o_busy,
rs1 => i_rs1,
rs2 => i_rs2,
rd => i_rd,
imm => i_imm,
o_address => i_o_address,
opcode => i_opcode,
illegal => i_illegal,
decoded_cnt => i_decoded_cnt
);
Source¶
Raw source Full file
/*
* File : rtl/core/decoder.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the instruction decoder, that parse an
* incomming 32 bit instruction into multiple outputs, which
* correspond to all of the fields contained into.
* Does also perform the data formatting required for the
* immediates fields.
*/
`timescale 1ns / 1ps
import core_config_pkg::IF_LEN;
import core_config_pkg::XLEN;
import core_config_pkg::REG_ADDR_W;
import core_config_pkg::opcodes_t;
import core_config_pkg::decoders_t;
module decoder (
input logic clk,
input logic clk_en,
input logic rst_n,
input logic [ (IF_LEN - 1) : 0] instruction,
input logic [ (XLEN - 1) : 0] i_address,
input logic i_busy, // Busy input from later stages.
output logic o_busy, // Busy output for previous stages.
output logic [(REG_ADDR_W - 1) : 0] rs1,
output logic [(REG_ADDR_W - 1) : 0] rs2,
output logic [(REG_ADDR_W - 1) : 0] rd,
output logic [ (XLEN - 1) : 0] imm,
output logic [ (XLEN - 1) : 0] o_address,
output opcodes_t opcode,
output logic illegal,
output logic decoded_cnt
);
/*
* First latches, registering the inputs, on each rising edges of the clock.
*/
logic [(XLEN - 1) : 0] r0_instruction;
logic [(XLEN - 1) : 0] r0_addr;
logic [(XLEN - 1) : 0] r1_addr;
logic first_flag;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
r0_instruction <= 0;
r0_addr <= 0;
r1_addr <= 0;
first_flag <= 1;
end else if (clk_en) begin
if (!first_flag) begin
r0_instruction <= instruction;
r0_addr <= i_address;
r1_addr <= r0_addr;
o_address <= r1_addr;
end else begin
first_flag <= 0;
end
end
end
/*
* Second, combinational logic to choose the right decoder
*/
logic decoder_illegal;
decoders_t selected_decoder;
always_comb begin
decoder_illegal = 0;
unique case (r0_instruction[6:0])
7'b0110111, 7'b0010111: selected_decoder = core_config_pkg::DEC_U; // LUI or AUIPC
7'b0010011, 7'b0001111, 7'b1100111, 7'b1110011, 7'b0000011:
selected_decoder = core_config_pkg::DEC_I; // Immediates operands
7'b0110011: selected_decoder = core_config_pkg::DEC_R; // Register operations
7'b1100011: selected_decoder = core_config_pkg::DEC_B; // Branchs
7'b0100011: selected_decoder = core_config_pkg::DEC_S; // Loads
7'b1101111: selected_decoder = core_config_pkg::DEC_J; // Jumps
7'b0000000: selected_decoder = core_config_pkg::DEC_NONE; // Others
default: begin
selected_decoder = core_config_pkg::DEC_NONE;
decoder_illegal = 1'b1;
end
endcase
end
/*
* Second registration stage, for the second decoding stage
*/
logic [(XLEN - 1) : 0] r1_instruction;
decoders_t r_selected_decoder;
logic r_decoder_illegal;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
r1_instruction <= 0;
r_selected_decoder <= core_config_pkg::DEC_NONE;
r_decoder_illegal <= 0;
end else if (clk_en) begin
r1_instruction <= r0_instruction;
r_selected_decoder <= selected_decoder;
r_decoder_illegal <= decoder_illegal;
end
end
/*
* Second combinational stage, and direct output to the remaining circuits.
*/
logic dec_illegal2;
always_comb begin
// Default assignments (avoid latch inference)
opcode = core_config_pkg::i_NOP;
dec_illegal2 = 1'b0;
rd = 5'b0;
rs1 = 5'b0;
rs2 = 5'b0;
imm = 32'b0;
// Using the right decoder...
unique case (r_selected_decoder)
core_config_pkg::DEC_R: begin
rd = r1_instruction[core_config_pkg::RD_MSB : core_config_pkg::RD_LSB];
rs1 = r1_instruction[core_config_pkg::RS1_MSB : core_config_pkg::RS1_LSB];
rs2 = r1_instruction[core_config_pkg::RS2_MSB : core_config_pkg::RS2_LSB];
unique case (r1_instruction[core_config_pkg::FUNCT7_MSB : core_config_pkg::FUNCT7_LSB])
7'b0000000: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_ADD;
3'b001: opcode = core_config_pkg::i_SLL;
3'b010: opcode = core_config_pkg::i_SLT;
3'b011: opcode = core_config_pkg::i_SLTU;
3'b100: opcode = core_config_pkg::i_XOR;
3'b101: opcode = core_config_pkg::i_SRL;
3'b110: opcode = core_config_pkg::i_OR;
3'b111: opcode = core_config_pkg::i_AND;
endcase
end
7'b0100000: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_SUB;
3'b101: opcode = core_config_pkg::i_SRA;
default: dec_illegal2 = 1;
endcase
end
7'b0000001: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_MUL;
3'b001: opcode = core_config_pkg::i_MULH;
3'b010: opcode = core_config_pkg::i_MULHSU;
3'b011: opcode = core_config_pkg::i_MULHU;
3'b100: opcode = core_config_pkg::i_DIV;
3'b101: opcode = core_config_pkg::i_DIVU;
3'b110: opcode = core_config_pkg::i_REM;
3'b111: opcode = core_config_pkg::i_REMU;
endcase
end
default: dec_illegal2 = 1;
endcase
end
core_config_pkg::DEC_I: begin
rd = r1_instruction[core_config_pkg::RD_MSB : core_config_pkg::RD_LSB];
rs1 = r1_instruction[core_config_pkg::RS1_MSB : core_config_pkg::RS1_LSB];
imm = {{32 - 12{r1_instruction[31]}}, r1_instruction[31:20]};
unique case (r1_instruction[core_config_pkg::OPCODE_MSB : core_config_pkg::OPCODE_LSB])
7'b0010011: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_ADDI;
3'b001: opcode = core_config_pkg::i_SLLI;
3'b010: opcode = core_config_pkg::i_SLTI;
3'b011: opcode = core_config_pkg::i_SLTIU;
3'b100: opcode = core_config_pkg::i_XORI;
3'b101: begin
if (r1_instruction[30]) begin
opcode = core_config_pkg::i_SRAI;
end else begin
opcode = core_config_pkg::i_SRLI;
end
end
3'b110: opcode = core_config_pkg::i_ORI;
3'b111: opcode = core_config_pkg::i_ANDI;
endcase
end
7'b0001111: opcode = core_config_pkg::i_FENCE;
7'b0000011: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_LB;
3'b001: opcode = core_config_pkg::i_LH;
3'b010: opcode = core_config_pkg::i_LW;
3'b100: opcode = core_config_pkg::i_LBU;
3'b101: opcode = core_config_pkg::i_LHU;
default: dec_illegal2 = 1;
endcase
end
7'b1100111: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_JALR;
default: dec_illegal2 = 1;
endcase
end
7'b1110011: begin
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: begin
/*
* Theses values aren't used by the encoding, and more importantly : They
* shall not appear on the ouputs.
*/
imm = 0;
rs1 = 0;
rd = 0;
unique case (r1_instruction[core_config_pkg::XLEN - 1 : core_config_pkg::RS2_LSB])
12'h000: opcode = core_config_pkg::i_ECALL;
12'h001: opcode = core_config_pkg::i_EBREAK;
12'h302: opcode = core_config_pkg::i_MRET;
default: dec_illegal2 = 1;
endcase
end
3'b001: opcode = core_config_pkg::i_CSRRW;
3'b010: opcode = core_config_pkg::i_CSRRS;
3'b011: opcode = core_config_pkg::i_CSRRC;
3'b101: opcode = core_config_pkg::i_CSRRWI;
3'b110: opcode = core_config_pkg::i_CSRRSI;
3'b111: opcode = core_config_pkg::i_CSRRCI;
default: dec_illegal2 = 1;
endcase
end
default: dec_illegal2 = 1;
endcase
end
core_config_pkg::DEC_S: begin
rs1 = r1_instruction[core_config_pkg::RS1_MSB : core_config_pkg::RS1_LSB];
rs2 = r1_instruction[core_config_pkg::RS2_MSB : core_config_pkg::RS2_LSB];
imm = {
{32 - 12{r1_instruction[31]}},
r1_instruction[core_config_pkg::FUNCT7_MSB : core_config_pkg::FUNCT7_LSB],
r1_instruction[core_config_pkg::RD_MSB : core_config_pkg::RD_LSB]
};
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_SB;
3'b001: opcode = core_config_pkg::i_SH;
3'b010: opcode = core_config_pkg::i_SW;
default: dec_illegal2 = 1;
endcase
end
core_config_pkg::DEC_B: begin
rs1 = r1_instruction[core_config_pkg::RS1_MSB : core_config_pkg::RS1_LSB];
rs2 = r1_instruction[core_config_pkg::RS2_MSB : core_config_pkg::RS2_LSB];
imm = {
{32 - 12{r1_instruction[31]}},
r1_instruction[7],
r1_instruction[30 : 25],
r1_instruction[11 : 8],
1'b0
};
unique case (r1_instruction[core_config_pkg::FUNCT3_MSB : core_config_pkg::FUNCT3_LSB])
3'b000: opcode = core_config_pkg::i_BEQ;
3'b001: opcode = core_config_pkg::i_BNE;
3'b100: opcode = core_config_pkg::i_BLT;
3'b101: opcode = core_config_pkg::i_BGE;
3'b110: opcode = core_config_pkg::i_BLTU;
3'b111: opcode = core_config_pkg::i_BGEU;
default: dec_illegal2 = 1;
endcase
end
core_config_pkg::DEC_U: begin
rd = r1_instruction[core_config_pkg::RD_MSB : core_config_pkg::RD_LSB];
imm = {r1_instruction[31 : core_config_pkg::FUNCT3_LSB], 12'b0};
unique case (r1_instruction[core_config_pkg::OPCODE_MSB : core_config_pkg::OPCODE_LSB])
7'b0110111 : opcode = core_config_pkg::i_LUI;
7'b0010111 : opcode = core_config_pkg::i_AUIPC;
default :
dec_illegal2 = 1;
endcase
end
core_config_pkg::DEC_J: begin
rd = r1_instruction[core_config_pkg::RD_MSB : core_config_pkg::RD_LSB];
opcode = core_config_pkg::i_JAL;
imm = {
{32 - 20{r1_instruction[31]}},
r1_instruction[19 : 12],
r1_instruction[20],
r1_instruction[30 : 21],
1'b0
};
end
core_config_pkg::DEC_NONE: dec_illegal2 = 1;
endcase
end
assign illegal = r_decoder_illegal | dec_illegal2;
assign o_busy = i_busy;
assign decoded_cnt = ~(illegal & o_busy);
endmodule
prediction¶
prediction.sv
prediction module
Imports¶
Imports 3 elements
core_config_pkg XLEN BPU_BITS_NB opcodes_t
Ports¶
Ports list 13 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
Standards |
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
predict_ok |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
mispredict |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rom_flush |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
bpu_branch_taken |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
addr 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
addr_in |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
addr_out |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
PC 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
PC_value |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
PC_write |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
actual 3 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
actual_addr |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
actual_imm |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
actual_instr |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 3 elements
• Process 1 Clocked Clocked by clk Reset by rst_n
- -
• Process 2 Combinatorial
Then, some logic to predict the next operation.
• Process 3 Clocked Clocked by clk Reset by rst_n
- -
Signals¶
Signals list 5 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
counter |
Implementing the small counter that register the taken / not taken IOs. |
|
|
Register clk rst_n |
Fanout : 0 |
counter_ack |
|
|
- |
Register clk rst_n |
Fanout : 0 |
next_addr |
Implementing control signals to manage the outputs |
|
|
Register clk rst_n |
Fanout : 0 |
updated_needed |
|
|
- |
Combinatorial |
Fanout : 0 |
active |
Finally, some logic to handle the signals timings, with a small FSM |
|
- |
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
prediction <name> (
.clk (i_clk),
.rst_n (i_rst_n),
.predict_ok (i_predict_ok),
.mispredict (i_mispredict),
.addr_in (i_addr_in),
.addr_out (i_addr_out),
.rom_flush (i_rom_flush),
.PC_value (i_PC_value),
.PC_write (i_PC_write),
.actual_addr (i_actual_addr),
.actual_imm (i_actual_imm),
.actual_instr (i_actual_instr),
.bpu_branch_taken (i_bpu_branch_taken)
);
<name>: entity work.prediction
port map (
clk => i_clk,
rst_n => i_rst_n,
predict_ok => i_predict_ok,
mispredict => i_mispredict,
addr_in => i_addr_in,
addr_out => i_addr_out,
rom_flush => i_rom_flush,
PC_value => i_PC_value,
PC_write => i_PC_write,
actual_addr => i_actual_addr,
actual_imm => i_actual_imm,
actual_instr => i_actual_instr,
bpu_branch_taken => i_bpu_branch_taken
);
Source¶
Raw source Full file
/*
* File : rtl/core/prediction.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the BPU, Branch Prediction Unit, which
* will try to help to reduce the pipeline stalls, by trying to predict
* the next program counter address.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
import core_config_pkg::BPU_BITS_NB;
import core_config_pkg::opcodes_t;
module prediction (
// Standards
input logic clk,
input logic rst_n,
input logic predict_ok,
input logic mispredict,
input logic [(core_config_pkg::XLEN - 1) : 0] addr_in,
output logic [(core_config_pkg::XLEN - 1) : 0] addr_out,
output logic rom_flush,
output logic [(core_config_pkg::XLEN - 1) : 0] PC_value,
output logic PC_write,
input logic [(core_config_pkg::XLEN - 1) : 0] actual_addr,
input logic [(core_config_pkg::XLEN - 1) : 0] actual_imm,
input opcodes_t actual_instr,
output logic bpu_branch_taken
);
/*
* Implementing the small counter that register the taken / not taken IOs.
*/
logic [(core_config_pkg::BPU_BITS_NB - 1) : 0] counter;
logic counter_ack;
/*
* Incrementing the counter if only one of the input signal is active, and ensure we ack
* this signal, to not count it twice.
* Return to the default state only if both are cleared, which is the idle state of the ALU.
*/
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
counter <= '0;
end else if (!counter_ack) begin
if (mispredict && counter != 0) begin
counter <= counter - 1;
counter_ack <= 1'b1;
end else if (predict_ok && counter != '1) begin
counter <= counter + 1;
counter_ack <= 1'b1;
end
end else if (predict_ok == 1'b0 && mispredict == 1'b0) begin
counter_ack <= 1'b0;
end
end
/*
* Implementing control signals to manage the outputs
*/
logic [(core_config_pkg::XLEN - 1) : 0] next_addr;
logic updated_needed;
/*
* Then, some logic to predict the next operation.
*/
always_comb begin
unique case (actual_instr)
// First, unconditionnal jumps (always taken)
core_config_pkg::i_JAL, core_config_pkg::i_JALR: begin
next_addr = $signed(actual_addr) + $signed(actual_imm);
updated_needed = 1'b1;
bpu_branch_taken = 1'b0;
end
// Then, conditionnal jumps (need to account for the counter MSB)
core_config_pkg::i_BEQ,
core_config_pkg::i_BNE,
core_config_pkg::i_BGE,
core_config_pkg::i_BLT,
core_config_pkg::i_BGEU,
core_config_pkg::i_BLTU : begin
next_addr = $signed(actual_addr) + $signed(actual_imm);
updated_needed = counter[core_config_pkg::BPU_BITS_NB - 1]; // Look for the MSB if needed
bpu_branch_taken = counter[core_config_pkg::BPU_BITS_NB-1];
end
default: begin
next_addr = '0;
updated_needed = 1'b0;
bpu_branch_taken = 1'b0;
end
endcase
end
/*
* Finally, some logic to handle the signals timings, with a small FSM
*/
logic active;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
addr_out <= '0;
rom_flush <= 1'b1; // inverted logic !
PC_value <= addr_in;
PC_write <= 1'b0;
end else begin
if (!active && updated_needed) begin
addr_out <= next_addr;
rom_flush <= 1'b0;
PC_value <= next_addr;
PC_write <= 1'b1;
active <= 1'b1;
end else begin
addr_out <= addr_in;
rom_flush <= 1'b1;
PC_value <= '0;
PC_write <= 1'b0;
active <= 1'b0;
end
end
end
endmodule
Registers¶
registers¶
registers.sv
registers module
Imports¶
Imports 3 elements
core_config_pkg XLEN REG_COUNT REG_ADDR_W
Ports¶
Ports list 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
we |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
wa |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
wd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
ra1 |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
ra2 |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
rd1 |
Output |
|
|
|
Register clk |
- |
Fanout : 0 |
rd2 |
Output |
|
|
|
Register clk |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk
Synchronous write logic (2 per cpu cycles).
Signals¶
Signals list 1 element
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
regs |
|
|
|
Combinatorial |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
registers <name> (
.clk (i_clk),
.we (i_we),
.wa (i_wa),
.wd (i_wd),
.ra1 (i_ra1),
.ra2 (i_ra2),
.rd1 (i_rd1),
.rd2 (i_rd2)
);
<name>: entity work.registers
port map (
clk => i_clk,
we => i_we,
wa => i_wa,
wd => i_wd,
ra1 => i_ra1,
ra2 => i_ra2,
rd1 => i_rd1,
rd2 => i_rd2
);
Source¶
Raw source Full file
/*
* File : rtl/core/registers.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the register file for the general purpose usage.
* With a decent tool, they shall be inferred into a RAM logic.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
import core_config_pkg::REG_COUNT;
import core_config_pkg::REG_ADDR_W;
module registers (
input logic clk,
input logic we,
input logic [(REG_ADDR_W - 1) : 0] wa,
input logic [ (XLEN - 1) : 0] wd,
input logic [(REG_ADDR_W - 1) : 0] ra1,
input logic [(REG_ADDR_W - 1) : 0] ra2,
output logic [ (XLEN - 1) : 0] rd1,
output logic [ (XLEN - 1) : 0] rd2
);
/*
* Storage array
*/
logic [(XLEN - 1) : 0] regs[(REG_COUNT - 1) : 0];
/*
* Synchronous write logic (2 per cpu cycles).
*/
always_ff @(posedge clk) begin
if (we) begin
if (wa != 0) begin
regs[wa] <= wd;
end
end
rd1 <= regs[ra1];
rd2 <= regs[ra2];
end
endmodule
csr¶
csr.sv
csr module
Imports¶
Imports 1 element
core_config_pkg XLEN
Ports¶
Ports list 19 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
we |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
wa |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
wd |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
ra |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
rd |
Output |
|
|
|
Register clk |
- |
Fanout : 0 |
err |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
cycleL |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
cycleH |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
instructionsL |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
instructionsH |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
flushsL |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
flushsH |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
waitsL |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
waitsH |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
decodedL |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
decodedH |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
interrupt_vect |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
int_pend |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 2 elements
• Process 1 Combinatorial
Comb. logic to assign the right ID to each values, and set the error pin.
• Process 2 Clocked Clocked by clk
Sync logic, perform read and writes (2 per cpu cycles !).
Signals¶
Signals list 7 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
csrs |
Storage types |
|
|
Combinatorial |
Fanout : 0 |
wid |
|
|
- |
Register clk |
Fanout : 0 |
rid |
|
|
- |
Combinatorial |
Fanout : 0 |
write_state |
|
|
- |
Register clk |
Fanout : 0 |
r 3 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
r_wid |
|
|
- |
Register clk |
Fanout : 0 |
r_wd |
|
|
|
Register clk |
Fanout : 0 |
r_readback |
0 if not performing a write (writting readback), 1 if performing a write (writing) |
|
|
Register clk |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
csr <name> (
.clk (i_clk),
.we (i_we),
.wa (i_wa),
.wd (i_wd),
.ra (i_ra),
.rd (i_rd),
.err (i_err),
.cycleL (i_cycleL),
.cycleH (i_cycleH),
.instructionsL (i_instructionsL),
.instructionsH (i_instructionsH),
.flushsL (i_flushsL),
.flushsH (i_flushsH),
.waitsL (i_waitsL),
.waitsH (i_waitsH),
.decodedL (i_decodedL),
.decodedH (i_decodedH),
.interrupt_vect (i_interrupt_vect),
.int_pend (i_int_pend)
);
<name>: entity work.csr
port map (
clk => i_clk,
we => i_we,
wa => i_wa,
wd => i_wd,
ra => i_ra,
rd => i_rd,
err => i_err,
cycleL => i_cycleL,
cycleH => i_cycleH,
instructionsL => i_instructionsL,
instructionsH => i_instructionsH,
flushsL => i_flushsL,
flushsH => i_flushsH,
waitsL => i_waitsL,
waitsH => i_waitsH,
decodedL => i_decodedL,
decodedH => i_decodedH,
interrupt_vect => i_interrupt_vect,
int_pend => i_int_pend
);
Source¶
Raw source Full file
/*
* File : rtl/core/csr.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the CSR register array, or, at least
* emulate it. In fact, there's only 8 registers that are
* stored, even if 23 of them are available !
* That's because some of them aren't writtable at all, so
* we return 0, some are just "interfaces" to some
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
module csr (
input logic clk,
input logic we,
input logic [(core_config_pkg::CSR_ADDR_W - 1) : 0] wa,
input logic [ (core_config_pkg::XLEN - 1) : 0] wd,
input logic [(core_config_pkg::CSR_ADDR_W - 1) : 0] ra,
output logic [ (core_config_pkg::XLEN - 1) : 0] rd,
output logic err,
input logic [ (core_config_pkg::XLEN - 1) : 0] cycleL,
input logic [ (core_config_pkg::XLEN - 1) : 0] cycleH,
input logic [ (core_config_pkg::XLEN - 1) : 0] instructionsL,
input logic [ (core_config_pkg::XLEN - 1) : 0] instructionsH,
input logic [ (core_config_pkg::XLEN - 1) : 0] flushsL,
input logic [ (core_config_pkg::XLEN - 1) : 0] flushsH,
input logic [ (core_config_pkg::XLEN - 1) : 0] waitsL,
input logic [ (core_config_pkg::XLEN - 1) : 0] waitsH,
input logic [ (core_config_pkg::XLEN - 1) : 0] decodedL,
input logic [ (core_config_pkg::XLEN - 1) : 0] decodedH,
input logic [ (core_config_pkg::XLEN - 1) : 0] interrupt_vect,
output logic int_pend
);
/*
* Function to identify the CSR using it's address
*/
function core_config_pkg::csr_t csr_index(input logic [11:0] addr);
unique case (addr)
12'h300: csr_index = core_config_pkg::r_MSTATUS;
12'h304: csr_index = core_config_pkg::r_MIE;
12'h305: csr_index = core_config_pkg::r_MTVEC;
12'h340: csr_index = core_config_pkg::r_MSCRATCH;
12'h341: csr_index = core_config_pkg::r_MEPC;
12'h342: csr_index = core_config_pkg::r_MCAUSE;
12'h343: csr_index = core_config_pkg::r_MTVAL;
12'h344: csr_index = core_config_pkg::r_MIP;
12'hB00: csr_index = core_config_pkg::r_CYCLE;
12'hB02: csr_index = core_config_pkg::r_INSTR;
12'hB03: csr_index = core_config_pkg::r_FLUSH;
12'hB04: csr_index = core_config_pkg::r_WAIT;
12'hB05: csr_index = core_config_pkg::r_DECOD;
12'hB80: csr_index = core_config_pkg::r_CYCLEH;
12'hB82: csr_index = core_config_pkg::r_INSTRH;
12'hB83: csr_index = core_config_pkg::r_FLUSHH;
12'hB84: csr_index = core_config_pkg::r_WAITH;
12'hB85: csr_index = core_config_pkg::r_DECODH;
12'hF10: csr_index = core_config_pkg::r_MISA;
12'hF11: csr_index = core_config_pkg::r_MVENDORID;
12'hF12: csr_index = core_config_pkg::r_MARCHID;
12'hF13: csr_index = core_config_pkg::r_MIMPID;
12'hF14: csr_index = core_config_pkg::r_MHARTID;
default: csr_index = core_config_pkg::r_NONE;
endcase
endfunction
/*
* Function to apply to compute the new value of the register, including masks.
*/
function logic [(core_config_pkg::XLEN - 1) : 0] update_bits(
input logic [(core_config_pkg::XLEN - 1) : 0] reg_value,
input logic [(core_config_pkg::XLEN - 1) : 0] mask,
input logic [(core_config_pkg::XLEN - 1) : 0] data);
update_bits = (data & mask) | (reg_value & ~mask);
endfunction
/*
* Storage types
*/
logic [(core_config_pkg::XLEN - 1) : 0] csrs[(core_config_pkg::r_MVENDORID - 1) : 0];
core_config_pkg::csr_t wid;
core_config_pkg::csr_t rid;
core_config_pkg::csr_t r_wid;
logic [(core_config_pkg::XLEN - 1) : 0] r_wd;
logic [(core_config_pkg::XLEN - 1) : 0] r_readback;
logic write_state; // 0 if not performing a write (writting readback), 1 if performing a write (writing)
/*
* Comb. logic to assign the right ID to each values, and set the error pin.
*/
always_comb begin
wid = csr_index(wa);
rid = csr_index(ra);
if (wid == core_config_pkg::r_NONE || rid == core_config_pkg::r_NONE) begin
err = 1;
end else begin
err = 0;
end
end
/*
* Sync logic, perform read and writes (2 per cpu cycles !).
*/
always_ff @(posedge clk) begin
// Assigning input values to the counters
if (we) begin
if (wid != core_config_pkg::r_NONE) begin
if (!write_state) begin
r_readback <= csrs[wid[2 : 0]]; // Theses registers are all located within the three LSB, thus this expression is correct.
write_state <= 1'b1;
r_wd <= wd;
r_wid <= wid;
end
end
end
if (write_state) begin
csrs[r_wid[2 : 0]] <= update_bits( // Theses registers are all located within the three LSB, thus this expression is correct.
r_readback, core_config_pkg::CSR_WMASK[r_wid], r_wd
);
write_state <= 1'b0;
end
if (rid != core_config_pkg::r_NONE) begin
unique case (rid)
// Theses registers are all located within the three LSB, thus this expression is correct.
core_config_pkg::r_MSTATUS,
core_config_pkg::r_MIE,
core_config_pkg::r_MTVEC,
core_config_pkg::r_MSCRATCH,
core_config_pkg::r_MEPC,
core_config_pkg::r_MCAUSE,
core_config_pkg::r_MTVAL :
rd <= csrs[rid[2 : 0]];
// The MIP register is build on the fly when needed.
core_config_pkg::r_MIP: rd <= interrupt_vect & csrs[core_config_pkg::r_MIE[2:0]];
core_config_pkg::r_CYCLE: rd <= cycleL;
core_config_pkg::r_CYCLEH: rd <= cycleH;
core_config_pkg::r_INSTR: rd <= instructionsL;
core_config_pkg::r_INSTRH: rd <= instructionsH;
core_config_pkg::r_FLUSH: rd <= flushsL;
core_config_pkg::r_FLUSHH: rd <= flushsH;
core_config_pkg::r_WAIT: rd <= waitsL;
core_config_pkg::r_WAITH: rd <= waitsH;
core_config_pkg::r_DECOD: rd <= decodedL;
core_config_pkg::r_DECODH: rd <= decodedH;
core_config_pkg::r_MVENDORID,
core_config_pkg::r_MARCHID,
core_config_pkg::r_MIMPID,
core_config_pkg::r_MHARTID,
core_config_pkg::r_MISA :
rd <= 32'h0; // Default value on simple impl.
core_config_pkg::r_NONE: rd <= 32'h0;
endcase
end
end
assign int_pend = |(interrupt_vect & csrs[core_config_pkg::r_MIE[2:0]]);
endmodule
ALU Managers¶
issuer¶
issuer.sv
issuer module
Imports¶
Imports 2 elements
core_config_pkg XLEN alu_commands_t
Ports¶
Ports list 75 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
flush_needed |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
commit_err |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
PC_ovf |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
dec 10 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
dec_rs1 |
Input |
Decoders IOs |
|
|
Register clk |
- |
Fanout : 0 |
dec_rs2 |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
dec_rd |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
dec_imm |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
dec_address |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
dec_opcode |
Input |
|
|
- |
Register clk |
- |
Fanout : 0 |
dec_illegal |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
dec_branch_taken |
Input |
|
|
- |
Register clk |
- |
Fanout : 0 |
dec_busy |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
dec_flush |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
occupancy 5 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
occupancy_lock |
Output |
Occupancy tracker IOs |
|
- |
Combinatorial |
- |
Fanout : 0 |
occupancy_exec |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
occupancy_rd |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
occupancy_rs1 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
occupancy_rs2 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
reg 4 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
reg_ra0 |
Output |
Register file IO |
|
|
Combinatorial |
- |
Fanout : 0 |
reg_ra1 |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
reg_rd0 |
Input |
|
|
|
Register clk |
- |
Fanout : 0 |
reg_rd1 |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu0 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu0_arg0 |
Output |
ALU IOs |
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu0_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu0_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu0_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu0_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu0_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu0_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu0_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1 9 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu1_arg0 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu1_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu1_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu1_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu1_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu1_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu1_predict_in |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu1_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu2_arg0 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu2_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu2_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu2_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu2_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu2_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu2_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu3_arg0 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu3_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu3_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu3_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu3_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu3_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu3_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu4_arg0 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu4_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu4_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu4_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu4_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu4_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu4_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5 8 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu5_arg0 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu5_arg1 |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu5_addr |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu5_imm |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu5_cmd |
Output |
|
|
- |
Register clk rst_n |
- |
Fanout : 0 |
alu5_rd |
Output |
|
|
|
Register clk rst_n |
- |
Fanout : 0 |
alu5_busy |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
halt 2 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
halt_needed |
Output |
To commiter |
|
- |
Combinatorial |
- |
Fanout : 0 |
halt_pending |
Input |
TRAP handling |
|
- |
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 3 elements
• Process 1 Clocked Clocked by clk Reset by rst_n
First, some logic to store the input from the decoder into the waiting stage
• Process 2 Combinatorial
- -
• Process 3 Clocked Clocked by clk Reset by rst_n
Latching the alu commands into the right bus :
Signals¶
Signals list 14 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
prog_enabled |
|
|
- |
Register clk rst_n |
Fanout : 0 |
arg1_imm |
|
|
- |
Combinatorial |
Fanout : 0 |
next 5 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
next_alu |
Flows controls |
|
- |
Combinatorial |
Fanout : 0 |
alu 4 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
next_alu_addr |
Registers for the output stage : |
|
|
Register clk rst_n |
Fanout : 0 |
next_alu_imm |
|
|
|
Register clk rst_n |
Fanout : 0 |
next_alu_cmd |
|
|
- |
Register clk rst_n |
Fanout : 0 |
next_alu_rd |
|
|
|
Register clk rst_n |
Fanout : 0 |
r/dec 7 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
r_dec_rs1 |
Storage registers |
|
|
Register clk rst_n |
Fanout : 0 |
r_dec_rs2 |
|
|
|
Register clk rst_n |
Fanout : 0 |
r_dec_rd |
|
|
|
Register clk rst_n |
Fanout : 0 |
r_dec_imm |
|
|
|
Register clk rst_n |
Fanout : 0 |
r_dec_address |
|
|
|
Register clk rst_n |
Fanout : 0 |
r_dec_opcode |
|
|
- |
Register clk rst_n |
Fanout : 0 |
r_dec_branch_taken |
|
|
- |
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
issuer <name> (
.clk (i_clk),
.rst_n (i_rst_n),
.dec_rs1 (i_dec_rs1),
.dec_rs2 (i_dec_rs2),
.dec_rd (i_dec_rd),
.dec_imm (i_dec_imm),
.dec_address (i_dec_address),
.dec_opcode (i_dec_opcode),
.dec_illegal (i_dec_illegal),
.dec_branch_taken (i_dec_branch_taken),
.dec_busy (i_dec_busy),
.dec_flush (i_dec_flush),
.occupancy_lock (i_occupancy_lock),
.occupancy_exec (i_occupancy_exec),
.occupancy_rd (i_occupancy_rd),
.occupancy_rs1 (i_occupancy_rs1),
.occupancy_rs2 (i_occupancy_rs2),
.reg_ra0 (i_reg_ra0),
.reg_ra1 (i_reg_ra1),
.reg_rd0 (i_reg_rd0),
.reg_rd1 (i_reg_rd1),
.alu0_arg0 (i_alu0_arg0),
.alu0_arg1 (i_alu0_arg1),
.alu0_addr (i_alu0_addr),
.alu0_imm (i_alu0_imm),
.alu0_cmd (i_alu0_cmd),
.alu0_rd (i_alu0_rd),
.alu0_busy (i_alu0_busy),
.alu0_error (i_alu0_error),
.alu1_arg0 (i_alu1_arg0),
.alu1_arg1 (i_alu1_arg1),
.alu1_addr (i_alu1_addr),
.alu1_imm (i_alu1_imm),
.alu1_cmd (i_alu1_cmd),
.alu1_rd (i_alu1_rd),
.alu1_predict_in (i_alu1_predict_in),
.alu1_busy (i_alu1_busy),
.alu1_error (i_alu1_error),
.alu2_arg0 (i_alu2_arg0),
.alu2_arg1 (i_alu2_arg1),
.alu2_addr (i_alu2_addr),
.alu2_imm (i_alu2_imm),
.alu2_cmd (i_alu2_cmd),
.alu2_rd (i_alu2_rd),
.alu2_busy (i_alu2_busy),
.alu2_error (i_alu2_error),
.alu3_arg0 (i_alu3_arg0),
.alu3_arg1 (i_alu3_arg1),
.alu3_addr (i_alu3_addr),
.alu3_imm (i_alu3_imm),
.alu3_cmd (i_alu3_cmd),
.alu3_rd (i_alu3_rd),
.alu3_busy (i_alu3_busy),
.alu3_error (i_alu3_error),
.alu4_arg0 (i_alu4_arg0),
.alu4_arg1 (i_alu4_arg1),
.alu4_addr (i_alu4_addr),
.alu4_imm (i_alu4_imm),
.alu4_cmd (i_alu4_cmd),
.alu4_rd (i_alu4_rd),
.alu4_busy (i_alu4_busy),
.alu4_error (i_alu4_error),
.alu5_arg0 (i_alu5_arg0),
.alu5_arg1 (i_alu5_arg1),
.alu5_addr (i_alu5_addr),
.alu5_imm (i_alu5_imm),
.alu5_cmd (i_alu5_cmd),
.alu5_rd (i_alu5_rd),
.alu5_busy (i_alu5_busy),
.alu5_error (i_alu5_error),
.halt_needed (i_halt_needed),
.flush_needed (i_flush_needed),
.halt_pending (i_halt_pending),
.commit_err (i_commit_err),
.PC_ovf (i_PC_ovf)
);
<name>: entity work.issuer
port map (
clk => i_clk,
rst_n => i_rst_n,
dec_rs1 => i_dec_rs1,
dec_rs2 => i_dec_rs2,
dec_rd => i_dec_rd,
dec_imm => i_dec_imm,
dec_address => i_dec_address,
dec_opcode => i_dec_opcode,
dec_illegal => i_dec_illegal,
dec_branch_taken => i_dec_branch_taken,
dec_busy => i_dec_busy,
dec_flush => i_dec_flush,
occupancy_lock => i_occupancy_lock,
occupancy_exec => i_occupancy_exec,
occupancy_rd => i_occupancy_rd,
occupancy_rs1 => i_occupancy_rs1,
occupancy_rs2 => i_occupancy_rs2,
reg_ra0 => i_reg_ra0,
reg_ra1 => i_reg_ra1,
reg_rd0 => i_reg_rd0,
reg_rd1 => i_reg_rd1,
alu0_arg0 => i_alu0_arg0,
alu0_arg1 => i_alu0_arg1,
alu0_addr => i_alu0_addr,
alu0_imm => i_alu0_imm,
alu0_cmd => i_alu0_cmd,
alu0_rd => i_alu0_rd,
alu0_busy => i_alu0_busy,
alu0_error => i_alu0_error,
alu1_arg0 => i_alu1_arg0,
alu1_arg1 => i_alu1_arg1,
alu1_addr => i_alu1_addr,
alu1_imm => i_alu1_imm,
alu1_cmd => i_alu1_cmd,
alu1_rd => i_alu1_rd,
alu1_predict_in => i_alu1_predict_in,
alu1_busy => i_alu1_busy,
alu1_error => i_alu1_error,
alu2_arg0 => i_alu2_arg0,
alu2_arg1 => i_alu2_arg1,
alu2_addr => i_alu2_addr,
alu2_imm => i_alu2_imm,
alu2_cmd => i_alu2_cmd,
alu2_rd => i_alu2_rd,
alu2_busy => i_alu2_busy,
alu2_error => i_alu2_error,
alu3_arg0 => i_alu3_arg0,
alu3_arg1 => i_alu3_arg1,
alu3_addr => i_alu3_addr,
alu3_imm => i_alu3_imm,
alu3_cmd => i_alu3_cmd,
alu3_rd => i_alu3_rd,
alu3_busy => i_alu3_busy,
alu3_error => i_alu3_error,
alu4_arg0 => i_alu4_arg0,
alu4_arg1 => i_alu4_arg1,
alu4_addr => i_alu4_addr,
alu4_imm => i_alu4_imm,
alu4_cmd => i_alu4_cmd,
alu4_rd => i_alu4_rd,
alu4_busy => i_alu4_busy,
alu4_error => i_alu4_error,
alu5_arg0 => i_alu5_arg0,
alu5_arg1 => i_alu5_arg1,
alu5_addr => i_alu5_addr,
alu5_imm => i_alu5_imm,
alu5_cmd => i_alu5_cmd,
alu5_rd => i_alu5_rd,
alu5_busy => i_alu5_busy,
alu5_error => i_alu5_error,
halt_needed => i_halt_needed,
flush_needed => i_flush_needed,
halt_pending => i_halt_pending,
commit_err => i_commit_err,
PC_ovf => i_PC_ovf
);
Source¶
Raw source Full file
/*
* File : rtl/core/issuer.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the issuer module, the one charged to
* split incomming instructions into the right ALU, and start
* as many instruction as it can to get the maximal performance
* available from the core.
*/
import core_config_pkg::XLEN;
import core_config_pkg::alu_commands_t;
module issuer (
input logic clk,
input logic rst_n,
// Decoders IOs
input logic [(REG_ADDR_W - 1) : 0] dec_rs1,
input logic [(REG_ADDR_W - 1) : 0] dec_rs2,
input logic [(REG_ADDR_W - 1) : 0] dec_rd,
input logic [ (XLEN - 1) : 0] dec_imm,
input logic [ (XLEN - 1) : 0] dec_address,
input opcodes_t dec_opcode,
input logic dec_illegal,
input logic dec_branch_taken,
output logic dec_busy,
output logic dec_flush,
// Occupancy tracker IOs
output logic occupancy_lock,
input logic occupancy_exec,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] occupancy_rd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] occupancy_rs1,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] occupancy_rs2,
// Register file IO
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] reg_ra0,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] reg_ra1,
input logic [ (core_config_pkg::XLEN - 1) : 0] reg_rd0,
input logic [ (core_config_pkg::XLEN - 1) : 0] reg_rd1,
// ALU IOs
output logic [ (core_config_pkg::XLEN - 1) : 0] alu0_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu0_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu0_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu0_imm,
output alu_commands_t alu0_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu0_rd,
input logic alu0_busy,
input logic alu0_error,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu1_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu1_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu1_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu1_imm,
output alu_commands_t alu1_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu1_rd,
output logic alu1_predict_in,
input logic alu1_busy,
input logic alu1_error,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu2_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu2_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu2_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu2_imm,
output alu_commands_t alu2_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu2_rd,
input logic alu2_busy,
input logic alu2_error,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu3_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu3_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu3_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu3_imm,
output alu_commands_t alu3_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu3_rd,
input logic alu3_busy,
input logic alu3_error,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu4_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu4_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu4_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu4_imm,
output alu_commands_t alu4_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu4_rd,
input logic alu4_busy,
input logic alu4_error,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu5_arg0,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu5_arg1,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu5_addr,
output logic [ (core_config_pkg::XLEN - 1) : 0] alu5_imm,
output alu_commands_t alu5_cmd,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu5_rd,
input logic alu5_busy,
input logic alu5_error,
// To commiter
output logic halt_needed,
input logic flush_needed,
// TRAP handling
input logic halt_pending,
input logic commit_err,
input logic PC_ovf
);
/*
* Storage types :
*/
typedef enum logic [3:0] {
ALU0,
ALU1,
ALU2,
ALU4,
ALU5,
NONE
} alu_t;
/*
* Flows controls
*/
alu_t next_alu;
logic prog_enabled;
/*
* Storage registers
*/
logic [(REG_ADDR_W - 1) : 0] r_dec_rs1;
logic [(REG_ADDR_W - 1) : 0] r_dec_rs2;
logic [(REG_ADDR_W - 1) : 0] r_dec_rd;
logic [ (XLEN - 1) : 0] r_dec_imm;
logic [ (XLEN - 1) : 0] r_dec_address;
opcodes_t r_dec_opcode;
logic r_dec_branch_taken;
/*
* First, some logic to store the input from the decoder into the waiting stage
*/
always_ff @(posedge clk or negedge rst_n or negedge flush_needed) begin
if (!rst_n || !flush_needed) begin
r_dec_rs1 <= '0;
r_dec_rs2 <= '0;
r_dec_rd <= '0;
r_dec_imm <= '0;
r_dec_address <= '0;
r_dec_opcode <= core_config_pkg::i_NOP;
r_dec_branch_taken <= 1'b0;
end else if (occupancy_exec && prog_enabled) begin
r_dec_rs1 <= dec_rs1;
r_dec_rs2 <= dec_rs2;
r_dec_rd <= dec_rd;
r_dec_imm <= dec_imm;
r_dec_address <= dec_address;
r_dec_opcode <= dec_opcode;
r_dec_branch_taken <= dec_branch_taken;
end
end
/*
* Registers for the output stage :
*/
logic [ (core_config_pkg::XLEN - 1) : 0] next_alu_addr;
logic [ (core_config_pkg::XLEN - 1) : 0] next_alu_imm;
alu_commands_t next_alu_cmd;
logic [(core_config_pkg::REG_ADDR_W - 1) : 0] next_alu_rd;
logic arg1_imm;
/*
* Then, some logic to remove any conflicts. This is done within the
* occupancy module, and return a bit : occupancy_exec that we directly
* use a evolution enabled bit.
*/
always_comb begin
// Asking the occupancy tracker the next required bit.
occupancy_lock = 1'b1;
occupancy_rd = r_dec_rd;
occupancy_rs1 = r_dec_rs1;
occupancy_rs2 = r_dec_rs2;
// Asking the register file to output the right data
reg_ra0 = r_dec_rs1;
reg_ra1 = r_dec_rs2;
// Defaults :
next_alu_cmd = core_config_pkg::c_NONE;
next_alu_addr = r_dec_address;
next_alu_rd = r_dec_rd;
next_alu_imm = r_dec_imm;
next_alu = NONE;
arg1_imm = 1'b0; // We select the arg1 by default.
// Decide which ALU is the next :
unique case (r_dec_opcode)
core_config_pkg::i_NOP, core_config_pkg::i_FENCE: begin
next_alu = ALU0;
next_alu_rd = 0; // This writeback will be ignored anyway, so not risk of executing unwanted op.
end
/*
* ALU 0
*/
core_config_pkg::i_LUI,
core_config_pkg::i_AUIPC,
core_config_pkg::i_ADDI,
core_config_pkg::i_XORI,
core_config_pkg::i_ORI,
core_config_pkg::i_ANDI : begin
next_alu = ALU0;
arg1_imm = 1'b1;
end
core_config_pkg::i_ADD,
core_config_pkg::i_SUB,
core_config_pkg::i_OR,
core_config_pkg::i_AND,
core_config_pkg::i_XOR :
next_alu = ALU0;
/*
* ALU 1
*/
core_config_pkg::i_SLTI,
core_config_pkg::i_SLTIU,
core_config_pkg::i_JAL,
core_config_pkg::i_JALR : begin
next_alu = ALU1;
arg1_imm = 1'b1;
end
core_config_pkg::i_SLT,
core_config_pkg::i_SLTU,
core_config_pkg::i_BEQ,
core_config_pkg::i_BNE,
core_config_pkg::i_BLT,
core_config_pkg::i_BGE,
core_config_pkg::i_BLTU,
core_config_pkg::i_BGEU,
core_config_pkg::i_ECALL,
core_config_pkg::i_EBREAK,
core_config_pkg::i_MRET: begin
next_alu = ALU1;
end
/*
* ALU 2 & 3
*/
core_config_pkg::i_SLLI, core_config_pkg::i_SRAI, core_config_pkg::i_SRLI: begin
next_alu = ALU2;
arg1_imm = 1'b1;
end
core_config_pkg::i_SLL,
core_config_pkg::i_SRL,
core_config_pkg::i_SRA ,
core_config_pkg::i_MUL,
core_config_pkg::i_MULH,
core_config_pkg::i_MULHU,
core_config_pkg::i_MULHSU,
core_config_pkg::i_DIV,
core_config_pkg::i_DIVU,
core_config_pkg::i_REM,
core_config_pkg::i_REMU :
next_alu = ALU2;
/*
* ALU 4
*/
core_config_pkg::i_CSRRWI, core_config_pkg::i_CSRRSI, core_config_pkg::i_CSRRCI: begin
next_alu = ALU4;
arg1_imm = 1'b1;
end
core_config_pkg::i_CSRRW, core_config_pkg::i_CSRRS, core_config_pkg::i_CSRRC:
next_alu = ALU4;
/*
* ALU 5
*/
core_config_pkg::i_LB,
core_config_pkg::i_LH,
core_config_pkg::i_LW,
core_config_pkg::i_LBU,
core_config_pkg::i_LHU,
core_config_pkg::i_SB,
core_config_pkg::i_SH,
core_config_pkg::i_SW :
next_alu = ALU5;
endcase
// Decide the next alu command :
/*
* Since the ENUMS aren't the same, this cause a lot of logic. Could vastly be
* optimized away by changing the alu_commands_t to the raw instruction into the
* ALUs, and then, just copy.
* For a first version, it's done like that, and if that don't cause timing issues,
* well'see.
*/
unique case (r_dec_opcode)
// Theses instructions are treated as NOP.
core_config_pkg::i_NOP, core_config_pkg::i_FENCE: next_alu_cmd = core_config_pkg::c_ADD;
/*
* ALU 0
*/
core_config_pkg::i_LUI,
core_config_pkg::i_AUIPC,
core_config_pkg::i_ADDI,
core_config_pkg::i_ADD :
next_alu_cmd = core_config_pkg::c_ADD;
core_config_pkg::i_XORI, core_config_pkg::i_XOR: next_alu_cmd = core_config_pkg::c_XOR;
core_config_pkg::i_ANDI, core_config_pkg::i_AND: next_alu_cmd = core_config_pkg::c_AND;
core_config_pkg::i_ORI, core_config_pkg::i_OR: next_alu_cmd = core_config_pkg::c_OR;
core_config_pkg::i_SUB: next_alu_cmd = core_config_pkg::c_SUB;
/*
* ALU 1
*/
core_config_pkg::i_SLT, core_config_pkg::i_SLTI: next_alu_cmd = core_config_pkg::c_SLT;
core_config_pkg::i_SLTU, core_config_pkg::i_SLTIU:
next_alu_cmd = core_config_pkg::c_SLTU;
core_config_pkg::i_BEQ: next_alu_cmd = core_config_pkg::c_BEQ;
core_config_pkg::i_BNE: next_alu_cmd = core_config_pkg::c_BNE;
core_config_pkg::i_BLT: next_alu_cmd = core_config_pkg::c_BLT;
core_config_pkg::i_BGE: next_alu_cmd = core_config_pkg::c_BGE;
core_config_pkg::i_BLTU: next_alu_cmd = core_config_pkg::c_BLTU;
core_config_pkg::i_BGEU: next_alu_cmd = core_config_pkg::c_BGEU;
core_config_pkg::i_JALR: next_alu_cmd = core_config_pkg::c_JALR;
core_config_pkg::i_JAL: next_alu_cmd = core_config_pkg::c_JAL;
core_config_pkg::i_ECALL: next_alu_cmd = core_config_pkg::c_ECALL;
core_config_pkg::i_EBREAK: next_alu_cmd = core_config_pkg::c_EBREAK;
core_config_pkg::i_MRET: next_alu_cmd = core_config_pkg::c_MRET;
/*
* ALU 2 & 3
*/
core_config_pkg::i_SLL, core_config_pkg::i_SLLI: next_alu_cmd = core_config_pkg::c_SLL;
core_config_pkg::i_SRL, core_config_pkg::i_SRLI: next_alu_cmd = core_config_pkg::c_SRL;
core_config_pkg::i_SRA, core_config_pkg::i_SRAI: next_alu_cmd = core_config_pkg::c_SRA;
core_config_pkg::i_MUL: next_alu_cmd = core_config_pkg::c_MUL;
core_config_pkg::i_MULH: next_alu_cmd = core_config_pkg::c_MULH;
core_config_pkg::i_MULHU: next_alu_cmd = core_config_pkg::c_MULHU;
core_config_pkg::i_MULHSU: next_alu_cmd = core_config_pkg::c_MULHSU;
core_config_pkg::i_DIV: next_alu_cmd = core_config_pkg::c_DIV;
core_config_pkg::i_DIVU: next_alu_cmd = core_config_pkg::c_DIVU;
core_config_pkg::i_REM: next_alu_cmd = core_config_pkg::c_REM;
core_config_pkg::i_REMU: next_alu_cmd = core_config_pkg::c_REMU;
/*
* ALU 4
*/
core_config_pkg::i_CSRRW, core_config_pkg::i_CSRRWI:
next_alu_cmd = core_config_pkg::c_CSRRW;
core_config_pkg::i_CSRRS, core_config_pkg::i_CSRRSI:
next_alu_cmd = core_config_pkg::c_CSRRS;
core_config_pkg::i_CSRRC, core_config_pkg::i_CSRRCI:
next_alu_cmd = core_config_pkg::c_CSRRC;
/*
* ALU 5
*/
core_config_pkg::i_LB: next_alu_cmd = core_config_pkg::c_LB;
core_config_pkg::i_LH: next_alu_cmd = core_config_pkg::c_LH;
core_config_pkg::i_LW: next_alu_cmd = core_config_pkg::c_LW;
core_config_pkg::i_LBU: next_alu_cmd = core_config_pkg::c_LBU;
core_config_pkg::i_LHU: next_alu_cmd = core_config_pkg::c_LHU;
core_config_pkg::i_SB: next_alu_cmd = core_config_pkg::c_SB;
core_config_pkg::i_SH: next_alu_cmd = core_config_pkg::c_SH;
core_config_pkg::i_SW: next_alu_cmd = core_config_pkg::c_SW;
endcase
end
/*
* Latching the alu commands into the right bus :
*/
always_ff @(posedge clk or negedge rst_n or negedge flush_needed) begin
if (!rst_n || !flush_needed) begin
alu0_arg0 <= '0;
alu0_arg1 <= '0;
alu0_addr <= '0;
alu0_imm <= '0;
alu0_cmd <= core_config_pkg::c_NONE;
alu0_rd <= '0;
alu1_arg0 <= '0;
alu1_arg1 <= '0;
alu1_addr <= '0;
alu1_imm <= '0;
alu1_cmd <= core_config_pkg::c_NONE;
alu1_rd <= '0;
alu2_arg0 <= '0;
alu2_arg1 <= '0;
alu2_addr <= '0;
alu2_imm <= '0;
alu2_cmd <= core_config_pkg::c_NONE;
alu2_rd <= '0;
alu3_arg0 <= '0;
alu3_arg1 <= '0;
alu3_addr <= '0;
alu3_imm <= '0;
alu3_cmd <= core_config_pkg::c_NONE;
alu3_rd <= '0;
alu4_arg0 <= '0;
alu4_arg1 <= '0;
alu4_addr <= '0;
alu4_imm <= '0;
alu4_cmd <= core_config_pkg::c_NONE;
alu4_rd <= '0;
alu5_arg0 <= '0;
alu5_arg1 <= '0;
alu5_addr <= '0;
alu5_imm <= '0;
alu5_cmd <= core_config_pkg::c_NONE;
alu5_rd <= '0;
prog_enabled <= 1'b1;
end else if (occupancy_exec) begin
// Assign some defaults to the outpu
alu0_arg0 <= '0;
alu0_arg1 <= '0;
alu0_addr <= '0;
alu0_imm <= '0;
alu0_cmd <= core_config_pkg::c_NONE;
alu0_rd <= '0;
alu1_arg0 <= '0;
alu1_arg1 <= '0;
alu1_addr <= '0;
alu1_imm <= '0;
alu1_cmd <= core_config_pkg::c_NONE;
alu1_rd <= '0;
alu2_arg0 <= '0;
alu2_arg1 <= '0;
alu2_addr <= '0;
alu2_imm <= '0;
alu2_cmd <= core_config_pkg::c_NONE;
alu2_rd <= '0;
alu3_arg0 <= '0;
alu3_arg1 <= '0;
alu3_addr <= '0;
alu3_imm <= '0;
alu3_cmd <= core_config_pkg::c_NONE;
alu3_rd <= '0;
alu4_arg0 <= '0;
alu4_arg1 <= '0;
alu4_addr <= '0;
alu4_imm <= '0;
alu4_cmd <= core_config_pkg::c_NONE;
alu4_rd <= '0;
alu5_arg0 <= '0;
alu5_arg1 <= '0;
alu5_addr <= '0;
alu5_imm <= '0;
alu5_cmd <= core_config_pkg::c_NONE;
alu5_rd <= '0;
alu1_predict_in <= r_dec_branch_taken;
if (next_alu == ALU0) begin
if (!alu0_busy) begin
alu0_arg0 <= reg_rd0;
alu0_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu0_addr <= next_alu_addr;
alu0_imm <= next_alu_imm;
alu0_cmd <= next_alu_cmd;
alu0_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else begin
alu0_arg0 <= '0;
alu0_arg1 <= '0;
alu0_addr <= '0;
alu0_imm <= '0;
alu0_cmd <= core_config_pkg::c_NONE;
alu0_rd <= '0;
prog_enabled <= 1'b0;
end
end
if (next_alu == ALU1) begin
if (!alu1_busy) begin
alu1_arg0 <= reg_rd0;
alu1_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu1_addr <= next_alu_addr;
alu1_imm <= next_alu_imm;
alu1_cmd <= next_alu_cmd;
alu1_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else begin
alu1_arg0 <= '0;
alu1_arg1 <= '0;
alu1_addr <= '0;
alu1_imm <= '0;
alu1_cmd <= core_config_pkg::c_NONE;
alu1_rd <= '0;
prog_enabled <= 1'b0;
end
end
if (next_alu == ALU2) begin // This case also include ALU3, which don't exist as an enum member.
if (!alu2_busy) begin
alu2_arg0 <= reg_rd0;
alu2_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu2_addr <= next_alu_addr;
alu2_imm <= next_alu_imm;
alu2_cmd <= next_alu_cmd;
alu2_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else if (!alu3_busy) begin
alu3_arg0 <= reg_rd0;
alu3_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu3_addr <= next_alu_addr;
alu3_imm <= next_alu_imm;
alu3_cmd <= next_alu_cmd;
alu3_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else begin
prog_enabled <= 1'b0;
end
end
if (next_alu == ALU4) begin
if (!alu4_busy) begin
alu4_arg0 <= reg_rd0;
alu4_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu4_addr <= next_alu_addr;
alu4_imm <= next_alu_imm;
alu4_cmd <= next_alu_cmd;
alu4_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else begin
alu4_arg0 <= '0;
alu4_arg1 <= '0;
alu4_addr <= '0;
alu4_imm <= '0;
alu4_cmd <= core_config_pkg::c_NONE;
alu4_rd <= '0;
prog_enabled <= 1'b0;
end
end
if (next_alu == ALU5) begin
if (!alu5_busy) begin
alu5_arg0 <= reg_rd0;
alu5_arg1 <= (arg1_imm) ? next_alu_imm : reg_rd1;
alu5_addr <= next_alu_addr;
alu5_imm <= next_alu_imm;
alu5_cmd <= next_alu_cmd;
alu5_rd <= next_alu_rd;
prog_enabled <= 1'b1;
end else begin
alu5_arg0 <= '0;
alu5_arg1 <= '0;
alu5_addr <= '0;
alu5_imm <= '0;
alu5_cmd <= core_config_pkg::c_NONE;
alu5_rd <= '0;
prog_enabled <= 1'b0;
end
end
end
end
assign dec_busy = ~prog_enabled;
assign halt_needed = |{alu0_error, alu1_error, alu2_error, alu3_error, alu4_error, alu5_error, halt_pending, dec_illegal, commit_err, PC_ovf} & 1'b0;
assign dec_flush = flush_needed;
endmodule
commiter¶
commiter.sv
commiter module
Imports¶
Imports 2 elements
core_config_pkg XLEN IF_TRAP_UCODE
Ports¶
Ports list 53 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
Standard interface |
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
halt_needed |
Input |
General purpose IO |
|
- |
Combinatorial |
- |
Fanout : 0 |
issuer_flush |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
commit_err |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu0 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu0_error |
Input |
ALU interfaces |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu0_valid |
Input |
verilator lint_off UNUSEDSIGNAL |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu0_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu0_jmp |
Input |
verilator lint_on UNUSEDSIGNAL |
|
|
Combinatorial |
- |
Fanout : 0 |
alu0_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu0_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu0_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu1_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1_valid |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu1_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu1_jmp |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu1_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu1_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu2_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2_valid |
Input |
verilator lint_off UNUSEDSIGNAL |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu2_jmp |
Input |
verilator lint_on UNUSEDSIGNAL |
|
|
Combinatorial |
- |
Fanout : 0 |
alu2_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu2_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu2_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu3_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3_valid |
Input |
verilator lint_off UNUSEDSIGNAL |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu3_jmp |
Input |
verilator lint_on UNUSEDSIGNAL |
|
|
Combinatorial |
- |
Fanout : 0 |
alu3_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu3_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu3_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu4_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4_valid |
Input |
verilator lint_off UNUSEDSIGNAL |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu4_jmp |
Input |
verilator lint_on UNUSEDSIGNAL |
|
|
Combinatorial |
- |
Fanout : 0 |
alu4_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu4_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu4_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
alu5_error |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5_valid |
Input |
verilator lint_off UNUSEDSIGNAL |
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5_req |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
alu5_jmp |
Input |
verilator lint_on UNUSEDSIGNAL |
|
|
Combinatorial |
- |
Fanout : 0 |
alu5_res |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu5_rd |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
alu5_clear |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
reg 3 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
reg_data |
Output |
Register file interface |
|
|
Combinatorial |
- |
Fanout : 0 |
reg_addr |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
reg_we |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
pc 3 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
pc_value |
Output |
Program counter overwrite |
|
|
Combinatorial |
- |
Fanout : 0 |
pc_enable |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
pc_we |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 3 elements
• Process 1 Combinatorial
- -
• Process 2 Clocked Clocked by clk Reset by rst_n
- -
• Process 3 Combinatorial
- -
Signals¶
Signals list 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
last_active_alu |
Storages |
|
- |
Register clk rst_n |
Fanout : 0 |
active_alu |
|
|
- |
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
commiter <name> (
.clk (i_clk),
.rst_n (i_rst_n),
.alu0_error (i_alu0_error),
.alu0_valid (i_alu0_valid),
.alu0_req (i_alu0_req),
.alu0_jmp (i_alu0_jmp),
.alu0_res (i_alu0_res),
.alu0_rd (i_alu0_rd),
.alu0_clear (i_alu0_clear),
.alu1_error (i_alu1_error),
.alu1_valid (i_alu1_valid),
.alu1_req (i_alu1_req),
.alu1_res (i_alu1_res),
.alu1_jmp (i_alu1_jmp),
.alu1_rd (i_alu1_rd),
.alu1_clear (i_alu1_clear),
.alu2_error (i_alu2_error),
.alu2_valid (i_alu2_valid),
.alu2_req (i_alu2_req),
.alu2_jmp (i_alu2_jmp),
.alu2_res (i_alu2_res),
.alu2_rd (i_alu2_rd),
.alu2_clear (i_alu2_clear),
.alu3_error (i_alu3_error),
.alu3_valid (i_alu3_valid),
.alu3_req (i_alu3_req),
.alu3_jmp (i_alu3_jmp),
.alu3_res (i_alu3_res),
.alu3_rd (i_alu3_rd),
.alu3_clear (i_alu3_clear),
.alu4_error (i_alu4_error),
.alu4_valid (i_alu4_valid),
.alu4_req (i_alu4_req),
.alu4_jmp (i_alu4_jmp),
.alu4_res (i_alu4_res),
.alu4_rd (i_alu4_rd),
.alu4_clear (i_alu4_clear),
.alu5_error (i_alu5_error),
.alu5_valid (i_alu5_valid),
.alu5_req (i_alu5_req),
.alu5_jmp (i_alu5_jmp),
.alu5_res (i_alu5_res),
.alu5_rd (i_alu5_rd),
.alu5_clear (i_alu5_clear),
.reg_data (i_reg_data),
.reg_addr (i_reg_addr),
.reg_we (i_reg_we),
.pc_value (i_pc_value),
.pc_enable (i_pc_enable),
.pc_we (i_pc_we),
.halt_needed (i_halt_needed),
.issuer_flush (i_issuer_flush),
.commit_err (i_commit_err)
);
<name>: entity work.commiter
port map (
clk => i_clk,
rst_n => i_rst_n,
alu0_error => i_alu0_error,
alu0_valid => i_alu0_valid,
alu0_req => i_alu0_req,
alu0_jmp => i_alu0_jmp,
alu0_res => i_alu0_res,
alu0_rd => i_alu0_rd,
alu0_clear => i_alu0_clear,
alu1_error => i_alu1_error,
alu1_valid => i_alu1_valid,
alu1_req => i_alu1_req,
alu1_res => i_alu1_res,
alu1_jmp => i_alu1_jmp,
alu1_rd => i_alu1_rd,
alu1_clear => i_alu1_clear,
alu2_error => i_alu2_error,
alu2_valid => i_alu2_valid,
alu2_req => i_alu2_req,
alu2_jmp => i_alu2_jmp,
alu2_res => i_alu2_res,
alu2_rd => i_alu2_rd,
alu2_clear => i_alu2_clear,
alu3_error => i_alu3_error,
alu3_valid => i_alu3_valid,
alu3_req => i_alu3_req,
alu3_jmp => i_alu3_jmp,
alu3_res => i_alu3_res,
alu3_rd => i_alu3_rd,
alu3_clear => i_alu3_clear,
alu4_error => i_alu4_error,
alu4_valid => i_alu4_valid,
alu4_req => i_alu4_req,
alu4_jmp => i_alu4_jmp,
alu4_res => i_alu4_res,
alu4_rd => i_alu4_rd,
alu4_clear => i_alu4_clear,
alu5_error => i_alu5_error,
alu5_valid => i_alu5_valid,
alu5_req => i_alu5_req,
alu5_jmp => i_alu5_jmp,
alu5_res => i_alu5_res,
alu5_rd => i_alu5_rd,
alu5_clear => i_alu5_clear,
reg_data => i_reg_data,
reg_addr => i_reg_addr,
reg_we => i_reg_we,
pc_value => i_pc_value,
pc_enable => i_pc_enable,
pc_we => i_pc_we,
halt_needed => i_halt_needed,
issuer_flush => i_issuer_flush,
commit_err => i_commit_err
);
Source¶
Raw source Full file
/*
* File : rtl/core/commiter.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the commit module, the one who's
* charged to handle the ALU outputs and the registers write-back.
* It also expose an address load bus, in case a branch instruction
* was mispredicted, and we need to flush the pipeline.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
import core_config_pkg::IF_TRAP_UCODE;
module commiter (
// Standard interface
input logic clk,
input logic rst_n,
// ALU interfaces
input logic alu0_error,
input logic alu0_valid,
/* verilator lint_off UNUSEDSIGNAL */
input logic alu0_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu0_jmp,
/* verilator lint_on UNUSEDSIGNAL */
input logic [ (core_config_pkg::XLEN - 1) : 0] alu0_res,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu0_rd,
output logic alu0_clear,
input logic alu1_error,
input logic alu1_valid,
input logic alu1_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu1_res,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu1_jmp,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu1_rd,
output logic alu1_clear,
input logic alu2_error,
input logic alu2_valid,
/* verilator lint_off UNUSEDSIGNAL */
input logic alu2_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu2_jmp,
/* verilator lint_on UNUSEDSIGNAL */
input logic [ (core_config_pkg::XLEN - 1) : 0] alu2_res,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu2_rd,
output logic alu2_clear,
input logic alu3_error,
input logic alu3_valid,
/* verilator lint_off UNUSEDSIGNAL */
input logic alu3_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu3_jmp,
/* verilator lint_on UNUSEDSIGNAL */
input logic [ (core_config_pkg::XLEN - 1) : 0] alu3_res,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu3_rd,
output logic alu3_clear,
input logic alu4_error,
input logic alu4_valid,
/* verilator lint_off UNUSEDSIGNAL */
input logic alu4_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu4_jmp,
/* verilator lint_on UNUSEDSIGNAL */
input logic [ (core_config_pkg::XLEN - 1) : 0] alu4_res,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu4_rd,
output logic alu4_clear,
input logic alu5_error,
input logic alu5_valid,
/* verilator lint_off UNUSEDSIGNAL */
input logic alu5_req,
input logic [ (core_config_pkg::XLEN - 1) : 0] alu5_jmp,
/* verilator lint_on UNUSEDSIGNAL */
input logic [ (core_config_pkg::XLEN - 1) : 0] alu5_res,
input logic [(core_config_pkg::REG_ADDR_W - 1) : 0] alu5_rd,
output logic alu5_clear,
// Register file interface
output logic [ (core_config_pkg::XLEN - 1) : 0] reg_data,
output logic [(core_config_pkg::REG_ADDR_W - 1) : 0] reg_addr,
output logic reg_we,
// Program counter overwrite
output logic [(core_config_pkg::XLEN - 1) : 0] pc_value,
output logic pc_enable,
output logic pc_we,
// General purpose IO
input logic halt_needed,
output logic issuer_flush,
output logic commit_err
);
/*
* Defining the active_ALU type
*/
typedef enum logic [2:0] {
ALU0,
ALU1,
ALU2,
ALU3,
ALU4,
ALU5,
NONE,
ALL
} alu_t;
/*
* Storages
*/
alu_t last_active_alu;
alu_t active_alu;
/*
* First, some combinational logic to choose the ALU that will get the right
* to output it's data.
*
* Note : The ALU aren't ordered, that's because we prioritize the ALU's
* with the most critical functions. First, the branches conditions,
* because they could influes on the program counter outputs !
* Then, the long operations (MUL, DIV...) to ensure we liberate them
* the fastest as possible. And then, the remaining ALUs.
*/
always_comb begin
if (halt_needed) begin
active_alu = ALL;
reg_data = '0;
reg_addr = '0;
reg_we = 1'b0;
pc_value = core_config_pkg::IF_TRAP_UCODE;
pc_we = 1'b1;
issuer_flush = 1'b1;
end else begin
if (alu1_valid) begin
active_alu = ALU1;
reg_data = (alu1_req) ? '0 : alu1_res;
reg_addr = (alu1_req) ? '0 : alu1_rd;
reg_we = (alu1_req) ? 1'b0 : 1'b1;
pc_value = (alu1_req) ? alu1_jmp : '0;
pc_we = (alu1_req) ? 1'b1 : 1'b0;
issuer_flush = (alu1_req) ? 1'b1 : 1'b0;
end else if (alu2_valid) begin
active_alu = ALU2;
reg_data = alu2_res;
reg_addr = alu2_rd;
reg_we = 1'b1;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end else if (alu3_valid) begin
active_alu = ALU3;
reg_data = alu3_res;
reg_addr = alu3_rd;
reg_we = 1'b1;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end else if (alu5_valid) begin
active_alu = ALU5;
reg_data = alu5_res;
reg_addr = alu5_rd;
reg_we = 1'b1;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end else if (alu4_valid) begin
active_alu = ALU4;
reg_data = alu4_res;
reg_addr = alu4_rd;
reg_we = 1'b1;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end else if (alu0_valid) begin
active_alu = ALU0;
reg_data = alu0_res;
reg_addr = alu0_rd;
reg_we = 1'b1;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end else begin
active_alu = NONE;
reg_data = '0;
reg_addr = '0;
reg_we = 1'b0;
pc_value = '0;
pc_we = 1'b0;
issuer_flush = 1'b0;
end
end
end
/*
* Some synchronous logic to handle the clear signal
* to reset the different ALUs.
*
* Note : An additional register may be needed, if the ALU
* does clear it's output too fast.
*/
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
last_active_alu <= NONE;
end else begin
last_active_alu <= active_alu;
end
end
/*
* Some comb logic to just handle with clear signal is active.
* Enable the right ALU, or, in case of ALL, we flush all of them.
*/
always_comb begin
alu0_clear = 1'b0;
alu1_clear = 1'b0;
alu2_clear = 1'b0;
alu3_clear = 1'b0;
alu4_clear = 1'b0;
alu5_clear = 1'b0;
unique case (last_active_alu)
ALU0: alu0_clear = 1'b1;
ALU1: alu1_clear = 1'b1;
ALU2: alu2_clear = 1'b1;
ALU3: alu3_clear = 1'b1;
ALU4: alu4_clear = 1'b1;
ALU5: alu5_clear = 1'b1;
ALL: begin
alu0_clear = 1'b1;
alu1_clear = 1'b1;
alu2_clear = 1'b1;
alu3_clear = 1'b1;
alu4_clear = 1'b1;
alu5_clear = 1'b1;
end
default: ;
endcase
end
// Output the combined output logic, we probably won't handle it.
assign commit_err = |{alu0_error, alu1_error, alu2_error, alu3_error, alu4_error, alu5_error};
assign pc_enable = 1'b1;
endmodule
occupancy¶
occupancy.sv
occupancy module
Imports¶
Imports 3 elements
core_config_pkg XLEN REG_ADDR_W REG_COUNT
Ports¶
Ports list 9 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rst_n |
Input |
target register ID |
|
- |
Combinatorial |
Negative |
Fanout : 0 |
target |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
source1 |
Input |
arg2 |
|
|
Combinatorial |
- |
Fanout : 0 |
source2 |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
exec_ok |
Output |
Lock the target register if all are available |
|
- |
Register clk rst_n |
- |
Fanout : 0 |
lock |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
address |
Input |
Write enable. |
|
|
Combinatorial |
- |
Fanout : 0 |
write |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
Processes¶
Process list 1 element
• Process 1 Clocked Clocked by clk Reset by rst_n
Synchronous set and reset logic to the state register
Signals¶
Signals list 4 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
reg_state |
Storage type |
|
|
Register clk rst_n |
Fanout : 0 |
status0 |
1 is available, 0 is locked. |
|
- |
Combinatorial |
Fanout : 0 |
status1 |
|
|
- |
Combinatorial |
Fanout : 0 |
status2 |
|
|
- |
Combinatorial |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
occupancy <name> (
.clk (i_clk),
.rst_n (i_rst_n),
.target (i_target),
.source1 (i_source1),
.source2 (i_source2),
.exec_ok (i_exec_ok),
.lock (i_lock),
.address (i_address),
.write (i_write)
);
<name>: entity work.occupancy
port map (
clk => i_clk,
rst_n => i_rst_n,
target => i_target,
source1 => i_source1,
source2 => i_source2,
exec_ok => i_exec_ok,
lock => i_lock,
address => i_address,
write => i_write
);
Source¶
Raw source Full file
/*
* File : rtl/core/occupancy.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file define the module that track dependencies between registers.
* This ensure an instruction won't start until all of it's required data is
* available, on both the registers or the bypass.
* In the same manner, it will also track writting dependencies to ensure
* the correct order is present.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
import core_config_pkg::REG_ADDR_W;
import core_config_pkg::REG_COUNT;
module occupancy (
input logic clk,
input logic rst_n,
input logic [(REG_ADDR_W - 1) : 0] target, // target register ID
input logic [(REG_ADDR_W - 1) : 0] source1, // arg1
input logic [(REG_ADDR_W - 1) : 0] source2, // arg2
output logic exec_ok, // set to 1 if the execution is possible
input logic lock, // Lock the target register if all are available
input logic [(REG_ADDR_W - 1) : 0] address, // Address of the written register
input logic write // Write enable.
);
/*
* Storage type
*/
logic [(REG_COUNT - 1) : 0] reg_state; // 1 is available, 0 is locked.
logic status0;
logic status1;
logic status2;
/*
* Using an assign block did show better results than always_comb logic.
*/
assign status0 = reg_state[target];
assign status1 = reg_state[source1];
assign status2 = reg_state[source2];
/*
* Synchronous set and reset logic to the state register
*/
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
reg_state <= 32'hFFFFFFFF; // all availables.
exec_ok <= 0;
end else begin
exec_ok <= status0 && status1 && status2;
/*
* Set logic, if we're OK to lock this register
*/
if (exec_ok && lock) begin
if (target != 0) begin // protect against reserving the register 0
reg_state[target] <= 1'b0;
end
end
/*
* Reset logic, only based on the register access signals.
*/
if (write) begin
reg_state[address] <= 1'b1;
end
end
end
endmodule
ALU Managers¶
core¶
core.sv
core module
Imports¶
Imports 3 elements
core_config_pkg XLEN REG_ADDR_W opcodes_t
Ports¶
Ports list 16 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
clk |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
i_rst_n |
Input |
|
|
- |
Combinatorial |
Negative |
Fanout : 0 |
o_rst_n |
Output |
|
|
- |
Register clk |
Negative |
Fanout : 0 |
instr |
Input |
Program ROM IF |
|
|
Combinatorial |
- |
Fanout : 0 |
rom_addr |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
flush |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
enable |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
rden |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
interrupt_vect |
Input |
Interruption logic |
|
|
Combinatorial |
- |
Fanout : 0 |
mem 7 elements
Name |
Direction |
Description |
Type |
Size |
Kind |
Polarity |
Fanout |
|---|---|---|---|---|---|---|---|
mem_addr |
Output |
Peripherals / RAM interface |
|
|
Combinatorial |
- |
Fanout : 0 |
mem_byteen |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
mem_we |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
mem_req |
Output |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
mem_wdata |
Output |
|
|
|
Combinatorial |
- |
Fanout : 0 |
mem_rdata |
Input |
|
|
|
Combinatorial |
- |
Fanout : 0 |
mem_err |
Input |
|
|
- |
Combinatorial |
- |
Fanout : 0 |
Modules¶
Modules 11 elements
• clock : clk_gen
• pcounter : PC
Instantiating modules for the core
Connections :
• prediction : BPU
Connections :
• delay : instr_delay
• delay : branch_delay
Connections :
• decoder : DEC
• assembly_alu : ALUS
Finally, adding the whole execution logic
Connections :
• endianess : mem_read_cor
Connections :
• endianess : mem_write_cor
Connections :
Signals¶
Signals list 29 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
clk_en |
Global signals |
|
- |
Register clk rst_n |
Fanout : 0 |
if_addr |
BPU |
|
|
Register clk rst_n |
Fanout : 0 |
pc 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
pc_addr |
PC |
|
|
Register clk rst_n |
Fanout : 0 |
pc_ovf |
|
|
- |
Register clk rst_n |
Fanout : 0 |
bpu 4 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
bpu_branch_taken |
Used as output address. |
|
- |
Combinatorial |
Fanout : 0 |
bpu_write_addr |
|
|
|
Register clk rst_n |
Fanout : 0 |
bpu_write |
|
|
- |
Register clk rst_n |
Fanout : 0 |
bpu_flush |
|
|
- |
Register clk rst_n |
Fanout : 0 |
del 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
del_addr |
Delay lines |
|
|
Combinatorial |
Fanout : 0 |
del_branch_taken |
From if_addr to dec_i_addr; |
|
- |
Combinatorial |
Fanout : 0 |
cor 3 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
cor_instr |
Endianness corrections |
|
|
Combinatorial |
Fanout : 0 |
mem 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
cor_mem_rdata |
|
|
|
Combinatorial |
Fanout : 0 |
cor_mem_wdata |
|
|
|
Combinatorial |
Fanout : 0 |
dec 9 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
dec_opcode |
Decoder |
|
- |
Combinatorial |
Fanout : 0 |
dec_illegal |
|
|
- |
Combinatorial |
Fanout : 0 |
dec_imm |
|
|
|
Combinatorial |
Fanout : 0 |
dec_rs1 |
|
|
|
Combinatorial |
Fanout : 0 |
dec_rs2 |
|
|
|
Combinatorial |
Fanout : 0 |
dec_rd |
|
|
|
Combinatorial |
Fanout : 0 |
dec_addr |
|
|
|
Register clk rst_n |
Fanout : 0 |
dec_busy |
|
|
- |
Combinatorial |
Fanout : 0 |
dec_decoded |
|
|
- |
Combinatorial |
Fanout : 0 |
exec 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
exec_busy |
Execution logic |
|
- |
Combinatorial |
Fanout : 0 |
exec_flush |
|
|
- |
Combinatorial |
Fanout : 0 |
commit 3 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
commit_addr |
|
|
|
Combinatorial |
Fanout : 0 |
commit_write |
|
|
- |
Combinatorial |
Fanout : 0 |
commit_enable |
|
|
- |
Combinatorial |
Fanout : 0 |
alu/branch 2 elements
Name |
Description |
Type |
Size |
Kind |
Fanout |
|---|---|---|---|---|---|
alu_branch_taken |
|
|
- |
Register clk rst_n |
Fanout : 0 |
alu_branch_not_taken |
|
|
- |
Register clk rst_n |
Fanout : 0 |
Instantiation templates¶
Instantiation templates 2 elements
core <name> (
.clk (i_clk),
.i_rst_n (i_i_rst_n),
.o_rst_n (i_o_rst_n),
.instr (i_instr),
.rom_addr (i_rom_addr),
.flush (i_flush),
.enable (i_enable),
.rden (i_rden),
.mem_addr (i_mem_addr),
.mem_byteen (i_mem_byteen),
.mem_we (i_mem_we),
.mem_req (i_mem_req),
.mem_wdata (i_mem_wdata),
.mem_rdata (i_mem_rdata),
.mem_err (i_mem_err),
.interrupt_vect (i_interrupt_vect)
);
<name>: entity work.core
port map (
clk => i_clk,
i_rst_n => i_i_rst_n,
o_rst_n => i_o_rst_n,
instr => i_instr,
rom_addr => i_rom_addr,
flush => i_flush,
enable => i_enable,
rden => i_rden,
mem_addr => i_mem_addr,
mem_byteen => i_mem_byteen,
mem_we => i_mem_we,
mem_req => i_mem_req,
mem_wdata => i_mem_wdata,
mem_rdata => i_mem_rdata,
mem_err => i_mem_err,
interrupt_vect => i_interrupt_vect
);
Source¶
Raw source Full file
/*
* File : rtl/core/core.sv
*
* Author : l.heywang <leonard.heywang@proton.me>
* Date : 25/10.2025
*
* Brief : This file assemble all of the core components into
* a single entity, easier to use rather than a lot
* of smallers modules.
*/
`timescale 1ns / 1ps
import core_config_pkg::XLEN;
import core_config_pkg::REG_ADDR_W;
import core_config_pkg::opcodes_t;
module core (
input logic clk,
input logic i_rst_n,
output logic o_rst_n,
// Program ROM IF
input logic [(XLEN - 1) : 0] instr,
output logic [(XLEN - 1) : 0] rom_addr,
output logic flush,
output logic enable,
output logic rden,
// Peripherals / RAM interface
output logic [ (XLEN - 1) : 0] mem_addr,
output logic [((XLEN / 8) - 1) : 0] mem_byteen,
output logic mem_we,
output logic mem_req,
output logic [ (XLEN - 1) : 0] mem_wdata,
input logic [ (XLEN - 1) : 0] mem_rdata,
input logic mem_err,
// Interruption logic
input logic [(core_config_pkg::XLEN - 1) : 0] interrupt_vect
);
/*
* Global signals
*/
logic clk_en;
/*
* PC
*/
logic [(XLEN - 1) : 0] pc_addr;
logic pc_ovf;
/*
* BPU
*/
logic [(XLEN - 1) : 0] if_addr; // Used as output address.
logic bpu_branch_taken; // Show if the branch was predicted as taken or not.
logic [(XLEN - 1) : 0] bpu_write_addr;
logic bpu_write;
logic bpu_flush;
/*
* Delay lines
*/
logic [(XLEN - 1) : 0] del_addr; // From if_addr to dec_i_addr;
logic del_branch_taken; // Show if the branch was predicted as taken or not.
/*
* Endianness corrections
*/
logic [(XLEN - 1) : 0] cor_instr;
logic [(XLEN - 1) : 0] cor_mem_rdata;
logic [(XLEN - 1) : 0] cor_mem_wdata;
/*
* Decoder
*/
opcodes_t dec_opcode;
logic dec_illegal;
logic [(XLEN - 1) : 0] dec_imm;
logic [(REG_ADDR_W - 1) : 0] dec_rs1;
logic [(REG_ADDR_W - 1) : 0] dec_rs2;
logic [(REG_ADDR_W - 1) : 0] dec_rd;
logic [(XLEN - 1) : 0] dec_addr;
logic dec_busy;
logic dec_decoded;
/*
* Execution logic
*/
logic exec_busy;
logic exec_flush;
logic [(XLEN - 1) : 0] commit_addr;
logic commit_write;
logic commit_enable;
logic alu_branch_taken;
logic alu_branch_not_taken;
/*
* Instantiating modules for system wide
*/
clock clk_gen (
.clk(clk),
.rst_n(o_rst_n),
.clk_en(clk_en)
);
reset reset (
.clk(clk),
.rst_in(i_rst_n),
.rst_out(o_rst_n)
);
/*
* Instantiating modules for the core
*/
pcounter PC (
.clk(clk),
.clk_en(clk_en),
.rst_n(o_rst_n),
.enable(commit_enable),
.load(commit_write),
.load2(bpu_write),
.loaded(commit_addr),
.loaded2(bpu_write_addr),
.ovf(pc_ovf),
.address(pc_addr)
);
prediction BPU (
.clk(clk),
.rst_n(o_rst_n),
.predict_ok(alu_branch_taken),
.mispredict(alu_branch_not_taken),
.addr_in(pc_addr),
.addr_out(if_addr),
.rom_flush(bpu_flush),
.PC_value(bpu_write_addr),
.PC_write(bpu_write),
.actual_addr(dec_addr),
.actual_imm(dec_imm),
.actual_instr(dec_opcode),
.bpu_branch_taken(bpu_branch_taken)
);
/*
* Adding the delay lines, in parallel of the
* instruction memory (leaved outside, to ensure
* compatibility with any vendors IP or so...).
*/
delay #(
.WIDTH(XLEN)
) instr_delay (
.clk(clk),
.clk_en(clk_en),
.rst_n(o_rst_n),
.din(if_addr),
.dout(del_addr)
);
delay #(
.WIDTH(1)
) branch_delay (
.clk(clk),
.clk_en(clk_en),
.rst_n(o_rst_n),
.din(bpu_branch_taken),
.dout(del_branch_taken)
);
/*
* Adding the endianess corrections modules
* This is required since our design is based on big endian to
* make debugging easier, but the spec is little endian.
* Thus, we need to swap bytes on the edges of each modules.
*/
endianess if_endian (
.in (instr),
.out(cor_instr)
);
/*
* Adding the decoder
*/
decoder DEC (
.clk(clk),
.clk_en(clk_en),
.rst_n(o_rst_n),
.instruction(cor_instr),
.i_address(del_addr),
.i_busy(exec_busy),
.o_busy(dec_busy),
.rs1(dec_rs1),
.rs2(dec_rs2),
.rd(dec_rd),
.imm(dec_imm),
.o_address(dec_addr),
.opcode(dec_opcode),
.illegal(dec_illegal),
.decoded_cnt(dec_decoded)
);
/*
* Finally, adding the whole execution logic
*/
assembly_alu ALUS (
.clk(clk),
.clk_en(clk_en),
.rst_n(o_rst_n),
.rs1(dec_rs1),
.rs2(dec_rs2),
.rd(dec_rd),
.imm(dec_imm),
.address(dec_addr),
.opcode(dec_opcode),
.illegal(dec_illegal),
.busy(exec_busy),
.flush(exec_flush),
.branch_taken(del_branch_taken),
.count_decoded(dec_decoded),
.PC_ovf (pc_ovf),
.PC_en (commit_enable),
.PC_load(commit_write),
.PC_addr(commit_addr),
.mem_addr(mem_addr),
.mem_byteen(mem_byteen),
.mem_we(mem_we),
.mem_req(mem_req),
.mem_wdata(cor_mem_wdata),
.mem_rdata(cor_mem_rdata),
.mem_err(mem_err),
.bpu_branch_taken(alu_branch_taken),
.bpu_branch_not_taken(alu_branch_not_taken),
.interrupt_vect(interrupt_vect)
);
/*
* Endianess correction (for the same reasons as above),
* but for the memory interface.
*/
endianess mem_read_cor (
.in (mem_rdata),
.out(cor_mem_rdata)
);
endianess mem_write_cor (
.in (cor_mem_wdata),
.out(mem_wdata)
);
/*
* Statics IO of the module
*/
assign rom_addr = if_addr;
assign flush = bpu_flush | exec_flush;
assign enable = ~dec_busy;
assign rden = 1'b1;
endmodule