Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

123
deps/v8/test/js-perf-test/BigInt/add.js vendored Normal file
View File

@ -0,0 +1,123 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let initial_sum = 0n;
let a = 0n;
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Add-Zero', [1000], [
new Benchmark('Add-Zero', true, false, 0, TestAddZero, SetUpTestAddZero)
]);
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Add-SameSign-${d}`, [1000], [
new Benchmark(`Add-SameSign-${d}`, true, false, 0, TestAddSameSign,
() => SetUpTestAddSameSign(d))
]);
});
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Add-DifferentSign-${d}`, [1000], [
new Benchmark(`Add-DifferentSign-${d}`, true, false, 0,
TestAddDifferentSign, () => SetUpTestAddDifferentSign(d))
]);
});
new BenchmarkSuite('Add-Random', [1000], [
new Benchmark('Add-Random', true, false, 0, TestAddRandom,
SetUpTestAddRandom)
]);
function SetUpTestAddZero() {
initial_sum = 42n;
}
function TestAddZero() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = 0n + sum;
}
return sum;
}
function SetUpTestAddSameSign(bits) {
// Add two small random positive values to make sure the sum does not grow
// in digits.
initial_sum = SmallRandomBigIntWithBits(bits);
a = SmallRandomBigIntWithBits(bits);
}
function TestAddSameSign() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = a + sum;
}
return sum;
}
function SetUpTestAddDifferentSign(bits) {
// Add a small random negative value to a large positive one to make sure the
// sum does not shrink in digits.
initial_sum = MaxBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestAddDifferentSign() {
let sum = initial_sum;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = a + sum;
}
return sum;
}
function SetUpTestAddRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestAddRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum = random_bigints[i] + sum;
}
return sum;
}

View File

@ -0,0 +1,88 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt64-${d}`, [1000], [
new Benchmark(`AsInt64-${d}`, true, false, 0, TestAsInt64,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt32-${d}`, [1000], [
new Benchmark(`AsInt32-${d}`, true, false, 0, TestAsInt32,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt8-${d}`, [1000], [
new Benchmark(`AsInt8-${d}`, true, false, 0, TestAsInt8,
() => SetUpTestAsIntN(d))
]);
});
function SetUpTestAsIntN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsInt64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsInt32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsInt8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(8, random_bigints[i % 8]);
}
return result;
}

View File

@ -0,0 +1,88 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint64-${d}`, [1000], [
new Benchmark(`AsUint64-${d}`, true, false, 0, TestAsUint64,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint32-${d}`, [1000], [
new Benchmark(`AsUint32-${d}`, true, false, 0, TestAsUint32,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint8-${d}`, [1000], [
new Benchmark(`AsUint8-${d}`, true, false, 0, TestAsUint8,
() => SetUpTestAsUintN(d))
]);
});
function SetUpTestAsUintN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsUint64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsUint32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsUint8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(8, random_bigints[i % 8]);
}
return result;
}

View File

@ -0,0 +1,70 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
// Test configuration.
const TEST_ITERATIONS = 1000;
const SLOW_TEST_ITERATIONS = 50;
const BITS_CASES = [32, 64, 1024, 8192];
const RANDOM_BIGINTS_MAX_BITS = 64 * 100;
const BIGINT_MAX_BITS = %BigIntMaxLengthBits();
function RandomHexDigit(allow_zero) {
const chars = allow_zero ? '0123456789ABCDEF' : '123456789ABCDEF';
return chars.charAt(Math.floor(Math.random() * chars.length));
}
// Some benchmarks shall compute sums but the result must not grow in terms
// of digits. These can use "small" BigInts, which are BigInts where the most
// significant bits of a digit are 0, so it does not overflow.
function SmallRandomBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
// Make sure it does not start with four 0-bits.
let s = "0x" + RandomHexDigit(false);
bits -= 4;
// Digits are at least 32 bits long, so we round down to the next smaller
// multiple of 32 to keep the most significant digit small.
bits = Math.floor(bits / 32) * 32;
for (; bits > 0; bits -= 4) {
s += RandomHexDigit(true);
}
return BigInt(s);
}
function MaxBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
let s = "0x";
s += "F".repeat(bits / 4);
return BigInt(s);
}
// Generates a random BigInt between 2^(bits-4) and 2^bits-1 (for bits > 0).
function RandomBigIntWithBits(bits) {
console.assert(bits % 4 === 0);
if (bits <= 0) {
return 0n;
}
// Make sure it does not start with four 0-bits.
let s = "0x" + RandomHexDigit(false);
bits -= 4;
// Randomly generate remaining bits.
for (; bits > 0; bits -= 4) {
s += RandomHexDigit(true);
}
return BigInt(s);
}

