-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Common Subexpression Elimination #42
Comments
Adding this for single lines to the yolol-optimizer should be pretty easy. For example: Just adding the assignment to the start of the programm would be simple. But that might make the first lines just a little to long to be merged into a single line, which in turn might slow down an important part of the program. Tl;Dr: Doing this for a single line is easy. But trying to do this accross multiple lines might actually make it worse in some circumstances. I'll think a little about this, maybe if I can come up with something. If you have an idea how to reliably place that assignment accross multiple lines, please let me know. (If there is no reasonable way to do this for multple lines, I'll proably just implement the single-line version. It's still better than nothing) |
Yes, I understand that the multi-line management is very non-trivial. I included that as a bit of an afternote or long term goal. I think for now the single-line version should be very helpful, and fairly simple to implement. I'll see if I can find a solution to that and get back to you with anything I figure out. |
After thinking a bit about this, I came to the conclusion, that this problem here is effectively "common subexpression elimination".
When doing this for single lines, this is effectively local common subexpression elimination. Multi-line (a.k.a global common subexpression elimination) is much harder, and yes, thats something for the far far future. |
In the meantime you could probably brute force placement of global subexpression assignments? Time spent compiling is time saved in-game after all. |
I would need to brute-force the whole compilation-process. Unfortunately that would require major changes to the compiler. So for the foreseeable future there will only be optimizations that won't require backtracking. |
Well I don't know if there's any way to predict runtime-errors... |
Unfortunately, runtime-error can happen in many places. |
I have changed the issue title to a more accurate and descriptive one. |
For lines of NOLOL/YOLOL where a constant is mentioned multiple times, it could be assigned to a local variable to save characters.
For example, the line
a = 1526293.832 * (:y - 1526293.832)
could be optimised to
which saves on characters after compilation to YOLOL.
The optimiser would have to check if this indeed saves characters, as a 1 character constant, or few character constant with only two or so mentions on a line, may increase the length of a line if assigned to a local variable.
Of course, this behaviour can be emulated by the programmer, however, I believe it would be a helpful automatic optimisation.
This might be especially helpful for optimising NOLOL macros, as a single macro representing a long constant, repeated multiple times on a line, can easily lead to a lot of character wastage.
Global Common Subexpression Elimination:
Sometimes it may be beneficial to set constants that are only mentioned once, if there happens to be extra space available on another line, to save space on an over-length line.
Example:
Thank you.
Wock
The text was updated successfully, but these errors were encountered: