Skip to content
Permalink
Browse files
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

Canonical link: https://commits.webkit.org/205081@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed Oct 1, 2018
1 parent d254544 commit 61dee733625c4f3e917d3294ddd4adaf1024bc36
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 119 deletions.
@@ -1,3 +1,18 @@
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
@@ -13,30 +13,6 @@ 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");

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) {
@@ -1,3 +1,18 @@
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
@@ -53,7 +53,6 @@
#include "MathCommon.h"
#include "ParseInt.h"
#include <algorithm>
#include <wtf/MathExtras.h>

#define STATIC_ASSERT(cond) static_assert(cond, "JSBigInt assumes " #cond)

@@ -213,9 +212,6 @@ String JSBigInt::toString(ExecState* exec, unsigned radix)
if (this->isZero())
return exec->vm().smallStrings.singleCharacterStringRep('0');

if (hasOneBitSet(radix))
return toStringBasePowerOfTwo(exec, this, radix);

return toStringGeneric(exec, this, radix);
}

@@ -1184,71 +1180,6 @@ uint64_t JSBigInt::calculateMaximumCharactersRequired(unsigned length, unsigned
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
@@ -175,7 +175,6 @@ class JSBigInt final : public JSCell {
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();
@@ -1,3 +1,18 @@
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
@@ -575,30 +575,6 @@ inline unsigned clz64(uint64_t number)
#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;
@@ -608,6 +584,5 @@ using WTF::preciseIndexMaskShiftForSize;
using WTF::shuffleVector;
using WTF::clz32;
using WTF::clz64;
using WTF::ctz32;

#endif // #ifndef WTF_MathExtras_h

0 comments on commit 61dee73

Please sign in to comment.