Skip to content

Commit 89cd849

Browse files
Remove unused methods
1 parent 980347e commit 89cd849

File tree

5 files changed

+0
-250
lines changed

5 files changed

+0
-250
lines changed

src/ImageSharp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Numerics;
55
using System.Runtime.CompilerServices;
6-
using System.Runtime.InteropServices;
76

87
// ReSharper disable MemberHidesStaticFromOuterClass
98
namespace SixLabors.ImageSharp;
@@ -35,148 +34,5 @@ internal static void ConvertToSingle(
3534
dest1 = Vector.ConvertToSingle(i1);
3635
dest2 = Vector.ConvertToSingle(i2);
3736
}
38-
39-
/// <summary>
40-
/// <see cref="ByteToNormalizedFloat"/> as many elements as possible, slicing them down (keeping the remainder).
41-
/// </summary>
42-
[MethodImpl(InliningOptions.ShortMethod)]
43-
internal static void ByteToNormalizedFloatReduce(
44-
ref ReadOnlySpan<byte> source,
45-
ref Span<float> dest)
46-
{
47-
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
48-
49-
if (!IsAvailable)
50-
{
51-
return;
52-
}
53-
54-
int remainder = Numerics.ModuloP2(source.Length, Vector<byte>.Count);
55-
int adjustedCount = source.Length - remainder;
56-
57-
if (adjustedCount > 0)
58-
{
59-
ByteToNormalizedFloat(source[..adjustedCount], dest[..adjustedCount]);
60-
61-
source = source[adjustedCount..];
62-
dest = dest[adjustedCount..];
63-
}
64-
}
65-
66-
/// <summary>
67-
/// <see cref="NormalizedFloatToByteSaturate"/> as many elements as possible, slicing them down (keeping the remainder).
68-
/// </summary>
69-
[MethodImpl(InliningOptions.ShortMethod)]
70-
internal static void NormalizedFloatToByteSaturateReduce(
71-
ref ReadOnlySpan<float> source,
72-
ref Span<byte> dest)
73-
{
74-
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
75-
76-
if (!IsAvailable)
77-
{
78-
return;
79-
}
80-
81-
int remainder = Numerics.ModuloP2(source.Length, Vector<byte>.Count);
82-
int adjustedCount = source.Length - remainder;
83-
84-
if (adjustedCount > 0)
85-
{
86-
NormalizedFloatToByteSaturate(source[..adjustedCount], dest[..adjustedCount]);
87-
88-
source = source[adjustedCount..];
89-
dest = dest[adjustedCount..];
90-
}
91-
}
92-
93-
/// <summary>
94-
/// Implementation <see cref="SimdUtils.ByteToNormalizedFloat"/>, which is faster on new RyuJIT runtime.
95-
/// </summary>
96-
internal static void ByteToNormalizedFloat(ReadOnlySpan<byte> source, Span<float> dest)
97-
{
98-
DebugVerifySpanInput(source, dest, Vector<byte>.Count);
99-
100-
nuint n = dest.VectorCount<byte>();
101-
102-
ref Vector<byte> sourceBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference(source));
103-
ref Vector<float> destBase = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(dest));
104-
105-
for (nuint i = 0; i < n; i++)
106-
{
107-
Vector<byte> b = Unsafe.Add(ref sourceBase, i);
108-
109-
Vector.Widen(b, out Vector<ushort> s0, out Vector<ushort> s1);
110-
Vector.Widen(s0, out Vector<uint> w0, out Vector<uint> w1);
111-
Vector.Widen(s1, out Vector<uint> w2, out Vector<uint> w3);
112-
113-
Vector<float> f0 = ConvertToSingle(w0);
114-
Vector<float> f1 = ConvertToSingle(w1);
115-
Vector<float> f2 = ConvertToSingle(w2);
116-
Vector<float> f3 = ConvertToSingle(w3);
117-
118-
ref Vector<float> d = ref Unsafe.Add(ref destBase, i * 4);
119-
d = f0;
120-
Unsafe.Add(ref d, 1) = f1;
121-
Unsafe.Add(ref d, 2) = f2;
122-
Unsafe.Add(ref d, 3) = f3;
123-
}
124-
}
125-
126-
/// <summary>
127-
/// Implementation of <see cref="SimdUtils.NormalizedFloatToByteSaturate"/>, which is faster on new .NET runtime.
128-
/// </summary>
129-
internal static void NormalizedFloatToByteSaturate(
130-
ReadOnlySpan<float> source,
131-
Span<byte> dest)
132-
{
133-
DebugVerifySpanInput(source, dest, Vector<byte>.Count);
134-
135-
nuint n = dest.VectorCount<byte>();
136-
137-
ref Vector<float> sourceBase =
138-
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(source));
139-
ref Vector<byte> destBase = ref Unsafe.As<byte, Vector<byte>>(ref MemoryMarshal.GetReference(dest));
140-
141-
for (nuint i = 0; i < n; i++)
142-
{
143-
ref Vector<float> s = ref Unsafe.Add(ref sourceBase, i * 4);
144-
145-
Vector<float> f0 = s;
146-
Vector<float> f1 = Unsafe.Add(ref s, 1);
147-
Vector<float> f2 = Unsafe.Add(ref s, 2);
148-
Vector<float> f3 = Unsafe.Add(ref s, 3);
149-
150-
Vector<uint> w0 = ConvertToUInt32(f0);
151-
Vector<uint> w1 = ConvertToUInt32(f1);
152-
Vector<uint> w2 = ConvertToUInt32(f2);
153-
Vector<uint> w3 = ConvertToUInt32(f3);
154-
155-
var u0 = Vector.Narrow(w0, w1);
156-
var u1 = Vector.Narrow(w2, w3);
157-
158-
Unsafe.Add(ref destBase, i) = Vector.Narrow(u0, u1);
159-
}
160-
}
161-
162-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
163-
private static Vector<uint> ConvertToUInt32(Vector<float> vf)
164-
{
165-
var maxBytes = new Vector<float>(255f);
166-
vf *= maxBytes;
167-
vf += new Vector<float>(0.5f);
168-
vf = Vector.Min(Vector.Max(vf, Vector<float>.Zero), maxBytes);
169-
var vi = Vector.ConvertToInt32(vf);
170-
return Vector.AsVectorUInt32(vi);
171-
}
172-
173-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174-
private static Vector<float> ConvertToSingle(Vector<uint> u)
175-
{
176-
var vi = Vector.AsVectorInt32(u);
177-
var v = Vector.ConvertToSingle(vi);
178-
v *= new Vector<float>(1f / 255f);
179-
return v;
180-
}
18137
}
18238
}

