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

Use pmaddubsw for non-RDom horizontal widening adds #7440

Merged
merged 2 commits into from
Mar 24, 2023

Conversation

abadams
Copy link
Member

@abadams abadams commented Mar 20, 2023

We were rewriting the following into a pmaddubsw:

RDom r(0, 2);
f(x) += cast<uint16_t>(g(2*x + r));
f.update().atomic().vectorize(r).vectorize(x, 8);

But not the equivalent unrolled version, which is more likely to be written:

f(x) = cast<uint16_t>(g(2*x)) + g(2*x + 1)

This pattern shows up in downsampling code.

This PR fixes it, and also adds support for doing horizontal widening adds of i16 to i32 using pmaddwd, and adds some missing avx512 variants of horizontal adds using pmaddubsw.

Comment on lines +786 to +790
// Rewrite combinations of deinterleaves into horizontal ops
rewrite(widening_add(slice(x, 0, 2, lanes), slice(x, 1, 2, lanes)),
h_add(cast(op->type.with_lanes(lanes * 2), x), lanes)) ||
rewrite(widening_add(slice(x, 1, 2, lanes), slice(x, 0, 2, lanes)),
h_add(cast(op->type.with_lanes(lanes * 2), x), lanes)) ||
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be useful to have a mutator that attempts to perform this operation more generally, for other operations as well?

Copy link
Member

@rootjalex rootjalex left a comment

Choose a reason for hiding this comment

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

LGTM, left a small comment about a future possible codegen improvement but it's not necessary for this PR imo

@abadams abadams merged commit 2a51f71 into main Mar 24, 2023
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
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.

2 participants