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

Optimise variational action2 trivial cases #281

Merged
merged 2 commits into from Apr 3, 2023

Conversation

JGRennison
Copy link
Contributor

Drop useless binary operator operations with constant 0 for:

  • shift left/right
  • or
  • xor
  • rotate

Optimise trivial right shifts of variables by a constant value. Adjust the shift right and mask of a variable where possible, in the same way as is currently done for left shifts of inherently right shifted variables.

The practical upshot of this is that extremely common patterns like: getbits(extra_callback_info2, 0, 8) now result in the obvious representation:

  • ADD/RST variable 18, shift: 0, mask: FF

Instead of currently:

  • ADD/RST variable 18, shift: 0, mask: FFFFFFFF
  • SHR variable 1A, shift: 0, mask: 0
  • AND variable 1A, shift: 0, mask: FF

Using one instead of three ops allows direct references in more cases instead of needing to spill to a temporary register and use RST.

@glx22
Copy link
Contributor

glx22 commented Apr 2, 2023

Regression fails, but the output clearly shows the optimisation.

@FLHerne
Copy link
Contributor

FLHerne commented Apr 2, 2023

Nice improvement.

This looks correct to me - just need to update regression/expected/* with the new results.

@JGRennison JGRennison force-pushed the trivial-varaction2-optimisations branch from 6c02315 to d8a79a8 Compare April 2, 2023 23:09
@FLHerne FLHerne merged commit 1e26f14 into OpenTTD:master Apr 3, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants