Bug 1685708 - Part 5: Transpile BigInt.as{Int,Uint}N. r=jandem

`BigInt.as{Int,Uint}N(bits, x)` with bits={32,64} are expected to be common enough
to warrant providing specialised code. For example `BigInt.asIntN(64, x + y)` can
be used to inform the compiler to perform Int64 additions.

Differential Revision: https://phabricator.services.mozilla.com/D101173
This commit is contained in:
André Bargull 2021-01-13 15:17:36 +00:00
Родитель 926698e0b9
Коммит f967863436
18 изменённых файлов: 1782 добавлений и 49 удалений

Просмотреть файл

@ -0,0 +1,473 @@
const tests = [
[-0x10000000000000001n, 0, 0n],
[-0x10000000000000000n, 0, 0n],
[-0xffffffffffffffffn, 0, 0n],
[-0xfffffffffffffffen, 0, 0n],
[-0x8000000000000001n, 0, 0n],
[-0x8000000000000000n, 0, 0n],
[-0x7fffffffffffffffn, 0, 0n],
[-0x7ffffffffffffffen, 0, 0n],
[-0x100000001n, 0, 0n],
[-0x100000000n, 0, 0n],
[-0xffffffffn, 0, 0n],
[-0xfffffffen, 0, 0n],
[-0x80000001n, 0, 0n],
[-0x80000000n, 0, 0n],
[-0x7fffffffn, 0, 0n],
[-0x7ffffffen, 0, 0n],
[-9n, 0, 0n],
[-8n, 0, 0n],
[-7n, 0, 0n],
[-6n, 0, 0n],
[-5n, 0, 0n],
[-4n, 0, 0n],
[-3n, 0, 0n],
[-2n, 0, 0n],
[-1n, 0, 0n],
[0n, 0, 0n],
[1n, 0, 0n],
[2n, 0, 0n],
[3n, 0, 0n],
[4n, 0, 0n],
[5n, 0, 0n],
[6n, 0, 0n],
[7n, 0, 0n],
[8n, 0, 0n],
[9n, 0, 0n],
[0x7ffffffen, 0, 0n],
[0x7fffffffn, 0, 0n],
[0x80000000n, 0, 0n],
[0x80000001n, 0, 0n],
[0xfffffffen, 0, 0n],
[0xffffffffn, 0, 0n],
[0x100000000n, 0, 0n],
[0x100000001n, 0, 0n],
[0x7ffffffffffffffen, 0, 0n],
[0x7fffffffffffffffn, 0, 0n],
[0x8000000000000000n, 0, 0n],
[0x8000000000000001n, 0, 0n],
[0xfffffffffffffffen, 0, 0n],
[0xffffffffffffffffn, 0, 0n],
[0x10000000000000000n, 0, 0n],
[0x10000000000000001n, 0, 0n],
[-0x10000000000000001n, 1, -1n],
[-0x10000000000000000n, 1, 0n],
[-0xffffffffffffffffn, 1, -1n],
[-0xfffffffffffffffen, 1, 0n],
[-0x8000000000000001n, 1, -1n],
[-0x8000000000000000n, 1, 0n],
[-0x7fffffffffffffffn, 1, -1n],
[-0x7ffffffffffffffen, 1, 0n],
[-0x100000001n, 1, -1n],
[-0x100000000n, 1, 0n],
[-0xffffffffn, 1, -1n],
[-0xfffffffen, 1, 0n],
[-0x80000001n, 1, -1n],
[-0x80000000n, 1, 0n],
[-0x7fffffffn, 1, -1n],
[-0x7ffffffen, 1, 0n],
[-9n, 1, -1n],
[-8n, 1, 0n],
[-7n, 1, -1n],
[-6n, 1, 0n],
[-5n, 1, -1n],
[-4n, 1, 0n],
[-3n, 1, -1n],
[-2n, 1, 0n],
[-1n, 1, -1n],
[0n, 1, 0n],
[1n, 1, -1n],
[2n, 1, 0n],
[3n, 1, -1n],
[4n, 1, 0n],
[5n, 1, -1n],
[6n, 1, 0n],
[7n, 1, -1n],
[8n, 1, 0n],
[9n, 1, -1n],
[0x7ffffffen, 1, 0n],
[0x7fffffffn, 1, -1n],
[0x80000000n, 1, 0n],
[0x80000001n, 1, -1n],
[0xfffffffen, 1, 0n],
[0xffffffffn, 1, -1n],
[0x100000000n, 1, 0n],
[0x100000001n, 1, -1n],
[0x7ffffffffffffffen, 1, 0n],
[0x7fffffffffffffffn, 1, -1n],
[0x8000000000000000n, 1, 0n],
[0x8000000000000001n, 1, -1n],
[0xfffffffffffffffen, 1, 0n],
[0xffffffffffffffffn, 1, -1n],
[0x10000000000000000n, 1, 0n],
[0x10000000000000001n, 1, -1n],
[-0x10000000000000001n, 2, -1n],
[-0x10000000000000000n, 2, 0n],
[-0xffffffffffffffffn, 2, 1n],
[-0xfffffffffffffffen, 2, -2n],
[-0x8000000000000001n, 2, -1n],
[-0x8000000000000000n, 2, 0n],
[-0x7fffffffffffffffn, 2, 1n],
[-0x7ffffffffffffffen, 2, -2n],
[-0x100000001n, 2, -1n],
[-0x100000000n, 2, 0n],
[-0xffffffffn, 2, 1n],
[-0xfffffffen, 2, -2n],
[-0x80000001n, 2, -1n],
[-0x80000000n, 2, 0n],
[-0x7fffffffn, 2, 1n],
[-0x7ffffffen, 2, -2n],
[-9n, 2, -1n],
[-8n, 2, 0n],
[-7n, 2, 1n],
[-6n, 2, -2n],
[-5n, 2, -1n],
[-4n, 2, 0n],
[-3n, 2, 1n],
[-2n, 2, -2n],
[-1n, 2, -1n],
[0n, 2, 0n],
[1n, 2, 1n],
[2n, 2, -2n],
[3n, 2, -1n],
[4n, 2, 0n],
[5n, 2, 1n],
[6n, 2, -2n],
[7n, 2, -1n],
[8n, 2, 0n],
[9n, 2, 1n],
[0x7ffffffen, 2, -2n],
[0x7fffffffn, 2, -1n],
[0x80000000n, 2, 0n],
[0x80000001n, 2, 1n],
[0xfffffffen, 2, -2n],
[0xffffffffn, 2, -1n],
[0x100000000n, 2, 0n],
[0x100000001n, 2, 1n],
[0x7ffffffffffffffen, 2, -2n],
[0x7fffffffffffffffn, 2, -1n],
[0x8000000000000000n, 2, 0n],
[0x8000000000000001n, 2, 1n],
[0xfffffffffffffffen, 2, -2n],
[0xffffffffffffffffn, 2, -1n],
[0x10000000000000000n, 2, 0n],
[0x10000000000000001n, 2, 1n],
[-0x10000000000000001n, 31, -1n],
[-0x10000000000000000n, 31, 0n],
[-0xffffffffffffffffn, 31, 1n],
[-0xfffffffffffffffen, 31, 2n],
[-0x8000000000000001n, 31, -1n],
[-0x8000000000000000n, 31, 0n],
[-0x7fffffffffffffffn, 31, 1n],
[-0x7ffffffffffffffen, 31, 2n],
[-0x100000001n, 31, -1n],
[-0x100000000n, 31, 0n],
[-0xffffffffn, 31, 1n],
[-0xfffffffen, 31, 2n],
[-0x80000001n, 31, -1n],
[-0x80000000n, 31, 0n],
[-0x7fffffffn, 31, 1n],
[-0x7ffffffen, 31, 2n],
[-9n, 31, -9n],
[-8n, 31, -8n],
[-7n, 31, -7n],
[-6n, 31, -6n],
[-5n, 31, -5n],
[-4n, 31, -4n],
[-3n, 31, -3n],
[-2n, 31, -2n],
[-1n, 31, -1n],
[0n, 31, 0n],
[1n, 31, 1n],
[2n, 31, 2n],
[3n, 31, 3n],
[4n, 31, 4n],
[5n, 31, 5n],
[6n, 31, 6n],
[7n, 31, 7n],
[8n, 31, 8n],
[9n, 31, 9n],
[0x7ffffffen, 31, -2n],
[0x7fffffffn, 31, -1n],
[0x80000000n, 31, 0n],
[0x80000001n, 31, 1n],
[0xfffffffen, 31, -2n],
[0xffffffffn, 31, -1n],
[0x100000000n, 31, 0n],
[0x100000001n, 31, 1n],
[0x7ffffffffffffffen, 31, -2n],
[0x7fffffffffffffffn, 31, -1n],
[0x8000000000000000n, 31, 0n],
[0x8000000000000001n, 31, 1n],
[0xfffffffffffffffen, 31, -2n],
[0xffffffffffffffffn, 31, -1n],
[0x10000000000000000n, 31, 0n],
[0x10000000000000001n, 31, 1n],
[-0x10000000000000001n, 32, -1n],
[-0x10000000000000000n, 32, 0n],
[-0xffffffffffffffffn, 32, 1n],
[-0xfffffffffffffffen, 32, 2n],
[-0x8000000000000001n, 32, -1n],
[-0x8000000000000000n, 32, 0n],
[-0x7fffffffffffffffn, 32, 1n],
[-0x7ffffffffffffffen, 32, 2n],
[-0x100000001n, 32, -1n],
[-0x100000000n, 32, 0n],
[-0xffffffffn, 32, 1n],
[-0xfffffffen, 32, 2n],
[-0x80000001n, 32, 0x7fffffffn],
[-0x80000000n, 32, -0x80000000n],
[-0x7fffffffn, 32, -0x7fffffffn],
[-0x7ffffffen, 32, -0x7ffffffen],
[-9n, 32, -9n],
[-8n, 32, -8n],
[-7n, 32, -7n],
[-6n, 32, -6n],
[-5n, 32, -5n],
[-4n, 32, -4n],
[-3n, 32, -3n],
[-2n, 32, -2n],
[-1n, 32, -1n],
[0n, 32, 0n],
[1n, 32, 1n],
[2n, 32, 2n],
[3n, 32, 3n],
[4n, 32, 4n],
[5n, 32, 5n],
[6n, 32, 6n],
[7n, 32, 7n],
[8n, 32, 8n],
[9n, 32, 9n],
[0x7ffffffen, 32, 0x7ffffffen],
[0x7fffffffn, 32, 0x7fffffffn],
[0x80000000n, 32, -0x80000000n],
[0x80000001n, 32, -0x7fffffffn],
[0xfffffffen, 32, -2n],
[0xffffffffn, 32, -1n],
[0x100000000n, 32, 0n],
[0x100000001n, 32, 1n],
[0x7ffffffffffffffen, 32, -2n],
[0x7fffffffffffffffn, 32, -1n],
[0x8000000000000000n, 32, 0n],
[0x8000000000000001n, 32, 1n],
[0xfffffffffffffffen, 32, -2n],
[0xffffffffffffffffn, 32, -1n],
[0x10000000000000000n, 32, 0n],
[0x10000000000000001n, 32, 1n],
[-0x10000000000000001n, 33, -1n],
[-0x10000000000000000n, 33, 0n],
[-0xffffffffffffffffn, 33, 1n],
[-0xfffffffffffffffen, 33, 2n],
[-0x8000000000000001n, 33, -1n],
[-0x8000000000000000n, 33, 0n],
[-0x7fffffffffffffffn, 33, 1n],
[-0x7ffffffffffffffen, 33, 2n],
[-0x100000001n, 33, 0xffffffffn],
[-0x100000000n, 33, -0x100000000n],
[-0xffffffffn, 33, -0xffffffffn],
[-0xfffffffen, 33, -0xfffffffen],
[-0x80000001n, 33, -0x80000001n],
[-0x80000000n, 33, -0x80000000n],
[-0x7fffffffn, 33, -0x7fffffffn],
[-0x7ffffffen, 33, -0x7ffffffen],
[-9n, 33, -9n],
[-8n, 33, -8n],
[-7n, 33, -7n],
[-6n, 33, -6n],
[-5n, 33, -5n],
[-4n, 33, -4n],
[-3n, 33, -3n],
[-2n, 33, -2n],
[-1n, 33, -1n],
[0n, 33, 0n],
[1n, 33, 1n],
[2n, 33, 2n],
[3n, 33, 3n],
[4n, 33, 4n],
[5n, 33, 5n],
[6n, 33, 6n],
[7n, 33, 7n],
[8n, 33, 8n],
[9n, 33, 9n],
[0x7ffffffen, 33, 0x7ffffffen],
[0x7fffffffn, 33, 0x7fffffffn],
[0x80000000n, 33, 0x80000000n],
[0x80000001n, 33, 0x80000001n],
[0xfffffffen, 33, 0xfffffffen],
[0xffffffffn, 33, 0xffffffffn],
[0x100000000n, 33, -0x100000000n],
[0x100000001n, 33, -0xffffffffn],
[0x7ffffffffffffffen, 33, -2n],
[0x7fffffffffffffffn, 33, -1n],
[0x8000000000000000n, 33, 0n],
[0x8000000000000001n, 33, 1n],
[0xfffffffffffffffen, 33, -2n],
[0xffffffffffffffffn, 33, -1n],
[0x10000000000000000n, 33, 0n],
[0x10000000000000001n, 33, 1n],
[-0x10000000000000001n, 63, -1n],
[-0x10000000000000000n, 63, 0n],
[-0xffffffffffffffffn, 63, 1n],
[-0xfffffffffffffffen, 63, 2n],
[-0x8000000000000001n, 63, -1n],
[-0x8000000000000000n, 63, 0n],
[-0x7fffffffffffffffn, 63, 1n],
[-0x7ffffffffffffffen, 63, 2n],
[-0x100000001n, 63, -0x100000001n],
[-0x100000000n, 63, -0x100000000n],
[-0xffffffffn, 63, -0xffffffffn],
[-0xfffffffen, 63, -0xfffffffen],
[-0x80000001n, 63, -0x80000001n],
[-0x80000000n, 63, -0x80000000n],
[-0x7fffffffn, 63, -0x7fffffffn],
[-0x7ffffffen, 63, -0x7ffffffen],
[-9n, 63, -9n],
[-8n, 63, -8n],
[-7n, 63, -7n],
[-6n, 63, -6n],
[-5n, 63, -5n],
[-4n, 63, -4n],
[-3n, 63, -3n],
[-2n, 63, -2n],
[-1n, 63, -1n],
[0n, 63, 0n],
[1n, 63, 1n],
[2n, 63, 2n],
[3n, 63, 3n],
[4n, 63, 4n],
[5n, 63, 5n],
[6n, 63, 6n],
[7n, 63, 7n],
[8n, 63, 8n],
[9n, 63, 9n],
[0x7ffffffen, 63, 0x7ffffffen],
[0x7fffffffn, 63, 0x7fffffffn],
[0x80000000n, 63, 0x80000000n],
[0x80000001n, 63, 0x80000001n],
[0xfffffffen, 63, 0xfffffffen],
[0xffffffffn, 63, 0xffffffffn],
[0x100000000n, 63, 0x100000000n],
[0x100000001n, 63, 0x100000001n],
[0x7ffffffffffffffen, 63, -2n],
[0x7fffffffffffffffn, 63, -1n],
[0x8000000000000000n, 63, 0n],
[0x8000000000000001n, 63, 1n],
[0xfffffffffffffffen, 63, -2n],
[0xffffffffffffffffn, 63, -1n],
[0x10000000000000000n, 63, 0n],
[0x10000000000000001n, 63, 1n],
[-0x10000000000000001n, 64, -1n],
[-0x10000000000000000n, 64, 0n],
[-0xffffffffffffffffn, 64, 1n],
[-0xfffffffffffffffen, 64, 2n],
[-0x8000000000000001n, 64, 0x7fffffffffffffffn],
[-0x8000000000000000n, 64, -0x8000000000000000n],
[-0x7fffffffffffffffn, 64, -0x7fffffffffffffffn],
[-0x7ffffffffffffffen, 64, -0x7ffffffffffffffen],
[-0x100000001n, 64, -0x100000001n],
[-0x100000000n, 64, -0x100000000n],
[-0xffffffffn, 64, -0xffffffffn],
[-0xfffffffen, 64, -0xfffffffen],
[-0x80000001n, 64, -0x80000001n],
[-0x80000000n, 64, -0x80000000n],
[-0x7fffffffn, 64, -0x7fffffffn],
[-0x7ffffffen, 64, -0x7ffffffen],
[-9n, 64, -9n],
[-8n, 64, -8n],
[-7n, 64, -7n],
[-6n, 64, -6n],
[-5n, 64, -5n],
[-4n, 64, -4n],
[-3n, 64, -3n],
[-2n, 64, -2n],
[-1n, 64, -1n],
[0n, 64, 0n],
[1n, 64, 1n],
[2n, 64, 2n],
[3n, 64, 3n],
[4n, 64, 4n],
[5n, 64, 5n],
[6n, 64, 6n],
[7n, 64, 7n],
[8n, 64, 8n],
[9n, 64, 9n],
[0x7ffffffen, 64, 0x7ffffffen],
[0x7fffffffn, 64, 0x7fffffffn],
[0x80000000n, 64, 0x80000000n],
[0x80000001n, 64, 0x80000001n],
[0xfffffffen, 64, 0xfffffffen],
[0xffffffffn, 64, 0xffffffffn],
[0x100000000n, 64, 0x100000000n],
[0x100000001n, 64, 0x100000001n],
[0x7ffffffffffffffen, 64, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 64, 0x7fffffffffffffffn],
[0x8000000000000000n, 64, -0x8000000000000000n],
[0x8000000000000001n, 64, -0x7fffffffffffffffn],
[0xfffffffffffffffen, 64, -2n],
[0xffffffffffffffffn, 64, -1n],
[0x10000000000000000n, 64, 0n],
[0x10000000000000001n, 64, 1n],
[-0x10000000000000001n, 65, 0xffffffffffffffffn],
[-0x10000000000000000n, 65, -0x10000000000000000n],
[-0xffffffffffffffffn, 65, -0xffffffffffffffffn],
[-0xfffffffffffffffen, 65, -0xfffffffffffffffen],
[-0x8000000000000001n, 65, -0x8000000000000001n],
[-0x8000000000000000n, 65, -0x8000000000000000n],
[-0x7fffffffffffffffn, 65, -0x7fffffffffffffffn],
[-0x7ffffffffffffffen, 65, -0x7ffffffffffffffen],
[-0x100000001n, 65, -0x100000001n],
[-0x100000000n, 65, -0x100000000n],
[-0xffffffffn, 65, -0xffffffffn],
[-0xfffffffen, 65, -0xfffffffen],
[-0x80000001n, 65, -0x80000001n],
[-0x80000000n, 65, -0x80000000n],
[-0x7fffffffn, 65, -0x7fffffffn],
[-0x7ffffffen, 65, -0x7ffffffen],
[-9n, 65, -9n],
[-8n, 65, -8n],
[-7n, 65, -7n],
[-6n, 65, -6n],
[-5n, 65, -5n],
[-4n, 65, -4n],
[-3n, 65, -3n],
[-2n, 65, -2n],
[-1n, 65, -1n],
[0n, 65, 0n],
[1n, 65, 1n],
[2n, 65, 2n],
[3n, 65, 3n],
[4n, 65, 4n],
[5n, 65, 5n],
[6n, 65, 6n],
[7n, 65, 7n],
[8n, 65, 8n],
[9n, 65, 9n],
[0x7ffffffen, 65, 0x7ffffffen],
[0x7fffffffn, 65, 0x7fffffffn],
[0x80000000n, 65, 0x80000000n],
[0x80000001n, 65, 0x80000001n],
[0xfffffffen, 65, 0xfffffffen],
[0xffffffffn, 65, 0xffffffffn],
[0x100000000n, 65, 0x100000000n],
[0x100000001n, 65, 0x100000001n],
[0x7ffffffffffffffen, 65, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 65, 0x7fffffffffffffffn],
[0x8000000000000000n, 65, 0x8000000000000000n],
[0x8000000000000001n, 65, 0x8000000000000001n],
[0xfffffffffffffffen, 65, 0xfffffffffffffffen],
[0xffffffffffffffffn, 65, 0xffffffffffffffffn],
[0x10000000000000000n, 65, -0x10000000000000000n],
[0x10000000000000001n, 65, -0xffffffffffffffffn],
];
function f(tests) {
for (let test of tests) {
let input = test[0], bits = test[1], expected = test[2];
assertEq(BigInt.asIntN(bits, input), expected);
}
}
for (let i = 0; i < 10; ++i) {
f(tests);
}

Просмотреть файл

@ -0,0 +1,65 @@
const tests = [
[-0x10000000000000001n, -1n],
[-0x10000000000000000n, 0n],
[-0xffffffffffffffffn, 1n],
[-0xfffffffffffffffen, 2n],
[-0x8000000000000001n, -1n],
[-0x8000000000000000n, 0n],
[-0x7fffffffffffffffn, 1n],
[-0x7ffffffffffffffen, 2n],
[-0x100000001n, -1n],
[-0x100000000n, 0n],
[-0xffffffffn, 1n],
[-0xfffffffen, 2n],
[-0x80000001n, 0x7fffffffn],
[-0x80000000n, -0x80000000n],
[-0x7fffffffn, -0x7fffffffn],
[-0x7ffffffen, -0x7ffffffen],
[-9n, -9n],
[-8n, -8n],
[-7n, -7n],
[-6n, -6n],
[-5n, -5n],
[-4n, -4n],
[-3n, -3n],
[-2n, -2n],
[-1n, -1n],
[0n, 0n],
[1n, 1n],
[2n, 2n],
[3n, 3n],
[4n, 4n],
[5n, 5n],
[6n, 6n],
[7n, 7n],
[8n, 8n],
[9n, 9n],
[0x7ffffffen, 0x7ffffffen],
[0x7fffffffn, 0x7fffffffn],
[0x80000000n, -0x80000000n],
[0x80000001n, -0x7fffffffn],
[0xfffffffen, -2n],
[0xffffffffn, -1n],
[0x100000000n, 0n],
[0x100000001n, 1n],
[0x7ffffffffffffffen, -2n],
[0x7fffffffffffffffn, -1n],
[0x8000000000000000n, 0n],
[0x8000000000000001n, 1n],
[0xfffffffffffffffen, -2n],
[0xffffffffffffffffn, -1n],
[0x10000000000000000n, 0n],
[0x10000000000000001n, 1n],
];
function f(tests) {
for (let test of tests) {
let input = test[0], expected = test[1];
assertEq(BigInt.asIntN(32, input), expected);
}
}
for (let i = 0; i < 100; ++i) {
f(tests);
}

