diff options
author | H. Peter Anvin <hpa@zytor.com> | 2017-04-24 12:58:30 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2017-04-24 13:01:08 -0700 |
commit | d3e22572b348e2d20c6c6221dac6b218ed50fd27 (patch) | |
tree | fe19fd75c2604a2e0fba081b0382f793cb85f336 /include/compiler.h | |
parent | bbb39579ec340aba9cda4c7033dd934b620423ea (diff) | |
download | nasm-d3e22572b348e2d20c6c6221dac6b218ed50fd27.tar.gz |
Clean up byteorder functions
Move byte order handling functions to their own header file, and try
to be more specific about how exactly to handle things.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'include/compiler.h')
-rw-r--r-- | include/compiler.h | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/include/compiler.h b/include/compiler.h index 79a9ef2e..c068b72d 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -86,6 +86,39 @@ #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> #endif +#ifdef HAVE_ENDIAN_H +# include <endian.h> +#endif + +/* + * If we have BYTE_ORDER defined, trust it over what autoconf came up + * with, especially since autoconf obviously can't figure things out + * for a universal compiler. + */ +#if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) +# undef WORDS_LITTLEENDIAN +# undef WORDS_BIGENDIAN +# if BYTE_ORDER == LITTLE_ENDIAN +# define WORDS_LITTLEENDIAN 1 +# elif BYTE_ORDER == BIG_ENDIAN +# define WORDS_BIGENDIAN 1 +# endif +#endif + +/* + * Define this to 1 for faster performance if this is a littleendian + * platform which can do unaligned memory references. It is safe + * to leave it defined to 0 even if that is true. + */ +#if defined(__386__) || defined(__i386__) || defined(__x86_64__) \ + || defined(_M_IX86) || defined(_M_X64) +# define X86_MEMORY 1 +# ifndef WORDS_LITTLEENDIAN +# define WORDS_LITTLEENDIAN 1 +# endif +#else +# define X86_MEMORY 0 +#endif /* Some versions of MSVC have these only with underscores in front */ #ifndef HAVE_SNPRINTF @@ -161,20 +194,6 @@ size_t strnlen(const char *s, size_t maxlen); #endif /* - * Define this to 1 for faster performance if this is a littleendian - * platform which can do unaligned memory references. It is safe - * to leave it defined to 0 even if that is true. - */ -#if defined(__386__) || defined(__i386__) || defined(__x86_64__) -# define X86_MEMORY 1 -# ifndef WORDS_LITTLEENDIAN -# define WORDS_LITTLEENDIAN 1 -# endif -#else -# define X86_MEMORY 0 -#endif - -/* * Hints to the compiler that a particular branch of code is more or * less likely to be taken. */ |