[Numpy-svn] r6106 - branches/dynamic_cpu_configuration/numpy/core/include/numpy

numpy-svn@scip... numpy-svn@scip...
Tue Nov 25 07:57:35 CST 2008


Author: cdavid
Date: 2008-11-25 07:57:30 -0600 (Tue, 25 Nov 2008)
New Revision: 6106

Added:
   branches/dynamic_cpu_configuration/numpy/core/include/numpy/npy_endian.h
Log:
Add a (public) header to set cpu endianness when numpy headers are included instead of setting them at build time.

Added: branches/dynamic_cpu_configuration/numpy/core/include/numpy/npy_endian.h
===================================================================
--- branches/dynamic_cpu_configuration/numpy/core/include/numpy/npy_endian.h	2008-11-25 13:57:06 UTC (rev 6105)
+++ branches/dynamic_cpu_configuration/numpy/core/include/numpy/npy_endian.h	2008-11-25 13:57:30 UTC (rev 6106)
@@ -0,0 +1,32 @@
+#ifndef _NPY_ENDIAN_H_
+#define _NPY_ENDIAN_H_
+
+/* NPY_BYTE_ORDER is set to the same value as BYTE_ORDER set by glibc in
+ * endian.h */
+
+#ifdef NPY_HAVE_ENDIAN_H
+        /* Use endian.h if available */
+        #include <endian.h>
+        #define NPY_BYTE_ODER __BYTE_ORDER
+        #if (__BYTE_ORDER == __LITTLE_ENDIAN)
+                #define NPY_LITTLE_ENDIAN
+        #elif (__BYTE_ORDER == __BIG_ENDIAN)
+                #define NPY_BYTE_ODER __BYTE_ORDER
+        #else
+                #error Unknown machine endianness detected.
+        #endif
+#else
+        /* Set endianness info using target CPU */
+        #include "cpuarch.h"
+        
+        #if defined(NPY_X86) || defined(NPY_AMD64)
+                        #define NPY_LITTLE_ENDIAN
+                        #define NPY_BYTE_ORDER 1234
+        #elif defined(NPY_PPC) || defined(NPY_SPARC) || defined(NPY_S390) || \
+              defined(NPY_PA_RISC)
+                        #define NPY_BIG_ENDIAN
+                        #define NPY_BYTE_ORDER 4321
+        #endif
+#endif
+
+#endif



More information about the Numpy-svn mailing list