Просмотреть файл

@ -0,0 +1,65 @@
const tests = [
[-0x10000000000000001n, -1n],
[-0x10000000000000000n, 0n],
[-0xffffffffffffffffn, 1n],
[-0xfffffffffffffffen, 2n],
[-0x8000000000000001n, 0x7fffffffffffffffn],
[-0x8000000000000000n, -0x8000000000000000n],
[-0x7fffffffffffffffn, -0x7fffffffffffffffn],
[-0x7ffffffffffffffen, -0x7ffffffffffffffen],
[-0x100000001n, -0x100000001n],
[-0x100000000n, -0x100000000n],
[-0xffffffffn, -0xffffffffn],
[-0xfffffffen, -0xfffffffen],
[-0x80000001n, -0x80000001n],
[-0x80000000n, -0x80000000n],
[-0x7fffffffn, -0x7fffffffn],
[-0x7ffffffen, -0x7ffffffen],
[-9n, -9n],
[-8n, -8n],
[-7n, -7n],
[-6n, -6n],
[-5n, -5n],
[-4n, -4n],
[-3n, -3n],
[-2n, -2n],
[-1n, -1n],
[0n, 0n],
[1n, 1n],
[2n, 2n],
[3n, 3n],
[4n, 4n],
[5n, 5n],
[6n, 6n],
[7n, 7n],
[8n, 8n],
[9n, 9n],
[0x7ffffffen, 0x7ffffffen],
[0x7fffffffn, 0x7fffffffn],
[0x80000000n, 0x80000000n],
[0x80000001n, 0x80000001n],
[0xfffffffen, 0xfffffffen],
[0xffffffffn, 0xffffffffn],
[0x100000000n, 0x100000000n],
[0x100000001n, 0x100000001n],
[0x7ffffffffffffffen, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 0x7fffffffffffffffn],
[0x8000000000000000n, -0x8000000000000000n],
[0x8000000000000001n, -0x7fffffffffffffffn],
[0xfffffffffffffffen, -2n],
[0xffffffffffffffffn, -1n],
[0x10000000000000000n, 0n],
[0x10000000000000001n, 1n],
];
function f(tests) {
for (let test of tests) {
let input = test[0], expected = test[1];
assertEq(BigInt.asIntN(64, input), expected);
}
}
for (let i = 0; i < 100; ++i) {
f(tests);
}

Просмотреть файл

