avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Double precision floating point routines


From: Martin Cibulski
Subject: [avr-libc-dev] Double precision floating point routines
Date: Tue, 25 Nov 2003 22:47:56 +0100

Hi,

I just subscribed to the avr-libc-dev mailing list.
As an amateur astronomer I'm building a small controller for the stepper
motors of my telescope mount.
I use the AVR mega128 and my goal is to have all functions in this
controller so that the additional PC is no longer needed for coordinate
transforms or an object database.

For this project I need double precision floating point math on the AVR CPU.
Because the C library cannot handle double precision format I started to
program my own library for this.

The basic functions I need are ADD, SUB, MUL, DIV, SQRT, SIN, COS, ATAN and
ATAN2.
I programmed ADD,SUB,MUL,DIV by myself. For the transcend functions I
translated routines from C sourcecode (Cephes Lib) to assembler.
All these functions are nearly completed and give results mostly within
2E-15 when I check against my Athlon PC.
A test program on my PC sends random numbers to the AVR for calculating and
checks the AVR's results.
Additionally I programmed all comparisons (X<Y, X<=Y, ...) giving their
result in the AVR's T flag.
I implemented one type of NANs but still no infinite numbers.

My routines use a calculation stack (double registers _T, _Z, _Y, _X):
With this stack the formula 'C = 3 * sin(a+b)' is calculated this way
(assembler syntax with macros):

f_const label_3    ;load constant 3 into _X
f_enter    ;copy _Z into _T, _Y into _Z, _X into _Y
f_load b    ;load variable a into _X
f_enter    ;copy _Z into _T, _Y into _Z, _X into _Y
f_load b    ;load variable b into _X
f_add    ;add _Y into _X and shift _Z, _T one position back
f_sin    ;calc _X = sin(_X)
f_mul    ;multiply _Y into _X and shift _Z, _T one position back
        ;Now the result is in _X.


I would like to offer my functions to be used in the AVR-GCC library.

So my question is how can I make my functions 'GCC compatible' ?
With function calls are needed for the compiler ?
Is a calculation stack a possible solution at all ?

If yes: where is the best place for the calculation stack ?
1. On the CPU stack (difficult to handle in Assembler)
2. CPU stack and _X in the CPU(current program version, a little faster,
difficult to handle in Assembler too)
3. Separate parameter stack pointed by yh:yl. I think some compilers do so ?
(should be simpler because return adresses and push/pop use another stack)
4. Global array with shifting in memory or cyclic pointer (simple, but
problems with multitasking)
5. Several global arrays (multitasking possible but each task must save a
pointer to the calculation stack)

Solution 3 seems to be the simplest to use in Assembler.
I never used GCC up to now and I don't know how function calls work in GCC
so I ask for help here.

If anybody want to look at my routines I can post them on my website.

Best Regards,
Martin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]