Assembler Optimizer

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

By Bengalack

Hero (590)

Bengalack's picture

16-02-2021, 12:26

Ok, no new feedback on "-ro", as the reusable symbols remains as before, but "-po speed" gives these results:

v1.4: INFO: PatternBasedOptimizer: 203 patterns applied, -65 bytes, 756 t-states saved.
v1.3: INFO: PatternBasedOptimizer:  70 patterns applied,  58 bytes, 477 t-states saved.

and not only that: Using v1.4 on the SDCC-generated asm-file of 14693 lines, generates a fully valid asm file for sdasz80 when using -asm-dialect instead of -poapply! Great!

By santiontanon

Paragon (1639)

santiontanon's picture

16-02-2021, 15:29

alright!!! thanks to both!! I'm going to be working on the "-ro" issue this week, so hopefully I can resolve it soon! Smile

By jltursan

Prophet (2619)

jltursan's picture

17-02-2021, 19:13

Success!, now it even generates a working .asm optimized file:

INFO: mdl optimization summary: 40 bytes, 265 t-states saved. Pattern-based optimizer pattern applications: 24.

Although as expected, it complains about having more than one "output" statement and seems that, as for now, "page" pseudoinstruction only supports 1 page:

ERROR: Specifying more than one possible page not yet supported in foggy.asm#76: page 0..2

Most probably supporting n pages the optimizer will be 99% compatible with these sources.

OTOH, code with more than 1 output also uses "code @" pseudoinstruction, not supported yet.

If you feel brave and can provide more sources to test... Wink

By santiontanon

Paragon (1639)

santiontanon's picture

17-02-2021, 22:30

Wohoo!! That's awesome! Big smile

I have the multiple "output" in my todo list for this weekend (I still do not know exactly how am I going to solve it, but I'll figure something out haha). But I just made a note about the "page 0..2" thing too, and if I have time I will try to address that too for this upcoming version (and otherwise, for the next Wink ).

As for more sources to test, that would be fantastic! But let me first try to get that one you shared working 100%, and we can then move to some more complex ones Wink

By jltursan

Prophet (2619)

jltursan's picture

17-02-2021, 22:45

The shared one works 100%!, it complaints about multiple outputs but it can't fail as they're not used thanks to conditional pseudoinstructions. Of course I can send "real" multiple output sources or with multiple pages, whatever you want Smile

By santiontanon

Paragon (1639)

santiontanon's picture

17-02-2021, 22:57

haha, alright! then ready for the new challenge! If you have a "real" multiple output source, I'll try to tackle it this weekend! Smile

By jltursan

Prophet (2619)

jltursan's picture

20-02-2021, 11:13

Oh, well, seems that my last tests were a bit enthusiastic, I was compiling again the original assembler file, not the one generated by the optimizer!, DOH!.
Sigh, let's start again....

The optimized source doesn't compiles due the following:

; 		ld de,MAP           ; address of map.  ; -mdl
; 		and a               ; clear carry flag for subtraction.  ; -mdl
; 		sbc hl,de           ; find simple displacement for block.  ; -mdl 

    ld de, -(MAP)  ; +mdl
    add hl, de  ; +mdl

That's fine; but seems that sjasm 0.42c doesn't supports negative values past $8000; so in this case it fails with "out of range".

;        ld hl,$F05  ; -mdl
       ld hl, ?const  ; +mdl
       ld (charx),hl

Fails with syntax error, seems that "?const" is some kind of optimizer constant that remains unreplaced...

Fixing both problems, the game compiles but there's a flaw in the particles engine, the particles doesn't move correctly and this is caused by this optimization:

; 		push hl		  ; -mdl
; 		pop hl  ; -mdl
		ld h, h  ; +mdl
		ld l, l  ; +mdl
		pop hl
		add hl,bc

That it's absolutely correct if you don't consider the stack, which is the use case; so probably it can't be fixed as is nothing to fix. This kind of optimizations need to be approved before by the developer and that's why I need to move ASAP to an IDE like the VScode :-D

By santiontanon

Paragon (1639)

santiontanon's picture

20-02-2021, 17:26

Thanks for the report jltursan!!!

The later two cases are clearly bugs in the optimization pattern definition file! I'll fix them today, they seem like easy fixes (MDL has the machinery to check the stack, so, it's probably that I forgot to add the right check in the pattern!). Btw, could you share the 2/3 lines right before/after the push/pop case? I want to see which pattern triggered there.

For the first one, do you think if instead of "-(MAP)", MDL were to generate "(-(MAP) & 0xffff)" sjasm 0.42c would parse it?

As for the binary not working after optimization, that worries me a bit more... there might be again some optimization pattern with a missing safety check! Let me fix these things you mentioned first, and see if after that it still fails, and if it does, we can look at it in more detail Smile

By Metalion

Paragon (1529)

Metalion's picture

20-02-2021, 17:55

jltursan wrote:
; 		ld de,MAP           ; address of map.  ; -mdl
; 		and a               ; clear carry flag for subtraction.  ; -mdl
; 		sbc hl,de           ; find simple displacement for block.  ; -mdl 

    ld de, -(MAP)  ; +mdl
    add hl, de  ; +mdl

That's fine; but seems that sjasm 0.42c doesn't supports negative values past $8000; so in this case it fails with "out of range".

Well, of course, since a 16-bit signed number can only be between [-32768,32767].

By santiontanon

Paragon (1639)

santiontanon's picture

20-02-2021, 18:52

- The "?const" issue is now fixed (the fix will be included in the new release that I hope to release today!), thanks for the report!
- I was thinking about the "push hl/pop hl" a bit more, and I stand corrected. If what you actually want is for the side-effect of having "hl" in the next position of the stack (so those "push hl/pop hl" should not be removed), then MDL will not be able to see that. Luckily, there is a way to fix the problem easily Smile When you have in the code some instructions like these that you need to remain as they are, you can protect them from MDL by just adding this comment after them: "; mdl:no-opt". I added that for special cases where you do want instructions to have a certain timing (e.g. for sending data to the VDP), and a few other cases like this one Smile

I am still not sure what to do with the "-(MAP)" case though... I am still leaning towards "(-(MAP) & 0xffff)", but the generated code will look a bit ugly, so not sure haha Smile

In any case, thanks a lot for all of these reports and all the patience, they are extremely useful! MDL is growing into a fairly complex piece of software, and I think it'll still take a few more versions to iron out all the bugs/corner cases Smile

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