Equivalent to RTSC x86 indtruction on SH4

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 166
Joined: Sat Jul 27, 2013 1:16 pm

Equivalent to RTSC x86 indtruction on SH4

Post by Newbie » Mon Jul 31, 2017 9:04 am

Hi,

On all X86 architecture, the Time Stamp Counter (TSC) is a 64-bit register counts the number of cycles since reset. It is used as a precise timer (a clock cycle delta).

https://en.wikipedia.org/wiki/Time_Stamp_Counter

Is there something that could be equivalent on SH4 architecture ?

I need a timer at clock cycle ticks.

Thanks for your help.
TapamN
DCEmu Junior
DCEmu Junior
Posts: 42
Joined: Sun Oct 04, 2009 11:13 am

Re: Equivalent to RTSC x86 indtruction on SH4

Post by TapamN » Wed Aug 02, 2017 1:25 am

The closest thing to the x86 TSC would be using the undocumented performance monitor to count CPU cycles. That gives you a 48-bit timer. The normal, documented hardware timers don't have the resolution to give you exact CPU cycles.
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 166
Joined: Sat Jul 27, 2013 1:16 pm

Re: Equivalent to RTSC x86 indtruction on SH4

Post by Newbie » Wed Aug 02, 2017 6:10 pm

Thanks you very much, I will see this more closely.
I am every time amazed the number of things undocumented ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5357
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Contact:

Re: Equivalent to RTSC x86 indtruction on SH4

Post by BlueCrab » Thu Aug 03, 2017 12:14 am

Are you sure that the performance monitor is actually available on the Dreamcast's CPU? The Linux source code seems to imply that there are many SH-4 CPUs on which it is not available.

It wouldn't surprise me if it is, but it wouldn't surprise me if it isn't either. :wink:
TapamN
DCEmu Junior
DCEmu Junior
Posts: 42
Joined: Sun Oct 04, 2009 11:13 am

Re: Equivalent to RTSC x86 indtruction on SH4

Post by TapamN » Thu Aug 03, 2017 4:40 am

It works, I've tried it. (Although I had trouble getting the second counter to work consistently, it might just be a problem with my implementation.)
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5357
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Contact:

Re: Equivalent to RTSC x86 indtruction on SH4

Post by BlueCrab » Thu Aug 03, 2017 9:54 am

Cool. Always good to know that something has been tested and isn't just a theoretical possibility.
MetalliC
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 27
Joined: Wed Apr 23, 2014 3:04 pm

Re: Equivalent to RTSC x86 indtruction on SH4

Post by MetalliC » Sat Nov 11, 2017 7:05 pm

fun fact: Virtua Fighter 3TB uses SH4 performance monitor. game set 1st monitor to event 0x23 (elapsed cycles) and some time later read counter. probably dev/debug leftovers, not actually required for this game functioning.
Post Reply