diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-12-11 17:14:44 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-12-11 17:15:26 -0500 |
| commit | dec390744fe3466cede66d3b1a0209ca0c6a3df8 (patch) | |
| tree | 94c84c358476ad4d7fe152082ffbee5a497670e9 /src/bytorder.h | |
| parent | a2366b1568bf782ac70c1feca26a097e83dcb7a7 (diff) | |
| download | alftools-dec390744fe3466cede66d3b1a0209ca0c6a3df8.tar.gz | |
crunch.c: Speed up by 20%, if endianness can be determined at compile time.
Diffstat (limited to 'src/bytorder.h')
| -rw-r--r-- | src/bytorder.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bytorder.h b/src/bytorder.h new file mode 100644 index 0000000..cb8231e --- /dev/null +++ b/src/bytorder.h @@ -0,0 +1,52 @@ +#if defined(ALF_LSB_FIRST) && defined(ALF_MSB_FIRST) +# error Cannot define both ALF_LSB_FIRST and ALF_MSB_FIRST +#endif + +#if defined(ALF_LSB_FIRST) || defined(ALF_MSB_FIRST) +# define ALF_ENDIAN_OK +#endif + +/* try to get the byte order on this platform. + if we succeed, either ALF_LSB_FIRST or ALF_MSB_FIRST will + defined, and so will ALF_ENDIAN_OK. */ + +#ifndef ALF_ENDIAN_OK +# if defined(__BYTE_ORDER__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define ALF_LSB_FIRST +# define ALF_ENDIAN_OK +# else +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define ALF_MSB_FIRST +# define ALF_ENDIAN_OK +# endif +# endif +# endif +#endif + +#ifndef ALF_ENDIAN_OK +# if defined(__LITTLE_ENDIAN__) +# define ALF_LSB_FIRST +# define ALF_ENDIAN_OK +# else +# if defined(__BIG_ENDIAN__) +# define ALF_MSB_FIRST +# define ALF_ENDIAN_OK +# endif +# endif +#endif + +#ifdef ALF_ENDIAN_OK +# ifdef ALF_LSB_FIRST +# define HIBYTE 2 +# define MIDBYTE 1 +# define LOBYTE 0 +# else +# define HIBYTE 1 +# define MIDBYTE 2 +# define LOBYTE 3 +# endif +#else +# warning Cannot determine endianness, falling back to safe but slow append_bit(). +# warning Recompile with -DALF_LSB_FIRST or -DALF_MSB_FIRST. +#endif |
