If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
less cpu hungry power approximation?
7 posts
• Page 1 of 1
less cpu hungry power approximation?
Theme like tkis in stream:
is pretty cpu hungry. Are there any faster (non-hoped, mono4) approximations, that could do the job?
For the design, base can be an integer, starting from 2, or even power of 2; exp is in range (0;1).
The most minimalistic design requires base=2 (it's for signal scaling).
- Code: Select all
pow(base,exp);
is pretty cpu hungry. Are there any faster (non-hoped, mono4) approximations, that could do the job?
For the design, base can be an integer, starting from 2, or even power of 2; exp is in range (0;1).
The most minimalistic design requires base=2 (it's for signal scaling).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: less cpu hungry power approximation?
square: val * val
cube: val * val * val
does that simple thought from a simple soul help?
cube: val * val * val
does that simple thought from a simple soul help?
-
nix - Posts: 817
- Joined: Tue Jul 13, 2010 10:51 am
Re: less cpu hungry power approximation?
Nix, base as integer, exp as continuous range between 0 and 1.
Like 2^0.432, 2^0.456, etc.
Like 2^0.432, 2^0.456, etc.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: less cpu hungry power approximation?
Hmm... how much faster approximation is depends on accuracy you need.
Is this assembler code FS compatible https://wurstcaptures.untergrund.net/as ... ricks.html ?
Is this assembler code FS compatible https://wurstcaptures.untergrund.net/as ... ricks.html ?
- juha_tp
- Posts: 60
- Joined: Fri Nov 09, 2018 10:37 pm
Re: less cpu hungry power approximation?
This is my fast Mono4 2^x implementation for float x, accuracy close to machine precision.
- Code: Select all
streamin x; streamout y; // 2^x
// 2^x Approximation
// Author: Martin Vicanek
// Relative Error < 1e-7
// CPU load 2% of built-in pow() function
// y = 2^x
// decompose x = int + frac
// compute I = 2^int by bit shifting
// approximate F = 2^frac by polynomial
// so y = I*F
float xmax=127.5; // yields 1.#INF
float xmin=-126.5; // yields 0
float F0P5=0.5; float a0=1;
float a1=0.693147034; float a2=0.2402295 ;
float a3=0.055484164; float a4=0.009678109;
float a5=0.001243999; float a6=0.000217193;
int I127=127;
// decompose x into int and frac parts
movaps xmm0,x; minps xmm0,xmax; maxps xmm0,xmin;
movaps xmm1,xmm0; subps xmm1,F0P5; cvtps2dq xmm1,xmm1;
cvtdq2ps xmm2,xmm1; // xmm1 is the int part
subps xmm0,xmm2; // xmm0 is the frac part
// evaluate 2^int
paddd xmm1,I127; pslld xmm1,23; // xmm1 is 2^int
// evaluate 2^frac (polynomial approx.)
movaps xmm2,a6; mulps xmm2,xmm0;
addps xmm2,a5; mulps xmm2,xmm0;
addps xmm2,a4; mulps xmm2,xmm0;
addps xmm2,a3; mulps xmm2,xmm0;
addps xmm2,a2; mulps xmm2,xmm0;
addps xmm2,a1; mulps xmm2,xmm0;
addps xmm2,a0; // xmm2 is 2^frac
mulps xmm2,xmm1; // put it together
movaps y,xmm2;
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: less cpu hungry power approximation?
Thank you very much Martin, this should do the job for scaling cases.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: less cpu hungry power approximation?
oh sorry
I see now that this can use decimals
thanks guys
I see now that this can use decimals
thanks guys
-
nix - Posts: 817
- Joined: Tue Jul 13, 2010 10:51 am
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 92 guests