From 98f9ea4c0124ca23f482a647b1915e0b4647e1a4 Mon Sep 17 00:00:00 2001 From: Cyril Koenig Date: Fri, 25 Oct 2024 14:20:15 +0200 Subject: [PATCH] axi_pkg: Add iomsb to avoid underflow in array lengths Note, VCS does not support values greater than 2^31-1 as array bound --- src/axi_id_serialize.sv | 2 +- src/axi_pkg.sv | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/axi_id_serialize.sv b/src/axi_id_serialize.sv index 9a787dd25..671b38ad1 100644 --- a/src/axi_id_serialize.sv +++ b/src/axi_id_serialize.sv @@ -66,7 +66,7 @@ module axi_id_serialize #( /// Number of Entries in the explicit ID map (default: None) parameter int unsigned IdMapNumEntries = 32'd0, /// Explicit ID map; index [0] in each entry is the input ID to match, index [1] the output ID. - parameter int unsigned IdMap [IdMapNumEntries-1:0][0:1] = '{default: {32'b0, 32'b0}} + parameter int unsigned IdMap [axi_pkg::iomsb(IdMapNumEntries):0][0:1] = '{default: {32'b0, 32'b0}} ) ( /// Rising-edge clock of both ports input logic clk_i, diff --git a/src/axi_pkg.sv b/src/axi_pkg.sv index 4102be0e8..6e6450bbd 100644 --- a/src/axi_pkg.sv +++ b/src/axi_pkg.sv @@ -532,4 +532,9 @@ package axi_pkg; logic [31:0] end_addr; } xbar_rule_32_t; + // Return either the argument minus 1 or 0 if 0; useful for IO vector width declaration + function automatic integer unsigned iomsb (input integer unsigned width); + return (width != 32'd0) ? unsigned'(width-1) : 32'd0; + endfunction + endpackage