mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-22 03:43:58 +00:00
Bug 1299284 - Remove js::IsPowerOfTwo in favor of mozilla::IsPowerOfTwo. r=sfink
--HG-- extra : rebase_source : c9d695c25c9e53d7b86d9718611718af9fea8598
This commit is contained in:
parent
519d3b4049
commit
de8974994d
@ -56,6 +56,7 @@ using mozilla::Compression::LZ4;
|
||||
using mozilla::HashGeneric;
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::IsNegativeZero;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::Maybe;
|
||||
using mozilla::Move;
|
||||
using mozilla::PodCopy;
|
||||
|
@ -94,6 +94,9 @@
|
||||
*/
|
||||
|
||||
#include "asmjs/WasmBaselineCompile.h"
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
||||
#include "asmjs/WasmBinaryIterator.h"
|
||||
#include "asmjs/WasmGenerator.h"
|
||||
#include "asmjs/WasmSignalHandlers.h"
|
||||
@ -114,6 +117,7 @@
|
||||
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::FloatingPoint;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::SpecificNaN;
|
||||
|
||||
namespace js {
|
||||
@ -625,9 +629,9 @@ class BaseCompiler
|
||||
|
||||
int32_t pushLocal(size_t nbytes) {
|
||||
if (nbytes == 8)
|
||||
localSize_ = AlignBytes(localSize_, 8);
|
||||
localSize_ = AlignBytes(localSize_, 8u);
|
||||
else if (nbytes == 16)
|
||||
localSize_ = AlignBytes(localSize_, 16);
|
||||
localSize_ = AlignBytes(localSize_, 16u);
|
||||
localSize_ += nbytes;
|
||||
return localSize_; // Locals grow down so capture base address
|
||||
}
|
||||
@ -2073,7 +2077,7 @@ class BaseCompiler
|
||||
ABIArgIter<const ValTypeVector> i(args);
|
||||
while (!i.done())
|
||||
i++;
|
||||
return AlignBytes(i.stackBytesConsumedSoFar(), 16);
|
||||
return AlignBytes(i.stackBytesConsumedSoFar(), 16u);
|
||||
}
|
||||
|
||||
void startCallArgs(FunctionCall& call, size_t stackArgAreaSize)
|
||||
@ -7112,7 +7116,7 @@ BaseCompiler::init()
|
||||
|
||||
varHigh_ = localSize_;
|
||||
|
||||
localSize_ = AlignBytes(localSize_, 16);
|
||||
localSize_ = AlignBytes(localSize_, 16u);
|
||||
|
||||
addInterruptCheck();
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include "asmjs/WasmIonCompile.h"
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
||||
#include "asmjs/WasmBaselineCompile.h"
|
||||
#include "asmjs/WasmBinaryIterator.h"
|
||||
#include "asmjs/WasmGenerator.h"
|
||||
@ -30,6 +32,7 @@ using namespace js::jit;
|
||||
using namespace js::wasm;
|
||||
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::Maybe;
|
||||
using mozilla::Nothing;
|
||||
using mozilla::Some;
|
||||
|
@ -42,6 +42,7 @@ using mozilla::CeilingLog2;
|
||||
using mozilla::CountLeadingZeroes32;
|
||||
using mozilla::CheckedInt;
|
||||
using mozilla::FloatingPoint;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::Maybe;
|
||||
using mozilla::PositiveInfinity;
|
||||
using mozilla::SpecificNaN;
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include "asmjs/WasmTypes.h"
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
||||
#include "fdlibm.h"
|
||||
|
||||
#include "jslibmath.h"
|
||||
@ -37,6 +39,7 @@ using namespace js::jit;
|
||||
using namespace js::wasm;
|
||||
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
|
||||
void
|
||||
Val::writePayload(uint8_t* dst) const
|
||||
|
@ -31,6 +31,7 @@
|
||||
using mozilla::AssertedCast;
|
||||
using mozilla::CheckedInt32;
|
||||
using mozilla::DebugOnly;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::PodCopy;
|
||||
using mozilla::PointerRangeSize;
|
||||
|
||||
|
@ -911,7 +911,7 @@ IonScript::New(JSContext* cx, RecompileInfo recompileInfo,
|
||||
size_t backedgeEntries, size_t sharedStubEntries,
|
||||
OptimizationLevel optimizationLevel)
|
||||
{
|
||||
static const int DataAlignment = sizeof(void*);
|
||||
constexpr size_t DataAlignment = sizeof(void*);
|
||||
|
||||
if (snapshotsListSize >= MAX_BUFFER_SIZE ||
|
||||
(bailoutEntries >= MAX_BUFFER_SIZE / sizeof(uint32_t)))
|
||||
|
@ -39,6 +39,7 @@ using mozilla::CheckedInt;
|
||||
using mozilla::NumbersAreIdentical;
|
||||
using mozilla::IsFloat32Representable;
|
||||
using mozilla::IsNaN;
|
||||
using mozilla::IsPowerOfTwo;
|
||||
using mozilla::Maybe;
|
||||
using mozilla::DebugOnly;
|
||||
|
||||
@ -3390,7 +3391,7 @@ MMod::analyzeEdgeCasesForward()
|
||||
|
||||
if (rhs()->isConstant()) {
|
||||
int32_t n = rhs()->toConstant()->toInt32();
|
||||
if (n > 0 && !IsPowerOfTwo(n))
|
||||
if (n > 0 && !IsPowerOfTwo(uint32_t(n)))
|
||||
canBePowerOfTwoDivisor_ = false;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "jit/MacroAssembler.h"
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
||||
#if defined(JS_CODEGEN_X86)
|
||||
# include "jit/x86/MacroAssembler-x86-inl.h"
|
||||
#elif defined(JS_CODEGEN_X64)
|
||||
@ -732,7 +734,7 @@ MacroAssembler::assertStackAlignment(uint32_t alignment, int32_t offset /* = 0 *
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Label ok, bad;
|
||||
MOZ_ASSERT(IsPowerOfTwo(alignment));
|
||||
MOZ_ASSERT(mozilla::IsPowerOfTwo(alignment));
|
||||
|
||||
// Wrap around the offset to be a non-negative number.
|
||||
offset %= alignment;
|
||||
|
@ -19,6 +19,8 @@
|
||||
using namespace js;
|
||||
using namespace js::jit;
|
||||
|
||||
using mozilla::IsPowerOfTwo;
|
||||
|
||||
// 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.
|
||||
static const LiveRegisterSet AllRegs =
|
||||
@ -431,8 +433,9 @@ JitRuntime::generateArgumentsRectifier(JSContext* cx, void** returnAddrOut)
|
||||
"No need to consider the JitFrameLayout for aligning the stack");
|
||||
static_assert(JitStackAlignment % sizeof(Value) == 0,
|
||||
"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(rdx, rcx);
|
||||
masm.andl(Imm32(~(JitStackValueAlignment - 1)), rcx);
|
||||
|
@ -4,6 +4,8 @@
|
||||
* 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/. */
|
||||
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
|
||||
#include "jscompartment.h"
|
||||
|
||||
#include "jit/Bailouts.h"
|
||||
@ -22,6 +24,8 @@
|
||||
|
||||
#include "jit/MacroAssembler-inl.h"
|
||||
|
||||
using mozilla::IsPowerOfTwo;
|
||||
|
||||
using namespace js;
|
||||
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");
|
||||
static_assert(JitStackAlignment % sizeof(Value) == 0,
|
||||
"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);
|
||||
|
||||
// Account for newTarget, if necessary.
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "mozilla/Compiler.h"
|
||||
#include "mozilla/GuardObjects.h"
|
||||
#include "mozilla/HashFunctions.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
|
||||
#include <limits.h>
|
||||
@ -207,18 +208,14 @@ class MOZ_RAII AutoScopedAssign
|
||||
T old;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline bool
|
||||
IsPowerOfTwo(T t)
|
||||
{
|
||||
return t && !(t & (t - 1));
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
static inline U
|
||||
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;
|
||||
}
|
||||
|
||||
@ -226,13 +223,10 @@ template <typename T, typename U>
|
||||
static inline T
|
||||
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
|
||||
UnsignedPtrDiff(const void* bigger, const void* smaller)
|
||||
{
|
||||
return size_t(bigger) - size_t(smaller);
|
||||
return bytes + ComputeByteAlignment(bytes, alignment);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -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)
|
||||
*/
|
||||
template<typename T>
|
||||
inline bool
|
||||
constexpr bool
|
||||
IsPowerOfTwo(T x)
|
||||
{
|
||||
static_assert(IsUnsigned<T>::value,
|
||||
|
@ -41,40 +41,40 @@ TestClamp()
|
||||
static void
|
||||
TestIsPowerOfTwo()
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(0u));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(1u));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(2u));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(3u));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(4u));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(5u));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(6u));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(7u));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(8u));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(9u));
|
||||
static_assert(!IsPowerOfTwo(0u), "0 isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(1u), "1 is a power of two");
|
||||
static_assert(IsPowerOfTwo(2u), "2 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(3u), "3 isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(4u), "4 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(5u), "5 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(6u), "6 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(7u), "7 isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(8u), "8 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(9u), "9 isn't a power of two");
|
||||
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX/2))); // 127, 0x7f
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 1))); // 128, 0x80
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 2))); // 129, 0x81
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX - 1))); // 254, 0xfe
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint8_t(UINT8_MAX))); // 255, 0xff
|
||||
static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX/2)), "127, 0x7f isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 1)), "128, 0x80 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX/2 + 2)), "129, 0x81 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint8_t(UINT8_MAX - 1)), "254, 0xfe isn't a power of two");
|
||||
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
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 1))); // 0x8000
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 2))); // 0x8001
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX - 1))); // 0xfffe
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint16_t(UINT16_MAX))); // 0xffff
|
||||
static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX/2)), "0x7fff isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 1)), "0x8000 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX/2 + 2)), "0x8001 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX - 1)), "0xfffe isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint16_t(UINT16_MAX)), "0xffff isn't a power of two");
|
||||
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX/2)));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 1)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 2)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX - 1)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint32_t(UINT32_MAX)));
|
||||
static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX/2)), "0x7fffffff isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 1)), "0x80000000 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX/2 + 2)), "0x80000001 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX - 1)), "0xfffffffe isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint32_t(UINT32_MAX)), "0xffffffff isn't a power of two");
|
||||
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX/2)));
|
||||
MOZ_RELEASE_ASSERT( IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 1)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 2)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX - 1)));
|
||||
MOZ_RELEASE_ASSERT(!IsPowerOfTwo(uint64_t(UINT64_MAX)));
|
||||
static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX/2)), "0x7fffffffffffffff isn't a power of two");
|
||||
static_assert(IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 1)), "0x8000000000000000 is a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX/2 + 2)), "0x8000000000000001 isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX - 1)), "0xfffffffffffffffe isn't a power of two");
|
||||
static_assert(!IsPowerOfTwo(uint64_t(UINT64_MAX)), "0xffffffffffffffff isn't a power of two");
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
x
Reference in New Issue
Block a user