View File

@ -0,0 +1,95 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('BitwiseAnd-Zero', [1000], [
new Benchmark('BitwiseAnd-Zero', true, false, 0, TestBitwiseAndZero)
]);
new BenchmarkSuite('BitwiseAnd-Small', [1000], [
new Benchmark('BitwiseAnd-Small', true, false, 0, TestBitwiseAnd,
SetUpTestBitwiseAndSmall)
]);
new BenchmarkSuite('BitwiseAnd-Small-Truncated', [1000], [
new Benchmark('BitwiseAnd-Small-Truncated', true, false, 0,
TestBitwiseAndTruncated, SetUpTestBitwiseAndSmall)
]);
new BenchmarkSuite('BitwiseAnd-Random', [1000], [
new Benchmark('BitwiseAnd-Random', true, false, 0, TestBitwiseAnd,
SetUpTestBitwiseAndRandom)
]);
function TestBitwiseAndZero() {
let result = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
result += 0n & i;
}
return result;
}
function SetUpTestBitwiseAndSmall() {
random_bigints = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(60);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function SetUpTestBitwiseAndRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestBitwiseAnd() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
result += random_bigints[i] & random_bigints[i + 1];
}
return result;
}
function TestBitwiseAndTruncated() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
// Truncated explicitly
result += BigInt.asIntN(64, random_bigints[i] & random_bigints[i + 1]);
}
return result;
}

View File

@ -0,0 +1,120 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_dividends = [];
let random_divisors = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Divide-One', [1000], [
new Benchmark('Divide-One', true, false, 0, TestDivideOne)
]);
new BenchmarkSuite('Divide-Small', [1000], [
new Benchmark('Divide-Small', true, false, 0, TestDivideSmall,
SetUpTestDivideSmall)
]);
new BenchmarkSuite('Divide-Small-Truncated', [1000], [
new Benchmark('Divide-Small-Truncated', true, false, 0,
TestDivideSmallTruncated, SetUpTestDivideSmall)
]);
new BenchmarkSuite('Divide-Random', [10000], [
new Benchmark('Divide-Random', true, false, 0, TestDivideRandom,
SetUpTestDivideRandom)
]);
function TestDivideOne() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += i / 1n;
}
return sum;
}
function SetUpTestDivideSmall() {
random_dividends = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(60);
random_dividends.push(Math.random() < 0.5 ? -bigint : bigint);
}
random_divisors = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(32);
random_divisors.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestDivideSmall() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += random_dividends[i] / random_divisors[i];
}
return sum;
}
function TestDivideSmallTruncated() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += BigInt.asIntN(64, random_dividends[i] / random_divisors[i]);
}
return sum;
}
function SetUpTestDivideRandom() {
random_dividends = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_dividends.push(Math.random() < 0.5 ? -bigint : bigint);
}
random_divisors = [];
for (let i = 0; i < TEST_ITERATIONS; ++i) {
// Avoid divide-by-zero
const bits = Math.floor(1 + Math.random() * (max_in_4bits - 1)) * 4;
const bigint = RandomBigIntWithBits(bits);
random_divisors.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestDivideRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += random_dividends[i] / random_divisors[i];
}
return sum;
}

View File

@ -0,0 +1,95 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Multiply-Zero', [1000], [
new Benchmark('Multiply-Zero', true, false, 0, TestMultiplyZero)
]);
new BenchmarkSuite('Multiply-Small', [1000], [
new Benchmark('Multiply-Small', true, false, 0, TestMultiplySmall)
]);
new BenchmarkSuite('Multiply-Small-Truncated', [1000], [
new Benchmark('Multiply-Small-Truncated', true, false, 0,
TestMultiplySmallTruncated)
]);
new BenchmarkSuite('Multiply-Random', [10000], [
new Benchmark('Multiply-Random', true, false, 0, TestMultiplyRandom,
SetUpTestMultiplyRandom)
]);
function TestMultiplyZero() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += 0n * i;
}
return sum;
}
function TestMultiplySmall() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += i * (i + 1n);
}
return sum;
}
function TestMultiplySmallTruncated() {
let sum = 0n;
for (let i = 0n; i < TEST_ITERATIONS; ++i) {
sum += BigInt.asIntN(64, i * (i + 1n));
}
return sum;
}
function SetUpTestMultiplyRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestMultiplyRandom() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
sum += random_bigints[i] * random_bigints[i + 1];
}
return sum;
}

