Assembler Optimizer

Page 41/42
34 | 35 | 36 | 37 | 38 | 39 | 40 | | 42

By jltursan

Prophet (2453)

jltursan's picture

08-04-2021, 09:14

Yay!, time to give it a bad time again! Murdoch

By ToriHino

Hero (653)

ToriHino's picture

08-04-2021, 19:01

Yes that fixed the problem for me Smile

By santiontanon

Paragon (1286)

santiontanon's picture

08-04-2021, 22:03

Wohoo! thanks ToriHino for testing! Smile

And looking forward to more hard tests jltursan! bring them on! haha Smile

By ToriHino

Hero (653)

ToriHino's picture

09-04-2021, 00:34

Maybe a not so relevant issue: I happened to call a label DI:

RAM: PROC
DI                ds 1
        ENDP

Although the assembler has no issue with this, the optimizer returns with an error:

ERROR: No op spec matches with operator in line src\fall-ram.z80#14: DI                ds 1, arguments: [ds]
ERROR: Error parsing source file src\fall-ram.z80 in src\fall-ram.z80#14: DI                ds 1
ERROR: Problem parsing file src\fall-ram.z80

So it looks like the optimizer can not deal with a label with the name of an opcode (as a test renaming it to JP gave the same problem Tongue ). Of course an easy work around is renaming the label.

By santiontanon

Paragon (1286)

santiontanon's picture

09-04-2021, 04:43

ah! this is a tricky one! But if Glass parses it fine, I definitively want MDL to parse it fine too Smile

I'll try with different assemblers to see which ones parse this fine and which do not, to add the appropriate flags to each dialect. Thanks for the report! Big smile

By Bengalack

Champion (331)

Bengalack's picture

13-04-2021, 19:19

Hmm, strange I didn't see this update before now. But here we go!

I tested on my game, but it fails. Command:

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

SDCC gets a new identifier which is not defined:

?ASlink-Warning-Undefined Global '___MDL_SAFETY_LABEL_1' referenced by module 'game'

The original asm-code from SDCC is this:

	call	_printdos
;myassert.h:68: __endasm;
	ld	c,#0x62 ; DOS 2 function for program termination (_TERM)
;ld	b,l ;
	ld	b, #1
	call	5 ; On DOS 2 this terminates; on DOS 1 this returns...
	ld	c,#0x0
	jp	5 ;...and then this one terminates
;(DOS	1 function for program termination).
;myassert.h:69: }
	ld	sp, ix

And the resulting MDL-code is this:

    call _printdos
  ;myassert.h:68: __endasm;
    ld c, #0x62  ; DOS 2 function for program termination (_TERM)
  ;ld	b,l ;
    ld b, #1
    call 5  ; On DOS 2 this terminates; on DOS 1 this returns...
    ld c, #0x00
    jp ___MDL_SAFETY_LABEL_1 + 1  ;...and then this one terminates
  ;(DOS	1 function for program termination).
  ;myassert.h:69: }
    ld sp, ix

Not sure if the context matters at all, but I'm including 8 lines before the culprit. At least call 5 and jp 5 are treated differently.

Hilfe Smile

By santiontanon

Paragon (1286)

santiontanon's picture

13-04-2021, 19:55

oh, yes, I see the problem!!!

Since MDL might move things around (removing/adding instructions, etc.), it tries to remove jumps/calls to hardcoded memory addresses, and replaces them with "safety labels". So, there is probably a label that was created for address "5", that for some reason wasn't saved to the output assembler code. But in any case, I see 3 problems:
- MDL should have also replaced the "call 5" with "call ___MDL_SAFETY_LABEL_1"
- MDL should have defined ___MDL_SAFETY_LABEL_1 in the code (so there should not have been any compilation error!)
- I should probably add a flag to prevent these safety labels from being generated, since in some projects they might be problematic. These are needed, for example, to optimize code that comes from a disassembly, and has lots of things like "jp #8a30", etc., which would be broken after optimization if MDL does not replace them by labels.

I make a note, since there are definitively things that MDL is failing to do here!! Thanks a lot for the report! I have a couple of other bugs to fix, so, probably I can put together a bug-fixing release soon in a day or too Smile

By santiontanon

Paragon (1286)

santiontanon's picture

14-04-2021, 06:35

Well that was an easy fix. So, I just uploaded v1.9.1 fixing this and also the parsing issue reported by ToriHino earlier: https://github.com/santiontanon/mdlz80optimizer/releases/tag...

Fingers crossed this one works, otherwise, let me know :)

By Bengalack

Champion (331)

Bengalack's picture

14-04-2021, 17:30

Thanks for the quick response @santiontanon!

Good news: The "-po" works great:

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

Output:

INFO: mdl optimization summary: -55 bytes, 620 t-states saved. Pattern-based optimizer pattern applications: 186.

The bad news: "-ro" is not happy:
Command: java -jar mdl.jar Debug\objs\game.asm -dialect sdcc -ro-no-inliner -ro -po speed -asm-dialect Debug\objs\game.asm.mdl.asm

Output:

...
INFO: Reorganization optimization in Debug\objs\game.asm#3701: move lines 3701 - 3708 to right after Debug\objs\game.asm#12472 (3 bytes, 11 t-states saved)
ERROR: Undefined symbol "_myJIFFY" in Debug\objs\game.asm#11963
Exception in thread "main" java.lang.NullPointerException
        at workers.reorgopt.CodeReorganizer.mergeBlocks(CodeReorganizer.java:749)
        at workers.reorgopt.CodeReorganizer.reorganizeBlock(CodeReorganizer.java:391)
        at workers.reorgopt.CodeReorganizer.work(CodeReorganizer.java:162)
        at cl.MDLConfig.executeWorkers(MDLConfig.java:215)
        at cl.Main.main(Main.java:59)

(the symbol is there Smile)

By thegeps

Paladin (720)

thegeps's picture

14-04-2021, 18:15

Wow, 620 t-states are a lot!

Page 41/42
34 | 35 | 36 | 37 | 38 | 39 | 40 | | 42