You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spectral blocks rounding errors in jpeg encoder #1751
And we get 0 instead of -1. This error makes current implementation non-complient to the spec. Good news are that only values in range (-1..1) are affected by this.
Steps to Reproduce
None. Changing it to a correct rounding intrinsic vroundps for example shows a significant difference in binary size. In the debugger you can actually spot the difference in the WriteBlock call values.
Intrinsic all alone latency is 8 at max. Current implementation has a dependency chain of min -> max -> mul calls which has a total latency of 4 + 4 + 4 = 12 at max and 9 at min depending on the architecture. This can be improved by the loop unrolling possibly, but in the vacuum intrinsic seems to be faster by a tiny bit - at least it's not slower.
I'm already working on it as part of some optimizations to the jpeg encoder, I've opened this issue just to inform that the problem exists.
Long story short, I am trying to SIMD'ify entire jpeg encoding thingy and for zigzag to work I converted floats to shorts via intrinsic with built-in rounding which yielded quite the difference in binary size - up to 7% for quality=100. After resulting binary comparison I've discovered that intrinsic rounding writes more -1/1 values when current implementation does not.
Activity
br3aker commentedon Aug 26, 2021
On top of that current implementation might be slower than actually calling single precision rounding avx intrinsic.
Intrinsic all alone latency is 8 at max. Current implementation has a dependency chain of
min -> max -> mulcalls which has a total latency of 4 + 4 + 4 = 12 at max and 9 at min depending on the architecture. This can be improved by the loop unrolling possibly, but in the vacuum intrinsic seems to be faster by a tiny bit - at least it's not slower.I'm already working on it as part of some optimizations to the jpeg encoder, I've opened this issue just to inform that the problem exists.
JimBobSquarePants commentedon Aug 26, 2021
How did you even discover this?! 🤯
br3aker commentedon Aug 26, 2021
Long story short, I am trying to SIMD'ify entire jpeg encoding thingy and for zigzag to work I converted floats to shorts via intrinsic with built-in rounding which yielded quite the difference in binary size - up to 7% for quality=100. After resulting binary comparison I've discovered that intrinsic rounding writes more -1/1 values when current implementation does not.
br3aker commentedon Sep 7, 2021
Same problem for automatic vectorization
Vector4fallback code:ImageSharp/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
Lines 521 to 531 in 2b85b55
addmust be multiplied by either-1or1,Clampreturns any value between-1and1.JimBobSquarePants commentedon Sep 9, 2021
You absolutely rock mate. 🤘