Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Jpeg IDCT missing scalar implementation #1922

Merged
merged 3 commits into from
Jan 4, 2022

Conversation

br3aker
Copy link
Contributor

@br3aker br3aker commented Jan 4, 2022

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #1917.

Fix is simple: I've removed Debug check for Vector4.IsHardwareAccelerated as Vector4 code can be compiled to a scalar implementation. That check was deprecated long ago - when I've merged de-zigzag and single transpose call so now every IDCT implementation must do a single transpose call.

FDCT method does have a scalar implementation right now because current encoding pipeline does not have a merged zig-zag/transpose code. I'm yet to implement it in #1778 (coding those sse/avx zigzag tables is a horror). Because of two transpose calls scalar code can do DCT stuff a little trickier than simd without transpose calls at all but with a tranposed block input we must transpose it second time durint IDCT call.

@br3aker br3aker changed the title Fixed runtime error Fixed Jpeg IDCT missing scalar implementation Jan 4, 2022
@br3aker
Copy link
Contributor Author

br3aker commented Jan 4, 2022

As @JimBobSquarePants mentioned it's a problem that tests missed this bug, test suite clearly has a 'no-simd' path for IDCT method:

// 4 paths:
// 1. AllowAll - call avx/fma implementation
// 2. DisableFMA - call avx without fma implementation
// 3. DisableAvx - call sse Vector4 implementation
// 4. DisableHWIntrinsic - call scalar fallback implementation
FeatureTestRunner.RunWithHwIntrinsicsFeature(
RunTest,
seed,
HwIntrinsics.AllowAll | HwIntrinsics.DisableFMA | HwIntrinsics.DisableAVX | HwIntrinsics.DisableHWIntrinsic);

@codecov
Copy link

codecov bot commented Jan 4, 2022

Codecov Report

Merging #1922 (d61b845) into master (fe044d1) will increase coverage by 0%.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1922   +/-   ##
======================================
  Coverage      87%     87%           
======================================
  Files         961     961           
  Lines       51034   51034           
  Branches     6324    6324           
======================================
+ Hits        44793   44863   +70     
+ Misses       5202    5133   -69     
+ Partials     1039    1038    -1     
Flag Coverage Δ
unittests 87% <ø> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rp/Formats/Jpeg/Components/FastFloatingPointDCT.cs 100% <ø> (+36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe044d1...d61b845. Read the comment docs.

@JimBobSquarePants
Copy link
Member

@br3aker Ah... I see where the issue lies. HwIntrinsics.DisableHWIntrinsic doesn't disable System.Numerics so our tests will never hit that DebugGuard. We need HwIntrinsics.DisableSIMD when depending on Vector.IsHardwareAccelerated.

/// <summary>
/// See <see href="https://github.com/dotnet/runtime/blob/50ac454d8d8a1915188b2a4bb3fff3b81bf6c0cf/src/coreclr/src/jit/jitconfigvalues.h#L224"/>
/// <remarks>
/// <see cref="DisableSIMD"/> ends up impacting all SIMD support(including System.Numerics)
/// but not things like <see cref="DisableBMI1"/>, <see cref="DisableBMI2"/>, and <see cref="DisableLZCNT"/>.
/// </remarks>
/// </summary>
[Flags]
#pragma warning disable RCS1135 // Declare enum member with zero value (when enum has FlagsAttribute).
public enum HwIntrinsics
#pragma warning restore RCS1135 // Declare enum member with zero value (when enum has FlagsAttribute).
{
// Use flags so we can pass multiple values without using params.
// Don't base on 0 or use inverse for All as that doesn't translate to string values.
DisableSIMD = 1 << 0,
DisableHWIntrinsic = 1 << 1,

@br3aker
Copy link
Contributor Author

br3aker commented Jan 4, 2022

Ups!
Makes sense it didn't work, thanks for the explanation!

Edit:
And now we also got a better coverage, nice.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Glad the fix was simple.

@JimBobSquarePants JimBobSquarePants merged commit f7b332a into SixLabors:master Jan 4, 2022
@JimBobSquarePants JimBobSquarePants added this to the 2.0.0 milestone Jan 4, 2022
@br3aker br3aker deleted the dp/jpeg-idct-scalar branch January 4, 2022 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jpeg IDCT transform is missing a scalar implementation
2 participants