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 wrong division hack #2413

Merged
merged 2 commits into from
Mar 25, 2023
Merged

Fixed wrong division hack #2413

merged 2 commits into from
Mar 25, 2023

Conversation

gfoidl
Copy link
Contributor

@gfoidl gfoidl commented Mar 24, 2023

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

In #2401 I introduced a bug (sorry for that) -- this PR fixes that.
The bit-hack for divison by powers of two is only valid for positive numerators, and in the failed testcase (cf. #2409 (comment)) it was negative. As showcase see this sharplab.

Note to maintainers: please run CI on ARM too (as I understand that's not on by default, so that bug even came into main-branch)

The numerator can be negative, thus the bit-hack yields wrong results.
@gfoidl
Copy link
Contributor Author

gfoidl commented Mar 24, 2023

While hunting this bug I tried several things (although in hindsight it's quite obvious that the wrong use of the bit-hack is the bug), amongst others disabling SSE with this

<RunSettings>

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <RunConfiguration>
        <!--Used in conjunction with ActiveIssueAttribute to skip tests with known issues-->
        <TestCaseFilter>category!=failing</TestCaseFilter>

        <EnvironmentVariables>
            <DOTNET_EnableSSE>0</DOTNET_EnableSSE>
        </EnvironmentVariables>
    </RunConfiguration>
</RunSettings>

and more tests started to fail -- even when going back before #2401 (e.g. to 5283d77).
To reproduce together with that runsettings one can try this playlist.zip (for filtered tests).

To me it looks like there are latent bugs in the scalar code-pathes. Can anyone confirm? Should I open a separate issue to handle these (potential) failures?

@brianpopow
Copy link
Collaborator

In #2401 I introduced a bug (sorry for that) -- this PR fixes that.

No need to be sorry here, it happens, no problem.

Note to maintainers: please run CI on ARM too (as I understand that's not on by default, so that bug even came into main-branch)

ARM CI runner only runs when the PR is tagged with ARM. That's a compromise we need to make, because it costs us money to run those ARM CI runner. I know that's not ideal, but usually changes to ARM code was very rare in the past.

and more tests started to fail -- even when going back before #2401 (e.g. to 5283d77).
To reproduce together with that runsettings one can try this playlist.zip (for filtered tests).
To me it looks like there are latent bugs in the scalar code-pathes. Can anyone confirm? Should I open a separate issue to handle these (potential) failures?

Yes please open a issue for that, we should investigate that. We have a code coverage report, I will look into the report tomorrow and see if we would have known that its not covered.

One thing I would like to have is a simple unit test for AddSubtractComponentHalf to cover this issue. Just pick some random input values for a and b and make sure the right result is produced.

@gfoidl
Copy link
Contributor Author

gfoidl commented Mar 25, 2023

simple unit test for AddSubtractComponentHalf to cover this issue

It's a private method

private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) / 2)));

So for my PoV

No need to be sorry here, it happens, no problem.

I know, but my own quality standard shouldn't allow such a mistake 😁

@brianpopow
Copy link
Collaborator

simple unit test for AddSubtractComponentHalf to cover this issue

It's a private method

Ah, yes your right, I overlooked that it's private.

Copy link
Collaborator

@brianpopow brianpopow left a comment

Choose a reason for hiding this comment

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

@gfoidl thanks for looking into this issue and providing the fix.

@brianpopow brianpopow merged commit 9756ae9 into SixLabors:main Mar 25, 2023
@gfoidl gfoidl deleted the smash_bug branch March 25, 2023 15:27
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.

3 participants