Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View fractals.asm.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
fractalModule =function(stdlib){
"use asm";
var pow = stdlib.Math.pow;
var abs = stdlib.Math.abs;
var atan2 = stdlib.Math.atan2;
var cos = stdlib.Math.cos;
var sin = stdlib.Math.sin;
function mandlebrot(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn = +( (x*x) - (y*y) + cx);
y = +((x*y)*2.0 + cy);
x = +xn;
iter=(iter+1)|0;
}
return iter|0;
}
function burningShip(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn = (x*x) - (y*y) - cx;
y = abs(x*y)*2.0 + cy;
x = xn;
iter=(iter+1)|0;
}
return iter|0;
}
function multibrot(cx, cy, maxIter, cr) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
cr = +cr;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
var n1 = 0.0;
var n2 = 0.0;
var n3 = 0.0;
n3 = +((x*x)+(y*y));
while (+n3 < 4.0 & (iter|0) < (maxIter|0)) {
if(n3==0.0){
x=+cx;
y=+cy;
n3 = +((x*x)+(y*y));
continue;
}
n1=pow(n3,(cr/1.0));
n2=cr*atan2(y,x);
xn=n1*cos(n2) + cx;
y=n1*sin(n2) + cy;
x = xn;
n3=((x*x)+(y*y));
iter=(iter+1)|0;
}
return iter|0;
}
function multibrot3(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn=pow(x,3.0)-3.0*x*(y*y) + cx;
y=3.0*(x*x)*y-pow(y,3.0) + cy;
x = xn;
iter=(iter+1)|0;
}
return iter|0;
}
function multibrot5(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn=pow(x,5.0)-(10.0*pow(x,3.0)*(y*y))+(5.0*x*pow(y,4.0)) + cx;
y=(5.0*pow(x,4.0)*y)-(10.0*(x*x)*pow(y,3.0))+pow(y,5.0) + cy;
x = xn;
iter=(iter+1)|0;
}
return iter|0;
}
function tricorn(cx, cy, maxIter) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn = (x*x) - (y*y) - cx;
y =(x+x)*(-y) + cy;
x = xn;
iter=(iter+1)|0;
}
return iter|0;
}
function julia(cx, cy, maxIter, cr, ci) {
cx = +cx;
cy = +cy;
maxIter = maxIter|0;
cr = +cr;
ci = +ci;
var iter=0;
var xn= 0.0;
var x = 0.0;
var y = 0.0;
x = cx;
y = cy;
while ( (((x*x) + (y*y)) < 4.0)&((iter|0) < (maxIter|0))) {
xn = (x*x) - (y*y) + cr;
y = (x*y)*2.0 + ci;
x = xn;
iter=(iter+1)|0;
}
return iter|0;
}
return {
mandlebrot: mandlebrot,
burningShip: burningShip,
multibrot: multibrot,
multibrot3: multibrot3,
multibrot5: multibrot5,
tricorn: tricorn,
julia: julia
};
 
};
fractalFunctions=fractalModule(self);

Hi, have you got a benchmark of this with and without the "use asm" instruction? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.