bigint-and-for-effect.js (2634B)
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 testAnd() { 61 const int64 = new BigInt64Array(2); 62 const uint64 = new BigUint64Array(2); 63 64 const int64All = -1n; 65 const uint64All = 0xffff_ffff_ffff_ffffn; 66 67 // Test with constant index. 68 for (let i = 0; i < 20; ++i) { 69 for (let j = 0; j < bigIntValues.length; ++j) { 70 let value = bigIntValues[j]; 71 72 // x & 0 == 0 73 Atomics.and(int64, 0, value); 74 assertEq(int64[0], 0n); 75 76 Atomics.and(uint64, 0, value); 77 assertEq(uint64[0], 0n); 78 79 // x & -1 == x 80 int64[0] = int64All; 81 Atomics.and(int64, 0, value); 82 assertEq(int64[0], BigInt.asIntN(64, value)); 83 84 uint64[0] = uint64All; 85 Atomics.and(uint64, 0, value); 86 assertEq(uint64[0], BigInt.asUintN(64, value)); 87 88 // 0 & x == 0 89 Atomics.and(int64, 0, 0n); 90 assertEq(int64[0], 0n); 91 92 Atomics.and(uint64, 0, 0n); 93 assertEq(uint64[0], 0n); 94 } 95 } 96 97 // Test with variable index. 98 for (let i = 0; i < 20; ++i) { 99 for (let j = 0; j < bigIntValues.length; ++j) { 100 let value = bigIntValues[j]; 101 let idx = j & 1; 102 103 // x & 0 == 0 104 Atomics.and(int64, idx, value); 105 assertEq(int64[idx], 0n); 106 107 Atomics.and(uint64, idx, value); 108 assertEq(uint64[idx], 0n); 109 110 // x & -1 == x 111 int64[idx] = int64All; 112 Atomics.and(int64, idx, value); 113 assertEq(int64[idx], BigInt.asIntN(64, value)); 114 115 uint64[idx] = uint64All; 116 Atomics.and(uint64, idx, value); 117 assertEq(uint64[idx], BigInt.asUintN(64, value)); 118 119 // 0 & x == 0 120 Atomics.and(int64, idx, 0n); 121 assertEq(int64[idx], 0n); 122 123 Atomics.and(uint64, idx, 0n); 124 assertEq(uint64[idx], 0n); 125 } 126 } 127 } 128 for (let i = 0; i < 2; ++i) testAnd();