64-bit data models



The 64-bit architecture has the following advantages:
  • A 64-bit application can directly access 4 exabytes( 1 exabyte = 1018 bytes (or)  260 bytes ) of virtual memory, and the Intel Itanium processor provides a contiguous linear address space.
  • 64-bit Linux allows for file sizes up to 4 exabytes, a very significant advantage to servers accessing large databases.


32-bit and 64-bit data models
ILP32LP64LLP64ILP64
char8888
short16161616
int32323264
long32643264
long long64646464
pointer32646464
Note:
The disadvantage of the LP64 model is that storing a long into an int may overflow. On the other hand, casting a pointer to a long will work. In the LLP model, the reverse is true.

The difference among the three 64-bit models (LP64, LLP64, and ILP64) lies in the non-pointer data types. When the width of one or more of the C data types changes from one model to another, applications may be affected in various ways. These effects fall into two main categories:

  • Size of data objects. The compilers align data types on a natural boundary; in other words, 32-bit data types are aligned on a 32-bit boundary on 64-bit systems, and 64-bit data types are aligned on a 64-bit boundary on 64-bit systems. This means that the size of data objects such as a structure or a union will be different on 32-bit and 64-bit systems.
  • Size of fundamental data types. Common assumptions about the relationships between the fundamental data types may no longer be valid in a 64-bit data model. Applications that depend on those relationships will fail when compiled on a 64-bit platform. For example, the assumption sizeof (int) = sizeof (long) = sizeof (pointer) is valid for the ILP32 data model, but not valid for others.

Sample Operating Systems:

Microsoft Win64 (X64/IA64) => LLP64

Most Unix and Unix-like systems (Solaris, Linux, HP-UX Itanium , etc.) => LP64



Endianism refers to the way in which data is stored, and defines how bytes are addressed in integral and floating point data types.
Little-endian means that the least significant byte is stored at the lowest memory address and the most significant byte is stored at the highest memory address.
Big-endian means that the most significant byte is stored at the lowest memory address and the least significant byte is stored at the highest memory address.
Table 3 shows a sample layout of a 64-bit long integer.

Table 3. Layout of a 64-bit long int

Low addressHigh address
Little endianByte 0Byte 1Byte 2Byte 3Byte 4Byte 5Byte 6Byte 7
Big endianByte 7Byte 6Byte 5Byte 4Byte 3Byte 2Byte 1Byte 0


For example, the 32-bit word 0x12345678 will be laid out on a big endian machine as follows:

Table 4. 0x12345678 on a big-endian system

Memory offset0123
Memory content0x120x340x560x78


If we view 0x12345678 as two half words, 0x1234 and 0x5678, we would see the following in a big endian machine:

Table 5. 0x12345678 as two half words on a big-endian system

Memory offset02
Memory content0x12340x5678


However, on a little endian machine, the word 0x12345678 will be laid out as follows:

Table 6. 0x12345678 on a little-endian system

Memory offset0123
Memory content0x780x560x340x12


Similarly, the two half-words 0x1234 and 0x5678 would look like the following:

Table 7. 0x12345678 as two half words on a little-endian system

Memory offset02
Memory content0x56780x1234


The following example illustrates the difference in byte order between big endian and little endian machines.
The C program below will print out "Big endian" when compiled and run on a big endian machine, and "Little endian" when compiled and run on a little endian machine.

Listing 2. Big endian vs. little endian

#include 
main () {
int i = 0x12345678;
if (*(char *)&i == 0x12)
printf ("Big endian\n");
else if (*(char *)&i == 0x78)
      printf ("Little endian\n");
}


ref:
Porting Linux Applications to 64bit - http://www.ibm.com/developerworks/library/l-port64/index.html

Migrating to Solaris 64-bit: 32-bit Applications and Data Model - http://developers.sun.com/solaris/articles/solarisupgrade/64bit/Convert.html

Converting 32-bit Applications Into 64-bit Applications: Things to Consider - http://developers.sun.com/solaris/articles/ILP32toLP64Issues.html