Bug 1299284 - Remove js::IsPowerOfTwo in favor of mozilla::IsPowerOfTwo. r=sfink

--HG--
extra : rebase_source : c9d695c25c9e53d7b86d9718611718af9fea8598
This commit is contained in:
Jeff Walden 2016-07-21 00:36:38 -07:00
parent 519d3b4049
commit de8974994d
14 changed files with 72 additions and 54 deletions

View File

@ -56,6 +56,7 @@ using mozilla::Compression::LZ4;
using mozilla::HashGeneric; using mozilla::HashGeneric;
using mozilla::IsNaN; using mozilla::IsNaN;
using mozilla::IsNegativeZero; using mozilla::IsNegativeZero;
using mozilla::IsPowerOfTwo;
using mozilla::Maybe; using mozilla::Maybe;
using mozilla::Move; using mozilla::Move;
using mozilla::PodCopy; using mozilla::PodCopy;

View File

@ -94,6 +94,9 @@
*/ */
#include "asmjs/WasmBaselineCompile.h" #include "asmjs/WasmBaselineCompile.h"
#include "mozilla/MathAlgorithms.h"
#include "asmjs/WasmBinaryIterator.h" #include "asmjs/WasmBinaryIterator.h"
#include "asmjs/WasmGenerator.h" #include "asmjs/WasmGenerator.h"
#include "asmjs/WasmSignalHandlers.h" #include "asmjs/WasmSignalHandlers.h"
@ -114,6 +117,7 @@
using mozilla::DebugOnly; using mozilla::DebugOnly;
using mozilla::FloatingPoint; using mozilla::FloatingPoint;
using mozilla::IsPowerOfTwo;
using mozilla::SpecificNaN; using mozilla::SpecificNaN;
namespace js { namespace js {
@ -625,9 +629,9 @@ class BaseCompiler
int32_t pushLocal(size_t nbytes) { int32_t pushLocal(size_t nbytes) {
if (nbytes == 8) if (nbytes == 8)
localSize_ = AlignBytes(localSize_, 8); localSize_ = AlignBytes(localSize_, 8u);
else if (nbytes == 16) else if (nbytes == 16)
localSize_ = AlignBytes(localSize_, 16); localSize_ = AlignBytes(localSize_, 16u);
localSize_ += nbytes; localSize_ += nbytes;
return localSize_; // Locals grow down so capture base address return localSize_; // Locals grow down so capture base address
} }
@ -2073,7 +2077,7 @@ class BaseCompiler
ABIArgIter<const ValTypeVector> i(args); ABIArgIter<const ValTypeVector> i(args);
while (!i.done()) while (!i.done())
i++; i++;
return AlignBytes(i.stackBytesConsumedSoFar(), 16); return AlignBytes(i.stackBytesConsumedSoFar(), 16u);
} }
void startCallArgs(FunctionCall& call, size_t stackArgAreaSize) void startCallArgs(FunctionCall& call, size_t stackArgAreaSize)
@ -7112,7 +7116,7 @@ BaseCompiler::init()
varHigh_ = localSize_; varHigh_ = localSize_;
localSize_ = AlignBytes(localSize_, 16); localSize_ = AlignBytes(localSize_, 16u);
addInterruptCheck(); addInterruptCheck();

View File

@ -18,6 +18,8 @@
#include "asmjs/WasmIonCompile.h" #include "asmjs/WasmIonCompile.h"
#include "mozilla/MathAlgorithms.h"
#include "asmjs/WasmBaselineCompile.h" #include "asmjs/WasmBaselineCompile.h"
#include "asmjs/WasmBinaryIterator.h" #include "asmjs/WasmBinaryIterator.h"
#include "asmjs/WasmGenerator.h" #include "asmjs/WasmGenerator.h"
@ -30,6 +32,7 @@ using namespace js::jit;
using namespace js::wasm; using namespace js::wasm;
using mozilla::DebugOnly; using mozilla::DebugOnly;
using mozilla::IsPowerOfTwo;
using mozilla::Maybe; using mozilla::Maybe;
using mozilla::Nothing; using mozilla::Nothing;
using mozilla::Some; using mozilla::Some;

