Bug 737239 - Nix power of two for non-ARM builds. r=gw280

This commit is contained in:
Nicholas Cameron 2012-03-21 08:47:02 +13:00
Родитель 8cb1bc5982
Коммит bab74a92d2
1 изменённых файлов: 16 добавлений и 40 удалений

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

@ -181,48 +181,14 @@ 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
*/
@ -239,7 +205,17 @@ IsPowerOfTwo(int aNumber)
static inline int
NextPowerOfTwo(int aNumber)
{
return 1 << (32 - CountLeadingZeroes(aNumber - 1));
#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
}
} // namespace gfx