The 'impure' construct

A

Alif Wahid

Guest
A quick explanation of the 'impure' construct/keyword in VHDL would be
much appreciated. My VHDL reference (Rushton's "VHDL for Logic
Synthesis") doesn't seem to provide any explanation for it although I
could have missed it entirely.

Regards,

Alif.
 
Alif Wahid wrote:
A quick explanation of the 'impure' construct/keyword in VHDL would be
much appreciated.
A pure function requires parameter declarations.
An impure function can use anything in scope.
For example:

impure function bit_done return boolean is begin
return TxBitSampleCount_v = roll_c; -- counter rollover
end function bit_done;

For simple input-only functions like this
there is little risk of side effects and
the meaning is clear. Works fine on
all my tools.

-- Mike Treseler
 
Prior to VHDL 93, all (self declared) functions were implicitely pure.
This means, that when you call them with the same parameters, you will
always get the same result. In computer language these are called
functions with "no side effects".

If you know that functions have no side effects, several optimizations
are possible. For instance, the construct

IF func1(a,b) and func2(a,b) THEN

can evaluate func1 and func2 in any order, if func1 and func2 are pure.
This means, the result will be the same (excpt errors). If func1
returns false, the call of func2 may even be omitted, and vice versa.

Mathematical functions (sin(x), exp(x)) are pure functions. However,
functions like random(), or even read() are impure. Impure functions
have some internal state (coming from variables/signals outside the
function).

If you want to create a random number generator with a function
random(), this was not possible in VHDL'87 - you had to use a procedure
with an out parameter. In VHDL93 you can declare the function random as
impure:

--- very dumb random generator, unchecked
shared variable rstate:=3;
impure function random return integer is
begin
rstate:=(5*rstate+3) mod 16;
end function random;

Hubble.
 

Welcome to EDABoard.com

Sponsor

Back
Top