mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 18:00:16 +00:00
LibJS+LibCrypto: Use a bitwise approach for BigInt's as*IntN methods
This speeds up expressions such as `BigInt.asIntN(0x4000000000000, 1n)` (#3615). And those involving very large bigints.
This commit is contained in:
parent
92d0cd3c7c
commit
12cbefbee7
Notes:
github-actions[bot]
2025-03-20 08:45:14 +00:00
Author: https://github.com/ttrssreal
Commit: 12cbefbee7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3994
Reviewed-by: https://github.com/gmta ✅
9 changed files with 110 additions and 33 deletions
|
@ -22,12 +22,6 @@ describe("errors", () => {
|
|||
BigInt.asIntN(1, "foo");
|
||||
}).toThrowWithMessage(SyntaxError, "Invalid value for BigInt: foo");
|
||||
});
|
||||
|
||||
test("large allocation", () => {
|
||||
expect(() => {
|
||||
BigInt.asIntN(0x4000000000000, 1n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
});
|
||||
});
|
||||
|
||||
describe("correct behavior", () => {
|
||||
|
@ -82,4 +76,23 @@ describe("correct behavior", () => {
|
|||
expect(BigInt.asIntN(128, -extremelyBigInt)).toBe(99061374399389259395070030194384019691n);
|
||||
expect(BigInt.asIntN(256, -extremelyBigInt)).toBe(-extremelyBigInt);
|
||||
});
|
||||
|
||||
test("large bit values", () => {
|
||||
expect(BigInt.asIntN(0x4000000000000, 1n)).toBe(1n);
|
||||
expect(BigInt.asIntN(0x8ffffffffffff, 1n)).toBe(1n);
|
||||
expect(BigInt.asIntN(2 ** 53 - 1, 2n)).toBe(2n);
|
||||
|
||||
// These incur large intermediate values that 00M. For now, ensure they don't crash
|
||||
expect(() => {
|
||||
BigInt.asIntN(0x4000000000000, -1n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
|
||||
expect(() => {
|
||||
BigInt.asIntN(0x8ffffffffffff, -1n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
|
||||
expect(() => {
|
||||
BigInt.asIntN(2 ** 53 - 1, -2n);
|
||||
}).toThrowWithMessage(InternalError, "Out of memory");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue