Ho to do fast log routine in x86 Assembler

drtester
drtester used Ask the Experts™
on
Hello,

I am working with some audio dsp code that is using floating point numbers, ranging from 1.0e-8 to 1000.  I want to convert this value to a dB value, which will be an integer value from -160 to 60.  The usual formula is:

   result = log10(value) * 20

I currently do this with some code that looks like this:

    fld value.single
     fld x6.single
     fxch
     fyl2x
     fstp result

Open in new window


where x6 = a constant value of 6.  This works, but it seems that the fyl2x instruction eats up a ton of cycles.  I've got to do this a LOT in the code, and it needs to be very fast.  I'm not opposed to large lookup tables, if that's what it takes.

How can I improve on this?  The result only needs to be integer values - no fractional amounts are needed.  Code will be run on Pentium 4 and higher CPUs only.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
how about binary search through a list of powers of 10

Author

Commented:
Ozo: can you give me an example of what you mean?
Commented:
Never mind, I figured out a way myself! :-)  For the archives:

Took the exponent, multiplied it by a value, then implemented a lookup table based on a number of bits of the rest of it.  Got me in the ballpark, which is all I needed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial