1*ebfedea0SLionel Sambuc //
2*ebfedea0SLionel Sambuc // gettsc.inl
3*ebfedea0SLionel Sambuc //
4*ebfedea0SLionel Sambuc // gives access to the Pentium's (secret) cycle counter
5*ebfedea0SLionel Sambuc //
6*ebfedea0SLionel Sambuc // This software was written by Leonard Janke (janke@unixg.ubc.ca)
7*ebfedea0SLionel Sambuc // in 1996-7 and is entered, by him, into the public domain.
8*ebfedea0SLionel Sambuc
9*ebfedea0SLionel Sambuc #if defined(__WATCOMC__)
10*ebfedea0SLionel Sambuc void GetTSC(unsigned long&);
11*ebfedea0SLionel Sambuc #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12*ebfedea0SLionel Sambuc #elif defined(__GNUC__)
13*ebfedea0SLionel Sambuc inline
GetTSC(unsigned long & tsc)14*ebfedea0SLionel Sambuc void GetTSC(unsigned long& tsc)
15*ebfedea0SLionel Sambuc {
16*ebfedea0SLionel Sambuc asm volatile(".byte 15, 49\n\t"
17*ebfedea0SLionel Sambuc : "=eax" (tsc)
18*ebfedea0SLionel Sambuc :
19*ebfedea0SLionel Sambuc : "%edx", "%eax");
20*ebfedea0SLionel Sambuc }
21*ebfedea0SLionel Sambuc #elif defined(_MSC_VER)
22*ebfedea0SLionel Sambuc inline
GetTSC(unsigned long & tsc)23*ebfedea0SLionel Sambuc void GetTSC(unsigned long& tsc)
24*ebfedea0SLionel Sambuc {
25*ebfedea0SLionel Sambuc unsigned long a;
26*ebfedea0SLionel Sambuc __asm _emit 0fh
27*ebfedea0SLionel Sambuc __asm _emit 31h
28*ebfedea0SLionel Sambuc __asm mov a, eax;
29*ebfedea0SLionel Sambuc tsc=a;
30*ebfedea0SLionel Sambuc }
31*ebfedea0SLionel Sambuc #endif
32*ebfedea0SLionel Sambuc
33*ebfedea0SLionel Sambuc #include <stdio.h>
34*ebfedea0SLionel Sambuc #include <stdlib.h>
35*ebfedea0SLionel Sambuc #include <openssl/md4.h>
36*ebfedea0SLionel Sambuc
37*ebfedea0SLionel Sambuc extern "C" {
38*ebfedea0SLionel Sambuc void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39*ebfedea0SLionel Sambuc }
40*ebfedea0SLionel Sambuc
main(int argc,char * argv[])41*ebfedea0SLionel Sambuc void main(int argc,char *argv[])
42*ebfedea0SLionel Sambuc {
43*ebfedea0SLionel Sambuc unsigned char buffer[64*256];
44*ebfedea0SLionel Sambuc MD4_CTX ctx;
45*ebfedea0SLionel Sambuc unsigned long s1,s2,e1,e2;
46*ebfedea0SLionel Sambuc unsigned char k[16];
47*ebfedea0SLionel Sambuc unsigned long data[2];
48*ebfedea0SLionel Sambuc unsigned char iv[8];
49*ebfedea0SLionel Sambuc int i,num=0,numm;
50*ebfedea0SLionel Sambuc int j=0;
51*ebfedea0SLionel Sambuc
52*ebfedea0SLionel Sambuc if (argc >= 2)
53*ebfedea0SLionel Sambuc num=atoi(argv[1]);
54*ebfedea0SLionel Sambuc
55*ebfedea0SLionel Sambuc if (num == 0) num=16;
56*ebfedea0SLionel Sambuc if (num > 250) num=16;
57*ebfedea0SLionel Sambuc numm=num+2;
58*ebfedea0SLionel Sambuc num*=64;
59*ebfedea0SLionel Sambuc numm*=64;
60*ebfedea0SLionel Sambuc
61*ebfedea0SLionel Sambuc for (j=0; j<6; j++)
62*ebfedea0SLionel Sambuc {
63*ebfedea0SLionel Sambuc for (i=0; i<10; i++) /**/
64*ebfedea0SLionel Sambuc {
65*ebfedea0SLionel Sambuc md4_block_x86(&ctx,buffer,numm);
66*ebfedea0SLionel Sambuc GetTSC(s1);
67*ebfedea0SLionel Sambuc md4_block_x86(&ctx,buffer,numm);
68*ebfedea0SLionel Sambuc GetTSC(e1);
69*ebfedea0SLionel Sambuc GetTSC(s2);
70*ebfedea0SLionel Sambuc md4_block_x86(&ctx,buffer,num);
71*ebfedea0SLionel Sambuc GetTSC(e2);
72*ebfedea0SLionel Sambuc md4_block_x86(&ctx,buffer,num);
73*ebfedea0SLionel Sambuc }
74*ebfedea0SLionel Sambuc printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75*ebfedea0SLionel Sambuc e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76*ebfedea0SLionel Sambuc }
77*ebfedea0SLionel Sambuc }
78*ebfedea0SLionel Sambuc
79