Hi All,
Is there any simulation time will be consumed for $display?
Thanks & Regards,
Shriramvaraprasad B.
Hi All,
Is there any simulation time will be consumed for $display?
Thanks & Regards,
Shriramvaraprasad B.
In reply to SHRI12326:
Hi Shriramvaraprasad. No simulation time is consumed by $display. However, the time it takes to complete a simulation can be affected by $display tasks. If you are executing a $display task every clock cycle, say for debug purposes, then it will take longer to complete the simulation than if no $display tasks are executed.
In reply to SHRI12326:
No, $display is a procedural statement that does not consume simulated time. If you meant to say CPU time on the host running the simulation, then yes $display can consume CPU time depending on how complex the arguments to $display are.
In reply to kranthi445:
This is a wording
in the current LRM. In Verilog, all functions had to be used in expressions and always returned a value. Any routine called as a statement with no return value was categorized as a task. SystemVerilog added the concept void functions, and should have updated the terminology to system tasks.
In reply to dave_59:
In reply to SHRI12326:
No, $display is a procedural statement that does not consume simulated time. If you meant to say CPU time on the host running the simulation, then yes $display can consume CPU time depending on how complex the arguments to $display are.
Hi Dave,
When I ran below code I got the below result.
Code:
initial begin
for(i=0;i<10;i++) begin
fork
$display(“value in fork join none = %d”,i);
join_none
end
end
Result :
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
value in fork join none = 10
Is this is because the display statement consuming the CPU time.
Thanks & Regards,
Shriramvaraprasad B.
In reply to SHRI12326:
This has to do with the way
fork/join_none schedules the execution of its statements. It has nothing to do with
$display. See section 9.3.2 Parallel blocks in the 1800-2012 LRM. Specifically, the last example in that section.
In reply to dave_59:
Hi Dave,
As per the LRM - fork…join_none : The parent process continues to execute concurrently with all the processes spawned by the fork. The spawned processes do not start executing until the parent thread executes a blocking statement.
initial begin
for(i=0;i<10;i++) begin
fork
$display(“value in fork join none = %d”,i);
join_none
j = k; //blocking statement
end
end
In above case also my output is same as the result I posted previously. I am confused. Can you explain more on this.
Thanks & Regards,
Shriramvaraprasad B.
In reply to SHRI12326:
[LRM 9.3.2]::
Variables declared in the block_item_declarationof a fork-join block shall be initialized to their initialization value expression whenever execution enters their scope and before any processes are spawned.
Within a fork-join_anyor fork-join_noneblock, it shall be illegal to refer to formal arguments passed by reference other than in the initialization value expressions of variables declared in a block_item_declaration of the fork.
Desired functionality can be achieved by using automatic variable inside fork-join_none block.
module m;
initial begin
for(int i=0;i<10;i++) begin
fork
automatic int m=i;
$display("value in fork join none = %d",m);
join_none
end
end
endmodule
In reply to DigvijayS:
Hi Vijay,
In the above code if I declare int m without automatic keyword before it, then my compiler results to error. Can you explain why it is so.
From LRM-3.1a
join_none - The parent process continues to execute concurrently with all the processes spawned by the fork. The spawned processes do not start executing until the parent thread executes a blocking statement.
but the below code is providing the different result:
Code:
module fork_join_none();
int a,b,c;
initial begin
a=5;
fork
a=6;
join_none
$display(“value of A before blocking stmt a=%d”,a);
b=0; //blocking statement
$display(“value of A after blocking stmt a=%d”,a);
end
endmodule : fork_join_none
Result:
value of A before blocking stmt a= 5
value of A after blocking stmt a= 5
Thanks & Regards,
Shriramvaraprasad B.
In reply to SHRI12326:
I think it is race condition between the blocking assignment and display statement. There is no guarantee that “a” should get 6 first [as you written before] and display statement executes next.
In reply to SHRI12326:
Yes it is due to a race condition. Modify your code to:
module fork_join_none();
int a,b,c;
initial begin
a=5;
fork
a=6;
join_none
$display("value of A before blocking stmt a=%d",a);
b=0; //blocking statement
#0;
$display("value of A after blocking stmt a=%d",a);
end
endmodule : fork_join_none
and you will get the desired effect.
As a sidenote, please don’t read the 3.1a SystemVerilog LRM except for historical purposes. The 2012 LRM has been made free for download: https://standards.ieee.org/getieee/1800/download/1800-2012.pdf
In reply to dave_59:
Hi Dave,
Sorry for asking in this thread. I just wanted to know how does the following code print 311
module dummy();
initial
$display(2'b11,2'd11,2'h11);
endmodule
In reply to sai_pra99:
You are only requesting 2 bits of the number to be displayed.
'b11 = 0011 in binary → the lower 2 bits give you 3
'd11 = 1011 in binary → the lower 2 bits give you 3
'h11 = 0001_0001 in binary → the lower 2 bits give you 1
The output of "$display(2’b11,2’d11,2’h11); " should be “331”
In reply to KillSteal:
Oh ok got it. Thank You. I thought it would just concatenate the bits and give the final result value in decimal.