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

Optimization: Use an identity table to synthesize direct A,X/A,Y operand modes #373

Open
asiekierka opened this issue Oct 1, 2023 · 0 comments
Labels
enhancement New feature or request p2

Comments

@asiekierka
Copy link
Contributor

asiekierka commented Oct 1, 2023

Memblers of the NESdev forums pointed out the existence of an ASM trick called the "identity table": https://www.nesdev.org/wiki/Identity_table - this uses an identity table (where LDA table,x == x for any given x) to allow using any opcode with an abs,x or abs,y addressing mode as a direct x or y addressing mode.

This is particularly interesting as some of the NES targets already feature what is essentially a (limited) identity table, for handling bus conflicts.

The way I would see this done is:

  • Implement a compiler switch for enabling use of the identity table.
    • We certainly don't want this on by default, due to its compiler runtime requirements and 256-byte fixed cost.
    • However, given some NES mappers require handling bus conflicts, this optimization may be effectively free on those platforms.
  • Implement the necessary lowering, using an __identity_table table to synthesize, for example, ORA x to ORA __identity_table,x.
  • Measure if this actually provides meaningful code generation gains.
  • In llvm-mos-sdk, patch the rompoke logic for handling bus conflicts:
    • Use the __identity_table symbol name and set it to maximum size (256 bytes), if the identity table is used by the compiler. This may be a little tricky to model.
    • Make an effort to place __identity_table at the beginning of the fixed bank - this will ensure it's page-aligned, and thus avoid hurting performance.

This is a rough sketch - there's obviously details to be figured out.

@mysterymath mysterymath added enhancement New feature or request p2 labels Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2
Projects
None yet
Development

No branches or pull requests

2 participants