Skip to content
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

Support identity table usage #129

Open
joshop opened this issue Dec 17, 2021 · 2 comments
Open

Support identity table usage #129

joshop opened this issue Dec 17, 2021 · 2 comments

Comments

@joshop
Copy link

joshop commented Dec 17, 2021

There's an interesting 6502 assembly optimization where you put a 256-byte page aligned table in memory with each byte having the value of its index. Then you can make some pseudo-operations:

  • ADC X with ADC table,X
  • TXY with LDY table,X
  • etc.
    These are faster and smaller than doing it with a temp byte, so if they offset the cost of the table it can be worth it. Could such a feature (probably in the form of a flag) be added to the compiler?
@KarolS
Copy link
Owner

KarolS commented Feb 10, 2022

This sounds like something worth pursuing. For example, currently there are a lot of places that have the following code pattern: PHA ... TSX ORA $101,X INX TXS which usually could be simplified to TAX ... ORA identity,X. Variable-to-register optimization could optimize more opcodes (and since these already use cost-to-benefit calculations, they won't have speed regressions). There are also several places that could use TXY/TYX right now (even if they don't use it even on 65816)

I think it would almost always lead to larger code though, so I agree that it should be a flag.

@KarolS
Copy link
Owner

KarolS commented Feb 10, 2022

So I checked and it turned out that the identity table is actually already used in few places at the -Ob level of optimization. I'll add more uses for it, I'll add some optimizations that target it, so that things like LDA identity,X or ORA identity+n are optimized, and I'll move it to a separate flag, so that it can be used without -Ob (which is an optimization level that is a bit ridiculous, with things like loop unrolling etc., and blows up the code size too much).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants