Skip to content

Commit

Permalink
[rtl] Dedicated ibex_counter_flop modules
Browse files Browse the repository at this point in the history
Depending on whether we are targeting a Xilinx FPGA or a generic
target, we use a Xilinx specifc flop implementation for the
Ibex counters. To increase readability, this commit creates a
new module containing a Xilinx specific flop implementation. For
generic targets, the existing prim_flop is used. In the Xilinx
specific version, a DSP is used when the CounterWidth is below
49-bits.

Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
  • Loading branch information
nasahlpa committed Dec 3, 2024
1 parent 54985d2 commit 603cf8d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions dv/uvm/core_ibex/ibex_dv.f
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
${PRJ_DIR}/rtl/ibex_csr.sv
${PRJ_DIR}/rtl/ibex_cs_registers.sv
${PRJ_DIR}/rtl/ibex_counter.sv
${PRJ_DIR}/rtl/ibex_counter_flop_xilinx.sv
${PRJ_DIR}/rtl/ibex_decoder.sv
${PRJ_DIR}/rtl/ibex_dummy_instr.sv
${PRJ_DIR}/rtl/ibex_ex_block.sv
Expand Down
1 change: 1 addition & 0 deletions ibex_core.core
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ filesets:
- rtl/ibex_cs_registers.sv
- rtl/ibex_csr.sv
- rtl/ibex_counter.sv
- rtl/ibex_counter_flop_xilinx.sv
- rtl/ibex_decoder.sv
- rtl/ibex_ex_block.sv
- rtl/ibex_fetch_fifo.sv
Expand Down
1 change: 1 addition & 0 deletions rtl/ibex_core.f
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ibex_compressed_decoder.sv
ibex_controller.sv
ibex_counter.sv
ibex_counter_flop_xilinx.sv
ibex_cs_registers.sv
ibex_decoder.sv
ibex_ex_block.sv
Expand Down
43 changes: 21 additions & 22 deletions rtl/ibex_counter.sv
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,31 @@ module ibex_counter #(

`ifdef FPGA_XILINX
// On Xilinx FPGAs, 48-bit DSPs are available that can be used for the
// counter.
if (CounterWidth < 49) begin : g_dsp_counter
// Set DSP pragma for supported xilinx FPGAs
(* use_dsp = "yes" *) logic [CounterWidth-1:0] counter_q;
// DSP output register requires synchronous reset.
`define COUNTER_FLOP_RST posedge clk_i
end else begin : g_no_dsp_counter
(* use_dsp = "no" *) logic [CounterWidth-1:0] counter_q;
`define COUNTER_FLOP_RST posedge clk_i or negedge rst_ni
end
// counter. Hence, use Xilinx specific flop implementation.
localparam int DspPragma = CounterWidth < 49 ? "yes" : "no";
(* use_dsp = DspPragma *) logic [CounterWidth-1:0] counter_q;
(* use_dsp = DspPragma *) ibex_counter_flop_xilinx #(
.CounterWidth (CounterWidth),
.ResetValue('0)
) u_ibex_cnt_flop_xilinx (
.clk_i (clk_i),
.rst_ni (rst_ni),
.d_i (counter_d),
.q_o (counter_q)
);
`else
logic [CounterWidth-1:0] counter_q;

`define COUNTER_FLOP_RST posedge clk_i or negedge rst_ni
prim_flop #(
.Width(CounterWidth),
.ResetValue('0)
) u_ibex_cnt_flop (
.clk_i (clk_i),
.rst_ni (rst_ni),
.d_i (counter_d),
.q_o (counter_q)
);
`endif

// Counter flop
always_ff @(`COUNTER_FLOP_RST) begin
`undef COUNTER_FLOP_RST
if (!rst_ni) begin
counter_q <= '0;
end else begin
counter_q <= counter_d;
end
end

if (CounterWidth < 64) begin : g_counter_narrow
logic [63:CounterWidth] unused_counter_load;

Expand Down
43 changes: 43 additions & 0 deletions rtl/ibex_counter_flop_xilinx.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

/**
* Generic Counter Flop
*
* Counter flop implementation for non-Xilinx targets
*/
module ibex_counter_flop_xilinx #(
parameter int CounterWidth = 32,
parameter logic [CounterWidth-1:0] ResetValue = 0
) (
input logic clk_i,
input logic rst_ni,
input logic [CounterWidth-1:0] d_i,
output logic [CounterWidth-1:0] q_o
);
// On Xilinx FPGAs, 48-bit DSPs are available that can be used for the
// counter. When using a DSP, a sync. reset is needed for the flop.
localparam string ResetType = CounterWidth < 49 ? "SYNC" : "ASYNC";

generate
if(ResetType == "ASYNC") begin : g_async_reset_ff
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
q_o <= ResetValue;
end else begin
q_o <= d_i;
end
end
end else begin : g_sync_reset_ff
always_ff @(posedge clk_i) begin
if (!rst_ni) begin
q_o <= ResetValue;
end else begin
q_o <= d_i;
end
end
end
endgenerate

endmodule
1 change: 1 addition & 0 deletions src_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ibex:
rtl/ibex_controller.sv,
rtl/ibex_cs_registers.sv,
rtl/ibex_counters.sv,
rtl/ibex_counter_flop_xilinx.sv,
rtl/ibex_decoder.sv,
rtl/ibex_ex_block.sv,
rtl/ibex_id_stage.sv,
Expand Down

0 comments on commit 603cf8d

Please sign in to comment.