EmbeddedRelated.com
Forums

Re: IAR and AQ430 floating point library size

Started by Preston Gurd October 21, 2002
Paul,

That's exactly the problem. Since relative short distances are to be
calculated, i.e. delta values come close to 0.0001 (it's the way the
latitude and longitude are represented in a NMEA string), the error is such
that the result is always ZERO. Emulation with 64-point fp results in a
distance accuracy of <1 meter (which of course is already beyond the scope
of any regular GPS receiver). But for the sake of fp calculation this
illustrates the problem.

Thinking about this problem of integrating "double precision" into IAR
environment or any other 32 bits supported environment. Can the following
"mixing" solution be implemented:
(1) building a trig/math library based on 64-bit IEEE formatted routines
that accepts 32 bit floating point (or doubles as they are the same in IAR
enviroment) as input value. The result is returned as a float, but with
higher accuracy (as I assume). To save program space, a tailored library
(only containing the functions needed) could be build using a 64-bit
compiler.
(2) linking this lib with the project together with proper external function
prototype definitions
(3) calling the these routines from the program source code
Can in this way the 64-bit format issue be avoided in IAR, still gaining
from 64-bit based routines?

I'm wondering if Kris would be willing to share his "toy" with us
...... :-)

Thanks for your help. Nico


----- Original Message -----
From: "Paul Curtis" <plc@plc@...>
To: <msp430@msp4...>
Sent: Sunday, October 27, 2002 12:19 PM
Subject: RE: [msp430] IAR and AQ430 floating point library size


