VOGONS


First post, by red-ray

User metadata
Rank Oldbie
Rank
Oldbie

I am trying to figure out the best way to implement the PowerPC equivalent of the x32/x64 RDTSC instruction on Windows NT V4.00 SP2 and it seems to be to use the PowerPC TB register. I have written some assembler and would be interested to know if others think it's optimal/correct. It gives values what seem correct when I run it on my 133 Mhz PowerPC 604 Motorola PowerStack system, but I need to multiply the value by 8.

Looking at http://www.cap-lore.com/code/TB/ it mentions x 16 is needed, it also has the http://www.cap-lore.com/code/TB/tb.s code that seems very strange to me, my code is:

        .globl      ..ppc_rdtsc

.section .text

..ppc_rdtsc:
mftbu r4 # read TB upper
mftb r3 # read TB lower
mftbu r5 # read TB upper for check
cmpl 0,0,r4,r5 # TB upper changed ?
bne ..ppc_rdtsc # if NE yes, try again
blr # done

How can I know what to multiply by? Will I need a table for all the different CPU models (PVR values)?

Note: I am interested in solutions, not posts that simply imply it's tricky without links to justify the opinions.

Last edited by red-ray on 2025-08-18, 00:10. Edited 4 times in total.

Reply 1 of 1, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie

It's implementation dependent. In some cases the timebase register may not even update at a fixed frequency.