Bug 737239 - Nix power of two for non-ARM builds. r=gw280
authorNicholas Cameron <ncameron@mozilla.com>
Wed, 21 Mar 2012 08:47:02 +1300
changeset 94731 f64fb9a403e63c15db8cf30f8091a810531b0b25
parent 94730 fe5b6de3c7d1ca51d36c005d027f60b5dcd09adb
child 94732 83b64bb97f2562b3bdba5fb41511c8bd54f6b43d
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280
bugs737239
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 737239 - Nix power of two for non-ARM builds. r=gw280
gfx/thebes/gfxUtils.h
--- a/gfx/thebes/gfxUtils.h
+++ b/gfx/thebes/gfxUtils.h
@@ -176,73 +176,49 @@ public:
     static bool sDumpPaintingToFile;
     static FILE* sDumpPaintFile;
 #endif
 };
 
 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
  */
 static inline bool
 IsPowerOfTwo(int aNumber)
 {
     return (aNumber & (aNumber - 1)) == 0;
 }
 
 /**
  * Returns the first integer greater than |aNumber| which is a power of two
  * Undefined for |aNumber| < 0
  */
 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
 } // namespace mozilla
 
 #endif