Assembler Optimizer

صفحة 55/57
48 | 49 | 50 | 51 | 52 | 53 | 54 | | 56 | 57

بواسطة ARTRAG

Enlighted (6845)

صورة ARTRAG

07-01-2022, 06:41

You should add the same rule for IY and IX in place of HL
SDCC uses also those registers instead of ld (nnnn),a

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

07-01-2022, 11:38

ah, good point. I just generalized it to this:

pattern: replace ld ?reg2, a; ld ?reg16, ?const1; ld (?reg16), ?reg2 with ld (?const1), a
0: ld ?reg2, a
1: ld ?reg16, ?const1
2: ld (?reg16), ?reg2
replacement:
0: ld (?const1), a
constraints:
regsNotUsedAfter(2, ?reg2)
regsNotUsedAfter(2, ?reg16)
in(?reg16,bc,de,hl,ix,iy)

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

12-01-2022, 13:31

Hey @Arjan, I addressed all the issues you opened in GitHub (thanks for that, they were very useful!), and MDL works no on "that project", you can try it in the latest pre-release here: https://github.com/santiontanon/mdlz80optimizer/releases/tag...

to make it work on that project, just remember to use the "-quirk-sjasmplus-dirbol-double-directive" flag. Also, in order for include paths to work, the project expects that your current working directory is the "engine" folder inside of "that project", otherwise, some include files will not be found. I would recommend using the "-po" or "-po speed" flags. "-ro" could potentially be useful, but "-so" will take forever to run in this codebase haha

The project is enormous, so, MDL finds lots of potential optimizations, I hope some are useful!

Let me know if something does not work!

بواسطة Arjan

Paladin (768)

صورة Arjan

12-01-2022, 15:54

Thanks santiontanon! With the -po option it finishes in less than two minutes, but the -so is already running for a while. It will probably take an hour or so...

For big projects like this it would be very useful to be able to specify in which files MDL should look for optimizations.

Edit: Ok, -so finished in 25 minutes on an i3-10100, 981 optimization applied, 1289 bytes, 5195 t-states saved. -po found 2344 optimizations, 2438 bytes, 21544 t-states saved.

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

12-01-2022, 16:39

Cool!!! And wow, 25 minutes is faster than I expected haha. But good point, I'll take note of the suggestion of narrowing down the set of files for optimization! I hope some of the optimizations are useful! Smile

Also, btw, I would not trust the "-so" optimizations 100% yet, as that optimizer is still experimental. So, I'd proceed with care in implementing those Smile

بواسطة Arjan

Paladin (768)

صورة Arjan

12-01-2022, 23:32

There are a few issues with generating a bin and using the generated asm.

If I try to generate a bin with the -bin option it ends with an error:
Negative space (-966656) in [insertactualnameofthegame].asm#9855: ds $100000-totallenght

The generated rom is about 3.5MB while it should be 2MB.

When generating an asm file, MDL turns something like this:

slot:
.ram:

into

slot.ram

which makes sjasmplus unable to assemble the code because SLOT is a reserved keyword, resulting in a warning "SLOT only allowed in real device emulation mode (See DEVICE)" and errors like "Label not found: slot.ram".

I didn't know that there's a limit to label lengths in sjasmplus but apparently there is a limit "Labels are case-sensitive and may be of any reasonable length, that is: up to about 70 characters.". It complains about HandleControls.LocationJumpTableCastlesFortressesAndSwitchPalaces (which is less than 70 characters).

If I fix these issues, sjasmplus still ends with a warning "Negative BLOCK?". The generated rom is about 1.92MB so it's too small. I increased the file size to 2MB by appending 0's and compared the result with the original rom, at least the files are the same so that's good Smile

I'll try to see if I can find out where these size issues come from.

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

13-01-2022, 00:35

Oh!!! ok, I think probably what might be happening is that MDL doesn't fully implement yet a lot of the sjasmplus functionality (only sufficient to parse it and generate optimizations), but there's a few things (e.g. like "slot" above) is is probably not understanding correctly.

But this is good to know! I'll add this project to my test suite, and will make sure MDL can generate a correct binary for it! MDL will probably be much slower than sjasmplus in assembling (I'd still use sjasmplus for that), but at least it should generate a correct binary if desired!

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

13-01-2022, 04:17

I've been looking at this, and I think I know the problem! It seems that even when using the "--longptr" option, sjasmplus clamps all the addresses at "1MB". I've been tracking the addresses in the different parts of the code, and once it passes 1MB, sjasmplus loops back to 0, while MDL keeps counting up. So, the final line of the code, that looks like this is problematic:

    ds $100000 - totallenght ;fill er up to the end

Notice that $100000 is exactly 1MB, but the ROM should be 2MB, so, that line should actually be:

    ds $200000 - totallenght ;fill er up to the end

Since sjasmplus seems to clamp at 1MB, the original code works in sjasmplus, as "totallenght" is incorrect. In MDL, "totallenght" is correct (2015232), and $100000 - 2015232 is a negative number.

I have not tried generating an optimized binary yet, I was just trying to generate a regular binary with -bin. But at least I think this is a clue. (also, I fixed a couple of bugs in MDL, so, it might be worth re-downloading the development release from the link above just in case)

@Ped7g if you read this, could you confirm my suspicion about the 1MB limit in sjasmplus? (or at least the limit with the default "device").

بواسطة santiontanon

Paragon (1639)

صورة santiontanon

13-01-2022, 13:12

Ok, solved!

There were two problems:
1) The one I mentioned above of the addresses (I'm still curious to learn about sjasmplus intended behavior there!)
2) There was a bug in the handling of the "size" parameter of incbin in MDL. Fixed (and temporary release updated here: https://github.com/santiontanon/mdlz80optimizer/releases/tag... )

Now the binary has the expected size (if you change "ds $100000" to "ds $200000" as I mentioned above!).

The optimized binary displays some scrolling jerkiness, so, it seems some optimization is breaking something, but that's something we can look at separately :)

بواسطة Arjan

Paladin (768)

صورة Arjan

13-01-2022, 14:05

Great!

Yeah when I applied some optimizations I noticed that jerky scrolling too, but I don't remember exactly what caused it...

صفحة 55/57
48 | 49 | 50 | 51 | 52 | 53 | 54 | | 56 | 57