[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Got strange compilation problem
From: |
David Bourgeois |
Subject: |
[avr-gcc-list] Got strange compilation problem |
Date: |
Thu, 16 Feb 2006 10:24:01 +0100 |
User-agent: |
Opera M2/8.51 (Win32, build 7712) |
Hi all,
Replacing the 2 lines
length = (p->inIdx) - (p->outIdx);
length %= FIFO_SIZE;
by
length = (((p->inIdx) - (p->outIdx)) % FIFO_SIZE);
completely broke my code. I'm using avr-gcc 3.4.5 (latest winavr release)
under avrstudio, -Os.
Here's the generated assembly part. I guess there something fundamentally
wrong I'm doing here because it also brake without optimization (-O0) but
with much bigger code and the failure behaves a bit different.
Thanks for any opinion about this.
David
uint8_t fifoLength(fifo_t *p)
{
uint8_t length;
length = (p->inIdx) - (p->outIdx);
length %= FIFO_SIZE;
return length;
}
@00000224: fifoLength
46: {
+00000224: 01FC MOVW R30,R24 Copy register pair
48: length = (p->inIdx) - (p->outIdx);
+00000225: 8580 LDD R24,Z+8 Load indirect with
displacement
+00000226: 8591 LDD R25,Z+9 Load indirect with
displacement
+00000227: 1B89 SUB R24,R25 Subtract without carry
49: length %= FIFO_SIZE;
+00000228: 7087 ANDI R24,0x07 Logical AND with
immediate
51: }
+00000229: 2799 CLR R25 Clear Register
+0000022A: 9508 RET Subroutine return
uint8_t fifoLength(fifo_t *p)
{
uint8_t length;
length = (((p->inIdx) - (p->outIdx)) % FIFO_SIZE);
return length;
}
@00000224: fifoLength
46: {
+00000224: 01FC MOVW R30,R24 Copy register pair
49: length = (((c) % FIFO_SIZE);
+00000225: 8580 LDD R24,Z+8 Load indirect with
displacement
+00000226: 2F28 MOV R18,R24 Copy register
+00000227: 2733 CLR R19 Clear Register
+00000228: 8581 LDD R24,Z+9 Load indirect with
displacement
+00000229: 1B28 SUB R18,R24 Subtract without carry
+0000022A: 0931 SBC R19,R1 Subtract with carry
+0000022B: 01C9 MOVW R24,R18 Copy register pair
+0000022C: FD37 SBRC R19,7 Skip if bit in register
cleared
+0000022D: 9607 ADIW R24,0x07 Add immediate to word
+0000022E: 7F88 ANDI R24,0xF8 Logical AND with
immediate
+0000022F: 1B28 SUB R18,R24 Subtract without carry
+00000230: 2F82 MOV R24,R18 Copy register
51: }
+00000231: 2799 CLR R25 Clear Register
+00000232: 9508 RET Subroutine return
Here, the problem occurs when p->inIdx) - (p->outIdx) is <0, then the
modulus is not done, the return value is 0xF9 for example.
- [avr-gcc-list] Got strange compilation problem,
David Bourgeois <=