| OLD | NEW |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Misc. common utility functions | 10 // Misc. common utility functions |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) | 83 ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) |
| 84 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { | 84 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { |
| 85 return 31 ^ __builtin_clz(n); | 85 return 31 ^ __builtin_clz(n); |
| 86 } | 86 } |
| 87 #elif defined(_MSC_VER) && _MSC_VER > 1310 && \ | 87 #elif defined(_MSC_VER) && _MSC_VER > 1310 && \ |
| 88 (defined(_M_X64) || defined(_M_IX86)) | 88 (defined(_M_X64) || defined(_M_IX86)) |
| 89 #include <intrin.h> | 89 #include <intrin.h> |
| 90 #pragma intrinsic(_BitScanReverse) | 90 #pragma intrinsic(_BitScanReverse) |
| 91 | 91 |
| 92 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { | 92 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { |
| 93 uint32_t first_set_bit; | 93 unsigned long first_set_bit; |
| 94 _BitScanReverse(&first_set_bit, n); | 94 _BitScanReverse(&first_set_bit, n); |
| 95 return first_set_bit; | 95 return first_set_bit; |
| 96 } | 96 } |
| 97 #else | 97 #else |
| 98 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { | 98 static WEBP_INLINE int BitsLog2Floor(uint32_t n) { |
| 99 int log = 0; | 99 int log = 0; |
| 100 uint32_t value = n; | 100 uint32_t value = n; |
| 101 int i; | 101 int i; |
| 102 | 102 |
| 103 for (i = 4; i >= 0; --i) { | 103 for (i = 4; i >= 0; --i) { |
| 104 const int shift = (1 << i); | 104 const int shift = (1 << i); |
| 105 const uint32_t x = value >> shift; | 105 const uint32_t x = value >> shift; |
| 106 if (x != 0) { | 106 if (x != 0) { |
| 107 value = x; | 107 value = x; |
| 108 log += shift; | 108 log += shift; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 return log; | 111 return log; |
| 112 } | 112 } |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 //------------------------------------------------------------------------------ | 115 //------------------------------------------------------------------------------ |
| 116 | 116 |
| 117 #ifdef __cplusplus | 117 #ifdef __cplusplus |
| 118 } // extern "C" | 118 } // extern "C" |
| 119 #endif | 119 #endif |
| 120 | 120 |
| 121 #endif /* WEBP_UTILS_UTILS_H_ */ | 121 #endif /* WEBP_UTILS_UTILS_H_ */ |
| OLD | NEW |