Support

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?

For general discussion related FlowStone

less cpu hungry power approximation?

Postby tester » Sun Feb 06, 2022 1:12 pm

Theme like tkis in stream:

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.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: less cpu hungry power approximation?

Postby nix » Sun Feb 06, 2022 6:39 pm

square: val * val
cube: val * val * val

does that simple thought from a simple soul help?
User avatar
nix
 
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: less cpu hungry power approximation?

Postby tester » Sun Feb 06, 2022 6:48 pm

Nix, base as integer, exp as continuous range between 0 and 1.
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.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: less cpu hungry power approximation?

Postby juha_tp » Sun Feb 06, 2022 7:26 pm

Hmm... how much faster approximation is depends on accuracy you need.

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?

Postby martinvicanek » Sun Feb 06, 2022 7:38 pm

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;
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: less cpu hungry power approximation?

Postby tester » Mon Feb 07, 2022 11:47 am

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.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: less cpu hungry power approximation?

Postby nix » Mon Feb 07, 2022 10:10 pm

oh sorry
I see now that this can use decimals

thanks guys
User avatar
nix
 
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am


Return to General

Who is online

Users browsing this forum: No registered users and 90 guests