| 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.xor |
| 6 |
description: Test Atomics.xor 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 |
// And again |
| 12 |
// In-bounds boundary cases for indexing |
| 13 |
// Atomics.store() computes an index from Idx in the same way as other |
| 14 |
// Atomics operations, not quite like view[Idx]. |
| 15 |
const sab = new SharedArrayBuffer(1024); |
| 16 |
const ab = new ArrayBuffer(16); |
| 17 |
|
| 18 |
testWithBigIntTypedArrayConstructors(function(TA) { |
| 19 |
const view = new TA(sab, 32, 20); |
| 20 |
const control = new TA(ab, 0, 2); |
| 21 |
view[8] = 0x33333333n; |
| 22 |
control[0] = 0x33333333n; |
| 23 |
|
| 24 |
assert.sameValue( |
| 25 |
Atomics.xor(view, 8, 0x55555555n), |
| 26 |
control[0], |
| 27 |
'Atomics.xor(view, 8, 0x55555555n) returns the value of `control[0]` (0x33333333n)' |
| 28 |
); |
| 29 |
|
| 30 |
control[0] = 0x66666666n; |
| 31 |
|
| 32 |
assert.sameValue( |
| 33 |
view[8], |
| 34 |
control[0], |
| 35 |
'The value of view[8] equals the value of `control[0]` (0x66666666n)' |
| 36 |
); |
| 37 |
|
| 38 |
assert.sameValue( |
| 39 |
Atomics.xor(view, 8, 0xF0F0F0F0n), |
| 40 |
control[0], |
| 41 |
'Atomics.xor(view, 8, 0xF0F0F0F0) returns the value of `control[0]` (0x66666666n)' |
| 42 |
); |
| 43 |
|
| 44 |
control[0] = 0x96969696n; |
| 45 |
|
| 46 |
assert.sameValue( |
| 47 |
view[8], |
| 48 |
control[0], |
| 49 |
'The value of view[8] equals the value of `control[0]` (0x96969696n)' |
| 50 |
); |
| 51 |
|
| 52 |
view[3] = -5n; |
| 53 |
control[0] = -5n; |
| 54 |
|
| 55 |
assert.sameValue( |
| 56 |
Atomics.xor(view, 3, 0n), |
| 57 |
control[0], |
| 58 |
'Atomics.xor(view, 3, 0n) returns the value of `control[0]` (-5n)' |
| 59 |
); |
| 60 |
|
| 61 |
assert.sameValue( |
| 62 |
view[3], |
| 63 |
control[0], |
| 64 |
'The value of view[3] equals the value of `control[0]` (-5n)' |
| 65 |
); |
| 66 |
|
| 67 |
control[0] = 12345n; |
| 68 |
view[3] = 12345n; |
| 69 |
|
| 70 |
assert.sameValue( |
| 71 |
Atomics.xor(view, 3, 0n), |
| 72 |
control[0], |
| 73 |
'Atomics.xor(view, 3, 0n) returns the value of `control[0]` (12345n)' |
| 74 |
); |
| 75 |
|
| 76 |
assert.sameValue( |
| 77 |
view[3], |
| 78 |
control[0], |
| 79 |
'The value of view[3] equals the value of `control[0]` (12345n)' |
| 80 |
); |
| 81 |
|
| 82 |
control[0] = 123456789n; |
| 83 |
view[3] = 123456789n; |
| 84 |
|
| 85 |
assert.sameValue( |
| 86 |
Atomics.xor(view, 3, 0n), |
| 87 |
control[0], |
| 88 |
'Atomics.xor(view, 3, 0n) returns the value of `control[0]` (123456789n)' |
| 89 |
); |
| 90 |
|
| 91 |
assert.sameValue( |
| 92 |
view[3], |
| 93 |
control[0], |
| 94 |
'The value of view[3] equals the value of `control[0]` (123456789n)' |
| 95 |
); |
| 96 |
|
| 97 |
testWithAtomicsInBoundsIndices(function(IdxGen) { |
| 98 |
let Idx = IdxGen(view); |
| 99 |
view.fill(0n); |
| 100 |
Atomics.store(view, Idx, 37n); |
| 101 |
assert.sameValue(Atomics.xor(view, Idx, 0n), 37n, 'Atomics.xor(view, Idx, 0n) returns 37n'); |
| 102 |
}); |
| 103 |
}); |
| 104 |
|
| 105 |
reportCompare(0, 0); |