@ -0,0 +1,473 @@
const tests = [
[-0x10000000000000001n, 0, 0n],
[-0x10000000000000000n, 0, 0n],
[-0xffffffffffffffffn, 0, 0n],
[-0xfffffffffffffffen, 0, 0n],
[-0x8000000000000001n, 0, 0n],
[-0x8000000000000000n, 0, 0n],
[-0x7fffffffffffffffn, 0, 0n],
[-0x7ffffffffffffffen, 0, 0n],
[-0x100000001n, 0, 0n],
[-0x100000000n, 0, 0n],
[-0xffffffffn, 0, 0n],
[-0xfffffffen, 0, 0n],
[-0x80000001n, 0, 0n],
[-0x80000000n, 0, 0n],
[-0x7fffffffn, 0, 0n],
[-0x7ffffffen, 0, 0n],
[-9n, 0, 0n],
[-8n, 0, 0n],
[-7n, 0, 0n],
[-6n, 0, 0n],
[-5n, 0, 0n],
[-4n, 0, 0n],
[-3n, 0, 0n],
[-2n, 0, 0n],
[-1n, 0, 0n],
[0n, 0, 0n],
[1n, 0, 0n],
[2n, 0, 0n],
[3n, 0, 0n],
[4n, 0, 0n],
[5n, 0, 0n],
[6n, 0, 0n],
[7n, 0, 0n],
[8n, 0, 0n],
[9n, 0, 0n],
[0x7ffffffen, 0, 0n],
[0x7fffffffn, 0, 0n],
[0x80000000n, 0, 0n],
[0x80000001n, 0, 0n],
[0xfffffffen, 0, 0n],
[0xffffffffn, 0, 0n],
[0x100000000n, 0, 0n],
[0x100000001n, 0, 0n],
[0x7ffffffffffffffen, 0, 0n],
[0x7fffffffffffffffn, 0, 0n],
[0x8000000000000000n, 0, 0n],
[0x8000000000000001n, 0, 0n],
[0xfffffffffffffffen, 0, 0n],
[0xffffffffffffffffn, 0, 0n],
[0x10000000000000000n, 0, 0n],
[0x10000000000000001n, 0, 0n],
[-0x10000000000000001n, 1, 1n],
[-0x10000000000000000n, 1, 0n],
[-0xffffffffffffffffn, 1, 1n],
[-0xfffffffffffffffen, 1, 0n],
[-0x8000000000000001n, 1, 1n],
[-0x8000000000000000n, 1, 0n],
[-0x7fffffffffffffffn, 1, 1n],
[-0x7ffffffffffffffen, 1, 0n],
[-0x100000001n, 1, 1n],
[-0x100000000n, 1, 0n],
[-0xffffffffn, 1, 1n],
[-0xfffffffen, 1, 0n],
[-0x80000001n, 1, 1n],
[-0x80000000n, 1, 0n],
[-0x7fffffffn, 1, 1n],
[-0x7ffffffen, 1, 0n],
[-9n, 1, 1n],
[-8n, 1, 0n],
[-7n, 1, 1n],
[-6n, 1, 0n],
[-5n, 1, 1n],
[-4n, 1, 0n],
[-3n, 1, 1n],
[-2n, 1, 0n],
[-1n, 1, 1n],
[0n, 1, 0n],
[1n, 1, 1n],
[2n, 1, 0n],
[3n, 1, 1n],
[4n, 1, 0n],
[5n, 1, 1n],
[6n, 1, 0n],
[7n, 1, 1n],
[8n, 1, 0n],
[9n, 1, 1n],
[0x7ffffffen, 1, 0n],
[0x7fffffffn, 1, 1n],
[0x80000000n, 1, 0n],
[0x80000001n, 1, 1n],
[0xfffffffen, 1, 0n],
[0xffffffffn, 1, 1n],
[0x100000000n, 1, 0n],
[0x100000001n, 1, 1n],
[0x7ffffffffffffffen, 1, 0n],
[0x7fffffffffffffffn, 1, 1n],
[0x8000000000000000n, 1, 0n],
[0x8000000000000001n, 1, 1n],
[0xfffffffffffffffen, 1, 0n],
[0xffffffffffffffffn, 1, 1n],
[0x10000000000000000n, 1, 0n],
[0x10000000000000001n, 1, 1n],
[-0x10000000000000001n, 2, 3n],
[-0x10000000000000000n, 2, 0n],
[-0xffffffffffffffffn, 2, 1n],
[-0xfffffffffffffffen, 2, 2n],
[-0x8000000000000001n, 2, 3n],
[-0x8000000000000000n, 2, 0n],
[-0x7fffffffffffffffn, 2, 1n],
[-0x7ffffffffffffffen, 2, 2n],
[-0x100000001n, 2, 3n],
[-0x100000000n, 2, 0n],
[-0xffffffffn, 2, 1n],
[-0xfffffffen, 2, 2n],
[-0x80000001n, 2, 3n],
[-0x80000000n, 2, 0n],
[-0x7fffffffn, 2, 1n],
[-0x7ffffffen, 2, 2n],
[-9n, 2, 3n],
[-8n, 2, 0n],
[-7n, 2, 1n],
[-6n, 2, 2n],
[-5n, 2, 3n],
[-4n, 2, 0n],
[-3n, 2, 1n],
[-2n, 2, 2n],
[-1n, 2, 3n],
[0n, 2, 0n],
[1n, 2, 1n],
[2n, 2, 2n],
[3n, 2, 3n],
[4n, 2, 0n],
[5n, 2, 1n],
[6n, 2, 2n],
[7n, 2, 3n],
[8n, 2, 0n],
[9n, 2, 1n],
[0x7ffffffen, 2, 2n],
[0x7fffffffn, 2, 3n],
[0x80000000n, 2, 0n],
[0x80000001n, 2, 1n],
[0xfffffffen, 2, 2n],
[0xffffffffn, 2, 3n],
[0x100000000n, 2, 0n],
[0x100000001n, 2, 1n],
[0x7ffffffffffffffen, 2, 2n],
[0x7fffffffffffffffn, 2, 3n],
[0x8000000000000000n, 2, 0n],
[0x8000000000000001n, 2, 1n],
[0xfffffffffffffffen, 2, 2n],
[0xffffffffffffffffn, 2, 3n],
[0x10000000000000000n, 2, 0n],
[0x10000000000000001n, 2, 1n],
[-0x10000000000000001n, 31, 0x7fffffffn],
[-0x10000000000000000n, 31, 0n],
[-0xffffffffffffffffn, 31, 1n],
[-0xfffffffffffffffen, 31, 2n],
[-0x8000000000000001n, 31, 0x7fffffffn],
[-0x8000000000000000n, 31, 0n],
[-0x7fffffffffffffffn, 31, 1n],
[-0x7ffffffffffffffen, 31, 2n],
[-0x100000001n, 31, 0x7fffffffn],
[-0x100000000n, 31, 0n],
[-0xffffffffn, 31, 1n],
[-0xfffffffen, 31, 2n],
[-0x80000001n, 31, 0x7fffffffn],
[-0x80000000n, 31, 0n],
[-0x7fffffffn, 31, 1n],
[-0x7ffffffen, 31, 2n],
[-9n, 31, 0x7ffffff7n],
[-8n, 31, 0x7ffffff8n],
[-7n, 31, 0x7ffffff9n],
[-6n, 31, 0x7ffffffan],
[-5n, 31, 0x7ffffffbn],
[-4n, 31, 0x7ffffffcn],
[-3n, 31, 0x7ffffffdn],
[-2n, 31, 0x7ffffffen],
[-1n, 31, 0x7fffffffn],
[0n, 31, 0n],
[1n, 31, 1n],
[2n, 31, 2n],
[3n, 31, 3n],
[4n, 31, 4n],
[5n, 31, 5n],
[6n, 31, 6n],
[7n, 31, 7n],
[8n, 31, 8n],
[9n, 31, 9n],
[0x7ffffffen, 31, 0x7ffffffen],
[0x7fffffffn, 31, 0x7fffffffn],
[0x80000000n, 31, 0n],
[0x80000001n, 31, 1n],
[0xfffffffen, 31, 0x7ffffffen],
[0xffffffffn, 31, 0x7fffffffn],
[0x100000000n, 31, 0n],
[0x100000001n, 31, 1n],
[0x7ffffffffffffffen, 31, 0x7ffffffen],
[0x7fffffffffffffffn, 31, 0x7fffffffn],
[0x8000000000000000n, 31, 0n],
[0x8000000000000001n, 31, 1n],
[0xfffffffffffffffen, 31, 0x7ffffffen],
[0xffffffffffffffffn, 31, 0x7fffffffn],
[0x10000000000000000n, 31, 0n],
[0x10000000000000001n, 31, 1n],
[-0x10000000000000001n, 32, 0xffffffffn],
[-0x10000000000000000n, 32, 0n],
[-0xffffffffffffffffn, 32, 1n],
[-0xfffffffffffffffen, 32, 2n],
[-0x8000000000000001n, 32, 0xffffffffn],
[-0x8000000000000000n, 32, 0n],
[-0x7fffffffffffffffn, 32, 1n],
[-0x7ffffffffffffffen, 32, 2n],
[-0x100000001n, 32, 0xffffffffn],
[-0x100000000n, 32, 0n],
[-0xffffffffn, 32, 1n],
[-0xfffffffen, 32, 2n],
[-0x80000001n, 32, 0x7fffffffn],
[-0x80000000n, 32, 0x80000000n],
[-0x7fffffffn, 32, 0x80000001n],
[-0x7ffffffen, 32, 0x80000002n],
[-9n, 32, 0xfffffff7n],
[-8n, 32, 0xfffffff8n],
[-7n, 32, 0xfffffff9n],
[-6n, 32, 0xfffffffan],
[-5n, 32, 0xfffffffbn],
[-4n, 32, 0xfffffffcn],
[-3n, 32, 0xfffffffdn],
[-2n, 32, 0xfffffffen],
[-1n, 32, 0xffffffffn],
[0n, 32, 0n],
[1n, 32, 1n],
[2n, 32, 2n],
[3n, 32, 3n],
[4n, 32, 4n],
[5n, 32, 5n],
[6n, 32, 6n],
[7n, 32, 7n],
[8n, 32, 8n],
[9n, 32, 9n],
[0x7ffffffen, 32, 0x7ffffffen],
[0x7fffffffn, 32, 0x7fffffffn],
[0x80000000n, 32, 0x80000000n],
[0x80000001n, 32, 0x80000001n],
[0xfffffffen, 32, 0xfffffffen],
[0xffffffffn, 32, 0xffffffffn],
[0x100000000n, 32, 0n],
[0x100000001n, 32, 1n],
[0x7ffffffffffffffen, 32, 0xfffffffen],
[0x7fffffffffffffffn, 32, 0xffffffffn],
[0x8000000000000000n, 32, 0n],
[0x8000000000000001n, 32, 1n],
[0xfffffffffffffffen, 32, 0xfffffffen],
[0xffffffffffffffffn, 32, 0xffffffffn],
[0x10000000000000000n, 32, 0n],
[0x10000000000000001n, 32, 1n],
[-0x10000000000000001n, 33, 0x1ffffffffn],
[-0x10000000000000000n, 33, 0n],
[-0xffffffffffffffffn, 33, 1n],
[-0xfffffffffffffffen, 33, 2n],
[-0x8000000000000001n, 33, 0x1ffffffffn],
[-0x8000000000000000n, 33, 0n],
[-0x7fffffffffffffffn, 33, 1n],
[-0x7ffffffffffffffen, 33, 2n],
[-0x100000001n, 33, 0xffffffffn],
[-0x100000000n, 33, 0x100000000n],
[-0xffffffffn, 33, 0x100000001n],
[-0xfffffffen, 33, 0x100000002n],
[-0x80000001n, 33, 0x17fffffffn],
[-0x80000000n, 33, 0x180000000n],
[-0x7fffffffn, 33, 0x180000001n],
[-0x7ffffffen, 33, 0x180000002n],
[-9n, 33, 0x1fffffff7n],
[-8n, 33, 0x1fffffff8n],
[-7n, 33, 0x1fffffff9n],
[-6n, 33, 0x1fffffffan],
[-5n, 33, 0x1fffffffbn],
[-4n, 33, 0x1fffffffcn],
[-3n, 33, 0x1fffffffdn],
[-2n, 33, 0x1fffffffen],
[-1n, 33, 0x1ffffffffn],
[0n, 33, 0n],
[1n, 33, 1n],
[2n, 33, 2n],
[3n, 33, 3n],
[4n, 33, 4n],
[5n, 33, 5n],
[6n, 33, 6n],
[7n, 33, 7n],
[8n, 33, 8n],
[9n, 33, 9n],
[0x7ffffffen, 33, 0x7ffffffen],
[0x7fffffffn, 33, 0x7fffffffn],
[0x80000000n, 33, 0x80000000n],
[0x80000001n, 33, 0x80000001n],
[0xfffffffen, 33, 0xfffffffen],
[0xffffffffn, 33, 0xffffffffn],
[0x100000000n, 33, 0x100000000n],
[0x100000001n, 33, 0x100000001n],
[0x7ffffffffffffffen, 33, 0x1fffffffen],
[0x7fffffffffffffffn, 33, 0x1ffffffffn],
[0x8000000000000000n, 33, 0n],
[0x8000000000000001n, 33, 1n],
[0xfffffffffffffffen, 33, 0x1fffffffen],
[0xffffffffffffffffn, 33, 0x1ffffffffn],
[0x10000000000000000n, 33, 0n],
[0x10000000000000001n, 33, 1n],
[-0x10000000000000001n, 63, 0x7fffffffffffffffn],
[-0x10000000000000000n, 63, 0n],
[-0xffffffffffffffffn, 63, 1n],
[-0xfffffffffffffffen, 63, 2n],
[-0x8000000000000001n, 63, 0x7fffffffffffffffn],
[-0x8000000000000000n, 63, 0n],
[-0x7fffffffffffffffn, 63, 1n],
[-0x7ffffffffffffffen, 63, 2n],
[-0x100000001n, 63, 0x7ffffffeffffffffn],
[-0x100000000n, 63, 0x7fffffff00000000n],
[-0xffffffffn, 63, 0x7fffffff00000001n],
[-0xfffffffen, 63, 0x7fffffff00000002n],
[-0x80000001n, 63, 0x7fffffff7fffffffn],
[-0x80000000n, 63, 0x7fffffff80000000n],
[-0x7fffffffn, 63, 0x7fffffff80000001n],
[-0x7ffffffen, 63, 0x7fffffff80000002n],
[-9n, 63, 0x7ffffffffffffff7n],
[-8n, 63, 0x7ffffffffffffff8n],
[-7n, 63, 0x7ffffffffffffff9n],
[-6n, 63, 0x7ffffffffffffffan],
[-5n, 63, 0x7ffffffffffffffbn],
[-4n, 63, 0x7ffffffffffffffcn],
[-3n, 63, 0x7ffffffffffffffdn],
[-2n, 63, 0x7ffffffffffffffen],
[-1n, 63, 0x7fffffffffffffffn],
[0n, 63, 0n],
[1n, 63, 1n],
[2n, 63, 2n],
[3n, 63, 3n],
[4n, 63, 4n],
[5n, 63, 5n],
[6n, 63, 6n],
[7n, 63, 7n],
[8n, 63, 8n],
[9n, 63, 9n],
[0x7ffffffen, 63, 0x7ffffffen],
[0x7fffffffn, 63, 0x7fffffffn],
[0x80000000n, 63, 0x80000000n],
[0x80000001n, 63, 0x80000001n],
[0xfffffffen, 63, 0xfffffffen],
[0xffffffffn, 63, 0xffffffffn],
[0x100000000n, 63, 0x100000000n],
[0x100000001n, 63, 0x100000001n],
[0x7ffffffffffffffen, 63, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 63, 0x7fffffffffffffffn],
[0x8000000000000000n, 63, 0n],
[0x8000000000000001n, 63, 1n],
[0xfffffffffffffffen, 63, 0x7ffffffffffffffen],
[0xffffffffffffffffn, 63, 0x7fffffffffffffffn],
[0x10000000000000000n, 63, 0n],
[0x10000000000000001n, 63, 1n],
[-0x10000000000000001n, 64, 0xffffffffffffffffn],
[-0x10000000000000000n, 64, 0n],
[-0xffffffffffffffffn, 64, 1n],
[-0xfffffffffffffffen, 64, 2n],
[-0x8000000000000001n, 64, 0x7fffffffffffffffn],
[-0x8000000000000000n, 64, 0x8000000000000000n],
[-0x7fffffffffffffffn, 64, 0x8000000000000001n],
[-0x7ffffffffffffffen, 64, 0x8000000000000002n],
[-0x100000001n, 64, 0xfffffffeffffffffn],
[-0x100000000n, 64, 0xffffffff00000000n],
[-0xffffffffn, 64, 0xffffffff00000001n],
[-0xfffffffen, 64, 0xffffffff00000002n],
[-0x80000001n, 64, 0xffffffff7fffffffn],
[-0x80000000n, 64, 0xffffffff80000000n],
[-0x7fffffffn, 64, 0xffffffff80000001n],
[-0x7ffffffen, 64, 0xffffffff80000002n],
[-9n, 64, 0xfffffffffffffff7n],
[-8n, 64, 0xfffffffffffffff8n],
[-7n, 64, 0xfffffffffffffff9n],
[-6n, 64, 0xfffffffffffffffan],
[-5n, 64, 0xfffffffffffffffbn],
[-4n, 64, 0xfffffffffffffffcn],
[-3n, 64, 0xfffffffffffffffdn],
[-2n, 64, 0xfffffffffffffffen],
[-1n, 64, 0xffffffffffffffffn],
[0n, 64, 0n],
[1n, 64, 1n],
[2n, 64, 2n],
[3n, 64, 3n],
[4n, 64, 4n],
[5n, 64, 5n],
[6n, 64, 6n],
[7n, 64, 7n],
[8n, 64, 8n],
[9n, 64, 9n],
[0x7ffffffen, 64, 0x7ffffffen],
[0x7fffffffn, 64, 0x7fffffffn],
[0x80000000n, 64, 0x80000000n],
[0x80000001n, 64, 0x80000001n],
[0xfffffffen, 64, 0xfffffffen],
[0xffffffffn, 64, 0xffffffffn],
[0x100000000n, 64, 0x100000000n],
[0x100000001n, 64, 0x100000001n],
[0x7ffffffffffffffen, 64, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 64, 0x7fffffffffffffffn],
[0x8000000000000000n, 64, 0x8000000000000000n],
[0x8000000000000001n, 64, 0x8000000000000001n],
[0xfffffffffffffffen, 64, 0xfffffffffffffffen],
[0xffffffffffffffffn, 64, 0xffffffffffffffffn],
[0x10000000000000000n, 64, 0n],
[0x10000000000000001n, 64, 1n],
[-0x10000000000000001n, 65, 0xffffffffffffffffn],
[-0x10000000000000000n, 65, 0x10000000000000000n],
[-0xffffffffffffffffn, 65, 0x10000000000000001n],
[-0xfffffffffffffffen, 65, 0x10000000000000002n],
[-0x8000000000000001n, 65, 0x17fffffffffffffffn],
[-0x8000000000000000n, 65, 0x18000000000000000n],
[-0x7fffffffffffffffn, 65, 0x18000000000000001n],
[-0x7ffffffffffffffen, 65, 0x18000000000000002n],
[-0x100000001n, 65, 0x1fffffffeffffffffn],
[-0x100000000n, 65, 0x1ffffffff00000000n],
[-0xffffffffn, 65, 0x1ffffffff00000001n],
[-0xfffffffen, 65, 0x1ffffffff00000002n],
[-0x80000001n, 65, 0x1ffffffff7fffffffn],
[-0x80000000n, 65, 0x1ffffffff80000000n],
[-0x7fffffffn, 65, 0x1ffffffff80000001n],
[-0x7ffffffen, 65, 0x1ffffffff80000002n],
[-9n, 65, 0x1fffffffffffffff7n],
[-8n, 65, 0x1fffffffffffffff8n],
[-7n, 65, 0x1fffffffffffffff9n],
[-6n, 65, 0x1fffffffffffffffan],
[-5n, 65, 0x1fffffffffffffffbn],
[-4n, 65, 0x1fffffffffffffffcn],
[-3n, 65, 0x1fffffffffffffffdn],
[-2n, 65, 0x1fffffffffffffffen],
[-1n, 65, 0x1ffffffffffffffffn],
[0n, 65, 0n],
[1n, 65, 1n],
[2n, 65, 2n],
[3n, 65, 3n],
[4n, 65, 4n],
[5n, 65, 5n],
[6n, 65, 6n],
[7n, 65, 7n],
[8n, 65, 8n],
[9n, 65, 9n],
[0x7ffffffen, 65, 0x7ffffffen],
[0x7fffffffn, 65, 0x7fffffffn],
[0x80000000n, 65, 0x80000000n],
[0x80000001n, 65, 0x80000001n],
[0xfffffffen, 65, 0xfffffffen],
[0xffffffffn, 65, 0xffffffffn],
[0x100000000n, 65, 0x100000000n],
[0x100000001n, 65, 0x100000001n],
[0x7ffffffffffffffen, 65, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 65, 0x7fffffffffffffffn],
[0x8000000000000000n, 65, 0x8000000000000000n],
[0x8000000000000001n, 65, 0x8000000000000001n],
[0xfffffffffffffffen, 65, 0xfffffffffffffffen],
[0xffffffffffffffffn, 65, 0xffffffffffffffffn],
[0x10000000000000000n, 65, 0x10000000000000000n],
[0x10000000000000001n, 65, 0x10000000000000001n],
];
function f(tests) {
for (let test of tests) {
let input = test[0], bits = test[1], expected = test[2];
assertEq(BigInt.asUintN(bits, input), expected);
}
}
for (let i = 0; i < 10; ++i) {
f(tests);
}

