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

Investigate potentially more efficient calculation methods #181

Closed
lewisje opened this issue Mar 7, 2019 · 4 comments

Comments

@lewisje
Copy link

commented Mar 7, 2019

Problem Statement
You should look into ways to approximate mathematical functions that are more efficient than Taylor series. (I did a bit and found only a micro-optimization that doesn't work on ARMv7.)

Evidence or User Insights
Faster apps are better.

Proposal
The use of CORDICs or built-in mathematical functions (depending on what our supported CPU architectures have) or Chebyshev polynomials is more efficient for approximating functions over an interval than Taylor series, particularly far from the point at which the Taylor series is generated.

Goals
Calculate mathematical functions more quickly.

Non-Goals
Support the same CPU architectures as in Windows 3, with their limited built-in mathematical functions.

Low-Fidelity Concept
Look up the set of mathematical functions supported as CPU instructions by all supported architectures and replace the corresponding mathematical functions with them~~, and depending on whether they are faster, use Chebyshev polynomials or CORDICs instead of Taylor series for the rest~~.


EDIT: On briefly trying it out for myself, I have concluded that Chebyshev polynomials might not be such a good idea, considering as an example that the first coefficient in the expansion of sinh over [-1,1] is irrational, and the expansion definitely does not have the sort of pattern that the Maclaurin series does, which allows each term to be quickly calculated from the previous term.

Also, the ARMv7 architecture (the minimum for Windows 10 on ARM) has no built-in mathematical functions, and the only useful ones in SSE2 (the minimum for Windows 10 on x86) are square root and reciprocal of square root, which might be a faster conditional branch from the code path that interprets x^y as exp(y*ln(x)), but only if y is a positive-integer power of 2 or its negative.

Finally, CORDICs are best used for CPUs without multiply instructions, while both ARMv7 and SSE2 have multiply instructions.

@MicrosoftIssueBot

This comment has been minimized.

Copy link

commented Mar 7, 2019

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

@AeSix

This comment has been minimized.

Copy link

commented Mar 7, 2019

Faster apps are not better if they are inaccurate.

I feel like this is another troll, just a well thought out troll.

You can always fork, "fix" and PR.

@lewisje

This comment has been minimized.

Copy link
Author

commented Mar 8, 2019

This is not a troll (although I can understand why you're suspicious, because of another issue complaining about the use of "master" in Git), and Chebyshev polynomials are faster for a given accuracy than Taylor series, so it's not a matter of a tradeoff between speed and accuracy; I may well go the PR route, in case anyone from Microsoft happens to also consider this issue a troll.


(I have closed the issue after investigating for myself and finding only a tiny potential improvement.)

@mcooley

This comment has been minimized.

Copy link
Member

commented Mar 8, 2019

I think it's awesome that you looked into this, even though it ultimately didn't lead to improvements. Thanks for trying it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.