Have you tried using floating point log() in FlexC, compiling and looking at the disassembly? IIRC, FlexC uses the CORDIC unit for floating point math, at least QMUL, QDIV and SQRT. I haven't tested exp() and log(), so far.
No need to look at the disassembly, the source code for __builtin_log2f and __builtin_exp2f are in the FlexProp include/libsys/powers.c file. They're not highly optimized, but I think they work OK.
@bob_g4bby said:
Has anyone come up with a slick way of converting QLOG's fixed point result to SPIN2 floating point format?
You can convert QLOG’s fixed-point output to SPIN2 floating point by using the built-in FlexProp C functions __builtin_log2f and __builtin_exp2f. They handle the math in floating point and can serve directly in SPIN2 via inline C or compiled functions. Alternatively, implementing a simple scaling from Q format to float before applying log() in Spin2 also works.
It's a bit confusing as QLOG works in base 2 and log works in e... Think starting to get it now...
Also have to remember what version of debug type to use... UDEC for qlog, and FDEC for log...
QLOG is a fixed point logarithm using the cordic. Since it's an interface to P2 hardware it's not available on P1 (similarly for other cordic operations, like ROTXY and POLXY). However, the floating point LOG operators (LOG, LOG2, LOG10) are available on P1 in FlexSpin. On P1 they use the built in log tables in the ROM, so they're a little less accurate than the P2 versions. Ditto for QEXP vs EXP, EXP2, EXP10.
Comments
Have you tried using floating point log() in FlexC, compiling and looking at the disassembly? IIRC, FlexC uses the CORDIC unit for floating point math, at least QMUL, QDIV and SQRT. I haven't tested exp() and log(), so far.
No need to look at the disassembly, the source code for __builtin_log2f and __builtin_exp2f are in the FlexProp include/libsys/powers.c file. They're not highly optimized, but I think they work OK.
You can convert QLOG’s fixed-point output to SPIN2 floating point by using the built-in FlexProp C functions __builtin_log2f and __builtin_exp2f. They handle the math in floating point and can serve directly in SPIN2 via inline C or compiled functions. Alternatively, implementing a simple scaling from Q format to float before applying log() in Spin2 also works.
The latest versions of Spin2 (found in PNut, Pnut-TS, and PropTools, I believe) have several new log and exp functions that work in floating point.
Thanks, Chip - that'll be used in the spectrum display on the radio receiver I'm working on. Log amplitude is the norm.
Anybody know how qlog and qexp work?
Was just testing it and doesn't make any sense to me..
PUB Main()|x,y x:=2 y:=qexp(x) debug(fdec(y)) x:=256 y:=qlog(x) debug(fdec(y))Getting similar results in PNut, FlexProp, and Spin Tools IDE, so guess that's good anyway...
QLOG and QEXP are fixed point
PUB Main()|x,y x:=3<<27 y:=qexp(x) debug(udec(y)) x:=256 y:=qlog(x)>>27 debug(udec(y))From the latest Spin2 docs
Oh, I see .. thanks
It's a bit confusing as QLOG works in base 2 and log works in e... Think starting to get it now...
Also have to remember what version of debug type to use... UDEC for qlog, and FDEC for log...
There is a LOG2 operator in that list. Does that match QLOG?
@Rayman :
QLOG is a fixed point logarithm using the cordic. Since it's an interface to P2 hardware it's not available on P1 (similarly for other cordic operations, like ROTXY and POLXY). However, the floating point LOG operators (LOG, LOG2, LOG10) are available on P1 in FlexSpin. On P1 they use the built in log tables in the ROM, so they're a little less accurate than the P2 versions. Ditto for QEXP vs EXP, EXP2, EXP10.