P
pallav
Guest
I'm trying to create a library of parametrizable components. I'm
looking at a priority encoder. I found some code on the web that shows
how to do this in a recursive way (I didn't know Verilog-2001 allows
recursive instantiation). The code is shown below. It seems to look OK
by recursively breaking down the decoder into smaller powers of 2
decoder. Alternatively, see http://damdevil.org/paste/?ODBlNm
I'm trying to compile this using Synopsys VCS to see if it supports
this feature but I'm getting some errors I'm not sure how to fix:
vlogan +warn=all +v2k -l comp.logan x.v
vcs priencr -l comp.log
Chronologic VCS (TM)
Version C-2009.06 -- Thu Aug 13 03:44:19 2009
Copyright (c) 1991-2008 by Synopsys Inc.
ALL RIGHTS RESERVED
This program is proprietary and confidential information of Synopsys
Inc.
and may be used and disclosed only as authorized in a license
agreement
controlling such use and disclosure.
Parsing design file 'x.v'
CPU time: .032 seconds to compile
Doing common elaboration
..
Error-[V2KTDMI] Too deep module instantiation
x.v, 1
"priencr"
Module 'priencr' may be involved in infinite recursive
instantiation.
Instance stack trace:
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
...
Any ideas on what I'm doing wrong? Thanks.
Kind regards.
module priencr #(parameter width = 64)
(
input [width-1:0] decode,
output [log2(width)-1:0] encode,
output valid
);
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
generate
if (width == 2)
begin
assign valid = |decode;
assign encode = decode[1];
end
else if (width & (width-1))
priencr #(1<<log2(width)) priencr ({1<<log2(width) {1'b0}} |
decode,
encode,valid);
else
begin
wire [log2(width)-2:0] encode_low;
wire [log2(width)-2:0] encode_high;
wire valid_low, valid_high;
priencr #(width>>1) low(decode[(width>>1)-1:0],encode_low,valid_low);
priencr #(width>>1) high(decode
[width-1:width>>1],encode_high,valid_high);
assign valid = valid_low | valid_high;
assign encode = valid_high ? {1'b1,encode_high} : {1'b0,encode_low};
end
endgenerate
endmodule
looking at a priority encoder. I found some code on the web that shows
how to do this in a recursive way (I didn't know Verilog-2001 allows
recursive instantiation). The code is shown below. It seems to look OK
by recursively breaking down the decoder into smaller powers of 2
decoder. Alternatively, see http://damdevil.org/paste/?ODBlNm
I'm trying to compile this using Synopsys VCS to see if it supports
this feature but I'm getting some errors I'm not sure how to fix:
vlogan +warn=all +v2k -l comp.logan x.v
vcs priencr -l comp.log
Chronologic VCS (TM)
Version C-2009.06 -- Thu Aug 13 03:44:19 2009
Copyright (c) 1991-2008 by Synopsys Inc.
ALL RIGHTS RESERVED
This program is proprietary and confidential information of Synopsys
Inc.
and may be used and disclosed only as authorized in a license
agreement
controlling such use and disclosure.
Parsing design file 'x.v'
CPU time: .032 seconds to compile
Doing common elaboration
..
Error-[V2KTDMI] Too deep module instantiation
x.v, 1
"priencr"
Module 'priencr' may be involved in infinite recursive
instantiation.
Instance stack trace:
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
priencr x.v, 24
...
Any ideas on what I'm doing wrong? Thanks.
Kind regards.
module priencr #(parameter width = 64)
(
input [width-1:0] decode,
output [log2(width)-1:0] encode,
output valid
);
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
generate
if (width == 2)
begin
assign valid = |decode;
assign encode = decode[1];
end
else if (width & (width-1))
priencr #(1<<log2(width)) priencr ({1<<log2(width) {1'b0}} |
decode,
encode,valid);
else
begin
wire [log2(width)-2:0] encode_low;
wire [log2(width)-2:0] encode_high;
wire valid_low, valid_high;
priencr #(width>>1) low(decode[(width>>1)-1:0],encode_low,valid_low);
priencr #(width>>1) high(decode
[width-1:width>>1],encode_high,valid_high);
assign valid = valid_low | valid_high;
assign encode = valid_high ? {1'b1,encode_high} : {1'b0,encode_low};
end
endgenerate
endmodule