|
From: Cary R. <cy...@ya...> - 2016-03-15 08:43:50
|
That vlog95 support could be for a few reasons. It used to work that way, I expected it to be supported since it is in the standard so added the appropriate support to match named blocks or something I don't remember. I'm not exactly sure which it was, but given the code/comments I would expect the first option since the comments are fairly explicit about how this should work for SV tasks/functions.
Cary
On Monday, March 14, 2016 2:48 PM, Martin Whitaker <mai...@ma...> wrote:
Larry Doolittle wrote:
> Friends -
>
> Just for fun, I added an additional test to this sample code.
>
> module test();
> function int rounded_down_power_of_two(input int value);
> int n = 32'd0;
> int temp;
> //n = 32'd0;
> temp = value;
> while (temp > 32'd1) begin
> temp = temp / 32'd2;
> n = n + 32'd1;
> end
> return n;
> endfunction
> localparam value5 = rounded_down_power_of_two(34);
> localparam value3 = rounded_down_power_of_two(8);
> initial $display("%d %d", value5, value3);
> endmodule
>
> If n were considered static, I might expect this to print
> 5 8
> but in fact n seems to be initialized on every invocation
> (elaboration?) of rounded_down_power_of_two(), so it prints
> 5 3
> Martin, does this fit your understanding of how SystemVerilog
> is supposed to work?
Yes, because these are constant function calls, and there's a special rule for that:
"Constant function calls are evaluated at elaboration time. Their execution has no effect on the
initial values of the variables used either at simulation time or among multiple invocations of a
function at elaboration time. In each of these cases, the variables are initialized as they would be
for normal simulation."
If you try
$display("%d", rounded_down_power_of_two(34));
$display("%d", rounded_down_power_of_two(8));
you will get
5
8
Having said that, I've just tried changing the initial value of n to 1, and it has no effect. The
compiler doesn't seem to be generating the initialisation code. This is a bit of a surprise, as I
was looking at the vlog95 target code generator at the weekend, and it has code to handle this case.
Martin
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
Iverilog-devel mailing list
Ive...@li...
https://lists.sourceforge.net/lists/listinfo/iverilog-devel
|