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

Make float test more accurate, add integer performance tests. #217

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Kuratius
Copy link

@Kuratius Kuratius commented Nov 1, 2024

This doesn't contain an accuracy test for the integer square root functions, but I could add one if needed.

@@ -7,6 +7,82 @@

#include <nds.h>

#define TEST_SIZE (1000)

u32 dkp_sqrt32(int a)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid putting copy-pasted benchmarks for other projects in BlocksDS. Not only can they change the code at any time, which would make the copy paste outdated, it feels in bad taste.

This can be a separate project.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree with asie.

Copy link
Author

Choose a reason for hiding this comment

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

I'll remove them then. I could put in a software implementation test instead and rename the output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, measuring against a simple C-based implementation sounds like a better idea and provides meaningful information to developers; it can also be used to validate correct outputs from the BlocksDS hardware accelerated implementation.

tests/system/hw_math/source/main.c Outdated Show resolved Hide resolved
@@ -7,6 +7,82 @@

#include <nds.h>

#define TEST_SIZE (1000)

u32 dkp_sqrt32(int a)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree with asie.

Copy link
Member

@AntonioND AntonioND left a comment

Choose a reason for hiding this comment

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

You really need to try to match the code style of the repository when you contribute to projects.

In the case of this repository, don't leave many empty lines between functions (one is enough), try to match where braces are opened and closed, capitalise comments correctly... Take a look at other PRs and you will see that, for the most part, contributors imitate pre-existing code. I'm not going to complain about one brace here and there not matching other code, but this is too different, and I would just have to clean it up myself.

tests/system/hw_math/source/main.c Outdated Show resolved Hide resolved
//which gives the source as
//Square root by abacus algorithm, Martin Guy @ UKC, June 1985.
//From a book on programming abaci by Mr C. Woo.
//assert(("sqrt input should be non-negative", n > 0));
Copy link
Member

Choose a reason for hiding this comment

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

Don't leave this commented assert(). You should just make the function take unsigned ints as input and return unsigned ints.

tests/system/hw_math/source/main.c Show resolved Hide resolved
tests/system/hw_math/source/main.c Show resolved Hide resolved
@Kuratius
Copy link
Author

Kuratius commented Nov 4, 2024

I plan to work on this further, I wouldn't consider it finished. I assume to reduce noise/you getting unnecessary notifications it's probably not enough to mark it as a draft and request a review manually when necessary. The option I have here is either to close the PR until it's done, or to split the changes, although then I'm not sure why the draft feature exists to begin with.

@asiekierka
Copy link
Contributor

The draft feature is fine; just keep us updated on the status. If you ever feel like the PR is not up to standard, feel free to close it.

Add software integer square root implementations
Add performance tests for integer square roots
Add tests for inverse float square root
Add assembly 32-bit integer square root and associated tests
@Kuratius
Copy link
Author

I've updated my tests and also added some tests for the inverse sqrt in blocksds/libnds#156 . The file currently needs to be copied from there to run some of the tests.

I've modified the integer sqrt implementations for unsigned inputs and added an assembly routine for 32-bit integer sqrts. If you think the speed is good enough you may want the assembly routine as part of libnds, though. In this PR it is included as a separate file. I believe at least for DSi users it outperforms the hardware sqrt unit, but I cannot currently test on DS. I'm also curious if choosing a better starting value with clz for it is possible, but I havent experimented with it, as it already seems to be ridiculously fast.

@Kuratius Kuratius reopened this Jan 24, 2025
@Kuratius Kuratius marked this pull request as ready for review January 24, 2025 18:09
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