Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Adapted from
2 //
3 // https://github.com/RiverTrail/RiverTrail/blob/master/examples/mandelbrot/mandelbrot.js
4 //
5 // which in turn is adapted from a WebCL implementation available at
6 //
7 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
9 load(libdir + "parallelarray-helpers.js");
11 var nc = 30, maxCol = nc*3;
13 // this is the actual mandelbrot computation, ported to JavaScript
14 // from the WebCL / OpenCL example at
15 // http://www.ibiblio.org/e-notes/webcl/mandelbrot.html
16 function computeSetByRow(x, y) {
17 var Cr = (x - 256) / scale + 0.407476;
18 var Ci = (y - 256) / scale + 0.234204;
19 var I = 0, R = 0, I2 = 0, R2 = 0;
20 var n = 0;
21 while ((R2+I2 < 2.0) && (n < 512)) {
22 I = (R+R)*I+Ci;
23 R = R2-I2+Cr;
24 R2 = R*R;
25 I2 = I*I;
26 n++;
27 }
28 return n;
29 }
31 function computeSequentially() {
32 result = [];
33 for (var r = 0; r < rows; r++) {
34 for (var c = 0; c < cols; c++) {
35 result.push(computeSetByRow(r, c));
36 }
37 }
38 return result;
39 }
41 var scale = 10000*300;
42 var rows = 4;
43 var cols = 4;
45 // check that we get correct result
46 if (getBuildConfiguration().parallelJS) {
47 var expected = computeSequentially();
48 assertParallelExecSucceeds(
49 function (m) Array.buildPar(rows * cols, function (xy) {
50 return computeSetByRow((xy/cols)|0,(xy%cols))
51 }, m),
52 function (r) assertStructuralEq(expected, r));
53 }