2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
2012-12-19 00:31:19 +01:00
|
|
|
|
2012-11-30 01:36:10 +01:00
|
|
|
#ifndef VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
|
|
|
|
#define VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2014-02-05 03:28:45 +01:00
|
|
|
#ifdef _MSC_VER
|
2014-03-06 07:02:29 +01:00
|
|
|
# include <math.h> // the ceil() definition must precede intrin.h
|
2014-02-05 03:28:45 +01:00
|
|
|
# if _MSC_VER > 1310 && (defined(_M_X64) || defined(_M_IX86))
|
|
|
|
# include <intrin.h>
|
|
|
|
# define USE_MSC_INTRIN
|
|
|
|
# endif
|
|
|
|
# define snprintf _snprintf
|
2014-01-18 21:16:11 +01:00
|
|
|
#endif
|
|
|
|
|
2014-02-05 03:28:45 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2012-12-13 23:51:27 +01:00
|
|
|
#endif
|
|
|
|
|
2012-12-23 16:20:10 +01:00
|
|
|
#include "./vpx_config.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#if ARCH_X86 || ARCH_X86_64
|
|
|
|
void vpx_reset_mmx_state(void);
|
2012-10-31 22:40:53 +01:00
|
|
|
#define vp9_clear_system_state() vpx_reset_mmx_state()
|
2010-05-18 17:58:33 +02:00
|
|
|
#else
|
2012-10-31 22:40:53 +01:00
|
|
|
#define vp9_clear_system_state()
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2013-10-11 23:27:00 +02:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1800
|
|
|
|
// round is not defined in MSVC before VS2013.
|
2014-02-10 05:19:37 +01:00
|
|
|
static INLINE int round(double x) {
|
2012-12-13 23:51:27 +01:00
|
|
|
if (x < 0)
|
|
|
|
return (int)ceil(x - 0.5);
|
|
|
|
else
|
|
|
|
return (int)floor(x + 0.5);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-08 21:25:47 +01:00
|
|
|
// use GNU builtins where available.
|
|
|
|
#if defined(__GNUC__) && \
|
|
|
|
((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
|
|
|
|
static INLINE int get_msb(unsigned int n) {
|
|
|
|
return 31 ^ __builtin_clz(n);
|
|
|
|
}
|
2014-02-05 03:28:45 +01:00
|
|
|
#elif defined(USE_MSC_INTRIN)
|
2014-01-08 21:25:47 +01:00
|
|
|
#pragma intrinsic(_BitScanReverse)
|
|
|
|
|
|
|
|
static INLINE int get_msb(unsigned int n) {
|
|
|
|
unsigned long first_set_bit;
|
|
|
|
_BitScanReverse(&first_set_bit, n);
|
|
|
|
return first_set_bit;
|
|
|
|
}
|
2014-02-05 03:28:45 +01:00
|
|
|
#undef USE_MSC_INTRIN
|
2014-01-03 22:24:11 +01:00
|
|
|
#else
|
2014-01-08 21:25:47 +01:00
|
|
|
// Returns (int)floor(log2(n)). n must be > 0.
|
|
|
|
static INLINE int get_msb(unsigned int n) {
|
|
|
|
int log = 0;
|
|
|
|
unsigned int value = n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 4; i >= 0; --i) {
|
|
|
|
const int shift = (1 << i);
|
|
|
|
const unsigned int x = value >> shift;
|
|
|
|
if (x != 0) {
|
|
|
|
value = x;
|
|
|
|
log += shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return log;
|
2014-01-03 22:24:11 +01:00
|
|
|
}
|
2014-01-08 21:25:47 +01:00
|
|
|
#endif
|
2014-01-03 22:24:11 +01:00
|
|
|
|
2014-01-18 21:16:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2012-12-19 00:31:19 +01:00
|
|
|
#endif // VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
|