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

Float operations SqrtLower, MulSubAdd, GetExponent etc. #2425

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

Conversation

mazimkhan
Copy link

Introduces:

  • Masked arithmetic operations (SqrtLower, MaskedSqrtOrZero, MaskedApproximateReciprocalSqrtOrZero, MaskedApproximateReciprocalOrZero)
  • GetExponent which returns the exponents of a vector of floating point numbers.
  • MulSubAdd, a variant of MulAddSub which applied a fused multiply-add operation on even lanes and a fused multiply-subtract operation on odd ones.

Operations have been written for arm_sve-inl.h and generic_ops-inl.h and all operations have tests written for them.

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.

@johnplatts
Copy link
Contributor

There are targets other than SVE that have instructions for the GetExponent op, including AVX3/PPC9/PPC10.

GetExponent can be implemented on AVX3 using _mm_getexp_ps/_mm_getexp_pd/_mm_getexp_ph, and GetExponent can be implemented on PPC9/PPC10 using vec_extract_exp (which returns the biased exponent) followed by a subtraction by MaxExponentField<T>() >> 1.

@jan-wassenberg
Copy link
Member

There are targets other than SVE that have instructions for the GetExponent op, including AVX3/PPC9/PPC10.

GetExponent can be implemented on AVX3 using _mm_getexp_ps/_mm_getexp_pd/_mm_getexp_ph, and GetExponent can be implemented on PPC9/PPC10 using vec_extract_exp (which returns the biased exponent) followed by a subtraction by MaxExponentField<T>() >> 1.

Nice. @mazimkhan , would you like to add either of those, or insert a TODO comment mentioning them?

@@ -657,6 +657,10 @@ from left to right, of the arguments passed to `Create{2-4}`.
* `V`: `{f}` \
<code>V **Sqrt**(V a)</code>: returns `sqrt(a[i])`.

* `V`: `{f}` \
<code>V **SqrtLower**(V a)</code>: returns `sqrt(a[0])` in lowest lane and
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in other PRs, I think we'd be better off with a new First1 op, and removing the other newly added *Lower ops.

to, and potentially more efficient than, `IfThenElseZero(m, Add(a, b));` etc.

* `V`: `{f}` \
<code>V **MaskedSqrtOrZero**(M m, V a)</code>: returns `sqrt(a[i])` where
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 also drop the OrZero suffix here.

@@ -1234,6 +1243,29 @@ HWY_SVE_FOREACH_F(HWY_SVE_RETV_ARGV, ApproximateReciprocal, recpe)
// ------------------------------ Sqrt
HWY_SVE_FOREACH_F(HWY_SVE_RETV_ARGPV, Sqrt, sqrt)

// ------------------------------ MaskedSqrt
namespace detail {
HWY_SVE_FOREACH_F(HWY_SVE_RETV_ARGMV_M, MaskedSqrt, sqrt)
Copy link
Member

Choose a reason for hiding this comment

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

If we rely on First1 and remove the SqrtLower wrapper, then we can instead expose this op as MaskedSqrtOr(V no, V a).

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.

3 participants