Page 1 of 2

SQRT optimization

Posted: Tue Nov 19, 2019 11:28 am
by Rocko
Hey there,

I got to a point in which I need to use a function:
Y = sqrt(x)
in which X is limited between [1:0].

Can this be optimized, by avoiding sqrt and instead using taylor/maclaurin approximations?
I guess those would reach 3rd order (to reach satsifactory precision) and some multiplications and additions. Is that really better than using the original sqrt function ?

Re: SQRT optimization

Posted: Tue Nov 19, 2019 10:07 pm
by martinvicanek
There is not much to optimize: the sqrt function is as fast as a division, which is about four multiplies.

Re: SQRT optimization

Posted: Thu Feb 20, 2020 1:25 pm
by steph_tsf
I am attaching a .fsm, aiming at showing the state of the art. Kind of zoo. This goes beyond the SQRT optimization. It also covers the lin2db and db2lin functions. Please let me know if there is something missing. By the way, inside the .fsm, there is a question about the way one is raising audio to the 2nd power. Have a nice day.
RMS detector square root lin2db db2lin.fsm
(8.75 KiB) Downloaded 1581 times

Re: SQRT optimization

Posted: Thu Feb 20, 2020 6:10 pm
by trogluddite
steph_tsf wrote:...question about the way one is raising audio to the 2nd power

The max is irrelevant to the power function. It is just obtaining whichever stereo channel has the greater absolute magnitude (assuming that left/right are packed into the first two SSE channels).

Re: SQRT optimization

Posted: Thu Feb 20, 2020 7:17 pm
by martinvicanek
To use the x^a power function for a square root is indeed "sub-optimal". Better use sqrt (code) or sqrtps (ASM).

Re: SQRT optimization

Posted: Fri Feb 21, 2020 1:13 am
by steph_tsf
http://www.dsprobotics.com/support/viewtopic.php?f=2&t=37876&start=20
I've read the trogluddite post, confirming that "sqrtps" is full precision. Good news.
Contrary to "rsqrtps" (the reciprocal of it), that's limited to approximately 11-bits of precision ("half-precision").
Time to edit the RMS detector canvas, thus. One thus need to rely on the "sqrtps" instruction, just before the output.

Re: SQRT optimization

Posted: Fri Feb 21, 2020 3:27 pm
by steph_tsf
I am attaching a .fsm and a .jpg, for asking what's the specification of the sqrt(x) function that's supported by Flowstone 3.0.4. The .fsm shows that the the sqrt(x) DSP Code Component function doesn't deliver the square root of the input. Have a nice day.
sqrt(x) function for audio.fsm
(12.09 KiB) Downloaded 1511 times

DSP Code Component (650 pix).jpg
DSP Code Component (650 pix).jpg (99.48 KiB) Viewed 27657 times

Re: SQRT optimization

Posted: Fri Feb 21, 2020 5:05 pm
by deraudrl
steph_tsf wrote:**** Sorry, the board attachment quota has been reached. *****

Is such quota, a weekly limitation? When will I be able to attach the .fsm and .jpg?
Given that we've had three users hit the limit in the last two days, I'm starting to think the "limit" is global, not per-user.

Re: SQRT optimization

Posted: Sat Feb 22, 2020 12:06 am
by trogluddite
steph_tsf wrote:Is such quota, a weekly limitation? When will I be able to attach the .fsm and .jpg?

deraudrl wrote:Given that we've had three users hit the limit in the last two days, I'm starting to think the "limit" is global, not per-user.

In all my years moderating, I've still never worked out what the hell the algorithm is for it - there seem to be post-count, per-user, and global elements. I would have thought that having been here so long, I would have had it happen to me many times before, but it never has, even when we've had flurries like this one (I now have the horrible feeling that I've probably just jinxed myself! :shock: )

I also can't help wondering whether all the damned spammers aren't helping. Spogg and I can only ban them, which stops them from logging back in, but it doesn't delete their NSFW animated-GIF avatars etc. (q.v. the way that they still show in the "birthdays" list). The amount of junk on the server doesn't bear thinking about, given that we sometimes ban dozens in a single day.

In the mean-time, the only advice we can offer is to send an email to support@dsprobotics.com reporting that you can no longer upload, and hope for the best - Malc doesn't seem to check the account all that often, but he usually does fix it once he knows.

Re: SQRT optimization

Posted: Sat Feb 22, 2020 1:38 am
by steph_tsf
trogluddite wrote:the only advice we can offer is to send an email to support@dsprobotics.com reporting that you can no longer upload, and hope for the best

Without doing anything, without sending an email, I am again allowed to attach files. The attachments are now on my post, above. The sqrt(x) doesn't deliver what one is expecting. There must me something obvious like an offset, or some rescaling. Can you please tell?