Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Package and Function in VHDL

Status
Not open for further replies.
Packages: a package is like a library of stuff that can be imported. You probably use one package in every VHDL file you write:

use ieee.std_logic_1164.all;

std_logic_1164 is a package that contains the std_logic type and how it behaves.

Functions: All functions are pure unless declared impure. Pure functions are self contained. Impure functions can modify elements not contained within the function.:

Code:
variable a : integer := 0;

impure function do_something(x : integer) return integer is
begin
  a := a + 1;  --this changes the value of a that is declared OUTSIDE the function

  return x + a;
end function do_something;

This function would be illegal if it was pure.
 
thank you
still i don't understand why there are a pure and impure fn.
it will be great if you gives me a small example of both.
 

like I said, a pure function has to be self contained:

Code:
function do_something(x : integer) return integer is
begin
  return x + 1;
end function;

Its pure because it doesnt access anything externally, so can therefore be called in any file.

Code:
variable a : integer := 0;

impure function do_something(x : integer) return integer is
begin
  a := a + 1;  --this changes the value of a that is declared OUTSIDE the function

  return x + a;
end function do_something;

This accesses and modifes the external a variable, so could only run if there was a variable called "a" within the scope of the function call.

You will probably never need to use an impure function. Impure functions usually imply poor design.
 
thank you
still i don't understand why there are a pure and impure fn.
it will be great if you gives me a small example of both.

first you need to use it on shared variable outside a process range.
you can then be able to protect share variable from modifications.
you can use multiple impure functions to read a global variable/shared variable (without decalaring it in the function header). this way variable will not be changed by those functions.
 

first you need to use it on shared variable outside a process range.
you can then be able to protect share variable from modifications.
you can use multiple impure functions to read a global variable/shared variable (without decalaring it in the function header). this way variable will not be changed by those functions.

This doesnt make much sense, and it sounds like very bad design practice to me...

Plus an impure function can be used on variables, shared variables and signals, not just shared variables.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top