香港歩る記

Recent site activity

64-bit Computing

32- vs. 64-bit Comparison Chart


 32-bit      64-bit
OS 
 -
  • 64-bit Windows Vista,
  • Windows XP Professional x64 Edition
  • Windows Server 2003 R2 x64 Enterprise Edition
CPU 
 
  • AMD Opteron
  • Athlon64 processors
  • Intel Itanium Processor Family (IPF)
Physical memory 
 4Gb  2Tb
Process / user-mode address space 
 3Gb  8Tb (7 Tb on Itanium-based systems)
Physical Data Alignment for Structs 
  It is recommended that all structures larger than 16 bytes align on 16-byte boundaries. In general, for the best performance, align data as follows:
  • Align 8-bit data at any address
  • Align 16-bit data to be contained within an aligned four-byte word
  • Align 32-bit data so that its base address is a multiple of four
  • Align 64-bit data so that its base address is a multiple of eight
  • Align 80-bit data so that its base address is a multiple of sixteen
  • Align 128-bit data so that its base address is a multiple of sixteen
Abstract Data Model 
 ILP32:
 32-bit integer, long, & pointer
 LLP64 (or P64):
 64-bit pointer;
 32-bit integer & long
Header files 



 Winuser.h:
  • GWL_WNDPROC
  • GWL_HINSTANCE
  • GWL_HWDPARENT
  • GWL_USERDATA
Basetsd.h defines 64-bit types, macros, and help functions for type conversions included by Windows.h

 Winuser.h:
  • GWLP_WNDPROC
  • GWLP_HINSTANCE
  • GWLP_HWNDPARENT
  • GWLP_USERDATA
  • GWLP_ID
Compiler Switches 
   -Wp64 -W3 enables warnings below:
  • C4305: Truncation warning. For example, "return": truncation from "unsigned int64" to "long."
  • C4311: Truncation warning. For example, "type cast": pointer truncation from "int*_ptr64" to "int."
  • C4312: Conversion to bigger-size warning. For example, "type cast": conversion from "int" to "int*_ptr64" of greater size.
  • C4318: Passing zero length. For example, passing constant zero as the length to the memset function.
  • C4319: Not operator. For example, "~": zero extending "unsigned long" to "unsigned _int64" of greater size.
  • C4313: Calling the printf family of functions with conflicting conversion type specifiers and arguments. For example, "printf": "%p" in format string conflicts with argument 2 of type "_int64." Another example is the call printf("%x", pointer_value); this causes a truncation of the upper 32 bits. The correct call is printf("%p", pointer_value).
  • C4244: Same as the existing warning C4242. For example, "return": conversion from "_int64" to "unsigned int," possible loss of data.
Link & Libraries 
 
  • can run Win32-based applications with WOW64 x86 emulator
  • a 64-bit process cannot load a 32-bit DLL
  • a 32-bit process cannot load a 64-bit DLL
  • supports RPC between 64-bit and 32-bit processes
  • can wrap 32-bit DLL, not COM-aware, in an out-of-process COM server and use COM to marshal calls to and from a 64-bit process.
Linker Options 
   /LARGEADDRESSAWARE:NO => 2 GB limit on memory allocation
  • A 2 GB address space is sufficient.
  • The code has many pointer truncation warnings.
  • Pointers and integers are freely mixed.
  • The code has polymorphism using 32-bit data types.
  • Note: DLL built with this option must be called by application built with this option too, otherwise, significant upper 32bits of 64-bit pointers will be truncated - a failure without warnings.
/LTCG => Causes the linker to use Whole Process Optimization (WPO)
/ALLOWBIND: NO => sets a bit in a DLL's header that indicates to Bind.exe not to bound the image.
/opt:lbr => Optimizes away unnecessary long-branch table entries



Fault Alignments 

Itanium-based systems:
System alignment fault handler is turned off by default
unaligned data access generates an exception, UNLESS
call function SetErrorMode with SEM_NOALIGNMENTFAULTEXCEPT
Note performance degradation

x64 systems:
Alignment faults are handled by a combination of hardware and software. For best performance, all memory access should be aligned
Registry Entry 
InprocServer entry for in-process servers registration
InprocServer32 entry for 64- and 32-bit in-process servers registration
Drivers
  32-bit drivers must be ported, no emulation layer for drivers

Migration Points to Note

Some reasons for a program to behave differently when run by a 32-bit and 64-bit CLR:

  • Structs that contain members that change size depending on the platform, such as any pointer type
  • Pointer arithmetic that includes constant sizes
  • Incorrect platform invoke or COM declarations that use Int32 for handles instead of IntPtr
  • Casting IntPtr to Int32
Term Description

POINTER_32

A 32-bit pointer. On 32-bit Windows, this is a native pointer. On 64-bit Windows, this is a truncated 64-bit pointer.

POINTER_64

A 64-bit pointer. On 64-bit Windows, this is a native pointer. On 32-bit Windows, this is a sign-extended 32-bit pointer.

Note that it is not safe to assume the state of the high pointer bit.