Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Nonconstant index in Verilog

Status
Not open for further replies.

wittman

Newbie level 2
Joined
Apr 25, 2018
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
21
Hi
I want to check if "N" bits bus are all logic 1 and assign to the "pass" signal. The
bus width is variable and is defined by parameter N. But I get the "nonconstant index"
error message. How can I fix this issue?
Any help would be greatly appreciated!

Code:
parameter N;//2~64
integer i;
reg [(N*N)-1 : 0] status;
reg [N-1:0] pass;
//pass[0] is for status[N-1:0], pass[1] is for status[(2*N)-1 : N] ... ,etc

always @(status)
  for(i=0;i<=N-1;i=i+1)
    pass[i] =  & status[N-1+(i*N) : (i*N)];
 

If I interpreted what you are trying to do correctly...
Code:
   pass[i] =  & status[(i*N) +: N];
should do what you want.

Both the upper and lower bounds of a slice can't both be calculated
 
This is an artificial Verilog-ism. VHDL is totally fine with this -- other than lacking +:.

For Verilog, you can do:
Code:
pass[i] =  &((status >> (i*N)) & ((1<<(N+1))-1));
// or
pass[i] =  &((status >> (i*N)) & (N){1'b1});
although it feels like a hack.

I'd like to know if there are better solutions. I think the last time I tried this was 1 year ago, maybe Verilog allows +: with variable index now.

--edit: not sure on the precedence of >> vs *. either way it's probably not clear to many readers.

--edit2: actually, it looks like +: should work. I have no idea why it didn't the last time I tried it. maybe I made some other mistake. It looks like the LRM has an example for this case. If +: works, use it, it is a better construct anyways.
 
Last edited:

Indexed part select syntax +: and -: is supported at least since Verilog 2001.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top