Assembler Optimizer

Page 35/42
28 | 29 | 30 | 31 | 32 | 33 | 34 | | 36 | 37 | 38 | 39 | 40

By jltursan

Prophet (2457)

jltursan's picture

03-03-2021, 21:40

Well, another success Smile, regarding one of my last tests ("03") I've found that the reorganization was the culprit of the non working game; but it's not a bug, it's as simple as some hardcoded startup addresses are changing due the reorganization and thus, calling the old address produces havoc. I've consolidated the suggested optimizations, updated the hardcoded addresses and hey, all the rest of optimizations are fine, the game seems to work flawlessly.
I just don't understand these lines, lots of them:

INFO: Optimization undone, as it was breaking the equality constraint: (DelyCnt) & #ff00 == (ChanA + CHNPRM_NtSkCn) & #ff00

...but as they are not optimizations, well, they're harmless. Anyway, is there a way to disable the "undone" comments?.

And a nice surprise, now, the last and biggest test in my hands is being optimized, no more nullPointers; so that means that my changes above are avoiding the error. Now the test game mostly works but I've found a little bug so I'll try to find the problem, 98 patterns applied I need to check Smile

Again, I'll be back!

By santiontanon

Paragon (1290)

santiontanon's picture

03-03-2021, 22:06

Wohoo!! Cool!!! Thanks a lot for all the testing!

About those "optimization undone", that's an internal message, I should really not print those out to the console. I'll remove them. What it means is this:
- Imagine that optimization 1 changes something like "ld a,LABEL", by "xor a", since "LABEL" has value 0.
- Now optimization 2 wants to optimize something else, but by applying the optimization changes the value of "LABEL.
- That would break optimization 1. So, every time an optimization is done, I add an "equality constraint" to a list, containing the assumptions that previous optimizations make about the value of constants and labels. If an optimization breaks any of those assumptions, it is undone for safety, and that message is printed.

But really, the user should not care about it. So, I'll just remove those messages Smile

By santiontanon

Paragon (1290)

santiontanon's picture

04-03-2021, 06:36

And btw, I found another project that produces the crash you mentioned above too, just fixed it in GitHub, will be included in the next release Smile

By jltursan

Prophet (2457)

jltursan's picture

04-03-2021, 18:52

About the crash, seems random?, I've seen it again:

←[31mERROR: Problem parsing file metamorphosis.asm: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0←[0m
←[31mERROR:     java.util.ArrayList.rangeCheck(Unknown Source)←[0m
←[31mERROR:     java.util.ArrayList.get(Unknown Source)←[0m
←[31mERROR:     parser.SourceMacro.instantiate(SourceMacro.java:164)←[0m
←[31mERROR:     parser.PreProcessor.handleStatement(PreProcessor.java:314)←[0m
←[31mERROR:     parser.CodeBaseParser.parseSourceFileInternal(CodeBaseParser.java:207)←[0m
←[31mERROR:     parser.CodeBaseParser.parseSourceFile(CodeBaseParser.java:111)←[0m
←[31mERROR:     parser.CodeBaseParser.parseMainSourceFile(CodeBaseParser.java:39)←[0m
←[31mERROR:     cl.Main.main(Main.java:49)←[0m
←[31mERROR: Could not fully parse the code (error code 2).←[0m

Seems that my console doesn't likes ANSI codes... Crying
Is it the same bug you've found?

By santiontanon

Paragon (1290)

santiontanon's picture

04-03-2021, 19:59

Oh, that's a different one then! I'll look into it!!

About the ANSI codes, what do you think? should I remove them? they are super useful in standard ansi consoles to show messages in different colors. I wonder if I can detect in any way if the current console is not ANSI, and deactivate them? I'll investigate!

By Pencioner

Scribe (1354)

Pencioner's picture

04-03-2021, 20:03

As simplest solution you can have a command line option which will control the output, to enable/disable ANSI codes

By santiontanon

Paragon (1290)

santiontanon's picture

04-03-2021, 23:09

Makes sense! I think I will do that! I wonder what should be the default no colors, and activate them with a flag, or colors, and deactivate them with a flag Smile

By santiontanon

Paragon (1290)

santiontanon's picture

08-03-2021, 04:30

As usual, new version of the weekend Smile I just released version 1.7 in Github https://github.com/santiontanon/mdlz80optimizer/releases/tag...

Lots of small fixes/improvements here and there as usual. But the two main new big features are:
- initial support for the macro80/m80 assembler (I was able to parse a few of the Nextor source files, finding many optimizations).
- the code reorganizer has a new "function inlining" functionality, which detects "simple functions" (single entry point, single ret, etc.) that are called only once, and in-lines them in the place where they were called saving the call/ret (this is super simple, but I was surprised how often this actually occurs!) (you can deactivate this with -ro-no-inliner, as it can mess up sdcc code, removing functions that MDL believes are only called once, but that are in fact called by external code).

The one downside is that if you turn on all the optimizations, it is starting to get slower and slower. So, I might have to look into "optimizing the optimizer" at some point :) (too bad it's not written in assembler, as otherwise it could optimizer itself, hahaha). The pattern-based optimizer now can do multiple passes (as I noticed this improves the number of found optimizations). Previous versions did just 1 pass, and the current version does 2 passes. This, of course, doubles the execution time of MDL. This can be controller by stating -po1/-po2/-po3 to control the number of passes. The standard flag "-po" is a synonimous of "-po2" (so, two passes by default).

Although I still have a bunch of small improvements to both optimizers in the to-do list, I was trying to plan future improvements to MDL and one question I had was whether it would be useful if MDL could generate .rel files, which I see assemblers like macro80 or sdasz80 generate.

Anyway, feedback or bug reports are welcome :)

By jltursan

Prophet (2457)

jltursan's picture

08-03-2021, 09:25

-ansioff/-ansion

You're fast! Big smile

As usual, really great work!

I've been thinking about another kind of size optimization related to the use of ALIGNed code fragments. Sometimes it you need to align some code with a, for example, 256 bytes boundary, there's usually some space wasted until you get the alignment. Maybe these free gaps can be reused to fit something...

By santiontanon

Paragon (1290)

santiontanon's picture

08-03-2021, 16:28

Oh! Interesting idea! Definitively, we could detect if there is any code block that can be extracted from its current place and is small enough to fit there! With some safety constraints (only code from the same page in dialects that have pages, etc.) I think it could be made to work!

Page 35/42
28 | 29 | 30 | 31 | 32 | 33 | 34 | | 36 | 37 | 38 | 39 | 40