Skip to content

Use pmaddubsw for non-RDom horizontal widening adds#7440

Merged
abadams merged 2 commits intomainfrom
abadams/use_pmaddubsw_for_downsample
Mar 24, 2023
Merged

Use pmaddubsw for non-RDom horizontal widening adds#7440
abadams merged 2 commits intomainfrom
abadams/use_pmaddubsw_for_downsample

Conversation

@abadams
Copy link
Copy Markdown
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 thread src/FindIntrinsics.cpp
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
Copy Markdown
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
Copy Markdown
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