- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd like to share some experience on porting a C/C++ project to a 64-bit platform. It was started last week and I already
have lots of different problems.
Here is a list of Tips, Detected Problems and Issues:
1. I recommend to take a look at the following topics on MSDN if you're about to start a 64-bit programming:
 "Platform SDK: 64-bit Windows Programming"
 "Migration Tips"
 "64-Bit Programming with Visual C++"
 "How to: Configure Projects to Target Platforms"
 2. Turn on a /Wp64 compiler option for Microsoft compatible C++ compilers. It detects 64-bit
 portability problems on types that are marked with the __w64 keyword;
 3. Issue - LONGLONG data type:
 ...
 #if !defined( _M_IX86 )
 typedef __int64 LONGLONG;
 #else
 typedef double LONGLONG;
 #endif
 ...
4. Issue - Date & Time CRT-functions and data types
 5. Issue - A 'size_t' type is used in 'new' C++ operators to pass a size of a memory to allocate and
  it is 8-bytes long on a 64-bit platform
 6. Microsoft C++ compiler ( a test case ):
 ...
 int iInt32 = 0xffffeeeeddddcccc; // -> iInt32 = 0xddddcccc - This is simplya verification of truncation
 ...
 7. Problem - MinGW C++ compiler ( a test case ):
 ...
 int iInt32 = 0xffffeeeeddddcccc; // -> Error: integer constant is too large for "long" type
 ...
 8. Use explicit 'ifdef's for different platforms ( pseudo codes ):
 ...
 #ifdef _16BIT_PLATFORM_
 //...
 #endif
 #ifdef _32BIT_PLATFORM_
 //...
 #endif
 #ifdef _64BIT_PLATFORM_
 //...
 #endif
 ...
9. Default ( turn on ) the following warnigs for Microsoft compatible C++ compilers:
 #pragma warning ( default : 4239 )// Nonstandard extension used : 'type cast' : conversion from 'type1' to 'type2'
 #pragma warning ( default : 4242 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4244 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4305 )// 'Initializing' : truncation from 'type1' to 'type2'
 #pragma warning ( default : 4309 )// 'Initializing' : truncation of constant value
 #pragma warning ( default : 4311 )// 'Type cast' : pointer truncation from 'type1' to 'type2'
10. Verify how the __w64 keyword works for Microsoft compatible C++ compilers:
 // Test Case - Verification of __w64 keyword - based on MSDN example
 // 'V64C' stands for 'Verify 64-bit Compatibility'
 ...
 #if ( defined ( _WIN32_MSC ) || defined ( _WIN32_ICC ) )
 #define _RTV64C__w64
 #endif
 #if ( defined ( _WIN32CE_MSC ) || defined ( _WIN32_BCC ) || defined ( _WIN32_MGW ) ||\\
  defined ( _COS16_TCC ) )
 #define _RTV64C
 #endif
 ...
#pragma warning ( default : 4244 )// Conversion from 'type1' to 'type2', possible loss of data
 #define _WIN64
 //#undef _WIN64
typedef int Int_32;
 #ifdef _WIN64
 typedef __int64 Int_Native;
 #else
 typedef int _RTV64C Int_Native;
 #endif
 Int_32 iInt_32 = 0xffeeddcc;
 Int_Native iInt_Native = 0xffffeeeeddddcccc;
 iInt_32 = iInt_Native; // MSDN - Warning C4244: 64-bit int assigned to 32-bit int
 // Compiler - Warning C4244: '=' : conversion from 'Int_Native' to 'Int_32', possible loss of data
 #undef _WIN64
 #pragma warning ( disable : 4244 )
 ...
11. If a project has Test Cases ALL of them must be verified on a 64-bit platform
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
assigned to a 32-bit variable:
State 1 - Values are uninitialized

State 2 - Values initialized

State 3 - A 64-bit value was assigned to a 32-bit variable
 
					
				
			
			
				
			
			
			
			
			
			
			
		- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
have lots of different problems...
...
4. Issue - Date & Time CRT-functions and data types
...
Please take a look at a thread:
Is a "Y2K38 disaster" looming? Issues with a 'time_t' type
http://software.intel.com/en-us/forums/showthread.php?t=105868&o=a&s=lr
for more technical details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For a 32-bit platform it is declared as follows:
  int fseek( FILE *stream, long offset, int origin );
For a 64-bit platform it is declared as follows:
  int _fseeki64( FILE *stream, __int64 offset, int origin );
