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.

[SOLVED] Verilog 2001 indexed part-select +: in always block

Status
Not open for further replies.

ShanghaiDSP

Newbie level 3
Joined
May 29, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Germany
Activity points
45
Hi to all,

I'm writing a generic multiplexer and facing a problem regarding Verilog.

I try to use a for-loop (with bounded index - to keep it synthesizable) and
assign a sliced part of the input to the output depending on cnt (one-hot encoded).
The idea is to slice a wide input vector (e.g. 128 bit) to a narrow (e.g. 32 bit) output
but in a generic way, so bit widths may change.
Consider the following code:

Code:
integer i;
always@(*) begin
	data_o =  data_mux[LINK_WIDTH-1 : 0]; 
	for(i=0; i < SERDES_LEVEL ; i= i+1) 
		begin
			if(cnt[i] == 1'b1) 
				begin
					data_o =  data_mux[((i+1)*LINK_WIDTH-1) +: (LINK_WIDTH*i)];
				end	
		end
		
	end

According Verilog 2001 spec the "+: " operator should be used,
because ":" is not sufficient when a index variable is involved.
But ModelSim 10.4 reports "Range width must be constant expression." for the "data_o = data_mux[((i+1)*LINK_WIDTH-1) +: (LINK_WIDTH*i)];" assignment
(verilog files are compiled as verilog 2001 version).
I checked several times...the width of sliced vector part is not changing during loop iterations.

For me this behavior is not understandable, starting from the introduction of indexed part-select "+:" operator. I can agree if someone tries to use a unbound for loop or the indexed bit width is changing. But verilog compiler just refuse in any case even if its a (in general) valid code.

Would be nice if someone could explain these limitation to me or where the error is :grin:
 

iamyuchenjie

Junior Member level 1
Joined
Aug 3, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,429
I will try lovely ncsim for u
Hi to all,

I'm writing a generic multiplexer and facing a problem regarding Verilog.

I try to use a for-loop (with bounded index - to keep it synthesizable) and
assign a sliced part of the input to the output depending on cnt (one-hot encoded).
The idea is to slice a wide input vector (e.g. 128 bit) to a narrow (e.g. 32 bit) output
but in a generic way, so bit widths may change.
Consider the following code:

Code:
integer i;
always@(*) begin
	data_o =  data_mux[LINK_WIDTH-1 : 0]; 
	for(i=0; i < SERDES_LEVEL ; i= i+1) 
		begin
			if(cnt[i] == 1'b1) 
				begin
					data_o =  data_mux[((i+1)*LINK_WIDTH-1) +: (LINK_WIDTH*i)];
				end	
		end
		
	end

According Verilog 2001 spec the "+: " operator should be used,
because ":" is not sufficient when a index variable is involved.
But ModelSim 10.4 reports "Range width must be constant expression." for the "data_o = data_mux[((i+1)*LINK_WIDTH-1) +: (LINK_WIDTH*i)];" assignment
(verilog files are compiled as verilog 2001 version).
I checked several times...the width of sliced vector part is not changing during loop iterations.

For me this behavior is not understandable, starting from the introduction of indexed part-select "+:" operator. I can agree if someone tries to use a unbound for loop or the indexed bit width is changing. But verilog compiler just refuse in any case even if its a (in general) valid code.

Would be nice if someone could explain these limitation to me or where the error is :grin:
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,807
Helped
1,810
Reputation
3,630
Reaction score
1,769
Trophy points
1,393
Location
USA
Activity points
58,934
It's defined like this:
[Least_significant_bit_of_slice +: the_width_of_the_slice]

The width of the slice is not variable, only the starting bit.
 

iamyuchenjie

Junior Member level 1
Joined
Aug 3, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,429
It's defined like this:
[Least_significant_bit_of_slice +: the_width_of_the_slice]

The width of the slice is not variable, only the starting bit.


Thank you very much!It wokrs
 

ShanghaiDSP

Newbie level 3
Joined
May 29, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Germany
Activity points
45
Thanks, you are right!
if you are used to [MSB:LSB] notation this +: operator is not straightforward :-?

It's defined like this:
[Least_significant_bit_of_slice +: the_width_of_the_slice]

The width of the slice is not variable, only the starting bit.
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,807
Helped
1,810
Reputation
3,630
Reaction score
1,769
Trophy points
1,393
Location
USA
Activity points
58,934
Thanks, you are right!
if you are used to [MSB:LSB] notation this +: operator is not straightforward :-?

Not sure why it's always considered confusing by so many as it's described pretty good in the LRM:

Capture0.JPG
Capture.JPG

As you can see it says right there K must be a constant.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top