// Render the fractal on a single thread using raw Vector<double> data types // For a well commented version, go see VectorFloatRenderer.RenderSingleThreadedWithADT in VectorFloat.cs public override bool RenderSingleThreaded(Float128 xmin, Float128 xmax, Float128 ymin, Float128 ymax, Float128 step, int maxIterations) { Vector <double> vmax_iters = new Vector <double>((double)maxIterations); Float128FastVector vlimit = new Float128FastVector(limit); Float128FastVector vstep = new Float128FastVector(step); Float128FastVector vinc = new Float128FastVector(new Float128((double)Vector <double> .Count) * step); Float128FastVector vxmax = new Float128FastVector(xmax); Float128FastVector vxmin = Create(i => xmin + step * new Float128((double)i)); Float128 y = ymin; int yp = 0; for (Float128FastVector vy = new Float128FastVector(ymin); (y - ymax).Hi < 0 && !Abort; vy += vstep, y += step, yp++) { if (Abort) { return(false); } int xp = 0; for (Float128FastVector vx = vxmin; Float128FastVector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector <double> .Count) { Float128FastVector accumx = vx; Float128FastVector accumy = vy; Vector <double> viters = Vector <double> .Zero; Vector <double> increment = Vector <double> .One; do { Float128FastVector naccumx = accumx.Sqr() - accumy.Sqr(); Float128FastVector naccumy = (accumx * accumy).MulPwrOf2(2); accumx = naccumx + vx; accumy = naccumy + vy; viters += increment; Float128FastVector sqabs = accumx.Sqr() + accumy.Sqr(); Vector <double> vCond = Vector.LessThanOrEqual <double>(sqabs.Hi, vlimit.Hi) & Vector.LessThanOrEqual <double>(viters, vmax_iters); increment = increment & vCond; } while (increment != Vector <double> .Zero); viters.ForEach((iter, elemNum) => DrawPixel(xp + elemNum, yp, (int)iter)); } } return(true); }
// Render the fractal on multiple threads using raw Vector<double> data types // For a well commented version, go see VectorFloatRenderer.RenderSingleThreadedWithADT in VectorFloat.cs public override bool RenderMultiThreaded(Float128 xmin, Float128 xmax, Float128 ymin, Float128 ymax, Float128 step, int maxIterations) { Vector <double> vmax_iters = new Vector <double>((double)maxIterations); Float128FastVector vlimit = new Float128FastVector(limit); Float128FastVector vstep = new Float128FastVector(step); Float128FastVector vinc = new Float128FastVector(new Float128((double)Vector <double> .Count) * step); Float128FastVector vxmax = new Float128FastVector(xmax); Float128FastVector vxmin = Create(i => xmin + step * new Float128((double)i)); Parallel.For(0, (((ymax - ymin) / step) + HALF).IntValue(), (yp) => { if (Abort) { return; } Float128FastVector vy = new Float128FastVector(ymin + step * new Float128((double)yp)); int xp = 0; for (Float128FastVector vx = vxmin; Float128FastVector.LessThanOrEqualAll(vx, vxmax); vx += vinc, xp += Vector <double> .Count) { Float128FastVector accumx = vx; Float128FastVector accumy = vy; Vector <double> viters = Vector <double> .Zero; Vector <double> increment = Vector <double> .One; do { Float128FastVector naccumx = accumx.Sqr() - accumy.Sqr(); Float128FastVector naccumy = (accumx * accumy).MulPwrOf2(2); accumx = naccumx + vx; accumy = naccumy + vy; viters += increment; Float128FastVector sqabs = accumx.Sqr() + accumy.Sqr(); Vector <double> vCond = Vector.LessThanOrEqual <double>(sqabs.Hi, vlimit.Hi) & Vector.LessThanOrEqual <double>(viters, vmax_iters); increment = increment & vCond; } while (increment != Vector <double> .Zero); viters.ForEach((iter, elemNum) => DrawPixel(xp + elemNum, yp, (int)iter)); } }); return(!Abort); }