using FxpConvert.Common; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; namespace BaseCpuFxpConvert { public sealed class CpuCalc : ICalc { public IAdd Add { get; } = new CpuAdd(); public ISubtract Subtract { get; } = new CpuSubtract(); public IMultiply Multiply { get; } = new CpuMultiply(); public IDivision Division { get; } = new CpuDivision(); public IFFT FFT { get; } = new CpuFFT(); public IArraySum Sum { get; } = new CpuArraySum(); public unsafe void Fill(ref float result, float value, uint count) { if (count == 0) return; if(value ==0) { Unsafe.InitBlock(ref Unsafe.As(ref result), 0, count * 4); return; } Span temp = new Span(Unsafe.AsPointer(ref result),(int)count); temp.Fill(value); } } public sealed class CpuArraySum : IArraySum { public unsafe float Rms(ref float value, uint count) { if (count == 0) return 0; if (count == 1) return value; float temp = value*value; float* ptr = (float*)Unsafe.AsPointer(ref value); for(int i=1;i