src/ImageSharp/Common/Helpers/SimdUtils.FallbackIntrinsics128.cs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,6 @@ internal static void ByteToNormalizedFloatReduce(
3939
}
4040
}
4141

42-
/// <summary>
43-
/// <see cref="NormalizedFloatToByteSaturate"/> as many elements as possible, slicing them down (keeping the remainder).
44-
/// </summary>
45-
[MethodImpl(InliningOptions.ShortMethod)]
46-
internal static void NormalizedFloatToByteSaturateReduce(
47-
ref ReadOnlySpan<float> source,
48-
ref Span<byte> dest)
49-
{
50-
DebugGuard.IsTrue(source.Length == dest.Length, nameof(source), "Input spans must be of same length!");
51-
52-
int remainder = Numerics.Modulo4(source.Length);
53-
int adjustedCount = source.Length - remainder;
54-
55-
if (adjustedCount > 0)
56-
{
57-
NormalizedFloatToByteSaturate(
58-
source[..adjustedCount],
59-
dest[..adjustedCount]);
60-
61-
source = source[adjustedCount..];
62-
dest = dest[adjustedCount..];
63-
}
64-
}
65-
6642
/// <summary>
6743
/// Implementation of <see cref="SimdUtils.ByteToNormalizedFloat"/> using <see cref="Vector4"/>.
6844
/// </summary>
@@ -95,43 +71,6 @@ internal static void ByteToNormalizedFloat(ReadOnlySpan<byte> source, Span<float
9571
}
9672
}
9773

98-
/// <summary>
99-
/// Implementation of <see cref="SimdUtils.NormalizedFloatToByteSaturate"/> using <see cref="Vector4"/>.
100-
/// </summary>
101-
[MethodImpl(InliningOptions.ColdPath)]
102-
internal static void NormalizedFloatToByteSaturate(
103-
ReadOnlySpan<float> source,
104-
Span<byte> dest)
105-
{
106-
DebugVerifySpanInput(source, dest, 4);
107-
108-
uint count = (uint)source.Length / 4;
109-
if (count == 0)
110-
{
111-
return;
112-
}
113-
114-
ref Vector4 sBase = ref Unsafe.As<float, Vector4>(ref MemoryMarshal.GetReference(source));
115-
ref ByteVector4 dBase = ref Unsafe.As<byte, ByteVector4>(ref MemoryMarshal.GetReference(dest));
116-
117-
var half = new Vector4(0.5f);
118-
var maxBytes = new Vector4(255f);
119-
120-
for (nuint i = 0; i < count; i++)
121-
{
122-
Vector4 s = Unsafe.Add(ref sBase, i);
123-
s *= maxBytes;
124-
s += half;
125-
s = Numerics.Clamp(s, Vector4.Zero, maxBytes);
126-
127-
ref ByteVector4 d = ref Unsafe.Add(ref dBase, i);
128-
d.X = (byte)s.X;
129-
d.Y = (byte)s.Y;
130-
d.Z = (byte)s.Z;
131-
d.W = (byte)s.W;
132-
}
133-
}
134-
13574
[StructLayout(LayoutKind.Sequential)]
13675
private struct ByteVector4
13776
{

tests/ImageSharp.Benchmarks/Bulk/FromVector4.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,6 @@ public void PixelOperations_Specialized()
6464

6565
public class FromVector4Rgba32 : FromVector4<Rgba32>
6666
{
67-
[Benchmark]
68-
public void FallbackIntrinsics128()
69-
{
70-
Span<float> sBytes = MemoryMarshal.Cast<Vector4, float>(this.Source.GetSpan());
71-
Span<byte> dFloats = MemoryMarshal.Cast<Rgba32, byte>(this.Destination.GetSpan());
72-
73-
SimdUtils.FallbackIntrinsics128.NormalizedFloatToByteSaturate(sBytes, dFloats);
74-
}
75-
76-
[Benchmark]
77-
public void ExtendedIntrinsic()
78-
{
79-
Span<float> sBytes = MemoryMarshal.Cast<Vector4, float>(this.Source.GetSpan());
80-
Span<byte> dFloats = MemoryMarshal.Cast<Rgba32, byte>(this.Destination.GetSpan());
81-
82-
SimdUtils.ExtendedIntrinsics.NormalizedFloatToByteSaturate(sBytes, dFloats);
83-
}
84-
8567
[Benchmark]
8668
public void UseHwIntrinsics()
8769
{

tests/ImageSharp.Benchmarks/Bulk/ToVector4_Rgba32.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ public void PixelOperations_Base()
3030
this.source.GetSpan(),
3131
this.destination.GetSpan());
3232

33-
[Benchmark]
34-
public void ExtendedIntrinsics()
35-
{
36-
Span<byte> sBytes = MemoryMarshal.Cast<Rgba32, byte>(this.source.GetSpan());
37-
Span<float> dFloats = MemoryMarshal.Cast<Vector4, float>(this.destination.GetSpan());
38-
39-
SimdUtils.ExtendedIntrinsics.ByteToNormalizedFloat(sBytes, dFloats);
40-
}
41-
4233
[Benchmark]
4334
public void HwIntrinsics()
4435
{

tests/ImageSharp.Tests/Common/SimdUtilsTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ public void FallbackIntrinsics128_BulkConvertByteToNormalizedFloat(int count) =>
122122
count,
123123
(s, d) => SimdUtils.FallbackIntrinsics128.ByteToNormalizedFloat(s.Span, d.Span));
124124

125-
[Theory]
126-
[MemberData(nameof(ArraySizesDivisibleBy32))]
127-
public void ExtendedIntrinsics_BulkConvertByteToNormalizedFloat(int count) => TestImpl_BulkConvertByteToNormalizedFloat(
128-
count,
129-
(s, d) => SimdUtils.ExtendedIntrinsics.ByteToNormalizedFloat(s.Span, d.Span));
130-
131125
[Theory]
132126
[MemberData(nameof(ArraySizesDivisibleBy32))]
133127
public void HwIntrinsics_BulkConvertByteToNormalizedFloat(int count)
@@ -166,18 +160,6 @@ private static void TestImpl_BulkConvertByteToNormalizedFloat(
166160
Assert.Equal(expected, result, new ApproximateFloatComparer(1e-5f));
167161
}
168162

169-
[Theory]
170-
[MemberData(nameof(ArraySizesDivisibleBy4))]
171-
public void FallbackIntrinsics128_BulkConvertNormalizedFloatToByteClampOverflows(int count) => TestImpl_BulkConvertNormalizedFloatToByteClampOverflows(
172-
count,
173-
(s, d) => SimdUtils.FallbackIntrinsics128.NormalizedFloatToByteSaturate(s.Span, d.Span));
174-
175-
[Theory]
176-
[MemberData(nameof(ArraySizesDivisibleBy32))]
177-
public void ExtendedIntrinsics_BulkConvertNormalizedFloatToByteClampOverflows(int count) => TestImpl_BulkConvertNormalizedFloatToByteClampOverflows(
178-
count,
179-
(s, d) => SimdUtils.ExtendedIntrinsics.NormalizedFloatToByteSaturate(s.Span, d.Span));
180-
181163
[Theory]
182164
[InlineData(1234)]
183165
public void ExtendedIntrinsics_ConvertToSingle(short scale)

0 commit comments

Comments
 (0)