• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <stdio.h>
3 #include <assert.h>
4 
5 typedef  unsigned long long int  ULong;
6 typedef  unsigned int            UInt;
7 
GetCPU_ClockCyclesSinceStartup(void)8 static ULong GetCPU_ClockCyclesSinceStartup(void)
9  {
10    UInt uTimeBaseLow;
11    UInt uTimeBaseHigh;
12    UInt uCheck;
13    __asm__ __volatile__("1:     mfspr %0,269\n\t"
14                         "       mfspr %1,268\n\t"
15                         "       mfspr %2,269\n\t"
16                         "       cmpw   %2, %0\n\t"
17                         "       bne    1b"
18                         : "=r" (uTimeBaseHigh),
19                           "=r" (uTimeBaseLow),
20                           "=r" (uCheck)
21                         : /*in*/
22                         : /*trash*/ "cr0","cr7" );
23 
24    return (((ULong)(uTimeBaseHigh) << 32) | uTimeBaseLow);
25  }
26 
main(int argc,char ** argv)27  int main(int argc, char** argv)
28  {
29     ULong cys = GetCPU_ClockCyclesSinceStartup();
30     /* implausible that machine has been up less than 4G cycles */
31     assert(cys > (1ULL << 32));
32     printf("success\n");
33     return 0;
34  }
35