cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Voyager
Voyager
318 Views
Registered: ‎04-12-2012

foreach generate in Systemverilog

Jump to solution
Hello,
 
I have a module parameter named : "selector" which is a vector.
I have an internal variable named : "destination" which can get its value from either "source_1" or "source_2". 
The bit value of "selector" will determine the bit driver ( either "source_1" of "source_2" ).

This is what I wrote:

generate
    foreach ( selector [ bit_number ] )
    begin
        if ( selector [ bit_number ] == 1'b1 )
            assign destination [ bit_number ] = source_1 ;
        else
            assign destination [ bit_number ] = source_2 ;
    end     
endgenerate

Help me fix the code so I can synthesize it.

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
208 Views
Registered: ‎07-21-2014

Yes, you can use foreach in always_comb.

-Shreyas

----------------------------------------------------------------------------------------------
Try to search answer for your issue in forums or xilinx user guides before you post a new thread.

Kindly note- Please mark the Answer as "Accept as solution" if information provided solves your query.
Give Kudos (star provided in right) to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

View solution in original post

4 Replies
Highlighted
Xilinx Employee
Xilinx Employee
292 Views
Registered: ‎05-14-2008

You can use a generate for loop instead of foreach.

 

genvar bit_number;

generate for(bit_number=0;nit_number<?;bit_number=bit_number+1) begin : 

if ( selector [ bit_number ] == 1'b1 )
            assign destination [ bit_number ] = source_1 ;
        else
            assign destination [ bit_number ] = source_2 ;


endgenerate

 

-vivian

-------------------------------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------------------------------
如果提供的信息能解决您的问题,请标记为“接受为解决方案”。
如果您认为帖子有帮助,请点击“奖励”。谢谢!
-------------------------------------------------------------------------------------------------
Highlighted
Xilinx Employee
Xilinx Employee
268 Views
Registered: ‎07-21-2014

Hi @shaikon 

Foreach is a procedural programming statement that can only be used within a procedural block (eg. initial, always blocks). 

 In this case, as @viviany  suggested, you have to use "generate for".

-Shreyas

----------------------------------------------------------------------------------------------
Try to search answer for your issue in forums or xilinx user guides before you post a new thread.

Kindly note- Please mark the Answer as "Accept as solution" if information provided solves your query.
Give Kudos (star provided in right) to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
Highlighted
Voyager
Voyager
251 Views
Registered: ‎04-12-2012
So I can put the "foreach" in an "always_comb" block ?
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
209 Views
Registered: ‎07-21-2014

Yes, you can use foreach in always_comb.

-Shreyas

----------------------------------------------------------------------------------------------
Try to search answer for your issue in forums or xilinx user guides before you post a new thread.

Kindly note- Please mark the Answer as "Accept as solution" if information provided solves your query.
Give Kudos (star provided in right) to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------

View solution in original post