Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unnecessary Push/Pop
#4
britlion Wrote:Straight to assembler, without O3 -

Turns the relevant part into:
Code:
_pokethis:
    push ix
    ld ix, 0
    add ix, sp
    ld hl, __LABEL__label
    inc hl
    push hl
    ld a, (ix+5)
    pop hl
    ld (hl), a
    jp _pokethis__leave
__LABEL__label:
#line 6
        LD A,00
And it's OK:
POKE Expr1, Expr2 could be something like:
Code:
POKE 10, 2
or something very complicated like
Code:
POKE SIN(EXP(3*LN 52)) / RND * 72, RND *45 + USR "a" OR 1
both expressions are correct and must be allowed (or even more complicated ones). Since ZX have few registers and most of them 8 bits and many other limitations, a stack must be used to carry out math operations, etc. Thus the compiler calculates 1st expression, saves it in the stack (to free registers), calculates the 2nd, and recovers the 1st from the stack. No optimization can be done at this stage.

Optimization in the backend stage (pipeline, -O3) knows this (to some extent).

Britlion Wrote:With O3, it does certainly see the optimization, showing that the optimizer module is very impressive!
;-) thx!
Britlion Wrote:The other thing that I'm curious about (as I noted in the other post, with this code in it), is that it doesn't load HL with [@label+1] - it loads it with @label, and then does inc HL. This isn't optimized by -O3.
I'll answer that in the other topic, BTW, moved to Whislist forum.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)