using FFTW.NET; using FxpConvert.Common; using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Text; using System.Threading.Tasks; namespace SIMDFxpConvert { public sealed class SIMDCalc : ICalc { public IAdd Add { get; } = new SIMDAdd(); public ISubtract Subtract { get; } = new SIMDSubtract(); public IMultiply Multiply { get; } = new SIMDMultiply(); public IDivision Division { get; } = new SIMDDivision(); public IFFT FFT { get; } = new SIMDFFT(); public IArraySum Sum { get; } = new SIMDArraySum(); public unsafe void Fill(ref float result, float value, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref result); var desc = Vector512.One * value; uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc = desc; } if (c1 > 0) { float* resultptr = (float*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = value; } } } public unsafe void Fill(ref double result, double value, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref result); var desc = Vector512.One * value; uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc = desc; } if (c1 > 0) { double* resultptr = (double*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = value; } } } } public sealed class SIMDArraySum : IArraySum { public unsafe float Rms(ref float value, uint count) { if (count == 0) return 0; if (count == 1) return value; float temp = 0; float* ptr = (float*)Unsafe.AsPointer(ref value); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var refvalue = ref Unsafe.As>(ref value); for (int i = 0; i < c; i++) { ref var tempref = ref Unsafe.Add(ref refvalue, i); var t = tempref * tempref; for (int j = 0; j < onecount; j++) { temp += t[j]; } } if (c1 > 0) { for (int i = 0; i < c1; i++) { temp += (ptr[start + i] * ptr[start + i]); } } return MathF.Sqrt(temp / count); } public unsafe double Rms(ref double value, uint count) { if (count == 0) return 0; if (count == 1) return value; double temp = 0; double* ptr = (double*)Unsafe.AsPointer(ref value); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var refvalue = ref Unsafe.As>(ref value); for (int i = 0; i < c; i++) { ref var tempref = ref Unsafe.Add(ref refvalue, i); tempref *= tempref; for (int j = 0; j < onecount; j++) { temp += tempref[j]; } } if (c1 > 0) { for (int i = 0; i < c1; i++) { temp += (ptr[start + i] * ptr[start + i]); } } return Math.Sqrt(temp / count); } public unsafe float Sum(ref float value, uint count) { if (count == 0) return 0; if (count == 1) return value; float* ptr = (float*)Unsafe.AsPointer(ref value); float temp = value; for (int i = 1; i < count; i++) { temp += ptr[i]; } return temp; } public unsafe double Sum(ref double value, uint count) { if (count == 0) return 0; if (count == 1) return value; double* ptr = (double*)Unsafe.AsPointer(ref value); double temp = value; for (int i = 1; i < count; i++) { temp += ptr[i]; } return temp; } } public sealed class SIMDFFT : IFFT { public void FFT(double[] real, double[] imaginary) { MathNet.Numerics.IntegralTransforms.Fourier.Forward(real,imaginary, MathNet.Numerics.IntegralTransforms.FourierOptions.Matlab); } public void FFT(float[] real, float[] imaginary) { MathNet.Numerics.IntegralTransforms.Fourier.Forward(real,imaginary, MathNet.Numerics.IntegralTransforms.FourierOptions.Matlab); } } public unsafe sealed class SIMDAdd : IAdd { public void Add(ref float left, float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) + tempright; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] + right; } } } public void Add(ref float left, ref float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) + Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] + rightptr[start + i]; } } } public void Add(ref float left, float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc += tempright; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] += right; } } } public void Add(ref float left, ref float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc += Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] += rightptr[start + i]; } } } public void Add(ref double left, double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) + tempright; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] + right; } } } public void Add(ref double left, ref double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) + Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] + rightptr[start + i]; } } } public void Add(ref double left, double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc += tempright; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] += right; } } } public void Add(ref double left, ref double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc += Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] += rightptr[start + i]; } } } } public unsafe sealed class SIMDSubtract : ISubtract { public void Subtract(ref float left, float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) - tempright; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] - right; } } } public void Subtract(ref float left, ref float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) - Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] - rightptr[start + i]; } } } public void Subtract(ref float left, float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc -= tempright; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] -= right; } } } public void Subtract(ref float left, ref float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc -= Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] -= rightptr[start + i]; } } } public void Subtract(ref double left, double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) - tempright; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] - right; } } } public void Subtract(ref double left, ref double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) - Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] - rightptr[start + i]; } } } public void Subtract(ref double left, double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; var rightarray = Enumerable.Repeat(right, (int)onecount).ToArray(); ref var tempright = ref Unsafe.As>(ref rightarray[0]); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc -= tempright; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] -= right; } } } public void Subtract(ref double left, ref double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc -= Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] -= rightptr[start + i]; } } } } public unsafe sealed class SIMDMultiply : IMultiply { public void Multiply(ref float left, float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) * right; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] * right; } } } public void Multiply(ref float left, ref float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) * Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] * rightptr[start + i]; } } } public void Multiply(ref float left, float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc *= right; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] *= right; } } } public void Multiply(ref float left, ref float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc *= Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] *= rightptr[start + i]; } } } public void Multiply(ref double left, double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) * right; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] * right; } } } public void Multiply(ref double left, ref double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) * Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] * rightptr[start + i]; } } } public void Multiply(ref double left, double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc *= right; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] *= right; } } } public void Multiply(ref double left, ref double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc *= Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] *= rightptr[start + i]; } } } } public unsafe sealed class SIMDDivision : IDivision { public void Division(ref float left, float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) / right; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] / right; } } } public void Division(ref float left, ref float right, uint count, ref float result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) / Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* resultptr = (float*)Unsafe.AsPointer(ref result); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] / rightptr[start + i]; } } } public void Division(ref float left, float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc /= right; } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] /= right; } } } public void Division(ref float left, ref float right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc /= Unsafe.Add(ref tempright, i); } if (c1 > 0) { float* leftptr = (float*)Unsafe.AsPointer(ref left); float* rightptr = (float*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] /= rightptr[start + i]; } } } public void Division(ref double left, double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) / right; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] / right; } } } public void Division(ref double left, ref double right, uint count, ref double result) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); ref var desc = ref Unsafe.As>(ref result); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref desc, i); tempdesc = Unsafe.Add(ref source, i) / Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* resultptr = (double*)Unsafe.AsPointer(ref result); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { resultptr[start + i] = leftptr[start + i] / rightptr[start + i]; } } } public void Division(ref double left, double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc /= right; } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); for (int i = 0; i < c1; i++) { leftptr[start + i] /= right; } } } public void Division(ref double left, ref double right, uint count) { if (count == 0) return; ref var source = ref Unsafe.As>(ref left); uint onecount = (uint)(512 / (Unsafe.SizeOf() * 8)); uint c = count / onecount; uint c1 = count % onecount; uint start = c * onecount; ref var tempright = ref Unsafe.As>(ref right); for (int i = 0; i < c; i++) { ref var tempdesc = ref Unsafe.Add(ref source, i); tempdesc /= Unsafe.Add(ref tempright, i); } if (c1 > 0) { double* leftptr = (double*)Unsafe.AsPointer(ref left); double* rightptr = (double*)Unsafe.AsPointer(ref right); for (int i = 0; i < c1; i++) { leftptr[start + i] /= rightptr[start + i]; } } } } }