[A83] Z88DK vs. SDCC
[Prev][Next][Index][Thread]
[A83] Z88DK vs. SDCC
Consider the following code:
main ()
{
int i, j, k;
i = 23;
j = 45;
k = i * j;
return k;
}
Z88DK produces:
push bc
push bc
push bc
ld hl,4
add hl,sp
push hl
ld hl,23
pop de
call l_pint
ld hl,45
pop de
pop bc
push hl
push de
ld hl,4
add hl,sp
call l_gint
push hl
ld hl,4
add hl,sp
call l_gint
pop de
call l_mult
pop bc
push hl
ld hl,0
add hl,sp
call l_gint
pop bc
pop bc
pop bc
ret
SDCC produces:
push bc
push de
push ix
ld ix,#0
add ix,sp
ld hl,#0x040B
pop ix
pop de
pop bc
ret
Note how much better this is, even though it saves BC & DE and creates a
stack pointer for no reason. In a normal routine, saving BC & DE and
creating a stack pointer would all be necessary. This shows how much it
matters for the compiler itself to be good, and not just some sort of
peephole optimizer. Note that the SDCC code wasn't run through a peephole
optimizer (doesn't seem it would've helped this out much), whereas the Z88DK
code was. It was even worse before the peephole optimizer.