Backout e54c650e8748 (bug 737239) due to lack of proper reviews.

This commit is contained in:
Ryan VanderMeulen 2012-04-09 21:06:34 -04:00
Родитель ca6235473e
Коммит 22c4c68ac2
1 изменённых файлов: 40 добавлений и 16 удалений

Просмотреть файл

@ -181,14 +181,48 @@ public:
namespace mozilla {
namespace gfx {
/*
* Copyright 2008 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
* Copyright 2008 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Some helper functions for power-of-two arithmetic
// from Skia
#if defined(__arm__)
#define CountLeadingZeroes(x) __builtin_clz(x)
#else
#define sub_shift(zeros, x, n) \
zeros -= n; \
x >>= n
static inline int CountLeadingZeroes(uint32_t aNumber)
{
if (aNumber == 0) {
return 32;
}
int zeros = 31;
if (aNumber & 0xFFFF0000) {
sub_shift(zeros, aNumber, 16);
}
if (aNumber & 0xFF00) {
sub_shift(zeros, aNumber, 8);
}
if (aNumber & 0xF0) {
sub_shift(zeros, aNumber, 4);
}
if (aNumber & 0xC) {
sub_shift(zeros, aNumber, 2);
}
if (aNumber & 0x2) {
sub_shift(zeros, aNumber, 1);
}
return zeros;
}
#endif
/**
* Returns true if |aNumber| is a power of two
*/
@ -205,17 +239,7 @@ IsPowerOfTwo(int aNumber)
static inline int
NextPowerOfTwo(int aNumber)
{
#if defined(__arm__)
return 1 << (32 - __builtin_clz(aNumber - 1));
#else
--aNumber;
aNumber |= aNumber >> 1;
aNumber |= aNumber >> 2;
aNumber |= aNumber >> 4;
aNumber |= aNumber >> 8;
aNumber |= aNumber >> 16;
return ++aNumber;
#endif
return 1 << (32 - CountLeadingZeroes(aNumber - 1));
}
} // namespace gfx