Commit f5bec4bc authored by binji's avatar binji Committed by Commit bot

[Atomics] Remove support for atomic accesses on floating-point values.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/1318713007

Cr-Commit-Position: refs/heads/master@{#30755}
parent f44efd6b
...@@ -24,12 +24,6 @@ utils.Import(function(from) { ...@@ -24,12 +24,6 @@ utils.Import(function(from) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function CheckSharedTypedArray(sta) {
if (!%IsSharedTypedArray(sta)) {
throw MakeTypeError(kNotSharedTypedArray, sta);
}
}
function CheckSharedIntegerTypedArray(ia) { function CheckSharedIntegerTypedArray(ia) {
if (!%IsSharedIntegerTypedArray(ia)) { if (!%IsSharedIntegerTypedArray(ia)) {
throw MakeTypeError(kNotIntegerSharedTypedArray, ia); throw MakeTypeError(kNotIntegerSharedTypedArray, ia);
...@@ -46,7 +40,7 @@ function CheckSharedInteger32TypedArray(ia) { ...@@ -46,7 +40,7 @@ function CheckSharedInteger32TypedArray(ia) {
//------------------------------------------------------------------- //-------------------------------------------------------------------
function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
CheckSharedTypedArray(sta); CheckSharedIntegerTypedArray(sta);
index = $toInteger(index); index = $toInteger(index);
if (index < 0 || index >= %_TypedArrayGetLength(sta)) { if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
return UNDEFINED; return UNDEFINED;
...@@ -57,7 +51,7 @@ function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) { ...@@ -57,7 +51,7 @@ function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
} }
function AtomicsLoadJS(sta, index) { function AtomicsLoadJS(sta, index) {
CheckSharedTypedArray(sta); CheckSharedIntegerTypedArray(sta);
index = $toInteger(index); index = $toInteger(index);
if (index < 0 || index >= %_TypedArrayGetLength(sta)) { if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
return UNDEFINED; return UNDEFINED;
...@@ -66,7 +60,7 @@ function AtomicsLoadJS(sta, index) { ...@@ -66,7 +60,7 @@ function AtomicsLoadJS(sta, index) {
} }
function AtomicsStoreJS(sta, index, value) { function AtomicsStoreJS(sta, index, value) {
CheckSharedTypedArray(sta); CheckSharedIntegerTypedArray(sta);
index = $toInteger(index); index = $toInteger(index);
if (index < 0 || index >= %_TypedArrayGetLength(sta)) { if (index < 0 || index >= %_TypedArrayGetLength(sta)) {
return UNDEFINED; return UNDEFINED;
......
This diff is collapsed.
...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) { ...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) {
var MEMU8 = new stdlib.Uint8Array(heap); var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap); var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap); var MEMU32 = new stdlib.Uint32Array(heap);
var MEMF32 = new stdlib.Float32Array(heap);
var MEMF64 = new stdlib.Float64Array(heap);
var compareExchange = stdlib.Atomics.compareExchange; var compareExchange = stdlib.Atomics.compareExchange;
var fround = stdlib.Math.fround; var fround = stdlib.Math.fround;
...@@ -59,20 +57,6 @@ function Module(stdlib, foreign, heap) { ...@@ -59,20 +57,6 @@ function Module(stdlib, foreign, heap) {
return compareExchange(MEMU32, i, o, n)>>>0; return compareExchange(MEMU32, i, o, n)>>>0;
} }
function compareExchangef32(i, o, n) {
i = i | 0;
o = fround(o);
n = fround(n);
return fround(compareExchange(MEMF32, i, o, n));
}
function compareExchangef64(i, o, n) {
i = i | 0;
o = +o;
n = +n;
return +compareExchange(MEMF64, i, o, n);
}
return { return {
compareExchangei8: compareExchangei8, compareExchangei8: compareExchangei8,
compareExchangei16: compareExchangei16, compareExchangei16: compareExchangei16,
...@@ -80,8 +64,6 @@ function Module(stdlib, foreign, heap) { ...@@ -80,8 +64,6 @@ function Module(stdlib, foreign, heap) {
compareExchangeu8: compareExchangeu8, compareExchangeu8: compareExchangeu8,
compareExchangeu16: compareExchangeu16, compareExchangeu16: compareExchangeu16,
compareExchangeu32: compareExchangeu32, compareExchangeu32: compareExchangeu32,
compareExchangef32: compareExchangef32,
compareExchangef64: compareExchangef64
}; };
} }
...@@ -117,5 +99,3 @@ testElementType(Int32Array, m.compareExchangei32, 0); ...@@ -117,5 +99,3 @@ testElementType(Int32Array, m.compareExchangei32, 0);
testElementType(Uint8Array, m.compareExchangeu8, 0); testElementType(Uint8Array, m.compareExchangeu8, 0);
testElementType(Uint16Array, m.compareExchangeu16, 0); testElementType(Uint16Array, m.compareExchangeu16, 0);
testElementType(Uint32Array, m.compareExchangeu32, 0); testElementType(Uint32Array, m.compareExchangeu32, 0);
testElementType(Float32Array, m.compareExchangef32, NaN);
testElementType(Float64Array, m.compareExchangef64, NaN);
...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) { ...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) {
var MEMU8 = new stdlib.Uint8Array(heap); var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap); var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap); var MEMU32 = new stdlib.Uint32Array(heap);
var MEMF32 = new stdlib.Float32Array(heap);
var MEMF64 = new stdlib.Float64Array(heap);
var load = stdlib.Atomics.load; var load = stdlib.Atomics.load;
var fround = stdlib.Math.fround; var fround = stdlib.Math.fround;
...@@ -47,16 +45,6 @@ function Module(stdlib, foreign, heap) { ...@@ -47,16 +45,6 @@ function Module(stdlib, foreign, heap) {
return load(MEMU32, i)>>>0; return load(MEMU32, i)>>>0;
} }
function loadf32(i) {
i = i | 0;
return fround(load(MEMF32, i));
}
function loadf64(i) {
i = i | 0;
return +load(MEMF64, i);
}
return { return {
loadi8: loadi8, loadi8: loadi8,
loadi16: loadi16, loadi16: loadi16,
...@@ -64,8 +52,6 @@ function Module(stdlib, foreign, heap) { ...@@ -64,8 +52,6 @@ function Module(stdlib, foreign, heap) {
loadu8: loadu8, loadu8: loadu8,
loadu16: loadu16, loadu16: loadu16,
loadu32: loadu32, loadu32: loadu32,
loadf32: loadf32,
loadf64: loadf64
}; };
} }
...@@ -98,5 +84,3 @@ testElementType(Int32Array, m.loadi32, 0); ...@@ -98,5 +84,3 @@ testElementType(Int32Array, m.loadi32, 0);
testElementType(Uint8Array, m.loadu8, 0); testElementType(Uint8Array, m.loadu8, 0);
testElementType(Uint16Array, m.loadu16, 0); testElementType(Uint16Array, m.loadu16, 0);
testElementType(Uint32Array, m.loadu32, 0); testElementType(Uint32Array, m.loadu32, 0);
testElementType(Float32Array, m.loadf32, NaN);
testElementType(Float64Array, m.loadf64, NaN);
...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) { ...@@ -12,8 +12,6 @@ function Module(stdlib, foreign, heap) {
var MEMU8 = new stdlib.Uint8Array(heap); var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap); var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap); var MEMU32 = new stdlib.Uint32Array(heap);
var MEMF32 = new stdlib.Float32Array(heap);
var MEMF64 = new stdlib.Float64Array(heap);
var store = stdlib.Atomics.store; var store = stdlib.Atomics.store;
var fround = stdlib.Math.fround; var fround = stdlib.Math.fround;
...@@ -53,18 +51,6 @@ function Module(stdlib, foreign, heap) { ...@@ -53,18 +51,6 @@ function Module(stdlib, foreign, heap) {
return store(MEMU32, i, x)>>>0; return store(MEMU32, i, x)>>>0;
} }
function storef32(i, x) {
i = i | 0;
x = fround(x);
return fround(store(MEMF32, i, x));
}
function storef64(i, x) {
i = i | 0;
x = +x;
return +store(MEMF64, i, x);
}
return { return {
storei8: storei8, storei8: storei8,
storei16: storei16, storei16: storei16,
...@@ -72,8 +58,6 @@ function Module(stdlib, foreign, heap) { ...@@ -72,8 +58,6 @@ function Module(stdlib, foreign, heap) {
storeu8: storeu8, storeu8: storeu8,
storeu16: storeu16, storeu16: storeu16,
storeu32: storeu32, storeu32: storeu32,
storef32: storef32,
storef64: storef64
}; };
} }
...@@ -105,5 +89,3 @@ testElementType(Int32Array, m.storei32, 0); ...@@ -105,5 +89,3 @@ testElementType(Int32Array, m.storei32, 0);
testElementType(Uint8Array, m.storeu8, 0); testElementType(Uint8Array, m.storeu8, 0);
testElementType(Uint16Array, m.storeu16, 0); testElementType(Uint16Array, m.storeu16, 0);
testElementType(Uint32Array, m.storeu32, 0); testElementType(Uint32Array, m.storeu32, 0);
testElementType(Float32Array, m.storef32, NaN);
testElementType(Float64Array, m.storef64, NaN);
...@@ -38,11 +38,6 @@ var IntegerTypedArrayConstructors = [ ...@@ -38,11 +38,6 @@ var IntegerTypedArrayConstructors = [
makeConstructorObject(Uint32Array, 0, 0xffffffff, toRangeWrapped), makeConstructorObject(Uint32Array, 0, 0xffffffff, toRangeWrapped),
]; ];
var TypedArrayConstructors = IntegerTypedArrayConstructors.concat([
{constr: Float32Array},
{constr: Float64Array},
]);
(function TestBadArray() { (function TestBadArray() {
var ab = new ArrayBuffer(16); var ab = new ArrayBuffer(16);
var u32a = new Uint32Array(16); var u32a = new Uint32Array(16);
...@@ -50,8 +45,8 @@ var TypedArrayConstructors = IntegerTypedArrayConstructors.concat([ ...@@ -50,8 +45,8 @@ var TypedArrayConstructors = IntegerTypedArrayConstructors.concat([
var sf32a = new Float32Array(sab); var sf32a = new Float32Array(sab);
var sf64a = new Float64Array(sab); var sf64a = new Float64Array(sab);
// Atomic ops required shared typed arrays // Atomic ops required integer shared typed arrays
[undefined, 1, 'hi', 3.4, ab, u32a, sab].forEach(function(o) { [undefined, 1, 'hi', 3.4, ab, u32a, sab, sf32a, sf64a].forEach(function(o) {
assertThrows(function() { Atomics.compareExchange(o, 0, 0, 0); }, assertThrows(function() { Atomics.compareExchange(o, 0, 0, 0); },
TypeError); TypeError);
assertThrows(function() { Atomics.load(o, 0); }, TypeError); assertThrows(function() { Atomics.load(o, 0); }, TypeError);
...@@ -63,16 +58,6 @@ var TypedArrayConstructors = IntegerTypedArrayConstructors.concat([ ...@@ -63,16 +58,6 @@ var TypedArrayConstructors = IntegerTypedArrayConstructors.concat([
assertThrows(function() { Atomics.xor(o, 0, 0); }, TypeError); assertThrows(function() { Atomics.xor(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.exchange(o, 0, 0); }, TypeError); assertThrows(function() { Atomics.exchange(o, 0, 0); }, TypeError);
}); });
// Arithmetic atomic ops require integer shared arrays
[sab, sf32a, sf64a].forEach(function(o) {
assertThrows(function() { Atomics.add(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.sub(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.and(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.or(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.xor(o, 0, 0); }, TypeError);
assertThrows(function() { Atomics.exchange(o, 0, 0); }, TypeError);
});
})(); })();
function testAtomicOp(op, ia, index, expectedIndex, name) { function testAtomicOp(op, ia, index, expectedIndex, name) {
...@@ -163,7 +148,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) { ...@@ -163,7 +148,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
})(); })();
(function TestCompareExchange() { (function TestCompareExchange() {
TypedArrayConstructors.forEach(function(t) { IntegerTypedArrayConstructors.forEach(function(t) {
var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT); var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT);
var sta = new t.constr(sab); var sta = new t.constr(sab);
var name = Object.prototype.toString.call(sta); var name = Object.prototype.toString.call(sta);
...@@ -177,32 +162,10 @@ function testAtomicOp(op, ia, index, expectedIndex, name) { ...@@ -177,32 +162,10 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
assertEquals(50, sta[i], name); assertEquals(50, sta[i], name);
} }
}); });
// * Exact float values should be OK
// * Infinity, -Infinity should be OK (has exact representation)
// * NaN is not OK, it has many representations, cannot ensure successful CAS
// because it does a bitwise compare
[1.5, 4.25, -1e8, -Infinity, Infinity].forEach(function(v) {
var sab = new SharedArrayBuffer(10 * Float32Array.BYTES_PER_ELEMENT);
var sf32a = new Float32Array(sab);
sf32a[0] = 0;
assertEquals(0, Atomics.compareExchange(sf32a, 0, 0, v));
assertEquals(v, sf32a[0]);
assertEquals(v, Atomics.compareExchange(sf32a, 0, v, 0));
assertEquals(0, sf32a[0]);
var sab2 = new SharedArrayBuffer(10 * Float64Array.BYTES_PER_ELEMENT);
var sf64a = new Float64Array(sab2);
sf64a[0] = 0;
assertEquals(0, Atomics.compareExchange(sf64a, 0, 0, v));
assertEquals(v, sf64a[0]);
assertEquals(v, Atomics.compareExchange(sf64a, 0, v, 0));
assertEquals(0, sf64a[0]);
});
})(); })();
(function TestLoad() { (function TestLoad() {
TypedArrayConstructors.forEach(function(t) { IntegerTypedArrayConstructors.forEach(function(t) {
var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT); var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT);
var sta = new t.constr(sab); var sta = new t.constr(sab);
var name = Object.prototype.toString.call(sta); var name = Object.prototype.toString.call(sta);
...@@ -216,7 +179,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) { ...@@ -216,7 +179,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
})(); })();
(function TestStore() { (function TestStore() {
TypedArrayConstructors.forEach(function(t) { IntegerTypedArrayConstructors.forEach(function(t) {
var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT); var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT);
var sta = new t.constr(sab); var sta = new t.constr(sab);
var name = Object.prototype.toString.call(sta); var name = Object.prototype.toString.call(sta);
...@@ -228,20 +191,6 @@ function testAtomicOp(op, ia, index, expectedIndex, name) { ...@@ -228,20 +191,6 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
assertEquals(100, sta[i], name); assertEquals(100, sta[i], name);
} }
}); });
[1.5, 4.25, -1e8, -Infinity, Infinity, NaN].forEach(function(v) {
var sab = new SharedArrayBuffer(10 * Float32Array.BYTES_PER_ELEMENT);
var sf32a = new Float32Array(sab);
sf32a[0] = 0;
assertEquals(v, Atomics.store(sf32a, 0, v));
assertEquals(v, sf32a[0]);
var sab2 = new SharedArrayBuffer(10 * Float64Array.BYTES_PER_ELEMENT);
var sf64a = new Float64Array(sab2);
sf64a[0] = 0;
assertEquals(v, Atomics.store(sf64a, 0, v));
assertEquals(v, sf64a[0]);
});
})(); })();
(function TestAdd() { (function TestAdd() {
...@@ -348,7 +297,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) { ...@@ -348,7 +297,7 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
// Sizes that aren't equal to a typedarray BYTES_PER_ELEMENT always return // Sizes that aren't equal to a typedarray BYTES_PER_ELEMENT always return
// false. // false.
var validSizes = {}; var validSizes = {};
TypedArrayConstructors.forEach(function(t) { IntegerTypedArrayConstructors.forEach(function(t) {
validSizes[t.constr.BYTES_PER_ELEMENT] = true; validSizes[t.constr.BYTES_PER_ELEMENT] = true;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment