mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 21:35:39 +00:00
Adding mandelbrot to trace-test
This commit is contained in:
parent
867685a575
commit
e20071bf44
3
js/src/mandelbrot-results.js
Normal file
3
js/src/mandelbrot-results.js
Normal file
File diff suppressed because one or more lines are too long
@ -1552,13 +1552,6 @@ function testHOTLOOPSize() {
|
||||
testHOTLOOPSize.expected = true;
|
||||
test(testHOTLOOPSize);
|
||||
|
||||
function testGlobalProtoAccess() {
|
||||
return "ok";
|
||||
}
|
||||
this.__proto__.a = 3; for (var j = 0; j < 4; ++j) { [a]; }
|
||||
testGlobalProtoAccess.expected = "ok";
|
||||
test(testGlobalProtoAccess);
|
||||
|
||||
function testMatchStringObject() {
|
||||
var a = new String("foo");
|
||||
var b;
|
||||
@ -1778,6 +1771,261 @@ function testDestructuring() {
|
||||
testDestructuring.expected = (HOTLOOP + 1) * 3;
|
||||
test(testDestructuring);
|
||||
|
||||
// BEGIN MANDELBROT STUFF
|
||||
// XXXbz I would dearly like to wrap it up into a function to avoid polluting
|
||||
// the global scope, but the function ends up heavyweight, and then we lose on
|
||||
// the jit.
|
||||
load("mandelbrot-results.js");
|
||||
//function testMandelbrotAll() {
|
||||
// Configuration options that affect which codepaths we follow.
|
||||
var doImageData = true;
|
||||
var avoidSparseArray = true;
|
||||
|
||||
// Control of iteration numbers and sizing. We'll do
|
||||
// scaler * colorNames.length iterations or so before deciding that we
|
||||
// don't escape.
|
||||
const scaler = 5;
|
||||
const numRows = 600;
|
||||
const numCols = 600;
|
||||
|
||||
// For now, avoid hitting memory pressure
|
||||
gcparam("maxBytes", 1300000000);
|
||||
gcparam("maxMallocBytes", 1300000000);
|
||||
|
||||
const colorNames = [
|
||||
"black",
|
||||
"green",
|
||||
"blue",
|
||||
"red",
|
||||
"purple",
|
||||
"orange",
|
||||
"cyan",
|
||||
"yellow",
|
||||
"magenta",
|
||||
"brown",
|
||||
"pink",
|
||||
"chartreuse",
|
||||
"darkorange",
|
||||
"crimson",
|
||||
"gray",
|
||||
"deeppink",
|
||||
"firebrick",
|
||||
"lavender",
|
||||
"lawngreen",
|
||||
"lightsalmon",
|
||||
"lime",
|
||||
"goldenrod"
|
||||
];
|
||||
const threshold = (colorNames.length - 1) * scaler;
|
||||
|
||||
// Now set up our colors
|
||||
var colors = [];
|
||||
for (var colorNameIdx in colorNames) {
|
||||
colorNameIdx = parseInt(colorNameIdx);
|
||||
colors.push([colorNameIdx, colorNameIdx, colorNameIdx, 0]);
|
||||
}
|
||||
|
||||
// Storage for our point data
|
||||
var points;
|
||||
|
||||
var scratch = {};
|
||||
var scratchZ = {};
|
||||
function complexMult(a, b) {
|
||||
var newr = a.r * b.r - a.i * b.i;
|
||||
var newi = a.r * b.i + a.i * b.r;
|
||||
scratch.r = newr;
|
||||
scratch.i = newi;
|
||||
return scratch;
|
||||
}
|
||||
function complexAdd(a, b) {
|
||||
scratch.r = a.r + b.r;
|
||||
scratch.i = a.i + b.i;
|
||||
return scratch;
|
||||
}
|
||||
function abs(a) {
|
||||
return Math.sqrt(a.r * a.r + a.i * a.i);
|
||||
}
|
||||
|
||||
function escapeAbsDiff(normZ, absC) {
|
||||
var absZ = Math.sqrt(normZ);
|
||||
return normZ > absZ + absC;
|
||||
}
|
||||
|
||||
function escapeNorm2(normZ) {
|
||||
return normZ > 4;
|
||||
}
|
||||
|
||||
function fuzzyColors(i) {
|
||||
return Math.floor(i / scaler) + 1;
|
||||
}
|
||||
|
||||
function moddedColors(i) {
|
||||
return (i % (colorNames.length - 1)) + 1;
|
||||
}
|
||||
|
||||
function computeEscapeSpeedObjects(real, imag) {
|
||||
var c = { r: real, i: imag }
|
||||
scratchZ.r = scratchZ.i = 0;
|
||||
var absC = abs(c);
|
||||
for (var i = 0; i < threshold; ++i) {
|
||||
scratchZ = complexAdd(c, complexMult(scratchZ, scratchZ));
|
||||
if (escape(scratchZ.r * scratchZ.r + scratchZ.i * scratchZ.i,
|
||||
absC)) {
|
||||
return colorMap(i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function computeEscapeSpeedOneObject(real, imag) {
|
||||
// fold in the fact that we start with 0
|
||||
var r = real;
|
||||
var i = imag;
|
||||
var absC = abs({r: real, i: imag});
|
||||
for (var j = 0; j < threshold; ++j) {
|
||||
var r2 = r * r;
|
||||
var i2 = i * i;
|
||||
if (escape(r2 + i2, absC)) {
|
||||
return colorMap(j);
|
||||
}
|
||||
i = 2 * r * i + imag;
|
||||
r = r2 - i2 + real;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function computeEscapeSpeedDoubles(real, imag) {
|
||||
// fold in the fact that we start with 0
|
||||
var r = real;
|
||||
var i = imag;
|
||||
var absC = Math.sqrt(real * real + imag * imag);
|
||||
for (var j = 0; j < threshold; ++j) {
|
||||
var r2 = r * r;
|
||||
var i2 = i * i;
|
||||
if (escape(r2 + i2, absC)) {
|
||||
return colorMap(j);
|
||||
}
|
||||
i = 2 * r * i + imag;
|
||||
r = r2 - i2 + real;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
var computeEscapeSpeed = computeEscapeSpeedDoubles;
|
||||
var escape = escapeNorm2;
|
||||
var colorMap = fuzzyColors;
|
||||
|
||||
function addPointOrig(pointArray, n, i, j) {
|
||||
if (!points[n]) {
|
||||
points[n] = [];
|
||||
points[n].push([i, j, 1, 1]);
|
||||
} else {
|
||||
var point = points[n][points[n].length-1];
|
||||
if (point[0] == i && point[1] == j - point[3]) {
|
||||
++point[3];
|
||||
} else {
|
||||
points[n].push([i, j, 1, 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addPointImagedata(pointArray, n, col, row) {
|
||||
var slotIdx = ((row * numCols) + col) * 4;
|
||||
pointArray[slotIdx] = colors[n][0];
|
||||
pointArray[slotIdx+1] = colors[n][1];
|
||||
pointArray[slotIdx+2] = colors[n][2];
|
||||
pointArray[slotIdx+3] = colors[n][3];
|
||||
}
|
||||
|
||||
function createMandelSet() {
|
||||
var realRange = { min: -2.1, max: 1 };
|
||||
var imagRange = { min: -1.5, max: 1.5 };
|
||||
|
||||
var addPoint;
|
||||
if (doImageData) {
|
||||
addPoint = addPointImagedata;
|
||||
points = new Array(4*numCols*numRows);
|
||||
if (avoidSparseArray) {
|
||||
for (var idx = 0; idx < 4*numCols*numRows; ++idx) {
|
||||
points[idx] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addPoint = addPointOrig;
|
||||
points = [];
|
||||
}
|
||||
var realStep = (realRange.max - realRange.min)/numCols;
|
||||
var imagStep = (imagRange.min - imagRange.max)/numRows;
|
||||
for (var i = 0, curReal = realRange.min;
|
||||
i < numCols;
|
||||
++i, curReal += realStep) {
|
||||
for (var j = 0, curImag = imagRange.max;
|
||||
j < numRows;
|
||||
++j, curImag += imagStep) {
|
||||
var n = computeEscapeSpeed(curReal, curImag);
|
||||
addPoint(points, n, i, j)
|
||||
}
|
||||
}
|
||||
var result;
|
||||
if (doImageData) {
|
||||
if (colorMap == fuzzyColors) {
|
||||
result = mandelbrotImageDataFuzzyResult;
|
||||
} else {
|
||||
result = mandelbrotImageDataModdedResult;
|
||||
}
|
||||
} else {
|
||||
result = mandelbrotNoImageDataResult;
|
||||
}
|
||||
return points.toSource() == result;
|
||||
}
|
||||
|
||||
createMandelSet.expected = true;
|
||||
|
||||
const escapeTests = [ escapeAbsDiff ];
|
||||
const colorMaps = [ fuzzyColors, moddedColors ];
|
||||
const escapeComputations = [ computeEscapeSpeedObjects,
|
||||
computeEscapeSpeedOneObject,
|
||||
computeEscapeSpeedDoubles ];
|
||||
// Test all possible escape-speeed generation codepaths, using the
|
||||
// imageData + sparse array avoidance storage.
|
||||
doImageData = true;
|
||||
avoidSparseArray = true;
|
||||
for (var escapeIdx in escapeTests) {
|
||||
escape = escapeTests[escapeIdx];
|
||||
for (var colorMapIdx in colorMaps) {
|
||||
colorMap = colorMaps[colorMapIdx];
|
||||
for (var escapeComputationIdx in escapeComputations) {
|
||||
computeEscapeSpeed = escapeComputations[escapeComputationIdx];
|
||||
test(createMandelSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test all possible storage strategies. Note that we already tested
|
||||
// doImageData == true with avoidSparseArray == true.
|
||||
escape = escapeAbsDiff;
|
||||
colorMap = fuzzyColors; // This part doesn't really matter too much here
|
||||
computeEscapeSpeed = computeEscapeSpeedDoubles;
|
||||
|
||||
doImageData = true;
|
||||
avoidSparseArray = false;
|
||||
test(createMandelSet);
|
||||
|
||||
escape = escapeNorm2;
|
||||
doImageData = false; // avoidSparseArray doesn't matter here
|
||||
test(createMandelSet);
|
||||
//}
|
||||
//testMandelbrotAll();
|
||||
// END MANDELBROT STUFF
|
||||
|
||||
/* Keep this test last, since it screws up all for...in loops after it */
|
||||
function testGlobalProtoAccess() {
|
||||
return "ok";
|
||||
}
|
||||
this.__proto__.a = 3; for (var j = 0; j < 4; ++j) { [a]; }
|
||||
testGlobalProtoAccess.expected = "ok";
|
||||
test(testGlobalProtoAccess);
|
||||
|
||||
/* Keep these at the end so that we can see the summary after the trace-debug spew. */
|
||||
print("\npassed:", passes.length && passes.join(","));
|
||||
print("\nFAILED:", fails.length && fails.join(","));
|
||||
|
Loading…
Reference in New Issue
Block a user