EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Fast transcendental library?

Started by synergymusic2000 February 14, 2004
Hi,

My application needs a LOT of complex arithmetic and ultra-low power; 
I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
() to build on. At this stage I don't really care if it's for 
assembler, C, Java, Pascal, etc, as the maths is what's going to take 
up all the MCU's time anyway.

My first preference would be for a 16 bit library, but that would 
need to be highly optimized (eg, angles in the format 0.16 in units 
of 2Pi, sine/cos values in the format 2.14, etc). But if I can't find 
a 16bit package, where can I get a 32bit library with good 
transcental support (fixed or floating point)?




Beginning Microcontrollers with the MSP430

Dear X,

Why not simply use the libs that come with your favourite compiler?
Or choose a compiler based on what libs they offer?
Failing that, some open source compilers have their libs coded in C so you
could port these to be used with your own MSP430 compiler
[Simply rename the funcs and use them as app libraries - don't try to
replace the libs used in your compiler run-times!]

Also, complex maths will mean a certain amount of unavoidable CPU load and
battery usage.
You don't get something for nothing in this world ....

I'm sure 10 minutes searching with Google will find you something.

regards,

Richard


----- Original Message ----- 
From: synergymusic2000
To: msp430@msp4...
Sent: Sunday, February 15, 2004 1:57 AM
Subject: [msp430] Fast transcendental library?


Hi,

My application needs a LOT of complex arithmetic and ultra-low power;
I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
() to build on. At this stage I don't really care if it's for
assembler, C, Java, Pascal, etc, as the maths is what's going to take
up all the MCU's time anyway.

My first preference would be for a 16 bit library, but that would
need to be highly optimized (eg, angles in the format 0.16 in units
of 2Pi, sine/cos values in the format 2.14, etc). But if I can't find
a 16bit package, where can I get a 32bit library with good
transcental support (fixed or floating point)?





.











.


On Sun, 15 Feb 2004 01:57:09 -0000, amroe@amro... wrote:

>My application needs a LOT of complex arithmetic
and ultra-low power; 
>I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
>() to build on. At this stage I don't really care if it's for 
>assembler, C, Java, Pascal, etc, as the maths is what's going to take 
>up all the MCU's time anyway.
>
>My first preference would be for a 16 bit library, but that would 
>need to be highly optimized (eg, angles in the format 0.16 in units 
>of 2Pi, sine/cos values in the format 2.14, etc). But if I can't find 
>a 16bit package, where can I get a 32bit library with good 
>transcental support (fixed or floating point)?

Are you looking to build it?  Or buy it?  (I can offer a few
suggestions for the former, not the latter.)

Dashing off a few questions, not necessarily for me but perhaps
for anyone trying to help....   Do you know what your
requirements are, given that 'fast' seems important?  How many
operations (and, of what) per second do you require?  What is
the dynamic range of your input, your output, and your
intermediate calculations?  How much error and bias can you
tolerate overall?  Or per calculation?  Are you willing and able
to consider redesigning your calculations to meet your goals?
Have you even examined alternative methods or algorithms,
generally?  How much memory can you dedicate?

It looks like you don't really need the kind of dynamic range
supported by general purpose floating point, by the way, given
your examples as input angles.  And your sin/cos outputs, of
course, have an inherent limitation in that regard.  I notice
you failed to talk about functions which might require a wide
dynamic range in their outputs, such as tan.  Do you need it?

Given the examples you mentioned, a place to look for efficient
algorithms would be in DSP code, where such fixed-point formats
are very often used.  I'm more familiar with Analog Devices'
ADSP family and their books (which, I think, are available for
free on the web) cover some examples with good commentary about
the approaches.  But you'd be converting these, as needed,
yourself.  There are any number of helpful books on various
subjects of numeric processing, from "Numerical Recipes" to
"Numerical Methods for Engineers," but an odd one that may be
more interesting to get your mind onto the subject would be
"Math Toolkit for Real-Time Programming."  It contains errors,
but it is still an enjoyable read because of how it walks you
through thought processes on the subject.

Well, that's it for now.

Jon

I've never seen one commercially. It very much depends upon what you
are 
trying to do. For example I have my own library that I use for 
navigation systems, it is so highly optimised it would be useless for 
almost anything else, in fact it 'cheats' so much it would be useless
on 
most navigation  systems. The Compiler vendors here are the most likely 
source of help, although I havce no idea whwre they source theirs from.

Cheers

Al

synergymusic2000 wrote:

> Hi,
> 
> My application needs a LOT of complex arithmetic and ultra-low power; 
> I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
> () to build on. At this stage I don't really care if it's for 
> assembler, C, Java, Pascal, etc, as the maths is what's going to take 
> up all the MCU's time anyway.
> 
> My first preference would be for a 16 bit library, but that would 
> need to be highly optimized (eg, angles in the format 0.16 in units 
> of 2Pi, sine/cos values in the format 2.14, etc). But if I can't find 
> a 16bit package, where can I get a 32bit library with good 
> transcental support (fixed or floating point)?
> 
> 
> 
> 
> 
> 
> .
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 


My guess is that a number of consultants can build something like this for 
around $5K-$10K, to your specification. Let me know if you need names. I 
can't do it myself :-)

>On Sun, 15 Feb 2004 01:57:09 -0000, amroe@amro...
wrote:
>
> >My application needs a LOT of complex arithmetic and ultra-low power;
> >I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
> >() to build on. At this stage I don't really care if it's for
> >assembler, C, Java, Pascal, etc, as the maths is what's going to
take
> >up all the MCU's time anyway.
> >
> >My first preference would be for a 16 bit library, but that would
> >need to be highly optimized (eg, angles in the format 0.16 in units
> >of 2Pi, sine/cos values in the format 2.14, etc). But if I can't
find
> >a 16bit package, where can I get a 32bit library with good
> >transcental support (fixed or floating point)?
>...

// richard (This email is for mailing lists. To reach me directly, please 
use richard@rich...) 


Hi team,

There is a ton of stuff out there e.g. 
http://www-rab.larc.nasa.gov/nmp/fNMPcode.htm

And that's just one site ...

regards,

Richard

  ----- Original Message ----- 
  From: Richard F. Man 
  To: msp430@msp4... 
  Sent: Monday, February 16, 2004 9:33 PM
  Subject: Re: [msp430] Fast transcendental library?


  My guess is that a number of consultants can build something like this for 
  around $5K-$10K, to your specification. Let me know if you need names. I 
  can't do it myself :-)

  >On Sun, 15 Feb 2004 01:57:09 -0000, amroe@amro... wrote:
  >
  > >My application needs a LOT of complex arithmetic and ultra-low power;
  > >I need a library of the usual ln(), exp(), sine(), cos(), tan() atan
  > >() to build on. At this stage I don't really care if it's
for
  > >assembler, C, Java, Pascal, etc, as the maths is what's going to
take
  > >up all the MCU's time anyway.
  > >
  > >My first preference would be for a 16 bit library, but that would
  > >need to be highly optimized (eg, angles in the format 0.16 in units
  > >of 2Pi, sine/cos values in the format 2.14, etc). But if I can't
find
  > >a 16bit package, where can I get a 32bit library with good
  > >transcental support (fixed or floating point)?
  >...

  // richard (This email is for mailing lists. To reach me directly, please 
  use richard@rich...) 



  .





------
  . 






First, thanks to Jon, Richard, onestone and Augmentics, all of whose 
answers are helpful in one way or another.

I have spent quite a bit of time Googling for this, but without 
success. I'm new to the MSP430, and so far I only have the TI dev 
system and the freeware Micro-C, neither of which seem to have what I 
want. My background is mostly assembler on many other MCUs (but I'm 
blown away by the orthogonality of the '430). I also have a little 
experience with Pascal on the AVR, plus Delphi and C/C++ on the PC.

I'd prefer an existing free or low cost solution, or enough hints so 
I can "roll my own" library. But if it's justifiable I can spring
for 
a "proper" library and/or compiler.

In terms of actual requirements, I need to keep Icc below 3mA, and 
the basic need is to regularly (within a timer interrupt every 10ms) 
calculate Y = (K1/X - K2)*K3, where X and Y are in rectangular form, 
ultimately 16 bit resolution, maybe 13 bit accuracy (but this is 
flexible). K1-K3 are constants, and everything is complex. So 
whether it's explicit or implicit, I need to do the following (I've 
scratched my head a lot trying to minimize these steps, but 
apparently scratching one's head doesn't actually increase brain 
power):
 convert X to polar form (needs square root and atan),
 do the complex divide,
 convert the result back to rectangular (needs sin, cos),
 do the complex subtract,
 convert the result to polar (needs square root and atan),
 do the complex multiply,
 convert the result back to rectangular (needs sin, cos).

