santiontanon / mdlz80optimizer

MDL (a Z80 assembler optimizer)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search-based optimization with negative t-states saved

abekermsx opened this issue · comments

In the following case:
ld a,(label1)
ld e,a
ld d,0
ld a,(label2)

The search-based optimization suggests to replace 'ld a,(label1); ld e,a' with 'ld de,(label1)', saving 0 bytes and -3 t-states.

Ah, this could have been because the default objective is to minimize the number of instructions, and in this case it reduced from 2 to 1. I see that this can be confusing though, and maybe I should set the default to minimize bytes instead? I have it to minimize the number of instructions by default, since that's the easies objective, and the one that can be done with the least computation :)

Ah ok, I really should've read the exhaustive list of flags :) Personally I'm not interested in reducing the number of instructions but I guess everybody has their own preferences.

To prevent this confusion, I have created a new search objective (minimizing ops, but ensuring at least some improvement in size or time), and made it the new default. I do not want to make size or speed the default, as those searches are more computationally expensive. So, they should be selected only when the user really wants that.

This is done in this commit, and should be included in the upcoming 2.3 release: 905a447

Thanks for reporting! I created a unit test with the example you provided above (as I had never encountered this before! haha). So, this was very useful!