Optimize IPixel<T, TPixel>.ToPixel() with SSE2, if supported
このコミットが含まれているのは:
1 親
d15967b92a
コミット
b847b516d7
3ファイル変更
+56
検索条件に一致するファイルはありません
@@ -2,6 +2,10 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -87,6 +91,22 @@ public struct Bgra32 : IEquatable<Bgra32>, IPixel<Bgra32, Float4>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Float4 ToPixel()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
int pack = Unsafe.As<Bgra32, int>(ref Unsafe.AsRef(in this));
|
||||
Vector128<byte> vZero = Vector128<byte>.Zero;
|
||||
Vector128<byte> vByte = Vector128.CreateScalarUnsafe(pack).AsByte();
|
||||
Vector128<ushort> vUShort = Sse2.UnpackLow(vByte, vZero).AsUInt16();
|
||||
Vector128<int> vInt = Sse2.UnpackLow(vUShort, vZero.AsUInt16()).AsInt32();
|
||||
Vector128<int> vShuffle = Sse2.Shuffle(vInt, 0b11_00_01_10);
|
||||
Vector128<float> vFloat = Sse2.ConvertToVector128Single(vShuffle);
|
||||
Vector128<float> vMax = Vector128.Create((float)byte.MaxValue);
|
||||
Vector128<float> vNorm = Sse.Divide(vFloat, vMax);
|
||||
|
||||
return vNorm.AsVector4();
|
||||
}
|
||||
#endif
|
||||
Vector4 linear = new(this.R, this.G, this.B, this.A);
|
||||
Vector4 normalized = linear / byte.MaxValue;
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -86,6 +90,21 @@ public struct Rgba32 : IEquatable<Rgba32>, IPixel<Rgba32, Float4>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Float4 ToPixel()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
int pack = Unsafe.As<Rgba32, int>(ref Unsafe.AsRef(in this));
|
||||
Vector128<byte> vZero = Vector128<byte>.Zero;
|
||||
Vector128<byte> vByte = Vector128.CreateScalarUnsafe(pack).AsByte();
|
||||
Vector128<ushort> vUShort = Sse2.UnpackLow(vByte, vZero).AsUInt16();
|
||||
Vector128<int> vInt = Sse2.UnpackLow(vUShort, vZero.AsUInt16()).AsInt32();
|
||||
Vector128<float> vFloat = Sse2.ConvertToVector128Single(vInt);
|
||||
Vector128<float> vMax = Vector128.Create((float)byte.MaxValue);
|
||||
Vector128<float> vNorm = Sse.Divide(vFloat, vMax);
|
||||
|
||||
return vNorm.AsVector4();
|
||||
}
|
||||
#endif
|
||||
Vector4 linear = new(this.R, this.G, this.B, this.A);
|
||||
Vector4 normalized = linear / byte.MaxValue;
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
#if NET6_0_OR_GREATER
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp;
|
||||
|
||||
@@ -86,6 +90,19 @@ public struct Rgba64 : IEquatable<Rgba64>, IPixel<Rgba64, Float4>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Float4 ToPixel()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
if (Sse2.IsSupported)
|
||||
{
|
||||
long pack = Unsafe.As<Rgba64, long>(ref Unsafe.AsRef(in this));
|
||||
Vector128<ushort> vUShort = Vector128.CreateScalarUnsafe(pack).AsUInt16();
|
||||
Vector128<int> vInt = Sse2.UnpackLow(vUShort, Vector128<ushort>.Zero).AsInt32();
|
||||
Vector128<float> vFloat = Sse2.ConvertToVector128Single(vInt);
|
||||
Vector128<float> vMax = Vector128.Create((float)ushort.MaxValue);
|
||||
Vector128<float> vNorm = Sse.Divide(vFloat, vMax);
|
||||
|
||||
return vNorm.AsVector4();
|
||||
}
|
||||
#endif
|
||||
Vector4 linear = new(this.R, this.G, this.B, this.A);
|
||||
Vector4 normalized = linear / ushort.MaxValue;
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする