Internals: Remove unneeded return, cleanup param test. No functional change

This commit is contained in:
Wilson Snyder 2025-08-30 07:42:41 -04:00
parent fbfd1f12dd
commit 712ff95a48
6 changed files with 111 additions and 109 deletions

View File

@ -4047,8 +4047,7 @@ void V3Const::constifyParamsNoWarnEdit(AstNode* nodep) {
//! generated. Since such occurrences, must be constant, in order to be //! generated. Since such occurrences, must be constant, in order to be
//! something a generate block can depend on, we can wait until later to do the //! something a generate block can depend on, we can wait until later to do the
//! width check. //! width check.
//! @return Pointer to the edited node. void V3Const::constifyGenerateParamsEdit(AstNode* nodep) {
AstNode* V3Const::constifyGenerateParamsEdit(AstNode* nodep) {
// UINFOTREE(1, nodep, "", "forceConPRE:"); // UINFOTREE(1, nodep, "", "forceConPRE:");
// Resize even if the node already has a width, because buried in the tree // Resize even if the node already has a width, because buried in the tree
// we may have a node we just created with signing, etc, that isn't sized // we may have a node we just created with signing, etc, that isn't sized
@ -4064,11 +4063,10 @@ AstNode* V3Const::constifyGenerateParamsEdit(AstNode* nodep) {
// init value because we need widthing above to handle the var's type. // init value because we need widthing above to handle the var's type.
if (varp->valuep()) visitor.mainAcceptEdit(varp->valuep()); if (varp->valuep()) visitor.mainAcceptEdit(varp->valuep());
} else { } else {
nodep = visitor.mainAcceptEdit(nodep); VL_DO_DANGLING(visitor.mainAcceptEdit(nodep), nodep);
} }
// Because we do edits, nodep links may get trashed and core dump this. // Because we do edits, nodep links may get trashed and core dump this.
// UINFOTREE(1, nodep, "", "forceConDONE"); // UINFOTREE(1, nodep, "", "forceConDONE");
return nodep;
} }
void V3Const::constifyAllLint(AstNetlist* nodep) { void V3Const::constifyAllLint(AstNetlist* nodep) {

View File

@ -28,7 +28,7 @@ class V3Const final {
public: public:
static void constifyParamsEdit(AstNode* nodep) VL_MT_DISABLED; static void constifyParamsEdit(AstNode* nodep) VL_MT_DISABLED;
static void constifyParamsNoWarnEdit(AstNode* nodep) VL_MT_DISABLED; static void constifyParamsNoWarnEdit(AstNode* nodep) VL_MT_DISABLED;
static AstNode* constifyGenerateParamsEdit(AstNode* nodep) VL_MT_DISABLED; static void constifyGenerateParamsEdit(AstNode* nodep) VL_MT_DISABLED;
// Only do constant pushing, without removing dead logic // Only do constant pushing, without removing dead logic
static void constifyAllLive(AstNetlist* nodep) VL_MT_DISABLED; static void constifyAllLive(AstNetlist* nodep) VL_MT_DISABLED;
// Everything that's possible // Everything that's possible

View File

@ -4,11 +4,11 @@
// any use, without warranty, 2021 by Michael Lefebvre. // any use, without warranty, 2021 by Michael Lefebvre.
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
module t(/*AUTOARG*/); module t;
localparam int unsigned A3 [2:0] = '{4,5,6}; localparam int unsigned A3[2:0] = '{4, 5, 6};
// slicesel out of range should fail // slicesel out of range should fail
localparam int unsigned B32_T [1:0] = A3[3:1]; localparam int unsigned B32_T[1:0] = A3[3:1];
endmodule endmodule

View File

@ -14,9 +14,9 @@ package config_pkg;
int USE_QUAD0; int USE_QUAD0;
int USE_QUAD1; int USE_QUAD1;
int USE_QUAD2; int USE_QUAD2;
} config_struct; } config_struct_t;
endpackage : config_pkg endpackage
module t; module t;
import config_pkg::*; import config_pkg::*;
@ -28,11 +28,11 @@ module t;
USE_QUAD1: 5, USE_QUAD1: 5,
USE_QUAD2: 6 USE_QUAD2: 6
})) a_submodule_I (); })) a_submodule_I ();
endmodule : t endmodule
module struct_submodule module struct_submodule
import config_pkg::*; import config_pkg::*;
#(parameter config_struct MY_CONFIG = '0); #(parameter config_struct_t MY_CONFIG = '0);
initial begin initial begin
`checkd(MY_CONFIG.UPPER0, 10); `checkd(MY_CONFIG.UPPER0, 10);
@ -43,4 +43,4 @@ module struct_submodule
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end
endmodule : struct_submodule endmodule

View File

