diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-05-01 02:25:58 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-05-01 02:25:58 +0000 |
commit | 39dd39596b97f09b2e84ed612e60a0402dc3ab41 (patch) | |
tree | e244aed80596da9fac78d06db2ed57a5f351fa16 /lib/util/wordaccess_64_le.h | |
parent | 76bbc70fe011921c87f3a21a9175152bae293cdf (diff) | |
download | netpbm-mirror-39dd39596b97f09b2e84ed612e60a0402dc3ab41.tar.gz netpbm-mirror-39dd39596b97f09b2e84ed612e60a0402dc3ab41.tar.xz netpbm-mirror-39dd39596b97f09b2e84ed612e60a0402dc3ab41.zip |
improvements to efficient word access
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@904 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/util/wordaccess_64_le.h')
-rw-r--r-- | lib/util/wordaccess_64_le.h | 48 |
1 files changed, 11 insertions, 37 deletions
diff --git a/lib/util/wordaccess_64_le.h b/lib/util/wordaccess_64_le.h index ad316df2..4d148ad2 100644 --- a/lib/util/wordaccess_64_le.h +++ b/lib/util/wordaccess_64_le.h @@ -2,28 +2,21 @@ This file is the part of wordaccess.h for use under these conditions: - * GCC (>=3.4), GLIBC - * 64 bit Little-Endian machines (IA64, X86-64, AMD64) -=============================================================================*/ - -/* - 64 bit hton and ntoh do not exist. Here we use bswap_64. - - While bswap_64 works on 64 bit data, __builtin_clzl works on "long" which - may or may not be 64 bits. Code provided to find the right data type and - file off any extra when necessary. -*/ - -#include <byteswap.h> /* See note above on bswap_64 */ - -#include "pm.h" + * GCC (>=3.4) (__builtin_clz appears in GCC 3.4) + * Little-Endian machines (IA64, X86-64, AMD64) + * 64 bit long +=============================================================================*/ + +#include "intcode.h" + typedef uint64_t wordint; typedef unsigned char wordintBytes[sizeof(wordint)]; + static __inline__ wordint -bytesToWordint(wordintBytes bytes) { - return ((wordint) bswap_64(*(wordint *)bytes)); +bytesToWordint(wordintBytes const bytes) { + return (wordint) pm_uintFromBigend64(*(bigend64*)bytes); } @@ -31,24 +24,5 @@ bytesToWordint(wordintBytes bytes) { static __inline__ void wordintToBytes(wordintBytes * const bytesP, wordint const wordInt) { - *(wordint *)bytesP = bswap_64(wordInt); -} - - - -static __inline__ unsigned int -wordintClz(wordint const x){ - - unsigned int s; - - if (x == 0) - return sizeof(wordint) * 8; - - /* Find the data type closest to 64 bits, and file off any extra. */ - else if ((s=sizeof(long int)) >= 8) - return (__builtin_clzl((long int)x << (s - 8) * 8)); - else if ((s=sizeof(long long int)) >= 8) - return (__builtin_clzll((long long int)x << (s - 8) * 8)); - else - pm_error("Long long int is less than 64 bits on this machine"); + *(bigend64*)bytesP = pm_bigendFromUint64(wordInt); } |