Documentation

Data Types and Scaling in Digital Hardware

在数字硬件中,数字以二进制单词存储。二进制单词是二进制数字(1和0)的固定长度序列。硬件组件或软件功能解释1和0的顺序的方式由数据类型描述。

Binary numbers are represented as either fixed-point or floating-point data types. A fixed-point data type is characterized by the word size in bits, the binary point, and whether it is signed or unsigned. The position of the binary point is the means by which fixed-point values are scaled and interpreted. With the Fixed-Point Designer™ software, fixed-point data types can be integers, fractionals, or generalized fixed-point numbers. The main difference between these data types is their default binary point. For example, a binary representation of a generalized fixed-point number (either signed or unsigned) is shown below:

where

  • bi是个ithbinary digit.

  • wl是个word length in bits.

  • bwl-1是个location of the most significant, or highest, bit (MSB).

  • b0是个location of the least significant, or lowest, bit (LSB).

  • The binary point is shown four places to the left of the LSB. In this example, therefore, the number is said to have four fractional bits, or a fraction length of four.

Binary Point Interpretation

二进制点是缩放固定点的均值。通常是决定二进制点的软件。当执行基本数学功能(例如加法或减法)时,硬件使用相同的逻辑电路,而不管比例因子的值如何。从本质上讲,逻辑电路不了解规模因素。他们正在执行签名或未签名的固定点二进制代数,就好像二进制点在b0

定点设计师supports the generalbinary point scaling V = Q * 2 ^ E V是个real-world value,Q是个stored integer value, andEis equal to-FractionLength。In other words,REALWORLDVALUE = StordInteger * 2 ^ -FractionLength

分数长defines the scaling of the stored integer value. The word length limits the values that the stored integer can take, but it does not limit the values分数长can take. The software does not restrict the value of exponentE基于存储整数的单词长度Q。BecauseEis equal to-FractionLength,将二进制点限制在与分数相邻的情况下是不必要的;分数长度可能为负或大于单词长度。

例如,通常表示由三个未签名位组成的单词scientific notationin one of the following ways.

b b b = b b b × 2 0 b b b = b b b × 2 1 b b b = b b b × 2 2 b b b = b b b × 2 3

If the exponent were greater than 0 or less than -3, then the representation would involve lots of zeros.

b b b 00000。 = b b b × 2 5 b b b 00. = b b b × 2 2 。00 b b b = b b b × 2 5 .00000 b b b = b b b × 2 8

但是,这些额外的零永远不会改变,因此它们不会出现在硬件中。此外,与浮点指数不同,固定点指数从未出现在硬件中,因此固定点指数不受有限数量的位数的限制。

考虑一个单词长度为8的签名值,分数长度为10,存储的整数值为5(二进制值00000101). The real-word value is calculated using the formula
REALWORLDVALUE = StordInteger * 2 ^ -FractionLength。在这种情况下,REALWORLDVALUE = 5 * 2 ^ -10 = 0.0048828125。因为分数长度比单词长度长2位,所以存储整数的二进制值为x.xx00000101, wherexis a placeholder for implicit zeros.0.0000000101(二进制)等同于0.0048828125(decimal). For an example using afiobject, seeFraction Length Greater Than Word Length

Signed Fixed-Point Numbers

Computer hardware typically represents the negation of a binary fixed-point number in three different ways: sign/magnitude, one's complement, and two's complement. Two's complement是个preferred representation of signed fixed-point numbers and is the only representation used by Fixed-Point Designer software.

Negation using two's complement consists of a bit inversion (translation into one's complement) followed by the addition of a one. For example, the two's complement of 000101 is 111011.

是否在二进制字中签名或未签名的定点值通常不明确编码;也就是说,没有符号。相反,符号信息是在计算机体系结构中隐式定义的。

Floating-Point Data Types

浮点数据类型的特征是符号位,分数(或mantissa)字段和指数字段。定点设计师遵守IEEE®Standard 754-1985 for Binary Floating-Point Arithmetic (referred to simply as the IEEE Standard 754 throughout this guide) and supports singles and doubles.

When choosing a data type, you must consider these factors:

  • The numerical range of the result

  • 结果所需的精度

  • The associated quantization error (i.e., the rounding mode)

  • The method for dealing with exceptional arithmetic conditions

这些选择取决于您的特定应用程序,所使用的计算机架构以及开发成本等。

With the Fixed-Point Designer software, you can explore the relationship between data types, range, precision, and quantization error in the modeling of dynamic digital systems. With the金宝app®CODER™product, you can generate production code based on that model. With HDL Coder™, you can generate portable, synthesizable VHDL and Verilog code from Simulink models and Stateflow®charts.

Fixed-point data types can be either signed or unsigned. Signed binary fixed-point numbers are typically represented in one of three ways:

相关话题