Debian Codegraph @

js/src/jit-test/tests/atomics/bigint-sub-for-effect.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 testSub() {
61 const int64 = new BigInt64Array(2);
62 const uint64 = new BigUint64Array(2);
63
64 // Test with constant index.
65 for (let i = 0; i < 20; ++i) {
66 for (let j = 0; j < bigIntValues.length; ++j) {
67 let value = bigIntValues[j];
68
69 Atomics.sub(int64, 0, value);
70 assertEq(int64[0], BigInt.asIntN(64, -value));
71
72 Atomics.sub(uint64, 0, value);
73 assertEq(uint64[0], BigInt.asUintN(64, -value));
74
75 Atomics.sub(int64, 0, -value);
76 assertEq(int64[0], 0n);
77
78 Atomics.sub(uint64, 0, -value);
79 assertEq(uint64[0], 0n);
80 }
81 }
82
83 // Test with variable index.
84 for (let i = 0; i < 20; ++i) {
85 for (let j = 0; j < bigIntValues.length; ++j) {
86 let value = bigIntValues[j];
87 let idx = j & 1;
88
89 Atomics.sub(int64, idx, value);
90 assertEq(int64[idx], BigInt.asIntN(64, -value));
91
92 Atomics.sub(uint64, idx, value);
93 assertEq(uint64[idx], BigInt.asUintN(64, -value));
94
95 Atomics.sub(int64, idx, -value);
96 assertEq(int64[idx], 0n);
97
98 Atomics.sub(uint64, idx, -value);
99 assertEq(uint64[idx], 0n);
100 }
101 }
102 }
103 for (let i = 0; i < 2; ++i) testSub();