> Nico,
>
> > The calculation that requires "double precision" is given by
> > the formula:
> >    Result = A * acos[sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y2-y1)]
> > It calculates a distance based on latitude (rad) and
> > longitude (rad) values. A 32-bit fp gives to much deviation
> > from the "real" value, compared to a off-chip emulated
> > 64-bits fp. So, for best accuracy 64-bits fp should be used.
> > That's why.
>
> Hmm.  Ok.  I'll go away and play.
>
> > Are you refering to the v4.01 fpp of TI?
>
> Nope.
>
> > Can you give more info on that compiler that supports
> > 64-bit doubles and competent trig lib for the MSP430?
>
> It's Kris' latest toy, the "beta" compiler and IDE. 
However, 64-bit is
> expensive both in speed and accuracy, but a hardware multiplier helps.
> As I wrote the 32-bit and 64-bit IEEE routines and the 8, 16, 32, and
> 64-bit integer routines for the MSP430 compiler, plus the full C99 trig
> library, I have some experience with this stuff.
>
> > Can such lib be integrated somehow in the IAR environment?
>
> Not really.  AFAIK, the IAR compiler treats float and double as one and
> the same, and so there is no way for a user to provide 64-bit floating
> point.  However, it is possible to compute such things using fixed
> point, so perhaps you can do that if you wish to stick with IAR?  Ahh.
> I see IAR doesn't support 64-bit ints and unsigneds.  How quaint.
> It's even harder if you don't have *any* 64-bit type.
>
> -- Paul.
>
> > ----- Original Message -----
> > From: "Paul Curtis" <plc@plc@...>
> > To: <msp430@msp4...>
> > Sent: Sunday, October 27, 2002 8:36 AM
> > Subject: RE: [msp430] IAR and AQ430 floating point library size
> >
> >
> > > Why do you need 64-bit floating-point?  Given that IAR support
only
> > > 32-bit fp with a 24-bit mantissa, your only hope is a compiler
with
> > > 64-bit doubles and a 53-bit mantissa.  I do know of one for
> > the MSP430
> > > with 64-bit doubles and a competent trig library, but I
> > still wonder
> > > why such precision is required.  Can you elucidate?
> > >
> > > -- Paul.
> > >
> > > > -----Original Message-----
> > > > From: Nico_Resiproc [mailto:N.Arends@N.Ar...]
> > > > Sent: 27 October 2002 03:25
> > > > To: msp430@msp4...
> > > > Subject: Re: [msp430] IAR and AQ430 floating point library
size
> > > >
> > > >
> > > > Hi there,
> > > >
> > > > Just picking up the discussion about FPP.
> > > > I'm working with the full licienced version of IAR WB,
> > already two
> > > > years now. Upgrading my "old" 1.24 version to the
1.26
> > version will
> > > > be charged by IAR with G400.00 GBP
> > > > (!!!!!!!!!) while having already spent so much money on the
IAR
> > > > package. What is their policy towards programmers like us?
> > > >
> > > > Anyhow, I need a double precision Floating Point
> > (multiply cos and
> > > > acos
> > > > calculations) on a MSP430F149 device.
> > > > The IAR math lib really has a poor performance (lots of
rounding
> > > > errors and only 7 digits resolution). Can anybody tell me
whether
> > > > the TI FPP v4.01 has a better performance, and how to
integrate
> > > > these routines in my C program. Can it be done with the
> > 1.24 version
> > > > of IAR, as I understood that TI FP formats are not
> > supported by IAR
> > > > (float and double are treated the same way).
> > > >
> > > > I really hope this discussion proceeds, since floating
> > point is an
> > > > important issue after all.
> > > >
> > > > Nico
> > > >
> > > > ----- Original Message -----
> > > > From: "To chi kin" <to_chi_kin@to_c...>
> > > > To: <msp430@msp4...>
> > > > Sent: Wednesday, October 23, 2002 6:30 AM
> > > > Subject: Re: [msp430] IAR and AQ430 floating point library
size
> > > >
> > > >
> > > > > Dear Kris,
> > > > >
> > > > > Thanks for you advice!
> > > > >
> > > > > So, I also heard T.I. has a Floating Point Package,
> > > > > FPP, v4.01 for T.I. Assembler and IAR. How do I update
> > > > > it to IAR and does it help the floating point
functionality of
> > > > > IAR? (I am currently using v1.26A evaluation version.)
> > > > >
> > > > > By the way, where to get T.I. assembler and simulator?
> > > > >
> > > > > have a good day
> > > > > Ken
> > > > >
> > > > >
> > > > >  --- Kris De Vos <microbit@micr...>
ao?lDo?oRe!G> Hi
> > > > > Ken,
> > > > > >
> > > > > > As you indicate concern for floating point, I
should
> > point out a
> > > > > > few floating point issues on EW430 :
> > > > > >
> > > > > > 1.    Don't expect too good precision of IAR
floats
> > > > > > for MSP430 . It's full of rounding errors
that I
> > > > > > don't get with other
> > > > > >        tools.
> > > > > >        Furthermore, be VERY careful when you store
> > results with
> > > > > > functions like sscanf(). It STILL happily writes
> > > > > >        floats in odd-alignment at certain
exceptions.........
> > > > > >        (The best way is to check alignment
yourself
> > > > > > at runtime, and adjust it in your own S/W ,
because
> > > > > > it
> > > > > >        indeed is not always possible for the
> > > > > > compiler nor linek to know about runtime, and
> > > > > > actually is impossible.
> > > > > >        (At least the "new tool" I'm
testing prompts
> > > > > > an "odd alignment" possibility, nowhere
to be seen
> > > > > > with EW430 after
> > > > > >        18 months of promises)
> > > > > > 2.    Be careful when it is possible to come
across
> > > > > > NaNs (Not a Number), or + and - infinities.
> > > > > >       Try giving +/- INF to IAR's
printf()
> > > > > > .................. It never returns.
> > > > > >       I've queried this with IAR about 1 year
ago,
> > > > > > and I was told not to feed NANs to printf() ......
> > > > > >       "Not Good Enough"...
> > > > > >
> > > > > > If you are specifically after floating point
> > > > > > operation, you *might* not have your needs
fulfilled
> > > > > > on EW430....
> > > > > > Each case is different, but my specific code
> > > > > > couldn't afford to (and shouldn't have
to !) check
> > > > > > for NaNs etc. at runtime
> > > > > > before I call printf().
> > > > > >
> > > > > > Printf() should handle that itself.........
> > > > > >
> > > > > > Kris
> > > > > >
> > > > > >   ----- Original Message -----
> > > > > >   From: To chi kin
> > > > > >   To: msp430@msp4...
> > > > > >   Sent: Monday, October 21, 2002 7:20 PM
> > > > > >   Subject: [msp430] IAR and AQ430 floating point
library size
> > > > > >
> > > > > >
> > > > > >   Dear all,
> > > > > >
> > > > > >   Once again, I am a newbee for MSP430. I am still
> > > > > >   searching for a right C toolchain for my 1st
> > > > > > MSP430
> > > > > >   project.
> > > > > >
> > > > > >   And floating point support is one of my major
> > > > > > concern,
> > > > > >   so I modify the MSP430F413 FET C example a bit
to
> > > > > > try
> > > > > >   it out. I just want to test a floating +, - , *,
/
> > > > > >   library size. And I wondering the result. And
> > > > > > except
> > > > > >   the C source code, I change nothing regarding
the
> > > > > >   complier or linker setting?
> > > > > >
> > > > > >   Generated code size:
> > > > > >   IAR: 808 byte
> > > > > >   AQ430: 3002 byte
> > > > > >
> > > > > >   Is that the truth? Ok, if that's the truth!
I also
> > > > > >   feel more confortable when I pay so much $$$ for
> > > > > > it.
> > > > > >
> > > > > >   Thanks in advance!
> > > > > >
> > > > > >   have a good day
> > > > > >   Ken
> > > > > >
> > > > > >   test code:
> > > > > >   #include  <msp430x41x.h>
> > > > > >
> > > > > >   float a, b, c;
> > > > > >
> > > > > >   void main(void)
> > > > > >   {
> > > > > >
> > > > > >     WDTCTL = WDTPW + WDTHOLD;
> > > > > >     P5DIR |= 0x02;
> > > > > >
> > > > > >         a = 100.0;
> > > > > >         b = 2.5;
> > > > > >         c = a + b;
> > > > > >         c = a * b;
> > > > > >         c = a / b;
> > > > > >         c = a - b;
> > > > > >
> > > > > >     for (;;)
> > > > > >     {
> > > > > >       unsigned int i;
> > > > > >
> > > > > >       P5OUT ^= 0x02;
> > > > > >       i = 50000;
> > > > > >       do (i--);
> > > > > >       while (i != 0);
> > > > > >     }
> > > > > >   }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
_________________________________________________________
> > > > > >
> > > > > > 1874(3?3L3)!A|ALGASgPo?2u(|oAyMO)!A?E3u(M--A?a)...
> > > > > >   ?V800-o|UPs|UHit?a?1aAn!
> > > > > >   Over 800 latest ringtones, only on Yahoo!
> > > > > >   http://ringtone.yahoo.com.hk
> > > > > >
> > > > > >         
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >   .
> > > > > >
> > > > > >
> > > > > >
> > > > > >   ">http://docs.yahoo.com/info/terms/
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > ------------------------ Yahoo! Groups Sponsor
> > > > ---------------------~-->
> > > > Get 128 Bit SSL Encryption!
> > > > http://us.click.yahoo.com/JjlUgA/vN2EAA/kG8FAA/CFFolB/TM
> > > > --------------------------
> > > > -------~->
> > > >
> > > > .
> > > >
> > > >
> > > >
> > > > ">http://docs.yahoo.com/info/terms/
> > > >
> > > >
> > > >
> > >
> > >
> > > .
> > >
> > >
> > >
> > > ">http://docs.yahoo.com/info/terms/
> > >
> > >
> >
> >
> >
> > ------------------------ Yahoo! Groups Sponsor
> > ---------------------~-->
> > Get 128 Bit SSL Encryption!
> > http://us.click.yahoo.com/JjlUgA/vN2EAA/kG8FAA/CFFolB/TM
> > --------------------------
> > -------~->
> >
> > .
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >
>
>
> .
>
>
>
> ">http://docs.yahoo.com/info/terms/
>
>


