if else inside generate statement

Status
Not open for further replies.

shainky

Junior Member level 1
Joined
Apr 18, 2009
Messages
17
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,281
Visit site
Activity points
1,414
hi,
can i use if else inside generate statement?

Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
generate
      for (i = 0; i < my_size; i = i + 1)
    begin : size
                    u_mux(.in(index[i]),
                  .sel(idx_int[i]),
                  .out(side[4*i +: 4]));
           if (i == 'd0)
           assign my_data[64*i +: 64] = {{56{1'b0}},data[8*i +: 8]}; 
       else if (i == 'd1) 
            assign my_data[64*i +: 64] = (datasize == 1'b1) ? {{48{1'b0}}, data[8*i +: 16]} : 
                        {{56{1'b0}},data[8*i +: 8]}; 
       else  
            assign my_data[64*i +: 64] = {{56{1'b0}},data[((8*i)+8) +: 8]}; 
 
end 
   endgenerate



I think we cannot use assign statement with if statement.
But the moment i am removing assign statement i am getting spyglass lint errors.
Is this code synthesizable?
 
Last edited by a moderator:

A generate if can be used in this place, because the if condition is static, only depending on generate var i.

Regular if statements can be only used inside a sequential block or function.
 

The if is used to select how the least significant 64-bit words are assigned to the my_data bus. As the if is used to conditionally assign 64-bits it is required, otherwise the three assigns would conflict with each other.

It should have no problen synthesizing.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…