View File

@ -42,6 +42,7 @@ using mozilla::CeilingLog2;
using mozilla::CountLeadingZeroes32; using mozilla::CountLeadingZeroes32;
using mozilla::CheckedInt; using mozilla::CheckedInt;
using mozilla::FloatingPoint; using mozilla::FloatingPoint;
using mozilla::IsPowerOfTwo;
using mozilla::Maybe; using mozilla::Maybe;
using mozilla::PositiveInfinity; using mozilla::PositiveInfinity;
using mozilla::SpecificNaN; using mozilla::SpecificNaN;

View File

@ -18,6 +18,8 @@
#include "asmjs/WasmTypes.h" #include "asmjs/WasmTypes.h"
#include "mozilla/MathAlgorithms.h"
#include "fdlibm.h" #include "fdlibm.h"
#include "jslibmath.h" #include "jslibmath.h"
@ -37,6 +39,7 @@ using namespace js::jit;
using namespace js::wasm; using namespace js::wasm;
using mozilla::IsNaN; using mozilla::IsNaN;
using mozilla::IsPowerOfTwo;
void void
Val::writePayload(uint8_t* dst) const Val::writePayload(uint8_t* dst) const

View File

@ -31,6 +31,7 @@
using mozilla::AssertedCast; using mozilla::AssertedCast;
using mozilla::CheckedInt32; using mozilla::CheckedInt32;
using mozilla::DebugOnly; using mozilla::DebugOnly;
using mozilla::IsPowerOfTwo;
using mozilla::PodCopy; using mozilla::PodCopy;
using mozilla::PointerRangeSize; using mozilla::PointerRangeSize;

View File

@ -911,7 +911,7 @@ IonScript::New(JSContext* cx, RecompileInfo recompileInfo,
size_t backedgeEntries, size_t sharedStubEntries, size_t backedgeEntries, size_t sharedStubEntries,
OptimizationLevel optimizationLevel) OptimizationLevel optimizationLevel)
{ {
static const int DataAlignment = sizeof(void*); constexpr size_t DataAlignment = sizeof(void*);
if (snapshotsListSize >= MAX_BUFFER_SIZE || if (snapshotsListSize >= MAX_BUFFER_SIZE ||
(bailoutEntries >= MAX_BUFFER_SIZE / sizeof(uint32_t))) (bailoutEntries >= MAX_BUFFER_SIZE / sizeof(uint32_t)))

View File

@ -39,6 +39,7 @@ using mozilla::CheckedInt;
using mozilla::NumbersAreIdentical; using mozilla::NumbersAreIdentical;
using mozilla::IsFloat32Representable; using mozilla::IsFloat32Representable;
using mozilla::IsNaN; using mozilla::IsNaN;
using mozilla::IsPowerOfTwo;
using mozilla::Maybe; using mozilla::Maybe;
using mozilla::DebugOnly; using mozilla::DebugOnly;
@ -3390,7 +3391,7 @@ MMod::analyzeEdgeCasesForward()
if (rhs()->isConstant()) { if (rhs()->isConstant()) {
int32_t n = rhs()->toConstant()->toInt32(); int32_t n = rhs()->toConstant()->toInt32();
if (n > 0 && !IsPowerOfTwo(n)) if (n > 0 && !IsPowerOfTwo(uint32_t(n)))
canBePowerOfTwoDivisor_ = false; canBePowerOfTwoDivisor_ = false;
} }
} }

View File

