[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is fault
From: |
anonymous |
Subject: |
[avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty |
Date: |
Sat, 24 Sep 2005 03:06:13 +0000 |
User-agent: |
|
Follow-up Comment #4, bug #14616 (project avr-libc):
Qualificator 'volatile' works fine in the above example.
Look, please, an expanded variant:
int acc;
int val;
int volatile acc_v;
int volatile val_v;
foo1(): no protection, loop is fully optimized:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void foo1 (void)
{
unsigned char i;
for (i = 10; i; i--) {
asm volatile ("cli");
acc += val; /* nonvolatile both */
asm volatile ("sei");
}
}
.L6:
/* #APP */
cli
/* #NOAPP */
add r24,r18
adc r25,r19
/* #APP */
sei
/* #NOAPP */
subi r20,lo8(-(-1))
brne .L6
foo2(): acc_v is protected, only val fetch is optimized:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void foo2 (void)
{
unsigned char i;
for (i = 10; i; i--) {
asm volatile ("cli");
acc_v += val; /* acc_v is volatile */
asm volatile ("sei");
}
}
.L15:
/* #APP */
cli
/* #NOAPP */
lds r24,acc_v
lds r25,(acc_v)+1
add r24,r18
adc r25,r19
sts (acc_v)+1,r25
sts acc_v,r24
/* #APP */
sei
/* #NOAPP */
subi r20,lo8(-(-1))
brne .L15
foo3(): val_v is protected, acc i/o is optimized:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void foo3 (void)
{
unsigned char i;
for (i = 10; i; i--) {
asm volatile ("cli");
acc += val_v; /* val_v is volatile */
asm volatile ("sei");
}
}
.L23:
/* #APP */
cli
/* #NOAPP */
lds r24,val_v
lds r25,(val_v)+1
add r18,r24
adc r19,r25
/* #APP */
sei
/* #NOAPP */
subi r20,lo8(-(-1))
brne .L23
foo4(): both are protected, all i/o is not optimized:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void foo4 (void)
{
unsigned char i;
for (i = 10; i; i--) {
asm volatile ("cli");
acc_v += val_v; /* both are volatile */
asm volatile ("sei");
}
}
.L32:
/* #APP */
cli
/* #NOAPP */
lds r24,acc_v
lds r25,(acc_v)+1
lds r18,val_v
lds r19,(val_v)+1
add r24,r18
adc r25,r19
sts (acc_v)+1,r25
sts acc_v,r24
/* #APP */
sei
/* #NOAPP */
subi r20,lo8(-(-1))
brne .L32
Is it possible to give an example, where 'volatile' variable is
not work (with simple sei()) ?
2.
Yes, sei() looks as function call. But there are many other
"almost functions", that ignore possible side effects.
For example:
#include <stdlib.h>
int acc, val;
void foo (void)
{
unsigned char i;
for (i = 10; i; i--) {
val = abs(val);
acc += val;
}
}
Without 'volatile': no protection, full optimization:
.L7:
mov r20,r24
mov r21,r25
sbrs r25,7
rjmp .L6
clr r20
clr r21
sub r20,r24
sbc r21,r25
.L6:
mov r25,r21
mov r24,r20
add r18,r20
adc r19,r21
subi r22,lo8(-(-1))
brne .L7
Dmitry.
_______________________________________________________
Reply to this item at:
<http://savannah.nongnu.org/bugs/?func=detailitem&item_id=14616>
_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, anonymous, 2005/09/22
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, anonymous, 2005/09/22
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, anonymous, 2005/09/22
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, anonymous, 2005/09/23
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty,
anonymous <=
- [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, anonymous, 2005/09/26
- Re: [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, Joerg Wunsch, 2005/09/26
- Re: [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, Russell Shaw, 2005/09/26
- Re: [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, Joerg Wunsch, 2005/09/27
- Re: [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, Dmitry K., 2005/09/26
- Re: [avr-libc-dev] [bug #14616] definition of sei() in interrupts.h is faulty, Björn Haase, 2005/09/27