1*0Sstevel@tonic-gate // 2*0Sstevel@tonic-gate // gettsc.inl 3*0Sstevel@tonic-gate // 4*0Sstevel@tonic-gate // gives access to the Pentium's (secret) cycle counter 5*0Sstevel@tonic-gate // 6*0Sstevel@tonic-gate // This software was written by Leonard Janke (janke@unixg.ubc.ca) 7*0Sstevel@tonic-gate // in 1996-7 and is entered, by him, into the public domain. 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gate #if defined(__WATCOMC__) 10*0Sstevel@tonic-gate void GetTSC(unsigned long&); 11*0Sstevel@tonic-gate #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; 12*0Sstevel@tonic-gate #elif defined(__GNUC__) 13*0Sstevel@tonic-gate inline 14*0Sstevel@tonic-gate void GetTSC(unsigned long& tsc) 15*0Sstevel@tonic-gate { 16*0Sstevel@tonic-gate asm volatile(".byte 15, 49\n\t" 17*0Sstevel@tonic-gate : "=eax" (tsc) 18*0Sstevel@tonic-gate : 19*0Sstevel@tonic-gate : "%edx", "%eax"); 20*0Sstevel@tonic-gate } 21*0Sstevel@tonic-gate #elif defined(_MSC_VER) 22*0Sstevel@tonic-gate inline 23*0Sstevel@tonic-gate void GetTSC(unsigned long& tsc) 24*0Sstevel@tonic-gate { 25*0Sstevel@tonic-gate unsigned long a; 26*0Sstevel@tonic-gate __asm _emit 0fh 27*0Sstevel@tonic-gate __asm _emit 31h 28*0Sstevel@tonic-gate __asm mov a, eax; 29*0Sstevel@tonic-gate tsc=a; 30*0Sstevel@tonic-gate } 31*0Sstevel@tonic-gate #endif 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <stdlib.h> 35*0Sstevel@tonic-gate #include <openssl/rc5.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate void main(int argc,char *argv[]) 38*0Sstevel@tonic-gate { 39*0Sstevel@tonic-gate RC5_32_KEY key; 40*0Sstevel@tonic-gate unsigned long s1,s2,e1,e2; 41*0Sstevel@tonic-gate unsigned long data[2]; 42*0Sstevel@tonic-gate int i,j; 43*0Sstevel@tonic-gate static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate RC5_32_set_key(&key, 16,d,12); 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate for (j=0; j<6; j++) 48*0Sstevel@tonic-gate { 49*0Sstevel@tonic-gate for (i=0; i<1000; i++) /**/ 50*0Sstevel@tonic-gate { 51*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 52*0Sstevel@tonic-gate GetTSC(s1); 53*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 54*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 55*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 56*0Sstevel@tonic-gate GetTSC(e1); 57*0Sstevel@tonic-gate GetTSC(s2); 58*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 59*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 60*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 61*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 62*0Sstevel@tonic-gate GetTSC(e2); 63*0Sstevel@tonic-gate RC5_32_encrypt(&data[0],&key); 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate printf("cast %d %d (%d)\n", 67*0Sstevel@tonic-gate e1-s1,e2-s2,((e2-s2)-(e1-s1))); 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71