using System.Numerics; using System.Runtime.CompilerServices; namespace Misaki.HighPerformance.HPC; public readonly unsafe partial struct WideLane : ISPMDLane, TNumber> where TNumber : unmanaged, INumber, IBinaryNumber, IMinMaxValue, IBitwiseOperators { [MethodImpl(MethodImplOptions.AggressiveInlining)] public TOther Cast() where TOther : ISPMDLane where TOtherNumber : unmanaged, INumber, IBinaryNumber, IMinMaxValue, IBitwiseOperators { if (typeof(TNumber) == typeof(float) && typeof(TOtherNumber) == typeof(int)) { return Unsafe.BitCast, TOther>(Vector.ConvertToInt32(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(float) && typeof(TOtherNumber) == typeof(uint)) { return Unsafe.BitCast, TOther>(Vector.ConvertToUInt32(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(double) && typeof(TOtherNumber) == typeof(long)) { return Unsafe.BitCast, TOther>(Vector.ConvertToInt64(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(double) && typeof(TOtherNumber) == typeof(ulong)) { return Unsafe.BitCast, TOther>(Vector.ConvertToUInt64(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(int) && typeof(TOtherNumber) == typeof(float)) { return Unsafe.BitCast, TOther>(Vector.ConvertToSingle(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(uint) && typeof(TOtherNumber) == typeof(float)) { return Unsafe.BitCast, TOther>(Vector.ConvertToSingle(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(long) && typeof(TOtherNumber) == typeof(double)) { return Unsafe.BitCast, TOther>(Vector.ConvertToDouble(Unsafe.BitCast, Vector>(value))); } if (typeof(TNumber) == typeof(ulong) && typeof(TOtherNumber) == typeof(double)) { return Unsafe.BitCast, TOther>(Vector.ConvertToDouble(Unsafe.BitCast, Vector>(value))); } var casted = stackalloc TOtherNumber[LaneWidth]; for (var i = 0; (i < LaneWidth) && (i < TOther.LaneWidth); i++) { casted[i] = TOtherNumber.CreateTruncating(value[i]); } return TOther.Load(casted); } }