Assembler Optimizer

Page 57/58
50 | 51 | 52 | 53 | 54 | 55 | 56 | | 58

Par Metalion

Paragon (1625)

Portrait de Metalion

31-05-2022, 08:49

Hello santiontanon,

I don't know if your optimizer uses this (time and size) optimization:

ld a,r  ;  5
neg     ; 10

transformed into:

xor a   ; 5
sub a,r ; 5

Just a suggestion, if it's not already taken into account.

Par theNestruo

Champion (422)

Portrait de theNestruo

31-05-2022, 12:05

Metalion wrote:

Hello santiontanon,

I don't know if your optimizer uses this (time and size) optimization:

ld a,r  ;  5
neg     ; 10

transformed into:

xor a   ; 5
sub a,r ; 5

Just a suggestion, if it's not already taken into account.

Yup, it is there already: https://github.com/santiontanon/mdlz80optimizer/blob/master/...

Par santiontanon

Paragon (1806)

Portrait de santiontanon

06-09-2022, 16:48

It had been a while since I made a new release, so, I just released version 2.5 in GitHub: https://github.com/santiontanon/mdlz80optimizer/releases/tag...

The new version contains many many small improvements and fixes here and there (things that I needed), but the two main new additions are:
- support for the WLA-DX assembler (common in the console development world)
- a new "code execution" functionality which is useful to optimize code without having to get it into an emulator/system to measure its execution.

I find this last functionality very useful, and I have been using it a lot in a project I am working on that is not for MSX, and hence all the fancy features of openMSX are not available. For example, imagine you have this simple code:

    org #4000

start:
    ld hl,table
    ld de,#c000
    ld bc,4
    ldir
end:

table:
    db 0,1,2,3

You can call mdl like this (telling MDL to start executing at "start", and stop once the PC reaches "end"):

java -jar mdl.jar test.asm -e:u start end

And you will get this as output:

INFO: Execution result:
INFO:   f: 32 (#20)
INFO:   d: 192 (#c0)
INFO:   e: 4 (#04)
INFO:   h: 64 (#40)
INFO:   l: 15 (#0f)
INFO:   r: 4 (#04)
INFO:   (#c000) = 0 (#00)
INFO:   (#c001) = 1 (#01)
INFO:   (#c002) = 2 (#02)
INFO:   (#c003) = 3 (#03)
INFO:   4 instructions executed.
INFO:   execution time: 120 t-states

As you can see if shows everything that changed (registers and memory). Perhaps, I should also add which flags changed?

Naturally, you can change the z80 type. By default it uses an MSX-configured z80, but if you use "-cpu z80", then executio only takes 109 t-states (e.g., on a Spectrum), and if you say "-cpu z80cpc", you get "32 nops" (As time in the Amstrad CMC is measured in "nops").

Anyway, I find it very useful to check small routines :)

Par thegeps

Paragon (1189)

Portrait de thegeps

06-09-2022, 23:02

Oh this is a really cool update! It can be used as debugger for specific program zones! Thank you Santi!

Par ro

Scribe (4964)

Portrait de ro

07-09-2022, 12:53

but, "END" is an assembler command that tells it to shove it. I would expect "label table not found" error or something.

Par santiontanon

Paragon (1806)

Portrait de santiontanon

07-09-2022, 15:06

Ah yes! some assemblers reserve the "end" label for internal purposes, such as for finishing the assembly process. MDL does not make any assumptions about that, since not all assemblers reserve the "end" label for that, so, it'll not complain about it.

But I used "start" and "end" just for the example. You can use any two labels in your code, of course. Alternatively, with the "-e:s" flag, you can also tell it a start label, and a predefined number of t-states instead of specifying a target label to reach Smile

Par max_iwamoto

Hero (644)

Portrait de max_iwamoto

05-10-2022, 15:03

A few days ago I was optimizng some code and possibly found a new pattern for the Assembler Optimizer.

The code looked like that:

	LD	(IX+00h),20h			; 
	LD	(IX+01h),20h
	LD	(IX+18h),20h
	LD	(IX+19h),20h

	LD	BC,00h - 18h * 18h
	ADD	IX,BC

	LD	(IX+00h),20h			; 
	LD	(IX+01h),20h
	LD	(IX+18h),20h
	LD	(IX+19h),20h

Obviously, it was a bad code.

So optimization would be something like that:

LD A,20h, and replace all LD (IX+??),20h to LD (IX+??),A

But it should save register A if after working with IX register A is not refined and not save it if registerA has been changed without usage.

Par santiontanon

Paragon (1806)

Portrait de santiontanon

07-10-2022, 02:56

Oh, this is an interesting one! It might be tricky to define this as an optimization pattern that is general enough, but I think I could extend the pattern definition language to capture some of these more complex ones! I just added a note to try this to my todo list! Thanks for the example! Big smile

Par rolandve

Champion (358)

Portrait de rolandve

28-01-2023, 10:57

Mmm, can this optimise the code generated by the msx ascii C compiler?

Par santiontanon

Paragon (1806)

Portrait de santiontanon

28-01-2023, 13:23

Oh, not sure! Which assembler dialect does the ASCII C compiler generate assembler in? Do you have an example? I can definitively take a look Smile

Page 57/58
50 | 51 | 52 | 53 | 54 | 55 | 56 | | 58