numpy  2.0.0
include/numpy/npy_endian.h
Go to the documentation of this file.
00001 #ifndef _NPY_ENDIAN_H_
00002 #define _NPY_ENDIAN_H_
00003 
00004 /*
00005  * NPY_BYTE_ORDER is set to the same value as BYTE_ORDER set by glibc in
00006  * endian.h
00007  */
00008 
00009 #if defined(NPY_HAVE_ENDIAN_H) || defined(NPY_HAVE_SYS_ENDIAN_H)
00010     /* Use endian.h if available */
00011 
00012     #if defined(NPY_HAVE_ENDIAN_H)
00013     #include <endian.h>
00014     #elif defined(NPY_HAVE_SYS_ENDIAN_H)
00015     #include <sys/endian.h>
00016     #endif
00017 
00018     #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
00019         #define NPY_BYTE_ORDER    BYTE_ORDER
00020         #define NPY_LITTLE_ENDIAN LITTLE_ENDIAN
00021         #define NPY_BIG_ENDIAN    BIG_ENDIAN
00022     #elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
00023         #define NPY_BYTE_ORDER    _BYTE_ORDER
00024         #define NPY_LITTLE_ENDIAN _LITTLE_ENDIAN
00025         #define NPY_BIG_ENDIAN    _BIG_ENDIAN
00026     #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)
00027         #define NPY_BYTE_ORDER    __BYTE_ORDER
00028         #define NPY_LITTLE_ENDIAN __LITTLE_ENDIAN
00029         #define NPY_BIG_ENDIAN    __BIG_ENDIAN
00030     #endif
00031 #endif
00032 
00033 #ifndef NPY_BYTE_ORDER
00034     /* Set endianness info using target CPU */
00035     #include "npy_cpu.h"
00036 
00037     #define NPY_LITTLE_ENDIAN 1234
00038     #define NPY_BIG_ENDIAN 4321
00039 
00040     #if defined(NPY_CPU_X86)            \
00041             || defined(NPY_CPU_AMD64)   \
00042             || defined(NPY_CPU_IA64)    \
00043             || defined(NPY_CPU_ALPHA)   \
00044             || defined(NPY_CPU_ARMEL)   \
00045             || defined(NPY_CPU_AARCH64) \
00046             || defined(NPY_CPU_SH_LE)   \
00047             || defined(NPY_CPU_MIPSEL)  \
00048             || defined(NPY_CPU_PPC64LE)
00049         #define NPY_BYTE_ORDER NPY_LITTLE_ENDIAN
00050     #elif defined(NPY_CPU_PPC)          \
00051             || defined(NPY_CPU_SPARC)   \
00052             || defined(NPY_CPU_S390)    \
00053             || defined(NPY_CPU_HPPA)    \
00054             || defined(NPY_CPU_PPC64)   \
00055             || defined(NPY_CPU_ARMEB)   \
00056             || defined(NPY_CPU_SH_BE)   \
00057             || defined(NPY_CPU_MIPSEB)  \
00058             || defined(NPY_CPU_OR1K)    \
00059             || defined(NPY_CPU_M68K)
00060         #define NPY_BYTE_ORDER NPY_BIG_ENDIAN
00061     #else
00062         #error Unknown CPU: can not set endianness
00063     #endif
00064 #endif
00065 
00066 #endif