@ -4,53 +4,57 @@
// without warranty, 2017 by Matt Myers. // without warranty, 2017 by Matt Myers.
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// verilog_format: off
`define stop $stop `define stop $stop
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0); `define checkd(gotv, expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
// verilog_format: on
package config_pkg; package config_pkg;
typedef struct packed { typedef struct packed {
int UPPER0; int UPPER0;
struct packed { struct packed {
int USE_QUAD0; int USE_QUAD0;
int USE_QUAD1; int USE_QUAD1;
int USE_QUAD2; int USE_QUAD2;
} mac; } mac;
int UPPER2; int UPPER2;
} config_struct; } config_struct_t;
function automatic config_struct static_config(int selector); function automatic config_struct_t static_config(int selector);
config_struct return_config; config_struct_t return_config;
return_config = '0; return_config = '0;
return_config.UPPER0 = 10; return_config.UPPER0 = 10;
return_config.UPPER2 = 20; return_config.UPPER2 = 20;
return_config.mac.USE_QUAD0 = 4; return_config.mac.USE_QUAD0 = 4;
return_config.mac.USE_QUAD2 = 6; return_config.mac.USE_QUAD2 = 6;
case (selector) case (selector)
1: return_config.mac.USE_QUAD1 = 5; 1: return_config.mac.USE_QUAD1 = 5;
endcase endcase
return return_config; return return_config;
endfunction endfunction
endpackage : config_pkg endpackage
module t; module t;
import config_pkg::*; import config_pkg::*;
localparam config_struct MY_CONFIG = static_config(1); localparam config_struct_t MY_CONFIG = static_config(1);
struct_submodule #(.MY_CONFIG(MY_CONFIG)) a_submodule_I (); struct_submodule #(.MY_CONFIG(MY_CONFIG)) a_submodule_I ();
endmodule : t endmodule
module struct_submodule module struct_submodule
import config_pkg::*; import config_pkg::*;
#(parameter config_struct MY_CONFIG = '0); #(
parameter config_struct_t MY_CONFIG = '0
);
initial begin initial begin
`checkd(MY_CONFIG.UPPER0, 10); `checkd(MY_CONFIG.UPPER0, 10);
`checkd(MY_CONFIG.mac.USE_QUAD0, 4); `checkd(MY_CONFIG.mac.USE_QUAD0, 4);
`checkd(MY_CONFIG.mac.USE_QUAD1, 5); `checkd(MY_CONFIG.mac.USE_QUAD1, 5);
`checkd(MY_CONFIG.mac.USE_QUAD2, 6); `checkd(MY_CONFIG.mac.USE_QUAD2, 6);
`checkd(MY_CONFIG.UPPER2, 20); `checkd(MY_CONFIG.UPPER2, 20);
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end
endmodule : struct_submodule endmodule

View File

@ -6,76 +6,76 @@
package config_pkg; package config_pkg;
localparam int unsigned N = 10; localparam int unsigned N = 10;
typedef struct packed { typedef struct packed {
logic [N-1:0][31:0] lo; logic [N-1:0][31:0] lo;
logic [N-1:0][31:0] hi; logic [N-1:0][31:0] hi;
logic [100-1:0][31:0] x; logic [100-1:0][31:0] x;
int unsigned n; int unsigned n;
} config_struct; } config_struct_t;
function automatic logic subcheck(logic[31:0] lo, logic[31:0] hi, logic[31:0] val); function automatic logic subcheck(logic [31:0] lo, logic [31:0] hi, logic [31:0] val);
return lo <= val && val < hi; return lo <= val && val < hi;
endfunction endfunction
function automatic logic check(config_struct cfg, logic[31:0] val); function automatic logic check(config_struct_t cfg, logic [31:0] val);
logic[N-1:0] good = '0; logic [N-1:0] good = '0;
logic[N-1:0] bad = '0; logic [N-1:0] bad = '0;
for (int i = 0; i < cfg.n; i++) begin for (int i = 0; i < cfg.n; i++) begin
good[i] = subcheck(cfg.lo[i], cfg.hi[i], val); good[i] = subcheck(cfg.lo[i], cfg.hi[i], val);
end end
for (int i = cfg.n; i < N; i++) begin for (int i = cfg.n; i < N; i++) begin
bad[i] = !(cfg.lo[i] == '0 && cfg.hi[i] == '0); bad[i] = !(cfg.lo[i] == '0 && cfg.hi[i] == '0);
end end
return good != '0 && bad == '0; return good != '0 && bad == '0;
endfunction endfunction
endpackage : config_pkg endpackage : config_pkg
module t(/*AUTOARG*/ module t ( /*AUTOARG*/
// Inputs // Inputs
clk clk
); );
input clk; input clk;
import config_pkg::*; import config_pkg::*;
parameter config_struct MY_CONFIG = '{ parameter config_struct_t MY_CONFIG = '{
lo: {((N-3)*32)'('0), 32'h00, 32'h10, 32'h20}, lo: {((N - 3) * 32)'('0), 32'h00, 32'h10, 32'h20},
hi: {((N-3)*32)'('0), 32'h10, 32'h20, 32'h30}, hi: {((N - 3) * 32)'('0), 32'h10, 32'h20, 32'h30},
x : 3200'h0deadbeef, x : 3200'h0deadbeef,
n : 3 n : 3
}; };
struct_submodule #(.MY_CONFIG(MY_CONFIG)) a_submodule_I (.clk); struct_submodule #(.MY_CONFIG(MY_CONFIG)) a_submodule_I (.clk);
endmodule : t endmodule
module struct_submodule module struct_submodule
import config_pkg::*; import config_pkg::*;
#( #(
parameter config_struct MY_CONFIG = '0 parameter config_struct_t MY_CONFIG = '0
) ( ) (
input clk input clk
); );
logic [31:0] val; logic [31:0] val;
logic c; logic c;
int count = 0; int count = 0;
assign val = 3; assign val = 3;
assign c = check(MY_CONFIG, count); assign c = check(MY_CONFIG, count);
always @(posedge clk) begin always @(posedge clk) begin
count <= count + 1; count <= count + 1;
if (c != '1) begin if (c != '1) begin
$error("c not 1"); $error("c not 1");
$stop; $stop;
end
if (count >= 10) begin
$write("*-* All Finished *-*\n");
$finish;
end
end end
if (count >= 10) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule : struct_submodule endmodule