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

Thumb cycle counting #757

Open
thrust26 opened this issue Jan 25, 2021 · 10 comments
Open

Thumb cycle counting #757

thrust26 opened this issue Jan 25, 2021 · 10 comments

Comments

@thrust26
Copy link
Member

thrust26 commented Jan 25, 2021

Maybe we could extend the Thumbulator code to (roughly) count cycles? While not perfect, this might still help developer to identify slow code or code running out of time.

https://developer.arm.com/documentation/ddi0234/b/instruction-cycle-timings/instruction-cycle-count-summary

@thrust26 thrust26 added this to the Prio 2 milestone Jan 25, 2021
@sa666666
Copy link
Member

We've discussed this in the past, and found that there is really no optimal solution. But I am happy to revisit it to see if we can come up with an approximation.

@thrust26
Copy link
Member Author

thrust26 commented Jan 25, 2021

At the moment I cannot even match our code with the description in the link. Besides that, it doesn't look too complicated. 😄

Probably someone needs at least basic ARM assembler knowledge to implement this.

@thrust26
Copy link
Member Author

thrust26 commented Jun 13, 2021

@sa666666 @DirtyHairy
After having some coarse calculation available already, I added code (0c51180) which makes use of it during emulation in developer mode. Now the calculated cycles are multiplied with a user defined factor (default 1.25) and increase the system cycles. So that a timer overrun can be detected.

I have no clue how good the approximation is, but by some testing with existing ROMs I found the upper limit of the factor to be 1.79. Probably we should ask some ARM game developers (e.g. @SpiceWare) if they can provide a test program which helps getting an idea about the correctness of our calculations.

Probably I will add some UI elements for easier changing the new options. Not to the settings dialog, but to the debugger widgets.

@andrew-davie
Copy link

andrew-davie commented Jun 13, 2021 via email

@thrust26
Copy link
Member Author

thrust26 commented Jun 13, 2021

I can send you a confidential copy of my project for testing. It’s pushing the ARM quite hard and timing is quite critical.

Sure. But probably I need some help for setting up the development environment. Also, if you can compile Stella, you can check the changes yourself too.

@andrew-davie
Copy link

andrew-davie commented Jun 13, 2021 via email

@thrust26
Copy link
Member Author

If you let me know which situations are close to the edge, yes.

@andrew-davie
Copy link

andrew-davie commented Jun 13, 2021 via email

@thrust26
Copy link
Member Author

Got it. Thanks!

@thrust26
Copy link
Member Author

thrust26 commented Jun 25, 2021

Meanwhile I committed a number of updates. The cycle count has become a lot better, but there are still issues to solve:

  • no ARM pipeline emulation (this should reduce the cycle counts in case of slow Flash memory access)
  • missing driver cycles (these cycles can only be estimated, since they are not emulated)
    • IRQ driven audio regularly interrupts the Thumb code with some ARM code and 5 cycles of 6507 (currently 10% are added to the count if IRQ driven audio is enabled)
    • the Thumb code regularly switches to driver ARM code for updating audio values
  • adding known good cycle counts still making the game roll in Stella (mysterious)

Overall I estimate that the cycle count is ~10% too high.

@thrust26 thrust26 added the target 6.6 2021-11 Release label Aug 25, 2021
@thrust26 thrust26 added target 6.7 and removed target 6.6 2021-11 Release labels Nov 30, 2021
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

4 participants