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

pow() vs powf() #168

Closed
sezero opened this issue Feb 15, 2017 · 17 comments
Closed

pow() vs powf() #168

sezero opened this issue Feb 15, 2017 · 17 comments
Assignees
Labels
Milestone

Comments

@sezero
Copy link
Contributor

sezero commented Feb 15, 2017

In internal_midi.c:_WM_AdjustNoteVolumes() we use powf() and floats instead
of plain old pow(). Is there a specific reason? Is the extra precision harmful?

@psi29a
Copy link
Member

psi29a commented Feb 15, 2017

scratch this comment as redundant of the above.

Do we gain anything from using pow?

  • Does it effect the result?
  • Is it more CPU intensive than powf?

@sezero
Copy link
Contributor Author

sezero commented Feb 15, 2017

Do we gain anything from using pow?

pow() is ansi, powf() is c99. My question remains, i.e.
what do we gain anything from using powf()?

Is it more CPU intensive than powf?

For x86, it shouldn't be.

@psi29a
Copy link
Member

psi29a commented Feb 15, 2017

You mean standard C or ANSI C?

By default, Microsoft's Visual Studio C Compiler doesn't follow the ANSI C standard.

@sezero
Copy link
Contributor Author

sezero commented Feb 15, 2017

I meant C89, i.e. available practically in every and all libc

@psi29a
Copy link
Member

psi29a commented Feb 15, 2017

Good. :)

As you mentioned for x86 that there shouldn't be any overhead, how about our armhf friends (nintendo3dsdevkit and raspberry pi) ?

@sezero
Copy link
Contributor Author

sezero commented Feb 15, 2017

Not just arm, but ppc and any others. (Hope that anyone's listening.)
And we'd like to hear what @chrisisonwildcode has to say (his code and
that's the reason I assigned this to him.)

@chrisisonwildcode
Copy link
Contributor

chrisisonwildcode commented Feb 16, 2017 via email

@sezero
Copy link
Contributor Author

sezero commented Feb 28, 2017

I will have a look

Had any chance to look?

@chrisisonwildcode
Copy link
Contributor

chrisisonwildcode commented Feb 28, 2017 via email

@sezero
Copy link
Contributor Author

sezero commented Mar 17, 2017

PING ?

@sezero sezero added this to the 0.4.2 milestone Mar 17, 2017
@psi29a
Copy link
Member

psi29a commented Jul 26, 2017

@chrisisonwildcode any ideas on this?

@sezero
Copy link
Contributor Author

sezero commented Nov 3, 2017

I guess this question will go unanswered for quite a long time...

@sezero sezero modified the milestones: 0.4.2, 0.4.3 Nov 3, 2017
@chrisisonwildcode
Copy link
Contributor

chrisisonwildcode commented Nov 6, 2017 via email

@psi29a
Copy link
Member

psi29a commented Nov 6, 2017

Hmmm.. :)

@sezero
Copy link
Contributor Author

sezero commented Nov 7, 2017

I have an idea what is going on. 0.4 reworked a lot of the code. There is a flaw
in tracking timing changes in the initial read of the midi file. A simular flaw
occurs also in devtest.c

I believe your comment was intended for bug #176, yes?

@psi29a
Copy link
Member

psi29a commented May 7, 2018

Something interesting, using pow(x, 3) is more cpu intensive than just x * x * x, apparently even modern gcc and clang behave the same for float (powf). We could move to double (pow) and use --fast-math, which give us a speed boost (no overhead compared to x * x * x).

https://baptiste-wicht.com/posts/2017/09/cpp11-performance-tip-when-to-use-std-pow.html

If you are using double precision (double), std::pow(x, n) will be slower than the handcrafted equivalent unless you use -ffast-math, in which case, there is absolutely no overhead. The overhead without using the compiler option is quite large, around 2 orders of magnitude, starting from the third power. With or without -ffast-math, std::pow(x, 2) has no overhead compared to x * x.

For single precision, it's another story! For the two compilers that have been tested and for small integer values of n (but I think it's stays the same for large integer values of n), it's always faster to use direct multiplication rather than exponentiation via std::pow(x, n). Indeed, it seems that there is no optimization for the case when n is an integer. When -ffast-math is used, the difference it not very big, around 2.5 times slower for GCC and around 3.5 times slower for clang. I'm a bit disappointed by the lack of single-precision performance for std::pow. Basically, you should not use std::pow if you want single-precision powers.

@chrisisonwildcode
Copy link
Contributor

hmmm, I can't see why we couldn't use pow() in there. … can we get -ffast-math happening?

chrisisonwildcode pushed a commit that referenced this issue May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants