Assembler Optimizer

Page 29/57
22 | 23 | 24 | 25 | 26 | 27 | 28 | | 30 | 31 | 32 | 33 | 34

By thegeps

Paragon (1031)

thegeps's picture

06-02-2021, 16:34

What a great work! Respect!

By santiontanon

Paragon (1639)

santiontanon's picture

08-02-2021, 05:21

hehe, thanks! Smile

Did quite a lot of progress over the weekend, lots of debugging and added a bunch of unit tests to make sure the new "code reorganizer" optimizer works and does what is expected. I have also tested running the two optimizers in tandem: first the reorganizer followed by the pattern-based optimizer, and it seems work work well and produce working roms!

I am now finishing a little bit more work on initial support for sjasmplus, and I'll push a new release some time during the week (if anyone has more pointers to open source projects that use sjasmplus, that'd be of great help, thanks!)

By santiontanon

Paragon (1639)

santiontanon's picture

13-02-2021, 15:40

Version 1.4 is out, which includes both the new "code reorganizer" optimizer, and also initial support for sjasmplus Smile

Latest version here: https://github.com/santiontanon/mdlz80optimizer/releases

And a couple of videos explaining the features MDL has so far, and how to use them (apologies in advance as apparently while putting the video together there was some cropping at the top/bottom of the screen, but I hope the video is still understandable):

- in English: https://www.youtube.com/watch?v=2M8la7TuCzw

- In Spanish: https://www.youtube.com/watch?v=yVniGPu-znc

By Bengalack

Hero (590)

Bengalack's picture

13-02-2021, 18:08

I checked out the video. Awesome stuff - Love it!

I have a big c-file: 7200 lines. From this command:

java -jar mdl.jar Debug\objs\game.asm -dialect sdcc -poapply -po

I (already) got this:

INFO: PatternBasedOptimizer: 77 patterns applied, 71 bytes, 559 t-states saved.

Great! Then I added the speed-argument:

java -jar mdl.jar Debug\objs\game.asm -dialect sdcc -poapply -po speed

And I got this:

INFO: PatternBasedOptimizer: 90 patterns applied, 84 bytes, 602 t-states saved.

Even greater!!!

Then I wanted to use the "ro". But then it seemed like it was not applied anywhere(?) (like in -poapply). Was it? So I thought I'd add the -asm-flag. And then it seems like I head into the issue where writing asm for SDCC is a bit complicated :-)

INFO: PatternBasedOptimizer: 90 patterns applied, 84 bytes, 602 t-states saved.
INFO: Generating optimized file Debug\objs\game.asm.mdl.asm
INFO: mdl optimization summary: 153 bytes, 923 t-states saved. CodeReorganizer moves: 27. Pattern-based optimizer pattern applications: 90.

The generated asm cannot be understood by sdasz80 (as it could with "-poapply") :-(

The trick in the build-process is to pass this file on to sdasz80 using the "g"-flag, just telling sdasz80 to treat all unknown symbols as globals/external, so:

sdasz80 -o -s -w -g Debug\objs\game.rel Debug\objs\game.asm.mdl.asm

But using "-asm" chokes on things like this:

_g_bLevelLoaded:
    .ds 1, 0

To the best of my knowledge sdasz only accepts ".ds 1", it cannot accept default/fill value.

I also see this:

.db #0x20	 

being set to this:

.byte 0x20

-byte should work, but the number must be prefixed with "#".

And array of chars:

.byte "You can now"

must be written as

.ascii "You can now"

(or something similar found here: https://shop-pdp.net/ashtml/asmlnk.htm )

What to do? :-)

By santiontanon

Paragon (1639)

santiontanon's picture

13-02-2021, 18:36

Thanks for all of this testing Bengalack!

Unfortunately, the "-poapply" flag only applies to the pattern-based optimizer for now (added a "todo" item to expand to the other optimizer). Exactly as you say, it's the problem of MDL not yet being able to properly generate sdasz80 code.

But, I should be able to address at least a few of the issues above! I just added a few items to my to-do list (for the ".ds", ".db", and ".byte" things). I'll fix those later today, so, hopefully bit by bit we'll manage to make it fully work on SDCC Smile

ps: very cool new video of your platformer project (which I guess is the one you are testing!), I have seen several people in Spanish Whatsapp/Telegram groups being excited about it today Smile

By Bengalack

Hero (590)

Bengalack's picture

13-02-2021, 19:42

santiontanon wrote:

ps: very cool new video of your platformer project (which I guess is the one you are testing!)

Yes it is.

santiontanon wrote:

I have seen several people in Spanish Whatsapp/Telegram groups being excited about it today Smile

That's so nice to hear!

Another thing: It seems like the .area-directive is translated too. This is a little outside my normal domain, but I think SDCC-linker needs this information somehow.

.area _DATA

Becomes:

s__DATA:

I have a feeling this might not work. But I guess we will find out soon Smile

By santiontanon

Paragon (1639)

santiontanon's picture

14-02-2021, 04:22

oh, true! the ".area" directives should remain there! I'm still half way implementing this. I'm adding a new command-line argument like "-asm", but called "-asm-dialect", which tries to mimic the target dialect when generating assembler. For now, I am focusing on the SDCC use case for this, but I'll slowly expand to the other dialects. Might take me a day or two to get this done, but will ping here. I think that with this, the SDCC integration should be easier!

By jltursan

Prophet (2619)

jltursan's picture

14-02-2021, 10:49

Sad

I've finally tried the optimizer with some sjasm code and seems that it doesn't fully supports all the compiler syntax, am I wrong?. I've used the latest version and used "-dialect sjasm -poapply -po" parameters.

Apparently it has problems expanding macros like "ifexists" or "ifdifi", also seems to parse "phase/dephase" as macros (!). The errors seems too complex and even to get to this point I've needed first to polish a bit the code replacing all the "defpage/page" syntax as the first error was a "NullPointer".

I can provide more info; but at first sight, seems a daunting task to make it work Crying

By santiontanon

Paragon (1639)

santiontanon's picture

14-02-2021, 15:37

Hi jitursan, thanks for testing! Indeed, not all the syntax is supported yet. What I have been doing is to get all the projects I could find using sjasm from GitHub, and implement all that was needed to support those (sjasm has a crazy number of directives, so, it'll take forever to support them all hahaha). So, I'm adding as needed. But good to know this! indeed "phase/dephase/ifexists/ifdifi" are not yet supported (added to the to-do list!!). Do not bother modifying your code to make it work with MDL, I should just update MDL to make sure it's more robust hehe Smile

But if by any chance the sjasm project you are trying is in github or somewhere online, do let me know, so I can test it myself Smile

By jltursan

Prophet (2619)

jltursan's picture

14-02-2021, 17:35

Also good to know!. In fact it has been a crazy experiment as the AGD compiler project I'm working on, generates, obviously, a very unoptimized and rough code. I was thinking that maybe it could be a really great target to an assembler optimizer, seems like a real challenge to get something nice from this code Big smile
I can provide whatever sources you need!, here's for example a small one: https://www.sendspace.com/file/b9vcm5
All you need is packed, to compile as is, use "sjasm test.asm" and a test.rom will be generated.

Page 29/57
22 | 23 | 24 | 25 | 26 | 27 | 28 | | 30 | 31 | 32 | 33 | 34