diff options
author | Vikas Arora <vikasa@google.com> | 2014-07-25 13:53:32 -0700 |
---|---|---|
committer | Vikas Arora <vikasa@google.com> | 2014-07-25 13:53:32 -0700 |
commit | 33f74dabbc7920a65ed435d7417987589febdc16 (patch) | |
tree | b4a6d3345d23e0c12ea82ab354b75c83c7309516 /src/utils/utils.h | |
parent | 40d327484446eb6adea41a817b2fb218d00a7649 (diff) | |
download | webp-33f74dabbc7920a65ed435d7417987589febdc16.tar.gz |
Sync-patch with libwebp ver 0.4.1-rc1.
Sync-patch with libwebp ver 0.4.1-rc1 (change#I5346984d2).
- NEON assembly optimizations:
- ~25% faster lossy decode / encode (-m 4)
- ~10% faster lossless decode
- ~5-10% faster lossless encode (-m 3/4)
- Arch64 (arm64) & MIPS support/optimizations.
Change-Id: I855b65cec8fad5ec567c276b698e7714dc4bffd2
Diffstat (limited to 'src/utils/utils.h')
-rw-r--r-- | src/utils/utils.h | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/utils/utils.h b/src/utils/utils.h index 6969ed32..a8e8c3d6 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -35,10 +35,13 @@ extern "C" { // somewhere (like: malloc(num_pixels * sizeof(*something))). That's why this // safe malloc() borrows the signature from calloc(), pointing at the dangerous // underlying multiply involved. -void* WebPSafeMalloc(uint64_t nmemb, size_t size); +WEBP_EXTERN(void*) WebPSafeMalloc(uint64_t nmemb, size_t size); // Note that WebPSafeCalloc() expects the second argument type to be 'size_t' // in order to favor the "calloc(num_foo, sizeof(foo))" pattern. -void* WebPSafeCalloc(uint64_t nmemb, size_t size); +WEBP_EXTERN(void*) WebPSafeCalloc(uint64_t nmemb, size_t size); + +// Companion deallocation function to the above allocations. +WEBP_EXTERN(void) WebPSafeFree(void* const ptr); //------------------------------------------------------------------------------ // Reading/writing data. @@ -74,6 +77,41 @@ static WEBP_INLINE void PutLE32(uint8_t* const data, uint32_t val) { PutLE16(data + 2, (int)(val >> 16)); } +// Returns (int)floor(log2(n)). n must be > 0. +// use GNU builtins where available. +#if defined(__GNUC__) && \ + ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + return 31 ^ __builtin_clz(n); +} +#elif defined(_MSC_VER) && _MSC_VER > 1310 && \ + (defined(_M_X64) || defined(_M_IX86)) +#include <intrin.h> +#pragma intrinsic(_BitScanReverse) + +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + uint32_t first_set_bit; + _BitScanReverse(&first_set_bit, n); + return first_set_bit; +} +#else +static WEBP_INLINE int BitsLog2Floor(uint32_t n) { + int log = 0; + uint32_t value = n; + int i; + + for (i = 4; i >= 0; --i) { + const int shift = (1 << i); + const uint32_t x = value >> shift; + if (x != 0) { + value = x; + log += shift; + } + } + return log; +} +#endif + //------------------------------------------------------------------------------ #ifdef __cplusplus |