Skip to content

Conversation

@stevenraphael
Copy link

Some of the recognized associative operations for saturating addition return y instead of x + y. This PR fixes that bug.

@alexreinking
Copy link
Member

Thanks for opening this PR! Could you please add a test case to test/correctness/rfactor.cpp that triggers this?

@stevenraphael
Copy link
Author

Yes, I have added a test.

Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

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

Just a couple tidying comments. Please also run clang-format or manually format the code identified by the workflow.

Copy link
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

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

LGTM pending full buildbot results

table.emplace_back(select(x0 > tmax_0 - y0, tmax_0, y0), zero_0, true); // Saturating add
table.emplace_back(select(x0 < -y0, y0, tmax_0), zero_0, true); // Saturating add
table.emplace_back(select(x0 > tmax_0 - y0, tmax_0, x0 + y0), zero_0, true); // Saturating add
table.emplace_back(select(x0 < -y0, x0 + y0, tmax_0), zero_0, true); // Saturating add
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this condition: x0 < -y0 doesn't make sense to me with unsigned integer types.

Copy link
Member

Choose a reason for hiding this comment

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

In uint8, -y0 == 256 - y0 == (255-y0) + 1, which only overflows when y0 is zero, so let's consider that case first. If y0 == 0, x0 < -y0 is always false, so we return 255. That seems wrong. It's fine when y0 != 0

Maybe it's meant to be x0 < ~y0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants