- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-29-2009 02:21 PM
Just got bit by what appears to be a problem with XST and the $clog2 verilog function.
Using XST 11.3 and the simple testbench
module tb;
parameter A = $clog2(325);
endmodule
I get:
=================================================
* HDL Synthesis *
==================================================
Synthesizing Unit <tb>.
Related source file is "/home/jcasper/tmp/vtmp/clog2.v".
A = 6
Summary:
no macro.
Unit <tb> synthesized.
I would expect A to be 9, the ceiling of log2(325), not 6, which seems to come out of left field. Am I confused or does XST not know how to calculate clog2?
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-29-2009 02:45 PM
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-29-2009 03:26 PM
jc,
I can't find any support for that function in the xst manual.
In fact, I can't find any support for that function in vhdl.
The standard does not define arithmetic functions (beyond the simplest) so that will be dependent on the library that you are including for math functions.
Whose library are you including?
Principal Engineer
Xilinx San Jose
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-29-2009 03:40 PM
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-29-2009 03:44 PM
Just to be clear:
$ cat clog2.v
module tb;
parameter A = $clog2(325);
endmodule
$ cat clog2.prj
verilog work clog2.v
$ cat clog2.scr
run
-p xc6slx16-2-csg324
-top tb
-ifn clog2.prj
-ofn clog2.ngc
$ xst -ifn clog2.scr -intstyle ise
....
Synthesizing Unit <tb>.
Related source file is "/home/jcasper/tmp/vtmp/clog2.v".
A = 6
Summary:
no macro.
Unit <tb> synthesized.
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-30-2009 03:18 PM
XST does not support $clog2 since it is a Verilog 2005 construct. However, you can write your own version of the function. You can use it as a constant function when you compute port widths and so forth. There is a catch though. XST has a bug where it can't use constant functions anywhere except the right hand side of parameter assignments. So, you need to have a parameter declared as the result of the constant function and then use the parameter in your port declarations.
You can read a detailed description of this on my blog...
http://www.beyond-circuits.com/wordpress/2008/11/c
-Pete
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
10-31-2009 12:56 AM
Well if it doesn't support it, it should issue an error and not attempt to support it incorrectly.
Thanks for the tip about the constant function issues.
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-07-2009 06:34 AM
Hi,
We defined this as a Verilog macro and that works fine on most tools. Curiously, the same tools seem to have little difficulty understanding it on VHDL as a function. If you'd like to see the verilog, please tell me.
Johan
Re: XST and $clog2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-27-2012 10:01 PM
Well, this is weird. Having log10 result from log2 name function with no sign of warning or error...
Here's a workaround if someone will prefer to use 'officially not supported' built-in functions over constant-functions approach:
module counter #( parameter COUNTER_VALUE = 17, parameter integer COUNTER_WIDTH = $ceil($log10(COUNTER_VALUE)/$log10(2)) ) ...
the important part is to force type of COUNTER_WIDTH to integer (otherwise it's 'real' and no chance to specify a range with it). Expression inside $ceil() call is just a use of one of math properties of log functions: log2(x) = log10(x)/log10(2). Seems to work for 13.1 although it's not documented...
Regards,
Vladislav











