| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef VP9_COMMON_VP9_SYSTEMDEPENDENT_H_ | |
| 12 #define VP9_COMMON_VP9_SYSTEMDEPENDENT_H_ | |
| 13 | |
| 14 #include "vpx_ports/msvc.h" | |
| 15 | |
| 16 #ifdef _MSC_VER | |
| 17 # include <math.h> // the ceil() definition must precede intrin.h | |
| 18 # if _MSC_VER > 1310 && (defined(_M_X64) || defined(_M_IX86)) | |
| 19 # include <intrin.h> | |
| 20 # define USE_MSC_INTRINSICS | |
| 21 # endif | |
| 22 #endif | |
| 23 | |
| 24 #ifdef __cplusplus | |
| 25 extern "C" { | |
| 26 #endif | |
| 27 | |
| 28 #include "./vpx_config.h" | |
| 29 #if ARCH_X86 || ARCH_X86_64 | |
| 30 void vpx_reset_mmx_state(void); | |
| 31 #define vp9_clear_system_state() vpx_reset_mmx_state() | |
| 32 #else | |
| 33 #define vp9_clear_system_state() | |
| 34 #endif | |
| 35 | |
| 36 #if defined(_MSC_VER) && _MSC_VER < 1800 | |
| 37 // round is not defined in MSVC before VS2013. | |
| 38 static INLINE int round(double x) { | |
| 39 if (x < 0) | |
| 40 return (int)ceil(x - 0.5); | |
| 41 else | |
| 42 return (int)floor(x + 0.5); | |
| 43 } | |
| 44 #endif | |
| 45 | |
| 46 // use GNU builtins where available. | |
| 47 #if defined(__GNUC__) && \ | |
| 48 ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) | |
| 49 static INLINE int get_msb(unsigned int n) { | |
| 50 return 31 ^ __builtin_clz(n); | |
| 51 } | |
| 52 #elif defined(USE_MSC_INTRINSICS) | |
| 53 #pragma intrinsic(_BitScanReverse) | |
| 54 | |
| 55 static INLINE int get_msb(unsigned int n) { | |
| 56 unsigned long first_set_bit; | |
| 57 _BitScanReverse(&first_set_bit, n); | |
| 58 return first_set_bit; | |
| 59 } | |
| 60 #undef USE_MSC_INTRINSICS | |
| 61 #else | |
| 62 // Returns (int)floor(log2(n)). n must be > 0. | |
| 63 static INLINE int get_msb(unsigned int n) { | |
| 64 int log = 0; | |
| 65 unsigned int value = n; | |
| 66 int i; | |
| 67 | |
| 68 for (i = 4; i >= 0; --i) { | |
| 69 const int shift = (1 << i); | |
| 70 const unsigned int x = value >> shift; | |
| 71 if (x != 0) { | |
| 72 value = x; | |
| 73 log += shift; | |
| 74 } | |
| 75 } | |
| 76 return log; | |
| 77 } | |
| 78 #endif | |
| 79 | |
| 80 #ifdef __cplusplus | |
| 81 } // extern "C" | |
| 82 #endif | |
| 83 | |
| 84 #endif // VP9_COMMON_VP9_SYSTEMDEPENDENT_H_ | |
| OLD | NEW |