最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

system verilog - Correct syntax of SystemVerilog $display to produce formatted messages in Quartus message window - Stack Overfl

programmeradmin0浏览0评论

I often use $display, $error, $fatal functions in SystemVerilog to display all sorts of numeric values. When working with Questa for example, the following will correctly display the output to the console:

localparam uint64_t timeout_active = integer'(500e-6 / (g_clockPeriod * 1e-9));
$display(g_instance_name, ": Timeout to get 500us active time is %0d clock cycles", 
         timeout_active);

The following correctly displays in the console:

# motor: Timeout to get 500us active time is 25000 clock cycles

When I write %d instead of %0d, modelsim prepends spaces in place of zeros, the resulting console string looks as:

# motor: Timeout to get 500us active time is                25000 clock cycles

The same thing, during Quartus compilation however, it displays the messages completely differently.

This is how it shows when using %0d in the display:

Info (10648): Verilog HDL Display System Task info at motor.sv(162): rtm: 
Timeout to get 500us active time is %0d clock 
cycles64'b0000000000000000000000000000000000000000000000001111010000100100

The Quartus seems to ignore any formatting requests, and in addition, for certain types (as here, 64-bit integer), ignores decimal display, and shows binary representation.

The latter one can be caused just by 'logic' type used (uint64_t = logic [63:0]), but Quartus ignores formatting on ordinary integers/reals as well.

What is the proper way to use $display with Quartus?

I often use $display, $error, $fatal functions in SystemVerilog to display all sorts of numeric values. When working with Questa for example, the following will correctly display the output to the console:

localparam uint64_t timeout_active = integer'(500e-6 / (g_clockPeriod * 1e-9));
$display(g_instance_name, ": Timeout to get 500us active time is %0d clock cycles", 
         timeout_active);

The following correctly displays in the console:

# motor: Timeout to get 500us active time is 25000 clock cycles

When I write %d instead of %0d, modelsim prepends spaces in place of zeros, the resulting console string looks as:

# motor: Timeout to get 500us active time is                25000 clock cycles

The same thing, during Quartus compilation however, it displays the messages completely differently.

This is how it shows when using %0d in the display:

Info (10648): Verilog HDL Display System Task info at motor.sv(162): rtm: 
Timeout to get 500us active time is %0d clock 
cycles64'b0000000000000000000000000000000000000000000000001111010000100100

The Quartus seems to ignore any formatting requests, and in addition, for certain types (as here, 64-bit integer), ignores decimal display, and shows binary representation.

The latter one can be caused just by 'logic' type used (uint64_t = logic [63:0]), but Quartus ignores formatting on ordinary integers/reals as well.

What is the proper way to use $display with Quartus?

Share Improve this question asked Jan 29 at 16:22 David BelohradDavid Belohrad 4686 silver badges24 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 1

Some tools permit string formatting to only with the first argument. Looking through the IEEE Std 1800-2023 LRM, most of the examples of $display and $write use only the first argument for string formatting.

Per the IEEE Std 1800-2023 § 21.3.3 Formatting data to a string:

Unlike the display and write family of output system tasks, $sformat always interprets its second argument, and only its second argument, as a format string.

Quartus probability reusing the same underlining code to implement $display as it did with the the more restrictive $sformat.

Moving your g_instance_name after the format sting and including it into the the format string should work:

$display("%s: Timeout to get 500us active time is %0d clock cycles",
         g_instance_name, timeout_active);

The IEEE 1800-2023 SystemVerilog LRM section 21.2.1.2 Size of displayed data says:

When displaying decimal values, leading zeros are suppressed and replaced by spaces. In other radices, leading zeros are always displayed. [...]
If the field width is 0, the result is displayed in the minimum width, with no leading spaces or zeros

So this appears to be a bug. You might try displaying it unformatted

$display(g_instance_name, ": Timeout to get 500us active time is ", timeout_active, " clock cycles");

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论