Просмотреть файл

@ -0,0 +1,65 @@
const tests = [
[-0x10000000000000001n, 0xffffffffn],
[-0x10000000000000000n, 0n],
[-0xffffffffffffffffn, 1n],
[-0xfffffffffffffffen, 2n],
[-0x8000000000000001n, 0xffffffffn],
[-0x8000000000000000n, 0n],
[-0x7fffffffffffffffn, 1n],
[-0x7ffffffffffffffen, 2n],
[-0x100000001n, 0xffffffffn],
[-0x100000000n, 0n],
[-0xffffffffn, 1n],
[-0xfffffffen, 2n],
[-0x80000001n, 0x7fffffffn],
[-0x80000000n, 0x80000000n],
[-0x7fffffffn, 0x80000001n],
[-0x7ffffffen, 0x80000002n],
[-9n, 0xfffffff7n],
[-8n, 0xfffffff8n],
[-7n, 0xfffffff9n],
[-6n, 0xfffffffan],
[-5n, 0xfffffffbn],
[-4n, 0xfffffffcn],
[-3n, 0xfffffffdn],
[-2n, 0xfffffffen],
[-1n, 0xffffffffn],
[0n, 0n],
[1n, 1n],
[2n, 2n],
[3n, 3n],
[4n, 4n],
[5n, 5n],
[6n, 6n],
[7n, 7n],
[8n, 8n],
[9n, 9n],
[0x7ffffffen, 0x7ffffffen],
[0x7fffffffn, 0x7fffffffn],
[0x80000000n, 0x80000000n],
[0x80000001n, 0x80000001n],
[0xfffffffen, 0xfffffffen],
[0xffffffffn, 0xffffffffn],
[0x100000000n, 0n],
[0x100000001n, 1n],
[0x7ffffffffffffffen, 0xfffffffen],
[0x7fffffffffffffffn, 0xffffffffn],
[0x8000000000000000n, 0n],
[0x8000000000000001n, 1n],
[0xfffffffffffffffen, 0xfffffffen],
[0xffffffffffffffffn, 0xffffffffn],
[0x10000000000000000n, 0n],
[0x10000000000000001n, 1n],
];
function f(tests) {
for (let test of tests) {
let input = test[0], expected = test[1];
assertEq(BigInt.asUintN(32, input), expected);
}
}
for (let i = 0; i < 100; ++i) {
f(tests);
}

