#655 Code generator selects incorrect registers

closed-fixed
z80 port (188)
5
2009-04-03
2003-12-06
JC
No

This is from the 2003/12/03 nightly snapshot. The first
fragment from the .asm file is correct, the second is bad. The
addition of a printf() changes the register allocation strategy.
With the printf() in the good code, line 1352 correctly
calculates and stores uip_len. Without the printf(), it forgets
the HL register pair is in use (which contains uip_connr->len),
loads the address of uip_len into it, destroying the previous
value.

Unfortunately, the code is far too long to upload a test case,
but I will be happy to test any build and provide feedback.

----------------------------------------------------------------------------------
Good code

;uip.c:1350: if(uip_slen > 0 && uip_connr->len > 0) {
; genIfx
ld iy,#_uip_slen
ld a,0(iy)
or a,1(iy)
jp z,00299$
; genPlus
; AOP_STK for _uip_process_uip_connr_1_1
; genPlusIncr
; Can't optimise plus by inc, falling back to the normal way
ld a,-2(ix)
add a,#0x10
ld l,a
ld a,-1(ix)
adc a,#0x00
ld h,a
; genPointerGet
ld e,(hl)
inc hl
ld d,(hl)
; genIfx
ld a,e
or a,d
jp z,00299$
;uip.c:1352: uip_len = uip_connr->len + UIP_TCPIP_HLEN;
; genPlus
; genPlusIncr
; Can't optimise plus by inc, falling back to the normal way
; Shift into pair idx 0
ld hl,#_uip_len
ld a,e
add a,#0x28
ld (hl),a
ld a,d
adc a,#0x00
inc hl
ld (hl),a
;uip.c:1354: BUF->flags = TCP_ACK | TCP_PSH;
; genPlus
; genPlusIncr
ld hl,#_uip_buf + 33
; genAssign (pointer)
; isBitvar = 0
ld (hl),#0x18
;uip.c:1356: printf ("going to tcp_send_noopts1,
uip_connr->len=%d,UIP_TCP_HLEN=%d\r\n",
uip_connr->len, UIP_TCPIP_HLEN); // JCW
; genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 0 bcInUse: 0
deSending: 0
ld hl,#0x0028
push hl
; genIpush
push de
; genIpush
ld hl,#__str_22
push hl
; genCall
call _printf
pop af
pop af
pop af
;uip.c:1357: goto tcp_send_noopts;
; genGoto
jp 00336$

----------------------------------------------------------------------------------
Bad code

;uip.c:1350: if(uip_slen > 0 && uip_connr->len > 0) {
; genIfx
ld iy,#_uip_slen
ld a,0(iy)
or a,1(iy)
jp z,00299$
; genPlus
; AOP_STK for _uip_process_uip_connr_1_1
; genPlusIncr
; Can't optimise plus by inc, falling back to the normal way
ld a,-2(ix)
add a,#0x10
ld l,a
ld a,-1(ix)
adc a,#0x00
ld h,a
; genPointerGet
ld a,(hl)
inc hl
ld h,(hl)
; genIfx
ld l,a
or a,h
jp z,00299$
;uip.c:1352: uip_len = uip_connr->len + UIP_TCPIP_HLEN;
; genPlus
; genPlusIncr
; Can't optimise plus by inc, falling back to the normal way
; Shift into pair idx 0
ld hl,#_uip_len
ld a,l
add a,#0x28
ld (hl),a
ld a,h
adc a,#0x00
inc hl
ld (hl),a
;uip.c:1354: BUF->flags = TCP_ACK | TCP_PSH;
; genPlus
; genPlusIncr
ld hl,#_uip_buf + 33
; genAssign (pointer)
; isBitvar = 0
ld (hl),#0x18
;uip.c:1357: goto tcp_send_noopts;
; genGoto
jp 00336$

Discussion

  • Erik Petrich

    Erik Petrich - 2003-12-11

    Logged In: YES
    user_id=635249

    With src/z80/ralloc.c 1.66 I have temporarily disabled the
    use of HL for inter-iCode temporaries. In another week or
    two I should have a big enough block of free time to
    concentrate to work out a good long-term solution.

     
  • Erik Petrich

    Erik Petrich - 2003-12-11
    • assigned_to: nobody --> epetrich
    • status: open --> open-accepted
     
  • Philipp Klaus Krause

    I have reenabled the use of hl as inter-iCode temporary in sdcc 2.9.1 #5426. I have made a small change in register allocation which should help with this problem.

    Philipp

     
  • Philipp Klaus Krause

    • assigned_to: epetrich --> spth
    • status: open-accepted --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks