Overview
Several years ago we
started building C++ or C applications on various UNIX platforms
using default 32-bit mode and we ran Java applications in 32-bit JVM
environments without need of considering 64-bit options. Now we have
many options: Do I compile C++ or C applications in 64-bit objects or
32-bit objects? Do I run my 32-bit applications in 64-bit computing
environments or in 32-bit computing environments? What 64-bit options
do I need to run Java applications? What benefits or performance do I
gain to port 32-bit applications to 64-bit objects? All these
questions become valid.
Fundamental Benefit of
64-bit Computing
The memory addressing of
16-bit computing is 64KB, and the memory addressing of 32-bit
computing is increased to 4GB. Running out of addressing space is a
traditional difficulty in computing and in many large data
processing, even 4GB is still very limiting. Then how large is the
memory addressing of 64-bit computing? It is 16 exabytes. It gets
pass 4GB barrier and will take a long time to run out of addressing
space in 64-bit computing.
The fundamental
architecture of hardware from 32-bit to 64-bit is changed. The
operation systems has to be modified to take advantage of the 64-bit
computing architecture. However usually most applications are still
32-bit, the operating systems for these 64-bit architectures still
support both 32-bit and 64-bit applications. Some operating systems
can start with 32-bit mode kernel which allows to run 32-bit
applications only.
There are debate on
whether 64-bit computing is better than 32-bit computing if the
memory addressing is not more than 4GB. And also there are some cases
that some 64-bit applications would not gain any benefits from 64-bit
architecture from performance point of view. All these issues will
not in the scope of discussion.
General Differences
Between Building 32-bit Applications and 64-bit Applications
▪ Data Types
32-bit and 64-bit
computing base on two data models: ILP32 is for 32-bit and LP64 is
for 64-bit. The differences in size of data types of two data models
are one of primarily concerns of building 64-bit applications or
porting 32-bit applications to 64-bit applications. The table below
lists the basic C types and their corresponding sizes in bits.
|
C Data
Type
|
ILP32
|
LP64
|
|
char
|
8
|
8
|
|
short
|
16
|
16
|
|
int
|
32
|
32
|
|
long
|
32
|
64
|
|
long long
|
64
|
64
|
|
pointer
|
32
|
64
|
|
enum
|
32
|
32
|
|
float
|
32
|
32
|
|
double
|
64
|
64
|
|
long double
|
128
|
128
|
We can not
assume that above data type sizes are always true by default for all
compilers on various UNIX platforms. There are some exceptions, for
instance,on AIX 5.x if you use VisualAge C++ / C v6.0 compiler long
double is 64 bit by default. When compiled with ldbl128 option, long
double is increased to 128 bit. And long long integers is allowed
when compiled with longlong flag. On other platforms, for instance,
Red Hat Linux AS 3 for AMD 64, Solaris 8, 9 and 10 for Sparc, Solaris
10 for AMD64, HP-UX 11, 11i for PA-RISC, HP-UX 11i for Itanium, Tru64
UNIX 5.1A, if you use compilers that came with operating systems, the
above data models are true by default. But it is always suggested to
check with your compiler user guide first.
▪ Data Alignment
Aligning data on certain
boundaries within memory is good a choice when handling data
structures in some scenarios. But data alignment may be affected when
a program is ported from 32-bit to 64-bit. Different alignment
options may be chosen.
▪ Endian
Dependencies
Bytes ordering in memory
is platform-specific. Different platform architecture chooses
different endianness, either big-endian or little-endian.
|
Arch
|
i386
|
alpha
|
amd64
|
X86-64
|
Solaris Sparc
|
Tru64
|
HP PA_RISC
|
HP Itanium
|
AIX
|
|
Endianness
|
Little-endian
|
Little-endian
|
Little-endian
|
Little-endian
|
Big-endian
|
Big-endian
|
Big-endian
|
Big-endian
|
Big-endian
|
▪ Exchanging Data
Between 32-bit Applications and 64-bit Applications
64-bit applications get
64-bit values from operating for many parameters; 32-bit applications
have 32-bit values from operating. It will cause inconsistency in
many scenarios. For instance, socket invocation, shared memory,
memory-mapped file.
▪ Compiler Options
C++ and C compiler on all
64-bit UNIX platforms offer various 64-bit compiler options. If these
options are not set or enabled, some compilers generate 32-bit
objects by default. The some basic 64-bit compilation and link flags
for some platforms are listed below. But I suggest to consult
compiler user manual to choose compilation and link options for the
performance of the applications.
64-bit compilation
options for various platforms
|
Platform
|
Compiler
|
basic 64-bit
compilation and link options
|
|
RedHat AS 3 for AMD64
|
GCC 3.2.3
|
-m64, -march=k8, -mtune=k8
|
|
Solaris 8 and 9
|
Forte Developer 7 C++ 5.4
|
-xtarget=generic64,-xarch=v9
|
|
HP-UX 11, 11i For PA_RISC
|
aCC HP ANSI C++ 3.37
|
+DA2.0W, +DD64
|
|
HP-UX11.22 for Itanium
|
ACC HP aC++/ANSI C 5.52
|
+DA2.0W, +Dsitanium,+DD64,-AA
|
|
AIX 5.1 and AIX 5.2
|
VisualAge C++ / C v6.0
|
__AIX64__, -q64, -qldbl128
|
|
Solaris 10 for AMD64
|
Sun C++ 5.7
|
--xtarget=opteron, xarch=amd64
|
|
Tru64 UNIX 5.1A
|
Compaq C++ V 6.5
|
No flag needs to generate 64-bit
objects
|
▪ System Libraries
32-bit applications are
required to link with 32-bit libraries, and 64-bit applications are
required to link with 64-bit libraries. The 64-bit operating systems
provide both 32-bit and 64-bit systems libraries. The locations are
platform-specific. On Solaris 5.9 for sparc, 32-bit system libraries
are located under /usr/lib and 64-bit libraries are under
/usr/lib/64. You can find them from your application link path also.
On Red Hat Linux for AMD64, 2-bit system libraries are located under
/usr/lib and /lib and 64-bit libraries are under /usr/lib64 and
/lib64.
Command questions and
Frequently-Used Commands
When
work on various UNIX platforms, always there are lots of questions,
following questions are commands for the answers, for instance,
▪ Is the Operation System kernel
is 32-bit or 64-bit?
On Solaris 7, 8, 9 and 10, isainfo -v
tells whether 64-bit application objects are supported, or whether
the operating system kernel is running 32-bit or 64-bit. This command
does not work Solaris 6 or early version.
On HP-UX 11, 11i, getconf KERNEL_BITS;
on HP-UX 11.22 for Itanium, getconf SC_KERNEL_BITS
On AIX 5.1, 5.2, isconf -k or bootinfo
-K or lslpp -h bos.rte
▪ Is your application binary
32-bit or 64-bit?
On Solaris 7, 8, 9 and 10, use file
command to verify whether the application is ELF 64-bit or ELF
32-bit.
On AIX 5.1, AIX 5.2, use file command
verify whether the application is 64-bit or 32-bit.
More questions can be:
▪ How to get CPU information?
▪ What to get Operation System
information?
▪ What is the application's
libraries link path?
▪ and more for runtime
These questions can be answers by
various commands, but commands are sometimes platform-specific.
Some Resources Links
Solaris
64-bit Developer's Guide
HP-UX
64-bit porting concepts
AIX
5L Porting Guide
amd64
developer tools & porting documentation