Skip to content
Permalink
Browse files

Make SIMD compatible with latest version of System.Numerics.Vectors

  • Loading branch information...
terrajobst committed Nov 3, 2014
1 parent fb2fa8f commit a819804663d54366e419331a738cdab7bb44b035
@@ -9,6 +9,8 @@
using System.Diagnostics;
using System.Threading;

using Vector = System.Numerics.Vector;

namespace Mandelbrot
{
/// <summary>
@@ -27,7 +29,7 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

if (!VectorMath.IsHardwareAccelerated)
if (!Vector.IsHardwareAccelerated)
{
MessageBox.Show("SIMD isn't enabled for the current process. Please make sure that" + Environment.NewLine + Environment.NewLine +
"(1) You've run the 'enable-jit.cmd' script prior to running this app" + Environment.NewLine +
@@ -42,7 +42,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors">
<HintPath>..\packages\Microsoft.Bcl.Simd.1.0.1-beta\lib\portable-net45+win8\System.Numerics.Vectors.dll</HintPath>
<HintPath>..\packages\System.Numerics.Vectors.1.1.5-beta\lib\portable-net45+win8\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
@@ -99,10 +99,10 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<Content Include="RunWithSimd.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -32,7 +32,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
double step = (double)stepf;

Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vstep = new Vector<double>(step);
Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
@@ -43,7 +43,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
{
int xp = 0;
Vector<double> vxmaxd = new Vector<double>(xmax);
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmaxd); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmaxd); vx += vinc, xp += Vector<long>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
@@ -80,7 +80,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
double step = (double)stepf;

Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vstep = new Vector<double>(step);
Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vxmax = new Vector<double>(xmax);
@@ -91,7 +91,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
@@ -125,7 +125,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa

Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
@@ -137,7 +137,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa

Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
@@ -175,7 +175,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl

Vector<long> vmax_iters = new Vector<long>(max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);
@@ -187,7 +187,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl

Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<long>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
@@ -38,7 +38,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -49,7 +49,7 @@ public void RenderMultiThreadedWithADT(float xminf, float xmaxf, float yminf, fl

Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
@@ -83,7 +83,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -94,7 +94,7 @@ public void RenderMultiThreadedNoADT(float xminf, float xmaxf, float yminf, floa

Vector<double> vy = new Vector<double>(ymin + step * yp);
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
@@ -132,7 +132,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -141,7 +141,7 @@ public void RenderSingleThreadedWithADT(float xminf, float xmaxf, float yminf, f
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAny(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
ComplexVecDouble num = new ComplexVecDouble(vx, vy);
ComplexVecDouble accum = num;
@@ -175,7 +175,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
Vector<double> vmax_iters = new Vector<double>((double)max_iters);
Vector<double> vlimit = new Vector<double>(limit);
Vector<double> vstep = new Vector<double>(step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Length * step);
Vector<double> vinc = new Vector<double>((double)Vector<double>.Count * step);
Vector<double> vxmax = new Vector<double>(xmax);
Vector<double> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -184,7 +184,7 @@ public void RenderSingleThreadedNoADT(float xminf, float xmaxf, float yminf, flo
for (Vector<double> vy = new Vector<double>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Length)
for (Vector<double> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<double>.Count)
{
Vector<double> accumx = vx;
Vector<double> accumy = vy;
@@ -33,7 +33,7 @@ public void RenderSingleThreadedWithADT(float xmin, float xmax, float ymin, floa
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
// Use my little helper routine: it's kind of slow, but I find it pleasantly readable.
// The alternative would be this:
// float[] xmins = new float[Vector<float>.Length];
@@ -52,7 +52,7 @@ public void RenderSingleThreadedWithADT(float xmin, float xmax, float ymin, floa
int xp = 0;
for (Vector<float> vx = vxmin;
Vector.LessThanOrEqualAny(vx, vxmax); // Vector.{comparision}Any|All return bools, not masks
vx += vinc, xp += Vector<int>.Length)
vx += vinc, xp += Vector<int>.Count)
{
ComplexVecFloat num = new ComplexVecFloat(vx, vy);
ComplexVecFloat accum = num;
@@ -100,15 +100,15 @@ public void RenderSingleThreadedNoADT(float xmin, float xmax, float ymin, float
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

float y = ymin;
int yp = 0;
for (Vector<float> vy = new Vector<float>(ymin); y <= ymax && !Abort; vy += vstep, y += step, yp++)
{
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
Vector<float> accumx = vx;
Vector<float> accumy = vy;
@@ -140,7 +140,7 @@ public void RenderMultiThreadedNoADT(float xmin, float xmax, float ymin, float y
Vector<int> vmax_iters = new Vector<int>(max_iters);
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -151,7 +151,7 @@ public void RenderMultiThreadedNoADT(float xmin, float xmax, float ymin, float y

Vector<float> vy = new Vector<float>(ymin + step * yp);
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
Vector<float> accumx = vx;
Vector<float> accumy = vy;
@@ -184,7 +184,7 @@ public void RenderMultiThreadedWithADT(float xmin, float xmax, float ymin, float
Vector<int> vmax_iters = new Vector<int>(max_iters);
Vector<float> vlimit = new Vector<float>(limit);
Vector<float> vstep = new Vector<float>(step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Length * step);
Vector<float> vinc = new Vector<float>((float)Vector<float>.Count * step);
Vector<float> vxmax = new Vector<float>(xmax);
Vector<float> vxmin = VectorHelper.Create(i => xmin + step * i);

@@ -195,7 +195,7 @@ public void RenderMultiThreadedWithADT(float xmin, float xmax, float ymin, float

Vector<float> vy = new Vector<float>(ymin + step * yp);
int xp = 0;
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Length)
for (Vector<float> vx = vxmin; Vector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector<int>.Count)
{
ComplexVecFloat num = new ComplexVecFloat(vx, vy);
ComplexVecFloat accum = num;

2 comments on commit a819804

@birbilis

This comment has been minimized.

Copy link

replied Nov 7, 2014

when I first noticed you changed "Length" to "Count" it looked strange, but if this returns number of elements in the vector, then definitely it is the way to go (since Length means other thing in geometry)

@mellinoe

This comment has been minimized.

Copy link

replied Nov 7, 2014

Yep, we wanted to make sure there was no confusion between the two terms, and since "Count" is already used for things like Lists, etc. we figured this was clearer.

Please sign in to comment.
You can’t perform that action at this time.