28
deps/v8/test/js-perf-test/BigInt/run.js vendored Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js');
var success = true;
function PrintResult(name, result) {
print(`BigInt-${name}(Score): ${result}`);
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError });

View File

@ -0,0 +1,219 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let a = 0n;
let random_bigints = [];
let small_shift_values = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [100], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('ShiftLeft-Small', [1000], [
new Benchmark('ShiftLeft-Small', true, false, 0,
TestShiftLeftSmall, SetUpTestShiftLeftSmall)
]);
new BenchmarkSuite('ShiftLeft-Random', [1000], [
new Benchmark('ShiftLeft-Random', true, false, 0,
TestShiftLeftRandom, SetUpTestShiftLeftRandom)
]);
new BenchmarkSuite('ShiftLeft-Growing', [1000], [
new Benchmark('ShiftLeft-Growing', true, false, 0,
TestShiftLeftGrowing, SetUpTestShiftLeftGrowing)
]);
new BenchmarkSuite('ShiftRight-Maximum', [1000], [
new Benchmark('ShiftRight-Maximum', true, false, 0,
TestShiftRightMaximum, SetUpTestShiftRightMaximum)
]);
new BenchmarkSuite('ShiftRight-ToZero', [1000], [
new Benchmark('ShiftRight-ToZero', true, false, 0,
TestShiftRightToZero, SetUpTestShiftRightToZero)
]);
new BenchmarkSuite('ShiftRight-Small', [1000], [
new Benchmark('ShiftRight-Small', true, false, 0,
TestShiftRightSmall, SetUpTestShiftRightSmall)
]);
new BenchmarkSuite('ShiftRight-Random', [1000], [
new Benchmark('ShiftRight-Random', true, false, 0,
TestShiftRightRandom, SetUpTestShiftRightRandom)
]);
new BenchmarkSuite('ShiftRight-Shrinking', [1000], [
new Benchmark('ShiftRight-Shrinking', true, false, 0,
TestShiftRightShrinking, SetUpTestShiftRightShrinking)
]);
function SetUpRandomBigInts() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < Math.max(TEST_ITERATIONS, SLOW_TEST_ITERATIONS); ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function SetUpTestShiftLeftSmall() {
random_bigints = [];
// Set up all values such that the left shifted values still fit into one
// digit.
for (let i = 0; i < TEST_ITERATIONS; ++i) {
random_bigints[i] = SmallRandomBigIntWithBits(16);
small_shift_values[i] = SmallRandomBigIntWithBits(4);
}
}
function TestShiftLeftSmall() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] << small_shift_values[i];
}
return result;
}
function SetUpTestShiftLeftRandom() {
if (RANDOM_BIGINTS_MAX_BITS + 2**16 > BIGINT_MAX_BITS) {
throw "Invalid Test Configuration";
}
small_shift_values = [];
SetUpRandomBigInts();
for (let i = 0; i < TEST_ITERATIONS; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(16);
}
}
function TestShiftLeftRandom() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] << small_shift_values[i];
}
return result;
}
function SetUpTestShiftLeftGrowing() {
if (2**4 + (1000 * (2**8)) > BIGINT_MAX_BITS) {
throw "Invalid Test Configuration";
}
small_shift_values = [];
for (let i = 0; i < 1000; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(8);
}
}
function TestShiftLeftGrowing() {
let result = a;
for (let i = 0; i < 1000; ++i) {
result = result << small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightMaximum() {
// Right shifting by 2^80 will shift out all bits.
a = SmallRandomBigIntWithBits(80);
SetUpRandomBigInts();
}
function TestShiftRightMaximum() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> a;
}
return result;
}
function SetUpTestShiftRightToZero() {
// Choose a such that every random BigInt >> a will result in 0n/-1n.
a = BigInt(2 * RANDOM_BIGINTS_MAX_BITS);
SetUpRandomBigInts();
}
function TestShiftRightToZero() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> a;
}
return result;
}
function SetUpTestShiftRightSmall() {
random_bigints = [];
// We construct small BigInts with 32 bits such that they have a single digit
// even on 32bit architectures.
for (let i = 0; i < TEST_ITERATIONS; ++i) {
random_bigints[i] = SmallRandomBigIntWithBits(32);
small_shift_values[i] = BigInt(Math.floor(Math.random() * 30) + 1);
}
}
function TestShiftRightSmall() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightRandom() {
random_bigints = [];
small_shift_values = [];
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits_in_4 = Math.floor(Math.random() * max_in_4bits);
const shift_in_4 = Math.floor(Math.random() * bits_in_4);
const bigint = RandomBigIntWithBits(bits_in_4 * 4);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
small_shift_values.push(BigInt(shift_in_4 * 4));
}
}
function TestShiftRightRandom() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = random_bigints[i] >> small_shift_values[i];
}
return result;
}
function SetUpTestShiftRightShrinking() {
small_shift_values = [];
// Choose values such that shifting right by 1000 times will not make the
// result to go 0n/-1n.
a = RandomBigIntWithBits(16*1000);
for (let i = 0; i < 1000; ++i) {
small_shift_values[i] = SmallRandomBigIntWithBits(4);
}
}
function TestShiftRightShrinking() {
let result = a;
for (let i = 0; i < 1000; ++i) {
result = result >> small_shift_values[i];
}
return result;
}

