[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] -O3 problem
From: |
Dean Ferreyra |
Subject: |
[avr-gcc-list] -O3 problem |
Date: |
Thu, 17 May 2001 20:28:09 -0700 |
Hi,
I am running into this problem: I'm using a couple of layers of inline
functions. When I compile with -O3 the generated assembly code changes the
value of r29 which is busy in this function as the frame pointer. When the
function wants to return, this value gets copied back as the stack pointer
killing the stack. I've included a distilled sample below that trigger the
problem and I've included the assembly output. The problematic assignment
to r29 can be seen on the third line after the prolog.
I'm using CVS updates from May 16, 2001 for binutils and gcc. My host is
cygwin.
My current workaround is to compile with -O2 or where possible change the
function so that avr-gcc does not use an explicit stack frame pointer.
Dean Ferreyra
address@hidden
--------------------
Makefile
--------------------
CC=avr-gcc
AR=avr-ar
CFLAGS=-Wall -O3 -mmcu=atmega103
%.s: %.c ; $(CC) $(CFLAGS) -S $*.c
bug01.s: bug01.c
--------------------
bug01.c
--------------------
void exec_cmd(unsigned cmd,
const unsigned* cmd_data, char cmd_data_size,
unsigned* reply_data, char reply_data_size);
inline static void set_a16(char cmd, char axis, unsigned value)
{
exec_cmd(1, 0, 1, 0, 1);
}
inline static void set_source(char axis, char source)
{
set_a16(1, axis, source);
}
void fn(void)
{
unsigned data[10];
data[0] = 0;
set_source(1, 0);
set_source(1, 0);
}
--------------------
bug01.s
--------------------
.file "bug01.c"
.arch atmega103
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
_PC_ = 2
.text
.global fn
.type fn,@function
fn:
/* prologue: frame size=20 */
push r14
push r15
push r16
push r17
push r28
push r29
in r28,__SP_L__
in r29,__SP_H__
sbiw r28,20
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28
/* prologue end (size=14) */
std Y+1,__zero_reg__
std Y+2,__zero_reg__
ldi r29,lo8(1)
clr r14
clr r15
mov r16,r29
mov r19,r15
mov r18,r14
mov r20,r29
mov r23,r15
mov r22,r14
ldi r24,lo8(1)
ldi r25,hi8(1)
call exec_cmd
mov r19,r15
mov r18,r14
mov r20,r29
mov r23,r15
mov r22,r14
ldi r24,lo8(1)
ldi r25,hi8(1)
call exec_cmd
/* epilogue: frame size=20 */
adiw r28,20
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28
pop r29
pop r28
pop r17
pop r16
pop r15
pop r14
ret
/* epilogue end (size=13) */
/* function fn size 51 (24) */
.Lfe1:
.size fn,.Lfe1-fn
/* File bug01.c: code 51 = 0x0033 ( 24), prologues 14, epilogues 13 */
- [avr-gcc-list] -O3 problem,
Dean Ferreyra <=