Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#11 hc08: bugfix for bitops in Ifx

closed-rejected
Erik Petrich
None
5
2004-01-20
2004-01-17
Bjorn Bringert
No

The current CVS version of the hc08 compiler generates
incorrect code for bitwise binary operator when they
are used as the condition in an if och while statement.
This attached patch fixes that problem.

test.c:

volatile data unsigned char at 0x3a UIR1;

#define nop() _asm nop _endasm

void main (void)
{
if (UIR1 & 0x40)
nop();
if (UIR1 | 0x40)
nop();
if (UIR1 ^ 0x40)
nop();
}

Compiling with 'sdcc -mhc08 test.c' gives:

_main:
;test.c:7: if (UIR1 & 0x40)
; genAnd
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00102$
00112$:
;test.c:8: nop();
; genInline
nop
00102$:
;test.c:9: if (UIR1 | 0x40)
; genOr
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00104$
00113$:
;test.c:10: nop();
; genInline
nop
00104$:
;test.c:11: if (UIR1 ^ 0x40)
; genXor
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00107$
00114$:
;test.c:12: nop();
; genInline
nop
00107$:
rts

No code is generated for the conditions. The problem
seems to be the the result type of those expressions
are AOP_CRY, and they have size = 0. This means that 0
and, or, or eor instructions are generated. The
attached patch loops over the the size of the left
operand if the result type is AOP_CRY.
With the patch applid, the above code compiles to:

_main:
;test.c:7: if (UIR1 & 0x40)
; genAnd
; loadRegFromAop (a, DIR(_UIR1), 0)
lda *_UIR1
and #0x40
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00102$
00112$:
;test.c:8: nop();
; genInline
nop
00102$:
;test.c:9: if (UIR1 | 0x40)
; genOr
; loadRegFromAop (a, DIR(_UIR1), 0)
lda *_UIR1
ora #0x40
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00104$
00113$:
;test.c:10: nop();
; genInline
nop
00104$:
;test.c:11: if (UIR1 ^ 0x40)
; genXor
; loadRegFromAop (a, DIR(_UIR1), 0)
lda *_UIR1
eor #0x40
; genIfx
; genIfxJump
; Peephole 2d - eliminated jmp
beq 00107$
00114$:
;test.c:12: nop();
; genInline
nop
00107$:
rts

Discussion

  • Bjorn Bringert
    Bjorn Bringert
    2004-01-17

    Patch for src/hc08/gen.c

     
  • Erik Petrich
    Erik Petrich
    2004-01-20

    Logged In: YES
    user_id=635249

    The patch works for char sized operands, but fails for
    larger sizes. I've implemented a more general solution in
    src/hc08/gen.c 1.12. Nevertheless, thanks for the help.

     
  • Erik Petrich
    Erik Petrich
    2004-01-20

    • assigned_to: nobody --> epetrich
    • status: open --> closed-rejected