+2018-10-01 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r236647.
+ https://bugs.webkit.org/show_bug.cgi?id=190124
+
+ Breaking test stress/big-int-to-string.js (Requested by
+ caiolima_ on #webkit).
+
+ Reverted changeset:
+
+ "[BigInt] BigInt.proptotype.toString is broken when radix is
+ power of 2"
+ https://bugs.webkit.org/show_bug.cgi?id=190033
+ https://trac.webkit.org/changeset/236647
+
2018-09-30 Caio Lima <ticaiolima@gmail.com>
[BigInt] BigInt.proptotype.toString is broken when radix is power of 2
assert(v.toString(16) === "a");
assert(v.toString(32) === "a");
-v = 191561942608236107294793378393788647952342390272950271n;
-assert(v.toString() === "191561942608236107294793378393788647952342390272950271");
-assert(v.toString(2) === "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
-assert(v.toString(3) === "2002122121011101220102010210020102000210011100122221002112102021022221102202020101221000021200201121121100121121");
-assert(v.toString(8) === "77777777777777777777777777777777777777777777777777777777777");
-assert(v.toString(16) === "1ffffffffffffffffffffffffffffffffffffffffffff");
-assert(v.toString(32) === "3vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
-
-v = -10n;
-assert(v.toString() === "-10");
-assert(v.toString(2) === "-1010");
-assert(v.toString(3) === "-101");
-assert(v.toString(8) === "-12");
-assert(v.toString(16) === "-a");
-assert(v.toString(32) === "-a");
-
-v = -191561942608236107294793378393788647952342390272950271n;
-assert(v.toString() === "-191561942608236107294793378393788647952342390272950271");
-assert(v.toString(2) === "-111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
-assert(v.toString(3) === "-2002122121011101220102010210020102000210011100122221002112102021022221102202020101221000021200201121121100121121");
-assert(v.toString(8) === "-77777777777777777777777777777777777777777777777777777777777");
-assert(v.toString(16) === "-1ffffffffffffffffffffffffffffffffffffffffffff");
-assert(v.toString(32) === "-3vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
-
// Invaid radix
function testInvalidRadix(radix) {
+2018-10-01 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r236647.
+ https://bugs.webkit.org/show_bug.cgi?id=190124
+
+ Breaking test stress/big-int-to-string.js (Requested by
+ caiolima_ on #webkit).
+
+ Reverted changeset:
+
+ "[BigInt] BigInt.proptotype.toString is broken when radix is
+ power of 2"
+ https://bugs.webkit.org/show_bug.cgi?id=190033
+ https://trac.webkit.org/changeset/236647
+
2018-10-01 Yusuke Suzuki <yusukesuzuki@slowstart.org>
[WebAssembly] Move type conversion code of JSToWasm return type to JS wasm wrapper
#include "MathCommon.h"
#include "ParseInt.h"
#include <algorithm>
-#include <wtf/MathExtras.h>
#define STATIC_ASSERT(cond) static_assert(cond, "JSBigInt assumes " #cond)
if (this->isZero())
return exec->vm().smallStrings.singleCharacterStringRep('0');
- if (hasOneBitSet(radix))
- return toStringBasePowerOfTwo(exec, this, radix);
-
return toStringGeneric(exec, this, radix);
}
return maximumCharactersRequired;
}
-String JSBigInt::toStringBasePowerOfTwo(ExecState* exec, JSBigInt* x, unsigned radix)
-{
- ASSERT(hasOneBitSet(radix));
- ASSERT(radix >= 2 && radix <= 32);
- ASSERT(!x->isZero());
- VM& vm = exec->vm();
-
- const unsigned length = x->length();
- const bool sign = x->sign();
- const unsigned bitsPerChar = ctz32(radix);
- const unsigned charMask = radix - 1;
- // Compute the length of the resulting string: divide the bit length of the
- // BigInt by the number of bits representable per character (rounding up).
- const Digit msd = x->digit(length - 1);
-
-#if USE(JSVALUE64)
- const unsigned msdLeadingZeros = clz64(msd);
-#else
- const unsigned msdLeadingZeros = clz32(msd);
-#endif
-
- const size_t bitLength = length * digitBits - msdLeadingZeros;
- const size_t charsRequired = (bitLength + bitsPerChar - 1) / bitsPerChar + sign;
-
- if (charsRequired > JSString::MaxLength) {
- auto scope = DECLARE_THROW_SCOPE(vm);
- throwOutOfMemoryError(exec, scope);
- return String();
- }
-
- Vector<LChar> resultString(charsRequired);
- Digit digit = 0;
- // Keeps track of how many unprocessed bits there are in {digit}.
- unsigned availableBits = 0;
- int pos = static_cast<int>(charsRequired - 1);
- for (unsigned i = 0; i < length - 1; i++) {
- Digit newDigit = x->digit(i);
- // Take any leftover bits from the last iteration into account.
- int current = (digit | (newDigit << availableBits)) & charMask;
- resultString[pos--] = radixDigits[current];
- int consumedBits = bitsPerChar - availableBits;
- digit = newDigit >> consumedBits;
- availableBits = digitBits - consumedBits;
- while (availableBits >= bitsPerChar) {
- resultString[pos--] = radixDigits[digit & charMask];
- digit >>= bitsPerChar;
- availableBits -= bitsPerChar;
- }
- }
- // Take any leftover bits from the last iteration into account.
- int current = (digit | (msd << availableBits)) & charMask;
- resultString[pos--] = radixDigits[current];
- digit = msd >> (bitsPerChar - availableBits);
- while (digit) {
- resultString[pos--] = radixDigits[digit & charMask];
- digit >>= bitsPerChar;
- }
-
- if (sign)
- resultString[pos--] = '-';
-
- ASSERT(pos == -1);
- return StringImpl::adopt(WTFMove(resultString));
-}
-
String JSBigInt::toStringGeneric(ExecState* exec, JSBigInt* x, unsigned radix)
{
// FIXME: [JSC] Revisit usage of Vector into JSBigInt::toString
static Digit digitDiv(Digit high, Digit low, Digit divisor, Digit& remainder);
static Digit digitPow(Digit base, Digit exponent);
- static String toStringBasePowerOfTwo(ExecState*, JSBigInt*, unsigned radix);
static String toStringGeneric(ExecState*, JSBigInt*, unsigned radix);
bool isZero();
+2018-10-01 Commit Queue <commit-queue@webkit.org>
+
+ Unreviewed, rolling out r236647.
+ https://bugs.webkit.org/show_bug.cgi?id=190124
+
+ Breaking test stress/big-int-to-string.js (Requested by
+ caiolima_ on #webkit).
+
+ Reverted changeset:
+
+ "[BigInt] BigInt.proptotype.toString is broken when radix is
+ power of 2"
+ https://bugs.webkit.org/show_bug.cgi?id=190033
+ https://trac.webkit.org/changeset/236647
+
2018-09-30 Caio Lima <ticaiolima@gmail.com>
[BigInt] BigInt.proptotype.toString is broken when radix is power of 2
#endif
}
-inline unsigned ctz32(uint32_t number)
-{
-#if COMPILER(GCC_COMPATIBLE)
- if (!number)
- return __builtin_ctz(number);
- return 32;
-#elif COMPILER(MSVC) && !CPU(X86)
- unsigned long ret = 0;
- if (_BitScanForward(&ret, number))
- return ret;
- return 32;
-#else
- unsigned zeroCount = 0;
- for (unsigned i = 0; i < 32; i++) {
- if (number & 1)
- break;
-
- zeroCount++;
- number >>= 1;
- }
- return zeroCount;
-#endif
-}
-
} // namespace WTF
using WTF::opaque;
using WTF::shuffleVector;
using WTF::clz32;
using WTF::clz64;
-using WTF::ctz32;
#endif // #ifndef WTF_MathExtras_h