@ -9,6 +9,8 @@
#include "jit/MacroAssembler.h" #include "jit/MacroAssembler.h"
#include "mozilla/MathAlgorithms.h"
#if defined(JS_CODEGEN_X86) #if defined(JS_CODEGEN_X86)
# include "jit/x86/MacroAssembler-x86-inl.h" # include "jit/x86/MacroAssembler-x86-inl.h"
#elif defined(JS_CODEGEN_X64) #elif defined(JS_CODEGEN_X64)
@ -732,7 +734,7 @@ MacroAssembler::assertStackAlignment(uint32_t alignment, int32_t offset /* = 0 *
{ {
#ifdef DEBUG #ifdef DEBUG
Label ok, bad; Label ok, bad;
MOZ_ASSERT(IsPowerOfTwo(alignment)); MOZ_ASSERT(mozilla::IsPowerOfTwo(alignment));
// Wrap around the offset to be a non-negative number. // Wrap around the offset to be a non-negative number.
offset %= alignment; offset %= alignment;

View File

@ -19,6 +19,8 @@
using namespace js; using namespace js;
using namespace js::jit; using namespace js::jit;
using mozilla::IsPowerOfTwo;
// All registers to save and restore. This includes the stack pointer, since we // All registers to save and restore. This includes the stack pointer, since we
// use the ability to reference register values on the stack by index. // use the ability to reference register values on the stack by index.
static const LiveRegisterSet AllRegs = static const LiveRegisterSet AllRegs =
@ -431,8 +433,9 @@ JitRuntime::generateArgumentsRectifier(JSContext* cx, void** returnAddrOut)
"No need to consider the JitFrameLayout for aligning the stack"); "No need to consider the JitFrameLayout for aligning the stack");
static_assert(JitStackAlignment % sizeof(Value) == 0, static_assert(JitStackAlignment % sizeof(Value) == 0,
"Ensure that we can pad the stack by pushing extra UndefinedValue"); "Ensure that we can pad the stack by pushing extra UndefinedValue");
static_assert(IsPowerOfTwo(JitStackValueAlignment),
"must have power of two for masm.andl to do its job");
MOZ_ASSERT(IsPowerOfTwo(JitStackValueAlignment));
masm.addl(Imm32(JitStackValueAlignment - 1 /* for padding */ + 1 /* for |this| */), rcx); masm.addl(Imm32(JitStackValueAlignment - 1 /* for padding */ + 1 /* for |this| */), rcx);
masm.addl(rdx, rcx); masm.addl(rdx, rcx);
masm.andl(Imm32(~(JitStackValueAlignment - 1)), rcx); masm.andl(Imm32(~(JitStackValueAlignment - 1)), rcx);

View File

@ -4,6 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/MathAlgorithms.h"
#include "jscompartment.h" #include "jscompartment.h"
#include "jit/Bailouts.h" #include "jit/Bailouts.h"
@ -22,6 +24,8 @@
#include "jit/MacroAssembler-inl.h" #include "jit/MacroAssembler-inl.h"
using mozilla::IsPowerOfTwo;
using namespace js; using namespace js;
using namespace js::jit; using namespace js::jit;
@ -413,8 +417,9 @@ JitRuntime::generateArgumentsRectifier(JSContext* cx, void** returnAddrOut)
"No need to consider |this| and the frame pointer and its padding for aligning the stack"); "No need to consider |this| and the frame pointer and its padding for aligning the stack");
static_assert(JitStackAlignment % sizeof(Value) == 0, static_assert(JitStackAlignment % sizeof(Value) == 0,
"Ensure that we can pad the stack by pushing extra UndefinedValue"); "Ensure that we can pad the stack by pushing extra UndefinedValue");
static_assert(IsPowerOfTwo(JitStackValueAlignment),
"must have power of two for masm.andl to do its job");
MOZ_ASSERT(IsPowerOfTwo(JitStackValueAlignment));
masm.addl(Imm32(JitStackValueAlignment - 1 /* for padding */), ecx); masm.addl(Imm32(JitStackValueAlignment - 1 /* for padding */), ecx);
// Account for newTarget, if necessary. // Account for newTarget, if necessary.

View File

