Ed,

FWIW, I think you're right. I think that CW *is* using up too much stack space
for temporaries. It could easily use one temporary for all of the results from
floor(). Instead, it's creating a new temporary for each result.

I played around with a lot of different ways of jiggering the compiler to be
more space efficient. I tried putting braces around all of the expressions, I
tried inline functions, I tried all the different optimization levels I could
think of, etc. None of those worked, but I finally found something that did --
create your own temporary and use that. Here's my result. It uses 24 bytes of
stack space instead of 64. I think it could get away with 16, but I'm happy with
what we've got.

#pragma stack_cleanup on

#define PI2 (3.14159265 * 2)

typedef struct MOONPOSDATA
{
     double    l;
     double    m;
     double    f;
     double    d;
     double    n;
     double    g;
} MOONPOSDATA;

extern double floor (double);

void MoonPosTest(double t, double *a5, double *d5, double *r5)
{
     MOONPOSDATA* mp;
     double temp;

     mp = MemPtrNew(sizeof(MOONPOSDATA));

     mp->l = (mp->l - (temp = floor(mp->l))) * PI2;
     mp->m = (mp->m - (temp = floor(mp->m))) * PI2;
     mp->f = (mp->f - (temp = floor(mp->f))) * PI2;
     mp->d = (mp->d - (temp = floor(mp->d))) * PI2;
     mp->n = (mp->n - (temp = floor(mp->n))) * PI2;
     mp->g = (mp->g - (temp = floor(mp->g))) * PI2;

     MemPtrFree(mp);
}

-- Keith Rollin
-- Palm OS Emulator engineer






"M. Edward Wilborne III" <[EMAIL PROTECTED]> on 09/09/2000 09:00:03 AM

Please respond to "Palm Developer Forum" <[EMAIL PROTECTED]>

Sent by:  "M. Edward Wilborne III" <[EMAIL PROTECTED]>


To:   "Palm Developer Forum" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/US/PALM)
Subject:  Re: CodeWarrior Compiler Glitch with temporary stack space?



Additional information...

With:

#pragma stack_cleanup on

in the code, there appears to be 1 additional assemply instruction added to
each function:

00000xxx: 4FEF 0014          lea       20(a7),a7

after the sysTrapFlpEmDispatch instruction.

However, the use of stack relative to A6 appears to be the same as it was
with the stack clean up set off.  Which still leads me to believe that the
expressions are using more stack space than necessary.

Ed

----- Original Message -----
From: "M. Edward Wilborne III" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Saturday, September 09, 2000 11:26 AM
Subject: CodeWarrior Compiler Glitch with temporary stack space?


> I apologize for the long nature of this message (with the assembly code in
> it, well it gets pretty large).
>
> This is just a snippet of working code, please disregard the fact that it
> returns no useful result.  It is intended as an example only.
>
> I was compiling a much larger version of this function ("useful results
> version") and kept having problems with stack overflows on Palm OS 3.0,
and
> 2.0, but the function would work fine on Palm OS 3.5.
>
> After taking a look at the disassembled version of the code, and trying to
> make heads of tails of what is going on, the conclusion that I have come
up
> with is that CodeWarrior is setting aside space on the stack for temporary
> or intermediate results, but doesn't appear to resuse that space once an
> expression is done with the intermediate result.  If you pile a bunch of
> expressions into the function, then codewarrior allocates a larger amount
of
> stack space, and eventually you can overflow the stack.



--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/tech/support/forums/





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to