Assembler Optimizer

Page 2/49
1 | | 3 | 4 | 5 | 6 | 7

Par santiontanon

Paragon (1446)

Portrait de santiontanon

12-06-2020, 15:57

Hehe, sure! It's called "The Menace from Triton", and it's a horizontal shooter inspired in the classic Salamander/Gradius, but with heavy inspiration from more recent games like Steredenn and Z-Exemplar (e.g., mission/shop screens). Still a lot of work to do, but it's advancing nicely Smile

But now I have the usual feeling, I keep thinking of ideas for the optimizer, so, I want to start working on it. But I must resist, and finish the game first, haha

Par thegeps

Paladin (854)

Portrait de thegeps

12-06-2020, 23:42

LoL I know what you mean... I want to start another project too, but I have to draw all the gfx for level 4 and 5 to show a complete game as my entry (I'll eventually add prologue and epilogue after msxdev)

Par [D-Tail]

Ascended (8247)

Portrait de [D-Tail]

13-06-2020, 09:21

santiontanon wrote:

Indeed, that is true. It's hard to optimize without knowing what the code is supposed to do. But I'm not aiming for that yet, hehe Smile

<...>
4) apply substitutions only if they are safe based on the dependency graph
5) write out a modified version of the .asm code (original source, but just modified)

Sounds like a great initiative!! So what about timing effects? Because 'blindly' replacing code, even when based on a dependency graph, doesn't take timing into account. Maybe you could check for annotations in the code like ; pragma optimization off and such...

Par Grauw

Ascended (10013)

Portrait de Grauw

13-06-2020, 10:53

I reckon you could use such an optimiser in two ways: as an automated process prior to compilation, and as a linter of sorts. In the former case indeed you would want to have control over where the optimisations are applied, however in the latter case it could just do all the optimisations, and then in your version control system you can cherry-pick those that you are interested in. Downside of the latter style of course is that it risks obfuscating your code, but upside is that it gives you maximum control.

Par santiontanon

Paragon (1446)

Portrait de santiontanon

14-06-2020, 01:14

About "timing":
- In a first phase, I am going to ignore timing for now, and just use pattern-based replacements (just to have something working that I can built upon)
- However, I would like to incorporate timing information as well later on. Some instructions might be tricky, as jumps take different amount of time depending on if they are taken or not. But at least I would like to calculate upper/lower bounds on the time of code snippets. But again, that'll be for a later version. For now, version 1: blind pattern-based replacement
- As first step after that might be to add a small table with instruction size info, so the optimizer could also calculate how much space is being saved with each replacement (and maybe this could be used as a starting point for later add timing info as well)

And about prior-to-compilation vs lint-style:
- Yes, nice idea!
- I am split about how much to try to make the output optimized code "readable" (e.g., preserve comments, indentation, format, etc.), or not. Maintaining readability might be useful, but might complicate output generation for some optimizations maybe (haven't thought too much about it!)

I also like the idea of adding annotations to help the optimized. Maybe these can be added using some special syntax inside of comment blocks, so that it can be ignored by the assembler compilers and is not in the way.

Par pgimeno

Champion (298)

Portrait de pgimeno

14-06-2020, 02:53

Is this going to be an assembler with an integrated optimizer? Is that what you have in mind?

Par santiontanon

Paragon (1446)

Portrait de santiontanon

14-06-2020, 02:57

I was just thinking of a stand-along optimizer: taking one or several .asm files as input, and generating optimized .asm as output, that can then be compiled. But of course, I might integrate a compiler into the thing for making it self-contained.

Also, being a Unix user myself, I was wondering, what would be a language that I could build this in so that it's easy for others to use if they want. I usually default to Java for these cross-platform things. Not sure if Python would be more popular (although I use Python at work every day, I am not the biggest fan though haha).

Par pgimeno

Champion (298)

Portrait de pgimeno

14-06-2020, 03:28

I ask because I don't think it can possibly be useful in practical circumstances if it doesn't resolve all symbols, and for resolving all symbols, it needs at least to know the size of each instruction and to be able to resolve EQUs, IFs, INCBINs, INCLUDEs, evaluate expressions, etc. From there to a full assembler there's just one little step.

Par santiontanon

Paragon (1446)

Portrait de santiontanon

14-06-2020, 03:44

Sure! Again, I would like to start with something small. Past experience has shown me that any overambitious project never gets finished. So, I'll start step by step, but making sure I start something I will finish haha Smile

So, I might start with some limited support as for what the optimizer can take in, and expand from there. Ultimate goal would be to make it as useful as possible, so, I'd like to support everything, but step by step Smile

Par thegeps

Paladin (854)

Portrait de thegeps

14-06-2020, 09:36

I agree. Step by step you'll go far Wink

Page 2/49
1 | | 3 | 4 | 5 | 6 | 7