• 沒有找到結果。

Data Types

CHAPTER 4 DATA TYPES

4.2 NUMERIC DATA TYPES

Although bytes, words, and doublewords are the fundamental data types of the IA-32 architec-ture, some instructions support additional interpretations of these data types to allow operations to be performed on numeric data types (signed and unsigned integers, and floating-point numbers). See Figure 4-3.

Figure 4-3. Numeric Data Types

0

0

0 22

0

Double Extended Precision 63 62

0

Word Signed Integer 0

Byte Signed Integer 7 6

Sign

Sign

Doubleword Signed Integer 15 14

Sign

31 30 Sign

Quadword Signed Integer 0

0

Word Unsigned Integer 0

Byte Unsigned Integer 7

Doubleword Unsigned Integer 15

31

Quadword Unsigned Integer 63

0 0 23

30 31

51 52 62 63

62 63 64 78

79 Floating Point

Single Precision Floating Point

Double Precision Floating Point Sign

Integer Bit

Sign

Sign

4-4 Vol. 1 DATA TYPES

4.2.1 Integers

The IA-32 architecture defines two types of integers: unsigned and signed. Unsigned integers are ordinary binary values ranging from 0 to the maximum positive number that can be encoded in the selected operand size. Signed integers are two’s complement binary values that can be used to represent both positive and negative integer values.

Some integer instructions (such as the ADD, SUB, PADDB, and PSUBB instructions) operate on either unsigned or signed integer operands. Other integer instructions (such as IMUL, MUL, IDIV, DIV, FIADD, and FISUB) operate on only one integer type.

The following sections describe the encodings and ranges of the two types of integers.

4.2.1.1 Unsigned Integers

Unsigned integers are unsigned binary numbers contained in a byte, word, doubleword, and quadword. Their values range from 0 to 255 for an unsigned byte integer, from 0 to 65,535 for an unsigned word integer, from 0 to 232 – 1 for an unsigned doubleword integer, and from 0 to 264 – 1 for an unsigned quadword integer. Unsigned integers are sometimes referred to as ordinals.

4.2.1.2 Signed Integers

Signed integers are signed binary numbers held in a byte, word, doubleword, or quadword. All operations on signed integers assume a two's complement representation. The sign bit is located in bit 7 in a byte integer, bit 15 in a word integer, bit 31 in a doubleword integer, and bit 63 in a quadword integer (see the signed integer encodings in Table 4-1).

Table 4-1. Signed Integer Encodings

Class Two’s Complement Encoding

Sign

Positive Largest 0 11..11

. .

. .

Smallest 0 00..01

Zero 0 00..00

Negative Smallest 1 11..11

. .

. .

Largest 1 00..00

Integer indefinite 1 00..00

Signed Byte Integer:

Signed Word Integer:

Signed Doubleword Integer:

Signed Quadword Integer:

7 bits

15 bits

31 bits

63 bits

Vol. 1 4-5 DATA TYPES

The sign bit is set for negative integers and cleared for positive integers and zero. Integer values range from –128 to +127 for a byte integer, from –32,768 to +32,767 for a word integer, from –231 to +231 – 1 for a doubleword integer, and from –263 to +263 – 1 for a quadword integer.

When storing integer values in memory, word integers are stored in 2 consecutive bytes; double-word integers are stored in 4 consecutive bytes; and quaddouble-word integers are stored in 8 consecu-tive bytes.

The integer indefinite is a special value that is sometimes returned by the x87 FPU when oper-ating on integer values. For more information, see Section 8.2.1, “Indefinites”.

4.2.2 Floating-Point Data Types

The IA-32 architecture defines and operates on three floating-point data types: single-precision floating-point, double-precision floating-point, and double-extended precision floating-point (see Figure 4-3). The data formats for these data types correspond directly to formats specified in the IEEE Standard 754 for Binary Floating-Point Arithmetic.

Table 4-2 gives the length, precision, and approximate normalized range that can be represented by each of these data types. Denormal values are also supported in each of these types.

NOTE

Section 4.8, “Real Numbers and Floating-Point Formats” gives an overview of the IEEE Standard 754 floating-point formats and defines the terms integer bit, QNaN, SNaN, and denormal value.

Table 4-3 shows the floating-point encodings for zeros, denormalized finite numbers, normal-ized finite numbers, infinites, and NaNs for each of the three floating-point data types. It also gives the format for the QNaN floating-point indefinite value. (See Section 4.8.3.7, “QNaN Floating-Point Indefinite” for a discussion of the use of the QNaN floating-point indefinite value.)

For the single-precision and double-precision formats, only the fraction part of the significand is encoded. The integer is assumed to be 1 for all numbers except 0 and denormalized finite numbers. For the double extended-precision format, the integer is contained in bit 63, and the most-significant fraction bit is bit 62. Here, the integer is explicitly set to 1 for normalized numbers, infinities, and NaNs, and to 0 for zero and denormalized numbers.

Table 4-2. Length, Precision, and Range of Floating-Point Data Types Data Type Length Precision

(Bits) Approximate Normalized Range

Binary Decimal

Single Precision 32 24 2–126 to 2127 1.18 × 10–38 to 3.40 × 1038 Double Precision 64 53 21022 to 21023 2.23 × 10–308 to 1.79 × 10308 Double Extended Precision 80 64 2–16382 to 216383 3.37 × 10–4932 to 1.18 × 104932

4-6 Vol. 1 DATA TYPES

The exponent of each floating-point data type is encoded in biased format; see Section 4.8.2.2,

“Biased Exponent”. The biasing constant is 127 for the single-precision format, 1023 for the double-precision format, and 16,383 for the double extended-precision format.

When storing floating-point values in memory, single-precision values are stored in 4 consecu-tive bytes in memory; double-precision values are stored in 8 consecuconsecu-tive bytes; and double extended-precision values are stored in 10 consecutive bytes.

Table 4-3. Floating-Point Number and NaN Encodings

Class Sign Biased Exponent Significand

Integer1 Fraction

Positive +∞ 0 11..11 1 00..00

+Normals 0

. . 0

11..10 . . 00..01

1 . . 1

11..11 . . 00..00

+Denormals 0

. . 0

00..00 . . 00..00

0 . . 0

11.11 . . 00..01

+Zero 0 00..00 0 00..00

Negative −Zero 1 00..00 0 00..00

−Denormals 1

. . 1

00..00 . . 00..00

0 . . 0

00..01 . . 11..11

−Normals 1

. . 1

00..01 . . 11..10

1 . . 1

00..00 . . 11..11

−∞ 1 11..11 1 00..00

NaNs SNaN X 11..11 1 0X..XX2

QNaN X 11..11 1 1X..XX

QNaN Floating-Point Indefinite

1 11..11 1 10..00

Single-Precision:

Double-Precision:

Double Extended-Precision:

8 Bits

11 Bits

15 Bits

23 Bits

52 Bits

63 Bits

NOTES:

1. Integer bit is implied and not stored for single-precision and double-precision formats.

2. The fraction for SNaN encodings must be non-zero with the most-significant bit 0.

Vol. 1 4-7 DATA TYPES

The single-precision and double-precision floating-point data types are operated on by x87 FPU, and SSE/SSE2/SSE3 instructions. The double-extended-precision floating-point format is only operated on by the x87 FPU. See Section 11.6.8, “Compatibility of SIMD and x87 FPU Floating-Point Data Types” for a discussion of the compatibility of single-precision and double-precision floating-point data types between the x87 FPU and SSE/SSE2/SSE3 extensions.