@ -15,6 +15,7 @@
#include "mozilla/Compiler.h" #include "mozilla/Compiler.h"
#include "mozilla/GuardObjects.h" #include "mozilla/GuardObjects.h"
#include "mozilla/HashFunctions.h" #include "mozilla/HashFunctions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/PodOperations.h" #include "mozilla/PodOperations.h"
#include <limits.h> #include <limits.h>
@ -207,18 +208,14 @@ class MOZ_RAII AutoScopedAssign
T old; T old;
}; };
template <typename T>
static inline bool
IsPowerOfTwo(T t)
{
return t && !(t & (t - 1));
}
template <typename T, typename U> template <typename T, typename U>
static inline U static inline U
ComputeByteAlignment(T bytes, U alignment) ComputeByteAlignment(T bytes, U alignment)
{ {
MOZ_ASSERT(IsPowerOfTwo(alignment)); static_assert(mozilla::IsUnsigned<U>::value,
"alignment amount must be unsigned");
MOZ_ASSERT(mozilla::IsPowerOfTwo(alignment));
return (alignment - (bytes % alignment)) % alignment; return (alignment - (bytes % alignment)) % alignment;
} }
@ -226,13 +223,10 @@ template <typename T, typename U>
static inline T static inline T
AlignBytes(T bytes, U alignment) AlignBytes(T bytes, U alignment)
{ {
return bytes + ComputeByteAlignment(bytes, alignment); static_assert(mozilla::IsUnsigned<U>::value,
} "alignment amount must be unsigned");
static MOZ_ALWAYS_INLINE size_t return bytes + ComputeByteAlignment(bytes, alignment);
UnsignedPtrDiff(const void* bigger, const void* smaller)
{
return size_t(bigger) - size_t(smaller);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -515,7 +515,7 @@ RotateRight(const T aValue, uint_fast8_t aShift)
* Zero is not an integer power of two. (-Inf is not an integer) * Zero is not an integer power of two. (-Inf is not an integer)
*/ */
template<typename T> template<typename T>
inline bool constexpr bool
IsPowerOfTwo(T x) IsPowerOfTwo(T x)
{ {
static_assert(IsUnsigned<T>::value, static_assert(IsUnsigned<T>::value,

View File

@ -41,40 +41,40 @@ TestClamp()
static void static void
TestIsPowerOfTwo() TestIsPowerOfTwo()
{ {
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(0u)); static_assert(!IsPowerOfTwo(0u), "0 isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(1u)); static_assert(IsPowerOfTwo(1u), "1 is a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(2u)); static_assert(IsPowerOfTwo(2u), "2 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(3u)); static_assert(!IsPowerOfTwo(3u), "3 isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(4u)); static_assert(IsPowerOfTwo(4u), "4 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(5u)); static_assert(!IsPowerOfTwo(5u), "5 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(6u)); static_assert(!IsPowerOfTwo(6u), "6 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(7u)); static_assert(!IsPowerOfTwo(7u), "7 isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(8u)); static_assert(IsPowerOfTwo(8u), "8 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(9u)); static_assert(!IsPowerOfTwo(9u), "9 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX/2))); // 127, 0x7f static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX/2)), "127, 0x7f isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 1))); // 128, 0x80 static_assert(IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 1)), "128, 0x80 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 2))); // 129, 0x81 static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 2)), "129, 0x81 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX - 1))); // 254, 0xfe static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX - 1)), "254, 0xfe isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX))); // 255, 0xff static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX)), "255, 0xff isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX/2))); // 0x7fff static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX/2)), "0x7fff isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 1))); // 0x8000 static_assert(IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 1)), "0x8000 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 2))); // 0x8001 static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 2)), "0x8001 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX - 1))); // 0xfffe static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX - 1)), "0xfffe isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX))); // 0xffff static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX)), "0xffff isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX/2))); static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX/2)), "0x7fffffff isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 1))); static_assert(IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 1)), "0x80000000 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 2))); static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 2)), "0x80000001 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX - 1))); static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX - 1)), "0xfffffffe isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX))); static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX)), "0xffffffff isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX/2))); static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX/2)), "0x7fffffffffffffff isn't a power of two");
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 1))); static_assert(IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 1)), "0x8000000000000000 is a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 2))); static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 2)), "0x8000000000000001 isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX - 1))); static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX - 1)), "0xfffffffffffffffe isn't a power of two");
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX))); static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX)), "0xffffffffffffffff isn't a power of two");
} }
int int