diff --git a/src/ImageSharp/Common/Helpers/TensorPrimitives.cs b/src/ImageSharp/Common/Helpers/TensorPrimitives.cs index 4bff7882f..4be4ab3aa 100644 --- a/src/ImageSharp/Common/Helpers/TensorPrimitives.cs +++ b/src/ImageSharp/Common/Helpers/TensorPrimitives.cs @@ -204,15 +204,15 @@ internal static partial class TensorPrimitives_ ref T yRef = ref MemoryMarshal.GetReference(y); ref T destinationRef = ref MemoryMarshal.GetReference(destination); nuint length = (uint)x.Length; + nuint vector512Threshold = Unsafe.SizeOf() == 1 ? (uint)Vector512.Count : 512; - // AVX-512 setup only pays off for larger multi-byte inputs. Byte addition remains on AVX2 because direct - // PNG/WebP measurements show that its higher lane count does not recover the wider dispatch cost. + // Match the runtime's AVX-512 selection for byte-sized elements once one complete vector is available. + // Wider elements retain the measured crossover point where their 512-bit setup cost becomes worthwhile. // Each pipeline preloads its final inputs when a tail overlaps so same-start in-place operation remains correct. if (TOperator.Vectorizable && Vector512.IsHardwareAccelerated && Vector512.IsSupported - && Unsafe.SizeOf() > 1 - && length >= 512) + && length >= vector512Threshold) { InvokeVectorized512(ref xRef, ref yRef, ref destinationRef, length); return;