Skip to content

Commit 4571325

Browse files
committed
add DebugGuard to check for multiple of 8
1 parent 03a988b commit 4571325

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static void SumVertical(Span<float> target, Span<float> source)
123123
ref Vector256<float> sourceVectorRef = ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(source));
124124

125125
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
126+
DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8");
126127
nuint count = source.Vector256Count<float>();
127128
for (nuint i = 0; i < count; i++)
128129
{
@@ -135,6 +136,7 @@ static void SumVertical(Span<float> target, Span<float> source)
135136
ref Vector128<float> sourceVectorRef = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(source));
136137

137138
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
139+
DebugGuard.IsTrue(source.Length % 8 == 0, "source must be multiple of 8");
138140
nuint count = source.Vector128Count<float>();
139141
for (nuint i = 0; i < count; i++)
140142
{
@@ -213,6 +215,7 @@ static void MultiplyToAverage(Span<float> target, float multiplier)
213215
ref Vector256<float> targetVectorRef = ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(target));
214216

215217
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
218+
DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8");
216219
nuint count = target.Vector256Count<float>();
217220
Vector256<float> multiplierVector = Vector256.Create(multiplier);
218221
for (nuint i = 0; i < count; i++)
@@ -225,6 +228,7 @@ static void MultiplyToAverage(Span<float> target, float multiplier)
225228
ref Vector128<float> targetVectorRef = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(target));
226229

227230
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
231+
DebugGuard.IsTrue(target.Length % 8 == 0, "target must be multiple of 8");
228232
nuint count = target.Vector128Count<float>();
229233
Vector128<float> multiplierVector = Vector128.Create(multiplier);
230234
for (nuint i = 0; i < count; i++)

0 commit comments

Comments
 (0)