Guest
Trying to write a simple N bit priority arbiter (which will prioritize req[0]>req[1]>req[2] ... req[N].
Working code:
assign grant_simple[0] = req_in[0];
generate
for (i=1; i<N; i++)
assign grant_simple = req_in & (!(|req_in[i-1:0]));
endgenerate
But i tried without generate and using always_comb block like this.
assign grant_simple[0] = req_in[0];
always_comb begin
for (int i=1; i<N; i++)
grant_simple = req_in & (!(|req_in[i-1:0]));
end //always
This is giving me an error.
Error-[IRIPS] Illegal range in part select design.sv, 18 The range of the part select is illegal: req_in[(i - 1):0]
Error-[TCF-CETE] Cannot evaluate the expression design.sv, 18 "(i - 1)" Cannot evaluate the expression in left slicing expression. The expression must be compile time constant.
I tried replacing [i-1:0] with i-:1 but i dont think it does the same thing.. Looking for a clear explanation on why generate is ok with the [i-1:0] and not the for loop without generate. How to use the bit slicing in this case for system verilog. Thanks much.
Working code:
assign grant_simple[0] = req_in[0];
generate
for (i=1; i<N; i++)
assign grant_simple = req_in & (!(|req_in[i-1:0]));
endgenerate
But i tried without generate and using always_comb block like this.
assign grant_simple[0] = req_in[0];
always_comb begin
for (int i=1; i<N; i++)
grant_simple = req_in & (!(|req_in[i-1:0]));
end //always
This is giving me an error.
Error-[IRIPS] Illegal range in part select design.sv, 18 The range of the part select is illegal: req_in[(i - 1):0]
Error-[TCF-CETE] Cannot evaluate the expression design.sv, 18 "(i - 1)" Cannot evaluate the expression in left slicing expression. The expression must be compile time constant.
I tried replacing [i-1:0] with i-:1 but i dont think it does the same thing.. Looking for a clear explanation on why generate is ok with the [i-1:0] and not the for loop without generate. How to use the bit slicing in this case for system verilog. Thanks much.