Commit ce7ff3b6 authored by Aℓex Converse's avatar Aℓex Converse
Browse files

Add a C fallback for get_msb() and change inline to INLINE.

For systems without __builtin_clz() or _BitScanReverse(), taken from libwep

Change-Id: Iead257efc1772c466c79e1dc0356ed571d38d43e
parent af720818
No related merge requests found
Showing with 32 additions and 8 deletions
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#define VP9_COMMON_VP9_SYSTEMDEPENDENT_H_ #define VP9_COMMON_VP9_SYSTEMDEPENDENT_H_
#ifdef _MSC_VER #ifdef _MSC_VER
#include <intrin.h>
#include <math.h> #include <math.h>
#define snprintf _snprintf #define snprintf _snprintf
#endif #endif
...@@ -35,15 +34,40 @@ static int round(double x) { ...@@ -35,15 +34,40 @@ static int round(double x) {
} }
#endif #endif
static const inline int get_msb(int x) { // use GNU builtins where available.
#ifdef _MSC_VER #if defined(__GNUC__) && \
int r = 0; ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
_BitScanReverse(&r, x); static INLINE int get_msb(unsigned int n) {
return r; return 31 ^ __builtin_clz(n);
}
#elif defined(_MSC_VER) && _MSC_VER > 1310 && \
(defined(_M_X64) || defined(_M_IX86))
#include <intrin.h>
#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;
}
#else #else
return 31 ^ __builtin_clz(x); // Returns (int)floor(log2(n)). n must be > 0.
#endif 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;
} }
#endif
struct VP9Common; struct VP9Common;
void vp9_machine_specific_config(struct VP9Common *cm); void vp9_machine_specific_config(struct VP9Common *cm);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment