Hi,
I'm wondering why gcc doens't release the stack immediatly after
calling such functions which need arguments passed on the stack.
Example:
==================================================================
void test(){
print("%i %i %i\r\n", 1, 2, 3, 4);
728a: 30 12 04 00 push #4 ;#0x0004
728e: 30 12 03 00 push #3 ;#0x0003
7292: 23 12 push #2 ;r3 As==10
7294: 13 12 push #1 ;r3 As==01
7296: 30 12 7e 72 push #29310 ;#0x727e
729a: b0 12 62 7e call #32354 ;#0x7e62
print("%i %i %i\r\n", 8, 7, 6, 5);
729e: 30 12 05 00 push #5 ;#0x0005
72a2: 30 12 06 00 push #6 ;#0x0006
72a6: 30 12 07 00 push #7 ;#0x0007
72aa: 30 12 08 00 push #8 ;#0x0008
72ae: 30 12 7e 72 push #29310 ;#0x727e
72b2: b0 12 62 7e call #32354 ;#0x7e62
argtest(1, 2, 3, 4, 5, 6, 7, 8);
72b6: 30 12 08 00 push #8 ;#0x0008
72ba: 30 12 07 00 push #7 ;#0x0007
72be: 30 12 06 00 push #6 ;#0x0006
72c2: 30 12 05 00 push #5 ;#0x0005
72c6: 2c 42 mov #4, r12 ;r2 As==10
72c8: 3d 40 03 00 mov #3, r13 ;#0x0003
72cc: 2e 43 mov #2, r14 ;r3 As==10
72ce: 1f 43 mov #1, r15 ;r3 As==01
72d0: b0 12 7c 72 call #29308 ;#0x727c
special();
72d4: b0 12 7a 72 call #29306 ;#0x727a
72d8: 31 50 1c 00 add #28, r1 ;#0x001c
}
72dc: 30 41 ret
==================================================================
The stack is only cleaned once at 72d8, but i'd like to see it directly
after each call.
This is surely a nice optimization, but doesn't that also mean, that
the function special can't go as deep as it could go if the stack
is cleand up after each function call (in this example, special
would have 28 bytes less stack space because of both prints and argtest) ???
And that for the cost of some adds ?
One way i found to force stack cleanup before another function call is
to put a goto label in front of that function call:
==================================================================
void test(){
print("%i %i %i\r\n", 1, 2, 3, 4);
728a: 30 12 04 00 push #4 ;#0x0004
728e: 30 12 03 00 push #3 ;#0x0003
7292: 23 12 push #2 ;r3 As==10
7294: 13 12 push #1 ;r3 As==01
7296: 30 12 7e 72 push #29310 ;#0x727e
729a: b0 12 62 7e call #32354 ;#0x7e62
print("%i %i %i\r\n", 8, 7, 6, 5);
729e: 30 12 05 00 push #5 ;#0x0005
72a2: 30 12 06 00 push #6 ;#0x0006
72a6: 30 12 07 00 push #7 ;#0x0007
72aa: 30 12 08 00 push #8 ;#0x0008
72ae: 30 12 7e 72 push #29310 ;#0x727e
72b2: b0 12 62 7e call #32354 ;#0x7e62
argtest(1, 2, 3, 4, 5, 6, 7, 8);
72b6: 30 12 08 00 push #8 ;#0x0008
72ba: 30 12 07 00 push #7 ;#0x0007
72be: 30 12 06 00 push #6 ;#0x0006
72c2: 30 12 05 00 push #5 ;#0x0005
72c6: 2c 42 mov #4, r12 ;r2 As==10
72c8: 3d 40 03 00 mov #3, r13 ;#0x0003
72cc: 2e 43 mov #2, r14 ;r3 As==10
72ce: 1f 43 mov #1, r15 ;r3 As==01
72d0: b0 12 7c 72 call #29308 ;#0x727c
goto l;
72d4: 31 50 1c 00 add #28, r1 ;#0x001c
l: special();
72d8: b0 12 7a 72 call #29306 ;#0x727a
}
72dc: 30 41 ret
==================================================================
Now (at least) the stack is cleaned before the special call.
Is there any nicer way to achieve this behaviour?
There seems to be a threshhold for stack clean up, because
if i move in more prints, the stack gets cleaned in between.
The value for this lies somewhere between 30 and 40 bytes.
Can i somehow just set this to zero and so force
stack cleanup after every call?
Is this a gcc or mspgcc issue?!
Thanks in advance,
Björn Lichtblau
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.