| Both sides previous revisionPrevious revision | |
| en:multiasm:papc:chapter_6_4 [2026/03/29 18:50] – [Data Types and Encoding] ktokarz | en:multiasm:papc:chapter_6_4 [2026/06/22 12:04] (current) – pczekalski |
|---|
| ====== Data Types and Encoding ====== | ====== Data Types and Encoding ====== |
| The x86 family of processors allows for computations on integer, floating-point, and vector data. This data is stored in memory as binary strings of varying lengths. In this chapter, we will present fundamental data types, as well as the types based on them found in assembly language programs. | The x86 family of processors allows for computations on integer, floating-point, and vector data. This data is stored in memory as binary strings of varying lengths. In this chapter, we will present fundamental data types and the types derived from them in assembly language programs. |
| ===== Fundamental data types ===== | ===== Fundamental data types ===== |
| Fundamental data types cover the types of data elements that are stored in memory as 8-bit (Byte), 16-bit (Word), 32-bit (Doubleword), 64-bit (Quadword) or 128-bit (Double quadword), as shown in figure {{ref>fundamentaldata}}. Many instructions allow for processing data of these types without special interpretation. It depends on the programming engineer how to interpret the inputs and results of instruction execution. The order of bytes in the data types containing more than a single byte is little-endian. The lower (least significant) byte is stored at the lower address of the data. This address represents the address of the data as a whole. | Fundamental data types are the data elements stored in memory as 8-bit (Byte), 16-bit (Word), 32-bit (Doubleword), 64-bit (Quadword), or 128-bit (Double quadword), as shown in figure {{ref>fundamentaldata}}. Many instructions allow processing of these data types without special interpretation. It depends on the programming engineer how to interpret the inputs and results of instruction execution. The order of bytes in data types that contain more than a single byte is little-endian. The lower (least significant) byte is stored at the lower address of the data. This address represents the address of the data as a whole. |
| |
| <figure fundamentaldata> | <figure fundamentaldata> |
| </figure> | </figure> |
| |
| The data types which can be used in the x64 architecture processors can be integers or floating point numbers. Integers are processed by the main CPU as single values (scalars). They can also be packed into vectors and processed with the specific SIMD instructions, including MMX and partially by SSE and AVX instructions. Integers can be interpreted as unsigned or signed. They can also represent the pointer to some variable or address within the code. Scalar real numbers are processed by the FPU. SSE and AVX instructions support calculations with scalars or vectors composed of real values. All possible variants of data types are stored within the fundamental data types. Further in this chapter, we describe all possible singular or packed integers and floating-point values. | The data types that can be used in x64-architecture processors are integers and floating-point numbers. Integers are processed by the main CPU as single values (scalars). They can also be packed into vectors and processed with specific SIMD instructions, including MMX and, in part, SSE and AVX. Integers can be interpreted as unsigned or signed. They can also represent the pointer to some variable or address within the code. The FPU processes scalar real numbers. SSE and AVX instructions support calculations with scalars or vectors composed of real values. All possible variants of data types are stored within the fundamental data types. Further in this chapter, we describe all possible singular or packed integers and floating-point values. |
| |
| ===== Integers ===== | ===== Integers ===== |
| Integers are the numbers without the fractional part. In x64 architecture, it is possible to define a variety of data of different sizes, all of them based on bytes. A single byte forms the smallest possible information item stored in memory. Even if not all bits are effectively used, the smallest element which can be stored is a byte. Two bytes form the word. It means that in x64 architecture, Word data type means 16 bits. Two words form the Double Word data type (32 bits), and four words form the Quad Word data type (64 bits). With the use of large registers in modern processors, it is possible to use in a few instructions the Double Quad Word data type, containing 128 bits (sometimes called Octal Word). | Integers are the numbers without the fractional part. In the x64 architecture, it is possible to define a variety of data types of different sizes, all of which are based on bytes. A single byte forms the smallest possible information item stored in memory. Even if not all bits are effectively used, the smallest element which can be stored is a byte. Two bytes form the word. It means that in the x64 architecture, the Word data type is 16 bits. Two words form the Double Word data type (32 bits), and four words form the Quad Word data type (64 bits). With the use of large registers in modern processors, it is possible to use the Double Quad Word data type, containing 128 bits (sometimes called Octal Word), in a few instructions. |
| |
| ===== Integer scalar data types ===== | ===== Integer scalar data types ===== |
| </table> | </table> |
| |
| Signed integers are binary encoded in 2's complement binary code. The highest bit of the value is a sign bit. If it is zero, the number is non-negative; if it is one, the value is negative. It means that the starting value is encoded as the highest bit equal to 1 and all other bits equal to zero. The maximum value is formed with a "0" bit at the highest position and bits "1" at all other positions. The x64 architecture supports the signed integer data types shown in table {{ref>sinttypes}}. | Signed integers are binary encoded in 2's complement binary code. The most significant bit of the value is the sign bit. If it is zero, the number is non-negative; if it is one, the value is negative. It means that the starting value is encoded with the highest bit set to 1 and all other bits set to 0. The maximum value is formed with a "0" bit at the highest position and bits "1" at all other positions. The x64 architecture supports the signed integer data types shown in table {{ref>sinttypes}}. |
| <table sinttypes> | <table sinttypes> |
| <caption>Signed integer data types</caption> | <caption>Signed integer data types</caption> |
| </table> | </table> |
| ===== Integer vector data types ===== | ===== Integer vector data types ===== |
| Vector data types were introduced with SIMD instructions starting with the MMX extension, and followed in the SSE and AVX extensions. They form the packed data types containing multiple elements of the same size. The elements can be considered as signed or unsigned depending on the algorithm and instructions used. | Vector data types were introduced with SIMD instructions starting with the MMX extension, and followed in the SSE and AVX extensions. They form packed data types that contain multiple elements of the same size. The elements can be considered as signed or unsigned depending on the algorithm and instructions used. |
| |
| The 64-bit packed integer data type contains eight Bytes, four Words or two Doublewords as shown in figure {{ref>packedint64}}. | The 64-bit packed integer data type contains eight Bytes, four Words or two Doublewords as shown in figure {{ref>packedint64}}. |
| </figure> | </figure> |
| |
| The 512-bit packed integer data type contains sixty-four Bytes, thirty-two Words, sixteen Doublewords, eight Quadwords or four Double Quadwords as shown in figure {{ref>packedint512}}. Double Quadwords are not used as operands, they are the results of some operations only. | The 512-bit packed integer data type contains sixty-four Bytes, thirty-two Words, sixteen Doublewords, eight Quadwords or four Double Quadwords as shown in figure {{ref>packedint512}}. Double Quadwords are not used as operands; they are the results of some operations only. |
| |
| <figure packedint512> | <figure packedint512> |
| |
| ===== Floating point values ===== | ===== Floating point values ===== |
| Floating point values store the data encoded for calculation on real numbers. Depending on the precision required for the algorithm, we can use different data sizes. Scalar data types are supported by the FPU (Floating Point Unit), offering single precision, double precision or double extended precision real numbers. In C/C++ compilers, they are referred to as float, double and long double data types, respectively. Vector (packed) floating-point data types can be processed by many SSE and AVX instructions, offering fast vector, matrix or artificial intelligence calculations. Vector units can process half precision, single precision and double precision formats. The 16-bit Brain Float format was introduced to calculate the dot scalar product to improve the efficiency of AI training and inference algorithms. Floating point data types are shown in figure {{ref>floattypes}} and described in table {{ref>tablefloattypes}}. The table shows the number of bits used. In reality, the number of mantissa bits is assumed to be one bit longer, because the highest bit representing the integer part is always "1", so there is no need to store it (except for Double extended data format, where the integer bit is present). | Floating-point values store the data encoded for calculation on real numbers. Depending on the algorithm's precision requirements, we can use different data sizes. Scalar data types are supported by the FPU (Floating Point Unit), offering single-precision, double-precision, or double-extended-precision real numbers. In C/C++, they are referred to as the float, double, and long double data types, respectively. Vector (packed) floating-point data types can be processed by many SSE and AVX instructions, offering fast vector, matrix or artificial intelligence calculations. Vector units can process half-precision, single-precision and double-precision formats. The 16-bit Brain Float format was introduced to compute dot products to improve the efficiency of AI training and inference algorithms. Floating point data types are shown in figure {{ref>floattypes}} and described in table {{ref>tablefloattypes}}. The table shows the number of bits used. In reality, the number of mantissa bits is assumed to be one bit longer, because the highest bit represents the integer part, which is always "1", so there is no need to store it (except for Double extended data format, where the integer bit is present). |
| |
| <figure floattypes> | <figure floattypes> |
| |
| ===== Floating point vector data types ===== | ===== Floating point vector data types ===== |
| Floating-point vectors are formed with single or double-precision packed data formats. They are processed by SSE or AVX instructions in a SIMD approach of processing. A 128-bit packed data format can store four single-precision data elements or two double-precision data elements. A 256-bit packed data format can store eight single-precision values or four double-precision values. A 512-bit packed data format can store sixteen single-precision values or eight double-precision values. These packed data types are shown in figure {{ref>packedfloattypes}}. Instructions operating on 16-bit half-precision values or Brain Floats can use twice as many such elements simultaneously in comparison to single-precision data. | Floating-point vectors are formed with single or double-precision packed data formats. They are processed by SSE or AVX instructions using a SIMD approach. A 128-bit packed data format can store four single-precision data elements or two double-precision data elements. A 256-bit packed data format can store eight single-precision values or four double-precision values. A 512-bit packed data format can store either 16 single-precision values or 8 double-precision values. These packed data types are shown in figure {{ref>packedfloattypes}}. Instructions operating on 16-bit half-precision values, or Brain Floats, can use twice as many such elements simultaneously as single-precision data. |
| It is worth mentioning that some instructions operate on a single floating-point value, using only the lowest elements of the operands. | It is worth mentioning that some instructions operate on a single floating-point value, using only the lowest elements of the operands. |
| |
| |
| ===== Pointers ===== | ===== Pointers ===== |
| Pointers store the address of the memory which contains interesting information. They can point to the data or the instruction. If the segmentation is enabled, pointers can be near or far. The far pointer contains the logical address (formed with the segment and offset parts). The near pointer contains the offset only. The offset can be 16, 32 or 64 bits long. The segment selector is always stored as a 16-bit number. Illustration of possible pointer types is shown in figure {{ref>pointertypes}}. | Pointers store the address of the memory which contains interesting information. They can point to the data or the instruction. If the segmentation is enabled, pointers can be near or far. The far pointer contains the logical address (formed with the segment and offset parts). The near pointer contains only the offset. The offset can be 16, 32 or 64 bits long. The segment selector is always stored as a 16-bit number. Illustration of possible pointer types is shown in figure {{ref>pointertypes}}. |
| |
| <figure pointertypes> | <figure pointertypes> |
| |
| <note> | <note> |
| The offset is often the result of complex addressing mode calculations and is called an effective address. | The offset is often the result of complex addressing-mode calculations and is called the effective address. |
| </note> | </note> |
| |