Difference between revisions of "Porting/Macros"
(C/C++ preprocessor macros for PPC64 porting) |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Some projects have been ported to Apple ppc64. In that case, they may test macros like this: | Some projects have been ported to Apple ppc64. In that case, they may test macros like this: | ||
− | < | + | <pre> |
− | #if defined(__ppc64__) | + | #if defined(__ppc64__) |
#endif | #endif | ||
− | </ | + | </pre> |
GCC does not define __ppc64__ (lowercase). It defines __PPC64__ (uppercase). To make the above code also build on Debian ppc64le or ppc64 (big endian) change the above code to: | GCC does not define __ppc64__ (lowercase). It defines __PPC64__ (uppercase). To make the above code also build on Debian ppc64le or ppc64 (big endian) change the above code to: | ||
− | < | + | <pre> |
− | #if defined(__ppc64__) || defined(__PPC64__) | + | #if defined(__ppc64__) || defined(__PPC64__) |
#endif | #endif | ||
− | </ | + | </pre> |
+ | |||
+ | Details discussed on #talos-workstation: | ||
+ | |||
+ | Apple's gcc (4.0.1) in MacOS 10.5, ppc32 headers define: | ||
+ | |||
+ | <pre>__POWERPC__ and __ppc__</pre> | ||
+ | |||
+ | with -m64, the following are defined: | ||
+ | |||
+ | <pre>__POWERPC__, __ppc__, and __ppc64__</pre> | ||
+ | |||
+ | GCC compiling for the Linux kernel defines, for ppc32: | ||
+ | |||
+ | <pre>__PPC__ and __powerpc__</pre> [https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/rs6000/linux.h;h=8dc2a89684a29ff05f6f5a17a280eb29129db229;hb=HEAD#l57 gcc/config/rs6000/linux.h] | ||
+ | |||
+ | and for ppc64: | ||
+ | |||
+ | <pre>__PPC__, __powerpc__, __PPC64__ and __powerpc64__</pre> [https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/rs6000/linux64.h;h=98b7255c95f1b55ec5c97726cfcb9dc6fb9ebf56;hb=HEAD#l293 gcc/config/rs6000/linux64.h] | ||
+ | |||
+ | ''Example from Debian ppc64le package: libtbb-dev, version 2020.3-1, /usr/include/tbb/machine/gcc_arm.h:'' | ||
+ | |||
+ | <pre> | ||
+ | #if __powerpc64__ || __ppc64__ | ||
+ | // IBM XL documents __powerpc64__ (and __PPC64__). | ||
+ | // Apple documents __ppc64__ (with __ppc__ only on 32-bit). | ||
+ | #define __TBB_WORDSIZE 8 | ||
+ | #else | ||
+ | #define __TBB_WORDSIZE 4 | ||
+ | #endif | ||
+ | </pre> | ||
+ | |||
+ | ''Example from GCC/libstdc++-v3 source code: libstdc++-v3/src/c++17/fast_float/fast_float.h'' | ||
+ | |||
+ | <pre> | ||
+ | [...] || (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) ) | ||
+ | </pre> | ||
+ | |||
+ | [https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/src/c%2B%2B17/fast_float/fast_float.h;h=7551c4f89ef7b89c638995852e086109c1f43b4f;hb=HEAD#l101 libstdc++-v3 fast_float.h] | ||
+ | |||
+ | That refers to "ppc64le" variants, but those are not canonical. It's better to check endianess separately. | ||
+ | |||
+ | [[Category:Ports]] |
Latest revision as of 09:54, 14 September 2023
Some projects have been ported to Apple ppc64. In that case, they may test macros like this:
#if defined(__ppc64__) #endif
GCC does not define __ppc64__ (lowercase). It defines __PPC64__ (uppercase). To make the above code also build on Debian ppc64le or ppc64 (big endian) change the above code to:
#if defined(__ppc64__) || defined(__PPC64__) #endif
Details discussed on #talos-workstation:
Apple's gcc (4.0.1) in MacOS 10.5, ppc32 headers define:
__POWERPC__ and __ppc__
with -m64, the following are defined:
__POWERPC__, __ppc__, and __ppc64__
GCC compiling for the Linux kernel defines, for ppc32:
__PPC__ and __powerpc__
and for ppc64:
__PPC__, __powerpc__, __PPC64__ and __powerpc64__
Example from Debian ppc64le package: libtbb-dev, version 2020.3-1, /usr/include/tbb/machine/gcc_arm.h:
#if __powerpc64__ || __ppc64__ // IBM XL documents __powerpc64__ (and __PPC64__). // Apple documents __ppc64__ (with __ppc__ only on 32-bit). #define __TBB_WORDSIZE 8 #else #define __TBB_WORDSIZE 4 #endif
Example from GCC/libstdc++-v3 source code: libstdc++-v3/src/c++17/fast_float/fast_float.h
[...] || (defined(__ppc64__) || defined(__PPC64__) || defined(__ppc64le__) || defined(__PPC64LE__)) )
That refers to "ppc64le" variants, but those are not canonical. It's better to check endianess separately.