Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Update simd-mandelbrot.js to align with new simd spec #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions simd-mandelbrot/mandelbrot-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,27 @@ function mandelx4(c_re4, c_im4) {
var four4 = SIMD.Float32x4.splat (4.0);
var two4 = SIMD.Float32x4.splat (2.0);
var count4 = SIMD.Int32x4.splat (0);
var zero4 = SIMD.Int32x4.splat (0);
var one4 = SIMD.Int32x4.splat (1);

for (var i = 0; i < max_iterations; ++i) {
var z_re24 = SIMD.Float32x4.mul (z_re4, z_re4);
var z_im24 = SIMD.Float32x4.mul (z_im4, z_im4);

var mi4Tmp = SIMD.Float32x4.lessThanOrEqual (SIMD.Float32x4.add (z_re24, z_im24), four4);
var mb4 = SIMD.Float32x4.lessThanOrEqual (SIMD.Float32x4.add (z_re24, z_im24), four4);
// if all 4 values are greater than 4.0, there's no reason to continue
if(!SIMD.Bool32x4.anyTrue(mi4Tmp)) {
if (!SIMD.Bool32x4.allTrue(mb4)) {
break;
}

var mi4 = SIMD.Int32x4.splat(4);
for(var j=0; j < 4; j++) {
switch (SIMD.Bool32x4.extractLane(mi4Tmp, j)) {
case true:
mi4 = SIMD.Int32x4.replaceLane(mi4, j, -1);
break;
case false:
mi4 = SIMD.Int32x4.replaceLane(mi4, j, 0);
break;
default:
return false;
break;
}
}

var new_re4 = SIMD.Float32x4.sub (z_re24, z_im24);
var new_im4 = SIMD.Float32x4.mul (SIMD.Float32x4.mul (two4, z_re4), z_im4);
z_re4 = SIMD.Float32x4.add (c_re4, new_re4);
z_im4 = SIMD.Float32x4.add (c_im4, new_im4);
count4 = SIMD.Int32x4.add (count4, SIMD.Int32x4.and (mi4, one4));
var new_re4 = SIMD.Float32x4.sub(z_re24, z_im24);
var new_im4 = SIMD.Float32x4.mul(SIMD.Float32x4.mul (two4, z_re4), z_im4);
z_re4 = SIMD.Float32x4.add(c_re4, new_re4);
z_im4 = SIMD.Float32x4.add(c_im4, new_im4);
count4 = SIMD.Int32x4.add(count4, SIMD.Int32x4.select(mb4, one4, zero4));
}
return count4;

}

function mapColorAndSetPixel (x, y, value) {
Expand Down