Assembler Optimizer

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

By santiontanon

Paragon (1636)

santiontanon's picture

14-02-2021, 20:25

@Bengalack: I have a development version of MDL, that I hope is much more compatible with SDCC if you want to try it out. I uploaded it here ( https://braingames.santiontanon.dev/uploads/mdl.jar ). The way to trigger the new functionality (I will have to clean up the command line flags at some point haha), will be like this:

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

The new "-asm-dialect" flag is the same as "-asm", but tries to mimic the syntax of the target dialect. I plan to deprecate the "-poapply" flag that was an experiment that didn't work very well as it just tries to manipulate the original source code (as a string of text) to include the modifications, and it is very messy :)

@jitursan: thank you so much!! That is awesome! I'll be doing tests this week to make sure mdl works with that code base, and will ping back here once I have it working!

By jltursan

Prophet (2619)

jltursan's picture

14-02-2021, 20:32

Wow, cool!!.

I'm still thinking that it would be hard to tune. The "page allocation mode" (don't know how to call it) of sjasm it's really powerful but it could turn some optimizations into a nightmare. Every block of code with a "page" heading will be automatically relocated in the specified page/s starting with the bigger ones and ending with the smallest. Really nice; but you lose a bit of control of where the code is exactly located.

By thegeps

Paragon (1029)

thegeps's picture

14-02-2021, 21:26

Does MDL support megaroms yet?

By santiontanon

Paragon (1636)

santiontanon's picture

14-02-2021, 23:06

Ah yes, the "blocking" mechanism of sjasm was a pain to replicate (I had to reverse engineer it inside of MDL!). I haven't tested it very thoroughly (only with a few projects I found on github), but on the projects I tried, mdl places the pages in the same locations as sjasm. So, hopefully I implemented it using the same logic haha. But we'll see, when I get to test with your code base, that'll give me one more data point Smile

As for megaroms, in principle yes! again, it will probably need testing, but in principle I have the paging directives of asmsx/sjasm implemented. So, unless there are bugs (which is possible haha), it should work Smile

By Bengalack

Hero (580)

Bengalack's picture

14-02-2021, 23:30

santiontanon wrote:

@Bengalack: I have a development version of MDL, that I hope is much more compatible with SDCC if you want to try it out. I uploaded it here ( https://braingames.santiontanon.dev/uploads/mdl.jar ). The way to trigger the new functionality (I will have to clean up the command line flags at some point haha), will be like this:

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

The new "-asm-dialect" flag is the same as "-asm", but tries to mimic the syntax of the target dialect.

Super nice!

I have tried it (the visual link works - the hyperlink does not, BTW), but it chokes on "$".

dasz80 -o -s -w -g Debug\objs\game.rel Debug\objs\game.asm.mdl.asm
Debug\objs\game.asm.mdl.asm:819: Error:  .org in REL area or directive / mnemonic error

line 818-820 in the mdl-file:

; ---------------------------------
_printdos:: equ $
  ;printdos.h:43: __endasm;
CONOUT .equ 0x02

line 818-820 in the original asm-file:

; ---------------------------------
_printdos::
;printdos.h:43: __endasm;
CONOUT	.equ 0x02

I haven't really used $ much, so I cannot say exactly how to use this in SDCC/sdasz. But according to https://shop-pdp.net/ashtml/asmlnk.htm and "1.3.4 Current Location Counter", it is "." (dot). But one cannot just swap the $ with a dot in the case above.

Anyways, in the case above, it seems like the $ should just be omitted totally, and we would be good to go.

So I tried that, and it seems to work, at least sdasz80 does not complain.

But when I try the "-ro"-switch, there is a complaint like this:

Debug\objs\game.asm.mdl.asm:7079: Error: <u> undefined symbol encountered during assembly

Line 7079:

    jp 00110$

When I look, there are several "00110$" in the file. According to the same doc as mentioned above this is "1.3.3 Reusable Symbols". Yup. Some kind of scope defines where is starts and where it ends. Sooo :) Maybe if we can find out how that scope is, then things might work soon :)

Kudos on the great progress so far BTW :)

By Bengalack

Hero (580)

Bengalack's picture

14-02-2021, 23:33

So the scope is this: "The range of a reusable symbol block consists of those statements between two normally constructed symbolic labels". So, I guess "normally constructed" means non-reusable, or those without "$"? Maybe you must parse the file once, and make them all unique first?

By santiontanon

Paragon (1636)

santiontanon's picture

14-02-2021, 23:36

Thanks for testing to quickly! Ah, I think I see the problem with "-ro"... indeed those local labels will require a bit more tracking when the reorganizer moves them outside of the scope where they were originally defined. But definitively doable Smile

[edit: the idea you propose of making them all unique first is also another option that might be easier! Added to the potential solutions, and let's see what is easier to implement, thanks for the suggestion! Smile]

As for the "$", definitively that should not be there! I'll make sure it goes awa. MDL inserts that to prevent a corner case in the Glass assembler, but it should really only be generated when the dialect is Glass. So, I'll remove that. That's an easy fix Smile

By Bengalack

Hero (580)

Bengalack's picture

15-02-2021, 20:49

From the demo we see that "-po size" can swap JP to JR, shouldn't "-po speed", do the opposite?

By santiontanon

Paragon (1636)

santiontanon's picture

15-02-2021, 23:40

ah! good point! when a jr is unconditional, it's always slower than a jp, so, it could be changed by a jp! I just added this pattern, thanks for the suggestion! Big smile

also, I do not have either the SDCC nor the sjasm (for AGD) issues fully resolved yet, but I have some progress in a new test version ( https://braingames.santiontanon.dev/uploads/mdl.jar ):
- for SDCC the "equ $" should have been resolved.
- for sjasm, I have added support for phase/dephase/ifexists/ifnexists/ifdif/ifdifi and labels starting with "@", which were all needed to parse the AGD example shared by jltursan

But in order to make MDL fully work for both the SDCC and AGD use cases, I still need to fix these:
- the code-reorganizer messes up jump tables (thanks to "salute" for showing me an example of this!) and relative labels in SDCC
- there is one optimization pattern in particular that can mess up SDCC code ("salute" identified it, thanks!), I'll fix it asap!
- for sjasm/AGD there is one outstanding problem which is the "output" directive of sjasm. I was ignoring it for now, but in the AGD code-base, there are three "output" statements (to generate the rom, then some temporary ram file, and a loader for compiling to tape). MDL still does not support that. Will handle asap, but at least the AGD sample source code parses now, thanks a lot for sharing the example jltursan! very useful :)

Btw, really happy with the reaction to the latest version! Lots of people are trying it, and I've received lots of emails/messages with bug reports/suggested improvements. I'll be addressing all of them for v1.5! It might take me a week or two, but I'll get there :)

By jltursan

Prophet (2619)

jltursan's picture

16-02-2021, 09:09

Glad to help!, I'll try the new version ASAP!

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