Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - The 'impure' construct

 
Thread Tools Search this Thread
Old 01-04-2006, 01:46 AM   #1
Default The 'impure' construct


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
  Reply With Quote
Old 01-04-2006, 02:08 AM   #2
Mike Treseler
 
Posts: n/a
Default Re: The 'impure' construct
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


Mike Treseler
  Reply With Quote
Old 01-04-2006, 07:55 AM   #3
Reiner Huober
 
Posts: n/a
Default Re: The 'impure' construct
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.



Reiner Huober
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46