A macro-wrapper is needed to make codes more portable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
13. Issues with some intrinsic functions detected:
 Header: 'nmmintrin.h'
  ...
  // Calculate a number of bits set to 1
 ...
  #if defined( _M_X64 )
  extern __int64 _mm_popcnt_u64( unsigned __int64 v );
  #endif
  ...
 Header: 'smmintrin.h'
  ...
  // Insert integer into packed integer array element
  // selected by index
  ...
  #if defined( _M_X64 )
  extern __m128i _mm_insert_epi64( __m128i dst, __int64 s, const int ndx );
  #endif
  // Extract integer from packed integer array element
  // selected by index
  ...
  #if defined( _M_X64 )
  extern __int64 _mm_extract_epi64( __m128i src, const int ndx );
  #endif
  ...
Even if __int64 and __m128i data types could be used on a 32-bit platform these intrinsic functions are not available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
14. Forced truncations of Single- or Double-precision values to integer type:
 In the following example:
 ...
 float fPI = 3.141592653589793f;
 float fPIint = ( int )fPI;
 ...
 there is nothing wrong, but ifMicrosoftor Intel C++ compilers are useda warning:
 C4244: '=' : conversion from 'float' to 'int', possible loss of data
 will be displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
 #pragma warning ( default : 4239 )// Nonstandard extension used : 'type cast' : conversion from 'type1' to 'type2'
 #pragma warning ( default : 4242 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4244 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4305 )// 'Initializing' : truncation from 'type1' to 'type2'
 #pragma warning ( default : 4309 )// 'Initializing' : truncation of constant value
 #pragma warning ( default : 4311 )// 'Type cast' : pointer truncation from 'type1' to 'type2'
In case of Intel C++ compiler default ( turn on )a warning 2259:
#pragma warning (default : 2259 ) // Non-pointer conversion from "type1" to "type2" may lose significant bits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please take a look at a post:
http://software.intel.com/en-us/forums/showpost.php?p=189214
for more technical details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you and it is a really good note. I also had a similarissue and'LL' or 'ULL' resolved it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
 #pragma warning ( default : 4239 )// Nonstandard extension used : 'type cast' : conversion from 'type1' to 'type2'
 #pragma warning ( default : 4242 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4244 )// Conversion from 'type1' to 'type2', possible loss of data
 #pragma warning ( default : 4305 )// 'Initializing' : truncation from 'type1' to 'type2'
 #pragma warning ( default : 4309 )// 'Initializing' : truncation of constant value
 #pragma warning ( default : 4311 )// 'Type cast' : pointer truncation from 'type1' to 'type2'
In case of Intel C++ compiler default ( turn on )a warning 2259:
#pragma warning (default : 2259 ) // Non-pointer conversion from "type1" to "type2" may lose significant bits
A couple of notes regarding warnings. Take into account that as soon as these warnings are 'default'ed
( turned on ) you could be overwhelmed by a number of warnings during compilation of source codes.
Here is example:
- A software development environment has one Visual Studio solution and a number of different
 C/C++ projects is 36. Since every project is configured for different platforms a total number of
 projects to be compiled is 130
- All warnings related to 64-bit conversions are 'default'ed
- In case of rebuilding all projects a total number of warning messages is 1484
- A summary from a Visual Studio Output Window is as follows:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...
int iInt32 = 0xffffeeeeddddcccc; // -> Error: integer constant is too large for "long" type
...
There isa workaround and avalue 18446725308424768716( with LL or ULL )has to be used instead of 0xffffeeeeddddcccc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please take a look at a post:
http://software.intel.com/en-us/forums/showpost.php?p=189214
for more technical details.
Test Results:
 OS : Windows 7 64-bit Home Premium
 CPU: AMD ( 4 cores )
 RAM: 6GB
 VM: 96GB initial size \ 128GB maximum size
 APP: MemTestApp64.exe \ Release configuration
Attempts to allocate memory:
 0.25GB - Allocated
 0.50GB - Allocated
 1.GB - Allocated
 2.GB - Allocated
 4.GB - Allocated
 8.GB - Allocated
 14.GB - Allocated ( Target for a 61000x61000 Single-Precision matrix )
 16.GB - Allocated
 28.GB - Allocated ( Target for a 61000x61000 Double-Precision matrix )
 32.GB - Allocated
 64.GB - Allocated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2. Turn on a /Wp64 compiler option for Microsoft compatible C++ compilers. It detects 64-bit
portability problems on types that are marked with the __w64 keyword;
...
This is simply to note that 'Wp64' compiler option is deprecatedand Visual Studio 2008 ( Professional & Express Editions)displays
awarning message:
 ...
 cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
 ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
18. Intel 64-bit Mode Coding Guidelines
  Intel 64 and IA-32 Architectures Optimization Reference Manual
  November 2007
Chapter 9. 64-bit Mode Coding Guidelines
Note: 5 pages only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MIDL - Microsoft Interface Definition Language
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
 
					
				
				
			
		
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page