diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
commit | 1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch) | |
tree | 64c8c96cf54d8718847339a403e5e67b922e8c3f /lib/util/wordaccess_gcc3_le.h | |
download | netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip |
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/util/wordaccess_gcc3_le.h')
-rw-r--r-- | lib/util/wordaccess_gcc3_le.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/util/wordaccess_gcc3_le.h b/lib/util/wordaccess_gcc3_le.h new file mode 100644 index 00000000..7db218db --- /dev/null +++ b/lib/util/wordaccess_gcc3_le.h @@ -0,0 +1,54 @@ +/*============================================================================= + + This file is the part of wordaccess.h for use under these + conditions: + + * GCC (>=3.4), GLIBC + * 32 bit Little-Endian machines (intel MPUs 80386, Pentium, etc.) + * Other non-Big-Endian machines (very rare) + +=============================================================================*/ + +typedef uint32_t wordint; +typedef unsigned char wordintBytes[sizeof(wordint)]; + +#include <sys/types.h> +#include <netinet/in.h> + +/* + Here we use the more widely used functions htonl and ntohl instead of + bswap_32. This makes possible the handling of weird byte ordering + (neither Big-Endian nor Little-Endian) schemes, if any. +*/ + +static __inline__ wordint +bytesToWordint(wordintBytes const bytes) { + return (wordint) ntohl(*(wordint *)bytes); +} + + + +static __inline__ void +wordintToBytes(wordintBytes * const bytesP, + wordint const wordInt) { + + *(wordint *)bytesP = htonl(wordInt); +} + + + +static __inline__ unsigned int +wordintClz(wordint const x) { + + /* Find the data type closest to 32 bits, and file off any extra. */ + + if (x == 0) + return sizeof(wordint) * 8; + else if (sizeof(int) >= 4) + return __builtin_clz((int)x << (sizeof(int) - 4) * 8); + else if (sizeof(long int) >= 4) + return __builtin_clzl((long int)x << (sizeof(long int) - 4) * 8); + else + pm_error("Long int is less than 32 bits on this machine"); +} + |