Bug 737239 - Nix power of two for non-ARM builds. r=gw280
☠☠ backed out by 939ec96b6b38 ☠ ☠
authorNicholas Cameron <ncameron@mozilla.com>
Wed, 21 Mar 2012 08:47:02 +1300
changeset 94590 e54c650e87488ac80d0cce7e74cbd183b4a698cb
parent 94589 77123b152b5c7275625333848327f82bc744b2a1
child 94591 6990e7e757c39e6ddc9cba8a70a77b684ae8b933
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