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

check if fixed point square root in renderer can be replaced with hardware squareroot instruction #32

Closed
Kuratius opened this issue Jan 2, 2024 · 5 comments

Comments

@Kuratius
Copy link

Kuratius commented Jan 2, 2024

https://github.com/Hydr8gon/sm64/blob/nds/src/nds/nds_renderer.c

@Kuratius
Copy link
Author

Kuratius commented Jan 2, 2024

@Hydr8gon
Copy link
Owner

Hydr8gon commented Jan 5, 2024

For some reason, I didn't think fixed-point square root could be done by shifting a regular square root. You're right; this can be replaced with the hardware function.

@Kuratius
Copy link
Author

Kuratius commented Jan 5, 2024

Do the 64bit and 32 bit squareroots have identical performance for the hardware instruction? I can't tell without checking what the compiler generates in terms of load/store instructions and prologue. I don't expect the nds to have 64 bit registers, but I didn't really check.
Depending on the range of an int on an nds a 32 bit value may be enough even with shifting it. For example squareroot of a 64 bit int can never Take more than 32 bits if it is again an integer and not a float.

@Kuratius
Copy link
Author

Kuratius commented Jan 5, 2024

if (s > 0)

I think this will always evaluate to true except for NaN and s=0

since s is the squared norm of a vector. Does either of these happen?

Does the compiler recognize this?

@Hydr8gon
Copy link
Owner

Hydr8gon commented Jan 5, 2024

According to GBATEK, execution time is the same for both square root modes. The greater than zero check is just a precaution to avoid dividing by zero. Either way, we're talking about micro-optimizations that won't have any measurable impact on performance.

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

2 participants