stella-emu / stella

A multi-platform Atari 2600 Emulator
https://stella-emu.github.io
GNU General Public License v2.0
618 stars 112 forks source link

Thumb cycle counting #757

Open thrust26 opened 3 years ago

thrust26 commented 3 years ago

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

sa666666 commented 3 years ago

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 commented 3 years ago

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

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

thrust26 commented 3 years ago

@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 commented 3 years ago

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

On 13 Jun 2021, at 10:03 pm, Thomas Jentzsch @.***> wrote:

After having some coarse calculation available already, I added code (0c51180 https://github.com/stella-emu/stella/commit/0c511805c79bcc04a55f85bdbf2a6303babdd956) 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 https://github.com/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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stella-emu/stella/issues/757#issuecomment-860199676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5JZCYUQMHDC2RN576MYETTSSNCJANCNFSM4WSFVCSA.

thrust26 commented 3 years ago

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 commented 3 years ago

Wouldn’t a binary be sufficient?

On 13 Jun 2021, at 10:57 pm, Thomas Jentzsch @.***> wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stella-emu/stella/issues/757#issuecomment-860207016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5JZC2H6KI2OSM2UL2O4GDTSSTNDANCNFSM4WSFVCSA.

thrust26 commented 3 years ago

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

andrew-davie commented 3 years ago

Have sent to your yahoo email.

On 13 Jun 2021, at 11:04 pm, Thomas Jentzsch @.***> wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/stella-emu/stella/issues/757#issuecomment-860207936, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5JZC67Z72VCIC6BYFVAEDTSSUG3ANCNFSM4WSFVCSA.

thrust26 commented 3 years ago

Got it. Thanks!

thrust26 commented 3 years ago

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

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