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

✨ [FEATURE REQUEST] Hardware Accelerated Square Root #733

Open
SizzinSeal opened this issue Dec 24, 2024 · 9 comments
Open

✨ [FEATURE REQUEST] Hardware Accelerated Square Root #733

SizzinSeal opened this issue Dec 24, 2024 · 9 comments

Comments

@SizzinSeal
Copy link
Contributor

SizzinSeal commented Dec 24, 2024

Requested Feature

Hardware accelerated square root through. The Cortex A9 on the V5 Brain has instructions to compute the square root of floating-point numbers through the VSQRT instruction.

Current Implementation

Currently, GCC uses the sqrt implementation of libm which does not make use of this instruction.

Motivation

Computing the square root of a floating-point number is an expensive operation. With the use of more expensive algorithms like live-regenerating motion profiling and Monte Carlo Localization on the rise in VRC, it makes sense to get the V5 to perform as well as it possibly can. The better it performs, the less PROS users have to worry about performance limitations.

Features of VSQRT

  • Supports single-precision and double-precision floating-point numbers
  • Can produce "Invalid Operation" or "Inexact" exceptions (e.g, square root of -1, square root of 1 Googol)

Why doesn't GCC use this instruction automatically?

libm uses errno. Yup, that simple. GCC can't inline VSQRT because it does not set errno. This would be solved with -fno-math-errno but this is a bad idea because libraries like Eigen may check errno. Instead, libm functions would need to be overridden.

Possible implementations

We can override the sqrt provided by libm with a custom implementation that uses the VSQRT instruction, but also sets errno.

@djava
Copy link
Contributor

djava commented Dec 24, 2024

You're asking to set -fno-math-errno in PROS? No.

@Exortions
Copy link

You're asking to set -fno-math-errno in PROS? No.

Why not? Does pros use errno in a lot of places?

@SizzinSeal
Copy link
Contributor Author

PROS doesn't but something like Eigen might. I've discussed this with @djava and he's convinced me this is not the route to take

@Exortions
Copy link

👍

@SizzinSeal
Copy link
Contributor Author

@Rocky14683 has this been completed? I didn't see a commit to PROS which implements this

@Rocky14683
Copy link
Member

i thought u said its not the route to take

@Rocky14683 Rocky14683 reopened this Dec 26, 2024
@SizzinSeal
Copy link
Contributor Author

SizzinSeal commented Dec 26, 2024

Sorry, I should have been more specific. While we can't use -fno-math-errno, we can implement our own sqrt operation which uses the VSQRT instruction, but also sets errno, so behavior is still the same as previously, just much faster

@ion098
Copy link
Contributor

ion098 commented Dec 26, 2024

Re @SizzinSeal

While we can't use -fno-math-errno, we can implement our own sqrt operation which uses the VSQRT instruction, but also sets errno, so behavior is still the same as previously, just much faster

Doesn't newlib already do this? https://github.com/bminor/newlib/blob/363357c023ce01e936bdaedf0f479292a8fa4e0f/newlib/libm/machine/arm/e_sqrt.c#L30-L41

@SizzinSeal
Copy link
Contributor Author

Perhaps it does after the libm update PR. I've only analyzed binaries created using PROS 4.1.1, I'll find out

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

No branches or pull requests

5 participants