VHDL标准包与定点包详解
立即解锁
发布时间: 2025-08-16 01:28:57 阅读量: 2 订阅数: 11 


VHDL设计指南:从入门到精通
### VHDL标准包与定点包详解
#### 1. 标准包概述
在VHDL编程中,标准包起着至关重要的作用,它们提供了一系列的函数、类型和常量,方便开发者进行各种操作。下面我们将详细介绍一些重要的标准包及其功能。
#### 2. numeric_std_unsigned包
numeric_std_unsigned包定义了一些用于类型转换的函数和别名。以下是该包的部分代码:
```vhdl
To_StdLogicVector[natural, std_ulogic_vector return std_logic_vector];
alias To_SLV is
To_StdLogicVector[natural, std_ulogic_vector return std_logic_vector];
function To_StdULogicVector (arg : natural; size : natural)
return std_ulogic_vector;
function To_StdULogicVector (arg : natural; size_res : std_ulogic_vector)
return std_ulogic_vector;
alias To_Std_ULogic_Vector is
To_StdULogicVector[natural, natural return std_ulogic_vector];
alias To_SULV is
To_StdULogicVector[natural, natural return std_ulogic_vector];
alias To_Std_ULogic_Vector is
To_StdULogicVector[natural, std_ulogic_vector
return std_ulogic_vector];
alias To_SULV is
To_StdULogicVector[natural, std_ulogic_vector
return std_ulogic_vector];
end package numeric_std_unsigned;
```
需要注意的是,VHDL - 87、 - 93和 - 2002版本不提供numeric_std_unsigned包。
#### 3. 标准定点包
标准定点包在处理定点数运算时非常有用。下面我们将详细介绍相关的包。
##### 3.1 fixed_float_types包
fixed_float_types包用于定义标准定点包和标准浮点包的通用常量类型。以下是该包的代码:
```vhdl
package fixed_float_types is
type fixed_round_style_type is (fixed_round, fixed_truncate);
type fixed_overflow_style_type is (fixed_saturate, fixed_wrap);
type round_type is (round_nearest, round_inf, round_neginf, round_zero);
end package fixed_float_types;
```
该包定义了三种类型:
- `fixed_round_style_type`:包含`fixed_round`(四舍五入)和`fixed_truncate`(截断)两种舍入方式。
- `fixed_overflow_style_type`:包含`fixed_saturate`(饱和)和`fixed_wrap`(回绕)两种溢出处理方式。
- `round_type`:包含`round_nearest`(四舍五入到最近值)、`round_inf`(向正无穷舍入)、`round_neginf`(向负无穷舍入)和`round_zero`(向零舍入)四种舍入类型。
##### 3.2 fixed_generic_pkg包
fixed_generic_pkg包是一个通用的定点包,它依赖于`std.textio`、`ieee.std_logic_1164`、`ieee.numeric_std`和`ieee.fixed_float_types`包。以下是该包的部分代码:
```vhdl
use std.textio.all;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
use ieee.fixed_float_types.all;
package fixed_generic_pkg is
generic (
fixed_round_style : fixed_round_style_type := fixed_round;
fixed_overflow_style : fixed_overflow_style_type := fixed_saturate;
fixed_guard_bits : natural := 3;
no_warning : boolean := false
);
-- Author David Bishop ([email protected])
constant CopyRightNotice : string :=
"Copyright 2008 by IEEE. All rights reserved.";
type unresolved_ufixed is array (integer range <>) of std_ulogic;
type unresolved_sfixed is array (integer range <>) of std_ulogic;
alias u_ufixed is unresolved_ufixed;
alias u_sfixed is unresolved_sfixed;
subtype ufixed is (resolved) unresolved_ufixed;
subtype sfixed is (resolved) unresolved_sfix
```
0
0
复制全文
相关推荐