Beginning Microcontrollers with the MSP430

At 11:18 AM 10/27/2002 +0100, Nico_Resiproc wrote:
>Paul,
>
>The calculation that requires "double precision" is given by the
formula:
>    Result = A * acos[sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y2-y1)]
>It calculates a distance based on latitude (rad) and longitude (rad) values.
>A 32-bit fp gives to much deviation from the "real" value,
compared to a
>off-chip emulated 64-bits fp.
>So, for best accuracy 64-bits fp should be used. That's why.

Hi Nico, so far it is a vapor ware, but I have code for 64bitFP for our AVR 
compiler in testing right now. Once it is integrated and tested, it will be 
ported to our ICC430 compiler. Initially they will be functions calls, but 
eventually they will be folded into as part of the compiler (e.g. true 64 
bit double FP). We got tons of stuff to do, so I won't promise a day. In 
the ideal case, it should be no more than a few weeks worth of work.


// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo>
On-line orders, support, and listservers available on web site.
[ For technical support on ImageCraft products, please include all previous 
replies in your msgs. ]


Nico,

> That's exactly the problem. 

Hmm.  Seems that the private mail I sent you has got mixed up a bit with
the one posted to the list.  For the rest of the list tuning in, in the
private mail I sent, I simply hypothesized that the problem is with
relative error induced by the closeness of the spherical coordinates of
two points, where the angles subtended at the centre of the sphere are
rather small.  A spherical corrdinate is represented as a tuple (D,
theta, phi).  In Nico's case, D is the radius of the earth (I presume).

