Bug 935789, part 2: Implement RotateLeft/RotateRight in MFBT and use them, r=Waldo.
authorJoshua Cranmer <Pidgeot18@gmail.com>
Tue, 12 Nov 2013 18:24:56 -0600
changeset 154816 7c3792d389bc87d1bfb549cf7c44d45d3be2116e
parent 154815 6f28e77e0a200c723b7ec0545e3a73a147ebe3e9
child 154817 083e800d6c0344c6fbd5b3f35808d10b8b4c2fa0
push id25654
push userryanvm@gmail.com
push dateFri, 15 Nov 2013 03:19:28 +0000
treeherdermozilla-central@b2fab608772f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs935789
milestone28.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 935789, part 2: Implement RotateLeft/RotateRight in MFBT and use them, r=Waldo.
gfx/thebes/gfxFontconfigUtils.h
mfbt/MathAlgorithms.h
netwerk/protocol/websocket/WebSocketChannel.cpp
--- a/gfx/thebes/gfxFontconfigUtils.h
+++ b/gfx/thebes/gfxFontconfigUtils.h
@@ -3,21 +3,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_FONTCONFIG_UTILS_H
 #define GFX_FONTCONFIG_UTILS_H
 
 #include "gfxPlatform.h"
 
+#include "mozilla/MathAlgorithms.h"
 #include "nsAutoRef.h"
 #include "nsTArray.h"
 #include "nsTHashtable.h"
 #include "nsISupportsImpl.h"
-#include "prbit.h" // for PR_ROTATE_LEFT32
 
 #include <fontconfig/fontconfig.h>
 
 
 template <>
 class nsAutoRefTraits<FcPattern> : public nsPointerRefTraits<FcPattern>
 {
 public:
@@ -160,17 +160,17 @@ protected:
         // except for whitespace in the first character, while FcFontList
         // and config subsitution tests require whitespace to match
         // exactly.  CSS 2.1 implies that whitespace is important in the
         // font-family property.  FcStrCmpIgnoreCase considers whitespace
         // important.
         static PLDHashNumber HashKey(const FcChar8 *aKey) {
             uint32_t hash = 0;
             for (const FcChar8 *c = aKey; *c != '\0'; ++c) {
-                hash = PR_ROTATE_LEFT32(hash, 3) ^ FcToLower(*c);
+                hash = mozilla::RotateLeft(hash, 3) ^ FcToLower(*c);
             }
             return hash;
         }
         enum { ALLOW_MEMMOVE = true };
     };
 
 public:
     // Hash entry with a dependent const FcChar8* pointer to an external
--- a/mfbt/MathAlgorithms.h
+++ b/mfbt/MathAlgorithms.h
@@ -446,11 +446,35 @@ FloorLog2Size(size_t n)
 inline size_t
 RoundUpPow2(size_t x)
 {
   MOZ_ASSERT(x <= (size_t(1) << (sizeof(size_t) * CHAR_BIT - 1)),
              "can't round up -- will overflow!");
   return size_t(1) << CeilingLog2(x);
 }
 
+/**
+ * Rotates the bits of the given value left by the amount of the shift width.
+ */
+template<typename T>
+inline T
+RotateLeft(const T t, uint_fast8_t shift)
+{
+  MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
+  static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
+  return (t << shift) | (t >> (sizeof(T) * CHAR_BIT - shift));
+}
+
+/**
+ * Rotates the bits of the given value right by the amount of the shift width.
+ */
+template<typename T>
+inline T
+RotateRight(const T t, uint_fast8_t shift)
+{
+  MOZ_ASSERT(shift < sizeof(T) * CHAR_BIT, "Shift value is too large!");
+  static_assert(IsUnsigned<T>::value, "Rotates require unsigned values");
+  return (t >> shift) | (t << (sizeof(T) * CHAR_BIT - shift));
+}
+
 } /* namespace mozilla */
 
 #endif /* mozilla_MathAlgorithms_h */
--- a/netwerk/protocol/websocket/WebSocketChannel.cpp
+++ b/netwerk/protocol/websocket/WebSocketChannel.cpp
@@ -37,23 +37,23 @@
 #include "nsThreadUtils.h"
 #include "nsError.h"
 #include "nsStringStream.h"
 #include "nsAlgorithm.h"
 #include "nsProxyRelease.h"
 #include "nsNetUtil.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/MathAlgorithms.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 
 #include "plbase64.h"
 #include "prmem.h"
 #include "prnetdb.h"
-#include "prbit.h"
 #include "zlib.h"
 #include <algorithm>
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsINetworkStatsServiceProxy.h"
 #endif
 
 // rather than slurp up all of nsIWebSocket.idl, which lives outside necko, just
@@ -1510,17 +1510,17 @@ WebSocketChannel::ApplyMask(uint32_t mas
     return;
 
   // Optimally we want to apply the mask 32 bits at a time,
   // but the buffer might not be alligned. So we first deal with
   // 0 to 3 bytes of preamble individually
 
   while (len && (reinterpret_cast<uintptr_t>(data) & 3)) {
     *data ^= mask >> 24;
-    mask = PR_ROTATE_LEFT32(mask, 8);
+    mask = RotateLeft(mask, 8);
     data++;
     len--;
   }
 
   // perform mask on full words of data
 
   uint32_t *iData = (uint32_t *) data;
   uint32_t *end = iData + (len / 4);
@@ -1531,17 +1531,17 @@ WebSocketChannel::ApplyMask(uint32_t mas
   data = (uint8_t *)iData;
   len  = len % 4;
 
   // There maybe up to 3 trailing bytes that need to be dealt with
   // individually 
 
   while (len) {
     *data ^= mask >> 24;
-    mask = PR_ROTATE_LEFT32(mask, 8);
+    mask = RotateLeft(mask, 8);
     data++;
     len--;
   }
 }
 
 void
 WebSocketChannel::GeneratePing()
 {
@@ -1774,17 +1774,17 @@ WebSocketChannel::PrimeNewOutgoingMessag
   // We don't mask the framing, but occasionally we stick a little payload
   // data in the buffer used for the framing. Close frames are the current
   // example. This data needs to be masked, but it is never more than a
   // handful of bytes and might rotate the mask, so we can just do it locally.
   // For real data frames we ship the bulk of the payload off to ApplyMask()
 
   while (payload < (mOutHeader + mHdrOutToSend)) {
     *payload ^= mask >> 24;
-    mask = PR_ROTATE_LEFT32(mask, 8);
+    mask = RotateLeft(mask, 8);
     payload++;
   }
 
   // Mask the real message payloads
 
   ApplyMask(mask, mCurrentOut->BeginWriting(), mCurrentOut->Length());
 
   int32_t len = mCurrentOut->Length();