2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
11 #ifndef VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
12 #define VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
15 # include <math.h> // the ceil() definition must precede intrin.h
16 # if _MSC_VER > 1310 && (defined(_M_X64) || defined(_M_IX86))
18 # define USE_MSC_INTRIN
20 # define snprintf _snprintf
27 #include "./vpx_config.h"
28 #if ARCH_X86 || ARCH_X86_64
29 void vpx_reset_mmx_state(void);
30 #define vp9_clear_system_state() vpx_reset_mmx_state()
32 #define vp9_clear_system_state()
35 #if defined(_MSC_VER) && _MSC_VER < 1800
36 // round is not defined in MSVC before VS2013.
37 static INLINE int round(double x) {
39 return (int)ceil(x - 0.5);
41 return (int)floor(x + 0.5);
45 // use GNU builtins where available.
46 #if defined(__GNUC__) && \
47 ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
48 static INLINE int get_msb(unsigned int n) {
49 return 31 ^ __builtin_clz(n);
51 #elif defined(USE_MSC_INTRIN)
52 #pragma intrinsic(_BitScanReverse)
54 static INLINE int get_msb(unsigned int n) {
55 unsigned long first_set_bit;
56 _BitScanReverse(&first_set_bit, n);
61 // Returns (int)floor(log2(n)). n must be > 0.
62 static INLINE int get_msb(unsigned int n) {
64 unsigned int value = n;
67 for (i = 4; i >= 0; --i) {
68 const int shift = (1 << i);
69 const unsigned int x = value >> shift;
83 #endif // VP9_COMMON_VP9_SYSTEMDEPENDENT_H_