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

Masked compare and floating point classifications #2427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mazimkhan
Copy link

Introduces:

  • MaskedIsNaN(v): returns mask indicating whether v[i] is "not a number" (unordered) or false if m[i] is false.

  • MaskedIsInf(v): returns mask indicating whether v[i] is positive or negative infinity or false if m[i] is false.

  • MaskedIsFinite(v): returns mask indicating whether v[i] is neither NaN nor infinity, i.e. normal, subnormal or zero or false if m[i] is false. Equivalent to Not(Or(IsNaN(v), IsInf(v))).

  • MaskedCompEq(m, a, b), MaskedCompNe(m, a, b), MaskedCompLt(m, a, b), MaskedCompGt(m, a, b), MaskedCompLe(m, a, b), MaskedCompGe(m, a, b), returning the output for all versions of ==, !=, <, >, >=, <=, or false if m[i] is false.

All operations are written for both arm_sve-inl.h and generic_ops-inl.h and, equally, tests are included for all operations.

Copy link

google-cla bot commented Jan 6, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@jan-wassenberg jan-wassenberg left a comment

Choose a reason for hiding this comment

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

Nice :) I think the CLA issue is still unresolved, any update there?

equivalent to, and potentially more efficient than, `And(m, Eq(a, b));` etc.

* `V`: `{f}` \
<code>M **MaskedIsNaN**(V v)</code>: returns mask indicating whether `v[i]`
Copy link
Member

Choose a reason for hiding this comment

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

Let's add the mask argument to the documentation :)

#### Masked floating-point classification

All ops in this section return `false` for `mask=false` lanes. These are
equivalent to, and potentially more efficient than, `And(m, Eq(a, b));` etc.
Copy link
Member

Choose a reason for hiding this comment

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

And(m, IsNaN)?

All ops in this section return `false` for `mask=false` lanes. These are
equivalent to, and potentially more efficient than, `And(m, Eq(a, b));` etc.

* <code>M **MaskedCompEq**(M m, V a, V b)</code>: returns `a[i] == b[i]` or
Copy link
Member

Choose a reason for hiding this comment

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

Should we just call it MaskedEq for consistency with the usual naming convention, which is only to prepend Masked to the existing Eq?

}

namespace detail {
HWY_SVE_FOREACH(HWY_SVE_COMPARE_Z, MaskedEq, cmpeq)
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 we can expose these directly. Rather than putting them in detail:: and adding a wrapper function, you can just remove the namespace detail, and specify the desired name of the op as the second to last argument (MaskedEq is already good IMO).

}

template <class V, class M, class D = DFromV<V>>
HWY_API MFromD<D> MaskedIsInf(const M m, const V v) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we ever plan to provide a faster implementation of MaskIfInf/IsFinite, or can those be removed?

@mazimkhan
Copy link
Author

Nice :) I think the CLA issue is still unresolved, any update there?

Apologies, CLA issue has stuck around despite us signing it multiple times. Team was on holiday, now we are back and will resolve CLA and your comments soon.

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