Given that the earth is not a sphere, but is slighly more portly than
tall (a problem shared in men of my age), does this not make the
presented distance calculation rather idealistic?  Not having done any
GPS work, I don't know...

> Since relative short distances 
> are to be calculated, i.e. delta values come close to 0.0001 
> (it's the way the latitude and longitude are represented in a 
> NMEA string), the error is such that the result is always 
> ZERO. Emulation with 64-point fp results in a distance 
> accuracy of <1 meter (which of course is already beyond the 
> scope of any regular GPS receiver). But for the sake of fp 
> calculation this illustrates the problem.

Ok.

> Thinking about this problem of integrating
"double precision" 
> into IAR environment or any other 32 bits supported 
> environment. Can the following "mixing" solution be implemented:
> (1) building a trig/math library based on 64-bit IEEE 
> formatted routines that accepts 32 bit floating point (or 
> doubles as they are the same in IAR
> enviroment) as input value. The result is returned as a 
> float, but with higher accuracy (as I assume). To save 
> program space, a tailored library (only containing the 
> functions needed) could be build using a 64-bit compiler.

This is a rather interesting proposition which I hadn't considered.
Given the obvious technical problems involved (calling conventions,
object formats), the only portable solution would be to get the output
of the 64-bit compiler into the 32-bit compiler by way of assembly code.

> (2) linking this lib with the project together
with proper 
> external function prototype definitions
> (3) calling the these routines from the program source code
> Can in this way the 64-bit format issue be avoided in IAR, 
> still gaining from 64-bit based routines?

I would say that it is possible, but rather a long-winded way to go.
Unless, of course, you have no other option.

> I'm wondering if Kris would be willing to
share his "toy" 
> with us ...... :-)

I'm sure he's willing to trade experiences, but I rather doubt the toy
will be released into the wild just yet.  The FP code is spot on and
efficient, but it isn't portable to the IAR compiler because the IAR
compiler doesn't provide 64-bit ints.  I'm sure Kris can take a gander
at computing 64-bit sines/cosines and comparing the results to, for
instance, the 80x87.

Another alternative would be to use, for instance, John Hauser's
floating point emulator which can provide 64-bit IEEE reals with
C-callable interfaces.  However, you're stuck when it comes to the
transcendental routines that you require.  One source would be fdlibm
recoded to call the float routines explicitly, which is a chore.  A
simple minimax or CORDIC for sin/cos and acos would be all that's
needed, negating the need for precision to <=1 ulp that fdlibm provides
in most cases, and negating the need for accurate reduction modulo 2PI.

-- Paul.

Hi Nico/Paul/all,

A compiler with 64 bit ints and doubles is a must if you do scientfif apps in
general.
Of course it slows things down, but it general - at that time- speed is not of
the essence.

The main reason always seems to be a divison of some sorts where the denominator
becomes very, very small.
An industrial/Medical example is a Fermentation controller I did in 1992, used
to grow Ecoli, Influenza etc.
(To make serums)
The (very long) provided formula that calculated the amount of glucose, to be
pumped into 10 Liter flasks every minute typically
had very small denominators, either yielding high rel/absolute erros - or
underflowing to - INF.
It had to take parameters like exhaled oxygen, CO2, temperature etc etc.

64 bit double was a MUST, even doubles hardy kept precision !!

The example is that speed wasn't critical at all - precision was paramount
!!!!!!!
(Was Bioenginereering app)

Kris

> The calculation that requires "double
precision" is given by 
> the formula:
>    Result = A * acos[sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y2-y1)]
> It calculates a distance based on latitude (rad) and 
> longitude (rad) values. A 32-bit fp gives to much deviation 
> from the "real" value, compared to a off-chip emulated 
> 64-bits fp. So, for best accuracy 64-bits fp should be used. 
> That's why.