diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2015-08-12 11:42:45 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2015-08-12 14:15:27 +0200 |
commit | 3ab16f2dad821bafe596383659a084fdd01d717e (patch) | |
tree | d9e22c9580fad766ca7479bc882ec7eb7a2566c4 | |
parent | 03a28f58569524300f22a8401f4f6ca6b0037e54 (diff) |
Detects processor endianess using preprocessor
This allow to define macros based on endianess in public headers
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | spice/macros.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spice/macros.h b/spice/macros.h index 62157b4..3538989 100644 --- a/spice/macros.h +++ b/spice/macros.h @@ -359,4 +359,59 @@ #endif /* generic */ +/* detect endianess */ +#undef SPICE_ENDIAN +#define SPICE_ENDIAN_LITTLE 4321 +#define SPICE_ENDIAN_BIG 1234 +#define SPICE_ENDIAN_PDP 2143 + +/* gcc already defined these, use them */ +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ + && defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_PDP_ENDIAN__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_BIG +# elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_PDP +# else +# error __BYTE_ORDER__ not defined correctly +# endif +#endif + +/* use suggestions at http://sourceforge.net/p/predef/wiki/Endianness/ */ +#ifndef SPICE_ENDIAN +# if defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) \ + || defined(__THUMBEL__) || defined(__AARCH64EL__) \ + || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# endif +# if defined(__BIG_ENDIAN__) || defined(__ARMEB__) \ + || defined(__THUMBEB__) || defined(__AARCH64EB__) \ + || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) +# ifdef SPICE_ENDIAN +# error Both little and big endian detected +# endif +# define SPICE_ENDIAN SPICE_ENDIAN_BIG +# endif +#endif + +/* MS compiler */ +#if !defined(SPICE_ENDIAN) && defined(_MSC_VER) +/* Windows support only little endian arm */ +# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) \ + || defined(_M_ARM) +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# endif +#endif + +#if !defined(SPICE_ENDIAN) +#error Unable to detect processor endianess +#endif + +#if SPICE_ENDIAN == SPICE_ENDIAN_PDP +#error PDP endianess not supported by Spice +#endif + + #endif /* _H_SPICE_MACROS */ |