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: 171
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Equivalent to RTSC x86 indtruction on SH4

Post by Newbie »

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
DC Developer
DC Developer
Posts: 104
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 88 times

Re: Equivalent to RTSC x86 indtruction on SH4

Post by TapamN »

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: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: Equivalent to RTSC x86 indtruction on SH4

Post by Newbie »

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: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Equivalent to RTSC x86 indtruction on SH4

Post by BlueCrab »

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
DC Developer
DC Developer
Posts: 104
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 88 times

Re: Equivalent to RTSC x86 indtruction on SH4

Post by TapamN »

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: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Equivalent to RTSC x86 indtruction on SH4

Post by BlueCrab »

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: 28
Joined: Wed Apr 23, 2014 3:04 pm
Has thanked: 0
Been thanked: 0

Re: Equivalent to RTSC x86 indtruction on SH4

Post by MetalliC »

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