| 1 |
// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics |
| 2 |
// Copyright (C) 2018 Rick Waldron. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
/*--- |
| 5 |
esid: sec-atomics.sub |
| 6 |
description: Test Atomics.sub on arrays that allow atomic operations |
| 7 |
includes: [testAtomics.js, testBigIntTypedArray.js] |
| 8 |
features: [ArrayBuffer, Atomics, BigInt, DataView, SharedArrayBuffer, Symbol, TypedArray] |
| 9 |
---*/ |
| 10 |
// Make it interesting - use non-zero byteOffsets and non-zero indexes. |
| 11 |
// In-bounds boundary cases for indexing |
| 12 |
// Atomics.store() computes an index from Idx in the same way as other |
| 13 |
// Atomics operations, not quite like view[Idx]. |
| 14 |
const sab = new SharedArrayBuffer(1024); |
| 15 |
const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2); |
| 16 |
|
| 17 |
testWithBigIntTypedArrayConstructors(function(TA) { |
| 18 |
const view = new TA(sab, 32, 20); |
| 19 |
const control = new TA(ab, 0, 2); |
| 20 |
view[8] = 100n; |
| 21 |
assert.sameValue(Atomics.sub(view, 8, 10n), 100n, 'Atomics.sub(view, 8, 10n) returns 100n'); |
| 22 |
assert.sameValue(view[8], 90n, 'The value of view[8] is 90n'); |
| 23 |
assert.sameValue(Atomics.sub(view, 8, -5n), 90n, 'Atomics.sub(view, 8, -5n) returns 90n'); |
| 24 |
assert.sameValue(view[8], 95n, 'The value of view[8] is 95'); |
| 25 |
view[3] = -5n; |
| 26 |
control[0] = -5n; |
| 27 |
|
| 28 |
assert.sameValue( |
| 29 |
Atomics.sub(view, 3, 0n), |
| 30 |
control[0], |
| 31 |
'Atomics.sub(view, 3, 0n) returns the value of `control[0]` (-5n)' |
| 32 |
); |
| 33 |
|
| 34 |
control[0] = 12345n; |
| 35 |
view[3] = 12345n; |
| 36 |
|
| 37 |
assert.sameValue( |
| 38 |
Atomics.sub(view, 3, 0n), |
| 39 |
control[0], |
| 40 |
'Atomics.sub(view, 3, 0n) returns the value of `control[0]` (12345n)' |
| 41 |
); |
| 42 |
|
| 43 |
control[0] = 123456789n; |
| 44 |
view[3] = 123456789n; |
| 45 |
|
| 46 |
assert.sameValue( |
| 47 |
Atomics.sub(view, 3, 0n), |
| 48 |
control[0], |
| 49 |
'Atomics.sub(view, 3, 0n) returns the value of `control[0]` (123456789n)' |
| 50 |
); |
| 51 |
|
| 52 |
testWithAtomicsInBoundsIndices(function(IdxGen) { |
| 53 |
let Idx = IdxGen(view); |
| 54 |
view.fill(0n); |
| 55 |
Atomics.store(view, Idx, 37n); |
| 56 |
assert.sameValue(Atomics.sub(view, Idx, 0n), 37n, 'Atomics.sub(view, Idx, 0n) returns 37n'); |
| 57 |
}); |
| 58 |
}); |
| 59 |
|
| 60 |
reportCompare(0, 0); |