Browse Source

Add architecture macros

These macros are to set the target type to the four known unique
targets: x86, x86_64, ARM32 and ARM64. You should not have more
than one of them set in any given architecture, so if x86 is set,
this is *not* a 64-bit machine.

These macros should replace _64BIT_ and all x86 related ones, when
the _64BIT_ macro means actually x86_64, and help the migration to
ARM platforms, to come.
Renato Golin 11 years ago
parent
commit
719a3aefd8
1 changed files with 30 additions and 1 deletions
  1. 30 1
      system/include/platform.h

+ 30 - 1
system/include/platform.h

@@ -20,8 +20,37 @@
 
 #define _TESTING // this should remain set for the near future
 
+// **** Architecture detection ****
+// Ref: http://sourceforge.net/p/predef/wiki/Architectures/
+// Following GNU, ARMCC, ICC and MSVS macros only
+
+// Identify all possible flags that mean ARM32, even when in Thumb mode
+// further separation could be tested via #ifdef __thumb__
+#if defined(__arm__) || defined(__thumb__) \
+ || defined(_M_ARM) || defined(_M_ARMT) \
+ || defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB)
+#define _ARCH_ARM32_
+#endif
+
+// ARM64 has only one which all compilers follow
+#ifdef __aarch64__
+#define _ARCH_ARM64_
+#endif
+
+// Identify all possible flags that mean x86_64
+#if defined(__amd64__) || defined(__x86_64__) \
+ || defined(_M_X64) || defined(_M_AMD64)
+ #define _ARCH_X86_64_
+#else
+ // Identify all possible flags that mean x86
+ #if defined(__i386__) || defined(_M_IX86)
+  #define _ARCH_X86_
+ #endif
+#endif
+
 // **** START OF X-PLATFORM SECTION ****
-#if defined(_M_X64) || defined ( __x86_64) || __WORDSIZE==64
+
+#if defined(_ARCH_X86_64_) || defined(_ARCH_ARM64_) || __WORDSIZE==64
 #define __64BIT__
 #endif