What is the rdtsc opcode equivalent for PPC?

I have a build program that has the following code. This code compiles perfectly for the Intel processor. But, when I use the PPC (cross) compiler, I get an error that the operation code is not recognized. I am trying to find if there is an equivalent opcode for the PPC architecture.

.file "assembly.s" .text .globl func64 .type func64,@function func64: rdtsc ret .size func64,.Lfe1-func64 .globl func .type func,@function func: rdtsc ret 
+7
source share
4 answers

PowerPC includes a “time base” register, which is regularly increasing (although perhaps not at every clock cycle - it depends on the actual hardware and operating system). The TB register is a 64-bit value, read as two 32-bit halves with mftb (the lower half) and mftbu (the upper half). The four least significant TB bits are somewhat unreliable (they increase monotonously, but not necessarily at a fixed rate).

Some older PowerPC processors do not have a TB register (but the OS can emulate it, probably with dubious accuracy); however, the 603e already has one, so it’s arguable that most, if not all PowerPC systems actually in production have one. There is also a “temporary base register”.

See the Power ISA specification available on power.org for details . At the time of this writing, the current version was 2.06B, and the TB register and operation codes were documented on pages 703 through 706.

+8
source

When you need a 64-bit value in a 32-bit architecture (not sure how it works on a 64-bit version) and you read the TB register, you may run into the problem of the lower half going from 0xffffffff to 0 - this does not happen often but you can be sure that this will happen when it does the most damage;)

I recommend that you read the upper half first, then the lower half, and finally the upper half. Compare the two tops, and if they are equal, no problem. If they differ (the first should be smaller than the last), you should look at the bottom to see which vertex it should be mated to: if its most significant bit is set, it must be mated with the first, otherwise the last.

+3
source

Apple has three versions of mach_absolute_time () for different types of code:

  • 32 bit
  • 64-bit kernel, 32-bit application
  • 64-bit kernel, 64-bit application
+2
source

Inspired by Peter Cordes comment and clang __builtin_readcyclecounter :

 mfspr 3, 268 blr 

For gcc you can do the following:

 unsigned long long rdtsc(){ unsigned long long rval; __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval)); return rval; } 

Or for a clank:

 unsigned long long readTSC() { // _mm_lfence(); // optionally wait for earlier insns to retire before reading the clock return __builtin_readcyclecounter(); } 
0
source

Source: https://habr.com/ru/post/887276/


All Articles