A
Andy Peters
I'm evaluating Aldec Active-HDL v8.2, and it stumbles on the following
function:
function TimeToClocks (
timer : time;
clkper : time)
return natural is
variable division : natural;
variable remainder : time;
begin
division := timer / clkper;
remainder := timer rem clkper;
-- always round UP if the remainder is not zero.
if remainder /= (0 FS) then
division := division + 1;
end if;
division := division - 1;
return division;
end function TimeToClocks;
The compiler, set to analyzer to VDHL-2002, throws three errors, all
from the remainder assignment:
# Error: COMP96_0077: consts.vhdl : (765, 22): Assignment target
incompatible with right side. Expected type 'TIME'.
# Error: COMP96_0071: consts.vhdl : (765, 22): Operator "rem" is not
defined for such operands.
# Error: COMP96_0104: consts.vhdl : (765, 22): Undefined type of
expression.
What's odd is that ModelSim, similarly set to use the 2002 standard,
accepts the code without complaint. What's odder still is that if I
change remainder's type to natural. ModelSim throws the following
error:
# ** Error: consts.vhdl(765): Target type std.standard.natural in
variable assignment is different from expression type
std.standard.time.
and Active-HDL doesn't even try:
# Error: COMP96_0071: consts.vhdl : (765, 22): Operator "rem" is not
defined for such operands.
So my assumption was that dividing time by time would give me a
unitless result.
I can accept that dividing time by time would be bad, but why does
ModelSim accept it?
I suppose casting to natural would be a reasonable solution.
-a
function:
function TimeToClocks (
timer : time;
clkper : time)
return natural is
variable division : natural;
variable remainder : time;
begin
division := timer / clkper;
remainder := timer rem clkper;
-- always round UP if the remainder is not zero.
if remainder /= (0 FS) then
division := division + 1;
end if;
division := division - 1;
return division;
end function TimeToClocks;
The compiler, set to analyzer to VDHL-2002, throws three errors, all
from the remainder assignment:
# Error: COMP96_0077: consts.vhdl : (765, 22): Assignment target
incompatible with right side. Expected type 'TIME'.
# Error: COMP96_0071: consts.vhdl : (765, 22): Operator "rem" is not
defined for such operands.
# Error: COMP96_0104: consts.vhdl : (765, 22): Undefined type of
expression.
What's odd is that ModelSim, similarly set to use the 2002 standard,
accepts the code without complaint. What's odder still is that if I
change remainder's type to natural. ModelSim throws the following
error:
# ** Error: consts.vhdl(765): Target type std.standard.natural in
variable assignment is different from expression type
std.standard.time.
and Active-HDL doesn't even try:
# Error: COMP96_0071: consts.vhdl : (765, 22): Operator "rem" is not
defined for such operands.
So my assumption was that dividing time by time would give me a
unitless result.
I can accept that dividing time by time would be bad, but why does
ModelSim accept it?
I suppose casting to natural would be a reasonable solution.
-a