2 * measure-anything.c version 20090223
12 #include <sys/types.h>
14 # include <sys/resource.h>
16 #include "cpucycles.h"
21 static uint32 seed
[32] = { 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5 } ;
24 static int outleft
= 0;
26 #define ROTATE(x,b) (((x) << (b)) | ((x) >> (32 - (b))))
27 #define MUSH(i,b) x = t[i] += (((x ^ seed[i]) + sum) ^ ROTATE(x,b));
29 static void surf(void)
31 uint32 t
[12]; uint32 x
; uint32 sum
= 0;
32 int r
; int i
; int loop
;
34 for (i
= 0;i
< 12;++i
) t
[i
] = in
[i
] ^ seed
[12 + i
];
35 for (i
= 0;i
< 8;++i
) out
[i
] = seed
[24 + i
];
37 for (loop
= 0;loop
< 2;++loop
) {
38 for (r
= 0;r
< 16;++r
) {
40 MUSH(0,5) MUSH(1,7) MUSH(2,9) MUSH(3,13)
41 MUSH(4,5) MUSH(5,7) MUSH(6,9) MUSH(7,13)
42 MUSH(8,5) MUSH(9,7) MUSH(10,9) MUSH(11,13)
44 for (i
= 0;i
< 8;++i
) out
[i
] ^= t
[i
+ 4];
48 void randombytes(unsigned char *x
,unsigned long long xlen
)
52 if (!++in
[0]) if (!++in
[1]) if (!++in
[2]) ++in
[3];
62 extern const char *primitiveimplementation
;
63 extern const char *implementationversion
;
64 extern const char *sizenames
[];
65 extern const long long sizes
[];
66 extern void preallocate(void);
67 extern void allocate(void);
68 extern void measure(void);
70 static void printword(const char *s
)
72 if (!*s
) putchar('-');
74 if (*s
== ' ') putchar('_');
75 else if (*s
== '\t') putchar('_');
76 else if (*s
== '\r') putchar('_');
77 else if (*s
== '\n') putchar('_');
84 static void printnum(long long x
)
89 static void fail(const char *why
)
91 fprintf(stderr
,"measure: fatal: %s\n",why
);
95 unsigned char *alignedcalloc(unsigned long long len
)
97 unsigned char *x
= (unsigned char *) calloc(1,len
+ 128);
98 if (!x
) fail("out of memory");
99 /* will never deallocate so shifting is ok */
100 x
+= 63 & (-(unsigned long) x
);
104 static long long cyclespersecond
;
106 static void printimplementations(void)
110 printword("implementation");
111 printword(primitiveimplementation
);
112 printword(implementationversion
);
113 printf("\n"); fflush(stdout
);
115 for (i
= 0;sizenames
[i
];++i
) {
116 printword(sizenames
[i
]);
118 printf("\n"); fflush(stdout
);
123 printf("\n"); fflush(stdout
);
125 printword("cpucycles_persecond");
126 printnum(cyclespersecond
);
127 printf("\n"); fflush(stdout
);
129 printword("cpucycles_implementation");
130 printword(cpucycles_implementation
);
131 printf("\n"); fflush(stdout
);
133 printword("compiler");
135 #if defined(__VERSION__) && !defined(__ICC)
136 printword(__VERSION__
);
137 #elif defined(__xlc__)
143 sprintf(buf
, "%d.%d.%d", __ICC
/100, __ICC
%100,
144 __INTEL_COMPILER_BUILD_DATE
);
147 #elif defined(__PGIC__)
151 sprintf(buf
, "%d.%d.%d", __PGIC__
, __PGIC_MINOR__
, __PGIC_PATCHLEVEL__
);
154 #elif defined(__SUNPRO_C)
157 int major
, minor
, micro
;
159 micro
= __SUNPRO_C
& 0xf;
160 minor
= (__SUNPRO_C
>> 4) & 0xf;
161 major
= (__SUNPRO_C
>> 8) & 0xf;
164 sprintf(buf
, "%d.%d.%d", major
, minor
, micro
);
166 sprintf(buf
, "%d.%d", major
, minor
);
170 printword("unknown compiler version");
172 printf("\n"); fflush(stdout
);
175 void printentry(long long mbytes
,const char *measuring
,long long *m
,long long mlen
)
182 printword(measuring
);
183 if (mbytes
>= 0) printnum(mbytes
); else printword("");
185 for (j
= 0;j
+ 1 < mlen
;++j
) {
187 for (i
= 0;i
< mlen
;++i
) if (m
[i
] < m
[j
]) ++belowj
;
189 for (i
= 0;i
< mlen
;++i
) if (m
[i
] > m
[j
]) ++abovej
;
190 if (belowj
* 2 < mlen
&& abovej
* 2 < mlen
) break;
194 for (i
= 0;i
< mlen
;++i
) printnum(m
[i
]);
197 printf("\n"); fflush(stdout
);
207 setrlimit(RLIMIT_NOFILE
,&r
);
210 setrlimit(RLIMIT_NPROC
,&r
);
213 setrlimit(RLIMIT_CORE
,&r
);
220 cyclespersecond
= cpucycles_persecond();
223 printimplementations();