Bug 983686 - Parallel fromPar r=shu

This commit is contained in:
Nicholas D. Matsakis 2014-03-14 11:20:44 -04:00
Родитель f7be52658f
Коммит 045dbf4a61
5 изменённых файлов: 94 добавлений и 8 удалений

Просмотреть файл

@ -945,18 +945,21 @@ function TypedArrayMap(a, b) {
// Warning: user exposed!
function TypedArrayMapPar(a, b) {
// Arguments: [depth], func
// Defer to the sequential variant for error cases or
// when not working with typed objects.
if (!IsObject(this) || !ObjectIsTypedObject(this))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
return callFunction(TypedArrayMap, this, a, b);
var thisType = TYPEDOBJ_TYPE_DESCR(this);
if (!TypeDescrIsArrayType(thisType))
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
return callFunction(TypedArrayMap, this, a, b);
// Arguments: [depth], func
if (typeof a === "number" && typeof b === "function")
if (typeof a === "number" && IsCallable(b))
return MapTypedParImpl(this, a, thisType, b);
else if (typeof a === "function")
else if (IsCallable(a))
return MapTypedParImpl(this, 1, thisType, a);
return ThrowError(JSMSG_TYPEDOBJECT_BAD_ARGS);
return callFunction(TypedArrayMap, this, a, b);
}
// Warning: user exposed!
@ -1017,6 +1020,20 @@ function TypedObjectArrayTypeBuildPar(a,b,c) {
// Warning: user exposed!
function TypedObjectArrayTypeFromPar(a,b,c) {
// Arguments: arrayLike, [depth], func
// Use the sequential version for error cases or when arrayLike is
// not a typed object.
if (!IsObject(this) || !ObjectIsTypeDescr(this) || !TypeDescrIsArrayType(this))
return callFunction(TypedObjectArrayTypeFrom, this, a, b, c);
if (!IsObject(a) || !ObjectIsTypedObject(a))
return callFunction(TypedObjectArrayTypeFrom, this, a, b, c);
// Detect whether an explicit depth is supplied.
if (typeof b === "number" && IsCallable(c))
return MapTypedParImpl(a, b, this, c);
if (IsCallable(b))
return MapTypedParImpl(a, 1, this, b);
return callFunction(TypedObjectArrayTypeFrom, this, a, b, c);
}
@ -1355,6 +1372,10 @@ function MapTypedParImpl(inArray, depth, outputType, func) {
"Map/From called on non-object or untyped input array.");
assert(TypeDescrIsArrayType(outputType),
"Map/From called on non array-type outputType");
assert(typeof depth === "number",
"Map/From called with non-numeric depth");
assert(IsCallable(func),
"Map/From called on something not callable");
var inArrayType = TypeOfTypedObject(inArray);

Просмотреть файл

@ -0,0 +1,36 @@
// Test basic fromPar parallel execution using an out
// pointer to generate a struct return.
if (!getBuildConfiguration().parallelJS)
quit();
load(libdir + "parallelarray-helpers.js")
var { ArrayType, StructType, uint32 } = TypedObject;
function test() {
var L = minItemsTestingThreshold;
var Matrix = uint32.array(L, 2);
var matrix = new Matrix();
for (var i = 0; i < L; i++)
matrix[i][0] = i;
var Point = new StructType({x: uint32, y: uint32});
var Points = Point.array();
assertParallelExecSucceeds(
// FIXME Bug 983692 -- no where to pass `m` to
function(m) Points.fromPar(matrix, function(p, i, c, out) { out.y = p[0]; }),
function(points) {
for (var i = 0; i < L; i++) {
assertEq(matrix[i][0], i);
assertEq(matrix[i][1], 0);
assertEq(points[i].x, 0);
assertEq(points[i].y, i);
}
});
}
test();

Просмотреть файл

@ -0,0 +1,27 @@
// Test basic fromPar parallel execution using a scalar return value.
if (!getBuildConfiguration().parallelJS)
quit();
load(libdir + "parallelarray-helpers.js")
var { uint8, uint32 } = TypedObject;
function test() {
var L = minItemsTestingThreshold;
var Uints = uint32.array(L);
var Uint8s = uint8.array();
var uint32s = new Uints();
assertParallelExecSucceeds(
// FIXME Bug 983692 -- no where to pass `m` to
function(m) Uint8s.fromPar(uint32s, function(e) e + 1),
function(uint8s) {
for (var i = 0; i < L; i++)
assertEq((uint32s[i] + 1) & 0xFF, uint8s[i]);
});
}
test();

Просмотреть файл

@ -17,7 +17,8 @@ function test() {
points[i].x = i;
assertParallelExecSucceeds(
function() points.mapPar(function(p, i, c, out) { out.y = p.x; }),
// FIXME Bug 983692 -- no where to pass `m` to
function(m) points.mapPar(function(p, i, c, out) { out.y = p.x; }),
function(points2) {
for (var i = 0; i < L; i++) {
assertEq(points[i].x, i);

Просмотреть файл

@ -12,7 +12,8 @@ function test() {
var Uints = uint32.array(L);
var uints1 = new Uints();
assertParallelExecSucceeds(
function() uints1.mapPar(function(e) e + 1),
// FIXME Bug 983692 -- no where to pass `m` to
function(m) uints1.mapPar(function(e) e + 1),
function(uints2) {
for (var i = 0; i < L; i++)
assertEq(uints1[i] + 1, uints2[i]);