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