View File

@ -0,0 +1,124 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let initial_diff = 0n;
let a = 0n;
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('Subtract-Zero', [1000], [
new Benchmark('Subtract-Zero', true, false, 0, TestSubtractZero,
SetUpTestSubtractZero)
]);
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Subtract-SameSign-${d}`, [1000], [
new Benchmark(`Subtract-SameSign-${d}`, true, false, 0,
TestSubtractSameSign, () => SetUpTestSubtractSameSign(d))
]);
});
BITS_CASES.forEach((d) => {
new BenchmarkSuite(`Subtract-DifferentSign-${d}`, [1000], [
new Benchmark(`Subtract-DifferentSign-${d}`, true, false, 0,
TestSubtractDifferentSign, () => SetUpTestSubtractDifferentSign(d))
]);
});
new BenchmarkSuite('Subtract-Random', [1000], [
new Benchmark('Subtract-Random', true, false, 0, TestSubtractRandom,
SetUpTestSubtractRandom)
]);
function SetUpTestSubtractSameSign(bits) {
// Subtract a small random negative value from the maximal negative number to
// make sure the result stays negative.
initial_diff = -MaxBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestSubtractSameSign() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - a;
}
return diff;
}
function SetUpTestSubtractDifferentSign(bits) {
// Subtract a small random negative value from a small positive value so that
// the differnce stays positive but does not grow in digits.
initial_diff = SmallRandomBigIntWithBits(bits);
a = -SmallRandomBigIntWithBits(bits);
}
function TestSubtractDifferentSign() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - a;
}
return diff;
}
function SetUpTestSubtractRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestSubtractRandom() {
let diff = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - random_bigints[i];
}
return diff;
}
function SetUpTestSubtractZero() {
initial_diff = 42n;
}
function TestSubtractZero() {
let diff = initial_diff;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
diff = diff - 0n;
}
return diff;
}

View File

@ -0,0 +1,62 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
const ITERATIONS = 100000;
// This dummy ensures that the feedback for benchmark.run() in the Measure function
// from base.js is not monomorphic, thereby preventing the benchmarks below from being inlined.
// This ensures consistent behavior and comparable results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('ToBoolean', [10000], [
new Benchmark('ToBoolean', true, false, 0, TestToBoolean),
]);
new BenchmarkSuite('BooleanConstructor', [10000], [
new Benchmark('BooleanConstructor', true, false, 0, TestBooleanConstructor),
]);
new BenchmarkSuite('NewBooleanConstructor', [10000], [
new Benchmark('NewBooleanConstructor', true, false, 0, TestNewBooleanConstructor),
]);
function TestBooleanConstructor() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = Boolean(i % 2 == 0 ? 42n : 32n);
}
return kl;
}
function TestNewBooleanConstructor() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = new Boolean(i % 2 == 0 ? 42n : 32n);
}
return kl;
}
function TestToBoolean() {
let kl = true;
for (let i = 0; i < ITERATIONS; ++i) {
// Store to a variable to prevent elimination.
// Keep a depedency on the loop counter to prevent hoisting.
kl = (i % 2 == 0 ? 42n : 32n) ? true : false;
}
return kl;
}