Bug 961821: tests for jit-support for writes into TypedObject arrays (r=pnkfelix).

These iteration counts were selected to be close to the minimum number
necessary to expose bugs while working on this patch (see comments in
Bug 961821 for more details here).  Note that they are all 500
iterations (not 5000); please be wary of reducing the iteration count
further without first ensuring that the jit has time to compile this
code.
This commit is contained in:
Felix S. Klock II 2014-01-30 17:47:14 +01:00
Родитель fba7012b6a
Коммит c200f20793
6 изменённых файлов: 204 добавлений и 0 удалений

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

@ -0,0 +1,43 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var PointType = TypedObject.uint16.array(3);
var VecPointType = PointType.array(3);
function foo() {
for (var i = 0; i < 5000; i += 10) {
var vec = new VecPointType();
var i0 = i % 3;
var i1 = (i+1) % 3;
var i2 = (i+2) % 3;
vec[i0][i0] = i;
vec[i0][i1] = i+1;
vec[i0][i2] = i+2;
vec[i1][i0] = i+3;
vec[i1][i1] = i+4;
vec[i1][i2] = i+5;
vec[i2][i0] = i+6;
vec[i2][i1] = i+7;
vec[i2][i2] = i+8;
var sum = vec[i0][i0] + vec[i0][i1] + vec[i0][i2];
assertEq(sum, 3*i + 3);
sum = vec[i1][i0] + vec[i1][i1] + vec[i1][i2];
assertEq(sum, 3*i + 12);
sum = vec[i2][i0] + vec[i2][i1] + vec[i2][i2];
assertEq(sum, 3*i + 21);
}
}
foo();

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

@ -0,0 +1,34 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var Vec3u16Type = TypedObject.uint16.array(3);
var PairVec3u16Type = new TypedObject.StructType({fst: Vec3u16Type,
snd: Vec3u16Type});
function foo_u16() {
for (var i = 0; i < 5000; i += 10) {
var p = new PairVec3u16Type();
p.fst[(i) % 3] = i;
p.fst[(i+1) % 3] = i+1;
p.fst[(i+2) % 3] = i+2;
p.snd[(i) % 3] = i+3;
p.snd[(i+1) % 3] = i+4;
p.snd[(i+2) % 3] = i+5;
var sum = p.fst[0] + p.fst[1] + p.fst[2];
assertEq(sum, 3*i + 3);
sum = p.snd[0] + p.snd[1] + p.snd[2];
assertEq(sum, 3*i + 12);
}
}
foo_u16();

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

@ -0,0 +1,25 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var Vec3u16Type = TypedObject.uint16.array(3);
function foo_u16() {
for (var i = 0; i < 5000; i += 10) {
var vec = new Vec3u16Type();
// making index non-trivially dependent on |i| to foil compiler optimization
vec[(i) % 3] = i;
vec[(i + 1) % 3] = i+1;
vec[(i + 2) % 3] = i+2;
var sum = vec[0] + vec[1] + vec[2];
assertEq(sum, 3*i + 3);
}
}
foo_u16();

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

@ -0,0 +1,43 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var PointType = TypedObject.uint32.array(3);
var VecPointType = PointType.array(3);
function foo() {
for (var i = 0; i < 5000; i += 10) {
var vec = new VecPointType();
var i0 = i % 3;
var i1 = (i+1) % 3;
var i2 = (i+2) % 3;
vec[i0][i0] = i;
vec[i0][i1] = i+1;
vec[i0][i2] = i+2;
vec[i1][i0] = i+3;
vec[i1][i1] = i+4;
vec[i1][i2] = i+5;
vec[i2][i0] = i+6;
vec[i2][i1] = i+7;
vec[i2][i2] = i+8;
var sum = vec[i0][i0] + vec[i0][i1] + vec[i0][i2];
assertEq(sum, 3*i + 3);
sum = vec[i1][i0] + vec[i1][i1] + vec[i1][i2];
assertEq(sum, 3*i + 12);
sum = vec[i2][i0] + vec[i2][i1] + vec[i2][i2];
assertEq(sum, 3*i + 21);
}
}
foo();

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

@ -0,0 +1,34 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var Vec3u32Type = TypedObject.uint32.array(3);
var PairVec3u32Type = new TypedObject.StructType({fst: Vec3u32Type,
snd: Vec3u32Type});
function foo_u32() {
for (var i = 0; i < 5000; i += 10) {
var p = new PairVec3u32Type();
p.fst[(i) % 3] = i;
p.fst[(i+1) % 3] = i+1;
p.fst[(i+2) % 3] = i+2;
p.snd[(i) % 3] = i+3;
p.snd[(i+1) % 3] = i+4;
p.snd[(i+2) % 3] = i+5;
var sum = p.fst[0] + p.fst[1] + p.fst[2];
assertEq(sum, 3*i + 3);
sum = p.snd[0] + p.snd[1] + p.snd[2];
assertEq(sum, 3*i + 12);
}
}
foo_u32();

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

@ -0,0 +1,25 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
setJitCompilerOption("ion.usecount.trigger", 30);
var Vec3u32Type = TypedObject.uint32.array(3);
function foo_u32() {
for (var i = 0; i < 5000; i += 10) {
var vec = new Vec3u32Type();
// making index non-trivially dependent on |i| to foil compiler optimization
vec[(i) % 3] = i;
vec[(i + 1) % 3] = i+1;
vec[(i + 2) % 3] = i+2;
var sum = vec[0] + vec[1] + vec[2];
assertEq(sum, 3*i + 3);
}
}
foo_u32();