Skip to content

Commit 1d5c6fc

Browse files
authored
addr_decode: Arbitrary index types (#271)
* addr_decode: Support disabling indices assertions * addr_decode: Arbitrary `idx_t` types
1 parent 1391745 commit 1d5c6fc

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/addr_decode.sv

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ module addr_decode #(
4343
/// The address decoder expects three fields in `rule_t`:
4444
///
4545
/// typedef struct packed {
46-
/// int unsigned idx;
47-
/// addr_t start_addr;
48-
/// addr_t end_addr;
46+
/// idx_t idx;
47+
/// addr_t start_addr;
48+
/// addr_t end_addr;
4949
/// } rule_t;
5050
///
51-
/// - `idx`: index of the rule, has to be < `NoIndices`
51+
/// - `idx`: The index to be returned for a matching rule. Usually an integer but can
52+
/// be any type of data.
5253
/// - `start_addr`: start address of the range the rule describes, value is included in range
5354
/// - `end_addr`: end address of the range the rule describes, value is NOT included in range
5455
/// if `end_addr == '0` end of address space is assumed
@@ -59,13 +60,10 @@ module addr_decode #(
5960
parameter type rule_t = logic,
6061
// Whether this is a NAPOT (base and mask) or regular range decoder
6162
parameter bit Napot = 0,
62-
/// Dependent parameter, do **not** overwite!
63-
///
64-
/// Width of the `idx_o` output port.
63+
/// The output index type `idx_t` can be specified either with the width `IdxWidth`
64+
/// or directly with the type `idx_t`. By default, it will use the maximum index
65+
/// `NoIndices` to calculate the required width.
6566
parameter int unsigned IdxWidth = cf_math_pkg::idx_width(NoIndices),
66-
/// Dependent parameter, do **not** overwite!
67-
///
68-
/// Type of the `idx_o` output port.
6967
parameter type idx_t = logic [IdxWidth-1:0]
7068
) (
7169
/// Address to decode.
@@ -92,11 +90,11 @@ module addr_decode #(
9290

9391
// wraps the dynamic configuration version of the address decoder
9492
addr_decode_dync #(
95-
.NoIndices ( NoIndices ),
9693
.NoRules ( NoRules ),
9794
.addr_t ( addr_t ),
9895
.rule_t ( rule_t ),
99-
.Napot ( Napot )
96+
.Napot ( Napot ),
97+
.idx_t ( idx_t )
10098
) i_addr_decode_dync (
10199
.addr_i,
102100
.addr_map_i,

src/addr_decode_dync.sv

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ module addr_decode_dync #(
4848
/// The address decoder expects three fields in `rule_t`:
4949
///
5050
/// typedef struct packed {
51-
/// int unsigned idx;
52-
/// addr_t start_addr;
53-
/// addr_t end_addr;
51+
/// idx_t idx;
52+
/// addr_t start_addr;
53+
/// addr_t end_addr;
5454
/// } rule_t;
5555
///
56-
/// - `idx`: index of the rule, has to be < `NoIndices`
56+
/// - `idx`: The index to be returned for a matching rule. Usually an integer but can
57+
/// be any type of data.
5758
/// - `start_addr`: start address of the range the rule describes, value is included in range
5859
/// - `end_addr`: end address of the range the rule describes, value is NOT included in range
5960
/// if `end_addr == '0` end of address space is assumed
@@ -62,15 +63,12 @@ module addr_decode_dync #(
6263
/// power of two (NAPOT) region instead of an address range: `start_addr` becomes the base address
6364
/// and `end_addr` the mask. See the wrapping module `addr_decode_napot` for details.
6465
parameter type rule_t = logic,
65-
// Whether this is a NAPOT (base and mask) or regular range decoder
66+
/// Whether this is a NAPOT (base and mask) or regular range decoder
6667
parameter bit Napot = 0,
67-
/// Dependent parameter, do **not** overwite!
68-
///
69-
/// Width of the `idx_o` output port.
68+
/// The output index type `idx_t` can be specified either with the width `IdxWidth`
69+
/// or directly with the type `idx_t`. By default, it will use the maximum index
70+
/// `NoIndices` to calculate the required width.
7071
parameter int unsigned IdxWidth = cf_math_pkg::idx_width(NoIndices),
71-
/// Dependent parameter, do **not** overwite!
72-
///
73-
/// Type of the `idx_o` output port.
7472
parameter type idx_t = logic [IdxWidth-1:0]
7573
) (
7674
/// Address to decode.
@@ -130,7 +128,6 @@ module addr_decode_dync #(
130128
$sformatf("Input address has %d bits and address map has %d bits.",
131129
$bits(addr_i), $bits(addr_map_i[0].start_addr)))
132130
`ASSUME_I(norules_0, NoRules > 0, $sformatf("At least one rule needed"))
133-
`ASSUME_I(noindices_0, NoIndices > 0, $sformatf("At least one index needed"))
134131
end
135132

136133
`ASSERT_FINAL(more_than_1_bit_set, $onehot0(matched_rules) || config_ongoing_i,
@@ -155,15 +152,6 @@ module addr_decode_dync #(
155152
Rule> IDX: %h START: %h END: %h\n\
156153
#####################################################",
157154
i ,addr_map_i[i].idx, addr_map_i[i].start_addr, addr_map_i[i].end_addr))
158-
// check the SLV ids
159-
`ASSUME_I(check_idx, addr_map_i[i].idx < NoIndices,
160-
$sformatf("This rule has a IDX that is not allowed!!!\n\
161-
Violating rule %d.\n\
162-
Rule> IDX: %h START: %h END: %h\n\
163-
Rule> MAX_IDX: %h\n\
164-
#####################################################",
165-
i, addr_map_i[i].idx, addr_map_i[i].start_addr, addr_map_i[i].end_addr,
166-
(NoIndices-1)))
167155
for (int unsigned j = i + 1; j < NoRules; j++) begin
168156
// overlap check
169157
`ASSUME_I(check_overlap, Napot ||

0 commit comments

Comments
 (0)