-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cf_math_pkg tool incompatibilty #105
Comments
In general, math system functions, such as "Constant system function calls are calls to certain built-in system functions where the arguments meet conditions outlined in this subclause. When used in constant expressions, these function calls shall be evaluated at elaboration time. The system functions that may be used in constant system function calls are pure functions, i.e., those whose value depends only on their input arguments and that have no side effects. Certain built-in system functions where the arguments are constant expressions are constant system function." (11.2.1) (Quotes and section references from IEEE 1800-2012.) Because some EDA tools have bugs concerning constant system function calls, I have had some success defining a constant function // Ceiled Binary Logarithm of a Natural Number
//
// Returns the binary logarithm (i.e., the logarithm to the base 2) of a natural number rounded
// towards plus infinity.
//
// Use this as drop-in replacement for the `$clog2` system function where the latter is not
// supported by your toolchain.
// Ceiled Binary Logarithm of a Natural Number
//
// Returns the binary logarithm (i.e., the logarithm to the base 2) of a natural number rounded
// towards plus infinity.
//
// Use this as drop-in replacement for the `$clog2` system function where the latter is not
// supported by your toolchain.
function automatic integer clog2 (input longint unsigned val);
automatic longint unsigned tmp;
// pragma translate_off
`ifndef VERILATOR
if (val == 0) begin
$fatal(1, "Logarithm of 0 cannot be represented!");
end
`endif
// pragma translate_on
tmp = val - 1;
for (clog2 = 0; tmp > 0; clog2++) begin
tmp = tmp >> 1;
end
endfunction and calling into this |
Ah sorry, of course, I mean constant expressions, not the |
For whoever comes with the same problem of compile time errors in DC, the aforementioned solution works. |
The use of
$clog2
on a (generally non-static) function argument does not compile unless using the last year's [synthesis tool that shall not be named] or newer.Found here:
common_cells/src/cf_math_pkg.sv
Line 58 in a06e4be
This is bad since functions from
cf_math_pkg
were shoehorned into other common cells and subsequently massively break tool compatibility of IPs using common cells such asfpnew
.I'm not sure what the correct solution to the problem is because the use of
clog2
is not illegal per se, just not generally synthesizable unless the argument is known static.The text was updated successfully, but these errors were encountered: