VHDL coding tips and tricks: How to use ieee_proposed libraries in Modelsim?

Wednesday, October 18, 2017

How to use ieee_proposed libraries in Modelsim?

You might have come across the ieee_proposed fixed and floating point packages, if you were looking for ways to deal with fractional numbers in VHDL. These libraries are amazing. But they are not so widely supported by simulation and synthesis tools like other ieee libraries.

Many tools use their own version of these libraries.

Lets see what I meant. See the below code, using the floating point operations + and *.

LIBRARY ieee;
library ieee_proposed;
use ieee_proposed.float_pkg.all;
 
ENTITY temp IS
port( a,b : in float(3 downto -4);
    c,d : out float(3 downto -4)
    );  
END temp;
 
ARCHITECTURE behavior OF temp IS 
 
BEGIN

<= a+b;
<= a*b;

END;

Upon compilation in Modelsim 10.4a, we would get the following errors,

** Error: D:/MODELSIM/temp.vhd(2): Library ieee_proposed not found.
** Error: D:/MODELSIM/temp.vhd(3): (vcom-1136) Unknown identifier "ieee_proposed".
** Error: D:/MODELSIM/temp.vhd(5): VHDL Compiler exiting

This error can be easily removed by just changing the name of the library. As I said, some tools, use their own version of ieee_proposed. Modelsim names it floatfixlib.

See the new code, which compiles fine, without any errors.

LIBRARY ieee;
Library floatfixlib; 
use floatfixlib.float_pkg.all;
 
ENTITY temp IS
port( a,b : in float(3 downto -4);
    c,d : out float(3 downto -4)
    );  
END temp;
 
ARCHITECTURE behavior OF temp IS 
 
BEGIN

<= a+b;
<= a*b;

END;

The code simply adds and multiplies two floating point numbers. Without this package, somebody would have had to implement the whole floating point operation from scratch.

It goes without saying that for using fixed point library, I just have to include the following line in the code,

use floatfixlib.fixed_pkg.all;

I have used Modelsim version 10.4a for this particular post.

No comments:

Post a Comment