Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MSVC builtin macros _M_AMD64 and _M_X64

I was looking at the MSVC docs for builtin macros and saw the following macros:

_M_AMD64 Defined as the integer literal value 100 for compilations that target x64 processors. Otherwise, undefined.

_M_X64 Defined as the integer literal value 100 for compilations that target x64 processors. Otherwise, undefined.

Also, there is the following macro that seems to do the same?

_WIN64 Defined as 1 when the compilation target is 64-bit ARM or x64. Otherwise, undefined.

They both have exactly the same definition according to the docs - are they equivalent? Are there any situations where one will be defined whilst the other isn't? If not, what's the history here?

like image 366
H Bellamy Avatar asked Mar 02 '17 08:03

H Bellamy


1 Answers

_WIN64 is defined on every platform/CPU architecture where sizeof(void*) >= 8

The first 64-bit Windows release ("Windows XP 64-Bit Edition") was actually on the Intel Itanium CPU and its macro is _M_IA64. AMD then decided to create their own 64-bit instruction set and its macro is _M_AMD64 but the first desktop Windows release for it was actually called "Windows XP Professional x64 Edition". Intel caved in and started producing CPUs that support the AMD64 instruction set (EM64T AKA Intel 64) and Itanium is pretty much dead now.

You still see the AMD64 name in certain places and filenames but a lot of people just call it x64 or x86-64 now.

_M_AMD64 has existed since the start of that architecture but I cannot remember if _M_X64 was created at the same time or if it was added later. You probably have to look at the compilers from the Platform SDKs and WDKs released between Visual Studio 2003 and 2005 to find out.

This MSDN blog post says

_M_AMD64 and _M_X64 are equivalent.

like image 79
Anders Avatar answered Nov 01 '22 06:11

Anders