Assembler Optimizer

صفحة 9/58
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11 | 12 | 13 | 14

بواسطة theNestruo

Champion (421)

صورة theNestruo

03-07-2020, 13:55

hit9918 wrote:

it would be cool if it could deal SDCC code

What about the peep-hole optimizer? (note: I'm not a SDCC coder myself, so maybe it doesn't work as I think it does)

بواسطة ARTRAG

Enlighted (6935)

صورة ARTRAG

03-07-2020, 13:59

PS I am a big fun of this online assembler
http://msx.jannone.org/bit/
It has a small profiler, maybe its source code can be interesting
https://sourceforge.net/projects/bitz80/

بواسطة theNestruo

Champion (421)

صورة theNestruo

03-07-2020, 14:57

ARTRAG wrote:

PS I am a big fun of this online assembler
http://msx.jannone.org/bit/
It has a small profiler, maybe its source code can be interesting
https://sourceforge.net/projects/bitz80/

I was a fan of Jannone's bit for profiling, but not so fan of coding in a web... so I translated its funcionality to a VSCode extension :)

Here's the link: https://marketplace.visualstudio.com/items?itemName=theNestr...

(and here's the source code: https://github.com/theNestruo/z80-asm-meter-vscode)

بواسطة santiontanon

Paragon (1805)

صورة santiontanon

03-07-2020, 19:31

Thanks a lot for that list of issues TheNestruo! I'll start working my way through those!! Hopefully we can make it work in your projects soon! Smile

About SDCC, the current optimizer in MDL is very similar to the peep-hole optimizer in SDCC, so, if MDL currently manages to find any optimization in SDCC-generated code it might be just because of having a different set of patterns. I have ideas for additional optimizers. The way MDL is currently set up is that there is a set of "workers" that process the input source code one after another, and I currently only have one optimization worker that is the pattern-based one. But I have ideas for more, that could hopefully find better optimizations. For example, the one proposed by Artrag of swapping the use of iy by hl woul dbe very hard to define with a pattern-based approach. But it should not be hard to define a special optimizer to replace iy/ix by hl/de/bc when it is safe to do so.

About Jannone's bit, I am also a big fan of it, I use it heavily! I basically just have it open on a tab and keep copy pasting code there for profiling! Very cool plugin TheNestruo! makes me curious to try VSCode just for using it!

I have focused on "size in bytes" currently in MDL, but the infrastructure to measure timing is already set up, so, I think I could easily at least provide a subset of the functionality within MDL.

بواسطة santiontanon

Paragon (1805)

صورة santiontanon

03-07-2020, 20:46

Btw, just pushed a commit that adds a bit of better support for asMSX (.rom, .start, .print). So, I was able to run it in the pong example here ( https://github.com/Fubukimaru/asMSX/tree/master/code )

And about Jerome's profiler, something that MDL can already do is this. If you pass in the "-asm+ output-filename" flag, it will generate a text file with content like this:

; Address  Size  Time
; -------------------
...
  #8161               ;---------------------------------------------------------
  #8161               ;---------------------------------------------------------
  #8161               MOVE_BALL:
  #8161               ; Move the ball
  #8161               ;---------------------------------------------------------
  #8161               ; Horizontal position
  #8161     3     14      ld a, (BALL_X)
  #8164     1      5      ld b, a
  #8165     3     14      ld a, (SPEED_X)
  #8168     1      5      add a, b
  #8169     3     14      ld (BALL_X), a
  #816c               ; Vertical position
  #816c     3     14      ld a, (BALL_Y)
  #816f     1      5      ld b, a
  #8170     3     14      ld a, (SPEED_Y)
  #8173     1      5      add a, b
  #8174     3     14      ld (BALL_Y), a
  #8177               ; Return
  #8177     1     11      ret
...

So, not really as nice as Jerome's, but it is useful to see at a glance what each instruction in your code is using in terms of space and time!

بواسطة ARTRAG

Enlighted (6935)

صورة ARTRAG

03-07-2020, 21:27

What about a system able to test all permutations of data in registers to find the best sequence of instructions...
It should be a combinatorial approach with forbidden permutations

بواسطة santiontanon

Paragon (1805)

صورة santiontanon

03-07-2020, 21:44

Yes! I think a search-based optimizer ultimately is the only thing that can aim at optimal code! Full search might be infeasible for anything beyond just a short sequence of instructions, but maybe with some constraints (like you suggest searching over register permutations, instead of over the whole space of possible assembler instruction sequences) it might be feasible. An alternative could be using local-search techniques (hill climbing, GAs, etc.) that might not ensure an optimum, but at least might manage some optimizations.

Perhaps we could tell the optimizer to focus its search on a subset of the code, with some flag, like: "-fullopt main.asm:10-25" to just do this optimization in lines 10-25 of a certain file, etc.

بواسطة theNestruo

Champion (421)

صورة theNestruo

03-07-2020, 22:58

santiontanon wrote:

About Jannone's bit, I am also a big fan of it, I use it heavily! I basically just have it open on a tab and keep copy pasting code there for profiling! Very cool plugin TheNestruo! makes me curious to try VSCode just for using it!

There are even more profiler alternatives out there for those impious not worshipping VSCode*... xDDD

* Just kidding! Choose your tools freely!

بواسطة ARTRAG

Enlighted (6935)

صورة ARTRAG

03-07-2020, 23:48

This is interesting
https://directory.fsf.org/wiki/Superopt
Maybe a z80 fork could be feasible...

بواسطة santiontanon

Paragon (1805)

صورة santiontanon

04-07-2020, 02:54

That's pretty cool! I See the CPU ops are defined just in a .def file, it might be a matter of just defining the z80 ops there! but I'm not sure how does it handle the side effects of the ops (flags, memory, i/o ports, etc.). Just downloaded it though, I'll investigate to see which search strategy do they use.

صفحة 9/58
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11 | 12 | 13 | 14