npy_endian.h
1 #ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_ 2 #define NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_ 3 4 /* 5 * NPY_BYTE_ORDER is set to the same value as BYTE_ORDER set by glibc in 6 * endian.h 7 */ 8 9 #if defined(NPY_HAVE_ENDIAN_H) || defined(NPY_HAVE_SYS_ENDIAN_H) 10 /* Use endian.h if available */ 11 12 #if defined(NPY_HAVE_ENDIAN_H) 13 #include <endian.h> 14 #elif defined(NPY_HAVE_SYS_ENDIAN_H) 15 #include <sys/endian.h> 16 #endif 17 18 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) 19 #define NPY_BYTE_ORDER BYTE_ORDER 20 #define NPY_LITTLE_ENDIAN LITTLE_ENDIAN 21 #define NPY_BIG_ENDIAN BIG_ENDIAN 22 #elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) 23 #define NPY_BYTE_ORDER _BYTE_ORDER 24 #define NPY_LITTLE_ENDIAN _LITTLE_ENDIAN 25 #define NPY_BIG_ENDIAN _BIG_ENDIAN 26 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) 27 #define NPY_BYTE_ORDER __BYTE_ORDER 28 #define NPY_LITTLE_ENDIAN __LITTLE_ENDIAN 29 #define NPY_BIG_ENDIAN __BIG_ENDIAN 30 #endif 31 #endif 32 33 #ifndef NPY_BYTE_ORDER 34 /* Set endianness info using target CPU */ 35 #include "npy_cpu.h" 36 37 #define NPY_LITTLE_ENDIAN 1234 38 #define NPY_BIG_ENDIAN 4321 39 40 #if defined(NPY_CPU_X86) \ 41 || defined(NPY_CPU_AMD64) \ 42 || defined(NPY_CPU_IA64) \ 43 || defined(NPY_CPU_ALPHA) \ 44 || defined(NPY_CPU_ARMEL) \ 45 || defined(NPY_CPU_ARMEL_AARCH32) \ 46 || defined(NPY_CPU_ARMEL_AARCH64) \ 47 || defined(NPY_CPU_SH_LE) \ 48 || defined(NPY_CPU_MIPSEL) \ 49 || defined(NPY_CPU_PPC64LE) \ 50 || defined(NPY_CPU_ARCEL) \ 51 || defined(NPY_CPU_RISCV64) \ 52 || defined(NPY_CPU_LOONGARCH) \ 53 || defined(NPY_CPU_WASM) 54 #define NPY_BYTE_ORDER NPY_LITTLE_ENDIAN 55 56 #elif defined(NPY_CPU_PPC) \ 57 || defined(NPY_CPU_SPARC) \ 58 || defined(NPY_CPU_S390) \ 59 || defined(NPY_CPU_HPPA) \ 60 || defined(NPY_CPU_PPC64) \ 61 || defined(NPY_CPU_ARMEB) \ 62 || defined(NPY_CPU_ARMEB_AARCH32) \ 63 || defined(NPY_CPU_ARMEB_AARCH64) \ 64 || defined(NPY_CPU_SH_BE) \ 65 || defined(NPY_CPU_MIPSEB) \ 66 || defined(NPY_CPU_OR1K) \ 67 || defined(NPY_CPU_M68K) \ 68 || defined(NPY_CPU_ARCEB) 69 #define NPY_BYTE_ORDER NPY_BIG_ENDIAN 70 71 #else 72 #error Unknown CPU: can not set endianness 73 #endif 74 75 #endif 76 77 #endif /* NUMPY_CORE_INCLUDE_NUMPY_NPY_ENDIAN_H_ */