That just gives me the basic function. Then I have a list a mile long 
of other features I'd LIKE to add, depending on how much time the MCU 
has left, and these also require occasional transcendentals, but they 
are less critical than the basic function above. At the moment I have 
no concept of how long these processes take, so on the assumption 
that I'd probably run out of time somewhere along the road, I thought 
I'd start out trying for the fastest libraries I could find.

I'll follow up on all the tips mentioned - thanks again to all.



synergymusic2000 wrote:

> First, thanks to Jon, Richard, onestone and
Augmentics, all of whose 
> answers are helpful in one way or another.
> 
> I have spent quite a bit of time Googling for this, but without 
> success. I'm new to the MSP430, and so far I only have the TI dev 
> system and the freeware Micro-C, neither of which seem to have what I 
> want. My background is mostly assembler on many other MCUs (but I'm 
> blown away by the orthogonality of the '430). I also have a little 
> experience with Pascal on the AVR, plus Delphi and C/C++ on the PC.
> 
> I'd prefer an existing free or low cost solution, or enough hints so 
> I can "roll my own" library. But if it's justifiable I can
spring for 
> a "proper" library and/or compiler.
> 
> In terms of actual requirements, I need to keep Icc below 3mA, and 
> the basic need is to regularly (within a timer interrupt every 10ms) 
> calculate Y = (K1/X - K2)*K3, where X and Y are in rectangular form, 
> ultimately 16 bit resolution, maybe 13 bit accuracy (but this is 
> flexible). K1-K3 are constants, and everything is complex. So 
> whether it's explicit or implicit, I need to do the following
(I've 
> scratched my head a lot trying to minimize these steps, but 
> apparently scratching one's head doesn't actually increase brain 
> power):
>  convert X to polar form (needs square root and atan),
>  do the complex divide,
>  convert the result back to rectangular (needs sin, cos),
>  do the complex subtract,
>  convert the result to polar (needs square root and atan),
>  do the complex multiply,
>  convert the result back to rectangular (needs sin, cos).

Am I being really dense here (possibly a morphine induced stupor?) or 
does this not equate to:-

	Y = K3K1/X - K3K2

sO, RATHER THAN DO A SHIT LOAD OF CONVERSIONS you really only have two 
constants K3K1 and K3K2, so store these as pre-calculated values then it 
becomes a little simpler, you only have one conversion pair to perform. 
Or has math changed since 1969?

This would let you store K3K1 as a 32 bit integer, and just have to 
peform a 32 / 16 divide (assuming X is in 16 bit format.

Cheers

Al

> 
> That just gives me the basic function. Then I have a list a mile long 
> of other features I'd LIKE to add, depending on how much time the MCU 
> has left, and these also require occasional transcendentals, but they 
> are less critical than the basic function above. At the moment I have 
> no concept of how long these processes take, so on the assumption 
> that I'd probably run out of time somewhere along the road, I thought 
> I'd start out trying for the fastest libraries I could find.
> 
> I'll follow up on all the tips mentioned - thanks again to all.
> 
> 
> 
> 
> 
> .
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 


If you can convert Y = (K1/X - K2)*K3 into Y=(K1*K3)/X - K2*K3 and 
pre-calculate K1*K3 and K2*K3, then you'd be able to save some 
operations.

To give you an impression of how "long" calculations take:
I have an application which requires about 20 multiplications, 10 
add/sub, 1 div, every 10ms, all done in plain float (24 bit 
precision). Together with some integer stuff this takes 2..3ms IIRC, 
at 6MHz, 3mA, on a F435 which doesn't even have a hardware 
multiplier; Quadravox AQ430 C compiler.
I had considered doing all this in integer, with appropriate scaling 
etc., but why complicate things unnecessarily?

A sin() function for float precision basically needs 9 muls and 7 
adds.

Looks like on an MSP with hardware multiplier it'd be possible to 
do all your calculations simply in float.

Wolfgang



If you do the divide in rectangular form you could eliminate the
conversions.

If Xr and Xi and the real and imaginary parts of X then:

1/X = 1/(Xr+jXi) = (Xr-jXi)/(Xr^2+Xi^2)

Gary.




The 2024 Embedded Online Conference