Commit 81fe5b3c authored by pan.deng's avatar pan.deng Committed by Commit bot

Support SAB atomics for offset-TypedArray

BUG=497295
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#32064}
parent 8e5840e1
......@@ -444,18 +444,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsCompareExchange) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoCompareExchange<ctype>(isolate, buffer, index, oldobj, newobj);
return DoCompareExchange<ctype>(isolate, source, index, oldobj, newobj);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoCompareExchangeUint8Clamped(isolate, buffer, index, oldobj,
return DoCompareExchangeUint8Clamped(isolate, source, index, oldobj,
newobj);
default:
......@@ -475,18 +476,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsLoad) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoLoad<ctype>(isolate, buffer, index);
return DoLoad<ctype>(isolate, source, index);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoLoad<uint8_t>(isolate, buffer, index);
return DoLoad<uint8_t>(isolate, source, index);
default:
break;
......@@ -506,18 +508,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsStore) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoStore<ctype>(isolate, buffer, index, value);
return DoStore<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoStoreUint8Clamped(isolate, buffer, index, value);
return DoStoreUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -537,18 +540,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsAdd) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoAdd<ctype>(isolate, buffer, index, value);
return DoAdd<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoAddUint8Clamped(isolate, buffer, index, value);
return DoAddUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -568,18 +572,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsSub) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoSub<ctype>(isolate, buffer, index, value);
return DoSub<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoSubUint8Clamped(isolate, buffer, index, value);
return DoSubUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -599,18 +604,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsAnd) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoAnd<ctype>(isolate, buffer, index, value);
return DoAnd<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoAndUint8Clamped(isolate, buffer, index, value);
return DoAndUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -630,18 +636,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsOr) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoOr<ctype>(isolate, buffer, index, value);
return DoOr<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoOrUint8Clamped(isolate, buffer, index, value);
return DoOrUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -661,18 +668,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsXor) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoXor<ctype>(isolate, buffer, index, value);
return DoXor<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoXorUint8Clamped(isolate, buffer, index, value);
return DoXorUint8Clamped(isolate, source, index, value);
default:
break;
......@@ -692,18 +700,19 @@ RUNTIME_FUNCTION(Runtime_AtomicsExchange) {
RUNTIME_ASSERT(sta->GetBuffer()->is_shared());
RUNTIME_ASSERT(index < NumberToSize(isolate, sta->length()));
void* buffer = sta->GetBuffer()->backing_store();
uint8_t* source = static_cast<uint8_t*>(sta->GetBuffer()->backing_store()) +
NumberToSize(isolate, sta->byte_offset());
switch (sta->type()) {
#define TYPED_ARRAY_CASE(Type, typeName, TYPE, ctype, size) \
case kExternal##Type##Array: \
return DoExchange<ctype>(isolate, buffer, index, value);
return DoExchange<ctype>(isolate, source, index, value);
INTEGER_TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
case kExternalUint8ClampedArray:
return DoExchangeUint8Clamped(isolate, buffer, index, value);
return DoExchangeUint8Clamped(isolate, source, index, value);
default:
break;
......
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var add = stdlib.Atomics.add;
var fround = stdlib.Math.fround;
......@@ -61,9 +61,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -71,10 +68,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
assertEquals(0, f(0, 10), name);
assertEquals(10, ta[0]);
......@@ -85,9 +82,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.addi8);
testElementType(Int16Array, m.addi16);
testElementType(Int32Array, m.addi32);
testElementType(Uint8Array, m.addu8);
testElementType(Uint16Array, m.addu16);
testElementType(Uint32Array, m.addu32);
function testElement(m, offset) {
testElementType(Int8Array, m.addi8, offset);
testElementType(Int16Array, m.addi16, offset);
testElementType(Int32Array, m.addi32, offset);
testElementType(Uint8Array, m.addu8, offset);
testElementType(Uint16Array, m.addu16, offset);
testElementType(Uint32Array, m.addu32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var and = stdlib.Atomics.and;
var fround = stdlib.Math.fround;
......@@ -61,9 +61,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -71,10 +68,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
ta[0] = 0x7f;
assertEquals(0x7f, f(0, 0xf), name);
......@@ -86,9 +83,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.andi8);
testElementType(Int16Array, m.andi16);
testElementType(Int32Array, m.andi32);
testElementType(Uint8Array, m.andu8);
testElementType(Uint16Array, m.andu16);
testElementType(Uint32Array, m.andu32);
function testElement(m, offset) {
testElementType(Int8Array, m.andi8, offset);
testElementType(Int16Array, m.andi16, offset);
testElementType(Int32Array, m.andi32, offset);
testElementType(Uint8Array, m.andu8, offset);
testElementType(Uint16Array, m.andu16, offset);
testElementType(Uint32Array, m.andu32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var compareExchange = stdlib.Atomics.compareExchange;
var fround = stdlib.Math.fround;
......@@ -67,9 +67,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -77,10 +74,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f, oobValue) {
function testElementType(taConstr, f, oobValue, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
assertEquals(0, ta[0]);
assertEquals(0, f(0, 0, 50), name);
......@@ -93,9 +90,21 @@ function testElementType(taConstr, f, oobValue) {
assertEquals(oobValue, f(ta.length, 0, 0), name);
}
testElementType(Int8Array, m.compareExchangei8, 0);
testElementType(Int16Array, m.compareExchangei16, 0);
testElementType(Int32Array, m.compareExchangei32, 0);
testElementType(Uint8Array, m.compareExchangeu8, 0);
testElementType(Uint16Array, m.compareExchangeu16, 0);
testElementType(Uint32Array, m.compareExchangeu32, 0);
function testElement(m, offset) {
testElementType(Int8Array, m.compareExchangei8, 0, offset);
testElementType(Int16Array, m.compareExchangei16, 0, offset);
testElementType(Int32Array, m.compareExchangei32, 0, offset);
testElementType(Uint8Array, m.compareExchangeu8, 0, offset);
testElementType(Uint16Array, m.compareExchangeu16, 0, offset);
testElementType(Uint32Array, m.compareExchangeu32, 0, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var exchange = stdlib.Atomics.exchange;
var fround = stdlib.Math.fround;
......@@ -71,10 +71,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
ta[0] = 0x7f;
assertEquals(0x7f, f(0, 0xf), name);
......@@ -84,9 +84,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.exchangei8);
testElementType(Int16Array, m.exchangei16);
testElementType(Int32Array, m.exchangei32);
testElementType(Uint8Array, m.exchangeu8);
testElementType(Uint16Array, m.exchangeu16);
testElementType(Uint32Array, m.exchangeu32);
function testElement(m, offset) {
testElementType(Int8Array, m.exchangei8, offset);
testElementType(Int16Array, m.exchangei16, offset);
testElementType(Int32Array, m.exchangei32, offset);
testElementType(Uint8Array, m.exchangeu8, offset);
testElementType(Uint16Array, m.exchangeu16, offset);
testElementType(Uint32Array, m.exchangeu32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var load = stdlib.Atomics.load;
var fround = stdlib.Math.fround;
......@@ -55,9 +55,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -65,10 +62,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f, oobValue) {
function testElementType(taConstr, f, oobValue, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
ta[0] = 10;
assertEquals(10, f(0), name);
......@@ -78,9 +75,21 @@ function testElementType(taConstr, f, oobValue) {
assertEquals(oobValue, f(ta.length), name);
}
testElementType(Int8Array, m.loadi8, 0);
testElementType(Int16Array, m.loadi16, 0);
testElementType(Int32Array, m.loadi32, 0);
testElementType(Uint8Array, m.loadu8, 0);
testElementType(Uint16Array, m.loadu16, 0);
testElementType(Uint32Array, m.loadu32, 0);
function testElement(m, offset) {
testElementType(Int8Array, m.loadi8, 0, offset);
testElementType(Int16Array, m.loadi16, 0, offset);
testElementType(Int32Array, m.loadi32, 0, offset);
testElementType(Uint8Array, m.loadu8, 0, offset);
testElementType(Uint16Array, m.loadu16, 0, offset);
testElementType(Uint32Array, m.loadu32, 0, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var or = stdlib.Atomics.or;
var fround = stdlib.Math.fround;
......@@ -71,10 +71,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
assertEquals(0, f(0, 0xf), name);
assertEquals(0xf, ta[0]);
......@@ -85,9 +85,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.ori8);
testElementType(Int16Array, m.ori16);
testElementType(Int32Array, m.ori32);
testElementType(Uint8Array, m.oru8);
testElementType(Uint16Array, m.oru16);
testElementType(Uint32Array, m.oru32);
function testElement(m, offset) {
testElementType(Int8Array, m.ori8, offset);
testElementType(Int16Array, m.ori16, offset);
testElementType(Int32Array, m.ori32, offset);
testElementType(Uint8Array, m.oru8, offset);
testElementType(Uint16Array, m.oru16, offset);
testElementType(Uint32Array, m.oru32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var store = stdlib.Atomics.store;
var fround = stdlib.Math.fround;
......@@ -61,9 +61,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -71,10 +68,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f, oobValue) {
function testElementType(taConstr, f, oobValue, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
assertEquals(10, f(0, 10), name);
assertEquals(10, ta[0]);
......@@ -83,9 +80,21 @@ function testElementType(taConstr, f, oobValue) {
assertEquals(oobValue, f(ta.length, 0), name);
}
testElementType(Int8Array, m.storei8, 0);
testElementType(Int16Array, m.storei16, 0);
testElementType(Int32Array, m.storei32, 0);
testElementType(Uint8Array, m.storeu8, 0);
testElementType(Uint16Array, m.storeu16, 0);
testElementType(Uint32Array, m.storeu32, 0);
function testElement(m, offset) {
testElementType(Int8Array, m.storei8, 0, offset);
testElementType(Int16Array, m.storei16, 0, offset);
testElementType(Int32Array, m.storei32, 0, offset);
testElementType(Uint8Array, m.storeu8, 0, offset);
testElementType(Uint16Array, m.storeu16, 0, offset);
testElementType(Uint32Array, m.storeu32, 0, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var sub = stdlib.Atomics.sub;
var fround = stdlib.Math.fround;
......@@ -61,9 +61,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -71,10 +68,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
ta[0] = 30;
assertEquals(30, f(0, 10), name);
......@@ -86,9 +83,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.subi8);
testElementType(Int16Array, m.subi16);
testElementType(Int32Array, m.subi32);
testElementType(Uint8Array, m.subu8);
testElementType(Uint16Array, m.subu16);
testElementType(Uint32Array, m.subu32);
function testElement(m, offset) {
testElementType(Int8Array, m.subi8, offset);
testElementType(Int16Array, m.subi16, offset);
testElementType(Int32Array, m.subi32, offset);
testElementType(Uint8Array, m.subu8, offset);
testElementType(Uint16Array, m.subu16, offset);
testElementType(Uint32Array, m.subu32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
......@@ -4,14 +4,14 @@
// Flags: --harmony-sharedarraybuffer
function Module(stdlib, foreign, heap) {
function Module(stdlib, foreign, heap, offset) {
"use asm";
var MEM8 = new stdlib.Int8Array(heap);
var MEM16 = new stdlib.Int16Array(heap);
var MEM32 = new stdlib.Int32Array(heap);
var MEMU8 = new stdlib.Uint8Array(heap);
var MEMU16 = new stdlib.Uint16Array(heap);
var MEMU32 = new stdlib.Uint32Array(heap);
var MEM8 = new stdlib.Int8Array(heap, offset);
var MEM16 = new stdlib.Int16Array(heap, offset);
var MEM32 = new stdlib.Int32Array(heap, offset);
var MEMU8 = new stdlib.Uint8Array(heap, offset);
var MEMU16 = new stdlib.Uint16Array(heap, offset);
var MEMU32 = new stdlib.Uint32Array(heap, offset);
var xor = stdlib.Atomics.xor;
var fround = stdlib.Math.fround;
......@@ -61,9 +61,6 @@ function Module(stdlib, foreign, heap) {
};
}
var sab = new SharedArrayBuffer(16);
var m = Module(this, {}, sab);
function clearArray() {
var ui8 = new Uint8Array(sab);
for (var i = 0; i < sab.byteLength; ++i) {
......@@ -71,10 +68,10 @@ function clearArray() {
}
}
function testElementType(taConstr, f) {
function testElementType(taConstr, f, offset) {
clearArray();
var ta = new taConstr(sab);
var ta = new taConstr(sab, offset);
var name = Object.prototype.toString.call(ta);
assertEquals(0, f(0, 0xf), name);
assertEquals(0xf, ta[0]);
......@@ -85,9 +82,21 @@ function testElementType(taConstr, f) {
assertEquals(0, f(ta.length, 0), name);
}
testElementType(Int8Array, m.xori8);
testElementType(Int16Array, m.xori16);
testElementType(Int32Array, m.xori32);
testElementType(Uint8Array, m.xoru8);
testElementType(Uint16Array, m.xoru16);
testElementType(Uint32Array, m.xoru32);
function testElement(m, offset) {
testElementType(Int8Array, m.xori8, offset);
testElementType(Int16Array, m.xori16, offset);
testElementType(Int32Array, m.xori32, offset);
testElementType(Uint8Array, m.xoru8, offset);
testElementType(Uint16Array, m.xoru16, offset);
testElementType(Uint32Array, m.xoru32, offset);
}
var offset = 0;
var sab = new SharedArrayBuffer(16);
var m1 = Module(this, {}, sab, offset);
testElement(m1, offset);
offset = 32;
sab = new SharedArrayBuffer(64);
var m2 = Module(this, {}, sab, offset);
testElement(m2, offset);
This diff is collapsed.
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