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.

Question about Verilog RTL syntax

Status
Not open for further replies.

choonlle

Full Member level 2
Joined
Jul 18, 2006
Messages
126
Helped
20
Reputation
40
Reaction score
1
Trophy points
1,298
Location
AFRICA
Activity points
2,025
Izzit any different between below case?


Case 1:
always @(posedge clk_i)
begin
game_a_0 <= game_a_i;
game_b_1 <= game_b_i;
end


Case 2:
always @(posedge clk_i)
game_a_0 <= game_a_i;
always @(posedge clk_i)
game_b_1 <= game_b_i;

Will case 2 be better for synthesis tools to interpret?!


Any comments??!!
 

rtl syntax

These two pieces of code are really syntacially the same. To Verilog, the begin and end are the same as the "curly brace" to a C program. The compiler understands that everything between the begin and end occur at your clock transition.

Case #2 is sometimes viewed as bad coding style. The reason is it easily introduces errors when modified. For example, let us say I want to add a game_c set of flops. If I am careless, then I just paste them in as such:

always @(posedge clk_i)
game_a_0 <= game_a_i;
game_c_0 <= game_c_i;
always @(posedge clk_i)
game_b_1 <= game_b_i;

While you might think that the clock edge constraint would apply to game_c, it does not. The signal game_c_0 would be interpreted as combinatorial by the compiler. The "always @(posedge clk_i)" works just like an if statement in C. When you use an if statement in C, it only apply to the very next statement UNLESS you use the compound statement braces.
Therefore, it is better for readability and fewer errors when modifying to use your "CASE #1".
 

    choonlle

    Points: 2
    Helpful Answer Positive Rating
Re: Verilog RTL syntax

From synthesis point of view...the hardware generated by the tool for the two cases are identical...

i suggest to use case1, since u have all the operations based on the same clock, there is no need to put more always@

Regards,
dcreddy
 

    choonlle

    Points: 2
    Helpful Answer Positive Rating
Verilog RTL syntax

I think it is no difference to synthesis tool.
But i am prefer :

always @( posedge clk_i )
begin
game_a_0 <= game_a_i;
end

always @( posedge clk_i )
begin
game_b_1 <= game_b_i;
end

Only one variable is assigned in one always block
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top