Is there a good way to get the SDCC compiler to produce decent Z80 output
when handling long types. I'm getting some really long and quite
revolting code out of sdcc whenever I have longs involved

Stuff like

        ld      -4 (ix),l
        ld      -3 (ix),h
        ld      -2 (ix),c
        ld      -1 (ix),b
        pop     af
        ld      a,#0x10
00115$:
        sla     -4 (ix)
        rl      -3 (ix)
        rl      -2 (ix)
        rl      -1 (ix)
        dec     a
        jr      NZ,00115$

        (and then goes on and loads them into registers...!)


Rather than generating

00115$: sla     l
        rl      h
        rl      c
        rl      b
        dec     a
        jr nz, 00115$



Initializers like

;devsd.c:134: sd_first_uzi_sector = 0;
        xor     a, a
        ld      (#_sd_first_uzi_sector + 0),a
        ld      (#_sd_first_uzi_sector + 1),a
        ld      (#_sd_first_uzi_sector + 2),a
        ld      (#_sd_first_uzi_sector + 3),a
;devsd.c:135: sd_blockdev_count = 0;
        ld      hl,#_sd_blockdev_count + 0
        ld      (hl), #0x00
        ld      hl,#_sd_blockdev_count + 1
        ld      (hl), #0x00

rather than
        xor     a
        ld      hl, #_sd_first_uzi_sector
        ld      (hl), a
        inc     hl
        ld      (hl), a
        ...
        ld      hl, #_sd_blockdev_count
        ld      (hl), a
        inc     hl
        ld      (hl), a


and also weirdness like

        ld      -1 (ix),d
        ld      -2 (ix),e
        ld      -3 (ix),h
        ld      -4 (ix), l
        ld      -4 (ix), l
        ld      a,-3 (ix)
        ld      -3 (ix),a

at which point I'm in the 'stare in disbelief' state.

Some of it works better being split into tiny functions but then the
function call overhead (passing 32bit values by pointer, lack of argument
passing in registers for simple arguments) produce call/entry/exit
overhead thats as bad as the first case.

Currently using sdcc 3.3.0 and -mz80 --opt-code-size --max-allocs-per-node
5000 --Werror --stack-auto

The integer and pointer code is in most cases quite respectable (except
for the poor function calling API) it's just "long" that seems to make
the compilers brains fall out.

Using max-allocs-per-node=10000 fixes some but introduces other bizarre
bits out output like

        push    hl
        push    hl
        pop     hl
        pop     iy
        
and takes ages to run.

It's also noticable the compiler seems to like to generate weirdness like

        pop     af
        ld      hl, something
        push    hl
        [reloads hl with something different before reuse]

not the expected

        ld      hl, something
        ex      (sp), hl

which is 2 clocks faster and 1 byte shorter, and even more efficient when
the return value is in HL and being used as the argument.

Alan

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to