Debian Codegraph @

js/src/jit-test/tests/atomics/bigint-load.js

raw
1 // |jit-test| test-join=--spectre-mitigations=off
2
3 // These do not test atomicity, just that code generation for BigInt values
4 // works correctly.
5
6 const bigIntValues = [
7 // Definitely heap digits.
8 -(2n ** 2000n),
9 -(2n ** 1000n),
10
11 // -(2n**64n)
12 -18446744073709551617n,
13 -18446744073709551616n,
14 -18446744073709551615n,
15
16 // -(2n**63n)
17 -9223372036854775809n,
18 -9223372036854775808n,
19 -9223372036854775807n,
20
21 // -(2**32)
22 -4294967297n,
23 -4294967296n,
24 -4294967295n,
25
26 // -(2**31)
27 -2147483649n,
28 -2147483648n,
29 -2147483647n,
30
31 -1n,
32 0n,
33 1n,
34
35 // 2**31
36 2147483647n,
37 2147483648n,
38 2147483649n,
39
40 // 2**32
41 4294967295n,
42 4294967296n,
43 4294967297n,
44
45 // 2n**63n
46 9223372036854775807n,
47 9223372036854775808n,
48 9223372036854775809n,
49
50 // 2n**64n
51 18446744073709551615n,
52 18446744073709551616n,
53 18446744073709551617n,
54
55 // Definitely heap digits.
56 2n ** 1000n,
57 2n ** 2000n,
58 ];
59
60 function testLoad() {
61 const int64 = new BigInt64Array(2);
62 const uint64 = new BigUint64Array(2);
63
64 // Test with constant index.
65 for (let i = 0; i < 50; ++i) {
66 for (let j = 0; j < bigIntValues.length; ++j) {
67 let value = bigIntValues[j];
68
69 int64[0] = value;
70 assertEq(Atomics.load(int64, 0), BigInt.asIntN(64, value));
71
72 uint64[0] = value;
73 assertEq(Atomics.load(uint64, 0), BigInt.asUintN(64, value));
74 }
75 }
76
77 // Test with variable index.
78 for (let i = 0; i < 50; ++i) {
79 for (let j = 0; j < bigIntValues.length; ++j) {
80 let value = bigIntValues[j];
81 let idx = j & 1;
82
83 int64[idx] = value;
84 assertEq(Atomics.load(int64, idx), BigInt.asIntN(64, value));
85
86 uint64[idx] = value;
87 assertEq(Atomics.load(uint64, idx), BigInt.asUintN(64, value));
88 }
89 }
90 }
91 for (let i = 0; i < 2; ++i) testLoad();