Просмотреть файл

@ -0,0 +1,65 @@
const tests = [
[-0x10000000000000001n, 0xffffffffffffffffn],
[-0x10000000000000000n, 0n],
[-0xffffffffffffffffn, 1n],
[-0xfffffffffffffffen, 2n],
[-0x8000000000000001n, 0x7fffffffffffffffn],
[-0x8000000000000000n, 0x8000000000000000n],
[-0x7fffffffffffffffn, 0x8000000000000001n],
[-0x7ffffffffffffffen, 0x8000000000000002n],
[-0x100000001n, 0xfffffffeffffffffn],
[-0x100000000n, 0xffffffff00000000n],
[-0xffffffffn, 0xffffffff00000001n],
[-0xfffffffen, 0xffffffff00000002n],
[-0x80000001n, 0xffffffff7fffffffn],
[-0x80000000n, 0xffffffff80000000n],
[-0x7fffffffn, 0xffffffff80000001n],
[-0x7ffffffen, 0xffffffff80000002n],
[-9n, 0xfffffffffffffff7n],
[-8n, 0xfffffffffffffff8n],
[-7n, 0xfffffffffffffff9n],
[-6n, 0xfffffffffffffffan],
[-5n, 0xfffffffffffffffbn],
[-4n, 0xfffffffffffffffcn],
[-3n, 0xfffffffffffffffdn],
[-2n, 0xfffffffffffffffen],
[-1n, 0xffffffffffffffffn],
[0n, 0n],
[1n, 1n],
[2n, 2n],
[3n, 3n],
[4n, 4n],
[5n, 5n],
[6n, 6n],
[7n, 7n],
[8n, 8n],
[9n, 9n],
[0x7ffffffen, 0x7ffffffen],
[0x7fffffffn, 0x7fffffffn],
[0x80000000n, 0x80000000n],
[0x80000001n, 0x80000001n],
[0xfffffffen, 0xfffffffen],
[0xffffffffn, 0xffffffffn],
[0x100000000n, 0x100000000n],
[0x100000001n, 0x100000001n],
[0x7ffffffffffffffen, 0x7ffffffffffffffen],
[0x7fffffffffffffffn, 0x7fffffffffffffffn],
[0x8000000000000000n, 0x8000000000000000n],
[0x8000000000000001n, 0x8000000000000001n],
[0xfffffffffffffffen, 0xfffffffffffffffen],
[0xffffffffffffffffn, 0xffffffffffffffffn],
[0x10000000000000000n, 0n],
[0x10000000000000001n, 1n],
];
function f(tests) {
for (let test of tests) {
let input = test[0], expected = test[1];
assertEq(BigInt.asUintN(64, input), expected);
}
}
for (let i = 0; i < 100; ++i) {
f(tests);
}

Просмотреть файл

@ -1544,6 +1544,24 @@ function rbigintrsh(i) {
return i;
}
let uceFault_bigintasint = eval(`(${uceFault})`.replace('uceFault', 'uceFault_bigintasint'));
function rbigintasint(i) {
var x = BigInt.asIntN(6, i);
if (uceFault_bigintasint(i) || uceFault_bigintasint(i))
assertEq(x, -29n);
assertRecoveredOnBailout(x, true);
return i;
}
let uceFault_bigintasuint = eval(`(${uceFault})`.replace('uceFault', 'uceFault_bigintasuint'));
function rbigintasuint(i) {
var x = BigInt.asUintN(6, i);
if (uceFault_bigintasuint(i) || uceFault_bigintasuint(i))
assertEq(x, 35n);
assertRecoveredOnBailout(x, true);
return i;
}
for (j = 100 - max; j < 100; j++) {
with({}){} // Do not Ion-compile this loop.
let i = j < 2 ? (Math.abs(j) % 50) + 2 : j;
@ -1697,6 +1715,8 @@ for (j = 100 - max; j < 100; j++) {
rbigintbitnot(BigInt(i));
rbigintlsh(BigInt(i));
rbigintrsh(BigInt(i));
rbigintasint(BigInt(i));
rbigintasuint(BigInt(i));
}
// Test that we can refer multiple time to the same recover instruction, as well

Просмотреть файл

@ -118,6 +118,19 @@ function bigIntRshBail(i) {
if (i >= 99) bailout();
}
function bigIntAsUintBail(i) {
var x = [0, maxBitLength + 1][0 + (i >= 99)];
var a = BigInt.asUintN(x, -1n);
// Add a function call to capture a resumepoint at the end of the call or
// inside the inlined block, such as the bailout does not rewind to the
// beginning of the function.
resumeHere();
if (i >= 99) bailout();
}
// Prevent compilation of the top-level
eval(`(${resumeHere})`);
@ -196,3 +209,12 @@ try {
} catch (e) {
assertEq(e instanceof RangeError || e === "out of memory", true, String(e));
}
try {
for (let i = 0; i < 100; i++) {
bigIntAsUintBail(i);
}
throw new Error("missing exception");
} catch (e) {
assertEq(e instanceof RangeError || e === "out of memory", true, String(e));
}

Просмотреть файл

@ -2514,7 +2514,7 @@
- name: BigIntAsIntNResult
shared: true
transpile: false
transpile: true
cost_estimate: 5
args:
bits: Int32Id
@ -2522,7 +2522,7 @@
- name: BigIntAsUintNResult
shared: true
transpile: false
transpile: true
cost_estimate: 5
args:
bits: Int32Id

Просмотреть файл

@ -15605,6 +15605,159 @@ void CodeGenerator::visitCallObjectHasSparseElement(
bailoutFrom(&bail, lir->snapshot());
}
void CodeGenerator::visitBigIntAsIntN(LBigIntAsIntN* ins) {
Register bits = ToRegister(ins->bits());
Register input = ToRegister(ins->input());
pushArg(bits);
pushArg(input);
using Fn = BigInt* (*)(JSContext*, HandleBigInt, int32_t);
callVM<Fn, jit::BigIntAsIntN>(ins);
}
void CodeGenerator::visitBigIntAsIntN64(LBigIntAsIntN64* ins) {
Register input = ToRegister(ins->input());
Register temp = ToRegister(ins->temp());
Register64 temp64 = ToRegister64(ins->temp64());
Register output = ToRegister(ins->output());
Label done, create;
masm.movePtr(input, output);
// Load the BigInt value as an int64.
masm.loadBigInt64(input, temp64);
// Create a new BigInt when the input exceeds the int64 range.
masm.branch32(Assembler::Above, Address(input, BigInt::offsetOfLength()),
Imm32(64 / BigInt::DigitBits), &create);
// And create a new BigInt when the value and the BigInt have different signs.
Label nonNegative;
masm.branchIfBigIntIsNonNegative(input, &nonNegative);
masm.branchTest64(Assembler::NotSigned, temp64, temp64, temp, &create);
masm.jump(&done);
masm.bind(&nonNegative);
masm.branchTest64(Assembler::NotSigned, temp64, temp64, temp, &done);
masm.bind(&create);
emitCreateBigInt(ins, Scalar::BigInt64, temp64, output, temp);
masm.bind(&done);
}
void CodeGenerator::visitBigIntAsIntN32(LBigIntAsIntN32* ins) {
Register input = ToRegister(ins->input());
Register temp = ToRegister(ins->temp());
Register64 temp64 = ToRegister64(ins->temp64());
Register output = ToRegister(ins->output());
Label done, create;
masm.movePtr(input, output);
// Load the absolute value of the first digit.
masm.loadFirstBigIntDigitOrZero(input, temp);
// If the absolute value exceeds the int32 range, create a new BigInt.
masm.branchPtr(Assembler::Above, temp, Imm32(INT32_MAX), &create);
// Also create a new BigInt if we have more than one digit.
masm.branch32(Assembler::BelowOrEqual,
Address(input, BigInt::offsetOfLength()), Imm32(1), &done);
masm.bind(&create);
// |temp| stores the absolute value, negate it when the sign flag is set.
Label nonNegative;
masm.branchIfBigIntIsNonNegative(input, &nonNegative);
masm.negPtr(temp);
masm.bind(&nonNegative);
masm.move32To64SignExtend(temp, temp64);
emitCreateBigInt(ins, Scalar::BigInt64, temp64, output, temp);
masm.bind(&done);
}
void CodeGenerator::visitBigIntAsUintN(LBigIntAsUintN* ins) {
Register bits = ToRegister(ins->bits());
Register input = ToRegister(ins->input());
pushArg(bits);
pushArg(input);
using Fn = BigInt* (*)(JSContext*, HandleBigInt, int32_t);
callVM<Fn, jit::BigIntAsUintN>(ins);
}
void CodeGenerator::visitBigIntAsUintN64(LBigIntAsUintN64* ins) {
Register input = ToRegister(ins->input());
Register temp = ToRegister(ins->temp());
Register64 temp64 = ToRegister64(ins->temp64());
Register output = ToRegister(ins->output());
Label done, create;
masm.movePtr(input, output);
// Load the BigInt value as an uint64.
masm.loadBigInt64(input, temp64);
// Create a new BigInt when the input exceeds the uint64 range.
masm.branch32(Assembler::Above, Address(input, BigInt::offsetOfLength()),
Imm32(64 / BigInt::DigitBits), &create);
// And create a new BigInt when the input has the sign flag set.
masm.branchIfBigIntIsNonNegative(input, &done);
masm.bind(&create);
emitCreateBigInt(ins, Scalar::BigUint64, temp64, output, temp);
masm.bind(&done);
}
void CodeGenerator::visitBigIntAsUintN32(LBigIntAsUintN32* ins) {
Register input = ToRegister(ins->input());
Register temp = ToRegister(ins->temp());
Register64 temp64 = ToRegister64(ins->temp64());
Register output = ToRegister(ins->output());
Label done, create;
masm.movePtr(input, output);
// Load the absolute value of the first digit.
masm.loadFirstBigIntDigitOrZero(input, temp);
// If the absolute value exceeds the uint32 range, create a new BigInt.
#if JS_PUNBOX64
masm.branchPtr(Assembler::Above, temp, ImmWord(UINT32_MAX), &create);
#endif
// Also create a new BigInt if we have more than one digit.
masm.branch32(Assembler::Above, Address(input, BigInt::offsetOfLength()),
Imm32(1), &create);
// And create a new BigInt when the input has the sign flag set.
masm.branchIfBigIntIsNonNegative(input, &done);
masm.bind(&create);
// |temp| stores the absolute value, negate it when the sign flag is set.
Label nonNegative;
masm.branchIfBigIntIsNonNegative(input, &nonNegative);
masm.negPtr(temp);
masm.bind(&nonNegative);
masm.move32To64ZeroExtend(temp, temp64);
emitCreateBigInt(ins, Scalar::BigUint64, temp64, output, temp);
masm.bind(&done);
}
template <size_t NumDefs>
void CodeGenerator::emitIonToWasmCallBase(LIonToWasmCallBase<NumDefs>* lir) {
wasm::JitCallStackArgVector stackArgs;

Просмотреть файл

@ -5690,6 +5690,62 @@ void LIRGenerator::visitCallObjectHasSparseElement(
defineReturn(lir, ins);
}
void LIRGenerator::visitBigIntAsIntN(MBigIntAsIntN* ins) {
MOZ_ASSERT(ins->bits()->type() == MIRType::Int32);
MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
if (ins->bits()->isConstant()) {
int32_t bits = ins->bits()->toConstant()->toInt32();
if (bits == 64) {
auto* lir = new (alloc())
LBigIntAsIntN64(useRegister(ins->input()), temp(), tempInt64());
define(lir, ins);
assignSafepoint(lir, ins);
return;
}
if (bits == 32) {
auto* lir = new (alloc())
LBigIntAsIntN32(useRegister(ins->input()), temp(), tempInt64());
define(lir, ins);
assignSafepoint(lir, ins);
return;
}
}
auto* lir = new (alloc()) LBigIntAsIntN(useRegisterAtStart(ins->bits()),
useRegisterAtStart(ins->input()));
defineReturn(lir, ins);
assignSafepoint(lir, ins);
}
void LIRGenerator::visitBigIntAsUintN(MBigIntAsUintN* ins) {
MOZ_ASSERT(ins->bits()->type() == MIRType::Int32);
MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
if (ins->bits()->isConstant()) {
int32_t bits = ins->bits()->toConstant()->toInt32();
if (bits == 64) {
auto* lir = new (alloc())
LBigIntAsUintN64(useRegister(ins->input()), temp(), tempInt64());
define(lir, ins);
assignSafepoint(lir, ins);
return;
}
if (bits == 32) {
auto* lir = new (alloc())
LBigIntAsUintN32(useRegister(ins->input()), temp(), tempInt64());
define(lir, ins);
assignSafepoint(lir, ins);
return;
}
}
auto* lir = new (alloc()) LBigIntAsUintN(useRegisterAtStart(ins->bits()),
useRegisterAtStart(ins->input()));
defineReturn(lir, ins);
assignSafepoint(lir, ins);
}
void LIRGenerator::visitConstant(MConstant* ins) {
if (!IsFloatingPointType(ins->type()) && ins->canEmitAtUses()) {
emitAtUses(ins);

Просмотреть файл

@ -5883,7 +5883,7 @@ class MBigIntAdd : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntAdd)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -5900,7 +5900,7 @@ class MBigIntSub : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntSub)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -5919,7 +5919,7 @@ class MBigIntMul : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntMul)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -5955,7 +5955,7 @@ class MBigIntDiv : public MBigIntBinaryArithInstruction {
return AliasSet::None();
}
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return !canBeDivideByZero(); }
@ -5991,7 +5991,7 @@ class MBigIntMod : public MBigIntBinaryArithInstruction {
return AliasSet::None();
}
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return !canBeDivideByZero(); }
@ -6027,7 +6027,7 @@ class MBigIntPow : public MBigIntBinaryArithInstruction {
return AliasSet::None();
}
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return !canBeNegativeExponent(); }
@ -6046,7 +6046,7 @@ class MBigIntBitAnd : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntBitAnd)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6065,7 +6065,7 @@ class MBigIntBitOr : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntBitOr)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6084,7 +6084,7 @@ class MBigIntBitXor : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntBitXor)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6101,7 +6101,7 @@ class MBigIntLsh : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntLsh)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6118,7 +6118,7 @@ class MBigIntRsh : public MBigIntBinaryArithInstruction {
INSTRUCTION_HEADER(BigIntRsh)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6152,7 +6152,7 @@ class MBigIntIncrement : public MBigIntUnaryArithInstruction {
INSTRUCTION_HEADER(BigIntIncrement)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6169,7 +6169,7 @@ class MBigIntDecrement : public MBigIntUnaryArithInstruction {
INSTRUCTION_HEADER(BigIntDecrement)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6186,7 +6186,7 @@ class MBigIntNegate : public MBigIntUnaryArithInstruction {
INSTRUCTION_HEADER(BigIntNegate)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -6203,7 +6203,7 @@ class MBigIntBitNot : public MBigIntUnaryArithInstruction {
INSTRUCTION_HEADER(BigIntBitNot)
TRIVIAL_NEW_WRAPPERS
MOZ_MUST_USE bool writeRecoverData(
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
@ -12611,6 +12611,66 @@ class MCallObjectHasSparseElement
bool possiblyCalls() const override { return true; }
};
// Inline implementation of BigInt.asIntN().
class MBigIntAsIntN
: public MBinaryInstruction,
public MixPolicy<UnboxedInt32Policy<0>, BigIntPolicy<1>>::Data {
MBigIntAsIntN(MDefinition* bits, MDefinition* input)
: MBinaryInstruction(classOpcode, bits, input) {
setResultType(MIRType::BigInt);
setMovable();
}
public:
INSTRUCTION_HEADER(BigIntAsIntN)
TRIVIAL_NEW_WRAPPERS
NAMED_OPERANDS((0, bits), (1, input))
AliasSet getAliasSet() const override { return AliasSet::None(); }
bool congruentTo(const MDefinition* ins) const override {
return congruentIfOperandsEqual(ins);
}
bool possiblyCalls() const override { return true; }
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
ALLOW_CLONE(MBigIntAsIntN)
};
// Inline implementation of BigInt.asUintN().
class MBigIntAsUintN
: public MBinaryInstruction,
public MixPolicy<UnboxedInt32Policy<0>, BigIntPolicy<1>>::Data {
MBigIntAsUintN(MDefinition* bits, MDefinition* input)
: MBinaryInstruction(classOpcode, bits, input) {
setResultType(MIRType::BigInt);
setMovable();
}
public:
INSTRUCTION_HEADER(BigIntAsUintN)
TRIVIAL_NEW_WRAPPERS
NAMED_OPERANDS((0, bits), (1, input))
AliasSet getAliasSet() const override { return AliasSet::None(); }
bool congruentTo(const MDefinition* ins) const override {
return congruentIfOperandsEqual(ins);
}
bool possiblyCalls() const override { return true; }
[[nodiscard]] bool writeRecoverData(
CompactBufferWriter& writer) const override;
bool canRecoverOnBailout() const override { return true; }
ALLOW_CLONE(MBigIntAsUintN)
};
// Flips the input's sign bit, independently of the rest of the number's
// payload. Note this is different from multiplying by minus-one, which has
// side-effects for e.g. NaNs.

Просмотреть файл

@ -18,6 +18,7 @@
#include "jit/MIR.h"
#include "jit/MIRGraph.h"
#include "jit/VMFunctions.h"
#include "vm/BigIntType.h"
#include "vm/Interpreter.h"
#include "vm/Iteration.h"
#include "vm/JSContext.h"
@ -1900,3 +1901,47 @@ bool RAtomicIsLockFree::recover(JSContext* cx, SnapshotIterator& iter) const {
iter.storeInstructionResult(rootedResult);
return true;
}
bool MBigIntAsIntN::writeRecoverData(CompactBufferWriter& writer) const {
MOZ_ASSERT(canRecoverOnBailout());
writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntAsIntN));
return true;
}
RBigIntAsIntN::RBigIntAsIntN(CompactBufferReader& reader) {}
bool RBigIntAsIntN::recover(JSContext* cx, SnapshotIterator& iter) const {
int32_t bits = iter.read().toInt32();
RootedBigInt input(cx, iter.read().toBigInt());
MOZ_ASSERT(bits >= 0);
BigInt* result = BigInt::asIntN(cx, input, bits);
if (!result) {
return false;
}
iter.storeInstructionResult(JS::BigIntValue(result));
return true;
}
bool MBigIntAsUintN::writeRecoverData(CompactBufferWriter& writer) const {
MOZ_ASSERT(canRecoverOnBailout());
writer.writeUnsigned(uint32_t(RInstruction::Recover_BigIntAsUintN));
return true;
}
RBigIntAsUintN::RBigIntAsUintN(CompactBufferReader& reader) {}
bool RBigIntAsUintN::recover(JSContext* cx, SnapshotIterator& iter) const {
int32_t bits = iter.read().toInt32();
RootedBigInt input(cx, iter.read().toBigInt());
MOZ_ASSERT(bits >= 0);
BigInt* result = BigInt::asUintN(cx, input, bits);
if (!result) {
return false;
}
iter.storeInstructionResult(JS::BigIntValue(result));
return true;
}

Просмотреть файл

@ -130,6 +130,8 @@ namespace jit {
_(ArrayState) \
_(SetArrayLength) \
_(AtomicIsLockFree) \
_(BigIntAsIntN) \
_(BigIntAsUintN) \
_(AssertRecoveredOnBailout)
class RResumePoint;
@ -346,120 +348,120 @@ class RBigIntAdd final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntAdd, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntSub final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntSub, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntMul final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntMul, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntDiv final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntDiv, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntMod final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntMod, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntPow final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntPow, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntBitAnd final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntBitAnd, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntBitOr final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntBitOr, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntBitXor final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntBitXor, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntLsh final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntLsh, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntRsh final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntRsh, 2)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntIncrement final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntIncrement, 1)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntDecrement final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntDecrement, 1)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntNegate final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntNegate, 1)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntBitNot final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntBitNot, 1)
MOZ_MUST_USE bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RConcat final : public RInstruction {
@ -852,6 +854,22 @@ class RAtomicIsLockFree final : public RInstruction {
SnapshotIterator& iter) const override;
};
class RBigIntAsIntN final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntAsIntN, 2)
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RBigIntAsUintN final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(BigIntAsUintN, 2)
[[nodiscard]] bool recover(JSContext* cx,
SnapshotIterator& iter) const override;
};
class RAssertRecoveredOnBailout final : public RInstruction {
public:
RINSTRUCTION_HEADER_NUM_OP_(AssertRecoveredOnBailout, 1)

Просмотреть файл

@ -522,6 +522,24 @@ template bool ConvertToStringPolicy<1>::staticAdjustInputs(TempAllocator& alloc,
template bool ConvertToStringPolicy<2>::staticAdjustInputs(TempAllocator& alloc,
MInstruction* ins);
template <unsigned Op>
bool BigIntPolicy<Op>::staticAdjustInputs(TempAllocator& alloc,
MInstruction* ins) {
MDefinition* in = ins->getOperand(Op);
if (in->type() == MIRType::BigInt) {
return true;
}
MUnbox* replace = MUnbox::New(alloc, in, MIRType::BigInt, MUnbox::Fallible);
ins->block()->insertBefore(ins, replace);
ins->replaceOperand(Op, replace);
return replace->typePolicy()->adjustInputs(alloc, replace);
}
template bool BigIntPolicy<1>::staticAdjustInputs(TempAllocator& alloc,
MInstruction* ins);
template <unsigned Op>
bool UnboxedInt32Policy<Op>::staticAdjustInputs(TempAllocator& alloc,
MInstruction* def) {
@ -1204,6 +1222,7 @@ bool TypedArrayIndexPolicy::adjustInputs(TempAllocator& alloc,
_(MixPolicy<BoxPolicy<0>, BoxPolicy<1>>) \
_(MixPolicy<ObjectPolicy<0>, BoxPolicy<2>, ObjectPolicy<3>>) \
_(MixPolicy<BoxExceptPolicy<0, MIRType::Object>, ObjectPolicy<1>>) \
_(MixPolicy<UnboxedInt32Policy<0>, BigIntPolicy<1>>) \
_(NoFloatPolicy<0>) \
_(NoFloatPolicy<1>) \
_(NoFloatPolicy<2>) \

Просмотреть файл

@ -90,8 +90,8 @@ class BigIntArithPolicy final : public TypePolicy {
public:
constexpr BigIntArithPolicy() = default;
EMPTY_DATA_;
MOZ_MUST_USE bool adjustInputs(TempAllocator& alloc,
MInstruction* def) const override;
[[nodiscard]] bool adjustInputs(TempAllocator& alloc,
MInstruction* def) const override;
};
class AllDoublePolicy final : public TypePolicy {
@ -211,6 +211,20 @@ class ConvertToStringPolicy final : public TypePolicy {
}
};
// Expect a BigInt for operand Op. If the input is a Value, it is unboxed.
template <unsigned Op>
class BigIntPolicy final : public TypePolicy {
public:
constexpr BigIntPolicy() = default;
EMPTY_DATA_;
[[nodiscard]] static bool staticAdjustInputs(TempAllocator& alloc,
MInstruction* def);
[[nodiscard]] bool adjustInputs(TempAllocator& alloc,
MInstruction* def) const override {
return staticAdjustInputs(alloc, def);
}
};
// Expects either an Int32 or a boxed Int32 for operand Op; may unbox if needed.
template <unsigned Op>
class UnboxedInt32Policy final : private TypePolicy {

Просмотреть файл

@ -3690,6 +3690,30 @@ bool WarpCacheIRTranspiler::emitAtomicsIsLockFreeResult(
return true;
}
bool WarpCacheIRTranspiler::emitBigIntAsIntNResult(Int32OperandId bitsId,
BigIntOperandId bigIntId) {
MDefinition* bits = getOperand(bitsId);
MDefinition* bigInt = getOperand(bigIntId);
auto* ins = MBigIntAsIntN::New(alloc(), bits, bigInt);
add(ins);
pushResult(ins);
return true;
}
bool WarpCacheIRTranspiler::emitBigIntAsUintNResult(Int32OperandId bitsId,
BigIntOperandId bigIntId) {
MDefinition* bits = getOperand(bitsId);
MDefinition* bigInt = getOperand(bigIntId);
auto* ins = MBigIntAsUintN::New(alloc(), bits, bigInt);
add(ins);
pushResult(ins);
return true;
}
bool WarpCacheIRTranspiler::emitLoadValueTruthyResult(ValOperandId inputId) {
MDefinition* input = getOperand(inputId);

Просмотреть файл

@ -8730,6 +8730,102 @@ class LCallObjectHasSparseElement : public LCallInstructionHelper<1, 2, 2> {
const LDefinition* temp2() { return getTemp(1); }
};
class LBigIntAsIntN : public LCallInstructionHelper<1, 2, 0> {
public:
LIR_HEADER(BigIntAsIntN)
LBigIntAsIntN(const LAllocation& bits, const LAllocation& input)
: LCallInstructionHelper(classOpcode) {
setOperand(0, bits);
setOperand(1, input);
}
const LAllocation* bits() { return getOperand(0); }
const LAllocation* input() { return getOperand(1); }
};
class LBigIntAsIntN64 : public LInstructionHelper<1, 1, 1 + INT64_PIECES> {
public:
LIR_HEADER(BigIntAsIntN64)
LBigIntAsIntN64(const LAllocation& input, const LDefinition& temp,
const LInt64Definition& temp64)
: LInstructionHelper(classOpcode) {
setOperand(0, input);
setTemp(0, temp);
setInt64Temp(1, temp64);
}
const LAllocation* input() { return getOperand(0); }
const LDefinition* temp() { return getTemp(0); }
LInt64Definition temp64() { return getInt64Temp(1); }
};
class LBigIntAsIntN32 : public LInstructionHelper<1, 1, 1 + INT64_PIECES> {
public:
LIR_HEADER(BigIntAsIntN32)
LBigIntAsIntN32(const LAllocation& input, const LDefinition& temp,
const LInt64Definition& temp64)
: LInstructionHelper(classOpcode) {
setOperand(0, input);
setTemp(0, temp);
setInt64Temp(1, temp64);
}
const LAllocation* input() { return getOperand(0); }
const LDefinition* temp() { return getTemp(0); }
LInt64Definition temp64() { return getInt64Temp(1); }
};
class LBigIntAsUintN : public LCallInstructionHelper<1, 2, 0> {
public:
LIR_HEADER(BigIntAsUintN)
LBigIntAsUintN(const LAllocation& bits, const LAllocation& input)
: LCallInstructionHelper(classOpcode) {
setOperand(0, bits);
setOperand(1, input);
}
const LAllocation* bits() { return getOperand(0); }
const LAllocation* input() { return getOperand(1); }
};
class LBigIntAsUintN64 : public LInstructionHelper<1, 1, 1 + INT64_PIECES> {
public:
LIR_HEADER(BigIntAsUintN64)
LBigIntAsUintN64(const LAllocation& input, const LDefinition& temp,
const LInt64Definition& temp64)
: LInstructionHelper(classOpcode) {
setOperand(0, input);
setTemp(0, temp);
setInt64Temp(1, temp64);
}
const LAllocation* input() { return getOperand(0); }
const LDefinition* temp() { return getTemp(0); }
LInt64Definition temp64() { return getInt64Temp(1); }
};
class LBigIntAsUintN32 : public LInstructionHelper<1, 1, 1 + INT64_PIECES> {
public:
LIR_HEADER(BigIntAsUintN32)
LBigIntAsUintN32(const LAllocation& input, const LDefinition& temp,
const LInt64Definition& temp64)
: LInstructionHelper(classOpcode) {
setOperand(0, input);
setTemp(0, temp);
setInt64Temp(1, temp64);
}
const LAllocation* input() { return getOperand(0); }
const LDefinition* temp() { return getTemp(0); }
LInt64Definition temp64() { return getInt64Temp(1); }
};
template <size_t NumDefs>
class LIonToWasmCallBase : public LVariadicInstruction<NumDefs, 2> {
using Base = LVariadicInstruction<NumDefs, 2>;